Skip to content

建议:增加自动召回的短查询过滤参数(min_query_length) #1347

Closed

Description

@smasunspot

问题描述

在使用 memos-local-openclaw-plugin 过程中,发现自动召回机制存在明显的"短词召回污染"问题:

问题场景

用户日常对话中经常出现以下短词:

  • 好的 / 可以 / 没错 / 运行 / 执行 / 继续 / ? / 赞

这些词本质上是语气词或确认词,几乎没有实际语义。但自动召回会把它们当作查询词,从记忆库中搜索相关内容并注入上下文。

造成的问题

  1. 噪音注入:召回到的往往是向量相似度高但语义关联度低的历史记忆,对当前对话毫无帮助
  2. Token 浪费:每次短词触发都会注入 700-1500 chars 的无用内容,加速 context 窗口消耗
  3. 行为歧义:例如用户只说"好的"确认一件事,却被植入一堆不相关的历史记录,容易让 Agent 误解用户意图
  4. 潜在风险:记忆污染可能导致 Agent 基于不相关的历史做出错误判断和操作

实际案例

用户消息:"先这样"(结束对话的确认)

自动召回结果:

  • 召回到用户之前吐槽 MiniMax 的内容(与"先这样"无关)
  • 召回到不相关的 test 任务记录

这些内容对回答"先这样"没有任何正向作用,反而增加了理解成本。

建议方案

参考业界通用做法,添加一个短查询过滤参数:

memory_search:
  min_query_length: 10  # 少于10字的查询不触发召回

或作为召回配置项:

{
  "recall": {
    "minQueryLength": 10
  }
}

替代方案(如果上述实现复杂)

提供 auto_recall_min_query_length 插件级别配置,阻止短查询触发自动召回。

当前临时解决方案

目前通过设置 plugins.entries.memos-local-openclaw-plugin.hooks.allowPromptInjection = false 来禁用自动召回,但这也同时禁用了所有召回功能,用户体验不佳。

使用环境

  • memos-local-openclaw-plugin: v1.0.6-beta.11
  • OpenClaw: 2026.3.x
  • 记忆库规模:约 7000 条记录

期待官方考虑加入这个功能!中文技术支持响应也很及时 👍

Activity

  1. github-actions commented on Apr 25, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale due to inactivity.

  2. added
    status:staleAuto-marked stale after 30d inactivity; closes 7d later unless exempt.
    on Apr 25, 2026
  3. MaiHHConnect commented on Apr 26, 2026

    @MaiHHConnect
  4. removed
    status:staleAuto-marked stale after 30d inactivity; closes 7d later unless exempt.
    on Jun 18, 2026
  5. added
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jun 29, 2026
  6. self-assigned this
    on Jun 30, 2026
  7. Memtensor-AI commented on Jun 30, 2026

    @Memtensor-AI
    Collaborator

    🤖 AutoDev has picked up this issue and started working on it.

    Task ID: 42bc646552bc9665
    Working branch: feature/autodev-1347
    Target branch: latest dev* branch
    Workflow: opsp (analysis → coding → testing → PR)

    I will post the PR link here once done. If I need more information, I will ask in the comments.

  8. Memtensor-AI commented on Jun 30, 2026

    @Memtensor-AI
    Collaborator

    ✅ AutoDev task 42bc646552bc9665 completed.

    Summary: Adds a new recall.autoRecallMinQueryLength config knob (default 4) to @memtensor/memos-local-openclaw-plugin so that very short user prompts no longer trigger the before_prompt_build auto-recall pipeline. This addresses the "short-word recall pollution" issue (#1347) where one-word confirmations like "好的"/"可以"/"运行"/"继续"/"?" would fire vector + FTS search and inject 700-1500 chars of unrelated history into the agent context.

    The fix replaces the previous hard-coded query.length < 2 skip in apps/memos-local-openclaw/index.ts with a comparison against the configured threshold. The default of 4 chars filters every reporter-listed example while keeping legitimate short queries usable; users wanting the reporter's suggested 10 can opt in via config, and setting 0 restores the pre-feature behaviour. The knob only affects automatic recall — explicit memory_search tool calls are unchanged.

    Changes: src/types.ts adds the field to MemosLocalConfig.recall and a default in DEFAULTS; src/config.ts resolves it in resolveConfig; index.ts uses it in the auto-recall hook; README.md documents it. Three new vitest cases in tests/config.test.ts cover default / override / explicit-zero. All 5 new config tests pass; the 19 tests across config, plugin-openclaw-wiring, plugin-impl-access, and recall modules all pass. tsc --noEmit is clean. The 4 unrelated failing files in the full sweep (skill-auto-install, task-processor, update-install) were verified to fail identically on the base branch before any edits in this PR.

    Base branch: main
    Branch: feature/autodev-1347
    Commit: 21dedb3
    PR: #1976
    Assigned to: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller
    Reviewers: @MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller

  9. added
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:pr-readyAI-created PR is ready for review | AI 生成的 PR 已等待评审
    and removed
    ai:codingAI agent is coding | AI 正在编码
    ai:testingAI agent is running tests | AI 正在运行测试
    ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务
    on Jun 30, 2026
  10. added a commit that references this issue on Jul 2, 2026
    9176e38
  11. added and removed
    ai:pr-readyAI-created PR is ready for review | AI 生成的 PR 已等待评审
    on Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area:pluginOpenClaw & Hermestypes:enhancementNew feature or improvement | 新功能或改进

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions