Ollama context length: how to check what a 128K model actually uses
A model card’s 128K number is not the context your current session has allocated. Run the model in your usual app, then check the loaded tag with ollama ps. For long documents, count the text, instructions and answer together before changing the setting.
Calculate context budgetSeparate what the publisher supports from what you loaded
The Qwen3-4B publisher card distinguishes 32,768 tokens natively from 131,072 with YaRN, a way to extend context in a compatible, configured runtime. Neither figure tells you the allocation of your Ollama session. Ollama’s context-length page describes hardware-dependent defaults; its FAQ also lists a 4,096-token default. Your installed version, settings and the client’s request can affect which number you see. There is no safe universal number to assume from these pages alone.
Check the live allocation, not the downloaded inventory
Run a short test in the app and model tag you actually plan to use. While the model is still loaded, run ollama ps against the same Ollama instance. In versions that show it, read CONTEXT on that tag’s row. The corresponding running-model API is GET /api/ps; inspect that model’s context_length if the field is present. ollama list only answers whether a model is installed. A finished API response’s prompt_eval_count and eval_count describe that response; they are not the size of the allocated window.
Budget enough space for the answer
Say a document and your question take 6,000 tokens. Budget another 1,000 for system instructions, chat history, the chat template and any tool definitions, plus 1,500 for generation. That is 8,500 tokens, so an allocation of 8,192 leaves 308 too few. This is planning arithmetic, not a measurement or an automatic reply reservation. Tokenization depends on the model, and the overhead depends on the app and conversation. Start a fresh chat, split the document, or try a supported larger setting if you need the whole text at once.
Change one setting, then check again
In the Ollama app, the context slider is in settings. In an interactive ollama run session, use /set parameter num_ctx 16384, replacing 16384 with your target. Ollama documents the command with a 4,096-token example. For an API client using Ollama’s native API, request options.num_ctx. Send a short follow-up through the same client and check the same loaded model again. If your check still shows the old size, look at what your client actually requested before raising the server default. A higher allocation can need more memory; it does not enable YaRN or guarantee a complete, accurate answer.
If a longer window still misses an important detail
Use a harmless sample and ask for one fact near the beginning and one near the end. Check the answers against the text instead of accepting a plausible summary. If the workflow fails, try a fresh chat with a shorter piece or verify that your app really sent the document. Passing this spot-check is useful for that task, not proof that the model reliably uses every token in its window.
Context budget calculator
Enter counts from the same model tokenizer. Use the active runtime window, not the maximum quoted on the model card. Nothing is sent anywhere.
Window minus instructions, chat, and reserved output gives the document budget.
Enter all five counts (enter 0 if a category is empty).
Sources
- Ollama · DocumentationPublisher · docs.ollama.com↗
- Ollama · Frequently asked questionsPublisher · docs.ollama.com↗
- Ollama · DocumentationPublisher · docs.ollama.com↗
- Ollama · DocumentationPublisher · docs.ollama.com↗
- Ollama · DocumentationPublisher · docs.ollama.com↗
- Hugging Face · Qwen3 4B · Model cardPublisher · huggingface.co↗