Skip to content

πŸ”° A Comprehensive RAG repository covering basic vanilla RAG techniques, advanced retrieval methods, hybrid search fusion approaches, hands-on reranking techniques with code + explanation πŸ“šβœ¨

Notifications You must be signed in to change notification settings

Abeshith/RAG-FundaMentals

Repository files navigation

RAG-Fundamentals πŸš€

Comprehensive Collection of Retrieval-Augmented Generation Techniques

A complete hands-on guide to RAG implementations, from basic concepts to advanced techniques. This repository contains practical notebooks demonstrating various RAG approaches, retrieval strategies, and optimization methods.

πŸ“Š RAG Architecture Flowchart

Based on the provided flowchart, here's the complete RAG system architecture:

graph TD
    A[πŸ“„ DATA] --> B[πŸ”ͺ CHUNK 1]
    A --> C[πŸ”ͺ CHUNK 2] 
    A --> D[πŸ”ͺ CHUNK 3]
    
    B --> E[🧠 EMBEDDING 1]
    C --> F[🧠 EMBEDDING 2]
    D --> G[🧠 EMBEDDING 3]
    
    E --> H[πŸ’Ύ DATABASE<br/>Vector Store]
    F --> H
    G --> H
    
    I[πŸ‘€ USER] --> J[πŸ”Ž QUERY]
    J --> K[🧠 EMBEDDING<br/>Query]
    
    I -.->|Generation| L[πŸ” SEMANTIC SEARCH]
    K --> L
    H --> L
    
    L --> M[🎯 RETRIEVAL]
    M --> N[πŸ“Š RANKED RESULTS]
    N --> O[πŸ”„ RERANKED RESULTS]
    
    O --> P[πŸ€– LLM<br/>Query+Prompt+Context]
    P --> Q[πŸ’¬ RESPONSE]
    
    style A fill:#e1f5fe
    style H fill:#f3e5f5
    style I fill:#fff3e0
    style P fill:#e8f5e8
    style Q fill:#fce4ec
Loading

Core RAG Components:

  1. πŸ“„ Data Processing: Documents are split into manageable chunks
  2. 🧠 Embedding: Text chunks converted to vector representations
  3. πŸ’Ύ Vector Database: Stores embeddings for efficient retrieval
  4. πŸ” Semantic Search: Finds relevant chunks using similarity
  5. 🎯 Retrieval: Returns top-k most relevant documents
  6. πŸ”„ Reranking: Optimizes order for better context
  7. πŸ€– LLM Generation: Produces final answer with retrieved context

🎯 What is RAG?

Retrieval-Augmented Generation combines the power of:

  • πŸ” Information Retrieval: Finding relevant external knowledge
  • πŸ€– Language Generation: Creating contextual responses
  • πŸ“š External Knowledge: Up-to-date, domain-specific information

πŸ“ Repository Structure

πŸ”° Basic RAG

Foundation techniques for RAG implementation

Notebook Purpose Key Techniques
basic_rag.ipynb Core RAG pipeline Vector embeddings, semantic search, prompt engineering
document_rag.ipynb PDF document processing Local knowledge base, metadata handling
url_rag.ipynb Web content RAG Real-time retrieval, dynamic knowledge updates

Advanced retrieval strategies beyond basic semantic search

Technique Notebook Innovation
Contextual Compression Contextual_Compression_Retriever.ipynb Compresses retrieved docs to extract only relevant portions
HyDE Hypothetical_Document_Embedding_(HyDE).ipynb Generates hypothetical answers to improve retrieval accuracy
Multi-Hop Retrieval MultiHop_Query_Step_by_Step_Retrieval.ipynb Step-by-step retrieval for complex queries
Parent Document Parent_Document_Retriever.ipynb Retrieves small chunks but returns larger parent documents
Self-Query Self_Query_Retrieval.ipynb Natural language query parsing with metadata filtering
Sentence Window Sentence_Window_Retrieval.ipynb Expanded context windows around relevant sentences

Optimize retrieved document ordering for better LLM performance

Method Notebook Advantage
BM25 Rerank bm25_rerank_rag.ipynb Statistical keyword-based relevance scoring
Cohere Rerank cohere_rerank.ipynb State-of-the-art neural reranking API
Cross-Encoder cross_encoder_rerank.ipynb Joint query-document encoding for precise relevance
Flash ReRank Flash_ReRanking.ipynb Ultra-fast reranking for real-time applications

