Skip to content

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

Closed

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)

Activity

  1. added a commit that references this issue on May 11, 2026
  2. safishamsi commented on May 11, 2026

    @safishamsi
    Member

    Fixed in v0.7.15 — GRAPHIFY_OLLAMA_NUM_CTX IS correctly wired (see llm.py:290-304). Two real bugs fixed: (1) invalid env var value no longer falls back to hardcoded 131072 — it now falls through to auto-derivation; (2) when the pinned value is smaller than the estimated chunk size, graphify now warns explicitly that Ollama will silently truncate the prompt and suggests reducing --token-budget.

  3. added a commit that references this issue on Aug 13, 2026
  4. added a commit that references this issue on Sep 10, 2026
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