Three rankers, four questions
The vector side is a toy embedder (five hand-made meaning dimensions), so its numbers are not a real model's. The lab below uses the real one.
Keyword search finds exact words, codes and numbers. Vector search finds the same meaning in different words. Each one confidently misses what the other finds, so serious search runs both.
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 place(ranking, gold) that returns the 1-based place of gold in a list of ids, or "none" when it is missing. Print it for ["D3", "D1"] with gold D1, and for ["D3"] with gold D8.
Given a keyword ranking ["D2", "D9"] and a vector ranking ["D9", "D4", "D2"], print the ids that appear in both lists, in the order of the vector ranking. Why are such ids good candidates?
Explain it without notes
Give one example of a question keyword search answers better than vector search, and one the other way round. Explain why.
Why does merging two ranked lists help when each list is sometimes wrong?
What does it mean that both rankers fail silently, and what do you do about it?
Is hybrid search always worth its extra cost?
Expected output
Q: What does the monthly pass cost?
keyword D8 D10 D3 | vector D8 D1 D12 | hybrid D8 D12 D10
D8 is at: keyword 1, vector 1, hybrid 1
Q: I forgot my login, how do I get back in?
keyword D1 D10 D3 | vector D3 D5 D10 | hybrid D3 D1 D10
D3 is at: keyword 3, vector 1, hybrid 1
Q: 150 dollar fee
keyword D12 | vector D8 D1 D12 | hybrid D12 D8 D1
D12 is at: keyword 1, vector 3, hybrid 1
Q: Can I get my money back if I cancel?
keyword D10 D1 D5 | vector D8 D1 D12 | hybrid D1 D10 D5
D1 is at: keyword 2, vector 2, hybrid 1