Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 7.4 — Many Queries for One Question
RAG and Vector Search · Example 1 of 2

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.

01

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

02

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

01

Why can a single search miss half of a compound question?

02

How does reciprocal rank fusion combine lists, and why does it not need comparable scores?

03

What are the risks of splitting a question by rule, and how do you reduce them?

04

When is multi-query not worth it?

Split a compound question and merge
Sign in to run this example in your browser.

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