่ฟ”ๅ›ž็›ฎๅฝ•
ๅผ€ๆบ้กน็›ฎๆธธๆˆๅผ€ๅ‘็ฑปๆ–ฐๆ‰‹

GitHub - NirDiamant/RAG_Techniques: This repository showcases various advanced techniques for Retrieval-Augmented Generation (RAG) systems.

Advanced RAG Techniques ๐Ÿš€ Elevating Your Retrieval-Augmented Generation Systems 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,

0 ๆฌก้˜…่ฏป2026/11/10 ๅ‘ๅธƒ
GitHub - NirDiamant/RAG_Techniques: This repository showcases various advanced techniques for Retrieval-Augmented Generation (RAG) systems. ๆฅๆบๅ›พ็‰‡

็คพๅŒบไฝœ่€… ยท zZz

ๅฎƒ่งฃๅ†ณไป€ไนˆ้—ฎ้ข˜

Advanced RAG Techniques ๐Ÿš€

Elevating Your Retrieval-Augmented Generation Systems

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.

๐ŸŽ“ From RAG prototypes to production

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.

๐ŸŽ Try it on your own repo, free

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.

๐Ÿ‘‰ Get the full course

Sponsors โค๏ธ

We gratefully acknowledge the organizations and individuals who have made significant contributions to this project.

Company Sponsors

Individual Sponsors

๐Ÿ“ซ Stay Updated!

๐Ÿš€ 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!

๐ŸŽฌ Prefer video?

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

Why Does RAG Return a Paragraph When You Asked for One Fact?

why a paragraph's embedding is a blend that points at nothing in particular

Browse every episode โ†’

Introduction

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.

๐Ÿ“– Go deeper: the book

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

Related Projects

๐Ÿš€ 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.

Join the community

Contributions make this better - propose ideas, share techniques, or give feedback via CONTRIBUTING.md .

r/EducationalAI ยท Discord ยท LinkedIn

Key Features

  • ๐Ÿง  State-of-the-art RAG enhancements
  • ๐Ÿ“š Comprehensive documentation for each technique
  • ๐Ÿ› ๏ธ Practical implementation guidelines
  • ๐ŸŒŸ Regular updates with the latest advancements

Advanced Techniques

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

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

๐ŸŒฑ Foundational RAG Techniques

- Simple RAG ๐ŸŒฑ

  • ๐ŸŽฌ Watch it explained : RAG Explained: Why AI Gets Your Own Documents Wrong โ€” the intuition behind this notebook in 7 minutes: why chunks overlap, what "meaning space" actually is, and where simple RAG breaks down.
  • LangChain :
  • LlamaIndex :
  • Runnable Script

Overview ๐Ÿ”Ž

Introducing basic RAG techniques ideal for newcomers.

Implementation ๐Ÿ› ๏ธ

Start with basic retrieval queries and integrate incremental learning mechanisms.

- Simple RAG using a CSV file ๐Ÿงฉ

  • ๐ŸŽฌ Watch it explained : How Do You Search a Spreadsheet by Meaning? โ€” turn each row into one labelled line and search the table by meaning ; ask which customers are "in South American countries" and the Chile record comes back even though those words never appear.
  • LangChain :
  • LlamaIndex :

Overview ๐Ÿ”Ž

Introducing basic RAG using CSV files.

Implementation ๐Ÿ› ๏ธ

This uses CSV files to create basic retrieval and integrates with openai to create question and answering system.

- Reliable RAG ๐Ÿท๏ธ :

  • ๐ŸŽฌ Watch it explained : How Do You Know Your RAG Answer Isn't Made Up? โ€” the three checkpoints that catch a bad chunk on the way in and an unsupported claim on the way out, plus the source highlighting that lets a skeptical reader verify the answer themselves.

Overview ๐Ÿ”Ž

Enhances the Simple RAG by adding validation and refinement to ensure the accuracy and relevance of retrieved information.

Implementation ๐Ÿ› ๏ธ

Check for retrieved document relevancy and highlight the segment of docs used for answering.

- Choose Chunk Size ๐Ÿ“

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Selecting an appropriate fixed size for text chunks to balance context preservation and retrieval efficiency.

Implementation ๐Ÿ› ๏ธ

Experiment with different chunk sizes to find the optimal balance between preserving context and maintaining retrieval speed for your specific use case.

