Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs-v1.agno.com/llms.txt

Use this file to discover all available pages before exploring further.

The HuggingfaceCustomEmbedder class is used to embed text data into vectors using the Hugging Face API. You can get one from here.

Usage

cookbook/embedders/huggingface_embedder.py
from agno.agent import AgentKnowledge
from agno.vectordb.pgvector import PgVector
from agno.embedder.huggingface import HuggingfaceCustomEmbedder

# Embed sentence in database
embeddings = HuggingfaceCustomEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.")

# Print the embeddings and their dimensions
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")

# Use an embedder in a knowledge base
knowledge_base = AgentKnowledge(
    vector_db=PgVector(
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
        table_name="huggingface_embeddings",
        embedder=HuggingfaceCustomEmbedder(),
    ),
    num_documents=2,
)

Params

ParameterTypeDefaultDescription
dimensionsint-The dimensionality of the generated embeddings
modelstrall-MiniLM-L6-v2The name of the HuggingFace model to use
api_keystr-The API key used for authenticating requests
client_paramsOptional[Dict[str, Any]]-Optional dictionary of parameters for the HuggingFace client
huggingface_clientAny-Optional pre-configured HuggingFace client instance

Developer Resources