Lesson 2: Chunking and metadata

The unit you index decides what retrieval can ever find. Choose it per data shape, with evidence.

~15 minutes. Builds on Lesson 1.

One rule

A chunk must be able to answer a question on its own. Too small and it is a fragment that matches but cannot answer; too large and its embedding is a blur of many topics.

Three data shapes, three strategies

ShapeExampleStrategy
Small structured recordA listing; a CRM contact with requests and visitsOne chunk per record: render the fields as a short text ("3-bed apartment, Ghent, 385,000, EPC B, garden...") and store the raw fields as metadata
Long prose documentSale contract, brochureSplit on structure (sections, clauses) into ~200-500 token chunks, then prepend a context line
Frequently-changing feedPrice updates, status changesSame as records, but design ingest so a change re-renders and re-embeds exactly that record's chunk

Chunking strategy measurably moves retrieval quality: Chroma's evaluation found differences of up to ~9% recall between reasonable-looking strategies on the same corpus, and that simple structure-aware splitting is a strong baseline.[1] Do not take any strategy on faith - Lesson 6 gives you the measuring loop.

The context line

A chunk pulled out of a contract loses its surroundings: "The balance is due 30 days after the deed" - which property, which parties? Contextual retrieval fixes this: before embedding, prepend a generated one-liner situating the chunk.[2]

chunk_context = generate("Situate this chunk within the document", document, chunk)
index(embed(chunk_context + chunk), keywords(chunk_context + chunk), metadata)

Anthropic measured a 49% reduction in failed retrievals from this alone, 67% combined with reranking.[2] For record chunks the "context" is free: it is the field rendering itself.

Metadata is not prose

Price, city, bedrooms, property type, status, owner tenant, dates: store them as typed fields next to the vector, never only inside the text. Text similarity is approximate; a later lesson makes "under 400,000" a hard filter, and a filter can only bind to a field. Rule: anything a user could constrain exactly becomes a metadata field and appears in the rendered text.

Retrieval practice

From memory, before scrolling up.

Your win: given any new data source - a portal feed, a folder of PDFs, a CRM table - you can name its shape, its chunk unit, its context line, and which fields become metadata.

Primary source

Read Contextual Retrieval end to end (15 minutes) - it is the rare engineering post with an eval behind every claim. Then skim Chroma's chunking evaluation for the method, not just the numbers.

Unsure how to chunk a specific document you have? Ask your teaching agent with a sample - it can design the split with you.