Darkmind / Issue 009

Give Every Retrieval Chunk a Name Tag

Add a short, document-aware label to each isolated retrieval chunk before indexing it, so search can recover the who, when, and what that the chunk assumes.

Oct 16, 20264 min readBetter retrieval

A retrieval system can return a sentence that is true and still be useless. Imagine a chunk that says, “Revenue grew by 3% over the previous quarter.” On its own, it omits the company, the reporting period, and perhaps which revenue measure is meant. The words may be a strong semantic match for a question, yet the chunk loses the context that lets a model—or a reviewer—use it safely.

The practical move is to prepend a short, document-aware name tag to every chunk before you index it. The tag states the facts the local passage assumes: document title, subject or entity, time period, section, and any scope needed to interpret the text. Keep the original passage intact; add the tag as retrieval context, not as a replacement summary.

Anthropic calls a version of this technique Contextual Retrieval: it generates concise, chunk-specific context from the whole document and prepends that context before creating embeddings and a BM25 index.[1] Microsoft’s Azure AI Search guidance points to the same underlying problem from the chunking side: splitting helps with model limits and finer-grained retrieval, but chunks should preserve semantic coherence; for middle-of-document chunks, it specifically suggests appending the document title to prevent context loss.[2]

What the tag should repair

A good tag repairs references that make sense only inside the original document. The usual missing pieces are:

Do not turn the tag into a second article. It should be short enough to scan and specific enough to distinguish this passage from similar text elsewhere. “Documentation about billing” is weak. “Acme Cloud billing guide, Enterprise plan, effective 2026-01; section ‘overage invoices’” gives retrieval both vocabulary and boundaries.

This is particularly useful for large manuals, support archives, policy collections, release notes, and financial or operational reports. Those documents repeat generic phrases—“the service,” “this limit,” “the previous period”—that become ambiguous after splitting. A name tag gives semantic and keyword search stable terms that were present in the document context but absent from the isolated passage.

Copy this contextual-chunk template

Run this as an indexing step after you choose chunk boundaries and before you create embeddings or a keyword index. The bracketed values should come from the source document or a bounded extraction process, not from a model guessing beyond the document.

INPUTS
DOCUMENT_TITLE: [stable title]
DOCUMENT_ID_OR_URL: [stable locator]
DOCUMENT_CONTEXT: [full document, section tree, or trusted metadata]
CHUNK: [the exact text to be indexed]

TASK
Write one context label of 30–80 words that lets a search system interpret CHUNK
without seeing the rest of the document.

INCLUDE WHEN SUPPORTED
- document title or type
- named entity, product, policy, or project
- relevant date, version, jurisdiction, plan, or audience
- section or topic
- definitions needed to interpret pronouns or local terms

RULES
- Use only information supported by DOCUMENT_CONTEXT or trusted metadata.
- Do not add recommendations, conclusions, or facts absent from the source.
- Do not paraphrase CHUNK except to name its referent.
- If a key detail is unknown, omit it rather than inventing it.

OUTPUT
CONTEXT_LABEL: [concise context]
INDEX_TEXT: CONTEXT_LABEL + "\n\n" + CHUNK
METADATA: {document_id, title, section, version_or_date, chunk_id}

For example, a raw chunk might say: “The company’s revenue grew by 3% over the previous quarter.” A usable context label might be: “ACME Corp Q2 2023 SEC filing; quarterly performance section; the prior quarter’s revenue was $314 million.” The index text then keeps that label next to the original statement. The answer generator should still cite or display the source passage; the tag improves retrieval, not provenance.

Keep structure and metadata alongside the text

A name tag is not a substitute for good boundaries. First split at headings, paragraphs, or other meaningful structure when the source allows it. Microsoft distinguishes fixed-size, structure-aware, and semantic chunking, noting that semantic chunks preserve context and relationships across sentences and paragraphs.[2] Use overlap only when adjacent prose genuinely carries a thought across the boundary; overlap cannot restore a missing document title or date reliably.

Store the same facts as filterable metadata as well. A user asking about a specific release should be able to restrict retrieval by product and version rather than hoping a generated label wins a similarity search. The text label helps ranking and comprehension; metadata supports filtering, display, deletion, and re-indexing. Keep a stable document ID and the source version so an answer can be traced back after the corpus changes.

Before rolling this out everywhere, make a small retrieval test set. Include questions whose answers depend on entity, date, or section context—exactly the facts that disappear when chunks are isolated. Compare raw chunks against contextualized ones, and inspect both the top results and the final answer. Anthropic reports improvements from its own contextual-embedding, BM25, and reranking experiments, but those measurements are not a guarantee for a different corpus or retrieval stack.[1]

Failure mode: a confident label that is wrong

The extra label can create a new error path. If it assigns the wrong product, date, or definition, it may make a bad chunk look more relevant than it is. Generated context also adds indexing cost and can overemphasize repeated metadata. Treat labels as derived data: regenerate them when the source changes, preserve the original chunk, and sample-check labels against the source during evaluation.

The habit to keep

do not let a chunk enter a retrieval index as an orphaned paragraph. Give it a compact name tag that carries the document facts a later search cannot otherwise see.

Sources

  1. Anthropic: Contextual Retrieval in AI Systems
  2. Microsoft Learn: Chunk documents for vector search