Skip to content

memos-local-plugin: improve retrieval relevance and host-context handling #2195

Description

@Hun-ger

Summary

The standalone memos-local-plugin has several related correctness problems in automatic recall across OpenClaw and Hermes:

  1. Weak keyword or pattern matches, duplicated question traces, priority/recency signals, and unrelated memory tiers can dominate retrieval candidates for personal-fact queries.
  2. When the LLM relevance filter selects no candidates, the existing rescue path mechanically refills the result and can inject unrelated memories.
  3. OpenClaw IM channels can wrap the user body with metadata such as message_id and sender identifiers. The wrapped prompt may leak that metadata into memos_search and memory_add.
  4. OpenClaw heartbeat and asynchronous command-completion wakeups can be mistaken for user input and trigger memory search or capture.
  5. Excluding the entire current session prevents recall of older same-session memories after the host compresses them out of the model-visible conversation.
  6. Retrieval logs do not always make the mechanical ordering, score components, and actual post-LLM count clear.

This is a follow-up to #1913 and #1923. The prior fix avoided an empty injection by refilling candidates, but that fallback does not respect a valid empty LLM selection and can introduce unrelated context.

Expected behavior

  • Semantic retrieval should use the normalized user body only. Routing and visibility hints must not participate in semantic matching.
  • Personal-fact queries should prioritize relevant trace evidence over unrelated skills, world models, or recency-ranked pattern hits.
  • High-confidence duplicate candidates should not consume Top-K capacity, while distinct evidence and keyword or multi-channel eligibility remain preserved.
  • An empty LLM relevance-filter result should remain empty rather than being mechanically refilled.
  • OpenClaw integrations should use the official clean inbound body when available and use envelope parsing only as a compatibility fallback.
  • Internal OpenClaw events should not trigger memory search or capture.
  • Same-session traces still visible to the model should be excluded, while older traces outside the visible context after compression should be eligible for recall.
  • Logs should show candidates in their effective order with accurate score details and kept/dropped counts.

Proposed implementation

  • Build the semantic query only from clean user text and keep contextHints as routing/filter metadata.
  • Correct vector evidence scoring and add a personal-fact retrieval profile.
  • Apply conservative rule-based deduplication after scoring/RRF and before the relative threshold and MMR.
  • Preserve keyword-confirmed and multi-channel bypass capabilities during early deduplication.
  • Continue using MMR for embedding-based diversity.
  • Honor the LLM filter result when it returns an empty selection.
  • Correlate OpenClaw message_received.content with later agent hooks by runId; retain conservative legacy sanitization for old hosts and cache misses.
  • Filter heartbeat and internal wakeup signatures before recall and capture.
  • Pass model-visible conversation boundaries into retrieval. For Hermes, record the boundary during on_pre_compress without modifying the compression payload.
  • Add score diagnostics and accurate post-filter candidate logging.

Compatibility

  • No database schema migration.
  • No embedding model or dimension change.
  • No new runtime dependency.
  • Existing memories and embeddings remain compatible.
  • Before a compression boundary is known, preserve the legacy whole-session exclusion behavior.

Affected components

  • apps/memos-local-plugin/core/retrieval/
  • apps/memos-local-plugin/adapters/openclaw/
  • apps/memos-local-plugin/adapters/hermes/
  • Retrieval logging and viewer presentation

Acceptance criteria

  • Personal-fact regression tests cover unrelated pattern candidates, score ordering, duplicate candidates, exact identifiers, and mixed embedding dimensions.
  • The LLM filter can intentionally return zero candidates without fallback injection.
  • Feishu-style channel metadata is absent from search queries and captured user text when clean host input is available.
  • OpenClaw internal wakeups do not create memos_search or memory_add activity.
  • OpenClaw and Hermes can recall compacted same-session history while excluding content still visible to the model.
  • Retrieval logs report the actual candidate order, score components, and post-LLM counts.
  • Existing memory data remains readable without migration.

Metadata

Metadata

Labels

area:pluginOpenClaw & Hermesstatus:needs-triageNeeds initial triage | 需要初步判断 & 问题复现

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions