The CohereEmbedder class is used to embed text data into vectors using the Cohere API. You can get started with Cohere from here Get your key from here.

Usage

cookbook/embedders/cohere_embedder.py
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector
from agno.knowledge.embedder.cohere import CohereEmbedder

# Add embedding to database
embeddings = CohereEmbedder(id="embed-english-v3.0").get_embedding("The quick brown fox jumps over the lazy dog.")
# Print the embeddings and their dimensions
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")

# Use an embedder in a knowledge base
knowledge = Knowledge(
    vector_db=PgVector(
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
        table_name="cohere_embeddings",
        embedder=CohereEmbedder(id="embed-english-v3.0"),
    ),
    max_results=2,
)

Params

ParameterTypeDefaultDescription
modelstr"embed-english-v3.0"The name of the model used for generating embeddings.
input_typestrsearch_queryThe type of input to embed. You can find more details here
embedding_typesOptional[List[str]]-The type of embeddings to generate. Optional.
api_keystr-The Cohere API key used for authenticating requests.
request_paramsOptional[Dict[str, Any]]-Additional parameters to include in the API request. Optional.
client_paramsOptional[Dict[str, Any]]-Additional parameters for configuring the API client. Optional.
cohere_clientOptional[CohereClient]-An instance of the CohereClient to use for making API requests. Optional.

Developer Resources