C.W.K.
Stream
Lesson 03 of 10 · published

Chunking Strategies That Don't Lose the Argument

~18 min · context, chunking, rag

Level 0Apprentice
0 XP0/100 lessons0/14 achievements
0/120 XP to next level120 XP to go0% complete

The 500-token chunk is a default, not a law

A common starter chunk size is 500 tokens with 50-token overlap. It's a default that works on generic prose; it's a disaster on legal documents (where one paragraph spans 2,000 tokens), code (where boundaries are functions or classes), or chat logs (where a turn is the unit of meaning). Chunk size should follow the structure of the source.

Strategies that work

  • Structural chunking — split on headings, sections, function definitions, log entries. Aligns with how the document was authored.
  • Sliding window with overlap — generic prose where structure is light. Overlap so a sentence near the boundary stays attached to its neighbors.
  • Semantic chunking — embedding-based, splits where the embedding distance changes sharply. Useful for free-form text.
  • Contextual headers — prepend a one-sentence summary of the parent section to each chunk so retrieval doesn't lose the topic.

The argument-preservation test

For each chunking strategy, take a long argument from your corpus (a multi-paragraph claim, a step-by-step procedure). Ask: does the strategy keep the argument together? If the chunk break splits the conclusion from the premises, retrieval will surface either piece without the other and the model will work from half the case.

Code

Contextual chunk header (Anthropic-style)·python
def add_context_header(chunk: str, source_title: str, section: str) -> str:
    return (
        f"<source>{source_title}</source>\n"
        f"<section>{section}</section>\n"
        f"<content>\n{chunk}\n</content>"
    )

# After embedding the contextualized chunk, retrieval becomes
# robust to keyword drift across sections.

External links

Exercise

Take 20 documents from your corpus and chunk them three ways: 500-token sliding, structural (headings), and contextual headers. Run a small set of queries against each. Compare retrieval quality.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.