Skip to content

fix: 记忆检索链路太慢 - #588

Merged
origami-chen merged 2 commits into
MemTensor:v1.2.1from
Orsted290:fix-memory-retrieval-thinking-off
Oct 9, 2026
Merged

origami-chen merged 2 commits into
MemTensor:v1.2.1from
Orsted290:fix-memory-retrieval-thinking-off

Conversation

@Orsted290

Copy link
Copy Markdown
Contributor

问题定位

记忆检索变慢,是因为账号模式下检索调用摘要模型时,请求里没有带关闭思考的字段,模型按默认开着思考跑。

检索链路里的查询抽取和 LLM 过滤都传了 thinkingMode: "disabled",但这个选项在组装请求体时被丢掉了。账号模式有两种配置,两种都对不上现有的判断规则:

  • 账号自带模型的 sourceProvider 是 memmy_account,vendor 映射表里没有这一项,落到了 openai_compatible。
  • 自定义预设的 provider 写成 openai,地址却指向账号网关 api.memmy.cn/api/agentExternal/v1,模型名是网关别名 memory_summary。

两种情况下,vendor、模型名和网关地址都匹配不上已知的思考字段写法,请求体里什么都不带。网关把请求原样转给百炼,百炼按模型默认开着思考,而且网关不做字段转换。这是 2026-08-11 模型目录重构留下的回归,重构前账号模式写死 vendor 为 qwen,请求会带 enable_thinking。

同一条过滤请求的对比:旧版不带字段时返回约 270 个思考 token,耗时 15 到 60 秒;带上关闭字段后思考 token 为 0,输出只有 12 个 token。

修改内容

只改了 Memory/src/model/llm.ts 和 Memory/tests/llm-thinking.test.ts。

  • 来源是 memmy_account,或请求地址包含 /api/agentExternal/ 时,同时发送百炼的两套开关:enable_thinking 和 thinking.type。Qwen、DeepSeek、GLM、Kimi 认前者,MiniMax 认后者,网关别名背后是哪个模型客户端无从得知。
  • 关闭思考时保留 response_format;开启思考时去掉 JSON mode,并重新带上 thinking_budget: 1000,账号进化模型原来设的预算因此生效。
  • 真正的 OpenAI 地址不受影响。

测试结果

  • npm run memory:test:1076 个通过,1 个跳过。npm run lint 和 npm run typecheck 通过。新增用例在原代码上会失败。
  • 真实账号网关:关闭思考后思考 token 为 0;把思考打开,同一请求回到 223 个思考 token。
  • 打包后的桌面端,网络正常的一轮:6 次 memory_search 全部成功,没有超时或兜底,平均 4.3 秒,最慢 6.4 秒。查询抽取 2.2 到 3.5 秒,LLM 过滤 1.6 到 3.9 秒。修复前近 7 天 41 次平均 63 秒,最慢 117 秒。

Orsted290 and others added 2 commits October 9, 2026 15:31
Account-mode memory models resolved to vendor openai_compatible with gateway aliases such as memory_summary, so no thinking field was sent and retrieval calls requested with thinking disabled still ran with the Bailian default. Send both enable_thinking and thinking.type for memmy_account, keep JSON mode when disabled, and restore the account evolution thinking budget.

Co-authored-by: Cursor <cursoragent@cursor.com>
Account-mode memory summary can be assigned a custom provider preset that targets the account gateway, so the source provider is not memmy_account. Match the gateway endpoint path as well so those requests also send the Bailian thinking switches.

Co-authored-by: Cursor <cursoragent@cursor.com>
@origami-chen
origami-chen merged commit fc2025d into MemTensor:v1.2.1 Oct 9, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants