Agent with Knowledge Base
Search a PgVector knowledge base from an Azure AI Foundry agent.
Classic adapter: its SDK is retired. See the migration example.
Code
For an existing classic endpoint, use an available Command A deployment named Cohere-command-a, or set id to your actual compatible deployment name. The older Command R August 2024 model retired on May 12, 2026; see the model schedule.
from agno.agent import Agent
from agno.knowledge.embedder.azure_openai import AzureOpenAIEmbedder
from agno.knowledge.knowledge import Knowledge
from agno.models.azure import AzureAIFoundry
from agno.vectordb.pgvector import PgVector
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=AzureAIFoundry(id="Cohere-command-a"),
knowledge=knowledge,
)
agent.print_response("How to make Thai curry?", markdown=True)Usage
The AzureOpenAIEmbedder() example also needs a separate text-embedding-3-small deployment (1536 dimensions). Set AZURE_EMBEDDER_DEPLOYMENT to that deployment name, with its own resource endpoint and key in the AZURE_EMBEDDER_OPENAI_* variables, before starting Python. These settings are independent of the chat deployment.
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateSet your API keys
export AZURE_API_KEY=xxx
export AZURE_ENDPOINT=xxx
# For the AzureOpenAIEmbedder
export AZURE_EMBEDDER_OPENAI_API_KEY=xxx
export AZURE_EMBEDDER_OPENAI_ENDPOINT=xxx
export AZURE_EMBEDDER_DEPLOYMENT="your_embedding_deployment"Install dependencies
uv pip install -U azure-ai-inference aiohttp openai sqlalchemy pgvector pypdf "psycopg[binary]" agnoRun PgVector
docker run -d \
-e POSTGRES_DB=ai \
-e POSTGRES_USER=ai \
-e POSTGRES_PASSWORD=ai \
-e PGDATA=/var/lib/postgresql/data/pgdata \
-v pgvolume:/var/lib/postgresql/data \
-p 5532:5432 \
--name pgvector \
agnohq/pgvector:18Run Agent
Save the code above as knowledge.py, then run:
python knowledge.py