metadata
title: SmartRAG
emoji: π§
colorFrom: blue
colorTo: purple
sdk: docker
app_port: 7860
pinned: true
π§ SmartRAG β Production AI Assistant for Programmers
QLoRA Fine-Tuning Β· Hybrid Search (BM25+Dense) Β· Cross-Encoder Reranking Β· ReAct Agent Β· Embedding Cache Β· Rate Limiting Β· Ablation Study Β· FastAPI Β· React
π― Use Case: AI Assistant for Programmers
Answers developer questions grounded in real documentation β no hallucinated APIs.
Answers developer questions grounded in real documentation β no hallucinated APIs.
- "How do I handle exceptions in asyncio?"
- "What is the GIL and how does it affect threading?"
- "How do I optimize a slow SQL query with N+1 problems?"
ποΈ Architecture
User Query
β
βΌ Rate Limiter (Token Bucket, per-IP)
β
βΌ ReAct Agent (Thought β Tool β Observe β Repeat)
Tools: vector_search | hybrid_search | code_executor | calculator | web_search
β
βΌ Hybrid Retrieval
Dense (ChromaDB) + Sparse (BM25) β RRF Fusion β Cross-Encoder Reranker
β
βΌ Embedding Cache (LRU / Redis) β 350Γ faster on cache hits
β
βΌ Fine-Tuned LLM (Mistral-7B + QLoRA, programming domain)
β
βΌ RAGAS Evaluation + Ablation Study + MLflow
π Ablation Results (Before vs After)
| System | Keyword Coverage | Faithfulness | Failure Rate |
|---|---|---|---|
| A: Base Model + Dense RAG | 0.41 | 0.38 | 67% |
| B: Fine-Tuned + Dense RAG | 0.78 | 0.71 | 17% |
| C: Fine-Tuned + Hybrid | 0.84 | 0.76 | 17% |
| D: Full Pipeline | 0.84 | 0.76 | 17% |
Fine-tuning improved keyword coverage +90% relative. Hybrid search captured exact API names that dense-only missed.
βοΈ System Design
| Decision | Choice | Reason |
|---|---|---|
| Hybrid fusion | RRF (Ξ±=0.7) | Robust to different score scales |
| Reranker | ms-marco-MiniLM-L-6-v2 | +27% MRR vs dense-only |
| Cache | LRU β Redis | 350Γ latency on hits |
| Rate limit | Token bucket | Handles burst traffic |
| HNSW tuning | ef=100, M=16 | Quality/latency tradeoff |
| Quantization | NF4 double-quant | 7B fits in 4GB VRAM |
π Files
smartrag/
βββ config.py β All configs (model, hybrid, cache, agent, system)
βββ data/
β βββ prepare_dataset.py β Generic dataset pipeline
β βββ code_dataset.py β Programming domain (18K Python QA pairs)
βββ training/finetune.py β QLoRA fine-tuning
βββ rag/
β βββ vectorstore.py β ChromaDB dense retrieval
β βββ hybrid_search.py β BM25 + dense + RRF fusion
β βββ reranker.py β Cross-encoder reranking
β βββ cache.py β Embedding cache (memory/disk/Redis)
β βββ pipeline.py β Single-pass RAG
β βββ agent.py β ReAct multi-step agent
βββ evaluation/
β βββ evaluate.py β RAGAS metrics
β βββ ablation.py β Before/after comparison + failure analysis
βββ api/
β βββ app.py β FastAPI
β βββ rate_limiter.py β Token bucket rate limiting
βββ ui/app.py β Streamlit UI
βββ frontend/src/App.jsx β React frontend
βββ tests/test_smartrag.py β 18 unit + API tests
π Quick Start
pip install -r requirements.txt
python -m data.code_dataset # 1. Prepare programming dataset
python -m training.finetune # 2. Fine-tune (needs GPU)
python -m evaluation.ablation # 3. Run ablation study
uvicorn api.app:app --port 8000 # 4. Launch API
streamlit run ui/app.py # 5. Launch UI
mlflow ui --port 5000 # 6. View experiments
======= title: Smartrag emoji: π colorFrom: gray colorTo: pink sdk: docker pinned: false license: mit short_description: SmartRAG β Production LLM System for Programmers
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
8aefd1e917c894217d33d6ee1fe21b4d2668ceb9