Agent with Knowledge
Answer questions from a PDF using Groq, OpenAI embeddings, and PgVector.
Add a PDF to a Knowledge base and let the agent retrieve relevant chunks to answer questions.
Code
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.models.groq import Groq
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),
)
# Add content to the knowledge
knowledge.insert(url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf")
agent = Agent(
model=Groq(id="openai/gpt-oss-120b"),
knowledge=knowledge,
)
agent.print_response("How to make Thai curry?", markdown=True)Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateSet your API key
export GROQ_API_KEY=xxx
export OPENAI_API_KEY=xxxInstall dependencies
uv pip install -U sqlalchemy psycopg pgvector pypdf openai groq agnoRun 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 Agent
Save the code above as knowledge.py, then run:
python knowledge.py