Home / Learn / RAG Techniques - The most comprehensive learning resource for Retrieval-Augmented Generation techniques
AI Applications

RAG Techniques - The most comprehensive learning resource for Retrieval-Augmented Generation techniques

GitHubFree6 Clicks

RAG Techniques Learning Resources Detailed Introduction

Project Overview

RAG Techniques is an open-source GitHub project created by Nir Diamant, dedicated to showcasing various advanced Retrieval-Augmented Generation (RAG) system techniques. The project aims to provide researchers and developers with a comprehensive resource library to help them build more accurate and contextually relevant RAG systems.

Project Features

๐ŸŒŸ Core Features

  • Cutting-edge Techniques: Covers the latest RAG system enhancement techniques
  • Comprehensive Documentation: Detailed documentation for each technique
  • Practical Guides: Provides practical implementation guidance
  • Continuous Updates: Regularly updated with the latest technical advancements
  • Community-Driven: Features an active Discord community (20,000+ AI enthusiasts)

๐ŸŽฏ Target Audience

  • AI Researchers
  • Machine Learning Engineers
  • Developers and Practitioners
  • Learners interested in RAG techniques

Technical Classification and Detailed Introduction

1. Foundational Techniques ๐ŸŒฑ

Simple RAG

  • Description: Introduces basic RAG techniques, suitable for beginners
  • Implementation: Supports LangChain and LlamaIndex
  • Functionality: Basic retrieval queries and incremental learning mechanisms

Simple RAG using CSV

  • Description: Basic RAG implementation using CSV files
  • Functionality: Utilizes CSV files to create basic retrieval and integrates with OpenAI

Corrective RAG

  • Description: Enhances Simple RAG by adding validation and improvement mechanisms
  • Functionality: Checks the relevance of retrieved documents and highlights document snippets used for answering

2. Chunking Techniques

Choose Chunk Size

  • Description: Selecting an appropriate text chunk size to balance context retention and retrieval efficiency
  • Implementation:
# Example: Experimenting with different chunk sizes
chunk_sizes = [200, 500, 1000, 2000]
for size in chunk_sizes:
    # Test retrieval effectiveness for different sizes
    evaluate_chunk_performance(size)

Proposition Chunking

  • Description: Decomposing text into concise, complete, and meaningful sentences
  • Features:
    • ๐Ÿ’ช Proposition Generation: Uses LLM to generate factual statements for document chunks
    • โœ… Quality Check: Evaluates accuracy, clarity, completeness, and conciseness

Semantic Chunking

  • Description: Dividing documents based on semantic coherence rather than fixed size
  • Advantages: Uses NLP techniques to identify topic boundaries, creating more meaningful retrieval units

3. Query Processing Techniques

Query Transformations

  • Description: Modifying and expanding queries to improve retrieval effectiveness
  • Techniques include:
    • โœ๏ธ Query Rewriting: Rephrasing queries to improve retrieval
    • ๐Ÿ”™ Fallback Prompting: Generating broader queries for better context
    • ๐Ÿงฉ Sub-query Decomposition: Breaking down complex queries into simpler sub-queries

Hypothetical Questions (HyDE)

  • Description: Generating hypothetical questions to improve query-to-data matching
  • Functionality: Creates hypothetical questions that point to relevant locations in the data

Hypothetical Prompt Embeddings (HyPE)

  • Description: An enhanced version of HyDE, pre-computing hypothetical prompts during the indexing phase
  • Advantages:
    • ๐Ÿ“– Pre-computed Questions: Generates multiple hypothetical queries at indexing time
    • ๐Ÿ” Question-to-Question Matching: User queries are matched against stored hypothetical questions
    • โšก No Runtime Overhead: No need to call LLM at query time

4. Context Processing Techniques

Context Enrichment Techniques

  • Description: Enhancing retrieval accuracy by embedding individual sentences and expanding to neighboring sentences
  • Implementation:
# Example: Context window expansion
def get_context_window(sentence_index, window_size=2):
    start = max(0, sentence_index - window_size)
    end = min(len(sentences), sentence_index + window_size + 1)
    return sentences[start:end]

Contextual Compression

  • Description: Compressing retrieved information while preserving query-relevant content
  • Method: Using an LLM to compress or summarize retrieved chunks

Contextual Chunk Headers (CCH)

  • Description: Creating document-level and section-level context and adding it to chunk headers
  • Functionality: Improves retrieval accuracy

