Three recipes: weighted RRF, MMR, a two-stage retriever with fallback
The re-rankers here are fakes (a table of scores and a function that raises). The recipe code itself is what you copy.
Copy-ready recipes: a weighted RRF function, an MMR function, a two-stage retriever that survives a failing re-ranker, a hosted re-ranker call, and the checklist to run before you ship.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write weighted_rrf for two lists with weights (1, 2) and print the top two ids with 5 decimals for lists ["a", "b"] and ["b", "c"].
Write safe_call(fn, fallback) that returns fn() and, if it raises any exception, prints fallback used and returns fallback. Print the results for a function that works and one that raises.
Explain it without notes
When would you use weighted RRF instead of plain RRF?
Why should the two-stage retriever catch exceptions from the re-ranker?
How does the hosted re-ranker call plug into the retriever?
What goes on your "before you ship" list for hybrid retrieval?
Expected output
plain RRF: D1=0.03227, D3=0.03227, D2=0.01613, D4=0.01613
keyword x2: D3=0.04866, D1=0.04814, D4=0.03226, D2=0.01613
mmr lambda 1.0: copy 2, copy 1
mmr lambda 0.5: copy 2, other
good re-ranker: D4, D2
re-ranker failed (timed out after 200 ms), keeping the first-stage order
broken re-ranker: D5, D2