feat(harness): 为记忆与会话检索增加可选多关键词匹配模式 - #3062
Open
wzq-xzwj wants to merge 1 commit into
Open
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
dailingtao
approved these changes
Sep 9, 2026
| matchMode, | ||
| term -> { | ||
| String lowerTerm = term.toLowerCase(); | ||
| return text -> text.toLowerCase().contains(lowerTerm); |
Contributor
There was a problem hiding this comment.
Non-blocking: each term predicate lowercases the full session entry independently, so an all/any query with N terms can allocate N lowercase copies per entry. Could we normalize content once per entry (while preserving the existing locale behavior) and run the predicates against that normalized string?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3054
背景
模型有时会传入空格分隔的多个关键词,例如
query="部署 蓝鲸"。当前两个检索工具都把完整 query 当作字面短语,因此无法命中部署决定:使用蓝鲸方案。这个 PR 提供一个可选的多关键词匹配方案。默认行为保持不变,具体参数和语义可以根据评审意见调整。
方案
为
memory_search和session_search增加可选字符串参数matchMode:phrase(默认)allany调用示例:
{"query": "部署 蓝鲸", "matchMode": "all"}session_search仍可同时传入agentId和maxResults。边界与兼容性
matchMode或传入null时使用phrase。值区分大小写;非法值(包括空字符串)返回明确错误,不静默切换模式。allMatch的空集合语义而匹配所有记录。@Tool,避免重复注册。实现
KeywordMatcher,共用模式校验、空白拆词和 all/any 组合逻辑;每次查询创建匹配器,不在每条记录上重新拆词或编译正则。MemorySearchTool和SessionSearchTool接入匹配器,并补充工具参数描述。KeywordSearchModesTest,同时验证两个工具的实际文件检索及 Toolkit 注册/调用。测试
本地使用 JDK 21、Java release 17 编译,以下定向测试共 83 项通过,0 失败、0 错误、0 跳过,其中新增多关键词测试 18 项:
mvn -pl agentscope-harness -am test \ -Dtest=KeywordSearchModesTest,SessionTranscriptWriterTest,SessionTreeMirrorTest,MemoryConsolidatorFilesystemTest,HarnessAgentTest \ -Dsurefire.failIfNoSpecifiedTests=false -Dspotless.skip=true另行对本次修改的四个 Java 文件执行 Spotless 格式化与检查,通过:
mvn -pl agentscope-harness spotless:check \ '-DspotlessFiles=.*KeywordMatcher.java,.*MemorySearchTool.java,.*SessionSearchTool.java,.*KeywordSearchModesTest.java'git diff --cached --check通过。以上为定向回归,不是全仓测试,也没有调用真实 LLM 验证模型选择模式的概率。覆盖:默认/旧 Java 入口、完整短语空白保留、中文关键词、英文大小写、不相邻及乱序关键词、all/any 无匹配、正则特殊字符、Unicode 空白、重复词、空查询、无效模式、不跨行/entry、daily ledger、agentId 过滤、maxResults,以及新参数的 schema 和反射调用。
不在本次范围内
没有增加第三方依赖,也没有改默认模式为 OR 匹配。该改动改善显式多关键词查询,不代表模型一定会选择新模式。