Ollama’s default context length for Gemma 4 is 32,768

Ollama chose 32,768 tokens on its own and listed 19 GB. The process itself grew from 22.0 GB to 33.2 GB over 15 runs at 65,536.

0:00

Ollama picks a context window for you, and on a Mac with 48 GB of memory it picked 32,768 tokens for Gemma 4 31B. We then raised it to 65,536 and watched the memory. Ollama listed 19 GB both times, but the process measured by the operating system grew from 22.0 GB after one run to 33.2 GB after fifteen.

What is Ollama’s default context length for Gemma 4?

On our machine, 32,768 tokens. Ollama’s startup log said it chose a vram based default, and recorded 37.4 GiB of graphics memory available on this 48 GB Mac. The model itself supports 262,144 tokens, but Ollama did not use anywhere near that. The log also lists a setting called OLLAMA_CONTEXT_LENGTH, which was 0, meaning no override.

How much memory does Ollama use with Gemma 4 31B?

It depends on which number you read. ollama ps showed 19 GB and 100% GPU at both context sizes. The operating system’s measure of the Ollama process was larger and rose as we ran more prompts.

When we measured Context Ollama process size
After one run 32,768 22.0 GB
After the first run 65,536 24.9 GB
After 15 runs 65,536 33.2 GB
After 15 runs, thinking off 65,536 31.4 GB

We cannot say from this test why the process grew. Process size on a Mac can include memory the system could reclaim, so treat 33.2 GB as an upper reading and not as a requirement. What it does show is that the 19 GB on the listing is not the whole story, and that a 48 GB Mac had room for it.

Does a bigger context window slow Gemma 4 down?

We cannot tell. One run at the default context wrote at 11.92 tokens a second, and the middle of 15 runs at 65,536 was 11.50. One run against fifteen is not a comparison, and the gap is small. In LM Studio at 65,536 the same file wrote at 11.74, so the context size is not the main thing deciding speed here.

How do I change the context length in Ollama?

We set it per request. In the options of a call to /api/chat we passed "num_ctx": 65536, and ollama ps then showed a context of 65536. The server also has the OLLAMA_CONTEXT_LENGTH setting for a default that applies to everything. We did not test that one.

What did we not test?

The default context was measured with one run, not fifteen. We did not try other context sizes, other models or a Mac with less memory, where Ollama may choose differently. The same model in LM Studio is covered in Ollama against LM Studio, and the steps to load the file are in our import guide.

How many tokens did our own prompts need?

Very few, which is why the default did us no harm. The five short tasks ran from 73 to 117 tokens of prompt each. The long document we use to test reading came to 3,809 tokens. All of it fits many times over in 32,768. If your use is questions and answers, or one document at a time, Ollama’s default on a machine like this one is enough, and raising it buys you nothing but a larger memory footprint.

When is Ollama’s default context length too small?

When a program sends far more than you typed. Coding agents do. We ran three of them against this model through LM Studio and read from the server log how much each sent.

Agent Calls to the model First large request Largest request
Pi 10 1,663 tokens 10,243 tokens
OpenCode 8 31,034 tokens 34,666 tokens
Hermes 8 24,388 tokens 30,030 tokens

Pi stayed small. Hermes came close to the default with a largest request of 30,030 tokens. OpenCode went past it at 34,666. We did not run these agents through Ollama, so we have not watched what Ollama does when a request is larger than its window. The arithmetic is enough to act on: before pointing a heavy agent at Ollama, raise the context to at least 65,536. Other programs share that server on our Mac, so read the counts as close, not exact.

How long does Ollama take to reload when the context changes?

Changing the context window makes Ollama load the model again. The first request after our import waited 8.2 seconds to load at the default size. The first request at 65,536 waited 2.6 seconds. After that, with the model in memory, the load step took about 0.24 seconds a request. So set the size once and keep to it. A program that asks for a different size on every call would pay the reload each time.

Does Ollama reuse a prompt it has already read at 65,536 tokens?

Yes. At the larger window, Ollama took 45.3 seconds to read our 3,809 token document the first time. Sent again unchanged, it took 0.11 seconds, and 0.12 the third time. When we changed the first line, it read the whole document again. The saved prompt worked the same way as in LM Studio, and the bigger window did not get in its way.

How long does Ollama keep the model and its context in memory?

Four minutes after the last request, going by its own listing, which showed the model due to unload “4 minutes from now” straight after a run. When it unloads, the memory comes back and the next request loads the model afresh. That matters for the memory figures above: the growth we saw was within one loaded session, and it ends when the model unloads.

How does this memory compare with other models at the same context?

For scale, these are the five models we have measured in LM Studio on this Mac, all loaded at 65,536 tokens. The figure is the largest size the model process reached during 15 runs.

Model File on disk Process size at 65,536
Gemma 4 31B 17.65 GB 22.6 GB
Qwen 3.8 27B 17.74 GB 23.3 GB
Bonsai 27B 4.73 GB 14.1 GB
Qwen 3.6 35B-A3B 22.07 GB 24.3 GB
GLM 4.7 Flash 18.13 GB 20.8 GB

Gemma’s figure was read during a run and the others before and after, so the column is a guide and not a ranking. Each sat a few gigabytes above its file size. Ollama’s process with the same Gemma file read higher than LM Studio’s, and it kept growing as we ran more prompts. We have not found out why.

What context length should I set in Ollama?

Match it to the largest thing you will send, not to the most the model supports. For questions and single documents, the 32,768 that Ollama chose here is plenty. For a coding agent, set 65,536, which is what we ran and what one of the three agents we tested requires before it will start. Going higher costs memory for room you may never fill.

Whatever you choose, confirm it took effect. After a request, the context column of ollama ps shows the window the loaded model is really using, and that is the figure to quote beside any result.

Ollama now also serves a second kind of model that answers a question with a choice or a score instead of free text: see Ollama decision models reach the command line.

How we tested

Ollama 0.32.6 on a Mac with an M4 Pro chip and 48 GB of memory, macOS 27.0.1, the 17.65 GB Gemma 4 31B QAT Q4_0 file. Process size is the largest Ollama process as reported by the operating system, converted to decimal gigabytes. The method is on how we test.

Sources

  1. Google's Gemma 4 31B QAT model card
Cite this page

Hill. "Ollama’s default context length for Gemma 4 is 32,768". Onticpost, published 4 October 2026, updated 24 October 2026. https://onticpost.com/ollama-default-context-length-gemma-4-31b/

Updated 24 October 2026. This address stays the same when the piece is updated.

Share this

Subscribe to our newsletter

Checked: what AI can do for your business, checked by humans. Free, every Friday. One email a week, leave any time.

Free, every Friday. We send a link to confirm first. Our privacy policy says what we keep.