How giovannipasq/agentic-rag-for-dummies works
1. What this repository is
This repo is a reference implementation of an Agentic RAG system: a document question-answering pipeline that combines retrieval, query rewriting, clarification, multi-step reasoning, and answer synthesis. The repo is split into a learning path (notebooks/) and a modular runnable app (project/).
2. Two main delivery surfaces
- Notebooks: step-by-step experimentation for chunking, retrieval, evaluation, and observability.
- Project app: the production-shaped code path, launched from project/app.py, with modular packages for config, storage, graph orchestration, and UI.
3. Document ingestion and preprocessing
The ingestion pipeline converts PDFs to Markdown, then splits them into a hierarchical index:
- Parent chunks: larger markdown-based sections, stored as JSON files in a local parent store.
- Child chunks: smaller retrieval units embedded into Qdrant.
This design lets retrieval search precise snippets first, then pull larger surrounding context when needed.
4. Storage boundary
The architecture intentionally separates two retrieval stores:
- project/db/vector_db_manager.py for vector-backed child-chunk retrieval.
- project/db/parent_store_manager.py for local parent-chunk persistence.
That split is the key architectural boundary between semantic search and full-context document loading.
5. RAG orchestration layer
The project/core/ package holds the higher-level RAG plumbing:
- rag_system.py coordinates the overall retrieval/answering workflow.
- document_manager.py handles document lifecycle and indexing concerns.
- chat_interface.py and execution_logger.py support conversational execution and run tracking.
- observability.py integrates tracing/monitoring hooks.
This layer is the bridge between UI, storage, and the agent graph.
6. Agent workflow as a LangGraph state machine
The project/rag_agent/ package defines the core reasoning graph:
- graph.py, nodes.py, and edges.py describe the state transitions.
- graph_state.py defines the conversation and agent state objects.
- tools.py exposes retrieval tools to the LLM.
- prompts.py contains the system prompts for rewriting, orchestration, compression, and synthesis.
- schemas.py defines structured outputs used during query analysis.
This is the main control plane of the system.
7. How a question flows through the system
A user question enters the main graph, which:
- summarizes older conversation history,
- rewrites the query using recent context,
- optionally pauses for clarification,
- fans out into parallel agent subgraphs for multiple sub-questions,
- retrieves child chunks and, if needed, parent chunks,
- compresses intermediate context when the loop grows too large,
- aggregates answers into one final response.
This is a multi-stage retrieval-and-reasoning pipeline rather than a single prompt call.
8. Human-in-the-loop behavior
The system explicitly treats ambiguous follow-ups as a separate boundary. If the query depends on unresolved references, the graph can interrupt and ask for clarification before spending retrieval budget. That makes the architecture interactive and stateful, not just stateless search + generation.
9. State, memory, and execution limits
The graph uses structured state to keep:
- conversation summary,
- rewritten questions,
- pending clarification context,
- retrieval history,
- per-agent answer drafts.
The agent subgraph also enforces hard limits on tool calls and iterations, which protects against infinite retrieval loops and controls token growth.
10. Retrieval strategy
Retrieval is hybrid and hierarchical:
- Qdrant stores child chunks with vector search.
- The agent first searches children for precision.
- It loads parent chunks only when the child evidence is too fragmented.
This is the central data-flow pattern in the repo.
11. Interface and runtime
The UI is a Gradio chat application in project/ui/, with CSS customization and a chat wrapper that drives the graph. The repository also includes:
- a Dockerfile for containerized execution,
- .env.example for runtime configuration,
- requirements.txt for Python dependencies.
The default runtime is Python 3.11+.
12. Model/provider flexibility
The README emphasizes provider-agnostic LLM support through LangChain. Ollama is the default runnable setup, but the architecture is designed so the chat model can be swapped for OpenAI, Anthropic, Google, or other LangChain-supported providers without changing the overall graph structure.
13. Observability and evaluation
The repo has two non-production support tracks:
- Observability notebook and core/observability.py for tracing tool use and graph execution.
- Evaluation notebook with RAGAS-based scoring of retrieval and answer quality.
These are important because the system is agentic: correctness depends on intermediate retrieval behavior, not just final output.
14. How to think about the architecture diagram
A good diagram should show four major boundaries:
1) document ingestion/indexing,
2) persistent retrieval stores,
3) LangGraph-based agent orchestration,
4) Gradio chat front end.
The critical arrows are: user input → query rewriting/clarification → retrieval tools → child/parent stores → answer synthesis → UI response, with observability and evaluation as side channels.
Main entry points: rag_system.py RAG System · README.md Agentic RAG · nodes.py Agent Nodes · document_chunker.py Chunker
Components 23
Notebooks
Exploration, evaluation, and observability walkthroughs.
- PDF→Markdown · Experimentation path for document conversion and preprocessing.
notebooks/pdf_to_markdown.ipynb - RAG Walkthrough · End-to-end agentic RAG experimentation and iteration.
notebooks/agentic_rag.ipynb - Eval Notebook · RAGAS-based quality scoring and retrieval/answer assessment.
notebooks/evaluation.ipynb - Obs Notebook · Tracing and execution inspection for the agentic pipeline.
notebooks/observability.ipynb
Project App
Runnable application and supporting packages.
Ingestion
PDF-to-markdown conversion and chunking.
- Chunker · Splits markdown into hierarchical parent and child chunks.
project/document_chunker.py
Storage
Vector and parent chunk persistence.
- Vector Store · Embeds and searches child chunks for precise semantic retrieval.
project/db/vector_db_manager.py - Parent Store · Persists parent chunks as JSON for larger surrounding context.
project/db/parent_store_manager.py
Core
RAG coordination and execution support.
- RAG System · Top-level RAG coordination between UI, agent graph, and storage.
project/core/rag_system.py - Docs Manager · Document lifecycle, indexing, and preparation for retrieval.
project/core/document_manager.py - Chat Interface · Conversation handling and response shaping for the app runtime.
project/core/chat_interface.py - Execution Log · Execution logging and run bookkeeping for graph activity.
project/core/execution_logger.py - Observability · Monitoring and tracing integration for agent execution.
project/core/observability.py
Agent Graph
LangGraph-based reasoning and retrieval control plane.
- Graph State · Conversation, retrieval, clarification, and draft state for the agent.
project/rag_agent/graph_state.py - Graph Control · Defines agent flow, node transitions, and interruption points.
project/rag_agent/graph.py - Agent Nodes · Query rewriting, clarification, retrieval, compression, and synthesis steps.
project/rag_agent/nodes.py - Tools · LLM-facing access to child and parent retrieval functions.
project/rag_agent/tools.py - Prompts · System prompts for rewriting, orchestration, compression, and answer synthesis.
project/rag_agent/prompts.py - Schemas · Typed outputs used for query analysis and agent decisions.
project/rag_agent/schemas.py
UI
Chat front end.
Other components
- Agentic RAG · Notebook-driven learning path and modular runnable app for agentic retrieval-augmented QA.
README.md
Connections 26
- Agentic RAG → PDF→Markdown: learns via · The repository’s notebook path begins with conversion and preprocessing exploration.
- Agentic RAG → RAG Walkthrough: shows · The main learning workflow demonstrates the agentic RAG pipeline.
- Agentic RAG → Eval Notebook: evaluates · Evaluation notebook measures retrieval and answer quality.
- Agentic RAG → Obs Notebook: observes · Observability notebook inspects tracing and execution behavior.
- App Entry → RAG System: starts · The application entrypoint launches the RAG system.
- App Entry → Gradio UI: serves · The app runtime exposes the Gradio chat interface.
- Config → App Entry: configures · Runtime settings and model/provider choices feed startup.
- Gradio UI → Chat Interface: routes to · User chat is handled through the core conversation layer.
- Chat Interface → RAG System: delegates to · Conversation requests are handed to the RAG orchestrator.
- RAG System → Docs Manager: indexes · The orchestrator relies on document lifecycle and indexing management.
- Docs Manager → Chunker: chunks · Documents are split into hierarchical parent and child chunks.
- Chunker → Vector Store: embeds · Child chunks are prepared for vector retrieval.
- Chunker → Parent Store: persists · Parent chunks are stored for later full-context loading.
- RAG System → Graph Control: runs · The RAG system drives the LangGraph control plane.
- Graph Control → Graph State: mutates · Graph execution reads and updates structured agent state.
- Graph Control → Agent Nodes: executes · The control plane advances through reasoning and retrieval nodes.
- Agent Nodes → Tools: calls · Agent stages use retrieval tools for child and parent lookup.
- Agent Nodes → Prompts: guided by · Prompt templates steer rewriting, compression, and synthesis behavior.
- Agent Nodes → Schemas: emits · Structured schemas constrain analysis and decision outputs.
- Tools → Vector Store: searches · Primary retrieval queries the vector store for child chunks.
- Tools → Parent Store: loads · When child evidence is sparse, parent context is fetched.
- RAG System → Execution Log: logs · Execution bookkeeping captures run-level activity.
- RAG System → Observability: traces · Observability hooks instrument agent execution.
- Observability → Obs Notebook: inspires · Notebook-based observability mirrors runtime tracing.
- Gradio UI → UI Styles: styles · The UI is customized through shared CSS settings.
- Vector Store → Parent Store: hierarchy · Semantic child retrieval is paired with parent-context expansion.