This example application shows how to build a sophisticated RAG (Retrieval Augmented Generation) system that leverages search of a knowledge base with LLMs to provide deep insights into the data.
The agent can:
- Process and understand documents from multiple sources (PDFs, websites, text files)
- Build a searchable knowledge base using vector embeddings
- Maintain conversation context and memory across sessions
- Provide relevant citations and sources for its responses
- Generate summaries and extract key insights
- Answer follow-up questions and clarifications
The agent uses:
- Vector similarity search for relevant document retrieval
- Conversation memory for contextual responses
- Citation tracking for source attribution
- Dynamic knowledge base updates
Example queries to try:
- “What are the key points from this document?”
- “Can you summarize the main arguments and supporting evidence?”
- “What are the important statistics and findings?”
- “How does this relate to [topic X]?”
- “What are the limitations or gaps in this analysis?”
- “Can you explain [concept X] in more detail?”
- “What other sources support or contradict these claims?”
Code
The complete code is available in the Agno repository.
Usage
Clone the repository
git clone https://github.com/agno-agi/agno.git
cd agno
Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
Install dependencies
pip install -r cookbook/examples/streamlit_apps/agentic_rag/requirements.txt
Run PgVector
First, install Docker Desktop.
Then run either using the helper script:
./cookbook/scripts/run_pgvector.sh
Or directly with Docker:
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 \
agnohq/pgvector:16
Set up API keys
# Required
export OPENAI_API_KEY=***
# Optional
export ANTHROPIC_API_KEY=***
export GOOGLE_API_KEY=***
We recommend using gpt-4o for optimal performance.
Launch the app
streamlit run cookbook/examples/streamlit_apps/agentic_rag/app.py
Open localhost:8501 to start using the Agentic RAG.
Need help? Join our Discourse community for support!
Responses are generated using AI and may contain mistakes.