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 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.
"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.
"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.
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 Keygit clone https://github.com/wasxy47/RAG_Comparison_System.git
cd RAG_Comparison_SystemCreate a virtual environment to keep dependencies clean.
python -m venv venv
# Windows
venv\Scripts\activate
# Mac/Linux
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the root directory and add your Google Gemini API key:
GOOGLE_API_KEY=your_api_key_hereTo run all three techniques sequentially and see the speed/quality difference:
python src/compare_all.pyYou will be prompted to enter a question, and the system will run Naive, Advanced, and Agentic RAG side-by-side.
You can also run each technique independently:
Naive RAG:
python src/1_naive.pyAdvanced RAG:
python src/2_advanced.pyAgentic RAG:
python src/3_agentic.pyQuestion: "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)
This project is open-source and available for educational purposes. 🎓