Skip to content

kushalgarg101/Advanced_Rag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advanced RAG

Lego RAG Interface


An advanced, modular Retrieval-Augmented Generation system that connects to your documents with intelligent strategies. It offers multiple retrieval modes from quick facts to deep knowledge graph exploration.


🚀 Features

🔍 Multiple RAG Strategies

Lego RAG doesn't just retrieve it thinks about how to best answer your question:

Strategy Best For Description
⚡ Quick Fact Simple questions Fast semantic + keyword search for direct answers
🔬 Verbose Mode Deep context Comprehensive retrieval with rich, detailed responses
🌐 Web Intelligence Real-time info Search public internet when documents aren't enough
🔗 Connect Dots Complex relationships Knowledge Graph RAG that traverses entity connections

🎯 Key Capabilities

  • 📄 Multi-Document Support - Upload and cross-reference multiple PDFs, DOCX, and TXT files
  • 🧠 Knowledge Graph - Automatically extracts entities and relationships for connection-based reasoning
  • 🔄 Hybrid Retrieval - Combines vector similarity, keyword matching, and graph traversal
  • 📊 Confidence Scoring - Built-in response verification with confidence thresholds
  • 💬 Persistent Chat - Conversation history with context-aware responses
  • ⚙️ Real-time Settings - Adjustable parameters (alpha, top-K, threshold) during chats

🏗️ Architecture

┌─────────────────────────────────────────────────────────────────┐
│                         FRONTEND                                │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐           │
│  │   Sidebar    │  │    Chat      │  │  Knowledge   │           │
│  │   (Chats)    │  │  Interface   │  │   Panel      │           │
│  └──────────────┘  └──────────────┘  └──────────────┘           │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                   FASTAPI BACKEND                               │
│  ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌────────────┐ │
│  │   Chat API  │ │ System API  │ │  Database   │ │  SSE Stream│ │
│  └─────────────┘ └─────────────┘ └─────────────┘ └────────────┘ │
└─────────────────────────────────────────────────────────────────┘
                              │
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                  ORCHESTRATOR (Pipeline)                        │
│  ┌─────────┐   ┌─────────┐   ┌─────────┐   ┌─────────┐          │
│  │ Routing │ → │Schedule │ → │ Fusion  │ → │ Judging │          │
│  └─────────┘   └─────────┘   └─────────┘   └─────────┘          │
└─────────────────────────────────────────────────────────────────┘
                              │
         ┌────────────────────┼────────────────────┐
         ▼                    ▼                    ▼
┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐
│  RETRIEVER      │  │     INDEXER     │  │   GENERATOR     │
│ ┌─────────────┐ │  │ ┌─────────────┐ │  │ ┌─────────────┐ │
│ │ Pre-Process │ │  │ │ Documents   │ │  │ │ LLM Adapter │ │
│ │ Vector DB   │ │  │ │ Chunking    │ │  │ │ Streaming   │ │
│ │ Knowledge G │ │  │ │ Embeddings  │ │  │ │ Response    │ │
│ │ Post-Process│ │  │ │ Graph Build │ │  │ └─────────────┘ │
│ └─────────────┘ │  │ └─────────────┘ │  │                 │
└─────────────────┘  └─────────────────┘  └─────────────────┘

📋 Prerequisites

  • Python ≥ 3.12
  • Node.js ≥ 18
  • UV (Python package manager) - pip install uv
  • API Keys :
    • Groq - For LLM generation
    • Tavily - For web search capabilities

⚡ Quick Start

1. Clone & Setup

git clone <your-repo-url>
cd lego_rag

# Install Python dependencies
uv sync

# Setup environment
cp .env.example .env
# Edit .env with your paths and API keys

Start Backend

# Run FastAPI server
uv run uvicorn src.api.main:app --host 0.0.0.0 --port 8000 --reload

Start Frontend

cd frontend
npm install
npm run dev

Visit http://localhost:5173 and start chatting with your documents! 🎉


📂 Project Structure

lego_rag/
├── src/
│   ├── api/                    # FastAPI application
│   │   ├── main.py            # Entry point
│   │   ├── chat_routes.py     # Chat endpoints
│   │   ├── system_routes.py   # Upload & status
│   │   └── database.py        # SQLite persistence
│   ├── retriever/             # Multi-stage retrieval
│   │   ├── pre_retriever.py   # Query expansion
│   │   ├── retriever.py       # Hybrid retrieval
│   │   └── post_retriever.py  # Reranking & filtering
│   ├── indexer/               # Document indexing
│   │   └── indexer.py         # Vector DB + Graph builder
│   ├── ingestion/             # Document loaders
│   │   ├── pdf.py            # PDF processor
│   │   ├── docs.py           # DOCX processor
│   │   └── text.py           # TXT processor
│   ├── orchestrator.py        # Pipeline coordination
│   ├── generation.py          # LLM response generation
│   └── model_adapters.py      # Provider adapters
├── frontend/
│   ├── src/
│   │   ├── components/       # React components
│   │   │   ├── ChatInterface.tsx
│   │   │   ├── Sidebar.tsx
│   │   │   └── KnowledgePanel.tsx
│   │   └── services/api.ts   # API client
│   └── package.json
├── local_model_files/         # Local embedding model
└── assets/
    ├── documents/            # Upload directory
    └── rag_index/            # Vector DB & knowledge graph

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors