Skip to content

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

Rust

fix(store): keep the Japanese iteration mark inside a CJK run

Rudy Mizrahi Celekli2e7ff4ef809b
diff --git a/crates/ai-memory-store/src/fts_query.rs b/crates/ai-memory-store/src/fts_query.rs
index b7b675c9..a2be1d42 100644
--- a/crates/ai-memory-store/src/fts_query.rs
+++ b/crates/ai-memory-store/src/fts_query.rs
@@ -281,6 +281,16 @@ fn is_cjk(ch: char) -> bool {
ch as u32,
0x1100..=0x11ff
| 0x2e80..=0x2fff
+ // CJK Symbols and Punctuation holds a handful of LETTERS among its
+ // punctuation: the iteration marks 々 〆 〻 and the kana repeat
+ // marks. 々 is how 日々, 時々, 人々, 我々 and 様々 are written, so
+ // excluding the block split those words into single scalars on both
+ // the index and the query side, leaving the character-only match
+ // the bigrams exist to prevent. The `is_alphanumeric` guard above
+ // keeps the block's actual punctuation (、 。 「) out.
+ | 0x3005..=0x3006
+ | 0x3031..=0x3035
+ | 0x303b
| 0x3040..=0x30ff
| 0x3130..=0x318f
| 0x31f0..=0x31ff
@@ -489,6 +499,15 @@ mod tests {
"日 本 語 日本 本語 テ ス ト テス スト"
);
assert_eq!(cjk_index_terms("plain latin"), "");
+ // The iteration mark is a letter in CJK Symbols and Punctuation and
+ // must continue a run, or 日々 is indexed as two one-char runs and is
+ // unfindable as a unit.
+ assert_eq!(
+ cjk_index_terms("日々の作業"),
+ "日 々 の 作 業 日々 々の の作 作業"
+ );
+ // Control: the punctuation sharing that block still breaks a run.
+ assert_eq!(cjk_index_terms("日、本"), "日 本");
}
#[test]
@@ -504,6 +523,19 @@ mod tests {
assert_eq!(prepare_cjk_fts5_query("latin only"), None);
}
+ #[test]
+ fn cjk_queries_keep_the_japanese_iteration_mark() {
+ let query = prepare_cjk_fts5_query("日々").unwrap();
+ assert_eq!(query, "\"日々\"");
+ assert_parses(&query);
+ // Control: the same block's punctuation still separates two runs,
+ // so this is a widened letter range and not a widened block.
+ assert_eq!(
+ prepare_cjk_fts5_query("日、本"),
+ Some("\"日\" OR \"本\"".to_string())
+ );
+ }
+
#[test]
fn cjk_query_input_is_bounded_before_expansion() {
let query = prepare_cjk_fts5_query(&"日".repeat(10_000)).unwrap();
diff --git a/crates/ai-memory-store/tests/suite/cjk_search.rs b/crates/ai-memory-store/tests/suite/cjk_search.rs
index 90d2db7e..be483e2a 100644
--- a/crates/ai-memory-store/tests/suite/cjk_search.rs
+++ b/crates/ai-memory-store/tests/suite/cjk_search.rs
@@ -236,3 +236,61 @@ async fn superseded_cjk_text_is_hidden_and_startup_repairs_missing_index_rows()
assert_eq!(after_rebuild.len(), 1);
assert_eq!(after_rebuild[0].path.as_str(), "repair.md");
}
+
+#[tokio::test]
+async fn cjk_search_finds_a_word_written_with_the_iteration_mark() {
+ let tmp = tempfile::tempdir().unwrap();
+ let store = Store::open(tmp.path()).unwrap();
+ let (ws, project) = scope(&store, "default", "app").await;
+
+ store
+ .writer
+ .upsert_page(page(
+ ws,
+ project,
+ "daily.md",
+ "運用",
+ "日々の作業ログを残す。",
+ ))
+ .await
+ .unwrap();
+ store
+ .writer
+ .upsert_page(page(
+ ws,
+ project,
+ "country.md",
+ "概要",
+ "日本の明日の予定。",
+ ))
+ .await
+ .unwrap();
+
+ // Control: the decoy IS indexed and IS findable on its own terms, so its
+ // absence below means 日々 matched as a unit rather than nothing matching.
+ let decoy = store
+ .reader
+ .search_pages_for_project(ws, project, "日本".into(), 10, None)
+ .await
+ .unwrap();
+ let paths: Vec<_> = decoy.iter().map(|hit| hit.path.as_str()).collect();
+ assert!(
+ paths.contains(&"country.md"),
+ "control search failed: {paths:?}"
+ );
+
+ let iterated = store
+ .reader
+ .search_pages_for_project(ws, project, "日々".into(), 10, None)
+ .await
+ .unwrap();
+ let paths: Vec<_> = iterated.iter().map(|hit| hit.path.as_str()).collect();
+ assert!(
+ paths.contains(&"daily.md"),
+ "日々 was not findable as a unit: {paths:?}"
+ );
+ assert!(
+ !paths.contains(&"country.md"),
+ "日々 degraded to a bare 日 character match: {paths:?}"
+ );
+}