Lesson 1 of 4 in this unit
Find relevant information.
Compare keyword and learned-vector retrieval, change passage boundaries, and inspect what a ranking score can and cannot tell you.
By the end: Measure retrieval of required source spans while separating training loss, retrieval recall and answer support.
Prerequisites and path options
Why learn this? Find useful source passages for an assistant while spotting when a high search score still leaves the question unanswered.
Start with something concrete.
You need the weekly menu. Would you prefer a whole lunch document or the sentence containing the menu? Search both ways, then try a query that uses different words from the source.
Try the interactive modelA retrieval model gets lower loss on whole-document training pairs. What follows about finding an exact sentence?
Change one thing. Watch what follows.
Loading this browser experiment…
Understand what changed.
A shorter explanation, with the original worked examples available below. Both explain the same experiment and its limits.
Find somewhere useful to look
Suppose an assistant is asked for this week’s menu. It finds a notice saying when menus are posted. The notice is related, but it still does not say which meals are available. Retrieval finds possible evidence; it does not guarantee an answer.
This lab searches six fictional documents with two sentences each. A chunk is the piece returned by a search. You can search whole documents or individual sentences. Short pieces can be easier to inspect, but can leave out useful context.
Keep a simple comparison
Keyword search counts distinct query words found in a chunk. A sentence containing both “weekly” and “menu” scores 2 for “weekly menu”. Repeating “menu” does not increase this score. “Book” and “books” are different words to this simple method.
Try this: search “weekly menu” using keywords. Compare document and sentence chunks. Read the returned text and name what it actually tells you, as well as what is still missing.
Keyword matching can miss different wording for the same request. But a learned method is not automatically better: compare both on the passages you actually need.
Search with learned numbers
The learned method gives each known word four numbers, called a vector. It averages the query’s word vectors, does the same for each passage, then multiplies matching coordinates and adds them. That total is the ranking score.
For example, query vector (0.5, 1, 1, 0) and passage vector (2, 1, 0, 0) score 2: the four products are 1, 1, 0 and 0. The score can be negative. It is not a probability or a measure of truth.
Unknown query words are omitted. Repeated known words count repeatedly in the average. Averaging loses word order, so swapping the same words can leave the vector unchanged. Four numbers per word do not establish general language understanding.
What training changes
There are 75 word vectors with four numbers each: 300 adjustable numbers. Twelve supplied query/document pairs teach the model which document to favor. It changes the shared word vectors using both queries and documents together. Updates happen in batches of 25, up to 500 in a run.
The training loss measures how well it favors those labelled documents. A smaller loss does not guarantee that it finds the right sentence. Resetting restores the initial numbers; it does not make familiar practice questions new again.
Check the evidence you need
The six public practice questions each identify a required source sentence. Top k means the first k returned chunks. If those chunks contain the required sentence for five questions, the span recall is 5 out of 6, or about 83%.
Larger k can find more evidence but gives you more text to inspect. One whole document contains more text than one sentence, so equal k does not mean equal reading work.
Try learned ranking at rate 1 for 300 updates. With the supplied starting values, the training loss falls, yet top-one sentence recall is 3 out of 6 compared with 5 out of 6 for keywords. The model was taught document matching and is being asked to find sentences. This example does not establish that keywords always win.
Know when to stop claiming success
A common mix-up: first place does not mean a result is useful. Search “zzzz”: unknown words produce zero learned scores and the alphabetical tie still puts a passage first.
These repeatedly visible cases are development practice, not an independent final test. Use them to compare chunk size, k and missed evidence. Before answering, inspect whether the source supports the requested claim. Choose Technical for the training objective, exact scoring rules and implementation exercises.
Open the full worked examples, calculations and limitations
This is the same reference used in Technical mode. Expand it whenever you need the exact numbers, assumptions or further explanation.
Start with the source you need
Imagine someone asks for the weekly menu. The lunch document has two sentences: one gives the dining hall and lunch time, while the other says when the menu is posted. Returning the whole document gives context. Returning only the second sentence gives a shorter piece of evidence to inspect. Neither sentence supplies the actual meals for this week. A relevant result can still leave the requested answer unavailable.
A chunk is a unit of text indexed and retrieved together. The lab uses six fictional documents, each with two sentences. Whole-document mode indexes six chunks; sentence mode indexes twelve. Chunk boundaries affect both what gets ranked and what context a result carries. They are part of the retrieval design, not a cosmetic display preference.
Keep a keyword baseline
The keyword method lowercases text, extracts alphabetic words and counts distinct query words appearing in each chunk. For “weekly menu”, the matching sentence has both words, so its score is 2. Repeating “menu” in the query does not increase this score. There is no stemming: “book” and “books” are different tokens.
This baseline is deliberately inspectable, not a full search engine. It does not use inverse document frequency, spelling correction or phrase matching. It can miss paraphrases, but exact words often matter. Do not assume a learned system improves on it without measuring the task.
Need a geometric recap first? Compare dot product, cosine and distance on three notices, then return here. The recap also separates a high score from current source evidence.
Turn words into four-number vectors
A vector here is a list of four numbers. Each known token has a trainable vector. The query vector is the mean of its known token vectors; a passage vector is the mean of its token vectors. Repeated known tokens count repeatedly. Unknown query tokens are omitted. The lab shows each query token before averaging.
Here is a worked example, separate from the live model: suppose two query tokens have vectors (1, 0, 2, 0) and (0, 2, 0, 0). Their mean is (0.5, 1, 1, 0). If a passage has mean (2, 1, 0, 0), multiply matching coordinates and add:
0.5 × 2 + 1 × 1 + 1 × 0 + 0 × 0 = 2.
Here s is the ranking score, j identifies a coordinate, qⱼ is the query’s mean at that coordinate, and dⱼ is the passage’s mean. Read it as “add the four matching-coordinate products.” All quantities are dimensionless teaching values. The live table uses the current model and query rather than these worked values.
A nearby practice case: change the passage mean to (0, 1, 2, 0). Predict the score before reading on.
Check the arithmetic
The products are 0, 1, 2 and 0, giving 3. This ranks above 2 under this dot-product rule. It does not make the passage more reliable or its claims true.
Dot product is not cosine similarity: longer vectors can get larger scores. Scores can be negative and are not probabilities. Averaging also loses word order; “A follows B” and “B follows A” have the same token mean. Four coordinates cannot be assumed to capture general language meaning.
What actually learns?
The local model has 75 tokens × 4 coordinates = 300 trainable numbers. Twelve authored query/document pairs provide the learning signal. For each query, the model scores all six whole documents, converts these scores into a normalized training distribution and adjusts the token vectors to favor the labelled document. Both sides use the same vector table, so gradients from query and document occurrences must accumulate before any parameter changes.
The displayed mean cross-entropy measures how poorly that training distribution favors the labelled documents. Lower means a better fit to these twelve pairs, not a guarantee about new queries. Optional implementation depth is available in the automatic-gradient lesson. Understanding this lab does not require deriving the gradient.
Updates use all twelve pairs at once. Each worker batch applies at most 25 updates and the run stops at 500. The learning rate controls step size. Reset restores the same initial vectors; it does not create new evidence or erase your familiarity with the development cases.
Measure the spans you need
The six public development questions have authored required source sentences. For each question, top k means the first k ranked chunks. We count a hit if those chunks include the required sentence. Each question has one required span, so the reported mean span recall is questions with a hit ÷ six. If five are found, the result is 5/6 ≈ 83.3%.
Increasing k can recover more required spans, but requires inspecting more passages. Whole-document retrieval includes both sentences, while sentence retrieval must select the particular required sentence. Compare both the unit and the amount of text returned; equal k is not equal reading work.
The query strings differ from training, but these are tiny, authored, repeatedly visible development cases using the same documents. They are not an independent final test. The vocabulary is built from source documents and training queries; development prompts never enter the gradient objective.
Keep a failure that teaches something
With the supplied initialization, rate 1 and 300 updates, training loss falls from about 1.788 to 0.357. Yet top-one sentence-span recall is 3/6 for learned retrieval versus 5/6 for keyword overlap. This is a counterexample, not a universal ranking of search methods. The model trained against whole-document labels; finding a particular sentence is a different evaluation requirement.
Do not tune repeatedly on these six cases and then call them an untouched test. Record your comparisons as development evidence. An independent project needs unfamiliar queries, predeclared labels and a frozen selection procedure.
Apply retrieval without overstating it
For a guided experiment, compare chunking and k and explain a missed span. For implementation practice, reproduce the token mean and score with tests for repeated and unknown tokens; compare against the exported 300 parameters. For a decision brief, justify the reading burden, missing-evidence handling and the circumstances in which the keyword baseline is sufficient.
The next evidence lesson will distinguish source reliability, contradictions and actual claim support. This lesson only retrieves candidates. An entirely unknown query produces zero learned scores and an alphabetical tie; the first result is not an answer.
Three passages are retrieved for a question, but none contains the required fact. Which report is justified?
Take this idea with you.
Retrieval narrows what to inspect. Evaluate the required spans, retain a keyword baseline, and check support separately before answering.
Explore related topics and the topic map
How this topic connects
Explore this topic on the interactive mapUse these connections to review a foundation or choose where to go next. You can open any topic without completing the others.
What it builds on
- Define an assistant’s job
Specify what an assistant may answer or do before giving it access to tools and documents.
- Embeddings and vector comparisons
Compare meanings represented as numbers so you can reason about search results and the information a representation loses.
Compare keyword and learned-vector retrieval, change passage boundaries, and inspect what a ranking score can and cannot tell you.
What it enables
- Answer with evidence
Check whether citations support each claim so a convincing answer does not hide missing or conflicting evidence.