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.
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 |
- 📄 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
┌─────────────────────────────────────────────────────────────────┐
│ 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 │ │ │ └─────────────┘ │
│ └─────────────┘ │ │ └─────────────┘ │ │ │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- Python ≥ 3.12
- Node.js ≥ 18
- UV (Python package manager) -
pip install uv - API Keys :
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# Run FastAPI server
uv run uvicorn src.api.main:app --host 0.0.0.0 --port 8000 --reloadcd frontend
npm install
npm run devVisit http://localhost:5173 and start chatting with your documents! 🎉
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
