An open API service indexing awesome lists of open source software.

https://github.com/sosanzma/rag-techniques-handbook

A comprehensive guide to advanced RAG techniques including reranking, deep memory, and vector store optimization. Includes practical implementations and best practices using LlamaIndex, Langchain, etc..
https://github.com/sosanzma/rag-techniques-handbook

deep-memory llama-index machine-learning optimization rag reranking vector-store

Last synced: 2 months ago
JSON representation

A comprehensive guide to advanced RAG techniques including reranking, deep memory, and vector store optimization. Includes practical implementations and best practices using LlamaIndex, Langchain, etc..

Awesome Lists containing this project

README

          

# RAG Techniques Handbook

> **🎯 Status**: Production-Ready | **πŸ“š Complete Techniques**: 6 | **πŸ”— Integrated Docs**: 100%

## Overview

This repository provides a comprehensive collection of **advanced RAG (Retrieval Augmented Generation) techniques** with production-ready implementations and seamlessly integrated documentation. Each technique includes both theoretical explanations and working Python code that you can immediately use in your projects.

**Key Features:**
- βœ… **Production-Ready Code**: All implementations are tested and optimized
- πŸ“– **Integrated Documentation**: Theory and code seamlessly connected
- πŸš€ **Quick Start Guides**: Get running in 3 minutes with any technique
- πŸ”§ **Configurable**: Extensive configuration options for customization
- πŸ“Š **Evaluation Framework**: Built-in metrics and performance assessment
- πŸ€– **Multiple LLM Support**: OpenAI, Cohere, and more

## Currently Implemented Techniques

### βœ… RAG Metrics & Evaluation
**Complete evaluation framework with LlamaIndex and RAGAS integration**
- **Features**: Retrieval metrics (MRR, Hit Rate), Generation quality (Faithfulness, Relevancy), RAGAS comprehensive metrics
- **Classes**: `RAGEvaluationFramework`, `EvaluationConfig`
- **Documentation**: [RAG Metrics & Evaluation Guide](docs/rag_metrics_evaluation_guide.md)
- **Implementation**: [rag_metrics_evaluation_module.py](src/rag_metrics_evaluation_module.py)

### βœ… Vector Store Index Implementation
**Optimized vector store operations with DeepLake integration**
- **Features**: Deep Memory optimization, Performance evaluation, Cohere reranking, Async operations
- **Classes**: `VectorStoreManager`, `VectorStoreConfig`
- **Documentation**: [Vector Store Implementation Guide](docs/vector_store_index_implementation_guide.md)
- **Implementation**: [vector_store_index_implementation.py](src/vector_store_index_implementation.py)

### βœ… Advanced Reranking Systems
**Multiple reranking strategies with ensemble capabilities**
- **Features**: Cohere API, SentenceTransformer, LLM-based, Ensemble reranking, Performance caching
- **Classes**: `RerankerManager`, `RerankerConfig`, `EnsembleReranker`
- **Documentation**: [Reranking Systems Guide](docs/reranking_rag_systems.md)
- **Implementation**: [reranking_rag_systems.py](src/reranking_rag_systems.py)

### βœ… Advanced RAG Techniques
**LlamaIndex-based advanced query processing and retrieval**
- **Features**: Sub-question decomposition, Query transformation, Hierarchical retrieval, Streaming support
- **Classes**: `AdvancedRAGEngine`
- **Documentation**: [Advanced RAG Techniques Guide](docs/Advanced_RAg_techniques_LLamaIndex.md)
- **Implementation**: [Advanced_RAG_tenchniques_LLamaIndex.py](src/Advanced_RAG_tenchniques_LLamaIndex.py)

### βœ… RAG Agent System
**Multi-source agent-based RAG with tool integration**
- **Features**: Multi-document querying, Tool integration, OpenAI agents, DeepLake support
- **Classes**: `RAGAgent`
- **Documentation**: [RAG Agent Guide](docs/LlamaIndex_rag_agent.md)
- **Implementation**: [LlamaIndex_rag_agent.py](src/LlamaIndex_rag_agent.py)

### βœ… LangSmith Integration
**Complete monitoring and evaluation with LangSmith**
- **Features**: Tracing, Prompt management, Evaluation pipelines, Chain monitoring
- **Classes**: `LangSmithManager`
- **Documentation**: [LangSmith Integration Guide](docs/Langsmith.md)
- **Implementation**: [Langsmith.py](src/Langsmith.py)

## Quick Start

### Installation

```bash
# Clone the repository
git clone https://github.com/yourusername/rag-techniques-handbook.git
cd rag-techniques-handbook

# Install dependencies
pip install llama-index==0.9.14.post3 deeplake==3.8.12 openai==1.3.8 cohere==4.37 ragas==0.0.22 pandas

# Set up environment variables
export OPENAI_API_KEY="your_openai_key"
export ACTIVELOOP_TOKEN="your_deeplake_token"
export COHERE_API_KEY="your_cohere_key"
```

### 3-Minute Example: Complete RAG Evaluation

