Skip to content

Repository files navigation

The RAG Cookbook 2026

Recipes for production-grade retrieval — forty hands-on chapters covering the state of the art in retrieval-augmented generation, all runnable end-to-end on Nebius AI Studio (or any OpenAI-compatible provider).

Python License Docs Recipes


Why this exists

Most RAG tutorials stop at "embed a PDF, do cosine search, hand it to GPT." That worked in 2023. In 2026, production RAG looks completely different: late chunking, contextual retrieval, multi-vector late interaction, listwise rerankers, speculative drafters, agentic workflows over MCP servers, dual-level graph indexes, page-as-image vision retrieval, and compiled DSPy pipelines that out-perform anything a prompt engineer can hand-tune.

This cookbook teaches all of it. Forty self-contained recipes. Every recipe ships with theory, implementation, output discussion, and an evaluation harness. Nothing is hidden behind framework magic.

Quick start

# 1. Clone and install
git clone https://github.com/FareedKhan-dev/rag-cookbook-2026.git
cd rag-cookbook-2026
uv sync                          # or: pip install -e ".[docs,dev]"

# 2. Add your keys (Nebius is the default; OpenAI/Anthropic/Groq optional)
cp .env.example .env
$EDITOR .env

# 3. Download the public-domain corpus (one-time, ~150 MB)
uv run python scripts/fetch_corpus.py

# 4. Launch a recipe
uv run jupyter lab recipes/01-foundations/vanilla-pipeline.ipynb

Want to read the cookbook in your browser instead? uv run mkdocs servehttp://localhost:8000

Recipe Index

# Category Recipe Idea Best for
1 Foundations cookbook-tour Provider switcher, corpus, tracing First read
2 Foundations vanilla-pipeline The baseline you'll beat 38 times Mental model
3 Foundations embedding-zoo Voyage / BGE-M3 / Nebius / Qwen3 head-to-head Picking a model
4 Foundations chunk-size-sensitivity Sweep sizes, measure recall Tuning
5 Chunking semantic-boundary-splitting Split at embedding-distance breakpoints Mixed-topic docs
6 Chunking late-chunking-jina Embed first, chunk after Long context
7 Chunking contextual-retrieval-anthropic LLM-written "where this fits" headers Highest ROI tweak
8 Chunking proposition-decomposition Atomic-claim units Dense factual recall
9 Chunking sentence-window-and-parent-child Small to find, big to read Precision + synthesis
10 Chunking raptor-trees Recursive summary tree Multi-hop reasoning
11 Chunking document-summary-routing Doc summaries → sub-chunks Heterogeneous corpora
12 Chunking matryoshka-coarse-to-fine MRL embeddings, two-stage Low-latency search
13 Query hypothetical-document-embeddings HyDE Zero-shot retrieval
14 Query multi-query-rag-fusion N rewrites + RRF Recall boost
15 Query step-back-abstraction Abstract then ground Reasoning questions
16 Query sub-question-decomposition Tree of sub-queries Complex queries
17 Query semantic-router Classify and dispatch Multi-index systems
18 Retrieval hybrid-dense-plus-bm25 Dense + BM25 + RRF on Qdrant Real workloads
19 Retrieval colbert-late-interaction Token-level MaxSim Highest accuracy
20 Retrieval auto-retrieval-with-metadata LLM extracts filters Structured corpora
21 Retrieval mmr-diversity Penalize redundancy Diverse top-k
22 Reranking cross-encoder-rerank bge / Cohere / Jina Quality lift
23 Reranking listwise-llm-rerank RankGPT-style When budget allows
24 Agentic self-reflective-retrieval Self-RAG reflection tokens Selective retrieval
25 Agentic corrective-retrieval-with-web-fallback CRAG Robust answers
26 Agentic adaptive-routing-by-question-class Adaptive RAG Mixed query types
27 Agentic speculative-rag-drafter-verifier Small drafter, big verifier Latency-bound apps
28 Agentic langgraph-agentic-rag Stateful cyclic graph Tool-using agents
29 Agentic mcp-tool-retrieval Retrieval over MCP servers Modular tools
30 Agentic dspy-compiled-rag Optimize, don't prompt-engineer Repeatable pipelines
31 Graph microsoft-graphrag-pipeline Communities + global/local Global questions
32 Graph lightrag-dual-level LightRAG Cheap incremental KG
33 Graph hipporag-pagerank-memory PageRank over KG Multi-hop facts
34 Graph mem0-long-term-memory Persistent agent memory Chat assistants
35 Multimodal colpali-page-as-image VLM patch embeddings of PDFs No-OCR pipelines
36 Multimodal vlm-synthesis-over-pages ColPali → Qwen-VL Visual answers
37 Eval ragas-triad-eval Faithfulness / relevance / precision Default metrics
38 Eval deepeval-pytest-ci Metrics in CI Regression catch
39 Eval phoenix-tracing-debugging End-to-end OTel traces Debugging
40 Eval hallucination-guardrails-lynx Patronus Lynx Production safety

Stack

Layer Default Notes
LLM provider Nebius AI Studio Switchable to OpenAI, Anthropic, Groq, OpenRouter, Together via one env var
Provider abstraction LiteLLM Single LLMClient wraps chat / embed / rerank
Embeddings voyage-3-large, BGE-M3, Qwen3-Embedding-8B, Nebius Compared head-to-head in recipe 3
Rerankers Cohere Rerank 4, bge-reranker-v2-m3, jina-reranker-v3 Recipe 22
Vector store Qdrant in-memory by default; LanceDB and Chroma also wrapped Native hybrid + multi-vector
Graph store NetworkX (Neo4j optional) Recipes 31–34
Agent frameworks LangGraph, LlamaIndex Workflows, DSPy One recipe each
Tracing Arize Phoenix (local) + LangSmith (agentic) One-line init_tracing()
Evaluation RAGAS + DeepEval Plus Patronus Lynx guardrails
Documentation MkDocs Material + mkdocs-jupyter Served at mkdocs serve

Corpus

Four fresh, public-domain document sets — chosen to exercise every technique without overlapping any other RAG tutorial:

  1. A recent arXiv paper on state-space models (not "Attention Is All You Need")
  2. A Wikipedia subset on superconductors (~50 markdown pages)
  3. Palantir's 2024 SEC 10-K (text extracted, public filing)
  4. A curated chapter set from The Rust Programming Language (CC-BY)

Fetch reproducibly with uv run python scripts/fetch_corpus.py --verify.

Notebook structure

Every recipe follows the same six sections:

  1. What & Why — original paper / blog, when this technique helps, when it doesn't
  2. Setup — provider switch, tracing, corpus load (one cell)
  3. Build the Pipeline — the implementation, broken into small reviewable cells
  4. Run on Corpus — execute against one of the four corpora
  5. Discuss the Output — markdown analysis of what came out, failure modes, observations
  6. Evaluate — RAGAS / DeepEval metrics plus one custom assertion

Contributing

Issues and pull requests welcome. New techniques are added under the appropriate category as <technique-slug>.ipynb, following the six-section template above. See docs/theory/ for the conceptual framing you should match.

Citing

If this cookbook helps your research or teaching, please cite it via the CITATION.cff file.

License

Apache-2.0 © 2026 Fareed Khan.

About

Forty hands-on recipes for production-grade retrieval-augmented generation, Nebius-first and provider-agnostic.

Topics

Resources

Stars

23 stars

Watchers

0 watching

Forks

Contributors

Languages