正在加载项目…
正在加载项目…
This repository showcases various advanced techniques for Retrieval-Augmented Generation (RAG) systems. Each technique has a detailed notebook tutorial.
正在读取官方项目说明…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
A community-driven hub of 42+ runnable notebooks covering RAG techniques from foundational to cutting-edge - the intuition, the code, and the references to build more accurate, context-rich retrieval systems.
Prompt to Production - my full course on building software with AI the way professionals do: the methods and paradigms behind reliable, efficient, modular production systems, taught systematically. 17 modules, each pairing a video lecture with a hands-on lab, from your first structured prompt to a working production system.
The course is live. Every module is out, lecture and lab.
Your coding agent starts every session knowing nothing about your project, so it guesses. Paste one line into the agent you already have open, and about fifteen minutes later your repository has a docs layer written from the code itself, plus a card scoring what your agent knew before and after.
We ran it on six repositories you already depend on. Each one was asked five questions about itself, cold, then again after the layer was written. The last column counts statements in that project's own documentation that its own code disproves:
| repo | before | after | own docs its code disproves |
|---|---|---|---|
| fastapi | 2 of 5 | 5 of 5 | 2 |
| flask | 3 of 5 | 5 of 5 | 6 |
| django | 3 of 5 | 4 of 5 | 1 |
| express | 2 of 5 | 4 of 5 | 4 |
| requests | 2 of 5 | 4 of 5 | 0 |
| langchain | 5 of 5 | 4 of 5 | 5 |
Flask's six include four documentation examples that raise TypeError when you run them. Langchain scored lower afterwards, because it already ships a 380-line agent instruction file and the cold read was grading theirs; that row is in the table anyway.
Clone any of those repos, paste the same line, and check the number yourself. No signup.
We gratefully acknowledge the organizations and individuals who have made significant contributions to this project.
Company Sponsors
Individual Sponsors
| 🚀 Cutting-edge Updates | 💡 Expert Insights | 🎯 Top 0.1% Content |
Join over 50,000 AI enthusiasts getting unique cutting-edge insights and free tutorials! Plus, subscribers get exclusive early access and special 33% discounts to my book and the upcoming RAG Techniques course!
I break these ideas down into short, one-idea-per-episode explainers on YouTube.
🆕 AI Is Rewarded for Guessing [Hallucination]
why a model guesses instead of saying I don't know, watched on its own token probabilities, and where retrieval moves the fact out of the guess
RAG Explained: Why AI Gets Your Own Documents Wrong why chunks overlap, what "meaning space" is, and where simple RAG breaks down |
How Do You Search a Spreadsheet by Meaning? turn each row into one labelled line and search the table by meaning |
How Do You Know Your RAG Answer Isn't Made Up? three checkpoints that catch a bad chunk on the way in and an unsupported claim on the way out |
Retrieval-Augmented Generation (RAG) is revolutionizing the way we combine information retrieval with generative AI. This repository showcases a curated collection of advanced techniques designed to supercharge your RAG systems, enabling them to deliver more accurate, contextually relevant, and comprehensive responses.
Our goal is to provide a valuable resource for researchers and practitioners looking to push the boundaries of what's possible with RAG. By fostering a collaborative environment, we aim to accelerate innovation in this exciting field.
RAG Made Simple - the 400-page visual companion to this repo. Amazon Bestseller in Generative AI · 1,500+ readers · ⭐ 4.6
Get it on Amazon (paperback · Kindle · free on Kindle Unlimited) → · Read Chapter 1 free
🚀 Agents Towards Production - code-first tutorials for shipping production-grade GenAI agents, prototype to scale.
🤖 GenAI Agents - a broad collection of AI agent implementations and tutorials.
🖋️ Prompt Engineering Techniques - prompting strategies from basics to advanced.
🧠 Agent Memory Techniques - 30 notebooks on agent memory: vector stores, knowledge graphs, Mem0, MemGPT, Zep, Graphiti.
Contributions make this better - propose ideas, share techniques, or give feedback via CONTRIBUTING.md.
r/EducationalAI · Discord · LinkedIn
Explore our extensive list of cutting-edge RAG techniques:
Recently added: MemoRAG (memory-augmented retrieval), End-to-End RAG Evaluation, Open-RAG-Eval, JSON RAG. 42 notebooks and growing.
| # | Category | Technique | View |
|---|---|---|---|
| 1 | Foundational 🌱 | Basic RAG | |
| 2 | Foundational 🌱 | RAG with CSV Files | |
| 3 | Foundational 🌱 | Reliable RAG |
Simple RAG 🌱
Introducing basic RAG techniques ideal for newcomers.
Start with basic retrieval queries and integrate incremental learning mechanisms.
Simple RAG using a CSV file 🧩
Query Transformations 🔄
Modifying and expanding queries to improve retrieval effectiveness.
Hypothetical Questions (HyDE Approach) ❓
Hypothetical Prompt Embeddings (HyPE) ❓🚀
HyPE (Hypothetical Prompt Embeddings) is an enhancement to traditional RAG retrieval that precomputes hypothetical prompts at the indexing stage, but inseting the chunk in their place. This transforms retrieval into a question-question matching task. This avoids the need for runtime synthetic answer generation, reducing inference-time computational overhead while improving retrieval alignment.
Enhancing retrieval accuracy by embedding individual sentences and extending context to neighboring sentences.
Retrieve the most relevant sentence while also accessing the sentences before and after it in the original text.
Dividing documents based on semantic coherence rather than fixed sizes.
Use NLP techniques to identify topic boundaries or coherent sections within documents for more meaningful retrieval units.
Compressing retrieved information while preserving query-relevant content.
Use an LLM to compress or summarize retrieved chunks, preserving key information relevant to the query.
This implementation demonstrates a text augmentation technique that leverages additional question generation to improve document retrieval within a vector database. By generating and incorporating various questions related to each text fragment, the system enhances the standard retrieval process, thus increasing the likelihood of finding relevant documents that can be utilized as context for generative question answering.
Use an LLM to augment text dataset with all possible questions that can be asked to each document.
Fusion Retrieval 🔗
Optimizing search results by combining different retrieval methods.
Combine keyword-based search with vector-based search for more comprehensive and accurate retrieval.
Intelligent Reranking 📈
Retrieval with Feedback Loops 🔁
Implementing mechanisms to learn from user interactions and improve future retrievals.
Collect and utilize user feedback on the relevance and quality of retrieved documents and generated responses to fine-tune retrieval and ranking models.
Adaptive Retrieval 🎯
Dynamically adjusting retrieval strategies based on query types and user contexts.
Classify queries into different categories and use tailored retrieval strategies for each, considering user context and preferences.
DeepEval Evaluation:
| Comprehensive RAG system evaluation |
Performing evaluations Retrieval-Augmented Generation systems, by covering several metrics and creating test cases.
Use the deepeval library to conduct test cases on correctness, faithfulness and contextual relevancy of RAG systems.
GroUSE Evaluation:
| Contextually-grounded LLM evaluation |
Evaluate the final stage of Retrieval-Augmented Generation using metrics of the GroUSE framework and meta-evaluate your custom LLM judge on GroUSE unit tests.
Use the grouse package to evaluate contextually-grounded LLM generations with GPT-4 on the 6 metrics of the GroUSE framework and use unit tests to evaluate a custom Llama 3.1 405B evaluator.
End-to-End RAG Evaluation:
| Complete evaluation pipeline |
A comprehensive tutorial covering evaluation criteria selection, LLM-as-a-judge metrics, RAGAS integration, and full evaluation pipeline assembly.
MemoRAG:
| Memory-augmented retrieval |
A from-scratch implementation of MemoRAG - a memory-augmented RAG system with key-value pair extraction, surrogate query generation, and multi-query retrieval.
Explainable Retrieval 🔍
Providing transparency in the retrieval process to enhance user trust and system refinement.
Explain why certain pieces of information were retrieved and how they relate to the query.
Agentic RAG with Contextual AI 🤖
Building production-ready agentic RAG pipelines for financial document analysis with Contextual AI's managed platform. This comprehensive tutorial demonstrates how to leverage agentic RAG to solve complex queries through intelligent query reformulation, document parsing, reranking, and grounded language models.
Graph RAG with Milvus Vector Database 🔍
A simple yet powerful approach to implement Graph RAG using Milvus vector databases. This technique significantly improves performance on complex multi-hop questions by combining relationship-based retrieval with vector search and reranking.
Sophisticated Controllable Agent for Complex RAG Tasks 🤖
An advanced RAG solution designed to tackle complex questions that simple semantic similarity-based retrieval cannot solve. This approach uses a sophisticated deterministic graph as the "brain" 🧠 of a highly controllable autonomous agent, capable of answering non-trivial questions from your own data.
• Implement a multi-step process involving question anonymization, high-level planning, task breakdown, adaptive information retrieval and question answering, continuous re-planning, and rigorous answer verification to ensure grounded and accurate responses.
To begin implementing these advanced RAG techniques in your projects:
git clone https://github.com/NirDiamant/RAG_Techniques.git
cd all_rag_techniques/technique-name
This list contains Amazon affiliate links. As an Amazon Associate I earn from qualifying purchases. Every book below is one I've read and genuinely recommend to engineers working in this space. The companion book to this repo is featured separately at the top of this README.
🌟 Support This Project: Your sponsorship fuels innovation in RAG technologies. Become a sponsor to help maintain and expand this valuable resource!
Prompt Engineering: Master the Art of AI Interaction - the prompting foundation that makes RAG work better. Same visual approach, 22 hands-on techniques.
Run a course, newsletter, or dev community? You can earn 25% recommending RAG Made Simple to your audience.
We welcome contributions from the community! If you have a new technique or improvement to suggest:
git checkout -b feature/AmazingFeaturegit commit -m 'Add some AmazingFeature'git push origin feature/AmazingFeatureThis project is licensed under a custom non-commercial license - see the LICENSE file for details.
⭐️ If you find this repository helpful, please consider giving it a star!
Keywords: RAG, Retrieval-Augmented Generation, NLP, AI, Machine Learning, Information Retrieval, Natural Language Processing, LLM, Embeddings, Semantic Search, PydanticAI, Agent Frameworks

