Learn AI.
Build AI Systems · ORIGINAL LEARN AI LESSON

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.

01 · TRY

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 model ↓
02 · PREDICT
Before you experiment

A retrieval model gets lower loss on whole-document training pairs. What follows about finding an exact sentence?

A retrieval model gets lower loss on whole-document training pairs. What follows about finding an exact sentence?
03 · EXPERIMENT

Change one thing. Watch what follows.

  1. Search “weekly menu” with keyword overlap. Compare whole-document and sentence chunks; inspect the source sentence numbers.
  2. Search “borrow reading material”. Predict which words overlap, then inspect the token vectors and dot-product arithmetic.
  3. Switch to learned ranking. Record the initial public development recall, train twelve batches of 25 updates at rate 1, and compare recall and training loss.
  4. Switch between whole-document and sentence chunks without retraining. Explain why the result can change.
  5. Raise top k from one to two. Count required spans recovered and the additional passages a reader must inspect.
  6. Search “zzzz”. Explain why a first-ranked passage with a zero score is not a useful answer.

Loading this browser experiment…

04 · UNDERSTAND

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.

s=∑j=14qjdjs = \sum_{j=1}^{4} q_j d_j

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.

05 · APPLY
Check your understanding

Three passages are retrieved for a question, but none contains the required fact. Which report is justified?

Three passages are retrieved for a question, but none contains the required fact. Which report is justified?
06 · CONTINUE

Take this idea with you.

Retrieval narrows what to inspect. Evaluate the required spans, retain a keyword baseline, and check support separately before answering.

My work
Learn AI · Understand by doing.Loading local progress…Copyright (c) 2026 Mobi Weave, Inc. All rights reserved