Skip to content

Latest commit

 

History

History
139 lines (107 loc) · 9.63 KB

File metadata and controls

139 lines (107 loc) · 9.63 KB

Multi-Agentic RAG System

A sophisticated Retrieval-Augmented Generation (RAG) chatbot that uses multiple AI agents to answer questions from uploaded PDF documents.

Architecture

The system implements a multi-agent workflow with:

  1. Relevance Checker: Determines if the question can be answered from the documents
  2. Research Agent: Generates answers based on retrieved context
  3. Verification Agent: Validates the accuracy of generated answers
  4. Hybrid Retriever: Combines vector similarity and BM25 search for optimal document retrieval

Features

  • 📄 PDF document ingestion and indexing
  • 🔍 Hybrid retrieval (Vector + BM25)
  • 🤖 Multi-agent workflow with LangGraph
  • ✅ Answer verification and quality control
  • 💬 Interactive chat interface with Streamlit
  • 🔄 Iterative answer refinement

Setup

1. Install Dependencies

pip install -r requirements.txt

2. Configure Environment Variables

Create a .env file in the project root:

cp .env.example .env

Edit .env and add your Groq API key:

GROQ_API_KEY=your_actual_api_key_here

Get your API key from: https://console.groq.com/keys

3. Run the Application

streamlit run app.py

Usage

  1. Upload PDFs: Click "Browse files" and select one or more PDF documents
  2. Wait for Indexing: The system will process and index your documents
  3. Ask Questions: Type your question in the chat input
  4. Get Answers: The multi-agent system will:
    • Check if the question is relevant to your documents
    • Retrieve relevant context
    • Generate an answer
    • Verify the answer's accuracy
    • Refine if needed (up to 2 iterations)
  5. View Verification: Click on the "🔍 Verification Report" expander below each answer to see:
    • Whether the answer is supported by the documents
    • Any unsupported claims
    • Any contradictions found
    • Relevance assessment
    • Additional details

Project Structure

.
├── agents/
│   ├── __init__.py
│   ├── relevance_checker.py    # Checks question relevance
│   ├── research_agent.py        # Generates answers
│   ├── verification_agent.py    # Validates answers
│   └── workflow.py              # LangGraph workflow orchestration
├── data/
│   ├── uploads/                 # Uploaded PDF files
│   └── llamaindex/              # Vector store index
├── app.py                       # Streamlit UI
├── config.py                    # Configuration settings
├── ingest.py                    # PDF processing and indexing
├── retriever.py                 # Hybrid retrieval implementation
├── requirements.txt             # Python dependencies
├── runtime.txt                  # Python version specification
└── .env.example                 # Environment variables template

Error Fixes Applied

Critical Fixes:

  1. Fixed TypeError in app.py: Removed the extra chat_history argument from workflow.full_pipeline() call
  2. Added API key validation: All agents now check for GROQ_API_KEY and raise informative errors if missing
  3. Improved error handling: Added try-catch blocks throughout the pipeline
  4. Added iteration limits: Prevents infinite loops in the verification-research cycle (max 2 iterations)
  5. Enhanced retriever error handling: Gracefully handles missing or corrupted indices
  6. Fixed verification report parsing: More robust parsing of LLM responses
  7. Added empty document checks: Handles cases where no documents are retrieved
  8. Improved logging: Better error messages and debugging information

Additional Improvements:

  • Added .env.example for easy setup
  • Enhanced error messages for better user experience
  • Added safeguards against missing/empty documents
  • Improved state management in the workflow
  • Better metadata handling in document conversion

Dependencies

  • streamlit: Web interface
  • llama-index: Document indexing and retrieval
  • langchain: Agent framework and document processing
  • langgraph: Workflow orchestration
  • langchain-groq: Groq LLM integration
  • sentence-transformers: Text embeddings
  • pypdf: PDF processing

Troubleshooting

"GROQ_API_KEY environment variable is not set"

  • Make sure you created a .env file with your API key
  • Verify the key is correctly formatted (no quotes or extra spaces)

"No index found. Upload PDFs first."

  • Upload at least one PDF document through the UI
  • Wait for the indexing process to complete

"Maximum iterations reached"

  • The system tried to refine the answer twice but couldn't verify it
  • This usually means the documents don't contain enough information
  • Try rephrasing your question or uploading more relevant documents

License

This project is for educational and demonstration purposes.