A practical collection of 10 Retrieval-Augmented Generation techniques — with working code, real benchmarks, and plain-English explanations.
RAG · Advanced RAG · RAG Techniques · LlamaIndex · Hybrid RAG · HyDE · Fusion RAG · Parent-Child RAG · Retrieval Augmented Generation
This cookbook covers 10 RAG techniques — from the simplest naive baseline to multi-stage reranking pipelines. Each technique has:
- A README that explains what it does, why it works, and when to use it (no fluff)
- A standalone Python script you can run directly
- Real benchmark numbers from actual tests (not estimates)
Built with LlamaIndex + OpenAI. Tested against the same document set across all techniques so the comparisons are fair.
If you've ever Googled "which RAG technique should I use" and got a vague answer — this repo is the practical answer to that question.
| # | Technique | Accuracy | Avg Latency | Best For |
|---|---|---|---|---|
| 01 | Naive RAG | Medium | ~4.7s | Baseline, simple docs, getting started |
| 02 | Unstructured RAG | Medium | ~4.9s | Scanned PDFs, images, OCR-heavy files |
| 03 | Contextual Compression | High | ~10s | Long docs, noisy datasets, high precision |
| 04 | Fusion RAG | High | ~7.5s | Ambiguous queries, better recall |
| 05 | Hybrid RAG ⭐ | High | ~5.6s | Best all-around — keyword + semantic |
| 06 | HyDE RAG | High | ~12.5s | Short/vague queries, Q&A over profiles |
| 07 | Parent-Child RAG | Very High | ~8.3s | Long documents, context-heavy answers |
| 08 | RRR RAG | High | ~5.3s | Conversational queries, chatbot interfaces |
| 09 | Sentence Compression | High | ~6-7s | Noisy chunks, reducing context tokens |
| 10 | Rerank + Compress | Very High | ~10-11s | Max precision, high-stakes QA |
Default choice with no constraints → Hybrid RAG — handles keyword and semantic queries, reliable across document types.
Users type conversationally → RRR RAG — rewrites vague queries before retrieval.
Scanned PDFs or images → Unstructured RAG — OCR layer handles what text readers can't.
Short, vague questions → HyDE RAG — generates a hypothetical answer and retrieves against that.
Long documents, need context in answers → Parent-Child RAG — small chunks for precision, large chunks for context.
Accuracy is the only priority → Rerank + Compress — two-stage post-processing, cleanest context.
Just learning RAG → Naive RAG — understand the baseline before adding complexity.
git clone https://github.com/Jeevav62/Rag-techniques.git
cd Rag-techniquespip install -r requirements.txtcp .env.example .env
# Edit .env → add your OPENAI_API_KEYOnly needed for Unstructured RAG when working with scanned PDFs/images.
| OS | Command |
|---|---|
| macOS | brew install tesseract |
| Ubuntu | sudo apt-get install tesseract-ocr |
| Windows | Download installer |
Each techniques/XX/ folder has a standalone script. Update SAMPLE_FILES and SAMPLE_QUERY at the top, then:
cd techniques/05_hybrid_rag
python hybrid_rag.pyOutput includes: answer, latency, token count, and the exact chunks retrieved.
Try all 10 techniques side by side with your own documents:
python app.pyOpens at http://localhost:7860 — upload any PDF/doc/image, pick a technique, compare outputs.
All techniques tested on the same personal document QA dataset (bio/resume-style questions — "where does this person work?", "what city are they in?", etc.)
| Technique | Accuracy | Avg Latency | Extra LLM Calls |
|---|---|---|---|
| Naive RAG | Medium | 4.7s | 0 |
| Unstructured RAG | Medium | 4.9s | 0 |
| Contextual Compression | High | 10.0s | 1 (reranker) |
| Fusion RAG | High | 7.5s | 1 (query expansion) |
| Hybrid RAG | High | 5.6s | 0 |
| HyDE RAG | High | 12.5s | 1 (hypothesis gen) |
| Parent-Child RAG | Very High | 8.3s | 0 |
| RRR RAG | High | 5.3s | 1 (query rewrite) |
| Sentence Compression | High | 6-7s | 0 |
| Rerank + Compress | Very High | 10-11s | 1 (reranker) |
Before RAG comes chunking. If you want to understand how documents should be split before retrieval, check out the companion repo: Chunking Techniques — 6 strategies from fixed-size to agentic, with the same format as this cookbook.
| Component | Library |
|---|---|
| RAG Framework | LlamaIndex 0.10+ |
| LLM | OpenAI GPT-4o-mini |
| Embeddings | OpenAI text-embedding-3-large |
| Document Parsing | Unstructured |
| Sparse Retrieval | BM25 (rank-bm25) |
| UI | Gradio |
Rag-techniques/
├── app.py # Gradio demo — all 10 techniques
├── requirements.txt
├── .env.example
├── rag/ # Package imported by app.py
│ ├── naive_rag.py
│ ├── unstructured_rag.py
│ ├── contextual_rag.py
│ ├── fusion_rag.py
│ ├── hybrid_rag.py
│ ├── hyde_rag.py
│ ├── parent_child_rag.py
│ ├── rrr_rag.py
│ ├── sentence_compression_rag.py
│ └── rerank_compress_rag.py
└── techniques/ # Standalone scripts + docs per technique
├── 01_naive_rag/
├── 02_unstructured_rag/
├── 03_contextual_compression/
├── 04_fusion_rag/
├── 05_hybrid_rag/
├── 06_hyde_rag/
├── 07_parent_child_rag/
├── 08_rrr_rag/
├── 09_sentence_compression/
└── 10_rerank_compress/
Found a bug? Want to add a technique? PRs are welcome.
- Fork the repo
- Add your technique in
techniques/XX_<name>/with a README + script - Add the
run_rag()function torag/<name>.pyand register it inrag/__init__.pyandapp.py - Open a PR
MIT — use it, modify it, share it.
If this helped you understand RAG better, consider giving it a ⭐