October workshops are openBuild a Search AI Agent$99 early bird

Enroll now
Skip to content

PHASE 3 · LESSON 9 OF 24 · 3 SMALL IDEAS + A GUIDED LAB

Find a useful piece of information

A search result can contain the right word and still answer the wrong question.

You will learn to: Search a small collection, inspect full records, and distinguish lexical matching from semantic retrieval.

Preparing your lesson and this browser’s progress…
Read the complete lessonAll the ideas in one place · works without the editor

Use these notes to review a concept or read at your own pace. The interactive workspace above adds predictions, editable code, and actual run results.

IDEA 1

Search a small document collection

Retrieval means selecting information from a collection before using it in an answer. Our collection contains short, invented school notices. A search tool returns candidate IDs, not a verified answer. The program must read those records and check that they discuss the requested topic.

A chunk is a portion of a longer document. Searching chunks can avoid loading everything, but the chosen portion may omit a heading, date, or exception. Keep an ID that lets the program retrieve the fuller record. Finding a word is the beginning of an evidence check.

Search, then inspect

  1. Question. We need the library's opening time.
  2. Candidates. The word occurs in an opening notice and an art-club notice.
  3. Read records. Inspect each record's topic before selecting an answer.

Follow this authored example, then test the idea in the lab.

Read the example

const ids = tools.search(input.query);
const records = ids.map(id => tools.read(id));

The returned IDs are pointers. Reading a record supplies the fields you need to decide whether it answers the question.

Think it through: Search returns a notice saying 'Library poster competition'. What have you established?

IDEA 2

Compare word matching with semantic retrieval

A lexical search compares words. It can miss a useful notice when the question says 'bike' and the notice says 'bicycle'. An embedding model instead maps text to numerical representations used to compare meaning-related patterns. That model is a separate component; it does not appear just because we call a function search.

Semantic similarity can help recall, but related meaning is not the same as supporting a claim. A passage about yesterday's opening hours may resemble today's question. In this lab the search is literal text matching. Change the query and inspect the changed candidates; do not interpret its scores as model understanding.

Two different retrieval mechanisms

  1. Lexical query. 'bike' asks for a literal matching string in this lab.
  2. Possible miss. 'Bicycle storage' may contain the needed information without that string.
  3. Semantic extension. A real embedding model could suggest a related passage; it would still need checking.

Follow this authored example, then test the idea in the lab.

Read the example

const match = record.text.toLowerCase()
  .includes(query.toLowerCase());

This is string matching, not an embedding model. Its limitations are visible and reproducible.

Think it through: The notice says 'bicycle storage' and searching 'bike' returns nothing. Which conclusion is justified?

IDEA 3

Inspect what a retrieved chunk leaves out

Suppose a snippet says 'Open after school', while its full record says 'Open after school on Tuesdays only'. The condition changes which answer is supported. Reading only the attractive fragment would lose the condition even if the snippet came from a real document.

The lab keeps search and reading separate. Your solution should read every returned candidate, retain only records with the requested topic, and return their IDs. A no-match result is useful: it prevents the program from inventing an answer when none of the inspected records addresses the question.

Restore the missing condition

  1. Short snippet. A small piece looks promising.
  2. Full record. The source adds a day restriction.
  3. Qualified answer. Return evidence that addresses the requested topic.

Follow this authored example, then test the idea in the lab.

Read the example

if (record && record.topic === input.topic) {
  matches.push(record.id);
}

The explicit topic annotation is part of this fictional exercise. A real document system needs a separately evaluated relevance check.

Think it through: A search snippet omits an exception. What should the agent do before answering?

Put it into practice

Return the IDs of matching notices that actually address the requested topic.

  1. Read the selected case and predict its expected result.
  2. Run the starter once. Use the failed check and tool trace to locate the missing rule.
  3. Insert the explained snippet at the TODO, then run the case again.
  4. Test all three cases. Change the experiment input and explain whether the same rule still works.

Your next experiment: Change 'bike' to 'bicycle'. Predict which record becomes retrievable and why.

Retrieve candidates, inspect their context, and only then decide what they support.

Key terms

Retrieval
Selecting information from a collection for a task.
Chunk
A portion of a document that may need surrounding context.
Embedding
A model-produced numerical representation used in similarity comparisons.

Sources and scope

Original Stemtiq teaching, reviewed 2026-09-14. The named researchers and organizations do not endorse this course. Classroom cases are authored exercises, not published findings.

Lewis et al. · NeurIPS: Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks

NeurIPS 2020

Combine information retrieval with generation so a model can use external passages while producing an answer.

The paper uses a trained neural retrieval and generation architecture. A keyword lookup illustrates retrieval but neither reproduces that architecture nor proves a retrieved claim true.

Anthropic: Effective context engineering for AI agents

29 September 2025

Curate limited context, retrieve relevant information, and distinguish compaction, external notes, and separate subagent contexts during longer tasks.

Summaries can lose details. Persistent notes do not change model weights or establish truth, and a larger context window does not guarantee perfect recall.

Your JavaScript really runs. The model decisions and school data are authored simulations, so you can learn without an API key. Every workspace also includes a separate real SDK example to explore next. Passing the lab’s cases is practice, not proof that an agent is ready for real-world use.