Your local model forgets what you said five messages ago. A long chat suddenly fails with “the prompt is too long”. A model with tools returns a blank reply. All three are context length problems, and in Open WebUI they have a few very specific causes.
The biggest one surprises almost everyone: switching on the num_ctx control in Open WebUI pre-fills 2048 tokens, and that value quietly overrides whatever you set on the Ollama server.
This guide explains how context works in Open WebUI, how to set the right length for Ollama, llama.cpp and cloud models, how to fix “prompt too long” errors, and how to use the built-in Context Compaction feature so long chats keep going. It follows the Open WebUI and Ollama documentation as of December 2026.
- Ollama default: 4K context under 24 GiB VRAM, 32K at 24-48 GiB, 256K at 48 GiB+.
- Global fix: set
OLLAMA_CONTEXT_LENGTH=32768on the Ollama server and leavenum_ctxunset in Open WebUI. - Per model: set
num_ctxin Workspace > Models, never the 2048 pre-fill. - Check it:
ollama psshows the real CONTEXT and GPU/CPU split. - “Prompt too long”: start a new chat, or turn on Context Compaction in Admin Settings > Interface.
- Blank replies with tools: the context is too small for tool schemas. Raise it.
What Context Length Means in Open WebUI
A model’s context window is how many tokens it can see at once. In a chat, that is not just your newest message. On every turn Open WebUI sends:
- The system prompt (model, workspace and folder prompts)
- The full chat history so far
- Attached files that are inlined rather than retrieved
- Tool definitions and earlier tool results
- Context injected by RAG, web search and memories
- Your new message
So the prompt grows with every turn. Open WebUI deliberately does not trim your chat silently, because every model has a different tokenizer and window, and every team wants a different trimming policy. Its only built-in option, Context Compaction, is off by default.
Symptoms and Their Causes
| Symptom | Likely cause | Fix |
|---|---|---|
| Local model forgets earlier messages | Small Ollama context (4K default, or a 2048 num_ctx) |
Raise context |
| Blank reply or raw tool JSON with tools on | Tool schemas fill a tiny context | Raise context |
| “The prompt is too long” / “context length exceeded” | Chat exceeds the model’s real window | New chat, compaction or filter |
| Long pause before each reply | Chat and background tasks request different num_ctx, so Ollama reloads |
Set num_ctx on the model |
| Model gets much slower after raising context | Context no longer fits VRAM, model spills to CPU | Lower context or use a smaller quant |
The error messages come from the model provider (Ollama, OpenAI, Anthropic and so on), not from Open WebUI itself.
Fix It for Ollama: num_ctx vs OLLAMA_CONTEXT_LENGTH
For Ollama, the context length can come from two places, and one silently overrides the other:
| Setting | Where it lives | Default |
|---|---|---|
OLLAMA_CONTEXT_LENGTH |
Ollama server environment | Picked from VRAM: 4K under 24 GiB, 32K at 24-48 GiB, 256K at 48 GiB+ |
num_ctx |
Open WebUI advanced parameter | Unset, so Ollama’s value applies |
The trap: if num_ctx is set anywhere in Open WebUI, it is sent with every request and overrides OLLAMA_CONTEXT_LENGTH. Toggling the num_ctx control on pre-fills 2048, so it is easy to cap a model at 2048 tokens even after raising the server value.
Option A: one default for every model (recommended)
- Set the server value. Linux:
sudo systemctl edit ollama, addEnvironment="OLLAMA_CONTEXT_LENGTH=32768"under[Service], thensudo systemctl restart ollama. Windows: add it as a user environment variable and restart Ollama. Docker: pass-e OLLAMA_CONTEXT_LENGTH=32768. The Ollama desktop app also has a context slider in its settings. - Clear num_ctx in Open WebUI everywhere: the model editor, your account’s Settings > General > Advanced Parameters, and the chat’s Controls. Set each back to default.
- Verify: send a message, then run
ollama psand read the CONTEXT column.
ollama ps
NAME ID SIZE PROCESSOR CONTEXT UNTIL
gemma4:latest c6eb396dbd59 9.6 GB 100% GPU 131072 2 minutes from now
Ollama recommends at least 64,000 tokens for web search, agents and coding tools. Our Ollama environment variables guide shows how to set variables on each OS.
Option B: a value per model
Set num_ctx on the model in Open WebUI to a realistic value such as 8192, 16384 or the model’s maximum. Remember it overrides the server setting. Our Ollama context length guide covers the Ollama side in depth, including Modelfiles.
Where to Set num_ctx in Open WebUI
| Level | Where | Who | Wins over |
|---|---|---|---|
| Per chat | Chat Controls > Advanced Params | Anyone allowed | Account and model values |
| Per account | Settings > General > Advanced Parameters | Each user | Model value |
| Per model | Workspace > Models, edit, Advanced Params | Admins | Global defaults |
| Global | Global Model Defaults (admin) | Admins | Nothing set elsewhere |
A parameter nobody sets falls through to the next level. If a model has Model controls defined, the option picked there sits above all of these. For a team, set num_ctx once per model rather than asking users to change it. Our custom models guide shows the model editor.
Stop Background Tasks Reloading the Model
Open WebUI also sends background requests for chat titles, tags and search queries. A num_ctx set in a chat’s Controls or your account settings only goes out with the chat request; the background request uses the model editor’s value, or none.
Ollama then sees two different context lengths and reloads the model, so the next reply starts after a long pause.
- Set
num_ctxin the model editor instead of per chat, so both requests match. - Or set the same
num_ctxin Task Model Parameters under Admin Settings > Interface, when every task model is on Ollama. - Or pick a small task model that stays loaded beside the chat model, and check with
ollama psthat both are listed.
llama.cpp and Cloud Models
llama.cpp
num_ctx is an Ollama parameter. For llama-server the window is fixed when you start the server with -c (default 0 loads it from the model), and parallel slots share it. Restart with a larger -c to fix truncation. See our Open WebUI llama.cpp guide.
Cloud models
Claude, GPT and Gemini models have large windows (Claude 5 models have 1M tokens) and you cannot change them. Errors there mean the chat, files or tool results genuinely exceeded the window, or you are paying for a huge prompt on every turn. Use compaction or new chats.
Keep Long Chats Going With Context Compaction
Context Compaction summarizes older messages when a chat passes a token threshold, then continues from that summary plus the most recent messages. It is off by default. Turn it on in Admin Settings > Interface:
| Setting | Default | What it does |
|---|---|---|
| Context Compaction | Off | On/off (ENABLE_CONTEXT_COMPACTION) |
| Context Compaction Model | Current Model | Model that writes the summaries |
| Token Threshold | 80000 | Estimated size that triggers compaction; set it below the model’s real window |
| Retained Messages | 40% | Recent messages kept word for word (clamped to 10-50%) |
| Context Compaction Prompt | Built-in | Optional custom summary prompt |
- Your full chat is still stored and shown. A Context compacted line marks where the summary starts; click it to read the summary.
- System prompts, tools, skills, RAG and memory context are rebuilt fresh every turn, so they are never summarized away.
- Each model can set its own Context Compaction Threshold in its advanced params, which is useful for small local models. For a 32K Ollama model, try about 24000.
- If the summarizer fails, Open WebUI falls back to a short mechanical summary, or sends the full history.
For other policies, such as keeping only the newest N turns, Open WebUI recommends a filter function. Our Open WebUI functions guide shows how filters work.
How Much Context Can Your GPU Hold?
More context needs more VRAM for the KV cache. When it no longer fits, Ollama spills part of the model to the CPU and speed collapses. Check the PROCESSOR column in ollama ps: you want 100% GPU.
- Raise context in steps (8K, 16K, 32K) and check
ollama psafter each. - If it shows a CPU share, drop back one step or use a smaller quant.
- Ollama’s VRAM-based defaults are a good starting point for your card.
If the model became slow, our Ollama slow fix guide and Open WebUI slow fix guide cover the rest.
Troubleshooting
I raised OLLAMA_CONTEXT_LENGTH but nothing changed
A num_ctx is set somewhere in Open WebUI and overrides it, or Ollama was not restarted. Clear num_ctx at every level and restart Ollama.
ollama ps shows 2048
The num_ctx control was switched on with its pre-filled value. Change it to a real value or switch it off.
Blank responses with tools enabled
Native function calling injects tool schemas into the prompt. At 2048 tokens there is no room left. Raise context to at least 8K, ideally much more.
“The prompt is too long” on a cloud model
Start a new chat, remove large attached files, or enable Context Compaction with a threshold below the window.
Compaction never runs
Check it is enabled and the threshold is below the chat size. It also skips a turn when no user message sits far enough back to split at.
Uploaded document is ignored
Full-text mode can overflow a small context. Use RAG retrieval instead; see our Open WebUI RAG guide.
FAQ
What is the default context length in Open WebUI?
Open WebUI sets none by default. For Ollama, the server’s default applies, which depends on your VRAM.
How do I increase context length in Open WebUI?
Set OLLAMA_CONTEXT_LENGTH on Ollama and leave num_ctx unset, or set num_ctx per model in Workspace > Models.
Does num_ctx work for OpenAI or Claude models?
No. It is an Ollama option. Cloud models have fixed windows.
Does Open WebUI truncate long chats automatically?
No, unless you turn on Context Compaction or install a filter.
Why is the model slow after raising context?
The KV cache no longer fits in VRAM, so part of the model runs on the CPU. Lower context or use a smaller model.
What context should I use for agents and web search?
Ollama recommends at least 64,000 tokens for those tasks, if your hardware can hold it.



