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]]

abstract get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int

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]]

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int

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]]

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int

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

https://www.sbert.net/

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]]

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embeddings.

Return type:

int

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.

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int

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]]

abstract get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int

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.

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int

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]]

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int

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]]

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int

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]]

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int

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

https://www.sbert.net/

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]]

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embeddings.

Return type:

int

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.

get_output_dim() int[source]#

Returns the output dimension of the embeddings.

Returns:

The dimensionality of the embedding for the current model.

Return type:

int