```python
from src.rag_metrics_evaluation_module import RAGEvaluationFramework, EvaluationConfig
import asyncio

# Configure and run comprehensive evaluation
config = EvaluationConfig(llm_model="gpt-3.5-turbo", enable_ragas=True)
evaluator = RAGEvaluationFramework(config)

# Evaluate your documents
results = asyncio.run(
evaluator.comprehensive_evaluation(documents_path="your/docs/path")
)

print(f"πŸ“Š Retrieval MRR: {results['retrieval_metrics']['mrr']:.3f}")
print(f"βœ… Faithfulness: {results['generation_metrics']['faithfulness']:.3f}")
print(f"🎯 Relevancy: {results['generation_metrics']['relevancy']:.3f}")
```

## Project Structure

```
rag-techniques-handbook/
β”œβ”€β”€ πŸ“ docs/ # Comprehensive guides (theory + implementation)
β”‚ β”œβ”€β”€ πŸ“‹ rag_metrics_evaluation_guide.md
β”‚ β”œβ”€β”€ πŸ“‹ vector_store_index_implementation_guide.md
β”‚ β”œβ”€β”€ πŸ“‹ reranking_rag_systems.md
β”‚ β”œβ”€β”€ πŸ“‹ Advanced_RAg_techniques_LLamaIndex.md
β”‚ β”œβ”€β”€ πŸ“‹ LlamaIndex_rag_agent.md
β”‚ └── πŸ“‹ Langsmith.md
β”œβ”€β”€ 🐍 src/ # Production-ready implementations
β”‚ β”œβ”€β”€ πŸ”¬ rag_metrics_evaluation_module.py
β”‚ β”œβ”€β”€ πŸ—„οΈ vector_store_index_implementation.py
β”‚ β”œβ”€β”€ πŸ”„ reranking_rag_systems.py
β”‚ β”œβ”€β”€ πŸš€ Advanced_RAG_tenchniques_LLamaIndex.py
β”‚ β”œβ”€β”€ πŸ€– LlamaIndex_rag_agent.py
β”‚ └── πŸ“ˆ Langsmith.py
β”œβ”€β”€ πŸ““ src/Module_04_RAG_Metrics&Evaluation.ipynb # Jupyter notebook example
β”œβ”€β”€ πŸ“– CLAUDE.md # Development documentation
└── πŸ—ΊοΈ README.md # This file
```

## Key Features

### πŸ”— Seamless Documentation-Code Integration
Every documentation file is directly connected to its implementation:
- **Quick Start sections** with copy-paste ready code
- **Method references** with line numbers
- **Configuration guides** mapped to actual parameters
- **Source code exploration** for deeper understanding

### βš™οΈ Production-Ready Implementations
- **Error Handling**: Comprehensive exception handling and logging
- **Async Support**: Non-blocking operations for better performance
- **Configuration Management**: Structured configuration with dataclasses
- **Performance Optimization**: Built-in caching and batch processing

### πŸ“Š Comprehensive Evaluation
- **Multiple Frameworks**: Both LlamaIndex and RAGAS metrics
- **Retrieval Metrics**: MRR, Hit Rate, Context Precision/Recall
- **Generation Quality**: Faithfulness, Relevancy, Harmfulness
- **Automated Evaluation**: Batch processing and async operations

### 🎯 Multiple Use Cases Supported
- **Research**: Comprehensive evaluation and comparison
- **Development**: Quick prototyping with production-ready code
- **Production**: Monitoring and performance tracking
- **Education**: Learning advanced RAG techniques

## Prerequisites

- **Python**: 3.8+
- **API Keys**: OpenAI (required), Cohere (optional), ActiveLoop (for DeepLake)
- **Memory**: 8GB+ RAM recommended for large document processing
- **Storage**: Vector databases may require significant disk space

## Contributing

We welcome contributions! The repository is designed for easy extension:

### Current Areas for Contribution
- Additional evaluation metrics
- New vector store integrations
- Performance optimizations
- Documentation improvements
- Example notebooks

### How to Contribute
1. Fork the repository
2. Create a feature branch
3. Follow the existing patterns (see any `src/` file for reference)
4. Update both implementation and documentation
5. Submit a pull request

## Resources

### Documentation
- **[CLAUDE.md](CLAUDE.md)**: Complete technical documentation and development guide
- **[Planned Features](PLANNED_FEATURES.md)**: Upcoming techniques and improvements

### External Resources
- [LlamaIndex Documentation](https://docs.llamaindex.ai/)
- [RAGAS Documentation](https://docs.ragas.io/)
- [DeepLake Documentation](https://docs.deeplake.ai/)
- [OpenAI API Documentation](https://platform.openai.com/docs)

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Acknowledgments

- **LlamaIndex team** for the excellent RAG framework
- **RAGAS team** for comprehensive evaluation metrics
- **ActiveLoop** for DeepLake vector database
- **OpenAI** for LLM and embedding services
- **Cohere** for reranking capabilities

---

> **πŸš€ Ready to get started?** Pick any technique from the list above and follow its Quick Start guide. Each implementation is production-ready and includes comprehensive documentation to get you running in minutes!