Free | No tracking | Every fact with a source|German and English

Glossary / Text and chat

Context Length – explained simply

The context length determines how many tokens a language model can consider at once, meaning how much of the conversation it keeps in view.

Also: Context Window, Context Length, Context Window, num_ctx

Everything the model should consider right now has to fit in the context: the system prompt, the prior chat history, inserted documents, and the response. Think of the context as a desk that can only hold a certain amount of paper. Whatever falls off, the model forgets.

More context needs more memory. That’s why Ollama adjusts the default value to your VRAM: below 24 GB it is 4,096 tokens, above that it is more. You can change it in the app settings, via the OLLAMA_CONTEXT_LENGTH environment variable, or in the Modelfile with PARAMETER num_ctx. For agents, web search, and programming tools, Ollama recommends at least 64,000 tokens.

A large context can cause parts of the model to be swapped out to RAM and make everything slower.

What does that mean for you? If your model forgets long texts or earlier parts of the conversation, increase the context length and then check with ollama ps whether everything is still running on the GPU.

Related terms

Errors where that matters

Sources