Knowledge
Attach a PgVector knowledge base of recipes to Claude running on Bedrock.
"""Run `uv pip install ddgs sqlalchemy pgvector pypdf openai anthropic` to install dependencies."""
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.models.aws 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),
)
# Add content to the knowledge
knowledge.insert(url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf")
agent = Agent(
model=Claude(id="global.anthropic.claude-sonnet-4-5-20250929-v1:0"),
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 "anthropic[bedrock]" "psycopg[binary]" aioboto3 beautifulsoup4 boto3 openai pgvector pypdf sqlalchemyConfigure AWS access
Select a source region that supports the model or inference profile in the example. A geographic profile such as us. routes across the source and destination regions listed for that profile; a global. profile can route globally. Verify the model's regional availability and your IAM permission to invoke it. For Anthropic models, complete the account's first-use model access requirements.
export AWS_REGION="us-east-1"
export AWS_ACCESS_KEY_ID="your_aws_access_key_id"
export AWS_SECRET_ACCESS_KEY="your_aws_secret_access_key"
# Required when using temporary credentials:
# export AWS_SESSION_TOKEN="your_aws_session_token"Use credentials and any session token from the same session. Change AWS_REGION if you choose another supported source region. These examples use AWS credentials; agno.models.aws.Claude does not accept an Anthropic API key or a Bedrock API key in place of them.
Configure the OpenAI embedder
PgVector uses OpenAI embeddings by default in this example. Set the embedding key separately from the AWS credentials:
export OPENAI_API_KEY="your_openai_api_key"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:18Run the example
Save the code above as knowledge.py, then run:
python knowledge.pyFull source: cookbook/90_models/aws/claude/knowledge.py