You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ollama backend silently returns empty responses — GRAPHIFY_OLLAMA_NUM_CTX not wired into Python API #820
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 emptyif"moonshot"inbase_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 emptyif"moonshot"inbase_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.ifbackend=="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)
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.
Activity
fix #821 #818 #820: universal help guard, --version flag, Ollama num_…
safishamsi commentedon May 11, 2026
Fixed in v0.7.15 —
GRAPHIFY_OLLAMA_NUM_CTXIS correctly wired (seellm.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.fix Graphify-Labs#821 Graphify-Labs#818 Graphify-Labs#820: universal …
fix Graphify-Labs#821 Graphify-Labs#818 Graphify-Labs#820: universal …