Downloads ยท 30 days
0
Neha12210/project2-advanced-rag
project2-advanced-rag is a machine learning model from Neha12210. Use it for the machine learning task on the model card, and read the license before you ship it in a product.
Production-grade Retrieval-Augmented Generation with hybrid retrieval, graph-based reasoning, and rigorous evaluation
Downloads ยท 30 days
0
Access
Public
Updated Apr 24, 2026
Repo size
โ
Likes
0
Public
Click a slice to open those files.
.py60.4 KB ยท 87%
From the Hugging Face model README
Production-grade Retrieval-Augmented Generation with hybrid retrieval, graph-based reasoning, and rigorous evaluation
A 3-tier RAG system that goes far beyond basic "vector search โ LLM" tutorials:
| 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 |
All three tiers are evaluated with RAGAS metrics to prove the improvements aren't just theoretical.
| 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 |
(Fill in after running evaluation โ these numbers go in your resume!)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ 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.md
# 1. Install dependencies
pip install -r requirements.txt
# 2. Set up API key (free!)
# Go to https://console.groq.com โ Get API key
export GROQ_API_KEY="your-key-here"
# 3. Index sample documents
python ingest_sample_data.py
# 4. Launch the app
python app.py
# Opens at http://localhost:7860
# 1. Create a new Space on huggingface.co
# 2. Upload all files
# 3. Add GROQ_API_KEY to Space secrets
# 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 |