← Learning

Hybrid RAG: Combining Dense and Sparse Retrieval

A linear, one-concept-per-lesson path through Hybrid RAG, dense (embedding) retrieval combined with sparse (keyword) retrieval, from hand-rolled BM25 to a complete FastAPI hybrid retrieval service. 26 lessons · 3 tiers.

Prerequisites: Comfortable writing basic Python. Assumes you've done this site's Naive RAG course (or otherwise know what dense retrieval, cosine similarity, and embeddings are) - Lesson 2 here is a compressed recap, not a full re-teach.

Lessons use Google's Gemini free tier (gemini-embedding-001 for embeddings, gemini-3.5-flash-lite for chat), the same models as this site's other RAG courses. No Docker, no database, no extra account - GOOGLE_API_KEY in a .env file is the only setup.

Built on rank_bm25, the BM25 library this course graduates to in the Advanced tier.

Course source

Every lesson's README and lesson.py for this course live in the ai-agent-engineering repo.

View on GitHub →
Hybrid RAG: Combining Dense and Sparse Retrieval

Beginner

Sparse retrieval by hand, then fusing it with dense using Reciprocal Rank Fusion.

  1. 01What Is Hybrid RAGGitHub
  2. 02Dense Retrieval RecapGitHub
  3. 03Keyword Search by HandGitHub
  4. 04TF-IDF by HandGitHub
  5. 05BM25 by HandGitHub
  6. 06Dense vs. Sparse Head to HeadGitHub
  7. 07Naive Score CombinationGitHub
  8. 08Reciprocal Rank FusionGitHub
  9. 09Checkpoint: Hybrid Search CLIGitHub

Intermediate

Making the fusion robust: filters, persistence, and knowing which retriever to trust.

  1. 10Normalizing Scores Before FusionGitHub
  2. 11Tuning RRF's kGitHub
  3. 12Metadata-Aware Hybrid RetrievalGitHub
  4. 13Persisting Both IndexesGitHub
  5. 14Where Sparse WinsGitHub
  6. 15Where Dense WinsGitHub
  7. 16Failure Modes of Hybrid RetrievalGitHub
  8. 17Minimal Evaluation: Dense vs. Sparse vs. HybridGitHub
  9. 18Checkpoint: Persisted, Filterable Hybrid AssistantGitHub

Advanced

Graduating both retrievers to rank_bm25 and chromadb, and a capstone.

  1. 19Where Hand-Rolled Retrieval Breaks DownGitHub
  2. 20Introducing rank_bm25GitHub
  3. 21Repointing at chromadb and rank_bm25GitHub
  4. 22Alpha-Blended Fusion, RevisitedGitHub
  5. 23Refactoring Into ingest() and ask()GitHub
  6. 24Wrapping It as a ServiceGitHub
  7. 25Capstone: A Complete Hybrid RAG ServiceGitHub
  8. 26Where Hybrid RAG Hits a WallGitHub
Start at Lesson 1

Contact

Book a Call