C.W.K.
Stream
Lesson 01 of 05 · published

Why Chunk at All

~18 min · chunking, intuition

Level 0Scout
0 XP0/41 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Chunking exists for two reasons

  1. Embedding models have a token limit. Anything longer than the limit gets silently truncated.
  2. A whole document averages too many topics into one vector. A 10-page document about "billing" might cover trial signup, refund policy, dunning emails, and tax compliance. Embedding all of it as one point puts you in the average of those topics — far from any specific answer.

The retrieval-vs-context tradeoff

Smaller chunks → more precise retrieval but less context per hit. Larger chunks → richer context but noisier matches and a higher chance the chunk crosses topic boundaries. The sweet spot for most knowledge bases lands in the 200–800 token range with 10–20% overlap between adjacent chunks. That is a starting point, not a law — measure on your own corpus.

The four splitter families

  1. Fixed-size — every N characters or tokens. Brain-dead but reliable.
  2. Recursive character — try paragraphs, then sentences, then words. LangChain's default.
  3. Structure-aware — Markdown headings, HTML tags, code AST. Preserves logical boundaries.
  4. Semantic — embed sentences and start a new chunk when the running average drifts. Highest quality, slowest, most opaque.

Code

Fixed-size character split (the simplest baseline)·python
def fixed_chunks(text: str, size: int = 1200, overlap: int = 200):
    chunks = []
    start = 0
    while start < len(text):
        end = start + size
        chunks.append(text[start:end])
        start = end - overlap
    return chunks

chunks = fixed_chunks(open('handbook.md').read())
print(f'{len(chunks)} chunks, avg {sum(len(c) for c in chunks)//len(chunks)} chars')

External links

Exercise

Take one of your real documents (>3000 tokens). Chunk it three ways: 256 tokens / 512 tokens / 1024 tokens, all with 10% overlap. Embed each set. Run the same 5 queries. Manually rank the top result for each query. The winner becomes your starting chunk size.

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.