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)
Took me a while to figure why it wasnt working properly with my local ollama
Summary
_call_openai_compatnever passesnum_ctxto Ollama. Ollama's default is 2048 tokens, so any extraction chunk exceeding that returnscontent = "", which_parse_llm_jsonreports asExpecting value: line 1 column 1 (char 0).token_budgetbelow Ollama's default context (which defeats the purpose)._call_openai_compat— detectbackend == "ollama", injectextra_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.pyin the_call_openai_compatfunction. Here's the exact problem and solution:The bug: When calling Ollama, graphify never passes
num_ctxto override Ollama's default context window (2048 tokens). Any chunk larger than ~2048 tokens silently returns an empty response. TheGRAPHIFY_OLLAMA_NUM_CTXenv var exists in the CLI but is never wired into the Python API.Current code (around the
extra_bodysection):Fixed code: