Context length is how much text a model can use for a request, measured in tokens. Your instructions, earlier messages, supplied documents, retrieved passages, tool output, and the answer all need room. A model's published maximum and the context selected in your app are different numbers; available memory can constrain the usable setting further.
This guide is useful when a model forgets a detail, rejects a long prompt, slows down as a conversation grows, or fails after you increase context. If a short prompt is also wrong, begin with answer-quality troubleshooting rather than assuming context is the cause.
Keep three limits separate
| Limit | Where to look | What it establishes |
|---|---|---|
| Published model limit | The exact checkpoint's model card | The context configuration described by the publisher, sometimes with extra requirements |
| Selected model-runner context | App load settings or the running server | The allocation used by this setup |
| Practical memory capacity | A memory estimate and the actual running computer | Whether the selected workload leaves enough RAM or VRAM |
For example, the original Qwen3 4B card describes 32,768 native tokens and a larger limit with YaRN, a context-extension method. Setting an app to a larger number does not configure the extension or make your computer run it.
Estimate the text before raising the setting
Use the token counter with the material you intend to send. Its result is exact only for the tokenizer it uses; another model splits the same text differently. Page counts and word counts are weaker proxies, especially for code, tables, or languages other than English.
Work through a context budget
Everything in a request shares one budget: context = instructions + earlier messages + supplied text + room for the answer. The amounts below are examples for a 4,096-token context, not counts from a real app. Measure your own text with the token counter.
| Request | Instructions | Earlier messages | Supplied text | Answer room | Total | Result |
|---|---|---|---|---|---|---|
| Long chat with an attached report | 256 | 3,000 | 2,500 | 512 | 6,268 | 2,172 over. Depending on the app, it drops the oldest messages, cuts text from the middle, or stops with an error |
| Same thread, answer room cut to fit | 256 | 3,000 | 2,500 | 0 | 5,756 | Still over, and no room left for the answer |
| Fresh chat with only the relevant excerpt | 256 | 0 | 900 | 512 | 1,668 | 2,428 tokens spare |
The third row restores room without changing the model: start a new chat and supply only the passage the question needs. When the task really needs the whole report, raise the context instead, then check memory. For Qwen3 4B in Ollama on a 16 GB Windows PC without a graphics card, the calculator estimates 3.79 GiB at 4,096 tokens and 8.54 GiB at 32,768 tokens. Both fit, but the longer context leaves much less room for other apps.
Chat templates, tools and thinking models add tokens you may not see. A thinking model can spend thousands of tokens reasoning before it answers, so give it more answer room.
For document chat, find out whether the app supplies the whole file or selected passages. A 200-page PDF can produce a short prompt if search retrieves a few passages; the model does not see every page.
Start with a modest setting and inspect it
Check Ollama context length
In an Ollama conversation, an explicit starting setting is:
/set parameter num_ctx 4096
Send another short prompt, then inspect ollama ps in a second terminal. Its context and processor information helps distinguish the requested allocation and CPU/GPU placement. Ollama's context documentation describes hardware-dependent defaults. Ollama's context length page says the default context length depends on your VRAM: 4k tokens below 24 GiB, 32k from 24 to 48 GiB, and 256k at 48 GiB or more.
Check LM Studio context length
In LM Studio, choose the context in the model's load settings and reload it if the app requires that change. Its command-line load tool also supports --context-length. Check the displayed memory estimate before increasing the value. A model already loaded with one allocation may need a new load to use another.
Increase context only when the task needs it and the RAM and VRAM calculator leaves suitable space. Keep the exact model and quantization unchanged during that comparison so you can identify which setting caused the difference.
Changing context does not increase the maximum length of one answer. For responses that stop early, distinguish the context window from the output-token limit.
Why longer context uses more memory
Hybrid architectures may retain recurrent state as well as attention cache; cache growth can differ from full attention. Compare Qwen3.5 4B in the calculator at 4,096 tokens and change only context. A dense model's estimate does not apply, and not every runner supports every cache precision. Reasoning, images and tool output also consume context.
The model keeps conversation memory, often called the KV cache, while processing text. Its size depends on the model architecture, selected context, cache precision, and sometimes parallel requests. Model-weight compression and KV-cache compression are separate settings; a Q4 model does not have four-bit conversation memory.
Longer prompts also require more processing before an answer starts. If the model fits with a short chat but fails with a long one, reduce context or the material sent before changing drivers or redownloading weights.
Qwen3 8B; Q4; 4,096 context tokens; 1 concurrent user; LM Studio.
32 GiB system RAM / 8 GiB dedicated VRAM
- Model weights: 4.7 GiB
- Conversation memory (KV cache): 0.6 GiB
- Working memory: 0.3 GiB
- Media companion file: 0.0 GiB
- Safety allowance: 0.2 GiB
- App memory: 1.0 GiB
- Dedicated VRAM: 5.8 GiB needed; 7.5 GiB available
- System RAM: 1.0 GiB needed; 28.0 GiB available
From this site's RAM and VRAM calculator.
Check that the longer setting helps the task
Put "Intake code CEDAR-17" near the start and "Final room MAPLE-4" near the end of a representative document. In a fresh chat ask for both exact values and their locations. Run at each proposed setting, keeping the text unchanged, and inspect whether the client actually sent both passages. You want correct answers and acceptable memory use, not simply an app accepting the larger number.
Models overlook details inside an accepted context, search misses passages, and summaries drop qualifications. Check the underlying source.
If the required material will not fit, choose a model and machine that can handle it, or use a document-search workflow that preserves the relationships the question requires. Splitting a comparison across isolated fragments hides contradictions.
