RAG Context Budget Planner
Reserve instructions, history, tools, output and safety margin before choosing how many retrieved chunks fit a model.
Ready. Reserve fixed overhead before adding retrieved chunks.
Model limits source · Reviewed 2026-10-08.
Enable JavaScript to plan locally.
Reserve first, retrieve second.
The planner subtracts fixed instructions, history, query, tool schemas and other overhead from the model context. It also reserves a token safety margin and, for combined input/output windows, the requested output. Maximum whole chunks is the remaining retrieval budget divided by average chunk size, rounded down.
Average chunks are an assumption.
For an 8,000-token retrieval budget and 1,500-token average chunks, at most five whole chunks fit. Real retrieved chunks vary: use conservative sizes and include citation wrappers, separators and message overhead. A 90% allocation warning is a local planning convention, not a provider guarantee.
Context is separate from billing.
Cached input still occupies logical context. Gemini input-only windows keep output separate, while combined windows reserve output within context. Output maxima are checked independently. The planner uses numeric counts, never actual prompt content, and performs no retrieval or inference.