memnite 0.2.1

Event-sourced memory engine for AI agents: append-only log, SQLite projections, staleness, conflict graph. CLI binary.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/// Turn arbitrary user text into a safe FTS5 query: split on whitespace AND
/// control characters (incl. NUL, which would otherwise truncate the bound C
/// string and produce an unterminated FTS5 literal), then wrap each token as an
/// FTS5 string literal (double-quoted, embedded `"` doubled). This neutralizes
/// FTS5 operators/columns/hyphens so plain text never errors.
///
/// `match_any=false` joins tokens with a space (FTS5 implicit AND, the default).
/// `match_any=true` joins them with ` OR ` to broaden recall. Blank input => "".
pub fn sanitize_fts(query: &str, match_any: bool) -> String {
    let sep = if match_any { " OR " } else { " " };
    query
        .split(|c: char| c.is_whitespace() || c.is_control())
        .filter(|tok| !tok.is_empty())
        .map(|tok| format!("\"{}\"", tok.replace('"', "\"\"")))
        .collect::<Vec<_>>()
        .join(sep)
}