← Learning

Corrective RAG

A linear, one-concept-per-lesson path through Corrective RAG (CRAG), grading retrieved chunks for relevance and correcting a bad retrieval before it ever reaches generation, built from scratch with no framework, from your first relevance grade to a complete FastAPI corrective RAG service backed by ChromaDB. 26 lessons · 3 tiers.

Prerequisites: Completion of Naive RAG, or already comfortable with embeddings, cosine similarity, top-k retrieval, and why naive retrieval can confidently return the wrong chunk - Lesson 2 here is a compressed recap of that failure, not a full re-teach.

Lessons use Google's Gemini free tier (gemini-embedding-001 for embeddings, gemini-3.5-flash-lite for chat and grading), the same models as this site's other RAG courses. No Docker and no database through most of the course; the Advanced tier graduates the vector store to a local ChromaDB instance, still no server or account required.

Built on ChromaDB, the open-source vector database 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 →
Corrective RAG

Beginner

Grading a retrieved chunk, filtering out the bad ones, and rewriting the query when nothing survives.

  1. 01What Is Corrective RAGGitHub
  2. 02Where Naive Retrieval Is Confidently WrongGitHub
  3. 03Grading a Retrieved ChunkGitHub
  4. 04Grading All Top-k ChunksGitHub
  5. 05Filtering Out Incorrect ChunksGitHub
  6. 06Query RewritingGitHub
  7. 07Re-retrieval with the Rewritten QueryGitHub
  8. 08End-to-End Corrective QAGitHub
  9. 09Checkpoint: CLI Q&A That Self-CorrectsGitHub

Intermediate

Strip-level grading, three-way confidence buckets, and making the correction precise and bounded.

  1. 10Strip-Level GradingGitHub
  2. 11Recomposing Context from Relevant StripsGitHub
  3. 12Confidence Buckets and ActionsGitHub
  4. 13Persisting Grading ResultsGitHub
  5. 14Query Rewriting StrategiesGitHub
  6. 15Prompting for Disclosed CorrectionsGitHub
  7. 16Failure Modes of Grading and RewritingGitHub
  8. 17Minimal Evaluation: Before vs. After CorrectionGitHub
  9. 18Checkpoint: Notes Search with a Corrected IndicatorGitHub

Advanced

Making correction affordable and graduating to ChromaDB, plus a capstone.

  1. 19Where Per-Chunk Grading Gets ExpensiveGitHub
  2. 20A Cheap Pre-Filter Before GradingGitHub
  3. 21Bounding Correction LoopsGitHub
  4. 22External Web Search as the Incorrect BranchGitHub
  5. 23Refactoring into ingest(), grade(), correct(), ask()GitHub
  6. 24Wrapping It as a ServiceGitHub
  7. 25Capstone: A Complete Corrective RAG ServiceGitHub
  8. 26Where Corrective RAG Hits a WallGitHub
Start at Lesson 1

Contact

Book a Call