GeminiEmbedder 类用于通过 Gemini API 将文本数据嵌入到向量中。您可以 在此处 获取。

用法

cookbook/embedders/gemini_embedder.py
from agno.agent import AgentKnowledge
from agno.vectordb.pgvector import PgVector
from agno.embedder.google import GeminiEmbedder

# 将句子嵌入数据库
embeddings = GeminiEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.")

# 打印嵌入向量及其维度
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")

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

参数

参数类型默认值描述
dimensionsint768生成的嵌入向量的维度
modelstrmodels/text-embedding-004要使用的 Gemini 模型名称
task_typestr-生成嵌入向量的任务类型
titlestr-嵌入任务的可选标题
api_keystr-用于验证请求的 API 密钥
request_paramsOptional[Dict[str, Any]]-嵌入请求参数的可选字典
client_paramsOptional[Dict[str, Any]]-Gemini 客户端参数的可选字典
gemini_clientOptional[Client]-可选的预配置 Gemini 客户端实例

开发者资源