embedding.EmbeddingCohere

Creates an embedding function provider backed by Cohere’s embedding models.

Usage

Source

embedding.EmbeddingCohere(
    model="embed-english-v3.0", api_key=None, batch_size=96
)

Implements the EmbeddingProvider interface.

Cohere’s embedding models produce different embeddings for queries vs documents to optimize retrieval performance. Use input_type=EmbedInputType.QUERY when embedding search queries and input_type=EmbedInputType.DOCUMENT (default) when embedding documents for indexing.

Parameters

model: str = "embed-english-v3.0"

The Cohere embedding model to use. Default is “embed-english-v3.0”.

api_key: Optional[str] = None

The API key for authenticating with Cohere. If None, it will use the CO_API_KEY environment variable if set.

batch_size: int = 96
The number of texts to process in each batch when calling the API. Cohere supports up to 96 texts per request.

Examples

from raghilda.embedding import EmbeddingCohere, EmbedInputType

provider = EmbeddingCohere(model="embed-english-v3.0")

# Embed documents for indexing
doc_embeddings = provider.embed(
    ["Hello world", "Testing embeddings"],
    input_type=EmbedInputType.DOCUMENT
)

# Embed a query for search
query_embedding = provider.embed(
    ["How do I test embeddings?"],
    input_type=EmbedInputType.QUERY
)