- Proposition Chunking โ›“๏ธโ€๐Ÿ’ฅ :

  • ๐ŸŽฌ Watch it explained : Why Does RAG Return a Paragraph When You Asked for One Fact? โ€” why a paragraph's embedding is a blend that points at nothing in particular, how a language model rewrites the chunk as single self-contained facts, and what the quality gate throws away.

Overview ๐Ÿ”Ž

Breaking down the text into concise, complete, meaningful sentences allowing for better control and handling of specific queries (especially extracting knowledge).

Implementation ๐Ÿ› ๏ธ

  • ๐Ÿ’ช Proposition Generation: The LLM is used in conjunction with a custom prompt to generate factual statements from the document chunks.
  • โœ… Quality Checking: The generated propositions are passed through a grading system that evaluates accuracy, clarity, completeness, and conciseness.

- Simple RAG with JSON

Overview ๐Ÿ”Ž

RAG with JSON documents is a method of using JSON files to create a retrieval and question answering system.

Implementation ๐Ÿ› ๏ธ

  • ๐Ÿ“„ Data Loading & Extraction: JSON data with multiple fields per entry is loaded, and most relevant text fields are combined to generate an embedding.
  • ๐Ÿ” Retrieval: The system retrieves the most relevant JSON entries based on the user's query.

Additional Resources ๐Ÿ“š

  • The Propositions Method: Enhancing Information Retrieval for AI Systems - A comprehensive blog post exploring the benefits and implementation of proposition chunking in RAG systems.

๐Ÿ” Query Enhancement

- Query Transformations ๐Ÿ”„

  • LangChain :
  • Runnable Script
  • ๐ŸŽฌ Watch it explained : Why Does RAG Miss an Answer That's Right There in Your Documents? โ€” why the words in a question never quite line up with the words on the page, the three transformations (rewrite, step back, split) that fix the question instead of the index, and the rule that keeps the original question in charge of the answer.

Overview ๐Ÿ”Ž

Modifying and expanding queries to improve retrieval effectiveness.

Implementation ๐Ÿ› ๏ธ

  • โœ๏ธ Query Rewriting: Reformulate queries to improve retrieval.
  • ๐Ÿ”™ Step-back Prompting: Generate broader queries for better context retrieval.
  • ๐Ÿงฉ Sub-query Decomposition: Break complex queries into simpler sub-queries.

- Hypothetical Questions (HyDE Approach) โ“

  • LangChain :
  • Runnable Script
  • ๐ŸŽฌ Watch it explained : HyDE for RAG: Search With a Fake Answer to Find the Real One โ€” why a short question and a long document land far apart in embedding space even when they mean the same thing, why the made-up answer never has to be correct, and the two places the technique genuinely fails.

Overview ๐Ÿ”Ž

Generating hypothetical questions to improve alignment between queries and data.

Implementation ๐Ÿ› ๏ธ

Create hypothetical questions that point to relevant locations in the data, enhancing query-data matching.

Additional Resources ๐Ÿ“š

  • HyDE: Exploring Hypothetical Document Embeddings for AI Retrieval - A short blog post explaining this method clearly.

๐Ÿ“š Context and Content Enrichment

- Hypothetical Prompt Embeddings (HyPE) โ“๐Ÿš€

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

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 .

Implementation ๐Ÿ› ๏ธ

  • ๐Ÿ“– Precomputed Questions: Instead of embedding document chunks, HyPE generates multiple hypothetical queries per chunk at indexing time.
  • ๐Ÿ” Question-Question Matching: User queries are matched against stored hypothetical questions, leading to better retrieval alignment .
  • โšก No Runtime Overhead: Unlike HyDE, HyPE does not require LLM calls at query time , making retrieval faster and cheaper .
  • ๐Ÿ“ˆ Higher Precision & Recall: Improves retrieval context precision by up to 42 percentage points and claim recall by up to 45 percentage points .

Additional Resources ๐Ÿ“š

  • Preprint: Hypothetical Prompt Embeddings (HyPE) - Research paper detailing the method, evaluation, and benchmarks.

