Skip to content

[Bug]: Ollama ignores graphify's context size, so docs come back empty #4413

Open

Description

@smngvlkz

What's happening

I tried graphify extract --backend ollama with qwen2.5:14b on a few docs, and none of them made it into the graph. Every try, the model wrote a plain summary of the docs instead of JSON, and graphify gave up after 3 retries.

graphify works out a context size for each chunk and sends it to Ollama as num_ctx. But it sends it to Ollama's /v1 address, and that address ignores it. So Ollama just uses its own default, which is 4096 on my machine, and cuts off the rest of the prompt. That cuts off the part asking for JSON, so the model answers in plain text.

You can see it in graphify's own output. It says tokens: 4,096 in even though the docs were a lot bigger than that.

How to see it for yourself

This sends the same long prompt with num_ctx set to 20000, once to /v1 like graphify does and once to Ollama's own /api/chat:

python3 - <<'EOF'
import json, urllib.request
long = "word " * 12000
def post(path, body):
    r = urllib.request.Request("http://localhost:11434" + path, json.dumps(body).encode(), {"Content-Type": "application/json"})
    return json.load(urllib.request.urlopen(r))
m = "qwen2.5:14b"
a = post("/v1/chat/completions", {"model": m, "messages": [{"role": "user", "content": long}], "max_tokens": 10, "options": {"num_ctx": 20000}})
print("/v1:", a["usage"]["prompt_tokens"])
b = post("/api/chat", {"model": m, "messages": [{"role": "user", "content": long}], "stream": False, "options": {"num_ctx": 20000, "num_predict": 10}})
print("/api/chat:", b["prompt_eval_count"])
EOF

I got /v1: 4096 and /api/chat: 12030.

Proof it's the cause

Same 2 docs (requests' README and quickstart, about 5.5k tokens), same model. The only change was making a copy of the model with the bigger context built in (PARAMETER num_ctx 12288 in a Modelfile):

  • normal qwen2.5:14b: cut to 4,096 tokens, plain text back 3 times, empty graph after about 12 minutes
  • copy with 12k context: all 6,316 tokens read, proper JSON first try, done in 3 minutes

What should happen

The context size graphify works out should actually reach Ollama, so chunks bigger than Ollama's default don't get cut off.

Also, when this happens the message says it's usually "a rate limit, a transport hiccup, a refusal, or a model that answered in prose". That sent me looking in the wrong places. If the tokens in are exactly Ollama's context size, it would help to say the prompt was probably cut off.

Related: #3982 saw part of this. They asked for 14000 and got their server's 11000.


Version: graphify 0.9.87 · Ollama 0.17.5 · macOS 26.4.1 · Python 3.14

Activity

  1. github-actions commented on Oct 13, 2026

    @github-actions

    Thanks for opening this issue, @smngvlkz. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. ayushcodes10 commented on Oct 16, 2026

    @ayushcodes10
    Contributor

    This looks already fixed on v8: graphify/llm.py has _call_ollama_native, which sends requests to Ollama's native /api/chat endpoint (falling back to /v1 only for servers without it, e.g. LM Studio/llama.cpp) specifically citing this issue number in its comment, landed via #4414 (closed, not auto linked since it was cherry picked rather than merged through the PR button, same as #2780/#2779). Might be worth closing this one.

  3. omsenjalia commented on Oct 18, 2026

    @omsenjalia
    Contributor

    This looks fixed on the v8 branch by f48425e6 (send ollama requests to /api/chat so num_ctx actually applies). Could a maintainer confirm and close?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions