Tune passage size and overlap against answer-span recall, citation precision, duplicate context and indexing cost.
Chunk boundaries: test whether the answer survives the split
Chunking is a retrieval decision
A chunk is the smallest passage the index can return, so its boundaries determine what a retriever can prove. Splitting a procedure between a warning and the step it qualifies may produce a passage that looks relevant but is unsafe alone. Keeping an entire handbook as one chunk dilutes a precise answer and consumes context. Start with source structure: headings, paragraphs, table rows and transcript time ranges. Preserve parent document and revision identity so the original location remains auditable. Chunk identity defines stable IDs and citation boundaries after a split.
Treat overlap as a measured tradeoff
Overlap repeats material across adjacent chunks and can rescue an answer span crossing a fixed window. It also increases token storage, embedding work, candidate duplication and the chance that the same source is mistaken for independent support. A fixed percentage is not a guarantee: a table header, a negation or a section title may fall outside both useful windows. Prefer structure-aware boundaries; use overlap only where judged cases show a gain. Duplicate evidence must be collapsed before citing corroboration.
Record exact answer spans
For each judged query, annotate the source document, revision and minimal answer-bearing span, including qualifiers that change the claim. After chunking, ask whether at least one eligible returned chunk contains that full span. Measure answer-span recall at K, citation precision and the fraction of retrieved tokens that are duplicate overlap. This is more informative than measuring whether any chunk from the right document was returned. An answer can mention the right manual while omitting the limit value or exception that makes the result useful.
Use parent context without losing provenance
A small child chunk can retrieve accurately; a larger parent section can supply the surrounding condition. Keep the child's offset and the parent's revision, then expand context within a strict token budget. Never merge text across documents or policy revisions just because their headings match. For tables, keep header labels and units with each row. Parent-child retrieval describes the serving pattern, while table retrieval covers row-level evidence.
Run controlled chunking experiments
Hold corpus, queries, embedding model, retriever settings and K constant while changing only the splitting rule. Compare section-aware windows, fixed token windows and minimal overlap on the same answer-span labels. Inspect misses by document type: code blocks, tables, scanned PDFs and incident timelines behave differently. Count extra index entries and ingest time, not just recall. A higher recall score that doubles repeated context and citation confusion can worsen the final answer. Release gates should require both evidence quality and acceptable cost.
Worked contract
from dataclasses import dataclass
@dataclass(frozen=True)
class PassageWindow:
document_id: str
start: int
end: int
def windows(document_id: str, token_count: int, size: int,
overlap: int) -> list[PassageWindow]:
if token_count < 0 or size < 1 or not 0 <= overlap < size:
raise ValueError("invalid chunk settings")
result = []
step = size - overlap
for start in range(0, token_count, step):
end = min(start + size, token_count)
result.append(PassageWindow(document_id, start, end))
if end == token_count:
break
return result
def span_is_complete(chunks: list[PassageWindow], document_id: str,
answer_start: int, answer_end: int) -> bool:
return any(chunk.document_id == document_id
and chunk.start <= answer_start
and answer_end <= chunk.end for chunk in chunks)
plain = windows("pump-p47-v3", 83, 30, 0)
with_overlap = windows("pump-p47-v3", 83, 30, 12)
assert not span_is_complete(plain, "pump-p47-v3", 24, 35)
assert span_is_complete(with_overlap, "pump-p47-v3", 24, 35)
assert with_overlap[-1].end == 83Performance and operating cost
For T tokens, window size C and overlap O, the number of windows is roughly T divided by C minus O, so index entries and embedding work rise as overlap approaches C. The example emits windows in O(W) time and O(W) space for W windows; checking one answer span costs O(W) time. Actual tokenizer counts, structural parsing, retrieval and reranking add further cost. Keep offsets in the tokenization version used to build the index, or citations will drift after reprocessing.
Common Mistakes
- Selecting chunk size from model limits alone without measuring complete answer spans.
- Counting overlapping copies of one passage as independent evidence.
- Splitting a table value away from its unit or header.
- Changing tokenizer or parser without rebuilding offsets and citation IDs.
Validation drill
Annotate 53 answer spans across prose, tables and procedures. Compare three splitting policies at the same top-12 budget; report complete-span recall, duplicated retrieved tokens, index size and citation errors.