- Contextual Chunk Headers ๐Ÿท๏ธ :

  • ๐ŸŽฌ Watch it explained : Contextual Retrieval for RAG: Why Your Best Chunk Ranks Last โ€” why a chunk that is exactly on topic still ranks last, what the pronouns cost you the moment the paragraph leaves its document, and the one kind of knowledge base where this does nothing at all.

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

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.

Additional Resources ๐Ÿ“š

dsRAG : open-source retrieval engine that implements this technique (and a few other advanced RAG techniques)

- Relevant Segment Extraction ๐Ÿงฉ :

Overview ๐Ÿ”Ž

Relevant segment extraction (RSE) is a method of dynamically constructing multi-chunk segments of text that are relevant to a given query.

Implementation ๐Ÿ› ๏ธ

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 ๐Ÿ“

  • LangChain :
  • LlamaIndex :
  • Runnable Script

Overview ๐Ÿ”Ž

Enhancing retrieval accuracy by embedding individual sentences and extending context to neighboring sentences.

Implementation ๐Ÿ› ๏ธ

Retrieve the most relevant sentence while also accessing the sentences before and after it in the original text.

  • Semantic Chunking ๐Ÿง 
  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Dividing documents based on semantic coherence rather than fixed sizes.

Implementation ๐Ÿ› ๏ธ

Use NLP techniques to identify topic boundaries or coherent sections within documents for more meaningful retrieval units.

Additional Resources ๐Ÿ“š

  • Semantic Chunking: Improving AI Information Retrieval - A comprehensive blog post exploring the benefits and implementation of semantic chunking in RAG systems.
  • Contextual Compression ๐Ÿ—œ๏ธ
  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Compressing retrieved information while preserving query-relevant content.

Implementation ๐Ÿ› ๏ธ

Use an LLM to compress or summarize retrieved chunks, preserving key information relevant to the query.

  • Document Augmentation through Question Generation for Enhanced Retrieval
  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

Use an LLM to augment text dataset with all possible questions that can be asked to each document.

๐Ÿš€ Advanced Retrieval Methods

- Fusion Retrieval ๐Ÿ”—

  • LangChain :
  • LlamaIndex :
  • Runnable Script

Overview ๐Ÿ”Ž

Optimizing search results by combining different retrieval methods.

Implementation ๐Ÿ› ๏ธ

Combine keyword-based search with vector-based search for more comprehensive and accurate retrieval.

- Intelligent Reranking ๐Ÿ“ˆ

  • LangChain :
  • LlamaIndex :
  • Runnable Script

Overview ๐Ÿ”Ž

Applying advanced scoring mechanisms to improve the relevance ranking of retrieved results.

Implementation ๐Ÿ› ๏ธ

  • ๐Ÿง  LLM-based Scoring: Use a language model to score the relevance of each retrieved chunk.
  • ๐Ÿ”€ Cross-Encoder Models: Re-encode both the query and retrieved documents jointly for similarity scoring.
  • ๐Ÿ† Metadata-enhanced Ranking: Incorporate metadata into the scoring process for more nuanced ranking.

Additional Resources ๐Ÿ“š

  • Relevance Revolution: How Re-ranking Transforms RAG Systems - A comprehensive blog post exploring the power of re-ranking in enhancing RAG system performance.

- Multi-faceted Filtering ๐Ÿ”

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Applying various filtering techniques to refine and improve the quality of retrieved results.

Implementation ๐Ÿ› ๏ธ

  • ๐Ÿท๏ธ Metadata Filtering: Apply filters based on attributes like date, source, author, or document type.

๐Ÿ“Š Similarity Thresholds:

ๅฏๅคๅˆถๅ‘ฝไปค
Set thresholds for relevance scores to keep only the most pertinent results.
  • ๐Ÿ“„ Content Filtering: Remove results that don't match specific content criteria or essential keywords.
  • ๐ŸŒˆ Diversity Filtering: Ensure result diversity by filtering out near-duplicate entries.

- Hierarchical Indices ๐Ÿ—‚๏ธ

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Creating a multi-tiered system for efficient information navigation and retrieval.

Implementation ๐Ÿ› ๏ธ

Implement a two-tiered system for document summaries and detailed chunks, both containing metadata pointing to the same location in the data.

Additional Resources ๐Ÿ“š

  • Hierarchical Indices: Enhancing RAG Systems - A comprehensive blog post exploring the power of hierarchical indices in enhancing RAG system performance.

