Cohere
Cohere provides embedding models for semantic search, clustering, and recommendation. seekdb provides a CohereEmbeddingFunction wrapper (powered by LiteLLM) to generate Cohere embeddings and use them with seekdb collections.
Using Cohere service requires you to follow Cohere's pricing rules and may incur corresponding fees. Before proceeding, please visit their official website or refer to relevant documentation to confirm and accept their pricing standards. If you do not agree, please do not proceed.
Dependencies and authentication
CohereEmbeddingFunction calls the Cohere embedding API via LiteLLM. In practice, you typically need:
- A Cohere API key with access to the embedding models you plan to use
- Python packages:
pyseekdbandlitellm
Authentication is usually provided via environment variables (by default, COHERE_API_KEY). If you use a different environment variable name, set api_key_env.
Example: create a Cohere embedding function
-
Basic usage
from pyseekdb.utils.embedding_functions import CohereEmbeddingFunction
ef = CohereEmbeddingFunction(model_name="embed-english-v3.0") -
Multilingual model
from pyseekdb.utils.embedding_functions import CohereEmbeddingFunction
ef = CohereEmbeddingFunction(model_name="embed-multilingual-v3.0") -
Use a custom API key environment variable (
api_key_env)from pyseekdb.utils.embedding_functions import CohereEmbeddingFunction
ef = CohereEmbeddingFunction(
model_name="embed-english-v3.0",
api_key_env="YOUR_API_KEY_ENV",
) -
Set
input_type(recommended for retrieval)from pyseekdb.utils.embedding_functions import CohereEmbeddingFunction
ef = CohereEmbeddingFunction(
model_name="embed-english-v3.0",
input_type="search_document",
)
# For query-side embeddings, use input_type="search_query"
Parameters
model_name: Cohere embedding model name (for example,embed-english-v3.0).api_key_env: the environment variable name holding your Cohere API key (default:COHERE_API_KEY).input_type: an optional hint to optimize retrieval embeddings (commonlysearch_documentorsearch_query).