从零造搜索引擎:RAG 里 R 的第一性原理

Build a Search Engine: First Principles of RAG's "R"

Everyone builds RAG but never opens the retrieval core — hand-write an inverted index and BM25, and finally know why your retrieval misses

6 labs10 AI-mentored sessions~5 hoursBilingual · EN / 中
Start learning →

About this course

A build-it-yourself course: no libraries to install, no APIs to call. In every session
an AI mentor walks you through writing the retrieval core in pure Python — inverted
index, boolean queries, TF-IDF, BM25, phrase search, spell correction, index
compression, retrieval evaluation, all the way to vector retrieval and hybrid RAG
retrieval. Everyone builds RAG, yet almost nobody has opened the black box of "R":
why does keyword stuffing fool TF-IDF but not BM25? Why can't "new york" be faked
with AND? Why does one tokenization change wreck your recall? The course follows the
topic skeleton of Stanford's Introduction to Information Retrieval, with every
session rewritten as original hands-on teaching for the online sandbox — formulas
typeset, algorithms drawn, parameters draggable, code actually running in
milliseconds in your own sandbox. By the end you can answer the eternal question:
"why does my retrieval miss" — and know which layer to fix.

What you'll learn

  • Hand-write an inverted index + boolean queries — millisecond term-to-document retrieval
  • Implement TF-IDF and BM25 scoring; understand term-frequency saturation and length normalization
  • Watch first-hand why keyword stuffing fools TF-IDF but not BM25
  • Build a full text pipeline: mixed zh/en tokenization, positional phrase queries, edit-distance spell correction
  • Make the index small and fast with skip pointers, variable-byte compression and block merging, then score and tune retrieval with MAP/NDCG
  • Assemble hybrid lexical+vector retrieval and systematically diagnose & fix 'why my RAG retrieval misses'

Syllabus

1A Mini Search Engine: from Inverted Index to BM252 sessions
  • 1The Inverted Index: Heart of a Search Engine25 minStart →
  • 2From TF-IDF to BM25: Why Keyword Stuffing Fools TF-IDF but Not BM2530 minStart →
2Before Text Meets the Index: Tokenization, Phrases & Spell Correction3 sessions
  • 1Tokenization & Normalization: One Bad Token Kills the Whole Query30 minStart →
  • 2Positional Index & Phrase Queries: "new york" ≠ new AND york30 minStart →
  • 3Search Through Typos: Edit Distance & Spell Correction25 minStart →
3Index Engineering: Skip Pointers, Compression & Block Merging3 sessions
  • 1Skip Pointers: Make AND 10x Cheaper30 minStart →
  • 2Index Compression: Gaps & Variable-Byte Encoding25 minStart →
  • 3Block Building & Merging: When the Index Doesn't Fit in Memory25 minStart →
4Evaluating Retrieval: How Good Is Your Search, Really?2 sessions
  • 1Precision, Recall & MAP: Scoring Your Retrieval25 minStart →
  • 2NDCG & Tuning: Grid-Search Your Best k1 and b25 minStart →
5Vector Retrieval: When Keywords Aren't Enough0 sessions

Sessions are on the way.

6The "R" in RAG: Putting the Retrieval Core Back into Your RAG0 sessions

Sessions are on the way.

Same series · 人工智能全透析

AI, End to End

Synthesized from the best material across the web — rebuild the core of AI from scratch, the efficient way.