# abhilasha-mangal/rag-from-scratch architecture

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

- Interactive diagram: https://gitdiagram.com/abhilasha-mangal/rag-from-scratch
- Repository: https://github.com/abhilasha-mangal/rag-from-scratch

## Overview

This is a runnable, modular RAG application. Users index local files or URLs, then ask questions and receive generated answers with source chunks. Its main path extracts documents, chunks and embeds them, stores vectors, retrieves context, builds a prompt, and calls an LLM. The README also documents alternative stores and retrieval strategies, evaluation, and advanced RAG techniques. Some subsystem links rely on README documentation because their implementation was not sampled.

Main entry points: [`08_full_pipeline/pipeline.py`](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/08_full_pipeline/pipeline.py) (RAG Pipeline), [`05_retrieval/retriever.py`](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/05_retrieval/retriever.py) (Retrieval Strategies), [`07_llm_integration/llm_client.py`](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/07_llm_integration/llm_client.py) (LLM Client), [`04_vector_db/chroma/chroma_store.py`](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/04_vector_db/chroma/chroma_store.py) (Chroma Store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Document Ingestion"]
  node_loader["Document Loader<br/>[loader.py]"]
  node_document_model["Document Model<br/>[models.py]"]
  node_chunker["Chunking Strategies<br/>[chunker.py]"]
  node_chunk_model["Chunk Model<br/>[models.py]"]
end

subgraph group_index["Indexing and Search"]
  node_embedder["Embeddings<br/>[embedder.py]"]
  node_chroma[("Chroma Store<br/>[chroma_store.py]")]
  node_redis[("Redis Store<br/>[redis_store.py]")]
  node_db_comparison["Store Comparison<br/>[compare_dbs.py]"]
  node_retriever["Retrieval Strategies<br/>[retriever.py]"]
  node_advanced["Advanced RAG<br/>[advanced_rag.py]"]
end

subgraph group_answer["Answer Generation"]
  node_prompt["Prompt Builder<br/>[prompt_builder.py]"]
  node_llm["LLM Client<br/>[llm_client.py]"]
end

subgraph group_product["Application and Quality"]
  node_pipeline["RAG Pipeline<br/>[pipeline.py]"]
  node_app["Gradio App<br/>[app.py]"]
  node_evaluation["RAG Evaluation<br/>[evaluator.py]"]
  node_config["Configuration<br/>[config.yaml]"]
end

node_user(("User"))
node_documents["Documents"]
node_providers{{"LLM Providers"}}
node_answer_result["Answer and Sources"]

node_user -->|"uploads and asks"| node_app
node_documents -->|"extracts"| node_loader
node_loader -->|"creates"| node_document_model
node_pipeline -->|"loads documents"| node_loader
node_pipeline -->|"chunks documents"| node_chunker
node_chunker -->|"creates"| node_chunk_model
node_pipeline -->|"embeds chunks"| node_embedder
node_pipeline -->|"stores vectors"| node_chroma
node_pipeline -.->|"stores vectors"| node_redis
node_pipeline -->|"retrieves context"| node_retriever
node_retriever -->|"embeds query"| node_embedder
node_retriever -->|"queries vectors"| node_chroma
node_retriever -.->|"queries vectors"| node_redis
node_db_comparison -->|"benchmarks"| node_chroma
node_db_comparison -->|"benchmarks"| node_redis
node_pipeline -->|"formats messages"| node_prompt
node_prompt -->|"provides messages"| node_llm
node_pipeline -->|"generates answer"| node_llm
node_llm -->|"calls provider"| node_providers
node_pipeline -->|"configures stages"| node_config
node_app -->|"indexes and answers"| node_pipeline
node_pipeline -->|"returns answer and sources"| node_answer_result
node_evaluation -.->|"evaluates outputs"| node_pipeline
node_advanced -->|"generates query variants"| node_llm
node_advanced -->|"embeds expanded queries"| node_embedder
node_advanced -.->|"searches store"| node_chroma

click node_loader "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/01_document_loading/loader.py"
click node_document_model "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/src/models.py"
click node_chunker "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/02_chunking/chunker.py"
click node_chunk_model "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/src/models.py"
click node_embedder "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/03_embeddings/embedder.py"
click node_chroma "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/04_vector_db/chroma/chroma_store.py"
click node_redis "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/04_vector_db/redis/redis_store.py"
click node_db_comparison "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/04_vector_db/compare_dbs.py"
click node_retriever "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/05_retrieval/retriever.py"
click node_advanced "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/10_advanced/advanced_rag.py"
click node_prompt "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/06_prompting/prompt_builder.py"
click node_llm "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/07_llm_integration/llm_client.py"
click node_pipeline "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/08_full_pipeline/pipeline.py"
click node_app "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/08_full_pipeline/app.py"
click node_evaluation "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/09_evaluation/evaluator.py"
click node_config "https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/config.yaml"

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_loader,node_document_model,node_chunker,node_chunk_model,node_user toneBlue
class node_embedder,node_chroma,node_redis,node_db_comparison,node_retriever,node_advanced toneAmber
class node_prompt,node_llm toneMint
class node_pipeline,node_app,node_evaluation,node_config toneRose
class node_documents,node_providers,node_answer_result toneIndigo
```

## Components

### Document Ingestion

- [Document Loader](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/01_document_loading/loader.py): `01_document_loading/loader.py`
- [Document Model](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/src/models.py): `src/models.py`
- [Chunking Strategies](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/02_chunking/chunker.py): `02_chunking/chunker.py`
- [Chunk Model](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/src/models.py): `src/models.py`

### Indexing and Search

- [Embeddings](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/03_embeddings/embedder.py): `03_embeddings/embedder.py`
- [Chroma Store](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/04_vector_db/chroma/chroma_store.py): `04_vector_db/chroma/chroma_store.py`
- [Redis Store](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/04_vector_db/redis/redis_store.py): `04_vector_db/redis/redis_store.py`
- [Store Comparison](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/04_vector_db/compare_dbs.py): `04_vector_db/compare_dbs.py`
- [Retrieval Strategies](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/05_retrieval/retriever.py): `05_retrieval/retriever.py`
- [Advanced RAG](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/10_advanced/advanced_rag.py): `10_advanced/advanced_rag.py`

### Answer Generation

- [Prompt Builder](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/06_prompting/prompt_builder.py): `06_prompting/prompt_builder.py`
- [LLM Client](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/07_llm_integration/llm_client.py): `07_llm_integration/llm_client.py`

### Application and Quality

- [RAG Pipeline](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/08_full_pipeline/pipeline.py): `08_full_pipeline/pipeline.py`
- [Gradio App](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/08_full_pipeline/app.py): `08_full_pipeline/app.py`
- [RAG Evaluation](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/09_evaluation/evaluator.py): `09_evaluation/evaluator.py`
- [Configuration](https://github.com/abhilasha-mangal/rag-from-scratch/blob/main/config.yaml): `config.yaml`

### Other components

- **User**
- **Documents**
- **LLM Providers**
- **Answer and Sources**

## Connections

- User → Gradio App: uploads and asks (evidence: `README.md`)
- Documents → Document Loader: extracts (evidence: `README.md`)
- Document Loader → Document Model: creates (evidence: `01_document_loading/loader.py`)
- RAG Pipeline → Document Loader: loads documents (evidence: `08_full_pipeline/pipeline.py`)
- RAG Pipeline → Chunking Strategies: chunks documents (evidence: `08_full_pipeline/pipeline.py`)
- Chunking Strategies → Chunk Model: creates (evidence: `02_chunking/chunker.py`)
- RAG Pipeline → Embeddings: embeds chunks (evidence: `README.md`)
- RAG Pipeline → Chroma Store: stores vectors (evidence: `README.md`)
- RAG Pipeline → Redis Store: stores vectors (evidence: `08_full_pipeline/pipeline.py`)
- RAG Pipeline → Retrieval Strategies: retrieves context (evidence: `08_full_pipeline/pipeline.py`)
- Retrieval Strategies → Embeddings: embeds query (evidence: `05_retrieval/retriever.py`)
- Retrieval Strategies → Chroma Store: queries vectors (evidence: `05_retrieval/retriever.py`)
- Retrieval Strategies → Redis Store: queries vectors (evidence: `README.md`)
- Store Comparison → Chroma Store: benchmarks (evidence: `README.md`)
- Store Comparison → Redis Store: benchmarks (evidence: `README.md`)
- RAG Pipeline → Prompt Builder: formats messages (evidence: `08_full_pipeline/pipeline.py`)
- Prompt Builder → LLM Client: provides messages
- RAG Pipeline → LLM Client: generates answer (evidence: `08_full_pipeline/pipeline.py`)
- LLM Client → LLM Providers: calls provider (evidence: `07_llm_integration/llm_client.py`)
- RAG Pipeline → Configuration: configures stages (evidence: `README.md`)
- Gradio App → RAG Pipeline: indexes and answers (evidence: `08_full_pipeline/app.py`)
- RAG Pipeline → Answer and Sources: returns answer and sources (evidence: `README.md`)
- RAG Evaluation → RAG Pipeline: evaluates outputs (evidence: `README.md`)
- Advanced RAG → LLM Client: generates query variants (evidence: `10_advanced/advanced_rag.py`)
- Advanced RAG → Embeddings: embeds expanded queries (evidence: `10_advanced/advanced_rag.py`)
- Advanced RAG → Chroma Store: searches store (evidence: `10_advanced/advanced_rag.py`)
