Sunday, 6 December 2026 | Updating Daily AI insight, written for builders

How to Check and Change Ollama Context Length

  • Ollama defaults to 4k tokens on GPUs with under 24 GB VRAM, 32k for 24–48 GB, and 256k for 48+ GB.
  • Change context via three routes: the app settings slider, the OLLAMA_CONTEXT_LENGTH environment variable, or the num_ctx parameter in API calls and Modelfiles.
  • Verify what context a loaded model is using with ollama ps — the CONTEXT column shows the allocated window, and the PROCESSOR column shows if the model is on GPU or spilled to CPU.
  • Increasing context uses more VRAM. If a model no longer fits, it will offload to system memory and slow down significantly.

Ollama’s context length is the maximum number of tokens a model can see at once when generating a response. By default, it depends on your GPU’s VRAM: under 24 GB gives 4,096 tokens; 24–48 GB gives 32,768; and 48+ GB gives 262,144. Cloud-hosted models in Ollama are set to their maximum context by default. For tasks like coding, web search, or agents, Ollama recommends at least 64,000 tokens. Larger context windows use more GPU memory, so raising them requires planning to avoid your model spilling to CPU.

Understanding context length and memory

Context length determines how much text history a model can reference when generating the next token. A 4k context window means the model can “see” up to 4,096 tokens of previous conversation or input; anything older is discarded. A 256k window lets the model work with much longer documents, conversations, or codebases in a single request.

Increasing the context is not free. A larger context length increases the memory required to run a model. This matters because if the model no longer fits entirely in VRAM, Ollama will split it between GPU and system RAM. The offloaded portion runs on CPU, which is much slower. You’ll see this split reported by ollama ps as a CPU/GPU percentage (e.g., 48%/52%).

Use the VRAM calculator to estimate how much memory a model needs at a given context length. For popular Ollama models:

  • Llama 3.1 8B needs ~5 GB at 4-bit quantization for a base run; raising the context window will increase this.
  • Mistral NeMo 12B requires ~7.5 GB at 4-bit; a larger context will add overhead.
  • Llama 3.3 70B needs ~40 GB at 4-bit, leaving less headroom for context expansion on most systems.

Default context by GPU memory

Ollama’s default context length is set automatically based on detected VRAM:

VRAM Available Default Context Use Case
< 24 GB 4,096 tokens (4k) Consumer and mid-range GPUs; most laptops
24–48 GB 32,768 tokens (32k) High-end consumer and workstation GPUs
≥ 48 GB 262,144 tokens (256k) Enterprise GPUs (A100, H100, RTX 6000)

These defaults ensure models fit in VRAM without offloading. If you’re running multiple models concurrently or have limited VRAM, the defaults may still trigger CPU spillover; check with ollama ps.

Three ways to change context length

1. Via the Ollama app (Windows, macOS, Linux desktop)

Open Ollama’s desktop application and navigate to Settings. Look for a context length slider and set it to your desired window. The app will apply this to all subsequently loaded models. This is the simplest route if you use the GUI.

2. Via OLLAMA_CONTEXT_LENGTH environment variable

Set the context before starting the Ollama server. This overrides the default for all models loaded in that session.

Linux (systemd service):

systemctl edit ollama.service

Add or edit the following line under [Service]:

[Service]
Environment="OLLAMA_CONTEXT_LENGTH=64000"

Then restart:

systemctl daemon-reload
systemctl restart ollama

macOS:

launchctl setenv OLLAMA_CONTEXT_LENGTH 64000

Restart the Ollama application.

Windows:

Open Settings (Windows 11) or Control Panel (Windows 10), search for “environment variables,” and click “Edit environment variables for your account.” Add a new variable OLLAMA_CONTEXT_LENGTH with the value (e.g., 64000

Ad-hoc (any platform):

OLLAMA_CONTEXT_LENGTH=64000 ollama serve

3. Via the num_ctx parameter

Set context per model, per request, or per Modelfile. This is useful when you want different models at different context sizes.

In a running session (ollama run):

ollama run llama3.2
/set parameter num_ctx 64000

This applies only to the current session.

In an API request:

curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2",
  "prompt": "Why is the sky blue?",
  "options": {
    "num_ctx": 64000
  }
}'

