Views
No views yet
Production-grade Retrieval-Augmented Generation with hybrid retrieval, graph-based reasoning, and rigorous evaluation
| Tier | What It Does | How It's Different |
|---|---|---|
| Tier 1: Basic | Dense vector search → LLM | Baseline (what tutorials teach) |
| Tier 2: Hybrid | BM25 + Dense + RRF fusion + Cross-encoder reranking → LLM | Production-grade retrieval |
| Tier 3: Graph | LightRAG knowledge graph + multi-hop reasoning → LLM | Research-grade, multi-hop Q&A |
| Metric | Tier 1 (Basic) | Tier 2 (Hybrid) | Tier 3 (Graph) |
|---|---|---|---|
| Faithfulness | ~X.XX | ~X.XX | ~X.XX |
| Answer Relevancy | ~X.XX | ~X.XX | ~X.XX |
| Context Recall | ~X.XX | ~X.XX | ~X.XX |
| Context Precision | ~X.XX | ~X.XX | ~X.XX |
┌──────────────────────────────────────────────────────────────────┐
│ Advanced RAG Pipeline │
│ │
│ 📄 Documents │
│ │ │
│ ├──▶ 🔤 Chunking (recursive, 512 tokens, 50 overlap) │
│ │ │
│ ├──▶ 📊 TIER 1: Dense Retrieval │
│ │ └── BGE-small embeddings → FAISS index → Top-K │
│ │ │
│ ├──▶ 📊 TIER 2: Hybrid Retrieval │
│ │ ├── BM25 (sparse) ──┐ │
│ │ ├── BGE (dense) ────┤── RRF Fusion → Cross-encoder → Top-K│
│ │ └── Reciprocal Rank Fusion │
│ │ │
│ └──▶ 📊 TIER 3: Graph Retrieval (LightRAG) │
│ ├── Entity Extraction → Knowledge Graph │
│ ├── Local queries (specific entities) │
│ ├── Global queries (abstract themes) │
│ └── Hybrid mode (best of both) │
│ │
│ ❓ Query │
│ │ │
│ ├──▶ Retrieve relevant contexts (any tier) │
│ ├──▶ Rerank with cross-encoder │
│ ├──▶ Generate answer with LLM (Groq API / HF Inference) │
│ └──▶ Evaluate with RAGAS (faithfulness, relevancy, recall) │
│ │
│ 🖥️ Gradio Interface │
│ ├── Chat tab (ask questions) │
│ ├── Upload tab (add documents) │
│ ├── Compare tab (side-by-side tier comparison) │
│ └── Eval tab (RAGAS scores) │
└──────────────────────────────────────────────────────────────────┘| Component | Tool | Why |
|---|---|---|
| Dense Embeddings | BAAI/bge-small-en-v1.5 (33MB) | Best quality/size ratio, CPU-fast |
| Sparse Retrieval | rank_bm25 | Classic term-matching, complements dense |
| Fusion | Reciprocal Rank Fusion (RRF) | No tuning needed, robust across domains |
| Reranker | cross-encoder/ms-marco-MiniLM-L6-v2 | Best CPU reranker (74.3 NDCG@10) |
| Graph RAG | LightRAG (34K GitHub stars) | Entity-relationship graphs for multi-hop |
| LLM | Groq API (free, Llama 3.3 70B) | Zero cost, fast, high quality |
| Evaluation | RAGAS | Standard RAG evaluation framework |
| Frontend | Gradio → HF Spaces | Free deployment, no GPU needed |
| Vector Store | FAISS (CPU) | Fast, no server needed |
project2_advanced_rag/
├── README.md # This file
├── requirements.txt # Dependencies
├── rag_engine.py # Core RAG engine (all 3 tiers)
├── evaluation.py # RAGAS evaluation pipeline
├── app.py # Gradio web interface
├── ingest_sample_data.py # Download & index sample documents
├── config.py # Configuration (API keys, model names)
└── sample_data/ # Sample documents for demo
└── README.md1# 1. Install dependencies
2pip install -r requirements.txt
3
4# 2. Set up API key (free!)
5# Go to https://console.groq.com → Get API key
6export GROQ_API_KEY="your-key-here"
7
8# 3. Index sample documents
9python ingest_sample_data.py
10
11# 4. Launch the app
12python app.py
13# Opens at http://localhost:78601# 1. Create a new Space on huggingface.co
2# 2. Upload all files
3# 3. Add GROQ_API_KEY to Space secrets
4# 4. It deploys automatically!| Service | What For | Link |
|---|---|---|
| Groq | LLM (Llama 3.3 70B) | console.groq.com |
| HuggingFace | Embeddings (optional, runs locally) | huggingface.co/settings/tokens |