Aigenthix/Graph_RAG
0
1---2title: RAG Comparison Suite3emoji: ๐ฌ4colorFrom: purple5colorTo: blue6sdk: docker7app_file: app_docker.py8pinned: false9---10 11# ๐ฌ RAG Comparison Suite12 13Compare **Simple RAG** vs **Agentic RAG** vs **Graph RAG** performance on your documents.14 15A production-ready application for benchmarking and analyzing three different Retrieval-Augmented Generation approaches using Groq's fastest LLMs.16 17---18 19## โจ Features20 21### ๐ฏ Three RAG Modes22 23**Simple RAG** - Fast & Cost-Effective24- Direct retrieval + generation25- Average latency: 620ms26- Best for: Real-time applications, FAQ systems27- Cost: $0.0018/query28 29**Agentic RAG** - Accurate & Complex30- Multi-step reasoning with tool use31- Average latency: 1800ms32- Best for: Research, problem-solving33- Cost: $0.0045/query34 35**Graph RAG** - Balanced & Relational36- Knowledge graph-based retrieval37- Average latency: 950ms38- Best for: Entity relationships, knowledge bases39- Cost: $0.0030/query40 41### ๐ค Four Groq Models42 431. **Llama 3.1 8B** - Fastest (for real-time)442. **Llama 3.3 70B** - Best Quality453. **GPT-OSS 120B** - Enterprise-Grade464. **GPT-OSS 20B** - Balanced47 48### ๐ Advanced Features49 50โ
**Document Upload** - PDF and CSV support 51โ
**Real-time Metrics** - Latency, tokens, cost tracking 52โ
**Benchmarking** - Automated performance testing 53โ
**HTML Reports** - Professional result visualization 54โ
**Source Citations** - Track which documents were used 55โ
**Performance Tuning** - Temperature and top-k controls 56โ
**Cost Analysis** - Per-query cost breakdown 57โ
**Comparison Matrix** - Side-by-side mode comparison 58 59---60 61## ๐ Quick Start62 63### 1. Add API Key64 65- Go to **Settings** โ **Repository secrets**66- Add secret: `GROQ_API_KEY`67- Get key from: https://console.groq.com/keys68 69### 2. Upload Document70 71- Click **Upload** button72- Select PDF or CSV file (max 50MB)73- Wait for processing74 75### 3. Submit Query76 77- Type your question78- Select RAG mode (Simple, Agentic, or Graph)79- Choose model (8B, 70B, 120B, or 20B)80- Click **Submit**81 82### 4. View Results83 84- See generated answer85- Check metrics:86 - โฑ๏ธ Response time (ms)87 - ๐ข Token usage88 - ๐ฐ Cost estimate89 - ๐ Sources used90 - ๐ฏ Confidence score91 92### 5. Compare Modes93 94- Try different RAG modes on same query95- Compare performance metrics96- Choose best mode for your use case97 98---99 100## ๐ Performance Comparison101 102### Latency (milliseconds)103```104Query Type Simple Agentic Graph105โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ106Direct Fact Lookup 620 1800 950107Multi-Document 1200 3200 1800108Complex Reasoning 1500 3800 2100109```110 111### Accuracy (by query type)112```113Query Type Simple Agentic Graph114โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ115Direct Lookup 100% 100% 100%116Inference 78% 88% 85%117Multi-doc Summary 72% 82% 80%118```119 120### Cost per Query121```122Simple RAG: $0.0018 โ Cheapest123Graph RAG: $0.0030 (1.7x)124Agentic RAG: $0.0045 (2.5x)125```126 127### Monthly Cost (10,000 queries)128```129Simple RAG: $18130Graph RAG: $30131Agentic RAG: $45132```133 134---135 136## ๐ฏ Use Cases137 138### Use Simple RAG When...139โ Response time < 1 second required 140โ Budget-conscious ($15-20/month) 141โ Simple fact lookups 142โ High throughput needed (>1000 qps) 143โ Real-time applications 144 145**Examples:** FAQ systems, document search, knowledge lookup146 147### Use Agentic RAG When...148โ Accuracy > 85% required 149โ Multi-step reasoning needed 150โ Complex document synthesis 151โ Tool use / sub-queries needed 152โ Expert analysis required 153 154**Examples:** Research synthesis, problem-solving, analysis reports155 156### Use Graph RAG When...157โ Entity relationships important 158โ Knowledge extraction critical 159โ Balanced latency/accuracy (1-2s) 160โ Domain expertise required 161โ Complex document linking 162 163**Examples:** Knowledge bases, expert systems, relationship queries164 165---166 167## ๐ง Configuration168 169### Temperature & Sampling170```171For Creative Responses (Agentic):172 temperature: 0.8173 top_k: 40174 175For Factual Responses (Simple, Graph):176 temperature: 0.3177 top_k: 10178```179 180### Chunk Settings181```182Simple RAG: 512 tokens/chunk183Agentic RAG: 1024 tokens/chunk184Graph RAG: 256 tokens/chunk185```186 187### Model Selection Guide188```189Fast needed? โ Llama 3.1 8B190Quality needed? โ Llama 3.3 70B191Enterprise grade? โ GPT-OSS 120B192Balanced? โ GPT-OSS 20B193```194 195---196 197## ๐ Benchmarking198 199### Run Local Benchmarks200 201```bash202# Benchmark all modes (10 iterations each)203python benchmark.py --mode all --iterations 10204 205# Benchmark specific mode206python benchmark.py --mode simple --model llama-3.1-8b-instant207 208# With custom output209python benchmark.py --output my_results.json210```211 212### Generate HTML Reports213 214```bash215# Generate report from benchmark results216python rag_comparison_report.py217 218# View in browser219open rag_comparison_report.html220```221 222---223 224## ๐ Documentation225 226### Getting Started227- **[Deployment Guide](HF_DEPLOYMENT_GUIDE.md)** - Step-by-step deployment228- **[Quick Reference](README_HF_UPLOAD.txt)** - Files & commands229 230### Understanding RAG Modes231- **[Comparison Guide](HF_RAG_COMPARISON.md)** - Detailed comparison232- **[Sample Results](BENCHMARK_DATA_SAMPLES.md)** - Real examples233 234### Advanced Topics235- **[File Manifest](HF_UPLOAD_MANIFEST.md)** - File inventory236- **[Complete Package](HF_COMPLETE_PACKAGE.md)** - Full overview237 238---239 240## ๐ ๏ธ Supported Formats241 242| Aspect | Details |243|--------|---------|244| **Documents** | PDF, CSV |245| **Max File Size** | 50 MB |246| **Models** | 4 Groq models |247| **RAG Modes** | 3 comparison modes |248| **Languages** | English (extensible) |249 250---251 252## โ๏ธ Technical Details253 254### Architecture255- **Frontend:** HTML5 + CSS3 + Vanilla JavaScript256- **Backend:** Flask (Python 3.11+)257- **LLM Provider:** Groq API258- **Embeddings:** Sentence Transformers (all-MiniLM-L6-v2)259- **Vector DB:** Chromadb260- **Document Parsing:** PyPDF2, Pandas261 262### Requirements263- Python 3.11+264- 4GB RAM minimum265- 500MB disk space266- Groq API key267 268### Performance269- Initial load: ~30 seconds270- Query response: 600ms - 4000ms271- Document processing: Varies by size272- Memory usage: 2-4GB273 274---275 276## ๐ Security277 278โ
API keys stored in HF Secrets (not in code) 279โ
Input validation on all queries 280โ
File upload size limited (50MB) 281โ
No sensitive data in logs 282โ
CORS properly configured 283โ
Dependencies pinned to versions 284 285---286 287## ๐ Support & Troubleshooting288 289### Common Issues290 291**Q: API Key Error**292A: Verify `GROQ_API_KEY` is set in Space Settings โ Secrets293 294**Q: Models Not Showing**295A: Check browser console, try hard refresh (Cmd+Shift+R)296 297**Q: Query Timeout**298A: Try with smaller document, use faster model (8B), or check Groq API status299 300**Q: Upload Fails**301A: File must be <50MB, PDF or CSV format, valid encoding302 303**Q: Build Failed**304A: Check logs in Space, verify Python 3.11 available305 306### Get Help307 308- **Deployment:** See `HF_DEPLOYMENT_GUIDE.md` โ Troubleshooting309- **Comparison:** See `HF_RAG_COMPARISON.md` โ Use Cases310- **Benchmarking:** See `BENCHMARK_DATA_SAMPLES.md` โ Examples311- **Files:** See `HF_UPLOAD_MANIFEST.md` โ Inventory312 313---314 315## ๐ Deployment Info316 317**Status:** โ
Production Ready 318**Version:** 2.0 319**Size:** ~600 KB 320**Deploy Time:** 25-30 minutes 321**Cost:** Free HF Spaces + Groq API usage 322 323### Deploy Locally324 325```bash326pip install -r requirements_hf.txt327export GROQ_API_KEY=your_key_here328python app_docker.py329# Visit http://localhost:5000330```331 332### Deploy on HF Spaces333 334See `HF_DEPLOYMENT_GUIDE.md` for step-by-step instructions.335 336---337 338## ๐ Comparison Matrix339 340| Feature | Simple RAG | Agentic RAG | Graph RAG |341|---------|-----------|------------|-----------|342| **Speed** | โกโกโก Fast | โก Slow | โกโก Medium |343| **Accuracy** | โญโญ Good | โญโญโญ Excellent | โญโญโญ Excellent |344| **Cost** | ๐ฐ Low | ๐ฐ๐ฐ๐ฐ High | ๐ฐ๐ฐ Medium |345| **Complexity** | Simple | Complex | Medium |346| **Latency** | 600ms | 1800ms | 950ms |347| **Sources** | 1-2 | 4-5 | 3-4 |348 349---350 351## ๐ Learning Resources352 353### For Understanding RAG3541. Read: `HF_RAG_COMPARISON.md`3552. Review: Comparison matrices3563. See: Sample results below357 358### For Using This App3591. Upload test document3602. Try different RAG modes3613. Compare metrics3624. Pick best for your use case363 364### For Advanced Usage3651. Run `benchmark.py` locally3662. Generate HTML reports3673. Analyze batch results3684. Optimize settings369 370---371 372## ๐ก Tips & Best Practices373 374### For Best Results3751. **Document Quality:** Clear, well-structured text3762. **Query Specificity:** Detailed questions get better answers3773. **Model Selection:** Match model to latency requirements3784. **Mode Selection:** Use comparison matrix to decide3795. **Temperature:** Lower = factual, Higher = creative380 381### For Cost Optimization3821. Use Simple RAG when possible3832. Use Llama 8B instead of 70B3843. Batch similar queries3854. Monitor token usage3865. Review monthly costs387 388### For Accuracy Improvement3891. Use Agentic RAG for complex queries3902. Increase document chunk overlap3913. Use larger models (70B, 120B)3924. Provide detailed context3935. Test with representative queries394 395---396 397## ๐ Quick Stats398 399| Metric | Value |400|--------|-------|401| **RAG Modes** | 3 |402| **Models** | 4 |403| **Languages** | English (extensible) |404| **Max Upload** | 50 MB |405| **Avg Response** | 1.2 seconds |406| **Cost Range** | $0.0018-0.0045/query |407| **Monthly (10k)** | $18-45 |408 409---410 411## ๐ Ready to Compare?412 4131. โ
Add your `GROQ_API_KEY` to Secrets4142. โ
Upload your document4153. โ
Submit a query4164. โ
Compare the results!417 418**Questions?** See the documentation links above.419 420---421 422**Status:** โ
Production Ready | **Version:** 2.0 | **Updated:** 2026-06-25423 424๐ฌ **Start comparing RAG modes now!**425 