- Dartboard Retrieval ๐ŸŽฏ

  • LangChain :

Overview ๐Ÿ”Ž

Optimizing over Relevant Information Gain in Retrieval

Implementation ๐Ÿ› ๏ธ

  • Combine both relevance and diversity into a single scoring function and directly optimize for it.
  • POC showing plain simple RAG underperforming when the database is dense, and the dartboard retrieval outperforming it.

- Multi-modal Retrieval ๐Ÿ“ฝ๏ธ

Overview ๐Ÿ”Ž

Extending RAG capabilities to handle diverse data types for richer responses.

Implementation ๐Ÿ› ๏ธ

  • Multi-model RAG with Multimedia Captioning : - Caption and store all the other multimedia data like pdfs, ppts, etc., with text data in vector store and retrieve them together.
  • Multi-model RAG with Colpali : - Instead of captioning convert all the data into image, then find the most relevant images and pass them to a vision large language model.

๐Ÿ” Iterative and Adaptive Techniques

- Retrieval with Feedback Loops ๐Ÿ”

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Implementing mechanisms to learn from user interactions and improve future retrievals.

Implementation ๐Ÿ› ๏ธ

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 ๐ŸŽฏ

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Dynamically adjusting retrieval strategies based on query types and user contexts.

Implementation ๐Ÿ› ๏ธ

Classify queries into different categories and use tailored retrieval strategies for each, considering user context and preferences.

๐Ÿ“Š Evaluation

- DeepEval Evaluation : | Comprehensive RAG system evaluation |

Overview ๐Ÿ”Ž

Performing evaluations Retrieval-Augmented Generation systems, by covering several metrics and creating test cases.

Implementation ๐Ÿ› ๏ธ

Use the deepeval library to conduct test cases on correctness, faithfulness and contextual relevancy of RAG systems.

- GroUSE Evaluation : | Contextually-grounded LLM evaluation |

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

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 |

Overview ๐Ÿ”Ž

A comprehensive tutorial covering evaluation criteria selection, LLM-as-a-judge metrics, RAGAS integration, and full evaluation pipeline assembly.

Implementation ๐Ÿ› ๏ธ

  • Build custom metrics for completeness, relevance, and hallucination detection using the RAG-12000 dataset.

- Open-RAG-Eval : | Open-source RAG evaluation |

Overview ๐Ÿ”Ž

Demonstrates the open-rag-eval library for evaluation using UMBRELA scoring, AutoNuggetizer, and citation/hallucination detection.

Implementation ๐Ÿ› ๏ธ

  • Evaluate RAG pipelines using multiple open-source metrics against the FIQA financial dataset.

๐Ÿง  Memory-Augmented Retrieval

- MemoRAG : | Memory-augmented retrieval |

Overview ๐Ÿ”Ž

A from-scratch implementation of MemoRAG - a memory-augmented RAG system with key-value pair extraction, surrogate query generation, and multi-query retrieval.

Implementation ๐Ÿ› ๏ธ

  • Build a complete MemoryStore with FAISS-based retrieval, surrogate queries, and comparison evaluation against standard RAG.

๐Ÿ”ฌ Explainability and Transparency

- Explainable Retrieval ๐Ÿ”

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Providing transparency in the retrieval process to enhance user trust and system refinement.

Implementation ๐Ÿ› ๏ธ

Explain why certain pieces of information were retrieved and how they relate to the query.

๐Ÿ—๏ธ Advanced Architectures

- Agentic RAG with Contextual AI ๐Ÿค–

  • Agentic RAG :

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

  • Document Parser : Enterprise-grade parsing with vision models for complex tables, charts, and multi-page documents
  • Instruction-Following Reranker : SOTA reranker with instruction-following capabilities for handling conflicting information
  • Grounded Language Model (GLM) : World's most grounded LLM specifically engineered to minimize hallucinations for RAG use cases
  • LMUnit : Natural language unit testing framework for evaluating and optimizing RAG system performance

- Graph RAG with Milvus Vector Database ๐Ÿ”

  • Graph RAG with Milvus :

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

  • Store both text passages and relationship triplets (subject-predicate-object) in separate Milvus collections
  • Perform multi-way retrieval by querying both collections
  • Use an LLM to rerank retrieved relationships based on their relevance to the query
  • Retrieve the final passages based on the most relevant relationships

