Designing chunking and token budgets before you build
Most RAG prototypes look cheap on 50 sample PDFs and surprise teams in production. Two multipliers drive almost all of the cost: chunks per document (which determines vector count, embedding cost, and RAM for your vector index) and input tokens per query (top_k × chunk_size + system_prompt multiplied by monthly query volume).
Recursive vs. fixed-window chunking
- Recursive splitting breaks on paragraph boundaries first, then sentences, preserving complete ideas at the cost of slight variance in chunk length.
- Fixed token windows produce uniform chunk sizes (predictable prompt budgets), but can slice through the middle of code blocks or sentences unless paired with overlap.
Sizing your vector index next
Once you know your estimated corpus vector count, use the Size in pgvector Calculator button above to carry that exact row count and embedding model straight into the pgvector Index Size Calculator to check RAM fit and HNSW vs. Binary Quantization trade-offs.
Frequently asked questions
What chunk size and overlap should I start with for RAG?
Most technical documentation and knowledge-base RAG pipelines start around 300–512 tokens per chunk with 10–15% overlap (roughly 40–64 tokens). Smaller chunks improve retrieval precision for specific facts; larger chunks preserve narrative context at the cost of higher input token spend.
How are tokens estimated in this visualizer?
English prose averages roughly 4 characters (or ~0.75 words) per token across modern BPE tokenizers (tiktoken, SentencePiece). This tool uses a fast word-and-punctuation heuristic that stays within ~5–10% of exact tokenizer counts so chunk boundaries update instantaneously as you type.
Why does overlap inflate my vector database size?
With chunk size C and overlap O, each step advances by C - O tokens. A 25% overlap creates 33% more chunks — which increases both embedding spend and your HNSW index RAM footprint by a third.
How do I keep monthly RAG token costs predictable?
Retrieve 20–40 candidates cheaply, rerank down to the top 4–6 passages before calling the generator model, cache repeated system prompts, and measure recall before bumping top_k.
Built and maintained by Pradeep Bhandari, Senior Engineering Manager & Full-Stack Architect. Last reviewed .