smartrag / README.md
ShaunGves's picture
Merge remote main and resolve README conflict
16859f0
|
Raw
History Blame Contribute Delete
4.2 kB
---
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
```bash
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