Skip to content

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

Rust

fix(store): keep a known column filter whose term holds a second colon

Rudy Celeklia17dd2bcff27
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 91cde92d..4902a50e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -223,6 +223,12 @@ version in [`docs/changelog/`](docs/changelog/):
relay and wiki sync companions take the same `rustls-webpki` bump.
### Fixed
+- A `title:` or `body:` search filter whose term carries a second colon, such
+ as `title:10:30`, now keeps its column. FTS5 read the inner `10` as a column
+ name and rejected the whole expression, so the query degraded to the quoted
+ bag of words: the filter was dropped and every column was searched for the
+ literal word `title`.
+ ([#1521](https://github.com/akitaonrails/ai-memory/pull/1521))
- Reserved local-embedding capacity for interactive search queries instead of
allowing concurrent page writes and backfill work to occupy every inference
slot. Excess queries fall back immediately to non-vector retrieval, and a
diff --git a/crates/ai-memory-store/src/fts_query.rs b/crates/ai-memory-store/src/fts_query.rs
index c035f7f6..b7b675c9 100644
--- a/crates/ai-memory-store/src/fts_query.rs
+++ b/crates/ai-memory-store/src/fts_query.rs
@@ -382,11 +382,15 @@ fn prepare_fts5_token(token: &str) -> Vec<String> {
// A known column filter keeps its column when its term needs quoting:
// `title:ai-memory` becomes `title:("ai-memory" OR "ai memory")`, not a
// quoted phrase that also searches for the literal word `title`.
+ // A second colon in the term (`title:10:30`) needs that same quoting:
+ // left bare, FTS5 reads the inner `10` as a column name and rejects the
+ // whole expression, so the query degrades to the bag of words — which
+ // drops the filter and searches every column for the word `title`.
if !token.contains('"')
&& let Some((column, term)) = token.split_once(':')
&& matches!(column, "title" | "body")
&& !term.is_empty()
- && should_quote_fts5_token(term)
+ && (should_quote_fts5_token(term) || term.contains(':'))
{
return vec![format!("{column}:{}", quote_fts5_token(term))];
}
@@ -839,6 +843,21 @@ mod tests {
}
}
+ /// A second colon inside a known column's term must not defeat the
+ /// filter. FTS5 reads the inner `10` as a column name and rejects the
+ /// expression, so the whole query degrades to the quoted bag of words:
+ /// that drops the column filter and searches every column for the
+ /// literal word "title", the outcome
+ /// `known_column_filter_survives_quoting_of_its_term` exists to prevent.
+ #[test]
+ fn known_column_filter_survives_a_second_colon_in_its_term() {
+ assert_eq!(
+ prepare_fts5_query("title:10:30"),
+ r#"title:("10:30" OR "10 30")"#
+ );
+ assert_parses(&prepare_fts5_query("title:10:30"));
+ }
+
/// A column filter inside a group keeps its column: the paren attached
/// to `title:` must not turn it into an unknown column whose name is
/// then searched as the literal word "title".