Combine multiple search methodologies for superior performance

Technique Notebook Combines
Cosine Similarity cosine.ipynb Vector similarity mathematics and optimization
Hybrid Search hybridsearch-rag.ipynb Semantic + keyword search with score fusion algorithms

⚑ RAG Fusion

Fuse multiple retrieval methods for comprehensive results

Method Notebook Fusion Strategy
Reciprocal Rank Fusion ReciProcal_Rank_Fusion.ipynb Combines rankings from multiple retrievers using RRF algorithm

Solve positional bias where important info gets overlooked in middle context

Solution Notebook Approach
Merger & Reranking MergerRetriever_And_Reranking.ipynb Strategic document ordering and context reorganization

πŸ–ΌοΈ MultiModal RAG

Process and understand multiple data types including text, images, charts, and diagrams

Technique Notebook Innovation
MultiModal Processing MultiModal_RAG(IMG+TexT).ipynb CLIP-based unified embeddings for text and images, cross-modal retrieval

πŸ€– Agentic RAG

Intelligent agent-based RAG systems with autonomous decision making

Method Notebook Capability
Agentic RAG Agentic_RAG.ipynb Autonomous agent-based retrieval and generation
LangGraph RAG Rag_with_langgraph.ipynb Graph-based workflow orchestration for complex RAG
Routed RAG Routed_RAG_With_LLM_Router.ipynb LLM-powered routing for dynamic retrieval strategies

πŸ”¬ Advanced RAG

Cutting-edge RAG techniques for specialized applications

Technique Notebook Advanced Feature
Agentic RAG Agentic_RAG.ipynb Agent-based autonomous reasoning and retrieval
Corrective RAG (CRAG) Corrective_RAG_(CRAG).ipynb Self-correcting retrieval with confidence scoring

Comprehensive evaluation frameworks for RAG system performance

Framework Notebook Evaluation Focus
RAG Evaluation RAG_Evaluation.ipynb Custom evaluation metrics and benchmarking
RAGAs Evaluation RAGAs_Evaluation.ipynb Automated evaluation using RAGAs framework

πŸ”§ Key Technologies Used

  • 🦜 LangChain: RAG framework and components
  • πŸ€— HuggingFace: Embeddings and transformers
  • πŸ“Š ChromaDB: Vector database storage
  • πŸ” FAISS: Efficient similarity search
  • 🌐 OpenAI: Embeddings and language models
  • ⚑ Cohere: Professional reranking services
  • πŸ–ΌοΈ CLIP: Multimodal embeddings for text and images
  • πŸ”„ LangGraph: Graph-based workflow orchestration
  • βš–οΈ RAGAs: Automated RAG evaluation framework
  • 🧠 Groq: High-performance LLM inference

πŸš€ Getting Started

  1. Clone the repository
  2. Install dependencies: pip install -r requirements.txt
  3. Start with Basic RAG to understand fundamentals
  4. Explore Retriever Techniques for advanced retrieval strategies
  5. Implement ReRanking for better accuracy
  6. Try Hybrid Approaches for production systems
  7. Explore MultiModal RAG for documents with images and text
  8. Advance to Agentic RAG for autonomous intelligent systems
  9. Use RAG Evaluation to benchmark and optimize performance

🎯 Use Cases Covered

  • πŸ“– Document Q&A: Academic papers, legal documents
  • 🌐 Web Search: Real-time information retrieval
  • 🏒 Enterprise: Knowledge management systems
  • πŸ”¬ Research: Multi-document analysis and synthesis
  • πŸ’¬ Chatbots: Context-aware conversational AI
  • πŸ–ΌοΈ Multimodal Analysis: Documents with text, images, and charts
  • πŸ€– Autonomous Systems: Agent-based intelligent retrieval
  • πŸ“Š Performance Evaluation: RAG system benchmarking and optimization
  • πŸ”„ Self-Correcting Systems: Adaptive and corrective RAG implementations

🎯 Master RAG: From basic retrieval to advanced fusion techniques, this repository provides everything needed to build Development-ready RAG systems.

About

πŸ”° A Comprehensive RAG repository covering basic vanilla RAG techniques, advanced retrieval methods, hybrid search fusion approaches, hands-on reranking techniques with code + explanation πŸ“šβœ¨

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published