RAG Chunk Calculator
Plan chunk size, overlap, chunk count, and one-time embedding cost for a document corpus.
A rough planning estimate (corpus of 2,000,000 tokens). Real chunk counts vary with your splitter and token counter; overlap is re-embedded so smaller overlap = fewer tokens.
What this tool does
The RAG Chunk Calculator plans the ingestion step of a retrieval-augmented generation system. You enter the number of documents, their average length in tokens, the chunk size and overlap your splitter will use, and an embedding price. It returns chunks per document, total chunks, tokens to embed and the one-time embedding cost.
Engineers and architects use it before building the pipeline: to compare chunk-size and overlap choices, to estimate index size (one vector per chunk), and to see whether re-embedding a corpus after a splitter change is cheap or expensive. It answers a sizing question, not a quality one; which chunk size retrieves best needs an evaluation on your own questions.
How it works
The tool treats every document as the same length and slides a window of chunk-size tokens across it. Each chunk starts (chunk size minus overlap) tokens after the previous one. The arithmetic runs in your browser as you type, and the tool makes no network request for it.
- Stride
- stride = max(1, chunk - overlap)
- Chunks per document
- chunksPerDoc = ceil( max(0, tokensPerDoc - overlap) / stride ), or 0 if tokensPerDoc is 0
- Total chunks
- totalChunks = chunksPerDoc x docs
- Tokens to embed
- embeddedTokens = totalChunks x chunk
- One-time embedding cost
- embedCost = embeddedTokens / 1,000,000 x embedPrice
What it assumes
- Every document has the average length you enter; real corpora have short and very long documents, so true counts will differ.
- Every chunk is counted at the full chunk size, including each document's shorter last chunk, so tokens to embed is an overestimate: small for long documents, larger for short ones.
- Blank, negative or non-numeric inputs count as 0. If overlap is not smaller than chunk size, the stride falls back to 1 and the tool shows a warning.
- The $0.02 per million tokens in the price field is only a starting value, not a looked-up price. Enter your provider's current price.
- Only the one-time corpus embedding is counted: not vector storage, query embeddings, re-indexing or the answering model.
Worked example
An illustrative knowledge base of 500 documents, split into 512-token chunks with a 64-token overlap, at an illustrative price of $0.02 per million tokens (the tool's default inputs).
| Input | Value |
|---|---|
| Documents | 500 |
| Avg tokens / document | 4,000 |
| Chunk size | 512 tokens |
| Chunk overlap | 64 tokens |
| Embedding price | $0.02 per 1M tokens |
- stride = max(1, 512 - 64) = 448
- chunksPerDoc = ceil((4,000 - 64) / 448) = ceil(8.79) = 9
- totalChunks = 9 x 500 = 4,500
- embeddedTokens = 4,500 x 512 = 2,304,000
- embedCost = 2,304,000 / 1,000,000 x 0.02 = 0.04608
9 chunks per document, 4,500 total chunks, 2,304,000 tokens to embed, and a cost shown as $0.0461 (four decimals for amounts under $1). The corpus is 2,000,000 tokens, so overlap and partial last chunks add about 15%.
Frequently asked questions
- Why are the tokens to embed more than my corpus size?
- Overlap repeats tokens between neighbouring chunks, and every chunk is counted at full size. In the example, a 2,000,000-token corpus becomes 2,304,000 embedded tokens.
- What chunk size and overlap should I use?
- The calculator does not recommend one. It shows what each choice costs in chunks and tokens; compare retrieval quality on a test set to choose.
- Why do I get 0 chunks?
- The overlap is subtracted from the document length first. If the average document is no longer than the overlap, the result is 0. Lower the overlap or check the length.
- How is a document shorter than the chunk size counted?
- As one chunk (if longer than the overlap), billed at the full chunk size, so many short documents overstate the cost.
- Does the cost include answering questions?
- No. Only the one-time embedding of the corpus is included. Query embeddings, vector storage, re-embedding and the answering model are separate.
Read the guide
Building this for real?
I help teams design and ship AI systems — cost modelling, RAG, agents, and architecture.
Work with me