Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

fix(store): preserve grouped CJK column filters

Samir Hanna Verzaa7826228af4d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d7569b73..7658800a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,11 @@ version in [`docs/changelog/`](docs/changelog/):
## [Unreleased]
+### Fixed
+
+- Preserved `title:` and `body:` filters inside parenthesized CJK searches,
+ so grouped queries no longer include matches from other columns (#PR).
+
## [3.2.10] - 2026-10-29
### Changed
diff --git a/crates/ai-memory-store/src/fts_query.rs b/crates/ai-memory-store/src/fts_query.rs
index 7a5d4dca..2630a971 100644
--- a/crates/ai-memory-store/src/fts_query.rs
+++ b/crates/ai-memory-store/src/fts_query.rs
@@ -260,6 +260,10 @@ pub(crate) fn prepare_cjk_fts5_query(raw: &str) -> Option<String> {
}
let mut phrases = Vec::new();
for token in bounded.split_whitespace() {
+ // Grouping must not turn `(title:term)` into an unqualified match.
+ // Like prepare_fts5_token, peel opening parentheses before the column:
+ // https://www.sqlite.org/fts5.html#fts5_column_filters
+ let token = token.trim_start_matches('(');
let (column, text) = match token.split_once(':') {
Some((column @ ("title" | "body"), text)) => (Some(column), text),
_ => (None, token),
@@ -571,9 +575,22 @@ mod tests {
let title = prepare_cjk_fts5_query("title:支付服务").unwrap();
assert_eq!(title, "title:\"支付 付服 服务\"");
assert_parses(&title);
+ for query in ["(title:支付服务)", "((title:支付服务))"] {
+ let grouped = prepare_cjk_fts5_query(query).unwrap();
+ assert_eq!(grouped, title, "query={query}");
+ assert_parses(&grouped);
+ }
let body = prepare_cjk_fts5_query("body:支付服务").unwrap();
assert_eq!(body, "body:\"支付 付服 服务\"");
assert_parses(&body);
+ for query in ["(body:支付服务)", "((body:支付服务))"] {
+ let grouped = prepare_cjk_fts5_query(query).unwrap();
+ assert_eq!(grouped, body, "query={query}");
+ assert_parses(&grouped);
+ }
+ let alternatives = prepare_cjk_fts5_query("((title:支付服务) OR (body:支付服务))").unwrap();
+ assert_eq!(alternatives, format!("{title} OR {body}"));
+ assert_parses(&alternatives);
let single = prepare_cjk_fts5_query("title:支").unwrap();
assert_eq!(single, "title:\"支\"");
assert_parses(&single);
diff --git a/crates/ai-memory-store/tests/suite/cjk_search.rs b/crates/ai-memory-store/tests/suite/cjk_search.rs
index 452539f4..4ba10e83 100644
--- a/crates/ai-memory-store/tests/suite/cjk_search.rs
+++ b/crates/ai-memory-store/tests/suite/cjk_search.rs
@@ -293,7 +293,7 @@ async fn cjk_stream_does_not_fuse_back_a_not_excluded_term() {
}
#[tokio::test]
-async fn cjk_stream_honours_a_title_column_filter() {
+async fn cjk_stream_honours_column_filters() {
let tmp = tempfile::tempdir().unwrap();
let store = Store::open(tmp.path()).unwrap();
let (ws, project) = scope(&store, "default", "app").await;
@@ -321,9 +321,21 @@ async fn cjk_stream_honours_a_title_column_filter() {
.await
.unwrap();
- // Control: both pages carry 支付服务 in an unspaced run and both are
- // reachable through the CJK stream, so the narrowed search below failing
- // to return one of them means the column filter held.
+ store
+ .writer
+ .upsert_page(page(
+ ws,
+ project,
+ "支付服务.md",
+ "Path notes",
+ "English body",
+ ))
+ .await
+ .unwrap();
+
+ // Control: every column carries 支付服务 and all three pages are
+ // reachable through the CJK stream. Excluding a body/path-only match
+ // below therefore proves the column filter held.
let unqualified = store
.reader
.search_pages_for_project(ws, project, "支付服务".into(), 10, None)
@@ -339,20 +351,45 @@ async fn cjk_stream_honours_a_title_column_filter() {
"control search failed: {paths:?}"
);
- let titled = store
- .reader
- .search_pages_for_project(ws, project, "title:支付服务".into(), 10, None)
- .await
- .unwrap();
- let paths: Vec<_> = titled.iter().map(|hit| hit.path.as_str()).collect();
- assert!(
- paths.contains(&"titled.md"),
- "the title match lost its page: {paths:?}"
- );
assert!(
- !paths.contains(&"bodied.md"),
- "the CJK stream ignored the title filter: {paths:?}"
+ paths.contains(&"支付服务.md"),
+ "path control failed: {paths:?}"
);
+
+ for (query, expected) in [
+ ("title:支付服务", vec!["titled.md"]),
+ ("(title:支付服务)", vec!["titled.md"]),
+ ("((title:支付服务))", vec!["titled.md"]),
+ ("body:支付服务", vec!["bodied.md"]),
+ ("(body:支付服务)", vec!["bodied.md"]),
+ ("((body:支付服务))", vec!["bodied.md"]),
+ (
+ "(title:支付服务 OR body:支付服务)",
+ vec!["bodied.md", "titled.md"],
+ ),
+ (
+ "((title:支付服务) OR (body:支付服务))",
+ vec!["bodied.md", "titled.md"],
+ ),
+ ] {
+ let hits = store
+ .reader
+ .search_pages_for_project(ws, project, query.into(), 10, None)
+ .await
+ .unwrap();
+ let mut paths: Vec<_> = hits.iter().map(|hit| hit.path.as_str()).collect();
+ paths.sort_unstable();
+ assert_eq!(paths, expected, "project query={query}");
+
+ let hits = store
+ .reader
+ .search_pages_with_meta(query.into(), 10, None, None, Default::default())
+ .await
+ .unwrap();
+ let mut paths: Vec<_> = hits.iter().map(|hit| hit.path.as_str()).collect();
+ paths.sort_unstable();
+ assert_eq!(paths, expected, "global query={query}");
+ }
}
#[tokio::test]