Practical technical guides / AI engineering: retrieval evaluation

Rechunking Silently Breaks a Retrieval Eval: Label Relevant Character Spans, Not Chunk IDs

After rechunking, labels keyed by chunk id scored 3 of 8 where span labels scored 5 of 8, with a false hit and a false miss. Store character spans and pick a rule.

By Sandeep Belgavi · Published 2026-11-08

After rechunking, labels keyed by chunk id scored 3 of 8 where span labels scored 5 of 8, with a false hit and a false miss. Store character spans and pick a rule.

The eval said the new chunking was worse

Geetha maintains the retrieval behind the help-desk assistant at Belgavi's Book Store. The policy documents were split into 400-character chunks, and an evaluation set of questions was labelled by hand: for each question, the id of the chunk that holds the answer, such as returns#1. When the team tried 200-character chunks with 40 characters of overlap, the hit rate at 3 fell from 7 of 8 to 3 of 8, and the change was nearly rejected.

The retrieval had not got worse. The labels had stopped meaning anything. After rechunking, returns#1 names a different stretch of text, so the eval was scoring the new retriever against the old chunk boundaries. This guide shows the problem on a small synthetic corpus and the fix: store each label as a character span in the source document, and decide at evaluation time which chunks count as relevant.

Why chunk-id labels break

Information retrieval evaluation has used relevance judgements keyed by document id for decades; the TREC qrels format is a list of query id, document id and relevance grade. That works when the unit being retrieved is stable. In retrieval-augmented generation the retrieved unit is a chunk, and chunks are an implementation detail that changes whenever someone tunes the chunk size, the overlap, the splitter or the document parser.

A chunk id such as returns#1 is a position in one chunking. Under another chunking the same id can exist and point somewhere else, which produces false hits, or the answer can sit in a chunk whose id is not in the label set, which produces false misses. Both happened in the run below.

ChunkingHits by frozen chunk idsHits by span, chunk contains answerHits by span, half the answer overlaps
400 characters, no overlap (labels built here)7 of 87 of 87 of 8
200 characters, 40 overlap3 of 85 of 87 of 8
120 characters, no overlap1 of 82 of 88 of 8
600 characters, 100 overlap6 of 88 of 88 of 8

On the chunking the labels were built with, all three methods agree, as they must. On every other chunking the id-based score is wrong. With 200-character chunks it reported a hit for "What happens to a parcel nobody collects?" because the retriever returned shipping#1, which under the new chunking holds the sentences about free shipping, preorders and tracking links, not the answer. It reported a miss for "How long do refunds take to reach my card?" although the top result, returns#2, contains the whole answer.

Labels as spans

A span label records where the answer is in the source, independent of how the source is split:

{"question": "How long do refunds take to reach my card?", "doc": "returns", "start": 438, "end": 495}

Create it by locating the answer text in the document when the label is written, and fail loudly if the text is not found. Store it with a content hash of the document, so a later edit to the policy text is detected instead of silently shifting every offset.

def span_labels():
    out = []
    for q, doc, answer in QUESTIONS:
        start = DOCS[doc].find(answer)
        if start < 0:
            raise ValueError(f'answer not found for {q!r}')
        out.append({'question': q, 'doc': doc, 'start': start, 'end': start + len(answer)})
    return out

Every chunk must carry its own document id and character offsets. Most chunkers already know them; keep them in the chunk metadata rather than recomputing them later. At evaluation time a chunk is relevant to a question if it overlaps the label's span according to a rule you choose.

Choosing the relevance rule

The table shows that the rule matters as much as the labels. Two reasonable rules:

  • Contains: the chunk contains the whole answer span. Strict, and correct when the answer must be quoted in full. With 120-character chunks it scored only 2 of 8, because most answers are longer than or cross a chunk boundary, so no single chunk contains them.
  • Half overlap: the chunk covers at least half of the answer span. Lenient, and closer to what a generator needs when several chunks are passed together. It scored 8 of 8 on the same chunks.

Neither is the right answer in general. Pick the rule that matches how the generator uses context, write it down next to the eval set, and report it with every score. If answers are usually long, also report a coverage measure: the fraction of the answer span covered by the union of the top-k chunks. That number rewards a retriever that brings back both halves of an answer split across two chunks.

def relevant(c, l, rule):
    if c['doc'] != l['doc']:
        return False
    if rule == 'contains':
        return c['start'] <= l['start'] and l['end'] <= c['end']
    return min(c['end'], l['end']) - max(c['start'], l['start']) >= (l['end'] - l['start']) // 2

Migrating an existing id-labelled set

You do not need to relabel by hand. For each existing label, take the chunk text from the chunking the labels were built on, and find the answer within it: if the original labeller highlighted a sentence, use it; if not, have a reviewer mark the answer sentence once inside the labelled chunk, which is faster than searching the document. Convert the chunk-local offsets to document offsets using the chunk's start. Then re-run the eval on the original chunking with span labels and confirm the scores match the id-based scores exactly. Any difference is a labelling error to fix before you compare chunkings.

Keep the converted set in version control with the document hashes. When a source document changes, re-locate each answer string in the new text; if it is found once, update the offsets, and if it is missing or found twice, send the label for review.

What this does not solve

Span labels make an eval comparable across chunkings. They do not make the eval complete. Questions whose answer depends on two documents need two spans and a rule for when both must be retrieved. Questions with no answer in the corpus need a label that says so, and a metric that rewards retrieving nothing relevant rather than penalising it. And a keyword retriever, as in the companion code, is a stand-in: the example demonstrates the labelling problem, not the quality of any retrieval method.

There is also a neighbouring problem that span labels expose but do not fix: overlapping chunks can fill the top-k with copies of the same passage. If that happens, de-duplicate or merge by source span before scoring, which is a separate decision from how relevance is labelled.

Failure modes to test for

  • Offsets computed on different text. The parser that produced chunks normalised whitespace or stripped markup, and the labels were located in raw text. Locate answers in exactly the text the chunker receives.
  • Unicode offsets. One side counts bytes, the other code points. Pick code points, and test with a document containing non-ASCII characters.
  • A rule changed silently. A score from "contains" is compared with one from "half overlap". Store the rule in the result file.
  • Labels that no longer match the document. The hash check catches edits; without it, every offset after the edit points at the wrong text.

Verifying it

The companion tests check that every answer is located exactly; that on the original chunking ids and spans agree on every question; that after rechunking to 200 characters the id-based score is 3 of 8 against 5 of 8 by span, including the false hit and the false miss above; that the relevance rule changes the 120-character result from 2 of 8 to 8 of 8; and that the chunker rejects an overlap as large as the chunk. Before you compare two chunkings in your own system, add one assertion like the second: same chunking, same score, whichever way the labels are stored.

Primary references and authorship

Original explanation and synthetic examples by Sandeep Belgavi. Companion code: Sandeep-BA/agent-decision-lab/examples/python/span_relevance_labels. Views are my own and do not represent any employer, past or present.