PDFReader to Knowledge.insert() to configure PDF parsing and chunking.
pdf_reader.py
from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.knowledge.reader.pdf_reader import PDFReader
from agno.models.openai import OpenAIResponses
from agno.vectordb.pgvector import PgVector
db_url = "postgresql+psycopg://ai:ai@localhost:5532/ai"
knowledge = Knowledge(
vector_db=PgVector(
table_name="pdf_documents",
db_url=db_url,
),
)
agent = Agent(
model=OpenAIResponses(id="gpt-5.2"),
knowledge=knowledge,
search_knowledge=True,
)
if __name__ == "__main__":
knowledge.insert(
name="Thai Recipes",
url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
reader=PDFReader(split_on_pages=True),
)
agent.print_response(
"How do I make chicken and galangal in coconut milk soup?",
markdown=True,
)
Run the Agent
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno openai pgvector psycopg pypdf sqlalchemy
3
Export the API key
export OPENAI_API_KEY=your_openai_api_key_here
4
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
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
5
Run the agent
python pdf_reader.py
Reader Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
split_on_pages | bool | True | Create one document per page instead of one document for the whole file |
page_start_numbering_format | Optional[str] | "<start page {page_nr}>" | Marker inserted at the start of each page. Set to an empty string to remove |
page_end_numbering_format | Optional[str] | "<end page {page_nr}>" | Marker inserted at the end of each page. Set to an empty string to remove |
password | Optional[str] | None | Password to unlock encrypted PDFs |
sanitize_content | bool | True | Join fragmented lines from PDF text extraction into flowing text. Disable to preserve whitespace-sensitive content like code blocks or tables |
chunking_strategy | Optional[ChunkingStrategy] | DocumentChunking() | Strategy used to chunk documents |
PDFReader also accepts the base Reader constructor parameters.
Use PDFReader.async_read() or Knowledge.ainsert() in an asynchronous ingestion path.
Next Steps
| Task | Guide |
|---|---|
| Choose a chunking strategy | Chunking |
| Process images with OCR | Readers Overview |
| Configure another reader | Docling Reader |