Skip to content

Make Ollama context window configurable via num_ctx#29

Merged
rcjackson merged 1 commit into
ARM-Development:mainfrom
rcjackson:ollama-num-ctx
Jul 10, 2026
Merged

Make Ollama context window configurable via num_ctx#29
rcjackson merged 1 commit into
ARM-Development:mainfrom
rcjackson:ollama-num-ctx

Conversation

@rcjackson

Copy link
Copy Markdown
Collaborator

Summary

Ollama defaults to a small context window (2048 tokens), which silently truncates long prompts and image inputs — producing degraded or incomplete labels with no error.

This makes the context window configurable and sends it to Ollama via the request options.num_ctx for both the /api/generate (vision) and /api/chat (text) endpoints.

Changes

  • config.py: add OLLAMA_NUM_CTX (env var OLLAMA_NUM_CTX, default 8192).
  • OllamaModel.__init__: accept a num_ctx argument, falling back to the config default.
  • Both request payloads now include "options": {"num_ctx": self.num_ctx}.

Usage

# per-instance
ollama = OllamaModel("llama3.2-vision:latest", num_ctx=16384)
# or via environment
OLLAMA_NUM_CTX=16384

Notes

Larger context windows increase memory use; raise gradually for large vision models to avoid slow loads / OOM. Independent of #28.

🤖 Generated with Claude Code

Ollama defaults to a small context window (2048 tokens), which silently
truncates long prompts and image inputs. Expose it as a configurable
num_ctx passed in the request options for both the generate and chat
endpoints.

The value can be set per-instance (OllamaModel(num_ctx=...)) or via the
OLLAMA_NUM_CTX environment variable, defaulting to 8192.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@rcjackson rcjackson merged commit 79143d2 into ARM-Development:main Jul 10, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant