Module 2 · Tools, Knowledge, Memory & Research Design · scripted

Searching by Meaning

35 minoutcomes: context-engineering, knowledge-systems

A debt from earlier

When we designed tool results, we left a wound open. The agent needed the night-delivery rules; we gave it search; watch again what happened:

Example 1 · The failure we never fixed
assistant
⟨tool_use⟩
search_document(doc = "doc-77", pattern = "night deliver")
user
⟨tool_result⟩
0 matches.
assistant
⟨tool_use⟩
search_document(doc = "doc-77", pattern = "night")
user
⟨tool_result⟩
2 matches: p. 12 "overnight mooring"; p. 98 "night watch staffing".
NoteThe rules were in the document the whole time — filed under "deliveries outside ordinary working hours (23:00–06:00)". Not one word in common with the query. We named the diagnosis then: text search finds strings, not meanings — and we moved on, owing the cure. Now we pay the debt.

Meaning has a geography

Take a document everyone in a university knows: the undergraduate catalog — hundreds of pages of majors, requirements, prerequisites, and policies. Pull out a few statements and ask which ones are similar in meaning:

Similar in meaning — no strings attached

A. "Students must complete MATH 2410 before enrolling
in any 3000-level course."

B. "Calculus II is a prerequisite for upper-division work."

C. "The dining halls offer three meal-plan tiers."

A and B share almost no words — different course name, different vocabulary, different sentence shape. Yet every reader knows: A and B are nearly the SAME statement, and C is from another world entirely.

That judgment — same meaning, different words — is what we need the machine to make. An embedding is the device that makes it: a machine that reads a piece of text and produces its address — a point in a space arranged so that one rule holds everywhere:

The one rule of the space

Near in MEANING  =  near in SPACE.

Not similar spelling. Not shared words.
Similar meaning.

We can't draw the real space — it has thousands of dimensions — but we can look at its shadow in two, and even the shadow shows the structure:

A two-dimensional shadow of the space

"must complete MATH 2410 before
3000-level courses"· "three meal-plan tiers"
"Calculus II is a prerequisite· "dining hall hours" for upper-division work" "residence hall
"CS majors take a capstonemove-in day"
project in their final year"

The requirement statements cluster; the campus-life statements cluster elsewhere; A and B sit nearly on top of each other despite sharing no words. (This is the apple again, from the outside: the word connects to a rich learned representation, and the embedding gives that interior structure an address. It even crosses languages — eple lands beside apple on this map, because Norwegian text about eple behaves like English text about apples. Nobody told the space that. It was drawn by reading.)

What is the meaning of an entire catalog?

Now the question that makes this practical. The embedding machine will accept any text you hand it — a sentence, a page, the whole catalog — and hand back one point. So: embed the entire catalog. What does that point mean?

One point, three sizes of text

ONE SENTENCE"MATH 2410 is required for the CS major." A sharp, precise point — this address means one thing.
ONE MAJOR'S PAGESrequirements + electives + policies. The point must stand for ALL of it at once — it lands somewhere in the middle of everything the pages say. A blur.
THE WHOLE CATALOGforty majors, dining plans, honor code. One point standing for everything is a point that means "university catalog" — and nothing more specific than that.

It isn't literally an average, but it behaves like one: one address must stand for everything in the text, and the more the text says, the less the address can say. Detail washes out. And mixtures make it worse — the catalog contains statements that pull in opposite directions:

Two majors, one course, opposite rules

"CS majors MAY count STAT 3011 toward the statistics
requirement."
"Mathematics majors may NOT count STAT 3011 toward any
requirement."

Both statements are *about* STAT 3011 — so their individual addresses are neighbors. A text containing both gets one address that is very much "about STAT 3011 counting rules"… and silent about which rule is whose. The geography knows aboutness. It cannot hold a disagreement.

Recognize what embedding-something-large is: it's abstraction — detail traded away for one compact representation — except nobody chose what to keep. Embedding a whole document is abstraction without an author. If we want sharp addresses, we must hand the machine sharp pieces.

Tearing the pages

So we cut the catalog into pieces and embed each piece — this is called chunking, and the honest physical picture is tearing: take each page and tear it into strips, and every strip gets its own address. But here is the trap: the tearing is usually done by ordinary code — every N lines, every paragraph break — and code doesn't know where the meaning bends. Watch a real page get torn:

Where the tear falls

PAGE 212 of the catalog:…history of the department, faculty research areas, and accreditation details.
PAGE 213:MATH 2410 Calculus II · MATH 3320 Discrete Math · STAT 3011 Statistical Methods · CS 3250 Algorithms…
THE TEAR (every 12 lines):
strip 41: [department history … + the heading"REQUIRED COURSES — COMPUTER SCIENCE MAJOR:"]
strip 42: [CS 1101 · CS 2201]
strip 43: [MATH 2410 · MATH 3320 · STAT 3011 · CS 3250]

The heading tore off with the HISTORY. Strip 43 is a bare list of math courses — nothing on that strip says "computer science."

Now embed the strips and ask the obvious question:

Example 2 · The strip that lost its computer-scienceness
user

Is MATH 3320 required for the computer science major? Tools: search_by_meaning(query, top).

assistant
⟨tool_use⟩
search_by_meaning(query = "math courses required for the computer
science major", top = 3)
user
⟨tool_result⟩
1. strip 118 — Mathematics major: core requirements…
2. strip 41 — CS department history… "REQUIRED COURSES —
   COMPUTER SCIENCE MAJOR:" [list follows on next strip]
3. strip 87 — Math minor: course list…
assistant

The nearest passages cover the mathematics major and minor. Strip 41 mentions CS required courses but contains no course list. I don't have evidence that MATH 3320 is a CS requirement.

NoteStrip 43 — the one that actually answers the question — didn't even make the list. Look at its text: pure math courses, not one computer-science word. Its ADDRESS is pure math-ness; it sits in the math-department neighborhood, far from any CS query. The information isn't gone from the page. Its computer-scienceness was torn away — it lived in a heading that landed on another strip. Where you tear decides what each piece is about.

The tearing principle

A chunk's address is computed from the chunk alone.
Whatever context the tear separates from it — the heading,
the section, the "this is about X" — is subtracted from
its meaning.

Tear along the meaning, or the meaning tears.

The size of the tear

And tearing has a second dial: how big? We've now seen both ends fail:

The granularity Goldilocks

TOO BIGthe whole catalog: one blurred address that means "catalog." Abstraction without an author — detail gone, nuance gone, contradictions blended.
TOO SMALL single lines:"MATH 3320 Discrete Math" — a sharp address for a strip that no longer knows what question it answers, or for whom.
JUST RIGHTa piece that states one thing WITH its context: the heading, the rule, its exceptions — torn at the boundaries the *author* drew, not the ones the line-counter hit.

The same Goldilocks we met designing results, now on the ingestion side — and the same lesson: the right size is defined by the questions that will be asked, not by a number of lines.

Smarter tearing

If the problem is that code doesn't understand where meaning bends — we have a machine that does. Two ingestion patterns, both built from self-dialogue:

Let a mind place the tears. Before cutting, send each page through a disposable prompt: "Return the line numbers where this page should be split so each piece states one complete idea with its heading and context." The LLM reads page 212 and tears above the heading, keeping "REQUIRED COURSES — COMPUTER SCIENCE" attached to its list — and joining the list's continuation from page 213 to the same piece. Pay a prompt per page, once, at ingestion; every future search benefits.

Cast each piece as the questions it answers. An even stronger move. A chunk and the query that seeks it are different kinds of text — one is a list, the other is a question — and different kinds of text sit in slightly different neighborhoods. So, at ingestion, ask a disposable prompt: "What questions could this piece answer?" — and embed those:

Question-casting at ingestion

THE PIECE:[REQUIRED COURSES — COMPUTER SCIENCE MAJOR: CS 1101 · CS 2201 · MATH 2410 · MATH 3320 · STAT 3011 · CS 3250 …]
GENERATED:"Which courses are required for the CS major?" "Is MATH 3320 required for computer science?" "Do CS majors have to take statistics?" "What math do computer science students need?"

Store the piece under the ADDRESSES OF ITS QUESTIONS. When a real question arrives, it matches question-to-question — the same kind of text, the same neighborhood, by construction.

Notice what this is: at ingestion time, a mind imagined the future conversations this piece would matter to — and filed it where those conversations will look. The librarian shelving books by the questions readers will ask, not by the color of the covers.

Smarter asking

The same intelligence helps on the query side. A real task is usually not one clean question — and embedding the whole task has the same blur problem as embedding the whole catalog. So let the agent decompose before it searches, the way chain of thought decomposes before it answers:

Example 3 · Sub-questions before search
user

I'm switching from math to CS at the start of third year. What do I still need, and can I finish in two more years? Tools: search_by_meaning(query, top), read_piece(id).

assistant

Before searching, I'll break this into the sub-questions I'd need answered: (1) Which courses are required for the CS major? (2) Which of those have prerequisite chains, and how long? (3) Which math-major courses count toward CS requirements? (4) What is the maximum course load per term? (5) Are there residency or minimum-terms rules for a new major?

assistant
⟨tool_use⟩
search_by_meaning(query = "courses required for the computer
science major", top = 2)
assistant
⟨tool_use⟩
search_by_meaning(query = "transfer credit between majors —
courses counting toward a new major", top = 2)
assistant
⟨tool_use⟩
search_by_meaning(query = "maximum course load per semester", top
= 2)
user
⟨tool_result⟩
[three result sets: the CS requirements piece; the STAT 3011
counting rules for both majors; the overload policy…]
assistant

Aggregating: the CS core is 11 courses; your math credits cover MATH 2410, MATH 3320, and — per the CS counting rule — STAT 3011. Eight remain; the longest prerequisite chain is three terms; with the standard load plus one approved overload term, two years is feasible. One flag: the residency rule requires at least four terms in the new major — you have exactly four.

NoteOne blurry task became five sharp addresses. Each sub-question is the kind of text the question-cast pieces were filed under — so each lands in the right neighborhood. Then the agent did what only the loop can do: aggregate five answers into one. Decomposition before retrieval is chain of thought, pointed at a library.
The two sides of the same trick
  • Question-casting (ingestion) and sub-question decomposition (query) are mirror images. Say precisely what each one moves, and toward what.
  • In Example 3, which sub-question would the whole task's embedding have served worst — and why?

What the map doesn't know

Before we build on this, the honest limits — because the map has exactly one skill, aboutness, and several things that look like aboutness are not:

Three things the space gets wrong

TRUTH"CS majors may count STAT 3011" and "CS majors may not count STAT 3011" are about the same thing — so they are NEIGHBORS. The space cannot tell you which is true, or notice that they disagree.
NEGATION"effective against the pest" vs "not effective against the pest" — a world of difference, a few millimeters of distance.
EXACT IDSMATH 3320, invoice #2214, the gene BRCA2 — for identifiers, spelling IS the meaning, and the old string search is the better tool.

So the retrieval ladder from earlier doesn't get replaced — it gets its missing rung:

The ladder, completed

page through itprotects each call, wastes the trajectory
search it (strings)exact — wins for identifiers, numbers, names
search it (meaning)finds the synonym, the paraphrase, the other language — blind to truth and negation
ask ita mind reads it — judgment, at prompt prices

Each rung up costs more and understands more. A well-equipped agent holds several rungs at once — and choosing the rung per question is part of its job.

The principle

Meaning has a geography, and an embedding is a text's address
in it. But the address is only as sharp as the piece:
tear along the meaning, size the pieces to the questions,
and let a mind help on both sides —
filing the pieces, and phrasing the search.
Your turn

Take a real structured document from your field — a regulation, a curriculum, a methods handbook. (1) Tear it two ways: every N lines, and at author-drawn boundaries; find one strip that lost its aboutness to the tear. (2) Pick a piece and cast it as five questions it answers. (3) Take one realistic task against the document and decompose it into sub-questions; check which sub-question the whole task's single embedding would have served worst. (4) Name the one query in your domain where string search still beats all of this — and why.