# brenjoel/adaptive-agentic-rag architecture

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

- Interactive diagram: https://gitdiagram.com/brenjoel/adaptive-agentic-rag
- Repository: https://github.com/brenjoel/adaptive-agentic-rag

## Overview

Adaptive Agentic RAG routes a question to vector retrieval or web search, grades retrieved context, generates an answer, and checks grounding and usefulness before returning it or taking corrective action. The graph separates orchestration, workflow nodes, LLM decision/generation chains, and corpus retrieval. README documents local embeddings and Chroma; ingestion.py shows the configured retriever, but its example indexing operation is commented out. The workflow wiring is visible in graph.py; unsampled implementation details are not inferred.

Main entry points: [`graph/graph.py`](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/graph.py) (Graph Orchestrator), [`ingestion.py`](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/ingestion.py) (Corpus Preparation), [`graph/chains/answer_grader.py`](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/answer_grader.py) (Answer Grader), [`main.py`](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/main.py) (Application Entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application Entry"]
  node_main["Application Entry<br/>[main.py]"]
end

subgraph group_workflow["RAG Workflow"]
  node_orchestrator["Graph Orchestrator<br/>[graph.py]"]
  node_state["Workflow State<br/>[state.py]"]
  node_retrieve["Vector Retrieval<br/>[retrieve.py]"]
  node_document_grading["Document Grading<br/>[grade_document.py]"]
  node_web_search["Web Search Fallback<br/>[web_search.py]"]
  node_generate["Answer Generation<br/>[generate.py]"]
end

subgraph group_chains["LLM Chains"]
  node_router["Query Router<br/>[router.py]"]
  node_retrieval_grader["Relevance Grader"]
  node_generation_chain["Generation Chain<br/>[generation.py]"]
  node_hallucination_grader["Grounding Grader"]
  node_answer_grader["Answer Grader<br/>[answer_grader.py]"]
end

subgraph group_knowledge["Knowledge Sources"]
  node_retrieval_store[("Chroma Retriever<br/>[ingestion.py]")]
  node_ingestion["Corpus Preparation<br/>[ingestion.py]"]
end

node_user(("User"))
node_tavily{{"Tavily Search"}}
node_groq{{"Groq LLM"}}
node_ollama{{"Ollama Embeddings"}}
node_web_loader{{"Web Document Loader"}}

node_user -->|"asks question"| node_main
node_main -->|"loads graph"| node_orchestrator
node_orchestrator -->|"uses state"| node_state
node_orchestrator -->|"routes question"| node_router
node_orchestrator -->|"dispatches retrieval"| node_retrieve
node_orchestrator -->|"dispatches grading"| node_document_grading
node_orchestrator -->|"dispatches fallback"| node_web_search
node_orchestrator -->|"dispatches generation"| node_generate
node_orchestrator -->|"checks grounding"| node_hallucination_grader
node_orchestrator -->|"checks usefulness"| node_answer_grader
node_retrieve -->|"queries retriever"| node_retrieval_store
node_ingestion -->|"loads source pages"| node_web_loader
node_ingestion -->|"configures embeddings"| node_ollama
node_ingestion -->|"configures Chroma"| node_retrieval_store
node_document_grading -->|"grades documents"| node_retrieval_grader
node_web_search -->|"searches web"| node_tavily
node_generate -->|"builds answer"| node_generation_chain
node_generation_chain -->|"invokes model"| node_groq
node_retrieval_grader -.->|"scores relevance"| node_groq
node_hallucination_grader -.->|"scores grounding"| node_groq
node_answer_grader -->|"scores usefulness"| node_groq
node_router -->|"uses shared model"| node_answer_grader

click node_main "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/main.py"
click node_orchestrator "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/graph.py"
click node_state "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/state.py"
click node_router "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/router.py"
click node_retrieve "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/nodes/retrieve.py"
click node_retrieval_store "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/ingestion.py"
click node_ingestion "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/ingestion.py"
click node_document_grading "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/nodes/grade_document.py"
click node_retrieval_grader "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/retrieval_grader.py"
click node_web_search "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/nodes/web_search.py"
click node_generate "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/nodes/generate.py"
click node_generation_chain "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/generation.py"
click node_hallucination_grader "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/hallucination_grader.py"
click node_answer_grader "https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/answer_grader.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_main,node_user toneBlue
class node_orchestrator,node_state,node_retrieve,node_document_grading,node_web_search,node_generate toneAmber
class node_router,node_retrieval_grader,node_generation_chain,node_hallucination_grader,node_answer_grader toneMint
class node_retrieval_store,node_ingestion toneRose
class node_tavily,node_groq,node_ollama,node_web_loader toneIndigo
```

## Components

### Application Entry

- [Application Entry](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/main.py): `main.py`

### RAG Workflow

- [Graph Orchestrator](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/graph.py): `graph/graph.py`
- [Workflow State](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/state.py): `graph/state.py`
- [Vector Retrieval](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/nodes/retrieve.py): `graph/nodes/retrieve.py`
- [Document Grading](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/nodes/grade_document.py): `graph/nodes/grade_document.py`
- [Web Search Fallback](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/nodes/web_search.py): `graph/nodes/web_search.py`
- [Answer Generation](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/nodes/generate.py): `graph/nodes/generate.py`

### LLM Chains

- [Query Router](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/router.py): `graph/chains/router.py`
- [Relevance Grader](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/retrieval_grader.py): `graph/chains/retrieval_grader.py`
- [Generation Chain](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/generation.py): `graph/chains/generation.py`
- [Grounding Grader](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/hallucination_grader.py): `graph/chains/hallucination_grader.py`
- [Answer Grader](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/graph/chains/answer_grader.py): `graph/chains/answer_grader.py`

### Knowledge Sources

- [Chroma Retriever](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/ingestion.py): `ingestion.py`
- [Corpus Preparation](https://github.com/brenjoel/adaptive-agentic-rag/blob/master/ingestion.py): `ingestion.py`

### Other components

- **User**
- **Tavily Search**
- **Groq LLM**
- **Ollama Embeddings**
- **Web Document Loader**

## Connections

- User → Application Entry: asks question (evidence: `README.md`)
- Application Entry → Graph Orchestrator: loads graph (evidence: `main.py`)
- Graph Orchestrator → Workflow State: uses state (evidence: `graph/graph.py`)
- Graph Orchestrator → Query Router: routes question (evidence: `graph/graph.py`)
- Graph Orchestrator → Vector Retrieval: dispatches retrieval (evidence: `graph/graph.py`)
- Graph Orchestrator → Document Grading: dispatches grading (evidence: `graph/graph.py`)
- Graph Orchestrator → Web Search Fallback: dispatches fallback (evidence: `graph/graph.py`)
- Graph Orchestrator → Answer Generation: dispatches generation (evidence: `graph/graph.py`)
- Graph Orchestrator → Grounding Grader: checks grounding (evidence: `graph/graph.py`)
- Graph Orchestrator → Answer Grader: checks usefulness (evidence: `graph/graph.py`)
- Vector Retrieval → Chroma Retriever: queries retriever (evidence: `graph/nodes/retrieve.py`)
- Corpus Preparation → Web Document Loader: loads source pages (evidence: `ingestion.py`)
- Corpus Preparation → Ollama Embeddings: configures embeddings (evidence: `ingestion.py`)
- Corpus Preparation → Chroma Retriever: configures Chroma (evidence: `ingestion.py`)
- Document Grading → Relevance Grader: grades documents (evidence: `graph/nodes/grade_document.py`)
- Web Search Fallback → Tavily Search: searches web (evidence: `graph/nodes/web_search.py`)
- Answer Generation → Generation Chain: builds answer (evidence: `graph/nodes/generate.py`)
- Generation Chain → Groq LLM: invokes model (evidence: `graph/chains/generation.py`)
- Relevance Grader → Groq LLM: scores relevance
- Grounding Grader → Groq LLM: scores grounding
- Answer Grader → Groq LLM: scores usefulness (evidence: `graph/chains/answer_grader.py`)
- Query Router → Answer Grader: uses shared model (evidence: `graph/chains/router.py`)
