bRAGAI / bRAG-langchain

Everything you need to know to build your own RAG application
MIT License
256 stars 7 forks source link

Retrieval-Augmented Generation (RAG) Project

This repository contains a comprehensive exploration of Retrieval-Augmented Generation (RAG) for various applications. Each notebook provides a detailed, hands-on guide to setting up and experimenting with RAG from an introductory level to advanced implementations, including multi-querying and custom RAG builds.

rag_detail_v2

Project Structure

If you want to jump straight into it, check out the file full_basic_rag.ipynb -> this file will give you a boilerplate starter code of a fully customizable RAG chatbot.

Make sure to run your files in a virtual environment (checkout section Get Started)

The following notebooks can be found under the directory tutorial_notebooks/.

[1]_rag_setup_overview.ipynb

This introductory notebook provides an overview of RAG architecture and its foundational setup. The notebook walks through:

[2]_rag_with_multi_query.ipynb

Building on the basics, this notebook introduces multi-querying techniques in the RAG pipeline, exploring:

[3]_rag_routing_and_query_construction.ipynb

This notebook delves deeper into customizing a RAG pipeline. It covers:

[4]_rag_indexing_and_advanced_retrieval.ipynb

Continuing from the previous customization, this notebook explores:

[5]_rag_retrieval_and_reranking.ipynb

This final notebook brings together the RAG system components, with a focus on scalability and optimization:

Getting Started

Pre-requisites: Python 3.11.7 (preferred)

  1. Clone the repository:

    git clone https://github.com/bRAGAI/bRAG-langchain.git 
    
    cd bRAG-langchain
  2. Create a virtual environment

    python -m venv venv
    
    source venv/bin/activate
  3. Install dependencies: Make sure to install the required packages listed in requirements.txt.

    pip install -r requirements.txt

  4. Run the Notebooks: Begin with [1]_rag_setup_overview.ipynb to get familiar with the setup process. Proceed sequentially through the other notebooks to build and experiment with more advanced RAG concepts.

  5. Set Up Environment Variables:

    • Duplicate the .env.example file in the root directory and name it .env and include the following keys (replace with your actual keys):

      #LLM Modal
      OPENAI_API_KEY="your-api-key"
      
      #LangSmith
      LANGCHAIN_TRACING_V2=true
      LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
      LANGCHAIN_API_KEY="your-api-key"
      LANGCHAIN_PROJECT="your-project-name"
      
      #Pinecone Vector Database
      PINECONE_INDEX_NAME="your-project-index"
      PINECONE_API_HOST="your-host-url"
      PINECONE_API_KEY="your-api-key"
  6. Notebook Order: To follow the project in a structured manner:

    • Start with [1]_rag_setup_overview.ipynb

    • Proceed with [2]_rag_with_multi_query.ipynb

    • Then go through [3]_rag_routing_and_query_construction.ipynb

    • Continue with [4]_rag_indexing_and_advanced_retrieval.ipynb

    • Finish with [5]_rag_retrieval_and_reranking.ipynb

Usage

After setting up the environment and running the notebooks in sequence, you can:

  1. Experiment with Retrieval-Augmented Generation: Use the foundational setup in [1]_rag_setup_overview.ipynb to understand the basics of RAG.

  2. Implement Multi-Querying: Learn how to improve response relevance by introducing multi-querying techniques in [2]_rag_with_multi_query.ipynb.

Incoming Notebooks (work in progress)

  1. Context Precision with RAGAS + LangSmith
    • Guide on using RAGAS and LangSmith to evaluate context precision, relevance, and response accuracy in RAG.
  2. Deploying RAG application
    • Guide on how to deploy your RAG application


Contributor: Taha Ababou (GitHub: @tahababou12)