Information retrieval & hybrid search

P11.ir-rag.01 · Audience: guest, it-ml, language-pro · Prerequisites: Sentence Embeddings

Real LLM grading for this pageLLM grading (this page):

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).

Step 1 / 7Retrieval is a funnel, not a lookup

A search box hides four stages:

StageOptimised for
Query understanding — parse intent, extract hard constraintsintent
Candidate generation — a few hundred from millionsrecall + speed
Ranking / re-ranking — score carefully, orderprecision at the top
Business filters — in-network, licensed, open nownon-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.

Ctrl/Cmd + Enter to send

🎓 Practice ladder

3 graded rungs · ~30 min

Now 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.