RAG Techniques
A community-driven collection of 41 runnable Jupyter notebooks teaching Retrieval-Augmented Generation (RAG), from foundational retrieval and chunking through adaptive, agentic, graph-based and self-correcting systems. Each notebook is self-contained: the intuition behind one technique, a full implementation, and the paper or source it derives from. This is a teaching repository rather than a library, so there is no package to install and no public API. Authored by Nir Diamant. Licensed under a custom non-commercial license.
Core Documents
- README: Overview, the full technique index, prerequisites and quick start.
- CONTRIBUTING: How to add a technique and the pull request checklist.
- AGENTS: Repository conventions for AI coding agents.
- helper_functions.py: Shared loaders, splitters and retrieval utilities imported across notebooks.
- LICENSE: Custom non-commercial license. Read before any commercial reuse.
Foundational RAG
- Simple RAG: The baseline pipeline. Load, chunk, embed, retrieve, generate.
- Simple RAG with LlamaIndex: The same baseline built on LlamaIndex.
- Simple CSV RAG: Retrieval over tabular CSV data.
- Simple CSV RAG with LlamaIndex: The CSV baseline on LlamaIndex.
- Local RAG with Hugging Face and FAISS: A fully local pipeline with no hosted API calls.
- Choose Chunk Size: How chunk size changes retrieval quality, and how to pick one.
Chunking and Indexing
- Semantic Chunking: Split on meaning shifts rather than fixed character counts.
- Proposition Chunking: Decompose text into standalone factual propositions before indexing.
- Contextual Chunk Headers: Prepend document and section context to each chunk so it survives retrieval alone.
- Hierarchical Indices: Two-tier retrieval. Summaries first, then the chunks beneath the winning summary.
- RAPTOR: Recursive clustering and summarization into a tree, retrieved at multiple levels of abstraction.
- Document Augmentation: Generate questions each chunk answers, and index those alongside the text.
- Context Enrichment Window: Retrieve a chunk, then return its neighbours for continuity.
- Context Enrichment Window with LlamaIndex: The same window technique on LlamaIndex.
Query Transformation
- Query Transformations: Rewrite, expand and decompose a query before retrieving.
- HyDE: Embed a hypothetical answer instead of the question, then retrieve against it.
- HyPE: Move the hypothetical step to index time by embedding generated prompts.
Retrieval Strategies
- Fusion Retrieval: Combine keyword (BM25) and vector retrieval, then fuse the ranked lists.
- Fusion Retrieval with LlamaIndex: Hybrid fusion on LlamaIndex.
- Reranking: Over-retrieve, then reorder with a cross-encoder or LLM judge.
- Reranking with LlamaIndex: Reranking on LlamaIndex.
- Multi-Faceted Filtering: Metadata, similarity, diversity and relevance filters applied together.
- Dartboard: Optimize retrieval for relevance and diversity jointly rather than top-k similarity.
- Relevant Segment Extraction: Assemble contiguous multi-chunk segments instead of isolated chunks.
- Contextual Compression: Compress retrieved context down to the parts that answer the question.
- Adaptive Retrieval: Classify the query type and route it to a matching retrieval strategy.
- Explainable Retrieval: Return why each result was retrieved alongside the result.
Iterative and Self-Correcting RAG
- Self-RAG: The model decides when to retrieve, and critiques its own retrieved evidence.
- CRAG: Corrective RAG. Grade retrieved documents and fall back to web search when they are weak.
- Reliable RAG: Validation and hallucination checks layered over a standard pipeline.
- Retrieval with Feedback Loop: Learn from user feedback to improve future retrieval.
- Agentic RAG: An agent plans, retrieves, reflects and retries across multiple steps.
- MemoRAG: A global memory over the corpus that guides retrieval.
Graph RAG
- Graph RAG: Build a knowledge graph from documents and traverse it to answer multi-hop questions.
- Graph RAG with Local Attribution: Graph traversal that keeps span-level source attribution.
- Microsoft GraphRAG: Microsoft's community-detection approach to graph retrieval.
- GraphRAG with Milvus: Graph retrieval backed by the Milvus vector database.
- LightRAG: A lighter graph-and-vector hybrid.
Structured and Multimodal
- JSON RAG: Retrieval over structured JSON documents.
- Multimodal RAG with Captioning: Caption images so they become retrievable text.
- Multimodal RAG with ColPali: Retrieve document pages visually, without an OCR step.
Evaluation
- Define Evaluation Metrics: What to measure. Faithfulness, relevance, context precision and recall.
- End-to-End RAG Evaluation: Evaluating a full pipeline rather than retrieval alone.
- DeepEval: Evaluation with the DeepEval framework.
- Grouse: Evaluation with the Grouse framework.
- evalute_rag.py: Reusable evaluation harness.
Related work by the same author
- RAG Made Simple: The book that extends this repository. A 400-page visual guide to RAG.
- GenAI_Agents: Tutorials for building GenAI agents, from single bots to multi-agent systems.
- agents-towards-production: Taking agents from prototype to deployed product.
- Agent_Memory_Techniques: 30 notebooks on memory for LLM agents.
- Newsletter: Weekly deep dives on GenAI engineering.
- Community Discord: Questions, contributions and discussion.