advanced25 min studyLesson 671 in Engineering

Chunk boundaries: preserve source identity while budgeting overlap

Define token-window boundaries, overlap amplification, structural cuts, and versioned source mappings before building a retrieval index.

On this page

What you’ll understand

  • Calculate fixed-window chunk counts under an explicit stopping rule.
  • Track overlap without confusing duplicate evidence with independent support.
  • Define chunk identities and mappings across parser and tokenizer changes.

A chunk is both a retrieval unit and a claim about where text came from. Cutting a document changes which facts remain together, how often overlapping material is indexed, and how an answer can point back to evidence. Choose boundaries with an explicit tokenizer and source version, then evaluate retrieval and answer quality rather than assuming one window size works for every document.

A window rule needs a tokenizer and an end condition

For a teaching fixed-window rule, tokenize one nonempty normalized document into L tokens. Use window length w and overlap o, so successive starts differ by w−o. Start at zero and stop after the first window reaches the document end, keeping a possibly shorter final window. This rule differs from always creating every start below L, which can add a redundant trailing chunk. Empty documents, special tokens, headers, and parser failures need explicit policies. A character count is not a token count, especially across languages or structured content.

Tokenization itself includes normalization, segmentation, vocabulary rules, and possible post-processing. Changing any of these can change token positions without changing the displayed document meaning. Store the tokenizer artifact and normalization version with the ingestion manifest. If source citations use byte or character offsets, name the coordinate system and retain a tested mapping from parsed text to the original version. A token interval in one tokenizer is not automatically a valid byte span or a stable locator after document editing.

s=w−o,N=1+⌈max⁡(0,L−w)s⌉,Ij=[js,min⁡(js+w,L))s=w-o,\qquad N=1+\left\lceil\frac{\max(0,L-w)}{s}\right\rceil,\qquad I_j=[js,\min(js+w,L))
L,w are positive integer token counts, 0≤o<w, and j=0,…,N−1. This fixed-token-window rule stops when the first chunk reaches the end; intervals are half-open in this document's token coordinates. It excludes metadata, special tokens, and structural-boundary adjustments.↔ Scroll wide equations horizontally.

Overlap preserves local context at a measurable duplication cost

Overlap can keep a sentence or local relation visible in more than one chunk, but it does not guarantee that every relevant argument fits or that a table remains understandable. Under the exact window rule, repeated token occurrences increase index payload even though source coverage is unchanged. Neighboring retrieved chunks can therefore repeat the same evidence. Count unique source spans separately from raw hit count, and avoid interpreting several overlapping hits as independent confirmation of a claim.

Structure-aware cuts can keep headings, paragraphs, code blocks, or table headers with their content. Those choices replace the simple fixed-window arithmetic with measured chunk lengths and explicit maximum-size handling. A giant table may still need a specialized representation, while a short heading alone may be a poor embedding unit. Preserve parent structure and parser lineage so downstream expansion can recover needed context. Evaluate boundary-sensitive questions, cross-section references, and malformed extraction instead of optimizing only the average chunk length.

Lstored=∑j=0N−1∣Ij∣=L+(N−1)o,Astore=LstoredLL_{\rm stored}=\sum_{j=0}^{N-1}|I_j|=L+(N-1)o,\qquad A_{\rm store}=\frac{L_{\rm stored}}{L}
These exact token-occurrence counts apply to the stated fixed-window stopping rule with no padding or added headers. A_store is dimensionless duplication amplification, not a claim about compressed index bytes, embedding cost, or independent evidence count. Structural cuts require recounting.↔ Scroll wide equations horizontally.

Versioned identities make ingestion changes testable

A chunk record should distinguish logical document identity, immutable source version, parser and tokenizer configuration, local interval, and content digest. Two documents with identical text can have different ownership or permissions, so a digest alone is not a safe authorization identity. Rechunking creates a new index generation or mapping rather than silently reusing identifiers for different spans. Retain deletions and replacements in the update manifest so stale evidence and citations can be detected. Measure indexing cost and retrieval quality at a fixed document snapshot.

The modular lab isolates stride arithmetic only. Reset, set m=12 and a=3, predict period four, then Play or Step. Separately Reset, set m=12 and a=4, predict period three, then Play or Step. The orbit repeatedly adds a modulo twelve; it is not the linear document-window rule and cannot establish text coverage or overlap quality. Use the contrast to practice tracing starts under a precisely stated rule, then compute the actual half-open document intervals by hand without importing the cyclic model's wrapping behavior.

Count one fixed-window ingestion

A document has exactly 1,000 tokens under a pinned tokenizer. Use w=300 and overlap o=60, starting at zero and stopping when the first window reaches the end. Ignore headers and special tokens.

  1. Stride is 300−60=240 tokens. Chunk count is 1+ceil((1,000−300)/240)=4.

  2. Starts are 0,240,480,720. Half-open intervals end at 300,540,780,1,000, giving lengths 300,300,300,280.

  3. Stored token occurrences total 1,180=1,000+3×60, so amplification is 1.18. The extra 180 occurrences are overlap rather than new source information.

The result

Four chunks cover the source under this exact rule, with 18% extra token occurrences before any index metadata or embedding storage.

Explore the model

Interactive lab

Interactive lab · modular

Trace the rule before interpreting the stride

Reset, set m=12 and a=3, predict period 4, then Play or Step. Separately Reset, set m=12 and a=4, predict period 3, then Play or Step. This cyclic orbit does not implement document windows, text tokens, overlap, or source coverage.

Trace the rule before interpreting the strideAddition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Current readings: Residue r0: 0; Orbit period · m/gcd(m,a): 12; Distinct residues visited: 1 of 12. All parameters are adjustable with the labeled controls below.Repeated addition modulo 12: the current residue is 0, and the orbit period is 12.01234567891011+ 5mod 12An additive orbitn = 0rₙ = 0Period = 12Cycle starts at 0:0 → 5 → 10 → 3 →8 → 1 → 6 → 11 →4 → 9 → 2 → 7 → 0Exact residues · two additions per second
Additive orbitCurrent residue / next edge
Residue r0
0
Orbit period · m/gcd(m,a)
12
Distinct residues visited
1 of 12
t = 0 s

Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA stride calculation is meaningful only with its coordinate system and stopping rule.

Check your understanding

Why should two overlapping retrieved chunks not automatically count as two independent supporting sources?

Try it yourself

For L=850,w=300,o=50 under the same stopping rule, find the chunk starts and stored token occurrences.

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Stride is 250; keep the shorter final chunk and stop as soon as it reaches token 850.

Compare with the solution

There are 1+ceil(550/250)=4 chunks, starting at 0,250,500,750. Their lengths are 300,300,300,100, totaling 1,000 token occurrences. This equals 850+3×50 and represents 150 duplicate overlap occurrences, excluding headers or special tokens.

Take it with you

  • Chunk counts depend on exact tokenization and stopping rules.
  • Overlap adds repeated occurrences, not independent source support.
  • Source/version/span lineage must survive parser and index changes.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.