In a Modelfile:

FROM llama3.2
PARAMETER num_ctx 64000
SYSTEM "You are a helpful assistant."

Then create and run the model:

ollama create my-model -f ./Modelfile
ollama run my-model

This persists the context setting in the custom model.

Verify the allocated context

After loading a model, run ollama ps to see what context Ollama actually allocated and where the model is running:

ollama ps

NAME         ID                 SIZE      PROCESSOR      CONTEXT  UNTIL
gemma4:latest c6eb396dbd59    9.6 GB     100% GPU        131072   2 minutes from now

The CONTEXT column shows the token window size. The PROCESSOR column shows the split:

  • 100% GPU — model is entirely on the GPU, fastest.
  • 100% CPU — model is entirely in system RAM, slowest.
  • 48%/52% CPU/GPU — model is split across both; the GPU portion runs inference, but memory pressure is high and performance is degraded.

If you see a CPU/GPU split, your context (or model size) is too large for the available VRAM. Either reduce the context, switch to a smaller quantization, or add more GPU memory.

When to increase context

Tasks such as web search, agents, and coding tools should be set to at least 64,000 tokens. A larger window is valuable when:

  • You're passing long documents or code files in a single request.
  • You need the model to maintain coherence across a lengthy conversation.
  • You're running agentic tasks that require the model to reference past steps or search results.
  • You have spare VRAM and want to maximize the model's capability.

Start with the default for your GPU, monitor the PROCESSOR column, and increase context only if you have headroom. Use the self-hosting vs. API calculator to compare the cost of running a local model at a larger context versus calling a cloud API if you need very long contexts.

Troubleshooting context and memory

If you set a large context and the model stops responding or is very slow:

  1. Run ollama ps and check the PROCESSOR column.
  2. If you see a CPU/GPU split, the model no longer fits in VRAM. Reduce the context, unload other models, or switch to a smaller model.
  3. Check why Ollama might not be using your GPU and confirm the GPU is being detected.
  4. Use the GPU guide to verify your hardware is suitable for the model and context size you're trying to run.

Frequently asked questions

Can I set a context larger than my GPU's VRAM?

Yes, but it will offload to system RAM and be significantly slower. Ollama will keep the model loaded as long as there is any available memory, but performance will degrade if the entire context window and model weights do not fit in VRAM. Check ollama ps for the CPU/GPU split; if you see a mix, consider reducing context or upgrading your GPU.

Does context length affect response speed?

Yes. A larger context window means more tokens for the model to process at each step, which increases the memory footprint and can slow generation. If the model is on GPU, the slowdown is usually modest. If the model spills to CPU, the slowdown is severe.

Is 4096 tokens enough for most tasks?

For casual chat and shorter tasks, yes. For coding, long document summarization, or agentic workflows, you'll want at least 16k to 64k tokens. Check what your use case requires and whether your GPU can handle it.

How do I confirm Ollama is respecting my context setting?

Run ollama ps after loading a model. The CONTEXT column will show the allocated size. If it doesn't match what you set, the environment variable or Modelfile may not have been applied correctly. Restart the server and try again.

What happens if my prompt is longer than the context window?

See the official Ollama documentation for details on how the model handles inputs that exceed the context window.

Can I run different models with different context sizes at the same time?

Yes, but only if they both fit in VRAM. Set the context per model using a Modelfile or per-request via the API. Ollama will queue requests if both models cannot fit simultaneously.

See also

Primary source: Ollama Context Length and Ollama FAQ (official documentation).

Written by Mustafa Ihsan

Mustafa Ihsan is the founder and editor of Convly.ai. He built and maintains the site's live AI models database, its price-performance index, and its free calculators for VRAM requirements, API costs and self-hosting economics. He writes about model pricing, benchmark results and the hardware needed to run AI models locally, and consistently prefers measured numbers to vendor claims.

Scroll to Top