Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 12.3 — More Than One Vector per Passage
RAG and Vector Search · Example 1 of 2

Questions as extra keys for a passage

Jaccard on word sets stands in for a real similarity. The written questions are hand-made stand-ins for a model's output. The point is the rule: score a passage by its best key.

One vector per passage is a compromise. A passage can have several: one per sentence, one per question it answers, or one per token with late interaction. Each helps a different failure and costs more storage.

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.

01

Write best_key_score(question, keys) that returns the highest Jaccard similarity between the question's word set and the word set of any key (a key is a passage or a question written for it). Print it with 3 decimals for the question "How do I get my money back?" against the keys of passage D1 in Topic 12.3.

02

A passage of 200 tokens is stored in two ways: one vector per token with 128 numbers of 4 bytes each, or one vector of 384 numbers of 4 bytes. Write the byte counts and print how many times larger the per-token storage is, to one decimal. These sizes are examples for the arithmetic, not those of any named model.

Explain it without notes

01

Why might a passage need more than one vector?

02

What are hypothetical questions as keys, and how do they differ from HyDE?

03

Explain MaxSim and why a pooled vector can rank passages differently.

04

What are the cost trade-offs of the three multi-vector ideas?

Questions as extra keys for a passage
Sign in to run this example in your browser.

Expected output

Q: I forgot my login, how do I get back in?
D1 whole passage 0.074 | best question key 0.308
   key: Can I get my money back if I cancel?
D3 whole passage 0.037 | best question key 0.800
   key: I forgot my password, how do I get back in?