4.4.13 · D3Alignment, Prompting & RAG

Worked examples — Chunking strategies for retrieval

4,197 words19 min readBack to topic

Before we start, one promise: every symbol we use is one the parent already earned. Quick refresher so you never have to scroll:

Recall The six symbols we will reuse (peek if unsure)

::: total number of tokens in the document (a token ≈ 4 English characters; see Tokenization). ::: chunk size — how many tokens go into each piece. ::: overlap — how many tokens two neighbouring chunks share. stride ::: the number of new tokens each chunk adds beyond its predecessor, equal to . ::: number of chunks produced. ::: the length (in tokens) of a fact/answer span we want to keep whole.

One more piece of notation appears constantly below, so let's earn it now:

And the two formulas everything below tests:


The scenario matrix

Every chunk-sizing question is one of these cells. The examples below are labelled with the cell they hit, and together they touch all of them.

# Cell (case class) What makes it special Example
A Clean division, no overlap is a multiple of , Ex 1
B Ugly remainder, no overlap last chunk is partial → ceiling bites Ex 2
C Overlap present, non-integer division the parent's headline case Ex 3
D Degenerate: document smaller than one chunk → exactly 1 chunk Ex 4
E Limiting: overlap approaches chunk size stride , explodes; illegal Ex 5
F Zero / boundary: vs the break probability fact gets split Ex 6
G Real-world word problem: protect a fact (incl. ) choose from a span Ex 7
H Exam twist: solve backwards for given a budget inverse of the formula Ex 8
I Small-to-big: two different units index unit ≠ return unit Ex 9

The worked examples

Cell A — clean division, no overlap


Cell B — ugly remainder, no overlap


Cell C — overlap, non-integer division (the parent's headline)


Cell D — degenerate: document smaller than one chunk


Cell E — limiting behaviour: overlap approaches chunk size

Figure — Chunking strategies for retrieval

Cell F — the boundary that splits a fact ()

Figure — Chunking strategies for retrieval

Cell G — real-world word problem: protect a fact (and the trap)


Cell H — exam twist: solve backwards for


Cell I — small-to-big: two different units


Putting the matrix together

no

yes

no

yes

no

yes

no

yes

Sizing question

o less than c

Illegal stride zero or negative undefined

Overlap used

N divides c evenly

Cell A M equals N over c

Cell B ceiling adds tail

N bigger than c

Cell D exactly one chunk

Cell C use full formula

Cell E watch stride cliff

Cell G need c at least s then o at least s minus 1

Cell H solve backward for c

Cell I small to big two units


Active-recall flashcards

What does the ceiling operator mean?
Round up to the nearest whole number; it never rounds down, so any fractional leftover bumps the result up by one.
With , , , how many chunks and why?
; the ceiling keeps the 200-token tail as its own chunk.
Why does the chunk-count formula subtract in the numerator?
The first chunk consumes a full tokens; every later chunk adds only the stride , so we credit that one-time head start by subtracting the overlap once.
What is the legal range of the overlap ?
with an integer; if the stride is zero or negative and is undefined.
For a document smaller than one chunk (), what is ?
Exactly 1 — the ceiling forces whenever .
As overlap , what happens to the chunk count?
The stride so ; at the window never advances and is undefined.
Overlap needed to protect a 14-token fact (and the precondition)?
First need ; then so any window up to length straddling a boundary sits wholly inside one chunk.
Can any overlap protect a fact with ?
No — a length- window cannot fit inside a length- chunk; you must enlarge to at least first.
Break probability of a length- span with no overlap?
, because the span has internal gaps a boundary can land in.
Ex 7: with , , , how many chunks?
stride , .
Smallest chunk size giving for , ?
.
In small-to-big retrieval, what are the two different units?
A tiny index unit for precise matching and a larger parent unit returned to the LLM for context.