Knowledge
Give Claude a PgVector knowledge base built from a recipe PDF with Azure OpenAI embeddings.
Anthropic retired the source's dated Sonnet 4 and Opus 4 models on June 15, 2026. Before running your saved copy, replace claude-sonnet-4-20250514 or claude-opus-4-20250514 with the active claude-sonnet-4-6 model. See model lifecycle status.
"""Run `uv pip install ddgs sqlalchemy pgvector pypdf anthropic openai` to install dependencies."""
from agno.agent import Agent
from agno.knowledge.embedder.azure_openai import AzureOpenAIEmbedder
from agno.knowledge.knowledge import Knowledge
from agno.models.anthropic import Claude
from agno.vectordb.pgvector import PgVector
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
knowledge = Knowledge(
vector_db=PgVector(
table_name="recipes",
db_url=db_url,
embedder=AzureOpenAIEmbedder(),
),
)
# Add content to the knowledge
knowledge.insert(url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf")
agent = Agent(
model=Claude(id="claude-sonnet-4-20250514"),
knowledge=knowledge,
)
agent.print_response("How to make Thai curry?", markdown=True)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
passRun the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno "psycopg[binary]" anthropic beautifulsoup4 openai pgvector pypdf sqlalchemyExport environment variables
export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
export AZURE_EMBEDDER_OPENAI_API_KEY="your_azure_embedder_openai_api_key_here"
export AZURE_EMBEDDER_OPENAI_ENDPOINT="your_azure_embedder_openai_endpoint_here"Run PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql \
-v pgvolume:/var/lib/postgresql \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18Update the source model
In your saved copy, replace claude-sonnet-4-20250514 or claude-opus-4-20250514 with claude-sonnet-4-6. Keep the other model settings.
Select the Azure embedding deployment
Your Azure resource must already have a text-embedding-3-small deployment. If its deployment name is not text-embedding-3-small, export its actual name before starting Python:
export AZURE_EMBEDDER_DEPLOYMENT="your_embedding_deployment_name"The endpoint and key must belong to that resource. These variables select an existing deployment; they do not create one.
Run the example
Save the code above as knowledge.py, then run:
python knowledge.pyFull source: cookbook/90_models/anthropic/knowledge.py