| 4 | Foundational 🌱 | Optimizing Chunk Sizes |
| 5 | Foundational 🌱 | Proposition Chunking |
| 6 | Query Enhancement 🔍 | Query Transformations |
| 7 | Query Enhancement 🔍 | HyDE (Hypothetical Document Embedding) |
| 8 | Query Enhancement 🔍 | HyPE (Hypothetical Prompt Embedding) |
| 9 | Context Enrichment 📚 | Contextual Chunk Headers |
| 10 | Context Enrichment 📚 | Relevant Segment Extraction |
| 11 | Context Enrichment 📚 | Context Window Enhancement |
| 12 | Context Enrichment 📚 | Semantic Chunking |
| 13 | Context Enrichment 📚 | Contextual Compression |
| 14 | Context Enrichment 📚 | Document Augmentation |
| 15 | Advanced Retrieval 🚀 | Fusion Retrieval |
| 16 | Advanced Retrieval 🚀 | Reranking |
| 17 | Advanced Retrieval 🚀 | Multi-faceted Filtering |
| 18 | Advanced Retrieval 🚀 | Hierarchical Indices |
| 19 | Advanced Retrieval 🚀 | Dartboard Retrieval |
| 20 | Advanced Retrieval 🚀 | Multi-modal RAG with Captioning |
| 21 | Iterative Techniques 🔁 | Retrieval with Feedback Loop |
| 22 | Iterative Techniques 🔁 | Adaptive Retrieval |
| 23 | Evaluation 📊 | DeepEval |
| 24 | Evaluation 📊 | GroUSE |
| 25 | Explainability 🔬 | Explainable Retrieval |
| 26 | Advanced Architecture 🏗️ | Graph RAG with LangChain |
| 27 | Advanced Architecture 🏗️ | Microsoft GraphRAG |
| 28 | Advanced Architecture 🏗️ | RAPTOR |
| 29 | Advanced Architecture 🏗️ | Agentic RAG with Contextual AI |
| 30 | Advanced Architecture 🏗️ | Self-RAG |
| 31 | Advanced Architecture 🏗️ | Corrective RAG (CRAG) |
| 32 | Advanced Architecture 🏗️ | Local Graph RAG with Verifiable Attribution |
| 33 | Advanced Architecture 🏗️ | LightRAG |
| 34 | Evaluation 📊 | End-to-End RAG Evaluation |
| 35 | Evaluation 📊 | Open-RAG-Eval |
| 36 | Advanced 🔬 | MemoRAG |
| 37 | Special Technique 🌟 | Sophisticated Controllable Agent |
Introducing basic RAG using CSV files.
This uses CSV files to create basic retrieval and integrates with openai to create question and answering system.
Enhances the Simple RAG by adding validation and refinement to ensure the accuracy and relevance of retrieved information.
Check for retrieved document relevancy and highlight the segment of docs used for answering.
Choose Chunk Size 📏
Selecting an appropriate fixed size for text chunks to balance context preservation and retrieval efficiency.
Experiment with different chunk sizes to find the optimal balance between preserving context and maintaining retrieval speed for your specific use case.
Breaking down the text into concise, complete, meaningful sentences allowing for better control and handling of specific queries (especially extracting knowledge).
RAG with JSON documents is a method of using JSON files to create a retrieval and question answering system.
Generating hypothetical questions to improve alignment between queries and data.
Create hypothetical questions that point to relevant locations in the data, enhancing query-data matching.
Contextual chunk headers (CCH) is a method of creating document-level and section-level context, and prepending those chunk headers to the chunks prior to embedding them.
Create a chunk header that includes context about the document and/or section of the document, and prepend that to each chunk in order to improve the retrieval accuracy.
dsRAG: open-source retrieval engine that implements this technique (and a few other advanced RAG techniques)
Relevant Segment Extraction 🧩:
Relevant segment extraction (RSE) is a method of dynamically constructing multi-chunk segments of text that are relevant to a given query.
Perform a retrieval post-processing step that analyzes the most relevant chunks and identifies longer multi-chunk segments to provide more complete context to the LLM.
Context Enrichment Techniques 📝
Applying advanced scoring mechanisms to improve the relevance ranking of retrieved results.
Multi-faceted Filtering 🔍
Applying various filtering techniques to refine and improve the quality of retrieved results.
Hierarchical Indices 🗂️
Creating a multi-tiered system for efficient information navigation and retrieval.
Implement a two-tiered system for document summaries and detailed chunks, both containing metadata pointing to the same location in the data.
Dartboard Retrieval 🎯
Optimizing over Relevant Information Gain in Retrieval
Multi-modal Retrieval 📽️
Extending RAG capabilities to handle diverse data types for richer responses.
Open-RAG-Eval:
| Open-source RAG evaluation |
Demonstrates the open-rag-eval library for evaluation using UMBRELA scoring, AutoNuggetizer, and citation/hallucination detection.
Knowledge Graph Integration (Graph RAG) 🕸️
Incorporating structured data from knowledge graphs to enrich context and improve retrieval.
Retrieve entities and their relationships from a knowledge graph relevant to the query, combining this structured data with unstructured text for more informative responses.
GraphRag (Microsoft) 🎯
Microsoft GraphRAG (Open Source) is an advanced RAG system that integrates knowledge graphs to improve the performance of LLMs
• Analyze an input corpus by extracting entities, relationships from text units. generates summaries of each community and its constituents from the bottom-up.
RAPTOR: Recursive Abstractive Processing for Tree-Organized Retrieval 🌳
Implementing a recursive approach to process and organize retrieved information in a tree structure.
Use abstractive summarization to recursively process and summarize retrieved documents, organizing the information in a tree structure for hierarchical context.
Self RAG 🔁
A dynamic approach that combines retrieval-based and generation-based methods, adaptively deciding whether to use retrieved information and how to best utilize it in generating responses.
• Implement a multi-step process including retrieval decision, document retrieval, relevance evaluation, response generation, support assessment, and utility evaluation to produce accurate, relevant, and useful outputs.
Corrective RAG 🔧
A sophisticated RAG approach that dynamically evaluates and corrects the retrieval process, combining vector databases, web search, and language models for highly accurate and context-aware responses.
• Integrate Retrieval Evaluator, Knowledge Refinement, Web Search Query Rewriter, and Response Generator components to create a system that adapts its information sourcing strategy based on relevance scores and combines multiple sources when necessary.
Local Graph RAG with Verifiable Attribution 🔗
A privacy-first Graph RAG implementation running entirely locally with Ollama. Uses NetworkX for multi-hop graph traversal and provides sentence-level attribution — every claim traces back to the exact source sentence, unlike Vector RAG's chunk-level attribution.
• Extract entities and relationships from documents using a local LLM, building a knowledge graph with full source provenance. Combine vector similarity search (entry points) with graph traversal (multi-hop expansion). Generate answers with inline citations that map each claim to its source document, sentence, and graph path.
LightRAG 💡
A simple and fast graph-based RAG that extracts an entity-relationship knowledge graph from the corpus and retrieves with a dual-level strategy (specific entities + high-level themes), supporting cheap incremental updates.
Extract entities and relationships per chunk into a merged knowledge graph, embed entity and relation profiles into two vector indexes, split the query into low-level and high-level keywords, then retrieve the matching entities and relations (plus their source chunks) to build the context.