4.4.13 · D2Alignment, Prompting & RAG

Visual walkthrough — Chunking strategies for retrieval

1,999 words9 min readBack to topic

This is the visual companion to Chunking strategies for retrieval. If a word here feels unexplained (embedding, similarity, tokens), the linked prerequisite notes below build it.


Step 1 — What is a token? Draw the raw material

WHAT: Lay the whole document out as one long horizontal row of little squares. Each square is one token.

WHY: Before we can cut anything, we need a ruler. The row of tokens IS our ruler — position . The total count of squares is the symbol .

PICTURE: Look at the strip below. It is tokens wide. The number under each square is its position.

Figure — Chunking strategies for retrieval

Step 2 — A chunk is a window of width

WHAT: Place a window (a coloured box) over the first squares of the strip: positions through .

WHY: A retriever can only ever hand back one of these boxes (each box becomes one embedding vector stored in a vector database). So the box is the atom of retrieval. Its width is our choice — the central knob of chunking.

PICTURE: The blue box below covers exactly tokens. Notice it starts at position and ends at position ; that "" is because we count the first square as position , not .

Figure — Chunking strategies for retrieval

Step 3 — Why we must overlap: a fact falls in the crack

WHAT: Draw two adjacent boxes touching at position (no gap, no overlap). Drop a pink answer span of tokens right on top of that seam.

WHY: This is the failure we are trying to prevent. Seeing the pink span straddling the seam is the whole motivation for overlap — without this picture the formula's term looks arbitrary.

PICTURE: The pink span sits half in the left box, half in the right box. Neither box holds all of it. That is a broken span.

Figure — Chunking strategies for retrieval

Step 4 — Overlap : let neighbours share a strip of tokens

WHAT: Slide the second box left so it starts at position instead of . Now the region belongs to both boxes.

WHY: The shared strip is a safety net. Any answer span that fits inside a window of width straddling the seam is now fully contained in at least one box. Set that safety width to cover our span length :

PICTURE: The green shaded strip is the overlap. Watch the same pink span from Step 3 — now the right box, reaching back into the green, swallows it whole.

Figure — Chunking strategies for retrieval

Step 5 — The stride: how far each box advances

WHAT: Measure the gap between the start of box 1 (position ) and the start of box 2 (position ).

WHY: This distance is what actually eats through the strip. The width is how much each box sees; the stride is how much fresh ground each box conquers. Confusing the two is the classic chunking bug.

PICTURE: The yellow arrow spans from start-of-box-1 to start-of-box-2. Its length is .

Figure — Chunking strategies for retrieval

Step 6 — Counting the boxes: assembling

WHAT: Chain the boxes across the whole strip and count them. Box 1 covers tokens; each of the remaining boxes adds a stride. We need the total reach to hit at least .

WHY: We want the smallest whose boxes still cover the last token — no fact left uncovered. That "smallest whole number that is big enough" is exactly what the ceiling means.

PICTURE: Boxes tiled left-to-right, the first one flagged as the "startup cost" , the rest as repeated strides. The final box reaches (or passes) position .

Figure — Chunking strategies for retrieval

Set the coverage requirement and solve:


Step 7 — The degenerate cases (never let the reader fall through)

WHAT: Push each knob to an extreme and read the formula.

WHY: A formula you trust must survive its own boundaries. Here is every corner:

Figure — Chunking strategies for retrieval

The one-picture summary

Figure — Chunking strategies for retrieval

One figure holds the entire derivation: a token strip of length , three overlapping windows of width , the shared green overlap , the yellow stride arrow , and the count boxes — with the assembled formula printed beneath.

Recall Feynman retelling — the whole walk in plain words

Picture a long paper tape, one word per square — that length is . To find facts fast you lay a small frame of width over the tape; whatever the frame shows becomes one searchable "card." But if you slide the frame in clean jumps of , a two-word fact sitting on a seam gets sliced in half and is lost forever. So you pull each next frame back a little, letting it re-read the last words of the previous one — that shared strip catches any fact of length up to , so you pick at least for an answer of words. Because of the sharing, each frame after the first only walks forward by new words — the stride. The first frame costs a full ; the rest each cost one stride. Add them up, demand you cover the last word, round up so the leftover bit still gets a card, and out drops . Freeze the frame () and it never moves — infinite cards — which is why overlap must stay smaller than the chunk.

Recall Quick self-test

What does the stride measure? ::: The number of new tokens each chunk adds beyond the previous one. Why is there a ceiling in ? ::: A partial final chunk still needs its own embedding vector, so we round up. Set in the formula — what do you get? ::: , the plain no-overlap tiling. Why must ? ::: If the stride , the window never advances and blows up. Minimum overlap to keep an -token answer intact? ::: .

Back to the parent: Chunking strategies for retrieval · related: Retrieval-Augmented Generation (RAG), Metadata Filtering in Retrieval.