# premsagariit/langgraph-rag architecture

> Architecture diagram of the GitHub repository premsagariit/langgraph-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/premsagariit/langgraph-rag
- Repository: https://github.com/premsagariit/langgraph-rag

## Overview

#### 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: [`rag_agent/graph.py`](https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/graph.py) (Compiled agent graph), [`core/rag_system.py`](https://github.com/premsagariit/langgraph-rag/blob/main/core/rag_system.py) (RAG system bootstrap), [`rag_agent/nodes.py`](https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/nodes.py) (Agent nodes), [`ui/streamlit_chat.py`](https://github.com/premsagariit/langgraph-rag/blob/main/ui/streamlit_chat.py) (Chat and upload UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["User Interface"]
  node_app["Streamlit entrypoint<br/>application entry<br/>[app.py]"]
  node_chat_ui["Chat and upload UI<br/>Streamlit UI<br/>[streamlit_chat.py]"]
end

subgraph group_ingestion["Document Ingestion"]
  node_document_manager["Document manager<br/>corpus manager"]
  node_chunker["PDF Markdown chunker<br/>ingestion pipeline<br/>[chunker.py]"]
  node_vector_store[("Hybrid vector store<br/>retrieval service<br/>[vector_store.py]")]
end

subgraph group_agent["RAG Agent"]
  node_graph_state["Conversation state<br/>LangGraph state<br/>[graph_state.py]"]
  node_agent_graph["Compiled agent graph<br/>LangGraph workflow<br/>[graph.py]"]
  node_agent_nodes["Agent nodes<br/>LLM orchestration<br/>[nodes.py]"]
  node_agent_edges["Agent routing<br/>workflow routing<br/>[edges.py]"]
  node_prompts["Agent prompts<br/>prompt policy<br/>[prompts.py]"]
  node_search_tool["search_chunks tool<br/>retrieval tool<br/>[tools.py]"]
end

subgraph group_runtime["Runtime &amp; Evaluation"]
  node_rag_system["RAG system bootstrap<br/>composition root<br/>[rag_system.py]"]
  node_config["Runtime configuration<br/>settings<br/>[config.py]"]
  node_env["Groq API key<br/>runtime secret<br/>[.env.example]"]
  node_execution_logger["Execution tracing<br/>observability"]
  node_ragas_eval["RAGAS evaluation<br/>batch evaluator<br/>[run_ragas_eval.py]"]
end

node_app -->|"launches UI"| node_chat_ui
node_app -->|"initializes"| node_rag_system
node_chat_ui -->|"uploads PDFs"| node_document_manager
node_chat_ui -->|"submits chat and resumes clarification"| node_agent_graph
node_document_manager -->|"converts and chunks"| node_chunker
node_chunker -->|"indexes chunks"| node_vector_store
node_rag_system -->|"wires retriever"| node_vector_store
node_rag_system -->|"compiles"| node_agent_graph
node_config -.->|"model and limit settings"| node_rag_system
node_env -.->|"Groq credentials"| node_rag_system
node_agent_graph -->|"maintains"| node_graph_state
node_agent_graph -->|"executes"| node_agent_nodes
node_agent_graph -->|"routes through"| node_agent_edges
node_agent_nodes -->|"uses"| node_prompts
node_agent_nodes -->|"tool calls"| node_search_tool
node_search_tool -->|"hybrid search"| node_vector_store
node_search_tool -->|"evidence and citations"| node_graph_state
node_agent_nodes -->|"updates memory and answer"| node_graph_state
node_execution_logger -.->|"optional tracing"| node_agent_graph
node_ragas_eval -->|"evaluates live agent"| node_agent_graph
node_ragas_eval -.->|"uses separate judge model settings"| node_config

