Skip to content

0xarcher/learn-rag

Repository files navigation

Learn RAG - 25 RAG Variants Explained & Implemented

A deep dive into 25 Retrieval-Augmented Generation (RAG) variants: from foundational architectures to advanced frameworks, each with detailed tutorials and runnable Python implementations.


Overview

This repository is a hands-on learning resource for developers and researchers exploring RAG techniques. It covers 25 RAG variants ranging from the classic Standard RAG to advanced frameworks like Graph RAG. Each variant includes:

  • In-depth tutorials (bilingual: English & Chinese): architecture analysis, working principles, use cases, and trade-off analysis
  • Runnable code: complete Python implementations using sentence-transformers + FAISS + OpenAI API

Five Evolutionary Directions

Direction Use Case Representative Variants
Cost-Control Resource-constrained environments CORAG, Rule-based RAG
Real-time Interactive Finance / News applications Speculative RAG, Adaptive RAG
Domain Expert Specialized domains Agentic RAG, REALM
Cognitive Enhancement Complex reasoning tasks Self-RAG, ReAct, Graph RAG
Security & Compliance Sensitive data handling CRAG, EACO-RAG

Index of 25 RAG Variants

Foundational Architectures

# Variant Directory Core Idea
01 Standard RAG 01_standard_rag The classic retrieve-then-generate paradigm
02 CRAG (Corrective RAG) 02_crag Iterative feedback loops to correct low-confidence outputs
03 Speculative RAG 03_speculative_rag Dual-model strategy: specialist drafts, generalist verifies
04 Fusion RAG 04_fusion_rag Hybrid retrieval: semantic + keyword multi-path recall
05 Agentic RAG 05_agentic_rag Agent-driven autonomous retrieval and generation

Adaptive & Feedback

# Variant Directory Core Idea
06 Self-RAG 06_self_rag LLM self-evaluates and iteratively improves output
07 Adaptive RAG 07_adaptive_rag Gating mechanism dynamically decides whether retrieval is needed
08 REFEED 08_refeed Feedback-based secondary retrieval from initial output
09 REALM 09_realm Retrieval integrated into pre-trained language models
10 RAPTOR 10_raptor Recursive abstraction for hierarchical tree-structured retrieval

Model Integration & Enhancement

# Variant Directory Core Idea
11 REVEAL 11_reveal Multimodal visual-language retrieval augmentation
12 ReAct 12_react Interleaved reasoning and action chain-of-thought
13 REPLUG 13_replug Black-box retrieval plugin without model modification
14 Memo RAG 14_memo_rag Memory-compressed retrieval clue generation
15 ATLAS 15_atlas Retrieval fused into transformer attention layers

Architectural Innovation

# Variant Directory Core Idea
16 RETRO 16_retro Chunk-level cross-attention retrieval enhancement
17 Auto RAG 17_auto_rag Automated iterative optimization until confidence threshold
18 CORAG 18_corag Monte Carlo Tree Search for cost-constrained optimization
19 EACO-RAG 19_eaco_rag Edge computing distributed retrieval
20 Rule-based RAG 20_rule_rag Explicit rule engine for filtering and guided retrieval

Interaction & Structured Retrieval

# Variant Directory Core Idea
21 Conversational RAG 21_conversational_rag Multi-turn dialogue with persistent context retrieval
22 Iterative RAG 22_iterative_rag Iterative loops for progressive answer refinement
23 Tree Retrieval 23_tree_retrieval Complex query decomposition into sub-query trees
24 CRAT 24_crat Causal reasoning-augmented translation retrieval
25 Graph RAG 25_graph_rag Knowledge graph-driven structured retrieval

Quick Start

Prerequisites

  • Python >= 3.12
  • uv package manager

Installation

# Clone the repository
git clone https://github.com/your-username/learn-rag.git
cd learn-rag

# Install dependencies
uv sync

# Configure API Key (required for LLM generation)
cp .env.example .env
# Edit .env and add your OPENAI_API_KEY

Run an Example

# Run any variant
uv run python variants/01_standard_rag/main.py

# If you need to load environment variables from .env
source .env  # or: export OPENAI_API_KEY=sk-your-key
uv run python variants/01_standard_rag/main.py

Project Structure

learn-rag/
├── README.md                          # English documentation (this file)
├── README_CN.md                       # Chinese documentation
├── pyproject.toml                     # uv project configuration
├── .python-version                    # Python version
├── .env.example                       # Environment variable template
├── images/                            # Architecture diagrams
│   ├── rag_01.png
│   └── ...
└── variants/                          # 25 RAG variants
    ├── 01_standard_rag/
    │   ├── README.md                  # English tutorial
    │   ├── README_CN.md               # Chinese tutorial
    │   └── main.py                    # Runnable script
    ├── 02_crag/
    │   └── ...
    └── 25_graph_rag/
        └── ...

Tech Stack


Choosing the Right Variant

  • Getting started: Begin with Standard RAG to understand the fundamentals
  • Production deployment: Consider Fusion RAG for multi-method retrieval with high recall
  • Complex reasoning: Try Self-RAG or ReAct for autonomous reasoning
  • Resource-constrained: Use CORAG or Rule-based RAG to control costs
  • Multimodal needs: Explore REVEAL for text and visual data

References


License

MIT

About

A deep dive into 25 Retrieval-Augmented Generation (RAG) variants: from foundational architectures to advanced frameworks, each with detailed tutorials and runnable Python implementations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages