HuggingfaceCustomEmbedder 类用于通过 Hugging Face API 将文本数据嵌入到向量中。您可以从此处获取。

用法

cookbook/embedders/huggingface_embedder.py
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,
)

参数

参数类型默认值描述
dimensionsint-生成的嵌入向量的维度
modelstrall-MiniLM-L6-v2要使用的 HuggingFace 模型名称
api_keystr-用于身份验证请求的 API 密钥
client_paramsOptional[Dict[str, Any]]-HuggingFace 客户端的可选参数字典
huggingface_clientAny-可选的预配置 HuggingFace 客户端实例

##开发者资源