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
[Bug] shouldDisableReasoningForJson regex doesn't match deepseek-v4-flash → wastes ~88-94% of output tokens on reasoning trace
Body
Summary
shouldDisableReasoningForJson in src/llm-client.ts (line 102-103) currently uses the regex:
return/qwen3|deepseek.*r1|qwq/i.test(model);
This regex does not match deepseek-v4-flash (the v4 family ships without an explicit r1 suffix). When the model is configured for JSON extraction in smart-extractor, the LLM client therefore does not inject the chat_template_kwargs: { enable_thinking: false } flag, and DashScope's deepseek-v4-flash returns the answer only in the reasoning_content field with content empty.
PR #914 added a graceful fallback (recoverJsonFromReasoning) that rescues the JSON from the reasoning trace, so extraction still succeeds — but the regex still leaves the door open for downstream inefficiency:
Impact (measured)
Using DashScope OpenAI-compatible endpoint with model deepseek-v4-flash and 6-category extraction prompt:
Metric
Value
Tokens in prompt
~3,200
reasoning_content tokens (per call)
~2,800
content tokens (per call)
~50
Reasoning share of output
~88–94%
Estimated monthly waste on 200 extractions/day
~150M reasoning tokens
Since deepseek-v4-flash accepts chat_template_kwargs: { enable_thinking: false } on DashScope (verified end-to-end), this is pure waste — the model does have a non-thinking mode and the client just isn't asking for it.
Reproduction
Set llm.model to deepseek-v4-flash (DashScope OpenAI-compatible endpoint).
Trigger autoCapture / smart-extractor with a non-trivial conversation.
Inspect gateway logs / LLM request payload — note that chat_template_kwargs is not present in the request body.
The regex should treat the deepseek-v* family (non-reasoning variants) the same way it treats deepseek.*r1 — i.e., inject enable_thinking: false so the model emits JSON directly into content.
This makes the regex match deepseek-v4-flash, deepseek-v4-pro (the pro variant also accepts enable_thinking: false on DashScope), and any future deepseek-vN-* releases, while keeping the existing matches for deepseek-r1, qwen3, and qwq.
Workaround (in use locally)
Currently working around by configuring DashScope's deepseek-v4-flash directly and accepting the reasoning-token waste until the regex is fixed upstream. recoverJsonFromReasoning from PR #914 prevents the worst-case extraction failure, so this is a performance/cost issue rather than a correctness issue.
Issue Bug: Memory injection causes repetition loops in reasoning models (mimo-v2.5) #918 — separate concern (memory injection causing repetition loops on mimo-v2.5); the maintainer comments there list deepseek-v4-flash as a "non-reasoning model that works fine", which is exactly why I think this fix is safe — v4-flash is intended to be a non-thinking model.
Title
[Bug]
shouldDisableReasoningForJsonregex doesn't matchdeepseek-v4-flash→ wastes ~88-94% of output tokens on reasoning traceBody
Summary
shouldDisableReasoningForJsoninsrc/llm-client.ts(line 102-103) currently uses the regex:This regex does not match
deepseek-v4-flash(thev4family ships without an explicitr1suffix). When the model is configured for JSON extraction insmart-extractor, the LLM client therefore does not inject thechat_template_kwargs: { enable_thinking: false }flag, and DashScope'sdeepseek-v4-flashreturns the answer only in thereasoning_contentfield withcontentempty.PR #914 added a graceful fallback (
recoverJsonFromReasoning) that rescues the JSON from the reasoning trace, so extraction still succeeds — but the regex still leaves the door open for downstream inefficiency:Impact (measured)
Using
DashScopeOpenAI-compatible endpoint with modeldeepseek-v4-flashand 6-category extraction prompt:reasoning_contenttokens (per call)contenttokens (per call)Since
deepseek-v4-flashacceptschat_template_kwargs: { enable_thinking: false }on DashScope (verified end-to-end), this is pure waste — the model does have a non-thinking mode and the client just isn't asking for it.Reproduction
llm.modeltodeepseek-v4-flash(DashScope OpenAI-compatible endpoint).autoCapture/ smart-extractor with a non-trivial conversation.chat_template_kwargsis not present in the request body.choices[0].message.contentis empty or near-empty; the JSON lives insidereasoning_content. (PR fix(smart-extractor): only learn noise from a genuine empty extraction; recover JSON from the reasoning field #914'srecoverJsonFromReasoningrescues it, so extraction still works, but at the cost above.)Expected
The regex should treat the
deepseek-v*family (non-reasoning variants) the same way it treatsdeepseek.*r1— i.e., injectenable_thinking: falseso the model emits JSON directly intocontent.Suggested fix
One-line patch in
src/llm-client.ts:This makes the regex match
deepseek-v4-flash,deepseek-v4-pro(the pro variant also acceptsenable_thinking: falseon DashScope), and any futuredeepseek-vN-*releases, while keeping the existing matches fordeepseek-r1,qwen3, andqwq.Workaround (in use locally)
Currently working around by configuring DashScope's
deepseek-v4-flashdirectly and accepting the reasoning-token waste until the regex is fixed upstream.recoverJsonFromReasoningfrom PR #914 prevents the worst-case extraction failure, so this is a performance/cost issue rather than a correctness issue.Related
recoverJsonFromReasoning(merged; rescues JSON but doesn't disable reasoning)deepseek-v4-flashas a "non-reasoning model that works fine", which is exactly why I think this fix is safe —v4-flashis intended to be a non-thinking model.Environment
memory-lancedb-pro@e0cd6e8(master, latest)https://dashscope.aliyuncs.com/compatible-mode/v1deepseek-v4-flash