Reserve context for the entire request: instructions, conversation history, source text, formatting and the answer. In a 16,384-token window, an 11,000-token document plus 2,000 tokens of instructions and history leaves 16,384 − 11,000 − 2,000 = 3,384 tokens for the answer and remaining overhead.
Reserve the answer before adding source text
A practical context budget starts with the output your task needs. If the answer requires up to 2,048 tokens, reserve them before inserting documents. Then leave an explicit allowance for template formatting and any tool descriptions your application sends.
| Budget item | Illustrative token allocation | Running total |
|---|---|---|
| Source document | 11,000 | 11,000 |
| Instructions and history | 2,000 | 13,000 |
| Answer reserve | 2,048 | 15,048 |
| Template and other overhead allowance | 512 | 15,560 |
| Unused margin | 824 | 16,384 |
Replace the 512-token allowance with the tokens your application actually adds. Count the fully assembled request with the selected model's tokenizer, including the template and instructions.
If the source does not fit, decide what information the answer actually requires. Retrieve relevant sections, remove repeated history or summarize completed work while preserving critical facts. Expanding the window is appropriate when the task genuinely needs the additional material and the memory budget supports it.
Set Ollama's context explicitly
Set num_ctx explicitly and confirm the loaded context with ollama ps. As of 2026-11-22, Ollama's dedicated context documentation describes hardware-dependent defaults: 4K below the 24 GiB VRAM tier, 32K for the 24 to below 48 GiB tier, and 256K for the 48 GiB tier and above. The current server implementation selects 4,096, 32,768 or 262,144 tokens, using 23 GiB and 47 GiB thresholds to accommodate reported hardware sizes. The FAQ also lists a blanket 4,096-token default; use the dedicated context documentation and loaded value when configuring your runner.
Inspect the CONTEXT column to confirm the actual allocation for your loaded model.
Inside an ollama run conversation, set:
/set parameter num_ctx 16384
For an API request, put the setting in options. Here the context budget is 16,384 and the answer ceiling is 2,048:
curl http://localhost:11434/api/generate -d '{
"model": "YOUR_LOCAL_MODEL",
"prompt": "Summarize the decisions in the supplied document.",
"stream": false,
"options": {"num_ctx": 16384, "num_predict": 2048}
}'
ollama ps
Replace the model name and prompt with your local model and complete test input. To set a server default from a macOS or Linux terminal, after stopping any existing server that owns the port, use OLLAMA_CONTEXT_LENGTH=16384 ollama serve. For the macOS application, use launchctl setenv OLLAMA_CONTEXT_LENGTH 16384 and restart the app. A Linux systemd service needs the variable in its service environment and a restart; setting it only in a client shell does not reconfigure that running service.
Translate the window into cache memory
For a conventional full-attention transformer with equal key and value widths, the unquantized KV payload is:
cache bytes = 2 × layers × KV heads × head dimension
× bytes per element × tokens × concurrent sequences
The first factor of two accounts for keys and values. Use the KV head count when the architecture shares keys and values across query heads. The formula counts the attention payload; runtime buffers and allocation overhead require additional memory.
Consider an illustrative architecture with 32 layers, eight KV heads, a head dimension of 128 and a two-byte cache element. Each token costs 2 × 32 × 8 × 128 × 2 = 131,072 bytes. A 16,384-token sequence therefore costs 131,072 × 16,384 = 2,147,483,648 bytes, or 2 GiB. Four independent sequences at that capacity require 4 × 2 = 8 GiB before weights and buffers.
This example assumes full attention across the stored sequence and no cache sharing. Sliding-window or other cache architectures need their own calculation. The key budgeting lesson remains useful: choosing a larger window can consume memory that you otherwise wanted for parallel agents.
Choose useful context, then concurrency
Ollama documents that parallel requests increase context allocation. Set the smallest window that reliably contains the task, then test the number of workers you need. Four independent 16K tasks and one 16K task are different capacity plans even though they use the same weights. Agents on one local GPU share its throughput, and requests beyond its serving capacity wait in line.
Give each agent a scoped job. A worker checking one function may need a small set of source files; a worker reviewing a broad design may need a different selection. Sending every worker the full repository spends context on material you have not established it needs.
Keep enough evidence in each request to verify the answer. If narrowing the input removes a necessary exception, restore that section before interpreting the failure as a model weakness.
Try it on your workload
Use the opening 16,384-token budget with a document counted by your chosen tokenizer. Place an explicit fictional fact near the end, such as “The renewal deadline is June 17,” and ask for that fact plus an exception stated earlier. Reserve the answer and template allowance before assembling the final prompt.
Run the request, record the loaded context, memory, prompt-processing time and answer. Repeat with the fact near the beginning and middle. If a fact disappears, inspect the actual text submitted, truncation and retrieval before enlarging the window.
Then repeat with four independent requests if that is your expected workload. Keep the model and window fixed. Record whether all four run together, their finish times and whether the longest request still fits.
How to decide
- Use the smallest window that contains the required evidence and answer reserve.
- Fix missing input or poor retrieval before paying the memory cost of a larger window.
- Increase context only when a repeatable task requires it and the concurrent workload still fits.
Give ten document agents their own context for about 16 cents
Ten document agents working at once on deepseek/deepseek-v3.2 cost about 16 cents in tokens on TrustedRouter for this workload. Assign each worker the evidence its task needs, preserving your answer reserve and checking the accepted result against the source.
On 2026-11-22, the live catalog listed approximately $0.274 per million input tokens and $0.401 per million output tokens. Suppose each agent uses 50,000 input and 5,000 output tokens. Input = 10 × 50,000 = 500,000; output = 10 × 5,000 = 50,000. Cost = 0.5 × $0.274 + 0.05 × $0.401 = $0.15705, about 16 cents.
On one local GPU, those agents share throughput, and requests beyond its parallel capacity wait in line; through a per-token API, they can run together for the same token bill as sequential requests. Count duplicated document text in each worker's input budget. Prices change; check model details and prices and agent setup. For approved off-device documents, encrypted inference and zero data retention depend on model and provider. Local remains better for offline documents or when a focused window already fits the workload comfortably.
Sources
- Ollama: hardware-based context tiers and allocation display
- Ollama: exact default-context thresholds
- Ollama: context overrides, platform environment settings and parallel requests
- Ollama: context and generation-limit request options
- Hugging Face: KV payload arithmetic
- Hugging Face: cache strategies and sliding-window behavior