AI Foundry Knowledge

Query PgVector knowledge through a current Foundry deployment with separate Azure OpenAI embeddings.

This source uses Agno's classic AzureAIFoundry adapter and the azure-ai-inference package, which Microsoft retired on August 26, 2026. Existing endpoint availability is separate from SDK retirement. For a new integration, use the current Foundry API setup with a compatible deployment. The classic setup below applies only to an existing compatible endpoint unless a current adaptation is explicitly provided.

Microsoft retired Cohere-command-r-08-2024 on May 12, 2026. Keep the source for reference and apply the current adapter/deployment changes in the run steps. The deployment must support tool calling for this example. Choose a model available in your resource; changing a string does not create a deployment. See the Azure retirement schedule.

knowledge.py
"""Run `uv pip install ddgs sqlalchemy pgvector pypdf 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.azure import AzureAIFoundry
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=AzureAIFoundry(id="Cohere-command-r-08-2024"),
    knowledge=knowledge,
)
agent.print_response("How to make Thai curry?", markdown=True)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    pass

Run the Current Adaptation

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno "psycopg[binary]" beautifulsoup4 openai pgvector pypdf sqlalchemy

Use a current Foundry deployment

Deploy an available model supporting Chat Completions and the capabilities used by this example. Copy its exact deployment name, the resource's OpenAI-compatible URL ending in /openai/v1, and its key. See the current Foundry API setup.

export FOUNDRY_DEPLOYMENT="your_deployment_name"
export FOUNDRY_BASE_URL="https://your-resource.services.ai.azure.com/openai/v1"
export FOUNDRY_API_KEY="your_resource_key"

In the saved source, replace the AzureAIFoundry import with:

from os import environ
from agno.models.openai.like import OpenAILike

Replace the entire AzureAIFoundry(...) expression with:

OpenAILike(
    id=environ["FOUNDRY_DEPLOYMENT"],
    api_key=environ["FOUNDRY_API_KEY"],
    base_url=environ["FOUNDRY_BASE_URL"],
)

Keep the surrounding Agent arguments and run calls. The deployment name can differ from the catalog's model name; it must match the deployment at this endpoint.

Configure Azure OpenAI embeddings

Deploy text-embedding-3-small in your embedding resource. These values are separate from the Foundry chat deployment. Set them before starting Python:

export AZURE_EMBEDDER_OPENAI_API_KEY="your_embedding_resource_key"
export AZURE_EMBEDDER_OPENAI_ENDPOINT="https://your-embedding-resource.openai.azure.com"
export AZURE_EMBEDDER_DEPLOYMENT="your_embedding_deployment_name"

Keep AzureOpenAIEmbedder() in the source. Its default model is text-embedding-3-small; the deployment variable selects the name at the embedding endpoint.

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:18

Run the example

Apply the current model import and constructor replacements above. Save the adapted code as knowledge.py, then run:

python knowledge.py

Full source: cookbook/90_models/azure/ai_foundry/knowledge.py