# harishneel1/rag-for-beginners architecture

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

- Interactive diagram: https://gitdiagram.com/harishneel1/rag-for-beginners
- Repository: https://github.com/harishneel1/rag-for-beginners

## Overview

1. **What this repo is:** a tutorial-style RAG playground, not a single deployed application. The numbered scripts/notebooks walk through the RAG stack stage by stage, with each file demonstrating one architectural variant or optimization.

2. **Source corpus boundary:** the `docs/` folder is the local knowledge base. It contains several text documents (`Google.txt`, `Microsoft.txt`, `Nvidia.txt`, `SpaceX.txt`, `Tesla.txt`) plus `attention-is-all-you-need.pdf`, which together form the retrieval corpus.

3. **Evaluation/input artifacts:** `synthetic_questions.txt` appears to be a test set for probing retrieval and answer quality. This gives the repo a lightweight evaluation loop: corpus in `docs/`, questions in `synthetic_questions.txt`, and the RAG pipeline in the numbered scripts.

4. **Ingestion stage:** `1_ingestion_pipeline.py` is the entry point for turning raw documents into an indexed knowledge base. Architecturally, this is where document loading, preprocessing, chunk creation, and whatever storage/indexing layer is used are introduced.

5. **Chunking strategies as a separate subsystem:** `5_recursive_character_text_spliiter.py`, `6_semantic_chunking.py`, and `7_agentic_chunking.py` isolate alternative ways of splitting source documents into retrievable units. These are important because they sit between raw documents and the retrieval index, and the repo clearly treats chunking as a tunable boundary.

6. **Baseline retrieval path:** `2_retrieval_pipeline.py` is the query-to-context stage. It likely takes a user question, searches the indexed chunks, and returns the most relevant passages for downstream use.

7. **Answer synthesis:** `3_answer_generation.py` is the generation layer that consumes retrieved context and produces the final response. In architecture terms, this is the handoff from retrieval into LLM-based synthesis.

8. **Conversational extension:** `4_history_aware_generation.py` adds chat-state awareness. This is a separate boundary from plain retrieval: the system must incorporate previous turns, usually by rewriting or contextualizing the current query before retrieval/generation.

9. **Retrieval-enhancement experiments:** `9_retrieval_methods.py`, `10_multi_query_retrieval.py`, `11_reciprocal_rank_fusion.py`, `12_hybrid_search.ipynb`, and `13_reranker.ipynb` form a cluster of advanced retrieval variants. Together they represent the “search layer” optimization space: query expansion, result fusion, combining lexical and vector search, and reranking retrieved candidates.

10. **Multi-modal branch:** `8_multi_modal_rag.ipynb` is a separate experimental path for retrieving or reasoning over more than plain text. It sits beside the text-only RAG flow rather than inside it.

11. **Repo shape and execution model:** the project is notebook/script driven, with no visible web server, queue, or database service in the tree. The architecture is therefore local and modular: source docs and question sets in the filesystem, processing/retrieval/generation in standalone Python files, and exploratory variants in notebooks.

12. **How to draw it:** the main diagram should show a pipeline from `docs/` and `synthetic_questions.txt` into ingestion/chunking, then into retrieval/indexing, then into answer generation, with optional branches for history awareness, advanced retrieval techniques, and multi-modal processing.

