Skip to content

Ollama backend silently returns empty responses — GRAPHIFY_OLLAMA_NUM_CTX not wired into Python API #820

Description

@Korayem

Took me a while to figure why it wasnt working properly with my local ollama

Summary

  • Root cause: _call_openai_compat never passes num_ctx to Ollama. Ollama's default is 2048 tokens, so any extraction chunk exceeding that returns content = "", which _parse_llm_json reports as Expecting value: line 1 column 1 (char 0).
  • Impact: All Ollama extractions silently produce 0 nodes / 0 edges unless you work around it by shrinking token_budget below Ollama's default context (which defeats the purpose).
  • Fix: Two lines in _call_openai_compat — detect backend == "ollama", inject extra_body={"options": {"num_ctx": int(os.environ.get("GRAPHIFY_OLLAMA_NUM_CTX", 32768))}}. The env var already exists in the CLI, just needs to reach the API layer.

Details

The fix is in graphify/llm.py in the _call_openai_compat function. Here's the exact problem and solution:

The bug: When calling Ollama, graphify never passes num_ctx to override Ollama's default context window (2048 tokens). Any chunk larger than ~2048 tokens silently returns an empty response. The GRAPHIFY_OLLAMA_NUM_CTX env var exists in the CLI but is never wired into the Python API.

Current code (around the extra_body section):

# Kimi-k2.6 is a reasoning model — disable thinking so content isn't empty
if "moonshot" in base_url:
    kwargs["extra_body"] = {"thinking": {"type": "disabled"}}
resp = client.chat.completions.create(**kwargs)

Fixed code:

# Kimi-k2.6 is a reasoning model — disable thinking so content isn't empty
if "moonshot" in base_url:
    kwargs["extra_body"] = {"thinking": {"type": "disabled"}}

# Ollama requires explicit num_ctx — default is 2048 which causes silent
# empty responses for any chunk exceeding that. GRAPHIFY_OLLAMA_NUM_CTX
# is already documented for the CLI but never wired into the Python API.
if backend == "ollama":
    num_ctx = int(os.environ.get("GRAPHIFY_OLLAMA_NUM_CTX", 32768))
    kwargs["extra_body"] = {"options": {"num_ctx": num_ctx}}

resp = client.chat.completions.create(**kwargs)

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