pyseekdb.utils.embedding_functions.CohereEmbeddingFunction
- class pyseekdb.utils.embedding_functions.CohereEmbeddingFunction(model_name: str = 'embed-english-v3.0', api_key_env: str | None = None, input_type: str | None = None, **kwargs: Any)[source]
Bases:
LiteLLMBaseEmbeddingFunctionA convenient embedding function for Cohere embedding models using LiteLLM.
For more information about Cohere models, see https://docs.cohere.com/docs/cohere-embed
For LiteLLM documentation, see https://docs.litellm.ai/docs/embedding/supported_embedding
Example
pip install pyseekdb litellm
- __init__(model_name: str = 'embed-english-v3.0', api_key_env: str | None = None, input_type: str | None = None, **kwargs: Any)[source]
Initialize CohereEmbeddingFunction.
- Parameters:
model_name (str, optional) – Name of the Cohere embedding model. Defaults to “embed-english-v3.0”. See Cohere documentation for available models: https://docs.cohere.com/docs/cohere-embed
api_key_env (str, optional) – Name of the environment variable containing the Cohere API key. Defaults to “COHERE_API_KEY” if not provided.
input_type (str, optional) – Type of the input text. Options: None, “search_document”, “search_query”. When set to “search_document” or “search_query”, Cohere optimizes embeddings for retrieval/search tasks. Defaults to None.
**kwargs – Additional arguments to pass to LiteLLM.
See https://docs.litellm.ai/docs/providers/cohere#embedding for more information.
Methods
__init__([model_name, api_key_env, input_type])Initialize CohereEmbeddingFunction.
build_from_config(config)Build a CohereEmbeddingFunction from its configuration dictionary.
Get the configuration dictionary for the CohereEmbeddingFunction.
name()Get the unique name identifier for CohereEmbeddingFunction.
support_persistence(embedding_function)Check if the embedding function supports persistence.
Attributes
Get the dimension of embeddings produced by this function.
- static build_from_config(config: dict[str, Any]) CohereEmbeddingFunction[source]
Build a CohereEmbeddingFunction from its configuration dictionary.
- Parameters:
config – Dictionary containing the embedding function’s configuration
- Returns:
Restored CohereEmbeddingFunction instance
- Raises:
ValueError – If the configuration is invalid or missing required fields
- property dimension: int
Get the dimension of embeddings produced by this function.
Returns the known dimension for models without making an API call. If the model is in the known dimensions list, that value is returned.
If the model is not in the known dimensions list, falls back to making an API call to get the embedding and infer the dimension.
- Returns:
The dimension of embeddings for this model.
- Return type:
int