click node_app "https://github.com/premsagariit/langgraph-rag/blob/main/app.py"
click node_chat_ui "https://github.com/premsagariit/langgraph-rag/blob/main/ui/streamlit_chat.py"
click node_rag_system "https://github.com/premsagariit/langgraph-rag/blob/main/core/rag_system.py"
click node_config "https://github.com/premsagariit/langgraph-rag/blob/main/config.py"
click node_env "https://github.com/premsagariit/langgraph-rag/blob/main/.env.example"
click node_document_manager "https://github.com/premsagariit/langgraph-rag/blob/main/core/document_manager.py"
click node_chunker "https://github.com/premsagariit/langgraph-rag/blob/main/ingestion/chunker.py"
click node_vector_store "https://github.com/premsagariit/langgraph-rag/blob/main/ingestion/vector_store.py"
click node_graph_state "https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/graph_state.py"
click node_agent_graph "https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/graph.py"
click node_agent_nodes "https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/nodes.py"
click node_agent_edges "https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/edges.py"
click node_prompts "https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/prompts.py"
click node_search_tool "https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/tools.py"
click node_execution_logger "https://github.com/premsagariit/langgraph-rag/blob/main/core/execution_logger.py"
click node_ragas_eval "https://github.com/premsagariit/langgraph-rag/blob/main/eval/run_ragas_eval.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_chat_ui toneBlue
class node_document_manager,node_chunker,node_vector_store toneAmber
class node_graph_state,node_agent_graph,node_agent_nodes,node_agent_edges,node_prompts,node_search_tool toneMint
class node_rag_system,node_config,node_env,node_execution_logger,node_ragas_eval toneRose
```

## Components

### User Interface

- [Streamlit entrypoint](https://github.com/premsagariit/langgraph-rag/blob/main/app.py): application entry · `app.py`
- [Chat and upload UI](https://github.com/premsagariit/langgraph-rag/blob/main/ui/streamlit_chat.py): Streamlit UI · Streams answers and renders source citations. · `ui/streamlit_chat.py`

### Document Ingestion

- [Document manager](https://github.com/premsagariit/langgraph-rag/blob/main/core/document_manager.py): corpus manager · Adds, lists, and clears uploaded PDF documents. · `core/document_manager.py`
- [PDF Markdown chunker](https://github.com/premsagariit/langgraph-rag/blob/main/ingestion/chunker.py): ingestion pipeline · Splits by headers then paragraph windows with header metadata. · `ingestion/chunker.py`
- [Hybrid vector store](https://github.com/premsagariit/langgraph-rag/blob/main/ingestion/vector_store.py): retrieval service · Qdrant combines dense embeddings and BM25 sparse search. · `ingestion/vector_store.py`

### RAG Agent

- [Conversation state](https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/graph_state.py): LangGraph state · Holds messages, rolling memory, evidence, and citations. · `rag_agent/graph_state.py`
- [Compiled agent graph](https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/graph.py): LangGraph workflow · Runs preparation, clarification, research, and synthesis. · `rag_agent/graph.py`
- [Agent nodes](https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/nodes.py): LLM orchestration · Summarizes history, analyzes queries, calls tools, and synthesizes answers. · `rag_agent/nodes.py`
- [Agent routing](https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/edges.py): workflow routing · Routes clarification, tool execution, and completion. · `rag_agent/edges.py`
- [Agent prompts](https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/prompts.py): prompt policy · `rag_agent/prompts.py`
- [search_chunks tool](https://github.com/premsagariit/langgraph-rag/blob/main/rag_agent/tools.py): retrieval tool · Returns contextual chunks for evidence and citations. · `rag_agent/tools.py`

### Runtime & Evaluation

- [RAG system bootstrap](https://github.com/premsagariit/langgraph-rag/blob/main/core/rag_system.py): composition root · Builds the LLM, retriever, and compiled agent. · `core/rag_system.py`
- [Runtime configuration](https://github.com/premsagariit/langgraph-rag/blob/main/config.py): settings · Defines models, chunking, and research limits. · `config.py`
- [Groq API key](https://github.com/premsagariit/langgraph-rag/blob/main/.env.example): runtime secret · `.env.example`
- [Execution tracing](https://github.com/premsagariit/langgraph-rag/blob/main/core/execution_logger.py): observability · Optionally traces agent nodes and tool calls. · `core/execution_logger.py`
- [RAGAS evaluation](https://github.com/premsagariit/langgraph-rag/blob/main/eval/run_ragas_eval.py): batch evaluator · Runs curated questions against the live agent and writes CSV results. · `eval/run_ragas_eval.py`

## Connections

- 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
