Skip to content

Enhance memos-local retrieval with modular logic and LLM integration#1226

Open
lcpdeb wants to merge 3 commits intoMemTensor:mainfrom
lcpdeb:pr/memos-local-intent-filter
Open

Enhance memos-local retrieval with modular logic and LLM integration#1226
lcpdeb wants to merge 3 commits intoMemTensor:mainfrom
lcpdeb:pr/memos-local-intent-filter

Conversation

@lcpdeb
Copy link

@lcpdeb lcpdeb commented Mar 14, 2026

This pull request introduces a new intent filter module to improve the precision of memory retrieval in the memos-local-openclaw app. The changes add configurable logic to determine whether a user query should trigger memory search, skip retrieval, or require LLM-based intent judgment. The module is rigorously tested and integrated into the auto-recall flow, allowing for more relevant memory hits and reducing context pollution from irrelevant queries.

Intent filter module and pattern matching:

  • Added a new intent-filter.ts module implementing intent judgment logic, including pattern-based skip/search rules, LLM prompt generation, output parsing, and configuration options.
  • Introduced intent-patterns.ts containing regex patterns for skip and explicit memory recall, along with utilities for compiling and matching patterns.

Integration and configuration:

  • Integrated intent filter logic into the auto-recall flow in index.ts, using executeIntentJudge to decide whether to proceed with memory search and applying configurable max results. [1] [2] [3]
  • Added support for plugin-level configuration of intent filter options, including fallback strategies and result limits. [1] [2]

Testing and validation:

  • Added comprehensive tests in intent-filter.test.ts covering skip/search rules, LLM output parsing, fallback behaviors, and configuration value clamping.Key Improvements:
  • Modularized Intent Logic: Extracted judgment logic into dedicated intent-filter.ts and intent-patterns.ts to allow for specialized local processing.
  • Persistent Intent Filtering: Implemented a reliable filter mechanism that survives restarts, ensuring consistent recall behavior.
  • Advanced Regex Pattern Matching: Replaced brittle regex literals with dynamic new RegExp() constructors to fix UTF-8 encoding issues and support multi-language scenarios.
  • LLM-Powered Judgment: Integrated an LLM-based intent analyzer with configurable timeouts and fallbacks to reduce irrelevant memory searches.
  • Performance Optimization: Added query normalization (trimming) and filter-out logic for conversational fillers/real-time queries.
  • Configuration Integration: Exposed llmTimeoutMs and autoRecallMaxResults settings to the plugin configuration interface.
  • Quality Assurance: Introduced a full Vitest suite in tests/intent-filter.test.ts to validate intent branching and edge cases.

These changes collectively reduce context pollution and improve the overall "intelligence" of the auto-recall feature.

Description

Please include a summary of the change, the problem it solves, the implementation approach, and relevant context. List any dependencies required for this change.

Related Issue (Required): Fixes @issue_number

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • 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) | 我已在 MemOS-Docs 中创建了相关的文档 issue/PR(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

Reviewer Checklist

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Made sure Checks passed
  • Tests have been provided

…he memos-local memory retrieval system.

Key Improvements:
- Modularized Intent Logic: Extracted judgment logic into dedicated `intent-filter.ts` and `intent-patterns.ts` to allow for specialized local processing.
- Persistent Intent Filtering: Implemented a reliable filter mechanism that survives restarts, ensuring consistent recall behavior.
- Advanced Regex Pattern Matching: Replaced brittle regex literals with dynamic `new RegExp()` constructors to fix UTF-8 encoding issues and support multi-language scenarios.
- LLM-Powered Judgment: Integrated an LLM-based intent analyzer with configurable timeouts and fallbacks to reduce irrelevant memory searches.
- Performance Optimization: Added query normalization (trimming) and filter-out logic for conversational fillers/real-time queries.
- Configuration Integration: Exposed `llmTimeoutMs` and `autoRecallMaxResults` settings to the plugin configuration interface.
- Quality Assurance: Introduced a full Vitest suite in `tests/intent-filter.test.ts` to validate intent branching and edge cases.

These changes collectively reduce context pollution and improve the overall "intelligence" of the auto-recall feature.
Copilot AI review requested due to automatic review settings March 14, 2026 04:28
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an intent-filtering layer to the memos-local-openclaw plugin’s auto-recall flow, aiming to reduce irrelevant memory retrieval by using pattern rules first and an LLM-based judge when needed.

Changes:

  • Added intent-patterns.ts (regex pattern sources + compile/match utilities) and intent-filter.ts (skip/search/LLM-judge decision flow + output parsing + max-results resolver).
  • Integrated intent-judging into before_agent_start auto-recall in index.ts, including configurable autoRecallMaxResults.
  • Added Vitest coverage for skip/search rules, LLM output parsing, timeouts, and fallback behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
apps/memos-local-openclaw/index.ts Wires the new intent filter into auto-recall and reads plugin config for intent-filter options.
apps/memos-local-openclaw/src/intent-filter.ts Implements intent decision logic (patterns + optional LLM judge), parsing, and max-results resolution.
apps/memos-local-openclaw/src/intent-patterns.ts Defines and compiles regex pattern sources for skip and explicit memory queries.
apps/memos-local-openclaw/tests/intent-filter.test.ts Adds unit tests validating the intent-filter branching and parsing behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +161 to 162
const intentFilterOptions = ((pluginCfg as any).intentFilter ?? {}) as any;
const stateDir = api.resolvePath("~/.openclaw");
Comment on lines +262 to +266
const intentResult = await Promise.race([
summarizer.summarize(intentCheck.llmPrompt!),
timeoutPromise,
]).finally(() => {
if (tid !== undefined) timerApi.clearTimeout(tid);
lcpdeb and others added 2 commits March 14, 2026 12:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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