Information retrieval & hybrid search
P11.ir-rag.01 · Audience: guest, it-ml, language-pro · Prerequisites: Sentence Embeddings
Retrieval is a funnel, not a lookup: a search box hides four stages, and
confusing them is the single most common interview mistake. This module builds
candidate generation, hybrid search, and fusion — the stages a RAG system stands
on. Metrics get their own module next (P11.ir-rag.02).
A search box hides four stages:
| Stage | Optimised for |
|---|---|
| Query understanding — parse intent, extract hard constraints | intent |
| Candidate generation — a few hundred from millions | recall + speed |
| Ranking / re-ranking — score carefully, order | precision at the top |
| Business filters — in-network, licensed, open now | non-negotiables |
🎯 Keep the two retrieval numbers separate: candidate generation is judged by recall@k (did the right doc make the shortlist?), ranking by precision / nDCG (is it near the top?).
Ask the mentor about this module
Ask a question about this content. The mentor explains and grounds its answer in what you are studying; asking is recorded as a learning signal, not a grade.
🎓 Practice ladder
3 graded rungs · ~30 minNow build the retrieval maths yourself. Each rung is a three-panel workspace: instructions on the left, a code editor in the middle, output + test results on the right. Run checks the visible tests; Submit grades against hidden edge cases — a query term absent from every document, a doc ranked by only one list, the ideal-order nDCG = 1 and zero-relevant = 0 cases. The reference solution unlocks once you pass; the senior rung builds all three IR metrics.
Rung 1 — BM25, by hand
Loading exercise…
Rung 2 — Fuse two rankings with RRF
Loading exercise…
Senior rung — recall@k, MRR and nDCG
Loading exercise…
⚡ Interview Ref — the quick-scan Reference face
- The funnel: query understanding → candidate generation (recall) → ranking (precision) → business filters. Name the stage before you touch code.
- Diagnosis fork: right result not in the candidate set → recall problem (hybrid, filters, bigger k); in but buried → ranking problem (re-ranker).
- BM25 (sparse): IDF × saturating TF with length norm. Great on exact/rare tokens; scores unseen synonyms 0.
- Dense: cosine over learned/co-occurrence vectors; matches meaning across zero shared tokens; drifts on rare exact tokens.
- Hybrid + pre-filter: run both, fuse; apply hard constraints before ranking (filter → retrieve → rank).
- Fusion: RRF (rank-based, scale-free, default) vs normalized linear (min-max + one weight knob).
Try it yourself
A scratch console for this page's ideas — ungraded, nothing you run here is recorded.
Scratch console
A scratch console with the scientific stack (pandas, numpy, scikit-learn). Runs on the server — no network, resource-limited and measured.
Output appears here.
Where next?
Later in Information Retrieval & RAG
This module unlocks