Main entry points: [`1_ingestion_pipeline.py`](https://github.com/harishneel1/rag-for-beginners/blob/main/1_ingestion_pipeline.py) (Ingestion), [`2_retrieval_pipeline.py`](https://github.com/harishneel1/rag-for-beginners/blob/main/2_retrieval_pipeline.py) (Retrieval), [`9_retrieval_methods.py`](https://github.com/harishneel1/rag-for-beginners/blob/main/9_retrieval_methods.py) (Retrieval methods), [`docs`](https://github.com/harishneel1/rag-for-beginners/tree/main/docs) (docs/)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_corpus["Corpus"]
  node_docs_corpus[("docs/<br/>source corpus")]
  node_synthetic_questions["Questions<br/>eval set"]
end

subgraph group_group_core["Core RAG Flow"]
  node_ingestion_pipeline["Ingestion<br/>pipeline"]
  node_retrieval_pipeline["Retrieval<br/>query stage"]
  node_answer_generation["Generation<br/>LLM synthesis"]
  node_history_aware["History aware<br/>chat extension"]
end

subgraph group_group_chunking["Chunking"]
  node_recursive_chunking["Recursive split<br/>chunking strategy"]
  node_semantic_chunking["Semantic split<br/>chunking strategy"]
  node_agentic_chunking["Agentic split<br/>chunking strategy"]
end

subgraph group_group_search["Search Variants"]
  node_retrieval_methods["Retrieval methods<br/>search experiments"]
  node_multi_query["Multi-query<br/>query expansion"]
  node_rrf["RRF<br/>result fusion"]
  node_hybrid_search["Hybrid search<br/>lexical+vector"]
  node_reranker["Reranker<br/>candidate ranking<br/>[13_reranker.ipynb]"]
end

subgraph group_group_multimodal["Multi-modal"]
  node_multimodal_rag["Multi-modal RAG<br/>multimodal branch"]
end

node_docs_corpus -->|"source docs"| node_ingestion_pipeline
node_ingestion_pipeline -->|"index"| node_retrieval_pipeline
node_retrieval_pipeline -->|"context"| node_answer_generation
node_synthetic_questions -->|"queries"| node_retrieval_pipeline
node_synthetic_questions -->|"prompts"| node_answer_generation
node_docs_corpus -->|"raw text"| node_recursive_chunking
node_docs_corpus -->|"raw text"| node_semantic_chunking
node_docs_corpus -->|"raw text"| node_agentic_chunking
node_recursive_chunking -->|"chunks"| node_ingestion_pipeline
node_semantic_chunking -->|"chunks"| node_ingestion_pipeline
node_agentic_chunking -->|"chunks"| node_ingestion_pipeline
node_retrieval_methods -->|"search layer"| node_retrieval_pipeline
node_multi_query -->|"variant"| node_retrieval_methods
node_rrf -->|"variant"| node_retrieval_methods
node_hybrid_search -->|"variant"| node_retrieval_methods
node_reranker -->|"variant"| node_retrieval_methods
node_history_aware -->|"contextualize"| node_retrieval_pipeline
node_history_aware -->|"dialogue context"| node_answer_generation
node_multimodal_rag -.->|"alternate inputs"| node_ingestion_pipeline
node_multimodal_rag -.->|"alternate retrieval"| node_retrieval_pipeline
node_multimodal_rag -.->|"alternate synthesis"| node_answer_generation

click node_docs_corpus "https://github.com/harishneel1/rag-for-beginners/tree/main/docs"
click node_synthetic_questions "https://github.com/harishneel1/rag-for-beginners/blob/main/synthetic_questions.txt"
click node_ingestion_pipeline "https://github.com/harishneel1/rag-for-beginners/blob/main/1_ingestion_pipeline.py"
click node_retrieval_pipeline "https://github.com/harishneel1/rag-for-beginners/blob/main/2_retrieval_pipeline.py"
click node_answer_generation "https://github.com/harishneel1/rag-for-beginners/blob/main/3_answer_generation.py"
click node_history_aware "https://github.com/harishneel1/rag-for-beginners/blob/main/4_history_aware_generation.py"
click node_recursive_chunking "https://github.com/harishneel1/rag-for-beginners/blob/main/5_recursive_character_text_spliiter.py"
click node_semantic_chunking "https://github.com/harishneel1/rag-for-beginners/blob/main/6_semantic_chunking.py"
click node_agentic_chunking "https://github.com/harishneel1/rag-for-beginners/blob/main/7_agentic_chunking.py"
click node_retrieval_methods "https://github.com/harishneel1/rag-for-beginners/blob/main/9_retrieval_methods.py"
click node_multi_query "https://github.com/harishneel1/rag-for-beginners/blob/main/10_multi_query_retrieval.py"
click node_rrf "https://github.com/harishneel1/rag-for-beginners/blob/main/11_reciprocal_rank_fusion.py"
click node_hybrid_search "https://github.com/harishneel1/rag-for-beginners/blob/main/12_hybrid_search.ipynb"
click node_reranker "https://github.com/harishneel1/rag-for-beginners/blob/main/13_reranker.ipynb"
click node_multimodal_rag "https://github.com/harishneel1/rag-for-beginners/blob/main/8_multi_modal_rag.ipynb"

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_docs_corpus,node_synthetic_questions toneBlue
class node_ingestion_pipeline,node_retrieval_pipeline,node_answer_generation,node_history_aware toneAmber
class node_recursive_chunking,node_semantic_chunking,node_agentic_chunking toneMint
class node_retrieval_methods,node_multi_query,node_rrf,node_hybrid_search,node_reranker toneRose
class node_multimodal_rag toneIndigo
```

## Components

### Corpus

Local source documents and evaluation questions.

- [docs/](https://github.com/harishneel1/rag-for-beginners/tree/main/docs): source corpus · Local knowledge base used for retrieval: company text files and a PDF. · `docs`
- [Questions](https://github.com/harishneel1/rag-for-beginners/blob/main/synthetic_questions.txt): eval set · Synthetic prompts used to probe retrieval and answer quality. · `synthetic_questions.txt`

### Core RAG Flow

Primary ingestion, retrieval, and generation path.

- [Ingestion](https://github.com/harishneel1/rag-for-beginners/blob/main/1_ingestion_pipeline.py): pipeline · Loads raw documents, preprocesses them, chunks them, and builds the indexed store. · `1_ingestion_pipeline.py`
- [Retrieval](https://github.com/harishneel1/rag-for-beginners/blob/main/2_retrieval_pipeline.py): query stage · Turns a user question into relevant context from the indexed knowledge base. · `2_retrieval_pipeline.py`
- [Generation](https://github.com/harishneel1/rag-for-beginners/blob/main/3_answer_generation.py): LLM synthesis · Consumes retrieved context and produces the final answer. · `3_answer_generation.py`
- [History aware](https://github.com/harishneel1/rag-for-beginners/blob/main/4_history_aware_generation.py): chat extension · Adds conversation state so the current query is contextualized before retrieval or generation. · `4_history_aware_generation.py`

### Chunking

Alternative document splitting strategies.

- [Recursive split](https://github.com/harishneel1/rag-for-beginners/blob/main/5_recursive_character_text_spliiter.py): chunking strategy · Baseline character-based document splitting approach. · `5_recursive_character_text_spliiter.py`
- [Semantic split](https://github.com/harishneel1/rag-for-beginners/blob/main/6_semantic_chunking.py): chunking strategy · Chunks documents by meaning-aware boundaries. · `6_semantic_chunking.py`
- [Agentic split](https://github.com/harishneel1/rag-for-beginners/blob/main/7_agentic_chunking.py): chunking strategy · Uses an agent-driven approach to decide chunk boundaries. · `7_agentic_chunking.py`

### Search Variants

Retrieval optimizations and ranking experiments.

- [Retrieval methods](https://github.com/harishneel1/rag-for-beginners/blob/main/9_retrieval_methods.py): search experiments · Umbrella for alternative search and ranking techniques. · `9_retrieval_methods.py`
- [Multi-query](https://github.com/harishneel1/rag-for-beginners/blob/main/10_multi_query_retrieval.py): query expansion · Generates multiple queries to improve recall. · `10_multi_query_retrieval.py`
- [RRF](https://github.com/harishneel1/rag-for-beginners/blob/main/11_reciprocal_rank_fusion.py): result fusion · Combines multiple retrieval result sets using reciprocal rank fusion. · `11_reciprocal_rank_fusion.py`
- [Hybrid search](https://github.com/harishneel1/rag-for-beginners/blob/main/12_hybrid_search.ipynb): lexical+vector · Combines different retrieval signals in one search path. · `12_hybrid_search.ipynb`
- [Reranker](https://github.com/harishneel1/rag-for-beginners/blob/main/13_reranker.ipynb): candidate ranking · Re-scores retrieved candidates to improve final context selection. · `13_reranker.ipynb`

### Multi-modal

Experimental branch beyond plain text.

- [Multi-modal RAG](https://github.com/harishneel1/rag-for-beginners/blob/main/8_multi_modal_rag.ipynb): multimodal branch · Experimental retrieval and reasoning path beyond plain text. · `8_multi_modal_rag.ipynb`

## Connections

- docs/ → Ingestion: source docs · Raw documents feed the ingestion pipeline.
- Ingestion → Retrieval: index · Ingested chunks become the retrievable knowledge base.
- Retrieval → Generation: context · Retrieved passages are passed to generation.
- Questions → Retrieval: queries · Evaluation questions probe the retrieval stage.
- Questions → Generation: prompts · Questions can also be used to assess final responses.
- docs/ → Recursive split: raw text · Chunking strategies operate over the same source corpus.
- docs/ → Semantic split: raw text · Chunking strategies operate over the same source corpus.
- docs/ → Agentic split: raw text · Chunking strategies operate over the same source corpus.
- Recursive split → Ingestion: chunks · One possible chunking boundary for indexing.
- Semantic split → Ingestion: chunks · Alternative semantic chunking boundary for indexing.
- Agentic split → Ingestion: chunks · Alternative agent-driven chunking boundary for indexing.
- Retrieval methods → Retrieval: search layer · Shared retrieval experiments extend the base query-to-context stage.
- Multi-query → Retrieval methods: variant · Multi-query expansion is one retrieval optimization.
- RRF → Retrieval methods: variant · Reciprocal rank fusion is one retrieval optimization.
- Hybrid search → Retrieval methods: variant · Hybrid lexical/vector search is one retrieval optimization.
- Reranker → Retrieval methods: variant · Reranking is one retrieval optimization.
- History aware → Retrieval: contextualize · Conversation history reshapes the retrieval query.
- History aware → Generation: dialogue context · Conversation state also influences synthesis.
- Multi-modal RAG → Ingestion: alternate inputs · Multi-modal experiments sit beside the text pipeline.
- Multi-modal RAG → Retrieval: alternate retrieval · Experimental multi-modal retrieval path.
- Multi-modal RAG → Generation: alternate synthesis · Experimental multi-modal answer generation path.
