Choosing Chunk Size
Learn how to choose a chunk size that gives your RAG system useful context without creating noisy, expensive, or hard-to-retrieve chunks.
By the end of this lesson, you will be able to:
- Explain why there is no single perfect chunk size for every RAG system.
- Choose a starting chunk size using document type, model context, and retrieval needs.
- Understand the relationship between chunk size and overlap.
- Compare small and large chunks using Python experiments.
- Evaluate retrieval quality instead of choosing a size by habit.
- Use metadata and document structure alongside chunk size decisions.
What Is Chunk Size?
Chunk size is the amount of content placed into one chunk before that chunk is embedded and stored for retrieval. Depending on the chunker, size can be measured in characters, words, tokens, sentences, or another unit.
The important question is not βWhat number should I always use?β It is βHow much context does one retrieved chunk need to answer the questions users actually ask?β
Why Chunk Size Matters
Context can disappear
A chunk may contain only one detail while the explanation, definition, or condition needed to interpret it lives in another chunk.
Retrieval gets noisy
A large chunk may contain the answer plus many unrelated paragraphs, making ranking and generation less focused.
A useful chunk size sits between these extremes: enough context to preserve meaning, but small enough for precise retrieval.
Small vs Large Chunks
Precise retrieval
Smaller chunks often make it easier to retrieve a narrow fact or sentence.
Balanced context
Medium chunks often provide a practical balance between precision and enough surrounding explanation.
More context
Larger chunks can preserve complete sections, but may reduce retrieval precision and consume more context.
Measure it
Use representative questions and compare retrieval quality rather than assuming one size is best.
Tokens Are Often a Better Unit
Words and characters are convenient, but tokens are often more useful when working with language models because model context limits are expressed in tokens.
text = "Chunk size controls how much context each retrieved unit contains."
words = text.split()
print("Words:", len(words))
print("Approximate chunk target:", 12, "words")This is only a simple illustration. Production systems should use a tokenizer appropriate for the embedding or generation model when token limits matter.
Start With the Document Structure
Chunk size should not be chosen independently of the document. A technical manual, FAQ, legal policy, and product catalog have different natural units of meaning.
Sections and subsections
Preserve headings, explanations, code context, and related steps when possible.
Question + answer
Keep each question with its answer instead of splitting the pair into unrelated chunks.
Chunk Size and Overlap
Chunk size and overlap work together. If the chunk size is 500 tokens and the overlap is 50 tokens, the next chunk starts 450 tokens after the previous start.
Increasing overlap can protect information near boundaries, but it also increases repeated content, storage, embedding work, and potentially retrieval redundancy.
Python: Compare Candidate Sizes
A simple experiment can show how many chunks different sizes create for the same document.
def chunk_words(words, size):
return [words[i:i + size] for i in range(0, len(words), size)]
text = ("RAG retrieves relevant context before generation. "
"Chunk size affects retrieval precision and context. "
"Good evaluation uses realistic user questions.")
words = text.split()
for size in [5, 10, 15]:
chunks = chunk_words(words, size)
print(size, "words ->", len(chunks), "chunks")This does not prove which size is best. It gives you candidates to test with embeddings and real retrieval questions.
Chunk Size and Retrieval Precision
Suppose a user asks, βWhat is the refund window for damaged products?β A tiny chunk containing only β30 daysβ may be hard to interpret. A huge chunk containing an entire returns policy may include many unrelated rules.
Ask a realistic question
Use the same questions real users are likely to ask.
Compare top results
Check whether the relevant chunk appears near the top.
Read the context
Check whether the retrieved text contains enough information to answer correctly.
Test multiple sizes
Compare candidate sizes across many questions, not one example.
Chunk Size and Context Window
Your generator may support a large context window, but that does not mean every retrieved chunk should be large. Retrieval quality still matters.
If you retrieve several large chunks, their combined size can quickly consume the available context. Smaller, focused chunks can sometimes let the system retrieve more distinct evidence.
Chunk Size by Use Case
Often smaller
FAQ answers, product attributes, and short policies may benefit from focused chunks.
Often larger
Educational or technical material may need surrounding explanation, examples, and conditions.
Preserve structure
Keep a function with the relevant explanation and avoid splitting code arbitrarily when possible.
Respect sections
Keep definitions, conditions, exceptions, and headings together when they form one rule.
A Practical Starting Strategy
There is no universal number, but you can use a controlled process instead of guessing.
Understand the content
Identify natural units such as sections, paragraphs, questions, or procedures.
Choose a few candidates
Test several reasonable sizes instead of tuning one value blindly.
Add appropriate overlap
Protect boundaries only as much as the content requires.
Evaluate retrieval
Measure whether the right evidence is retrieved for realistic questions.
How to Evaluate Chunk Size
Build a small evaluation set with questions and expected evidence. Compare candidate chunk sizes using metrics such as retrieval hit rate, ranking position, answer correctness, and context usefulness.
results = {
250: [1, 1, 0, 1, 1],
500: [1, 1, 1, 1, 1],
800: [1, 0, 1, 1, 0],
}
for size, hits in results.items():
hit_rate = sum(hits) / len(hits)
print(f"{size} tokens: {hit_rate:.0%} hit rate")The example is intentionally simple. Real evaluation should use a larger, representative test set and inspect whether retrieved context actually supports the final answer.
Common Mistakes
- Using one size everywhere: different document types may need different strategies.
- Optimizing only for chunk count: fewer chunks does not automatically mean better retrieval.
- Ignoring structure: splitting headings, definitions, or question-answer pairs can damage meaning.
- Using excessive overlap: repeated content can increase cost and retrieval noise.
- Testing one query: a single successful retrieval is not enough evidence.
- Ignoring the generator: retrieved context must fit the overall context budget.
Chunk Size Is a System-Level Decision
Chunk size interacts with chunking strategy, overlap, embedding model, vector index, retrieval method, reranking, metadata filters, and the language model that generates the final answer.
Practice: Test Three Chunk Sizes
Take a short document and create chunks using three candidate sizes. Use five realistic questions and record whether the correct evidence appears in the top retrieved results.
Compare retrieval quality
Try small, medium, and large chunks. Keep the embedding and retrieval method the same, then compare the results.
Quick Quiz
1. Why can very small chunks hurt RAG?
They may retrieve a detail without the surrounding context needed to interpret it correctly.
2. Why can very large chunks hurt retrieval?
They can contain too much unrelated content, reducing precision and consuming more context.
3. What should determine chunk size?
Document structure, user questions, retrieval quality, model context, and system cost should all influence the decision.
4. Is there one universally correct chunk size?
No. The right size is workload-dependent and should be validated with evaluation data.
30-Second Recap
Enough context, without unnecessary noise.
Respect natural document boundaries.
Use it to protect important boundaries.
Choose using realistic retrieval tests.
Key Takeaways
- Chunk size directly affects retrieval precision and available context.
- Small chunks can improve focus but may lose surrounding meaning.
- Large chunks preserve context but can introduce noise and higher cost.
- Tokens are often a useful unit when model context limits matter.
- Document structure and overlap should be considered together with size.
- The best chunk size is the one validated by your workload and evaluation set.