SproutStackSproutStack home

Chunking Strategies

6 min readBeginner-friendlyFree to read

Read a little, play a little. No scary maths, and no rush.

Share:

Why chunking decides RAG quality

Retrieval returns whole chunks, so chunk boundaries are your answer boundaries. Too big and matches turn fuzzy while token bills swell; too small and each chunk lacks the context to be useful (or citable). Chunking strategy routinely moves retrieval quality more than swapping embedding models — unglamorous, decisive. Play /animations/chunking to feel the tradeoff.

The recipe that works most places

  • Split by headings first, then by tokens (never characters — token limits are what bind).
  • 300–800 tokens with 10–20% overlap, so ideas spanning a boundary survive in at least one chunk.
  • Keep metadata: {source, section, page, updated} — citations and tenant/date filters depend on it.
  • Tables and code stay whole. Slicing mid-row produces nonsense both humans and models confidently misread.
def chunk(text, n=500, overlap=80):
    words = text.split()
    out, i = [], 0
    while i < len(words):
        out.append(" ".join(words[i:i+n]))
        i += n - overlap
    return out

Two documents, two shapes

An FAQ page already has natural units: one question and its answer. Make each pair its own chunk. A user's question then matches the stored question closely, and the answer arrives complete.

A product manual is long sections nested under headings. Split by section, and put the heading path at the top of each chunk, such as "Billing > Refunds > Partial refunds". A paragraph that says "this applies within 14 days" means nothing on its own; with its heading path attached, both the embedding and the model know what "this" refers to.

Smarter strategies you will hear about

  • Semantic chunking splits where the topic shifts, detected by comparing the embeddings of neighboring sentences, instead of at a fixed length.
  • Small-to-big (also called parent-child) retrieves small, precise chunks for accurate matching, then hands the model the larger section each one came from, so it gets the surrounding context.
  • Sentence windows retrieve a single matching sentence and include a few sentences on either side.

All three are refinements of the basic recipe, not replacements. Start simple, measure, and adopt one only when your eval set shows it helps.

Common mistakes

  • Garbage in from PDFs. Extracted text often repeats page headers, footers, and page numbers in every chunk. Clean them out before chunking, or they pollute every embedding.
  • Huge chunks "to be safe." Large chunks dilute the match and cost more tokens on every query.
  • No overlap. A sentence split across a boundary is lost from both halves.
  • Forgetting updates. When a document changes, its old chunks must be replaced, not left beside the new ones.

How to know yours works

Don't debate chunk sizes in meetings — measure. Build the golden eval set (see Evals Basics), try 2–3 chunkings, and compare recall@K. Different corpora genuinely want different shapes: legal clauses like small precise chunks, tutorials like bigger narrative ones.

A sensible first attempt

If you have no data yet to guide you, start with sections split at headings, about 500 tokens per chunk, 80 tokens of overlap, and the heading path prepended to every chunk. Retrieve the top 4 or 5. Then build a small eval set of real questions and let the numbers, not instinct, tell you whether to go smaller or larger.

Remember this

  • Headings → tokens, 300–800 with overlap, metadata always, tables whole.
  • Chunking is an experiment with a number attached, not an opinion.

Check your understanding

5 questions · first-try answers earn the most XP

1. You chunk a technical document into fixed 2,000-token blocks with no overlap. A user asks about a definition that straddles the boundary of blocks 4 and 5. What breaks?
2. Which chunk size is most likely to work well for retrieving a specific fact from a long FAQ document?
3. Your retrieval quality report shows high recall at K=20 but the answers are worse than before. What most likely happened?
4. What is the main reason to preserve document headings when you chunk?
5. Your documents change every day. What is the least disruptive way to keep the index current?

My notes

Saved in this browser. Highlight a line above and save it, or write it in your own words.

Nothing saved yet. Your highlights will live here.

References

Finished reading?

Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.

Practice this in an incident

Related chapters

Spotted a mistake or want a topic covered? Report an issue

📬 An occasional email when new lessons land

New lessons and showdowns, no more than a few times a month. No spam, unsubscribe anytime. We store your email only to send the newsletter.