How harishneel1/rag-for-beginners works
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 Ingestion · 2_retrieval_pipeline.py Retrieval · 9_retrieval_methods.py Retrieval methods · docs docs/
Components 15
Corpus
Local source documents and evaluation questions.
Core RAG Flow
Primary ingestion, retrieval, and generation path.
- Ingestion · Loads raw documents, preprocesses them, chunks them, and builds the indexed store.
1_ingestion_pipeline.py - Retrieval · Turns a user question into relevant context from the indexed knowledge base.
2_retrieval_pipeline.py - Generation · Consumes retrieved context and produces the final answer.
3_answer_generation.py - History aware · 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 · Baseline character-based document splitting approach.
5_recursive_character_text_spliiter.py - Semantic split · Chunks documents by meaning-aware boundaries.
6_semantic_chunking.py - Agentic split · Uses an agent-driven approach to decide chunk boundaries.
7_agentic_chunking.py
Search Variants
Retrieval optimizations and ranking experiments.
- Retrieval methods · Umbrella for alternative search and ranking techniques.
9_retrieval_methods.py - Multi-query · Generates multiple queries to improve recall.
10_multi_query_retrieval.py - RRF · Combines multiple retrieval result sets using reciprocal rank fusion.
11_reciprocal_rank_fusion.py - Hybrid search · Combines different retrieval signals in one search path.
12_hybrid_search.ipynb - Reranker · Re-scores retrieved candidates to improve final context selection.
13_reranker.ipynb
Multi-modal
Experimental branch beyond plain text.
- Multi-modal RAG · Experimental retrieval and reasoning path beyond plain text.
8_multi_modal_rag.ipynb
Connections 21
- 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.