Embedders: Choosing and Configuring Embedding Models
Embedders convert text into vectors for semantic search.
Embedders convert text into vectors for semantic search. The choice of embedder affects search quality, cost, and privacy.
"""
Embedders: Choosing and Configuring Embedding Models
=====================================================
Embedders convert text into vectors for semantic search. The choice of
embedder affects search quality, cost, and privacy.
This example shows two common configurations:
1. OpenAI (cloud, recommended default)
2. Ollama (local, private, no API calls)
For a full comparison of all 17+ supported providers, see:
../reference/embedder_comparison.md
"""
import asyncio
from agno.agent import Agent
from agno.knowledge.embedder.openai import OpenAIEmbedder
from agno.knowledge.knowledge import Knowledge
from agno.models.openai import OpenAIResponses
from agno.vectordb.qdrant import Qdrant
from agno.vectordb.search import SearchType
# ---------------------------------------------------------------------------
# Setup
# ---------------------------------------------------------------------------
qdrant_url = "http://localhost:6333"
pdf_url = "https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
# ---------------------------------------------------------------------------
# Run Demo
# ---------------------------------------------------------------------------
if __name__ == "__main__":
async def main():
# --- 1. OpenAI embedder (cloud, recommended default) ---
print("\n" + "=" * 60)
print("EMBEDDER 1: OpenAI text-embedding-3-small")
print("=" * 60 + "\n")
knowledge_openai = Knowledge(
vector_db=Qdrant(
collection="embedder_openai",
url=qdrant_url,
search_type=SearchType.hybrid,
embedder=OpenAIEmbedder(id="text-embedding-3-small"),
),
)
await knowledge_openai.ainsert(url=pdf_url, skip_if_exists=True)
agent_openai = Agent(
model=OpenAIResponses(id="gpt-5.2"),
knowledge=knowledge_openai,
search_knowledge=True,
markdown=True,
)
agent_openai.print_response("How do I make pad thai?", stream=True)
# --- 2. Ollama embedder (local, private) ---
# Requires: ollama pull nomic-embed-text
print("\n" + "=" * 60)
print("EMBEDDER 2: Ollama nomic-embed-text (local)")
print("=" * 60 + "\n")
try:
from agno.knowledge.embedder.ollama import OllamaEmbedder
knowledge_ollama = Knowledge(
vector_db=Qdrant(
collection="embedder_ollama",
url=qdrant_url,
search_type=SearchType.hybrid,
embedder=OllamaEmbedder(
id="nomic-embed-text",
dimensions=768,
),
),
)
await knowledge_ollama.ainsert(url=pdf_url, skip_if_exists=True)
agent_ollama = Agent(
model=OpenAIResponses(id="gpt-5.2"),
knowledge=knowledge_ollama,
search_knowledge=True,
markdown=True,
)
agent_ollama.print_response("How do I make pad thai?", stream=True)
except ImportError:
print("Ollama not installed. Run: pip install ollama")
except Exception as e:
print("Ollama embedder failed (is Ollama running?): %s" % e)
asyncio.run(main())The Ollama variant computes embeddings locally, but both agents still send questions and retrieved context to OpenAI. This is not an entirely local RAG application. Qdrant’s hybrid search also initializes a FastEmbed sparse model.
Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno fastembed importlib-metadata ollama openai pypdf qdrant-clientExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Run Qdrant
docker run -d --name qdrant -p 6333:6333 qdrant/qdrant:latestStart the local Ollama service
Install Ollama and start its desktop app or service on http://localhost:11434. If you start it manually with ollama serve, keep that process running in a separate terminal.
In the terminal where you will pull models and run Python, select that server and clear the direct-cloud key. The native Ollama client also reads this key independently of Agno.
export OLLAMA_HOST=http://localhost:11434
unset OLLAMA_API_KEYPull the embedding model
With Ollama running, download the model before starting Python:
ollama pull nomic-embed-textRun the example
Save the code above as embedders.py, then run:
python embedders.pyFull source: cookbook/07_knowledge/02_building_blocks/06_embedders.py