camel.embeddings package#
Submodules#
camel.embeddings.base module#
- class camel.embeddings.base.BaseEmbedding[source]#
Bases:
ABC
,Generic
[T
]Abstract base class for text embedding functionalities.
- embed(obj: T, **kwargs: Any) list[float] [source]#
Generates an embedding for the given text.
- Parameters:
obj (T) β The object for which to generate the embedding.
**kwargs (Any) β Extra kwargs passed to the embedding API.
- Returns:
- A list of floating-point numbers representing the
generated embedding.
- Return type:
list[float]
- abstract embed_list(objs: list[T], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts.
- Parameters:
objs (list[T]) β The objects for which to generate the embeddings.
**kwargs (Any) β Extra kwargs passed to the embedding API.
- Returns:
- A list that represents the
generated embedding as a list of floating-point numbers.
- Return type:
list[list[float]]
camel.embeddings.mistral_embedding module#
- class camel.embeddings.mistral_embedding.MistralEmbedding(model_type: EmbeddingModelType = EmbeddingModelType.MISTRAL_EMBED, api_key: str | None = None, dimensions: int | None = None)[source]#
Bases:
BaseEmbedding
[str
]Provides text embedding functionalities using Mistralβs models.
- Parameters:
model_type (EmbeddingModelType, optional) β The model type to be used for text embeddings. (default:
MISTRAL_EMBED
)api_key (str, optional) β The API key for authenticating with the Mistral service. (default:
None
)dimensions (int, optional) β The text embedding output dimensions. (default:
None
)
- Raises:
RuntimeError β If an unsupported model type is specified.
- embed_list(objs: list[str], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts.
- Parameters:
objs (list[str]) β The texts for which to generate the embeddings.
**kwargs (Any) β Extra kwargs passed to the embedding API.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
list[list[float]]
camel.embeddings.openai_embedding module#
- class camel.embeddings.openai_embedding.OpenAIEmbedding(model_type: EmbeddingModelType = EmbeddingModelType.TEXT_EMBEDDING_3_SMALL, url: str | None = None, api_key: str | None = None, dimensions: int | NotGiven = NOT_GIVEN)[source]#
Bases:
BaseEmbedding
[str
]Provides text embedding functionalities using OpenAIβs models.
- Parameters:
model_type (EmbeddingModelType, optional) β The model type to be used for text embeddings. (default:
TEXT_EMBEDDING_3_SMALL
)url (Optional[str], optional) β The url to the OpenAI service. (default:
None
)api_key (str, optional) β The API key for authenticating with the OpenAI service. (default:
None
)dimensions (int, optional) β The text embedding output dimensions. (default:
NOT_GIVEN
)
- Raises:
RuntimeError β If an unsupported model type is specified.
- embed_list(objs: list[str], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts.
- Parameters:
objs (list[str]) β The texts for which to generate the embeddings.
**kwargs (Any) β Extra kwargs passed to the embedding API.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
list[list[float]]
camel.embeddings.sentence_transformers_embeddings module#
- class camel.embeddings.sentence_transformers_embeddings.SentenceTransformerEncoder(model_name: str = 'intfloat/e5-large-v2', **kwargs)[source]#
Bases:
BaseEmbedding
[str
]This class provides functionalities to generate text embeddings using Sentence Transformers.
References
- embed_list(objs: list[str], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts using the model.
- Parameters:
objs (list[str]) β The texts for which to generate the embeddings.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
list[list[float]]
camel.embeddings.vlm_embedding module#
- class camel.embeddings.vlm_embedding.VisionLanguageEmbedding(model_name: str = 'openai/clip-vit-base-patch32')[source]#
Bases:
BaseEmbedding
[str
|Image
]Provides image embedding functionalities using multimodal model.
- Parameters:
model_name β The model type to be used for generating embeddings. And the default value is: obj:openai/clip-vit-base-patch32.
- Raises:
RuntimeError β If an unsupported model type is specified.
- embed_list(objs: List[Image | str], **kwargs: Any) List[List[float]] [source]#
Generates embeddings for the given images or texts.
- Parameters:
objs (List[Image.Image|str]) β The list of images or texts for which to generate the embeddings.
image_processor_kwargs β Extra kwargs passed to the image processor.
tokenizer_kwargs β Extra kwargs passed to the text tokenizer (processor).
model_kwargs β Extra kwargs passed to the main model.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
List[List[float]]
- Raises:
ValueError β If the input type is not Image.Image or str.
Module contents#
- class camel.embeddings.BaseEmbedding[source]#
Bases:
ABC
,Generic
[T
]Abstract base class for text embedding functionalities.
- embed(obj: T, **kwargs: Any) list[float] [source]#
Generates an embedding for the given text.
- Parameters:
obj (T) β The object for which to generate the embedding.
**kwargs (Any) β Extra kwargs passed to the embedding API.
- Returns:
- A list of floating-point numbers representing the
generated embedding.
- Return type:
list[float]
- abstract embed_list(objs: list[T], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts.
- Parameters:
objs (list[T]) β The objects for which to generate the embeddings.
**kwargs (Any) β Extra kwargs passed to the embedding API.
- Returns:
- A list that represents the
generated embedding as a list of floating-point numbers.
- Return type:
list[list[float]]
- class camel.embeddings.JinaEmbedding(model_type: EmbeddingModelType = EmbeddingModelType.JINA_EMBEDDINGS_V3, api_key: str | None = None, dimensions: int | None = None, embedding_type: str | None = None, task: str | None = None, late_chunking: bool = False, normalized: bool = False)[source]#
Bases:
BaseEmbedding
[str
|Image
]Provides text and image embedding functionalities using Jina AIβs API.
- Parameters:
model_type (EmbeddingModelType, optional) β The model to use for embeddings. (default:
JINA_EMBEDDINGS_V3
)api_key (Optional[str], optional) β The API key for authenticating with Jina AI. (default:
None
)dimensions (Optional[int], optional) β The dimension of the output embeddings. (default:
None
)embedding_type (Optional[str], optional) β The type of embedding format to generate. Options: βint8β (binary encoding with higher storage and transfer efficiency), βuint8β (unsigned binary encoding with higher storage and transfer efficiency), βbase64β (base64 string encoding with higher transfer efficiency). (default:
None
)task (Optional[str], optional) β The type of task for text embeddings. Options: retrieval.query, retrieval.passage, text-matching, classification, separation. (default:
None
)late_chunking (bool, optional) β If true, concatenates all sentences in input and treats as a single input. (default:
False
)normalized (bool, optional) β If true, embeddings are normalized to unit L2 norm. (default:
False
)
- embed_list(objs: list[str | Image], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts or images.
- Parameters:
objs (list[Union[str, Image.Image]]) β The texts or images for which to generate the embeddings.
**kwargs (Any) β Extra kwargs passed to the embedding API. Not used in this implementation.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
list[list[float]]
- Raises:
ValueError β If the input type is not supported.
RuntimeError β If the API request fails.
- class camel.embeddings.MistralEmbedding(model_type: EmbeddingModelType = EmbeddingModelType.MISTRAL_EMBED, api_key: str | None = None, dimensions: int | None = None)[source]#
Bases:
BaseEmbedding
[str
]Provides text embedding functionalities using Mistralβs models.
- Parameters:
model_type (EmbeddingModelType, optional) β The model type to be used for text embeddings. (default:
MISTRAL_EMBED
)api_key (str, optional) β The API key for authenticating with the Mistral service. (default:
None
)dimensions (int, optional) β The text embedding output dimensions. (default:
None
)
- Raises:
RuntimeError β If an unsupported model type is specified.
- embed_list(objs: list[str], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts.
- Parameters:
objs (list[str]) β The texts for which to generate the embeddings.
**kwargs (Any) β Extra kwargs passed to the embedding API.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
list[list[float]]
- class camel.embeddings.OpenAICompatibleEmbedding(model_type: str, api_key: str | None = None, url: str | None = None)[source]#
Bases:
BaseEmbedding
[str
]Provides text embedding functionalities supporting OpenAI compatibility.
- Parameters:
model_type (str) β The model type to be used for text embeddings.
api_key (str) β The API key for authenticating with the model service.
url (str) β The url to the model service.
- embed_list(objs: list[str], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts.
- Parameters:
objs (list[str]) β The texts for which to generate the embeddings.
**kwargs (Any) β Extra kwargs passed to the embedding API.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
list[list[float]]
- class camel.embeddings.OpenAIEmbedding(model_type: EmbeddingModelType = EmbeddingModelType.TEXT_EMBEDDING_3_SMALL, url: str | None = None, api_key: str | None = None, dimensions: int | NotGiven = NOT_GIVEN)[source]#
Bases:
BaseEmbedding
[str
]Provides text embedding functionalities using OpenAIβs models.
- Parameters:
model_type (EmbeddingModelType, optional) β The model type to be used for text embeddings. (default:
TEXT_EMBEDDING_3_SMALL
)url (Optional[str], optional) β The url to the OpenAI service. (default:
None
)api_key (str, optional) β The API key for authenticating with the OpenAI service. (default:
None
)dimensions (int, optional) β The text embedding output dimensions. (default:
NOT_GIVEN
)
- Raises:
RuntimeError β If an unsupported model type is specified.
- embed_list(objs: list[str], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts.
- Parameters:
objs (list[str]) β The texts for which to generate the embeddings.
**kwargs (Any) β Extra kwargs passed to the embedding API.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
list[list[float]]
- class camel.embeddings.SentenceTransformerEncoder(model_name: str = 'intfloat/e5-large-v2', **kwargs)[source]#
Bases:
BaseEmbedding
[str
]This class provides functionalities to generate text embeddings using Sentence Transformers.
References
- embed_list(objs: list[str], **kwargs: Any) list[list[float]] [source]#
Generates embeddings for the given texts using the model.
- Parameters:
objs (list[str]) β The texts for which to generate the embeddings.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
list[list[float]]
- class camel.embeddings.VisionLanguageEmbedding(model_name: str = 'openai/clip-vit-base-patch32')[source]#
Bases:
BaseEmbedding
[str
|Image
]Provides image embedding functionalities using multimodal model.
- Parameters:
model_name β The model type to be used for generating embeddings. And the default value is: obj:openai/clip-vit-base-patch32.
- Raises:
RuntimeError β If an unsupported model type is specified.
- embed_list(objs: List[Image | str], **kwargs: Any) List[List[float]] [source]#
Generates embeddings for the given images or texts.
- Parameters:
objs (List[Image.Image|str]) β The list of images or texts for which to generate the embeddings.
image_processor_kwargs β Extra kwargs passed to the image processor.
tokenizer_kwargs β Extra kwargs passed to the text tokenizer (processor).
model_kwargs β Extra kwargs passed to the main model.
- Returns:
- A list that represents the generated embedding
as a list of floating-point numbers.
- Return type:
List[List[float]]
- Raises:
ValueError β If the input type is not Image.Image or str.