import asyncio
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.pgvector import PgVector
# Create Knowledge Instance
knowledge = Knowledge(
name="Basic SDK Knowledge Base",
description="Agno 2.0 Knowledge Implementation",
vector_db=PgVector(
table_name="vectors", db_url="postgresql+psycopg://ai:ai@localhost:5532/ai"
),
)
# Add from local file to the knowledge base
asyncio.run(
knowledge.add_content_async(
name="CV",
path="cookbook/knowledge/testing_resources",
metadata={"user_tag": "Engineering Candidates"},
# Only include PDF files
include=["*.pdf"],
# Don't include files that match this pattern
exclude=["*cv_5*"],
)
)
agent = Agent(
name="My Agent",
description="Agno 2.0 Agent Implementation",
knowledge=knowledge,
search_knowledge=True,
debug_mode=True,
)
agent.print_response(
"Who is the best candidate for the role of a software engineer?",
markdown=True,
)
# Alex River is not in the knowledge base, so the Agent should not find any information about him
agent.print_response(
"Do you think Alex Rivera is a good candidate?",
markdown=True,
)
Install libraries
pip install -U agno sqlalchemy psycopg pgvector openai
Set environment variables
export OPENAI_API_KEY=xxx
Run 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 \
agno/pgvector:16
Run the example
python cookbook/knowledge/basic_operations/08_include_exclude_files.py