By Annie Vane · Fixes · Docs-only · Checked November 30, 2026
Short answer: Ollama only reads as much of your prompt as its context length allows, and the default can be as small as 4096 tokens. Load your model, run ollama ps and read the CONTEXT column. If it is too small, raise it with the app slider, OLLAMA_CONTEXT_LENGTH or num_ctx. Bigger context needs more memory.
Why Ollama cuts off long prompts
The context window is the number of tokens the model can hold in memory at once: your instructions, the document you pasted, the chat so far and the reply. When a prompt is longer than the context length, the model never sees part of it. Open WebUI's Ollama guide puts it plainly: a context that is too small silently truncates the prompt. You get no error, just an answer that ignores the start of your document. For the theory, see context length explained.

What is the default context length in Ollama?
Ollama's own documentation gives two answers. The context-length page says the default depends on graphics memory (VRAM):
| Graphics memory (VRAM) | Default context |
|---|---|
| Under 24 GiB | 4k tokens (4096) |
| 24 to 48 GiB | 32k tokens (32768) |
| 48 GiB or more | 256k tokens (262144) |
Open WebUI's guide adds that Ollama has chosen this default from available VRAM since v0.15.5. The Ollama FAQ still says the default is 4096 tokens. Neither page says how a Mac's unified memory is counted, and cloud models are set to their maximum by default. So do not guess: check your own machine.
What should I set my Ollama context length to?
- Web search, agents and coding tools: at least 64000 tokens, per the context-length page. This matters for tools such as Claude Code with Ollama.
- Long documents: enough to hold the document plus your question and the reply. If you are unsure, step up (8192, 16384, 32768) and check
ollama pseach time. - Upper limit: no higher than the model's own maximum (see below) and no higher than your memory allows.
Ollama's docs say that for best performance you should use the maximum context length for a model and avoid offloading the model to the CPU. On most home machines you cannot have both, so pick the largest context that still shows 100% GPU.
How to check your context length
ollama ps
With a model loaded, the output looks like the example in Ollama's docs:
NAME ID SIZE PROCESSOR CONTEXT UNTIL
gemma4:latest c6eb396dbd59 9.6 GB 100% GPU 131072 2 minutes from now
CONTEXT is the window actually in use. PROCESSOR shows whether the model fits on the GPU. The /api/ps endpoint returns the same figure as context_length if you want to script the check. A long document plus a short window is the usual reason a model "forgets" the start of what you pasted.
How can I check a model's maximum context length?
The model's own limit is in its metadata. Ask the show model details API:
curl http://localhost:11434/api/show -d '{"model": "gemma4"}'
Look in model_info for the key ending in .context_length; the docs' example shows gemma4.context_length: 131072. That is the ceiling for that model. To see whether a model already has a num_ctx baked in, run ollama show --modelfile gemma4 (from the Modelfile reference) and look for a PARAMETER num_ctx line.
How to increase the context length in Ollama
There are five ways to set the context, from quickest to most permanent.
1. The slider in the Ollama app
Open the Ollama app's settings and move the context-length slider. This is the route the context-length page lists first.
2. The OLLAMA_CONTEXT_LENGTH environment variable
This sets the default context for every model the server loads:
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
That only works when you start the server yourself. If Ollama runs as a background service, set the variable where the service reads it, using the FAQ's method for environment variables:
- Linux (systemd): run
systemctl edit ollama.service, add the lines below, save, then runsystemctl daemon-reloadandsystemctl restart ollama. - Mac app: run
launchctl setenv OLLAMA_CONTEXT_LENGTH 64000, then restart the Ollama app. - Windows: quit Ollama from the taskbar, add
OLLAMA_CONTEXT_LENGTHunder "Edit environment variables for your account", then start Ollama again.
[Service]
Environment="OLLAMA_CONTEXT_LENGTH=64000"
3. /set parameter num_ctx inside a chat
Inside ollama run, type:
/set parameter num_ctx 16384
This changes the current session only. See our Ollama commands list for the other chat commands.
4. num_ctx in an API request
curl http://localhost:11434/api/generate -d '{
"model": "llama3.2",
"prompt": "Summarize this report...",
"options": {
"num_ctx": 16384
}
}'
The same options block works on /api/chat. A per-request num_ctx overrides the server's OLLAMA_CONTEXT_LENGTH.
5. A Modelfile (a new model with the setting saved)
FROM gemma4
PARAMETER num_ctx 16384
Save that as Modelfile, run ollama create gemma4-16k -f Modelfile, then use gemma4-16k in place of the original. The OpenAI compatibility page says the OpenAI API has no way to set context size, so this is the route for apps that talk to Ollama through /v1.
How to set context length in Open WebUI
In Open WebUI, num_ctx lives under Model controls > Controls > Advanced Params in a chat, or per model in the model editor. It is unset by default, so Ollama's own default applies. The catch, per Open WebUI's docs: switching the control on pre-fills it with 2048, and that value is sent on every request, overriding OLLAMA_CONTEXT_LENGTH. Either leave it unset and set the server default, or type a real value such as 8192 or 16384.
Why is my context length setting not taking effect?
- The variable is in the wrong place. Exporting
OLLAMA_CONTEXT_LENGTHin a terminal does not reach the Mac app or a systemd service. Uselaunchctlorsystemctl edit, then restart Ollama (see how to stop and restart Ollama). - Something sends its own num_ctx. A per-request value, an Open WebUI Advanced Param or a Modelfile
PARAMETER num_ctxbeats the server default. Check withollama show --modelfile. - The app uses the OpenAI-compatible endpoint. It cannot pass a context size; build a Modelfile model instead.
- You are reading the wrong number. Trust the CONTEXT column in
ollama ps, not the setting you typed.
How context length affects memory use and speed
The context-length page warns that a larger context increases the memory needed to run a model. If ollama ps stops showing 100% GPU after you raise it, part of the model has moved to the CPU and responses slow down. Step back down, or shrink the cache. Our guide to how much memory a model needs covers the sums.
- Quantize the K/V cache: per the FAQ,
OLLAMA_KV_CACHE_TYPE=q8_0uses about half the memory of the defaultf16, andq4_0about a quarter, with more precision loss. It needs flash attention and applies to all models. - Flash attention: Ollama turns it on automatically where supported;
OLLAMA_FLASH_ATTENTION=1forces it. - Parallel requests: these multiply the context. A 2K context with 4 parallel requests becomes an 8K context.
OLLAMA_NUM_PARALLELcontrols this.
If you installed Ollama with Homebrew on a Mac, its service already sets flash attention on and the cache to q8_0.
Frequently asked questions
What should I set my Ollama context length to?
At least 64000 tokens for agents, web search and coding tools, per Ollama's docs. For documents, enough to fit the text plus the reply, up to the model's maximum and what your memory allows.
Why does Ollama take so long?
Often because the model or its context cache no longer fits in GPU memory. Check PROCESSOR in ollama ps; anything below 100% GPU means CPU offloading. Lower the context, or see Ollama not using the GPU.
Is there a limit to Ollama's context length?
Yes, two: the model's own maximum (the context_length in /api/show) and your memory. Ollama itself only sets the default.
Why does Ollama ignore the start of my long prompt?
The prompt is longer than the context length, so part of it is cut without warning. Check CONTEXT in ollama ps and raise it.
Does a larger context window make a model smarter?
No. It lets the model see more of your input at once; the model itself is unchanged. It also costs memory and, if it pushes work to the CPU, speed.
Does OLLAMA_CONTEXT_LENGTH or num_ctx win?
num_ctx. A value sent with a request, or set in Open WebUI, overrides the server default.
Still stuck? Work through our Ollama troubleshooting guide.
How we researched this
This is a Docs-only guide: it is built from the official documentation linked below, opened on November 30, 2026. We have not run these steps on our own test machine yet. If something here no longer matches what you see, tell us and we will log the correction.
