Skip to content

wasxy47/RAG_Comparison_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RAG Comparison System

Python LangChain Gemini ChromaDB

📌 Overview

This project serves as a comprehensive benchmark comparing three evolutionary stages of Retrieval-Augmented Generation (RAG) systems. By using a Research Paper as a knowledge base, it demonstrates the capabilities and trade-offs of different RAG architectures.

The system is built to provide a direct "apple-to-apples" comparison of how different techniques handle the same user query.


🚀 The Three Techniques

1. Naive RAG

"The Direct Approach"

  • Mechanism: Standard similarity search -> Prompt Stuffing -> Answer.
  • Pros: Extremely fast, simple implementation.
  • Cons: Prone to hallucinations if context is irrelevant; often blindly trusts retrieved chunks.

2. Advanced RAG

"The Critical Thinker"

  • Mechanism: Retrieval -> Context Refinement -> Strict Evaluation -> Answer.
  • Highlights: Uses a prompt that strictly instructs the model to evaluate if the answer is actually present in the context.
  • Better For: Reducing hallucinations and ensuring accuracy.

3. Agentic RAG

"The Autonomous Investigator"

  • Mechanism: Zero-Shot ReAct Loop (Reason + Act).
  • Highlights: The LLM acts as an agent that can:
    • Reason about the question ("Thought").
    • Decide to use a tool ("Action").
    • Search the vector database specifically for what it needs ("Research_Paper_Search").
    • Iterate until satisfied.
  • Best For: Complex queries requiring multi-step reasoning.

📂 Project Structure

RAG_Comparison_System/
├── data/
│   └── research_paper.pdf    # 📄 The Knowledge Base
├── src/
│   ├── 1_naive.py            # ⚡ Naive RAG Implementation
│   ├── 2_advanced.py         # 🛡️ Advanced RAG Implementation
│   ├── 3_agentic.py          # 🤖 Agentic RAG Implementation
│   └── compare_all.py        # ⚔️ The Showdown Script (Run this!)
├── main.py                   # ⚙️ Configuration & Setup
└── .env                      # 🔗 API Key

🛠️ Installation & Setup

1. Clone the Repository

git clone https://github.com/wasxy47/RAG_Comparison_System.git
cd RAG_Comparison_System

2. Set Up Environment

Create a virtual environment to keep dependencies clean.

python -m venv venv
# Windows
venv\Scripts\activate
# Mac/Linux
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure API Key

Create a .env file in the root directory and add your Google Gemini API key:

GOOGLE_API_KEY=your_api_key_here

🎮 How to Use

The Ultimate Showdown ⚔️

To run all three techniques sequentially and see the speed/quality difference:

python src/compare_all.py

You will be prompted to enter a question, and the system will run Naive, Advanced, and Agentic RAG side-by-side.

Individual Techniques

You can also run each technique independently:

Naive RAG:

python src/1_naive.py

Advanced RAG:

python src/2_advanced.py

Agentic RAG:

python src/3_agentic.py

📊 Example Output

Question: "What is the main contribution of this paper?"

  • [Naive RAG] (1.2s): The paper contributes a new method for... (Good, fast)
  • [Advanced RAG] (2.1s): Based on the context, the authors propose... (More precise, verifies context)
  • [Agentic RAG] (5.4s): Thought: I need to find the contributions section. Action: Search... Final Answer: The main contribution is... (Iterative, most robust)

📜 License

This project is open-source and available for educational purposes. 🎓

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages