Em invoker
Defines a base class for embedding model invokers used in Gen AI applications.
References
NONE
BaseEMInvoker(model_id, default_hyperparameters=None, supported_attachments=None, retry_config=None, truncation_config=None)
Bases: ABC
A base class for embedding model invokers used in Gen AI applications.
The BaseEMInvoker class provides a framework for invoking embedding models.
Attributes:
| Name | Type | Description |
|---|---|---|
model_id |
str
|
The model ID of the embedding model. |
model_provider |
str
|
The provider of the embedding model. |
model_name |
str
|
The name of the embedding model. |
default_hyperparameters |
dict[str, Any]
|
Default hyperparameters for invoking the embedding model. Defaults to None, in which case an empty dictionary is used. |
retry_config |
RetryConfig
|
The retry configuration for the embedding model. Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used. |
truncation_config |
TruncationConfig | None
|
The truncation configuration for the embedding model. Defaults to None, in which case no truncation is applied. |
Initializes a new instance of the BaseEMInvoker class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id |
ModelId
|
The model ID of the embedding model. |
required |
default_hyperparameters |
dict[str, Any] | None
|
Default hyperparameters for invoking the embedding model. Defaults to None, in which case an empty dictionary is used. |
None
|
supported_attachments |
set[str] | None
|
A set of supported attachment types. Defaults to None, in which case an empty set is used (indicating that no attachments are supported). |
None
|
retry_config |
RetryConfig | None
|
The retry configuration for the embedding model. Defaults to None, in which case a default config with no retry and 30.0 seconds timeout will be used. |
None
|
truncation_config |
TruncationConfig | None
|
Configuration for text truncation behavior. Defaults to None, in which case no truncation is applied. |
None
|
model_id: str
property
The model ID of the embedding model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The model ID of the embedding model. |
model_name: str
property
The name of the embedding model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the embedding model. |
model_provider: str
property
The provider of the embedding model.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The provider of the embedding model. |
invoke(content, hyperparameters=None)
async
Invokes the embedding model with the provided content or list of contents.
This method invokes the embedding model with the provided content or list of contents. It includes retry logic with exponential backoff for transient failures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content |
EMContent | list[EMContent]
|
The input or list of inputs to be embedded using the embedding model. |
required |
hyperparameters |
dict[str, Any] | None
|
A dictionary of hyperparameters for the embedding model. Defaults to None, in which case the default hyperparameters are used. |
None
|
Returns:
| Type | Description |
|---|---|
Vector | list[Vector]
|
Vector | list[Vector]: The vector representations of the input contents:
1. If the input is an |
Raises:
| Type | Description |
|---|---|
CancelledError
|
If the invocation is cancelled. |
ModelNotFoundError
|
If the model is not found. |
ProviderAuthError
|
If the model authentication fails. |
ProviderInternalError
|
If the model internal error occurs. |
ProviderInvalidArgsError
|
If the model parameters are invalid. |
ProviderOverloadedError
|
If the model is overloaded. |
ProviderRateLimitError
|
If the model rate limit is exceeded. |
TimeoutError
|
If the invocation times out. |
ValueError
|
If the input content is invalid. |