HuggingfaceCustomEmbedder 类用于通过 Hugging Face API 将文本数据嵌入到向量中。您可以从此处获取。
用法
cookbook/embedders/huggingface_embedder.py
参数
##开发者资源
- 查看 Cookbook
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
HuggingfaceCustomEmbedder 类用于通过 Hugging Face API 将文本数据嵌入到向量中。您可以从此处获取。
from agno.agent import AgentKnowledge
from agno.vectordb.pgvector import PgVector
from agno.embedder.huggingface import HuggingfaceCustomEmbedder
# 将句子嵌入到数据库中
embeddings = HuggingfaceCustomEmbedder().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="huggingface_embeddings",
embedder=HuggingfaceCustomEmbedder(),
),
num_documents=2,
)
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
dimensions | int | - | 生成的嵌入向量的维度 |
model | str | all-MiniLM-L6-v2 | 要使用的 HuggingFace 模型名称 |
api_key | str | - | 用于身份验证请求的 API 密钥 |
client_params | Optional[Dict[str, Any]] | - | HuggingFace 客户端的可选参数字典 |
huggingface_client | Any | - | 可选的预配置 HuggingFace 客户端实例 |