5. Retrieval Enhancement Techniques

Fusion Retrieval

  • Description: Optimizing search results by combining different retrieval methods
  • Implementation: Combines keyword-based search and vector-based search

Intelligent Reranking

  • Description: Applying advanced scoring mechanisms to improve the relevance ranking of retrieval results
  • Techniques:
    • ๐Ÿง  LLM-based Scoring
    • ๐Ÿ”€ Cross-encoder Models
    • ๐Ÿ† Metadata-enhanced Ranking

Multi-faceted Filtering

  • Description: Applying various filtering techniques to improve the quality of retrieval results
  • Includes:
    • ๐Ÿท๏ธ Metadata Filtering
    • ๐Ÿ“Š Similarity Thresholding
    • ๐Ÿ“„ Content Filtering
    • ๐ŸŒˆ Diversity Filtering

6. Advanced Architecture Techniques

Hierarchical Indices

  • Description: Creating multi-layered systems for efficient information navigation and retrieval
  • Implementation: A two-layer system of document summaries and detailed chunks

Ensemble Retrieval

  • Description: Combining multiple retrieval models or techniques for more robust and accurate results
  • Method: Uses voting or weighting mechanisms to determine the final set of retrieved documents

RAPTOR

  • Description: Recursive Abstractive Processing for Tree-organized Retrieval
  • Features: Recursively processes retrieved documents using abstractive summarization, organizing information in a tree structure

7. Adaptive Techniques

Adaptive Retrieval

  • Description: Dynamically adjusting retrieval strategies based on query type and user context
  • Functionality: Uses tailored retrieval strategies for different categories of queries

Self RAG

  • Description: A dynamic approach combining retrieval and generation methods
  • Process: Retrieval decision โ†’ Document retrieval โ†’ Relevance assessment โ†’ Response generation

Corrective RAG (CRAG)

  • Description: A complex RAG method that dynamically evaluates and corrects the retrieval process
  • Components: Retrieval Evaluator, Knowledge Refiner, Web Search Query Rewriter

8. Multi-modal Techniques

Multi-modal Retrieval

  • Description: Extending RAG capabilities to handle multiple data types
  • Methods:
    • Multimedia Captioning: Generates captions for all multimedia data
    • Colpali: Converts all data into images and uses visual LLMs

9. Knowledge Graph Integration

Knowledge Graph Integration (Graph RAG)

  • Description: Integrating structured data from knowledge graphs to enrich context
  • Functionality: Retrieves entities and relationships relevant to the query

GraphRAG (Microsoft)

  • Description: Microsoft's open-source GraphRAG system
  • Features: Extracts entities and relationships from text units, generates community summaries

10. Evaluation Techniques

DeepEval Evaluation

  • Description: Comprehensive RAG system evaluation
  • Metrics: Correctness, Faithfulness, Contextual Relevance

GroUSE Evaluation

  • Description: Context-based LLM evaluation
  • Functionality: Evaluates using 6 metrics from the GroUSE framework

Implementation Guide

Quick Start

# Clone the repository
git clone https://github.com/NirDiamant/RAG_Techniques.git

# Navigate to a specific technique directory
cd all_rag_techniques/technique-name

# Follow the detailed implementation guide in each technique directory

Tech Stack Support

  • LangChain: Primary framework support
  • LlamaIndex: Partial technique support
  • OpenAI API: Generative model integration
  • Various Embedding Models: Supports multiple vectorization methods

Suggested Learning Paths

Beginner Path

  1. Simple RAG โ†’ Understand basic concepts
  2. Choose Chunk Size โ†’ Learn text chunking
  3. Query Transformations โ†’ Grasp query optimization
  4. Context Enrichment โ†’ Master context processing

Advanced Path

  1. Semantic Chunking โ†’ Advanced chunking techniques
  2. Fusion Retrieval โ†’ Combining multiple methods
  3. Intelligent Reranking โ†’ Result optimization
  4. Hierarchical Indices โ†’ Complex architectures

Expert Path

  1. Self RAG โ†’ Adaptive systems
  2. Graph RAG โ†’ Knowledge graph integration
  3. RAPTOR โ†’ Recursive processing
  4. Multi-modal Retrieval โ†’ Multi-modal processing

This learning resource provides a complete RAG technique learning path from foundational to advanced levels, suitable for learners of different proficiencies, and is one of the most comprehensive RAG technique resource libraries available today.

โ†— View source