mrsn0.3.0
auth
live

Ollama's context window — the silent 4096 wall

Ollama's default context window is 4096 tokens. A 15,437-token paste came back 200 with a fluent answer built from 2,050 read tokens — the head died, and only prompt_eval_count tells you.

2026-11-233 min read

Ollama's default context window is 4096 tokens, and it never announces itself. Paste longer: the server trims input, journals one WARN, and answers anyway. A 15,437-token paste came back 200, built from the last ~2,000 tokens — the input cap was 2,050. Only prompt_eval_count tells you.

default window
4096
ollama 0.40.15, no VRAM
paste sent
15,437
tokens, one 800-line doc
tokens read
2,050
clamped — the rest never evaluated
RAM cost
144 KiB
per token of window, linear
The API returns 200. The CLI answers. prompt_eval_count is the only witness you can read.

What is ollama's default context window?

$ curl -s localhost:11434/api/ps | jq '.models[0] | {name, context_length}'
{
  "name": "qwen3:4b",
  "context_length": 4096
}
msg="vram-based default context" total_vram="0 B" default_num_ctx=4096

4096 is printed in the wrong places — not at load, not in the CLI banner, not in an error. ollama ps has a CONTEXT column; /api/ps calls it context_length, readable only after load. Fresh serve, zero options; the GPU-less box logs "no VRAM found, so 4096".

Why does ollama forget the middle of my document?

The trim precedes evaluation — server journal, not client:

Nov 07 ollama[638]: level=WARN source=llama_server.go:344
  msg="truncating input prompt" limit=2,050 prompt=15437 keep=4 new=2,050
POST /api/generate → 200 … a fluent answer built from the kept tail

An 800-line doc, a unique safe word per line. Asked about line 0080, the model named its surviving strip: KILO-0696 to KILO-0800 — line 0080 was never read. At num_ctx 16384 the whole paste evaluated: 25 minutes on 4 threads.

asktruth (the doc)windowprompt_eval_countwhat came back
line 0080KILO-0080default 40962,050 — clampedanswered from the surviving strip, naming its own edges
line 0750PAPA-0750default 40962,050 — clampedquoted kept line 0696 verbatim, walked toward 0750 until the 256-token answer bound cut it
line 0750PAPA-0750num_ctx 16384no clamp — whole paste evaluatedno answer printed: 25 minutes of prompt evaluation before the client was cut loose

Witness rule: if the paste matters, read prompt_eval_count in every /api/generate and /api/chat response. Send 15,437 tokens, see 2,050 evaluated — that gap is the truncation.

How do I set the context window in ollama?

Three doors, all executed. Precedence: request option beats environment beats Modelfile beats 4096. The CLI has no context flag at ask time — terminal users get the env var or nothing.

doorscopewhere it livesmeasured
"options": {"num_ctx": N}this requestrequest bodyyes — ps flip + ask verified
OLLAMA_CONTEXT_LENGTHwhole serverservice environmentyes — ps flip after restart
PARAMETER num_ctx None model, bakedModelfile → ollama createyes — ps flip on load
(nothing set)everything—yes — 4096 observed

Does a bigger context window cost memory?

Linearly — the KV cache reserves RAM per token of window whether you paste or not.

windowresultRAM usedper-token arithmetic
4096loaded3,599 MiBbaseline (weights 3.1 GiB every row)
16384loaded5,397 MiB+1,798 MiB ≈ 144 KiB/token
32768loaded (24.6 s)7,531 MiB+3,932 MiB ÷ 28,672 tokens ≈ 140 KiB/tok
65536refused — HTTP 500—attempted 9,663,672,576 B of cache; box said no
2,050

of 15,437 pasted tokens were actually read — the window said 4096; the reserve ate half.

  1. read the window you got: ollama ps → CONTEXT column
  2. halve it in your head: the input cap is ~half, the rest is saved for the reply
  3. pasting a document? one ask: "options": {"num_ctx": …}
  4. terminal-only workflow? OLLAMA_CONTEXT_LENGTH on the service
  5. after the ask, compare prompt_eval_count to your paste size — a clamp means part of the doc was never read
  6. before raising it far, price the RAM: ~144 KiB of cache per token, linear
The wall: fluent is not the same as informed. A 200 with a clamped prompt_eval_count is a citation waiting to become an invention.
  • last tested 2026-11-07 · ollama 0.40.15 (Arch package) · 4 threads · 8 GiB VM · CPU-only bench — RAM numbers, not VRAM claims
  • 800-line doc, unique safe word per line · 15,437-token paste · default window 4096, input cap 2,050
  • all four window doors and all four RAM rungs executed on the bench; 65536 refused with HTTP 500
0appreciations — anonymous, one per reader
your message opens the chat panel on the right — the thread remembers, sources ride inline
the feedanswersthe agentsdocsaboutauthschema.jsonopenapi.jsonllms.txt