CohereEmbedder 类用于通过 Cohere API 将文本数据嵌入到向量中。您可以从 此处 开始了解 Cohere。

此处 获取您的密钥。

用法

cookbook/embedders/cohere_embedder.py
from agno.agent import AgentKnowledge
from agno.vectordb.pgvector import PgVector
from agno.embedder.cohere import CohereEmbedder

# 将嵌入添加到数据库
embeddings = CohereEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.")
# 打印嵌入及其维度
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")

# 在知识库中使用 embedder
knowledge_base = AgentKnowledge(
    vector_db=PgVector(
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
        table_name="cohere_embeddings",
        embedder=CohereEmbedder(),
    ),
    num_documents=2,
)

参数

参数类型默认值描述
modelstr"embed-english-v3.0"用于生成嵌入的模型名称。
input_typestrsearch_query要嵌入的输入类型。您可以在 此处 找到更多详细信息
embedding_typesOptional[List[str]]-要生成的嵌入类型。可选。
api_keystr-用于身份验证请求的 Cohere API 密钥。
request_paramsOptional[Dict[str, Any]]-要包含在 API 请求中的附加参数。可选。
client_paramsOptional[Dict[str, Any]]-用于配置 API 客户端的附加参数。可选。
cohere_clientOptional[CohereClient]-用于发出 API 请求的 CohereClient 实例。可选。

开发者资源