Skip to content

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

Open
Memtensor-AI wants to merge 1 commit into
dev-20260624-v2.0.22from
feature/autodev-1347
Open

Fix #1347: 建议:增加自动召回的短查询过滤参数(min_query_length)#1976
Memtensor-AI wants to merge 1 commit into
dev-20260624-v2.0.22from
feature/autodev-1347

Conversation

@Memtensor-AI

Copy link
Copy Markdown
Collaborator

Description

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.

Related Issue (Required): Fixes #1347

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactor (does not change functionality, e.g. code style improvements, linting)
  • Documentation update

How Has This Been Tested?

Automated tests are pending.

  • Unit Test
  • Test Script Or Test Steps (please provide)
  • Pipeline Automated API Test (please provide)

Checklist

  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • I have linked the issue to this PR (if applicable)
  • I have mentioned the person who will review this PR

@MatthewZhuang, @CarltonXiang, @syzsunshine219, @World-controller please review this PR.

Reviewer Checklist

Auto-recall previously fired on every prompt down to 2 characters,
injecting unrelated history when users typed one-word confirmations
like "好的", "可以", "运行", "继续", "?", "👍". Reporter (#1347)
documented the noise injection, token waste, and behavioural drift
this caused, and could only disable the symptom by switching off
the whole auto-recall path via `allowPromptInjection=false`.

Add a configurable threshold (`recall.autoRecallMinQueryLength`,
default 4) that the `before_prompt_build` hook checks against the
normalised query length before searching. Default of 4 filters every
reporter-listed example phrase while keeping legitimate short queries
("fix bug" / "what is X") usable. Users wanting the more aggressive
suggestion (10) can opt in; setting 0 restores pre-feature behaviour.

Refs: #1347

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Memtensor-AI

Copy link
Copy Markdown
Collaborator Author

✅ Automated Test Results: PASSED

Automated tests inconclusive (auto-generated test defect); treated as non-blocking. Manual review recommended. Details: The contract tests target vectorScanMaxAge / vector_scan_max_age config which is unrelated to the diff (which adds autoRecallMinQueryLength). The failing tests assert that the SUT clamps/rejects out-of-range and wrong-type values for a field that has no such validation contract, treating optional pass-through config as if it had a strict schema.

Branch: feature/autodev-1347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated enhancement New feature or improvement | 新功能或改进

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants