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,
)
参数
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
dimensions | int | 768 | 生成的嵌入向量的维度 |
model | str | models/text-embedding-004 | 要使用的 Gemini 模型名称 |
task_type | str | - | 生成嵌入向量的任务类型 |
title | str | - | 嵌入任务的可选标题 |
api_key | str | - | 用于验证请求的 API 密钥 |
request_params | Optional[Dict[str, Any]] | - | 嵌入请求参数的可选字典 |
client_params | Optional[Dict[str, Any]] | - | Gemini 客户端参数的可选字典 |
gemini_client | Optional[Client] | - | 可选的预配置 Gemini 客户端实例 |
开发者资源
- 查看 Cookbook