# saklaniabhimanyu/document-intelligence-rag architecture

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

- Interactive diagram: https://gitdiagram.com/saklaniabhimanyu/document-intelligence-rag
- Repository: https://github.com/saklaniabhimanyu/document-intelligence-rag

## Overview

This is a document Q&A application: users upload PDF, DOCX, or TXT files, which are cleaned and chunked, embedded into a FAISS index, and retrieved to ground generated answers with source citations. The app also supports retrieval tuning and a separate baseline-versus-optimised RAGAS evaluation workflow. The graph shows documented and excerpted calls; some evaluation capabilities are represented from the README and run-evaluation script, without assuming additional runtime wiring.

Main entry points: [`scripts/run_eval.py`](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/scripts/run_eval.py) (Evaluation runner), [`app.py`](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/app.py) (Upload and chat UI), [`src/qa_chain.py`](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/qa_chain.py) (QA chain and citations), [`src/retriever.py`](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/retriever.py) (Configurable retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_app["Upload and chat UI<br/>[app.py]"]
end

subgraph group_indexing["Document indexing"]
  node_ingestion["Load and chunk<br/>[ingestion.py]"]
  node_embedder["Embedding model"]
  node_embedding["Embed and index<br/>[embeddings.py]"]
  node_faiss[("FAISS vector index")]
end

subgraph group_answering["Grounded answering"]
  node_config["Pipeline configuration<br/>[config.py]"]
  node_retriever["Configurable retrieval<br/>[retriever.py]"]
  node_reranker["Cross-encoder reranker<br/>[retriever.py]"]
  node_qa["QA chain and citations<br/>[qa_chain.py]"]
  node_groq["Groq answer model"]
end

subgraph group_evaluation["Evaluation"]
  node_evalgen["Draft eval questions"]
  node_evalset["Evaluation dataset<br/>[eval_set.json]"]
  node_evalrunner["Evaluation runner<br/>[run_eval.py]"]
  node_evalmetrics["RAGAS scoring<br/>[evaluation.py]"]
  node_ragas["RAGAS evaluator"]
  node_judge["Groq judge model"]
  node_results["Metric comparison<br/>[comparison.csv]"]
end

node_user(("Document user"))

node_user -->|"uploads and asks"| node_app
node_app -->|"ingests uploads"| node_ingestion
node_app -->|"builds or updates"| node_embedding
node_embedding -->|"embeds chunks"| node_embedder
node_embedding -->|"builds and persists"| node_faiss
node_app -->|"configures retrieval"| node_retriever
node_retriever -->|"searches index"| node_faiss
node_retriever -->|"optionally reranks"| node_reranker
node_app -->|"builds and invokes"| node_qa
node_qa -->|"retrieves context"| node_retriever
node_qa -->|"generates answer"| node_groq
node_qa -->|"returns answer and citations"| node_app
node_app -->|"uses settings"| node_config
node_evalgen -->|"samples chunks"| node_faiss
node_evalgen -->|"drafts questions"| node_groq
node_evalgen -->|"writes questions"| node_evalset
node_evalrunner -->|"loads questions"| node_evalset
node_evalrunner -->|"builds evaluation corpora"| node_ingestion
node_evalrunner -->|"builds evaluation indexes"| node_embedding
node_evalrunner -->|"configures evaluation retrieval"| node_retriever
node_evalrunner -->|"runs question chains"| node_qa
node_evalrunner -->|"scores and compares"| node_evalmetrics
node_evalmetrics -->|"computes quality metrics"| node_ragas
node_evalrunner -->|"configures judge"| node_judge
node_evalrunner -->|"saves comparison"| node_results

click node_app "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/app.py"
click node_config "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/config.py"
click node_ingestion "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/ingestion.py"
click node_embedding "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/embeddings.py"
click node_retriever "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/retriever.py"
click node_reranker "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/retriever.py"
click node_qa "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/qa_chain.py"
click node_evalgen "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/scripts/generate_eval_dataset.py"
click node_evalset "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/data/eval_set.json"
click node_evalrunner "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/scripts/run_eval.py"
click node_evalmetrics "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/evaluation.py"
click node_results "https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/eval_results/comparison.csv"

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_user toneBlue
class node_ingestion,node_embedder,node_embedding,node_faiss toneAmber
class node_config,node_retriever,node_reranker,node_qa,node_groq toneMint
class node_evalgen,node_evalset,node_evalrunner,node_evalmetrics,node_ragas,node_judge,node_results toneRose
```

## Components

### User interface

- [Upload and chat UI](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/app.py): `app.py`

### Document indexing

- [Load and chunk](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/ingestion.py): `src/ingestion.py`
- **Embedding model**
- [Embed and index](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/embeddings.py): `src/embeddings.py`
- **FAISS vector index**

### Grounded answering

- [Pipeline configuration](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/config.py): `src/config.py`
- [Configurable retrieval](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/retriever.py): `src/retriever.py`
- [Cross-encoder reranker](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/retriever.py): `src/retriever.py`
- [QA chain and citations](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/qa_chain.py): `src/qa_chain.py`
- **Groq answer model**

### Evaluation

- [Draft eval questions](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/scripts/generate_eval_dataset.py): `scripts/generate_eval_dataset.py`
- [Evaluation dataset](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/data/eval_set.json): `data/eval_set.json`
- [Evaluation runner](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/scripts/run_eval.py): `scripts/run_eval.py`
- [RAGAS scoring](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/src/evaluation.py): `src/evaluation.py`
- **RAGAS evaluator**
- **Groq judge model**
- [Metric comparison](https://github.com/saklaniabhimanyu/document-intelligence-rag/blob/main/eval_results/comparison.csv): `eval_results/comparison.csv`

### Other components

- **Document user**

## Connections

- Document user → Upload and chat UI: uploads and asks (evidence: `README.md`)
- Upload and chat UI → Load and chunk: ingests uploads (evidence: `app.py`)
- Upload and chat UI → Embed and index: builds or updates (evidence: `app.py`)
- Embed and index → Embedding model: embeds chunks (evidence: `src/embeddings.py`)
- Embed and index → FAISS vector index: builds and persists (evidence: `src/embeddings.py`)
- Upload and chat UI → Configurable retrieval: configures retrieval (evidence: `app.py`)
- Configurable retrieval → FAISS vector index: searches index (evidence: `src/retriever.py`)
- Configurable retrieval → Cross-encoder reranker: optionally reranks (evidence: `src/retriever.py`)
- Upload and chat UI → QA chain and citations: builds and invokes (evidence: `app.py`)
- QA chain and citations → Configurable retrieval: retrieves context (evidence: `README.md`)
- QA chain and citations → Groq answer model: generates answer (evidence: `README.md`)
- QA chain and citations → Upload and chat UI: returns answer and citations (evidence: `app.py`)
- Upload and chat UI → Pipeline configuration: uses settings (evidence: `app.py`)
- Draft eval questions → FAISS vector index: samples chunks (evidence: `scripts/generate_eval_dataset.py`)
- Draft eval questions → Groq answer model: drafts questions (evidence: `scripts/generate_eval_dataset.py`)
- Draft eval questions → Evaluation dataset: writes questions (evidence: `README.md`)
- Evaluation runner → Evaluation dataset: loads questions (evidence: `scripts/run_eval.py`)
- Evaluation runner → Load and chunk: builds evaluation corpora (evidence: `scripts/run_eval.py`)
- Evaluation runner → Embed and index: builds evaluation indexes (evidence: `scripts/run_eval.py`)
- Evaluation runner → Configurable retrieval: configures evaluation retrieval (evidence: `scripts/run_eval.py`)
- Evaluation runner → QA chain and citations: runs question chains (evidence: `scripts/run_eval.py`)
- Evaluation runner → RAGAS scoring: scores and compares (evidence: `scripts/run_eval.py`)
- RAGAS scoring → RAGAS evaluator: computes quality metrics (evidence: `src/evaluation.py`)
- Evaluation runner → Groq judge model: configures judge (evidence: `scripts/run_eval.py`)
- Evaluation runner → Metric comparison: saves comparison (evidence: `README.md`)
