Tuning Ollama's num_ctx for Better Preference Analysis
Ollama's num_ctx setting, not open-context's own text limit, decides how much of your
conversation history a model can actually use when generating preferences.md and
memory.md. open-context's OllamaPreferenceAnalyzer trims your exported
conversations to roughly 100,000 tokens before sending them to Ollama, but it never sets
num_ctx on that request — so unless your Ollama server or model is configured with a
context window at least that large, the model is working with less of your history than
open-context intended to give it.
Key takeaways
OllamaPreferenceAnalyzercaps conversation text at roughly 100,000 tokens (about 400,000 characters) before sending it to Ollama, but never setsnum_ctxon the request itself.num_ctxcontrols how much of a prompt a loaded model can actually use — it's a separate limit from how much text you send, and it's set on the Ollama side, not the client side.gpt-oss:20b, open-context's default model, has a native context window of about 131,072 tokens, but Ollama doesn't automatically load that much by default — the active size depends on your Ollama version and available GPU memory.ollama show <model>tells you whethernum_ctxis explicitly configured for a model tag; if it's missing, you're on an unconfigured default.- You can raise it with the
OLLAMA_CONTEXT_LENGTHenvironment variable (server-wide), aPARAMETER num_ctxline in a custom Modelfile (per model), or anum_ctxfield in the API request options (per call) — open-context's CLI has no flag for this today.
What open-context actually sends to Ollama
OllamaPreferenceAnalyzer.prepareConversationText() sorts your parsed conversations
chronologically, formats each one as CONVERSATION/DATE/role lines, and
keeps appending them to a single block of text until it would exceed roughly 400,000 characters —
a rough 4-characters-per-token estimate of a 100,000-token budget. Once that budget is hit, it logs
a truncation warning and stops. That block becomes the prompt handed to
ollama.generate(), run against whichever model you picked with --model.
This is a client-side limit open-context enforces on its own, before anything reaches Ollama. It has nothing to do with what the model on the other end is actually configured to read.
num_ctx is a separate limit, not open-context's
Sending a 100,000-token prompt to a model doesn't mean the model reads all 100,000 tokens of it.
Every model Ollama loads gets a context buffer sized by num_ctx, and that buffer — not
the length of the prompt you send — is the real ceiling on how much of a request a model can
actually attend to during generation. If num_ctx is smaller than what you send, nothing
errors out. There's no warning that part of your conversation history wasn't fully usable context;
the run just finishes and hands back a result.
That's the gap worth knowing about: open-context's 100,000-token cap is a promise about what it will send. It isn't a promise about what the model will actually use.
gpt-oss:20b's real ceiling, and what Ollama actually loads
open-context defaults to gpt-oss:20b, listed in its own
model comparison as the
best-overall-results option. Per
a Hugging Face discussion
quoting its ollama show output and its
LM Studio model listing,
gpt-oss:20b's native context window is about 131,072 tokens — comfortably above
open-context's 100,000-token cap.
That number is the model's architectural ceiling, not what Ollama loads by default. Ollama's
default context allocation has changed across releases, and more recent versions size it based on
how much GPU memory Ollama detects when a model is loaded rather than on the model's own maximum.
In practice, an already-pulled gpt-oss:20b can end up running with a context window far
short of 131k tokens unless you've set one explicitly.
Checking what's actually configured
Run ollama show gpt-oss:20b (swap in whatever model you use) and look at the Modelfile
parameters section of the output. If num_ctx appears there, that's the context window
baked into that specific model tag. If it doesn't appear at all, you're running on whatever default
your installed Ollama version falls back to — not a number anyone chose on purpose.
Three ways to raise it
Environment variable — server-wide
Set it before starting the Ollama server, and every model it loads afterward inherits the value:
OLLAMA_CONTEXT_LENGTH=131072 ollama serve
Modelfile — per model
Bake it into a specific model tag so it's fixed regardless of server defaults:
FROM gpt-oss:20b
PARAMETER num_ctx 131072
ollama create gpt-oss-20b-longctx -f Modelfile
Then point open-context at the new tag with --model gpt-oss-20b-longctx.
Per-request API option — what open-context's own code would need
The underlying fix lives in src/analyzers/ollama-preferences.ts. Its call to
ollama.generate({ model: this.model, prompt, stream: false }) could pass
options: { num_ctx: 131072 } directly, syncing the Ollama request with the
100,000-token budget already baked into prepareConversationText(). open-context
doesn't do this today, so raising num_ctx server-side or via a custom Modelfile is the
only lever available in the meantime.
A recipe for large ChatGPT exports
If you're converting an export with dozens of long conversations and want gpt-oss:20b to actually use all of what open-context prepares for it:
- Pull the model if you haven't already:
ollama pull gpt-oss:20b - Create a Modelfile with
PARAMETER num_ctx 131072and build a new tag withollama create gpt-oss-20b-longctx -f Modelfile - Run the conversion against that tag:
npm start -- convert path/to/export.zip --model gpt-oss-20b-longctx - Confirm it took effect with
ollama show gpt-oss-20b-longctx—num_ctxshould read131072
If you'd rather skip the tuning entirely, --skip-preferences still produces a full
markdown conversion with a basic, non-AI preferences summary — see the
pipeline walkthrough for what
that fallback path looks like.
Convert your own ChatGPT export with open-context, tuned the way you want it.
Get started with open-context →FAQ
What is num_ctx in Ollama, and why does it matter for open-context?
num_ctx is the setting that controls how many tokens of a prompt a loaded Ollama model can actually use during inference. It matters for open-context because the preference analyzer sends up to roughly 100,000 tokens of your conversation history to Ollama, but that cap is unrelated to num_ctx — the model can only read as much of it as its actual context window allows.
Does open-context set num_ctx automatically when it calls Ollama?
No. OllamaPreferenceAnalyzer calls ollama.generate() with just a model name and prompt — it never passes a num_ctx option, so the request runs on whatever context window your Ollama server or Modelfile has configured for that model, not on open-context's own 100,000-token text cap.
How much context does gpt-oss:20b, open-context's default model, actually support?
gpt-oss:20b's native context window is about 131,072 tokens, per its model card and listings on Hugging Face and LM Studio. That's the model's architectural ceiling, not a guarantee of what Ollama allocates by default — the active context size still depends on your Ollama version and available GPU memory.
How do I check or raise the context window Ollama is using for a model?
Run ollama show <model> to see whether num_ctx appears among its Modelfile parameters; if it's absent, you're on an unconfigured default. Raise it with the OLLAMA_CONTEXT_LENGTH environment variable before starting the server, a PARAMETER num_ctx line in a custom Modelfile, or a num_ctx field in the API request's options object.
Does raising num_ctx change what open-context sends, or just what the model can use?
Just what the model can use. open-context's own 100,000-token cap in prepareConversationText() stays fixed regardless of num_ctx — raising num_ctx only ensures the model can actually read all of what open-context already sends, instead of silently working with less of it.