Split a compound question and merge
Both compound questions return only half the answer when searched whole with k = 1. The third has no "and" and is searched whole.
One question can be several questions, or one question in several phrasings. Search with each, then fuse the ranked lists with reciprocal rank fusion so passages that several searches agree on rise to the top.
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 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write split_parts(question) that splits at " and " only when each part has at least two words (by split()). Print the parts for "What does the pass cost and do I need a helmet?" and for "Tea and coffee?", joined with " | ".
Write rrf(rankings) returning "id score" pairs (4 decimals) for lists [["a", "b"], ["b", "c"]], best first, with 1 / (60 + rank).
Explain it without notes
Why can a single search miss half of a compound question?
How does reciprocal rank fusion combine lists, and why does it not need comparable scores?
What are the risks of splitting a question by rule, and how do you reduce them?
When is multi-query not worth it?
Expected output
Q: What does the monthly pass cost and do I need a helmet?
whole question, k=1: D8 (2)
part "What does the monthly pass cost" -> D8 (2)
part "do I need a helmet" -> D4 (1)
merged: D8, D4
Q: When do shops close and how long does a battery last?
whole question, k=1: D2 (2)
part "When do shops close" -> D2 (2)
part "how long does a battery last" -> D7 (1)
merged: D2, D7
Q: What are the rules for riders under 16?
whole question, k=1: D4 (3)
part "What are the rules for riders under 16?" -> D4 (3)
merged: D4