Hugging Face Embedder
Call a Hugging Face feature-extraction endpoint with HuggingfaceCustomEmbedder.
HuggingfaceCustomEmbedder defaults to intfloat/multilingual-e5-large. Set dimensions=1024 so Agno records that model's expected vector width.
from agno.knowledge.embedder.huggingface import HuggingfaceCustomEmbedder
embedder = HuggingfaceCustomEmbedder(dimensions=1024)
passage_vector = embedder.get_embedding(
"passage: The quick brown fox jumps over the lazy dog."
)
query_vector = embedder.get_embedding("query: Which animal jumps?")
print(f"Passage output length: {len(passage_vector)}")
print(f"Query output length: {len(query_vector)}")The default E5 model expects passage: for indexed passages and query: for retrieval queries. HuggingfaceCustomEmbedder does not add these prefixes. Add them before calling the embedder. The adapter also returns the feature-extraction response without pooling or flattening it. Confirm that your endpoint returns one flat vector before using it with a vector database.
The dimensions field does not request pooling or a specific output size from Hugging Face. It configures the expected width used by Agno's vector database integrations.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateExport the API key
export HUGGINGFACE_API_KEY=your_hugging_face_api_key_hereInstall dependencies
uv pip install -U agno huggingface-hubRun the example
python huggingface_embedder.py