# manojkesani/mrag architecture

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

- Interactive diagram: https://gitdiagram.com/manojkesani/mrag
- Repository: https://github.com/manojkesani/mrag

## Overview

M-RAG ingests PDFs, images, and text into searchable vectors, then answers questions through an iterative retrieval-and-assessment agent with citations. The main user workflow is upload/query through the Streamlit UI and FastAPI, followed by ingestion or RAG execution and a returned result. The graph preserves documented ingestion and agent stages plus their helper layers. Some subsystems are represented from README documentation and the SOURCE INDEX; unsampled implementation details and unverified links are omitted or marked dashed.

Main entry points: [`ingestion/nodes.py`](https://github.com/manojkesani/mrag/blob/main/ingestion/nodes.py) (Ingestion Nodes), [`rag/nodes.py`](https://github.com/manojkesani/mrag/blob/main/rag/nodes.py) (Agent Nodes), [`ingestion/graph.py`](https://github.com/manojkesani/mrag/blob/main/ingestion/graph.py) (Ingestion Graph), [`api/main.py`](https://github.com/manojkesani/mrag/blob/main/api/main.py) (FastAPI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_ui["Streamlit UI<br/>[app.py]"]
  node_api["FastAPI<br/>[main.py]"]
  node_rag_api["Query Router<br/>[rag_router.py]"]
  node_cli["CLI<br/>[main.py]"]
end

subgraph group_ingest["Ingestion Pipeline"]
  node_ing_graph["Ingestion Graph<br/>[graph.py]"]
  node_ing_nodes["Ingestion Nodes<br/>[nodes.py]"]
  node_loaders["File Loaders"]
  node_image_desc["Image Describer<br/>[image_describer.py]"]
  node_chunkers["Chunking Strategies"]
  node_embedders["Embedding Models"]
  node_elements["Content Elements<br/>[elements.py]"]
end

subgraph group_rag["Agentic Retrieval"]
  node_rag_graph["RAG Graph<br/>[graph.py]"]
  node_rag_nodes["Agent Nodes<br/>[nodes.py]"]
  node_strategies["Query Strategies<br/>[strategies.py]"]
  node_retriever["Multi-Query Retriever<br/>[retriever.py]"]
  node_reranker["Reranker<br/>[reranker.py]"]
  node_notepad["Agent Notepad<br/>[notepad.py]"]
end

subgraph group_services["Storage and Models"]
  node_qdrant_storer["Qdrant Storer<br/>[qdrant.py]"]
  node_qdrant[("Qdrant")]
  node_postgres[("PostgreSQL")]
  node_llm{{"Groq LLM"}}
  node_langfuse{{"Langfuse"}}
end

node_user(("User"))

node_user -->|"uses"| node_ui
node_ui -->|"uploads and queries"| node_api
node_user -->|"runs commands"| node_cli
node_cli -->|"runs ingestion"| node_ing_graph
node_api -->|"starts ingestion"| node_ing_graph
node_api -->|"routes queries"| node_rag_api
node_rag_api -->|"runs query"| node_rag_graph
node_ing_graph -->|"dispatches stages"| node_ing_nodes
node_ing_nodes -->|"loads files"| node_loaders
node_ing_nodes -->|"describes images"| node_image_desc
node_ing_nodes -->|"chunks content"| node_chunkers
node_ing_nodes -->|"embeds content"| node_embedders
node_ing_nodes -->|"stores vectors"| node_qdrant_storer
node_qdrant_storer -->|"writes vectors"| node_qdrant
node_ing_nodes -->|"processes elements"| node_elements
node_rag_graph -->|"dispatches stages"| node_rag_nodes
node_rag_nodes -->|"transforms queries"| node_strategies
node_rag_nodes -->|"probes and retrieves"| node_retriever
node_retriever -->|"embeds queries"| node_embedders
node_retriever -->|"searches vectors"| node_qdrant
node_rag_nodes -->|"reranks results"| node_reranker
node_rag_nodes -->|"updates memory"| node_notepad
node_rag_nodes -->|"plans and answers"| node_llm
node_ing_graph -->|"describes images"| node_llm
node_ing_graph -->|"stores metadata"| node_postgres
node_ing_graph -.->|"traces runs"| node_langfuse
node_rag_graph -.->|"traces runs"| node_langfuse

click node_ui "https://github.com/manojkesani/mrag/blob/main/frontend/app.py"
click node_api "https://github.com/manojkesani/mrag/blob/main/api/main.py"
click node_rag_api "https://github.com/manojkesani/mrag/blob/main/api/rag_router.py"
click node_cli "https://github.com/manojkesani/mrag/blob/main/cli/main.py"
click node_ing_graph "https://github.com/manojkesani/mrag/blob/main/ingestion/graph.py"
click node_ing_nodes "https://github.com/manojkesani/mrag/blob/main/ingestion/nodes.py"
click node_loaders "https://github.com/manojkesani/mrag/tree/main/core/loaders"
click node_image_desc "https://github.com/manojkesani/mrag/blob/main/core/processors/image_describer.py"
click node_chunkers "https://github.com/manojkesani/mrag/tree/main/core/chunkers"
click node_embedders "https://github.com/manojkesani/mrag/tree/main/core/embedders"
click node_elements "https://github.com/manojkesani/mrag/blob/main/core/elements.py"
click node_rag_graph "https://github.com/manojkesani/mrag/blob/main/rag/graph.py"
click node_rag_nodes "https://github.com/manojkesani/mrag/blob/main/rag/nodes.py"
click node_strategies "https://github.com/manojkesani/mrag/blob/main/rag/strategies.py"
click node_retriever "https://github.com/manojkesani/mrag/blob/main/rag/retriever.py"
click node_reranker "https://github.com/manojkesani/mrag/blob/main/rag/reranker.py"
click node_notepad "https://github.com/manojkesani/mrag/blob/main/rag/notepad.py"
click node_qdrant_storer "https://github.com/manojkesani/mrag/blob/main/core/storers/qdrant.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_ui,node_api,node_rag_api,node_cli,node_user toneBlue
class node_ing_graph,node_ing_nodes,node_loaders,node_image_desc,node_chunkers,node_embedders,node_elements toneAmber
class node_rag_graph,node_rag_nodes,node_strategies,node_retriever,node_reranker,node_notepad toneMint
class node_qdrant_storer,node_qdrant,node_postgres,node_llm,node_langfuse toneRose
```

## Components

### User Interfaces

- [Streamlit UI](https://github.com/manojkesani/mrag/blob/main/frontend/app.py): `frontend/app.py`
- [FastAPI](https://github.com/manojkesani/mrag/blob/main/api/main.py): `api/main.py`
- [Query Router](https://github.com/manojkesani/mrag/blob/main/api/rag_router.py): `api/rag_router.py`
- [CLI](https://github.com/manojkesani/mrag/blob/main/cli/main.py): `cli/main.py`

### Ingestion Pipeline

- [Ingestion Graph](https://github.com/manojkesani/mrag/blob/main/ingestion/graph.py): `ingestion/graph.py`
- [Ingestion Nodes](https://github.com/manojkesani/mrag/blob/main/ingestion/nodes.py): `ingestion/nodes.py`
- [File Loaders](https://github.com/manojkesani/mrag/tree/main/core/loaders): `core/loaders`
- [Image Describer](https://github.com/manojkesani/mrag/blob/main/core/processors/image_describer.py): `core/processors/image_describer.py`
- [Chunking Strategies](https://github.com/manojkesani/mrag/tree/main/core/chunkers): `core/chunkers`
- [Embedding Models](https://github.com/manojkesani/mrag/tree/main/core/embedders): `core/embedders`
- [Content Elements](https://github.com/manojkesani/mrag/blob/main/core/elements.py): `core/elements.py`

### Agentic Retrieval

- [RAG Graph](https://github.com/manojkesani/mrag/blob/main/rag/graph.py): `rag/graph.py`
- [Agent Nodes](https://github.com/manojkesani/mrag/blob/main/rag/nodes.py): `rag/nodes.py`
- [Query Strategies](https://github.com/manojkesani/mrag/blob/main/rag/strategies.py): `rag/strategies.py`
- [Multi-Query Retriever](https://github.com/manojkesani/mrag/blob/main/rag/retriever.py): `rag/retriever.py`
- [Reranker](https://github.com/manojkesani/mrag/blob/main/rag/reranker.py): `rag/reranker.py`
- [Agent Notepad](https://github.com/manojkesani/mrag/blob/main/rag/notepad.py): `rag/notepad.py`

### Storage and Models

- [Qdrant Storer](https://github.com/manojkesani/mrag/blob/main/core/storers/qdrant.py): `core/storers/qdrant.py`
- **Qdrant**
- **PostgreSQL**
- **Groq LLM**
- **Langfuse**

### Other components

- **User**

## Connections

- User → Streamlit UI: uses (evidence: `README.md`)
- Streamlit UI → FastAPI: uploads and queries (evidence: `README.md`)
- User → CLI: runs commands (evidence: `README.md`)
- CLI → Ingestion Graph: runs ingestion (evidence: `cli/main.py`)
- FastAPI → Ingestion Graph: starts ingestion (evidence: `api/main.py`)
- FastAPI → Query Router: routes queries (evidence: `api/main.py`)
- Query Router → RAG Graph: runs query (evidence: `api/rag_router.py`)
- Ingestion Graph → Ingestion Nodes: dispatches stages (evidence: `ingestion/graph.py`)
- Ingestion Nodes → File Loaders: loads files (evidence: `ingestion/nodes.py`)
- Ingestion Nodes → Image Describer: describes images (evidence: `ingestion/nodes.py`)
- Ingestion Nodes → Chunking Strategies: chunks content (evidence: `ingestion/nodes.py`)
- Ingestion Nodes → Embedding Models: embeds content (evidence: `ingestion/nodes.py`)
- Ingestion Nodes → Qdrant Storer: stores vectors (evidence: `ingestion/nodes.py`)
- Qdrant Storer → Qdrant: writes vectors (evidence: `README.md`)
- Ingestion Nodes → Content Elements: processes elements (evidence: `ingestion/nodes.py`)
- RAG Graph → Agent Nodes: dispatches stages (evidence: `rag/graph.py`)
- Agent Nodes → Query Strategies: transforms queries (evidence: `rag/nodes.py`)
- Agent Nodes → Multi-Query Retriever: probes and retrieves (evidence: `rag/nodes.py`)
- Multi-Query Retriever → Embedding Models: embeds queries (evidence: `rag/retriever.py`)
- Multi-Query Retriever → Qdrant: searches vectors (evidence: `README.md`)
- Agent Nodes → Reranker: reranks results (evidence: `rag/nodes.py`)
- Agent Nodes → Agent Notepad: updates memory (evidence: `rag/nodes.py`)
- Agent Nodes → Groq LLM: plans and answers (evidence: `README.md`)
- Ingestion Graph → Groq LLM: describes images (evidence: `README.md`)
- Ingestion Graph → PostgreSQL: stores metadata (evidence: `README.md`)
- Ingestion Graph → Langfuse: traces runs (evidence: `README.md`)
- RAG Graph → Langfuse: traces runs (evidence: `README.md`)
