How premsagariit/langgraph-rag works
Purpose and entry points
This is a local, agentic RAG application for asking cited questions over uploaded PDFs. app.py is the Streamlit launch target; it delegates chat/upload behavior to ui/streamlit_chat.py and system initialization to core/rag_system.py. Batch quality evaluation enters through eval/run_ragas_eval.py.
System bootstrap and runtime boundary
core/rag_system.py composes the Groq LLM, embedded local Qdrant-backed retriever, and compiled LangGraph agent. config.py centralizes model selections, chunking settings, and agent research limits. Runtime requires a GROQ_API_KEY; PDF corpus and vector index are local to the application environment.
Paths: core/rag_system.py, config.py, .env.example
Document ingestion pipeline
Uploaded PDFs pass through core/document_manager.py, which manages add/list/clear operations. The ingestion layer converts PDFs to Markdown, splits first by H1/H2/H3 and then paragraph-sized windows, retaining header-path metadata. Resulting chunks are indexed for hybrid retrieval.
Paths: core/document_manager.py, ingestion/chunker.py, ingestion/vector_store.py
Hybrid retrieval service
ingestion/vector_store.py exposes the corpus boundary to the agent: Qdrant combines dense embeddings from Qwen3-Embedding-0.6B with BM25 sparse matching. The retrieval tool in rag_agent/tools.py searches this store; returned chunks carry document/header context used as answer evidence and citations.
Paths: ingestion/vector_store.py, rag_agent/tools.py
LangGraph conversation and query preparation
The graph maintains messages, agent messages, and rolling memory in rag_agent/graph_state.py. It first summarizes history, then converts the user request into a self-contained query via structured query analysis. Ambiguous queries route to a clarification state; LangGraph interrupts and later resumes once the user supplies clarification.
Paths: rag_agent/graph.py, rag_agent/nodes.py, rag_agent/graph_state.py
Tool-calling research loop and answer control
The orchestrator is a Groq tool-calling LLM node. It invokes search_chunks, tracks deduplicated retrieval evidence and citations, and loops until it can answer. Routing in rag_agent/edges.py distinguishes clarification, tool execution, and completion. Configured iteration/tool-call caps are an important safety boundary: when reached, the LLM is invoked without tools to synthesize only from gathered evidence.
Paths: rag_agent/nodes.py, rag_agent/edges.py, rag_agent/prompts.py
User interface, observability, and evaluation
ui/streamlit_chat.py streams final tokens and renders the generated Sources: footer, while supporting PDF upload. core/execution_logger.py provides optional node/tool tracing. RAGAS runs curated sample-document questions against the live agent and uses a separate smaller Groq judge model, producing evaluation CSVs.
Paths: ui/streamlit_chat.py, core/execution_logger.py, eval/run_ragas_eval.py
Main entry points: graph.py Compiled agent graph · rag_system.py RAG system bootstrap · nodes.py Agent nodes · streamlit_chat.py Chat and upload UI
Components 16
User Interface
- Streamlit entrypoint
app.py - Chat and upload UI · Streams answers and renders source citations.
ui/streamlit_chat.py
Document Ingestion
- Document manager · Adds, lists, and clears uploaded PDF documents.
core/document_manager.py - PDF Markdown chunker · Splits by headers then paragraph windows with header metadata.
ingestion/chunker.py - Hybrid vector store · Qdrant combines dense embeddings and BM25 sparse search.
ingestion/vector_store.py
RAG Agent
- Conversation state · Holds messages, rolling memory, evidence, and citations.
rag_agent/graph_state.py - Compiled agent graph · Runs preparation, clarification, research, and synthesis.
rag_agent/graph.py - Agent nodes · Summarizes history, analyzes queries, calls tools, and synthesizes answers.
rag_agent/nodes.py - Agent routing · Routes clarification, tool execution, and completion.
rag_agent/edges.py - Agent prompts
rag_agent/prompts.py - search_chunks tool · Returns contextual chunks for evidence and citations.
rag_agent/tools.py
Runtime & Evaluation
- RAG system bootstrap · Builds the LLM, retriever, and compiled agent.
core/rag_system.py - Runtime configuration · Defines models, chunking, and research limits.
config.py - Groq API key
.env.example - Execution tracing · Optionally traces agent nodes and tool calls.
core/execution_logger.py - RAGAS evaluation · Runs curated questions against the live agent and writes CSV results.
eval/run_ragas_eval.py
Connections 21
- Streamlit entrypoint → Chat and upload UI: launches UI
- Streamlit entrypoint → RAG system bootstrap: initializes
- Chat and upload UI → Document manager: uploads PDFs
- Chat and upload UI → Compiled agent graph: submits chat and resumes clarification
- Document manager → PDF Markdown chunker: converts and chunks
- PDF Markdown chunker → Hybrid vector store: indexes chunks
- RAG system bootstrap → Hybrid vector store: wires retriever
- RAG system bootstrap → Compiled agent graph: compiles
- Runtime configuration → RAG system bootstrap: model and limit settings
- Groq API key → RAG system bootstrap: Groq credentials
- Compiled agent graph → Conversation state: maintains
- Compiled agent graph → Agent nodes: executes
- Compiled agent graph → Agent routing: routes through
- Agent nodes → Agent prompts: uses
- Agent nodes → search_chunks tool: tool calls
- search_chunks tool → Hybrid vector store: hybrid search
- search_chunks tool → Conversation state: evidence and citations
- Agent nodes → Conversation state: updates memory and answer
- Execution tracing → Compiled agent graph: optional tracing
- RAGAS evaluation → Compiled agent graph: evaluates live agent
- RAGAS evaluation → Runtime configuration: uses separate judge model settings