- Knowledge Graph Integration (Graph RAG) ๐Ÿ•ธ๏ธ

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Incorporating structured data from knowledge graphs to enrich context and improve retrieval.

Implementation ๐Ÿ› ๏ธ

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) ๐ŸŽฏ

  • GraphRag :

Overview ๐Ÿ”Ž

Microsoft GraphRAG (Open Source) is an advanced RAG system that integrates knowledge graphs to improve the performance of LLMs

Implementation ๐Ÿ› ๏ธ

  • 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 ๐ŸŒณ

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

Implementing a recursive approach to process and organize retrieved information in a tree structure.

Implementation ๐Ÿ› ๏ธ

Use abstractive summarization to recursively process and summarize retrieved documents, organizing the information in a tree structure for hierarchical context.

- Self RAG ๐Ÿ”

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

  • 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 ๐Ÿ”ง

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

  • 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 ๐Ÿ”—

  • NetworkX + Ollama :

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

  • 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 ๐Ÿ’ก

  • LangChain :
  • Runnable Script

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

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.

๐ŸŒŸ Special Advanced Technique ๐ŸŒŸ

- Sophisticated Controllable Agent for Complex RAG Tasks ๐Ÿค–

Overview ๐Ÿ”Ž

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.

Implementation ๐Ÿ› ๏ธ

  • 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.

Getting Started

To begin implementing these advanced RAG techniques in your projects:

  • Clone this repository:
ๅ‘ฝไปค
git clone https://github.com/NirDiamant/RAG_Techniques.git
  • Navigate to the technique you're interested in:
ๅ‘ฝไปค
cd all_rag_techniques/technique-name
  • Follow the detailed implementation guide in each technique's directory.

๐Ÿ“š Recommended reading

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.

  • Build a Large L

โ€” ๆœฌๆ–‡็”ฑ AI ๆ นๆฎๅ…ฌๅผ€ๆฅๆบ่พ…ๅŠฉๆ•ด็†๏ผŒๅ‘ฝไปคใ€็‰ˆๆœฌไธŽ่ฎธๅฏ่ฏ่ฏทๅœจไฝฟ็”จๅ‰ๅˆฐๅŽŸๅง‹้กต้ขๅคๆ ธใ€‚

ๅฎ‰่ฃ… / ๅผ€ๅง‹ไฝฟ็”จ

Getting Started To begin implementing these advanced RAG techniques in your projects:

  • Clone this repository:
ๅ‘ฝไปค
git clone https://github.com/NirDiamant/RAG_Techniques.git
  • Navigate to the technique you're interested in:
ๅ‘ฝไปค
cd all_rag_techniques/technique-name

๐Ÿ“š Recommended reading 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.

  • Follow the detailed implementation guide in each technique's directory.
  • Build a Large L

ๆฅๆบๆ•™็จ‹้…ๅ›พ

Claim your free module
้…ๅ›พ 1 ยท Claim your free moduleๆŸฅ็œ‹ๅŽŸๅ›พ
Contextual AI
้…ๅ›พ 2 ยท Contextual AIๆŸฅ็œ‹ๅŽŸๅ›พ
Contextual AI
้…ๅ›พ 3 ยท Contextual AIๆŸฅ็œ‹ๅŽŸๅ›พ
CodeRabbit
้…ๅ›พ 4 ยท CodeRabbitๆŸฅ็œ‹ๅŽŸๅ›พ
CodeRabbit
้…ๅ›พ 5 ยท CodeRabbitๆŸฅ็œ‹ๅŽŸๅ›พ
Qodo
้…ๅ›พ 6 ยท QodoๆŸฅ็œ‹ๅŽŸๅ›พ
ๆ•™็จ‹้…ๅ›พ
้…ๅ›พ 7 ยท ๆ•™็จ‹้…ๅ›พๆŸฅ็œ‹ๅŽŸๅ›พ
Subscribe to DiamantAI Newsletter
้…ๅ›พ 8 ยท Subscribe to DiamantAI NewsletterๆŸฅ็œ‹ๅŽŸๅ›พ

้€‚็”จๅœบๆ™ฏ

ๅญฆไน ็ ”็ฉถ
ๅผ€ๆบ้กน็›ฎๅฎž่ทต