Chunk Size Calculator
Determine the number of RAG chunks and effective coverage per chunk for a given document length and overlap.
Inputs
Should not exceed the embedding model's context window.
Percentage of each chunk repeated at the start of the next chunk to preserve context.
Number of Chunks
19
Effective New Content per Chunk
435tokens
Overlap Tokens
77tokens
Storage Redundancy from Overlap
17.8%
Step by step
Overlap tokens: chunk size × overlap %
512 × 15%
= 77 tokens
Effective stride (new content per chunk): chunk size − overlap tokens
512 − 77
= 435 tokens
Number of chunks: ⌈document length ÷ effective stride⌉
⌈8000 ÷ 435⌉
= 19
Redundancy from overlap: (total embedded tokens − doc length) ÷ total embedded tokens
(9728 − 8000) ÷ 9728
= 17.8%
How it works
RAG chunking splits a document into overlapping windows so that context near chunk boundaries isn't lost: num_chunks = ceil(document_length / (chunk_size − overlap_tokens)), where overlap_tokens = chunk_size × overlap%. Larger chunks capture more context per retrieval but reduce precision (more irrelevant text mixed in) and risk exceeding the embedding model's context window; smaller chunks improve retrieval precision but multiply storage and embedding cost, and overlap adds redundancy that trades extra storage for continuity across chunk boundaries.
Formula
num_chunks = ceil(doc_length / (chunk_size - chunk_size * overlap_percent / 100))
- doc_length
- Average document length in tokens
- chunk_size
- Chunk size in tokens
- overlap_percent
- Overlap between consecutive chunks as a percentage
Frequently Asked Questions
What's a good default chunk size?
300-800 tokens is a common starting range for general text RAG — small enough for precise retrieval, large enough to retain coherent context; the right value depends on your content type (dense technical text often benefits from smaller chunks, narrative text from larger ones).
Why use overlap between chunks at all?
Without overlap, a sentence or idea split exactly at a chunk boundary can lose context in both resulting chunks; overlap ensures each chunk contains a 'tail' of the preceding chunk's content so boundary-spanning information isn't lost.
What happens if chunk size exceeds the embedding model's context window?
The embedding API will typically truncate the input to fit its context window, silently discarding the excess text — always keep chunk size safely below the embedding model's maximum context window.
How does overlap affect storage cost?
Higher overlap percentages increase the number of chunks needed to cover a document (since each chunk contributes less new content), which directly increases both embedding cost and vector storage — see the Redundancy result for exactly how much duplicate content this adds.