$ show NirDiamant/RAG_Techniques
This repository is a comprehensive, educational collection of 42+ Jupyter notebooks and runnable scripts demonstrating a wide array of Retrieval-Augmented Generation (RAG) techniques. It is primarily a data_research and educational resource, not a deployable application or library. The codebase serves as a practical cookbook for engineers and researchers, covering the full RAG stack from basic chunking and retrieval (e.g., simple RAG, BM25) to advanced methods like GraphRAG, Self-RAG, HyDE, RAPTOR, and agentic RAG. It also includes a dedicated evaluation framework with notebooks and reusable scripts for measuring faithfulness, relevance, and correctness using tools like DeepEval and custom LLM judges. The architecture is modular, with a shared helper_functions.py providing common utilities for PDF loading, embedding, and retrieval, and an evaluation/ module offering reusable evaluation pipelines. The runnable scripts in all_rag_techniques_runnable_scripts/ provide cleaner, class-based implementations of the techniques that are more suitable for integration into other projects than the notebooks themselves. While the code is well-structured for an educational project and demonstrates high craftsmanship in its reusable components, it is not designed for production deployment. Reproducibility is limited by the lack of a pinned dependency file and reliance on external API keys. The repository is actively maintained and highly influential (29k+ stars), making it a valuable reference for anyone building or evaluating RAG systems.
The LLM identified 4 files worth highlighting for reuse:
Provides a centralized set of reusable functions for common RAG operations: PDF loading (encode_pdf, read_pdf_to_string), text chunking, embedding, vector store creation, retrieval (retrieve_context_per_question), BM25 search (bm25_retrieval), and API rate limiting (retry_with_exponential_backoff). This module is the backbone of the repository, demonstrating clean abstraction of boilerplate RAG code.
Defines a reusable evaluation pipeline for RAG systems. It creates test cases from Q&A data and evaluates RAG pipelines on faithfulness, relevancy, and correctness using the DeepEval library. The evaluate_rag function provides a standard interface for running these metrics, making it easy to benchmark different RAG configurations.
Demonstrates a clean, class-based RAG pipeline that can be run from the command line. It encapsulates the entire RAG flow (load, chunk, embed, store, retrieve, generate) in a reusable class with a run() method. This is a good example of how to structure a RAG application for reusability and testing.
Implements a sophisticated RAG pipeline with relevance grading, hallucination checking, and source highlighting using structured LLM output. The pattern of retrieve -> grade -> filter -> generate -> validate -> cite is a highly reusable architectural pattern for building trustworthy RAG systems. It uses Pydantic models for structured LLM output and LCEL for chain composition.