OpenAI Knowledge
Load a recipe PDF into PgVector with AzureOpenAIEmbedder and query it from an agent.
"""Run `uv pip install ddgs sqlalchemy pgvector pypdf openai` to install dependencies."""
import asyncio
from agno.agent import Agent
from agno.knowledge.embedder.azure_openai import AzureOpenAIEmbedder
from agno.knowledge.knowledge import Knowledge
from agno.models.azure import AzureOpenAI
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
asyncio.run(
knowledge.ainsert(
url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
)
)
agent = Agent(
model=AzureOpenAI(id="gpt-5.2"),
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]" beautifulsoup4 openai pgvector pypdf sqlalchemyExport environment variables
export AZURE_EMBEDDER_DEPLOYMENT="your_azure_embedder_deployment_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"
export AZURE_OPENAI_API_KEY="your_azure_openai_api_key_here"
export AZURE_OPENAI_DEPLOYMENT="your_azure_openai_deployment_here"
export AZURE_OPENAI_ENDPOINT="your_azure_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:18Configure Azure deployments
Confirm that AZURE_OPENAI_DEPLOYMENT and AZURE_EMBEDDER_DEPLOYMENT refer to deployed gpt-5.2 and text-embedding-3-small resources. Azure API calls use deployment names rather than model names. See Azure OpenAI deployment setup.
Run the example
Save the code above as knowledge.py, then run:
python knowledge.pyFull source: cookbook/90_models/azure/openai/knowledge.py