/** * Character-trigram text utilities for observational memory. * * Shared by the storage layer for: * - building FTS5 MATCH queries against the trigram-tokenized index * (`buildFtsMatchQuery`), * - typo-tolerant search fallback (`bestTokenTrigramJaccard`), * - write-time near-duplicate detection (`trigramJaccard`). * * Pure functions with no SQLite dependency so the logic is unit-testable * in isolation. */ /** * Minimum token length the SQLite trigram tokenizer can match. Tokens * shorter than this cannot be satisfied by an FTS5 MATCH query and must be * handled with complementary LIKE filtering (or the LIKE-only search path). */ export declare const MIN_TRIGRAM_TOKEN_LENGTH = 3; /** * Per-token floor for {@link bestTokenTrigramJaccard}: every trigram-matchable * query token must reach this Jaccard similarity against some content token, * otherwise the content is considered not to match the query at all. This * mirrors the AND semantics of the FTS MATCH path — every term must be * (approximately) present — while still tolerating typos. */ export declare const TYPO_FALLBACK_MIN_TOKEN_SIMILARITY = 0.2; /** Normalize text for trigram comparison: lowercase and collapse whitespace. */ export declare function normalizeForTrigrams(text: string): string; /** * Build the set of character trigrams of `text`. * * Strings shorter than one trigram collapse to a single pseudo-token so * identical short strings still compare equal (Jaccard 1.0). Empty input * yields an empty set. */ export declare function trigramSet(text: string): Set; /** * Jaccard similarity between the character-trigram sets of two strings, * in [0, 1]. Returns 0 when either side has no trigrams. */ export declare function trigramJaccard(a: string, b: string): number; /** * Typo-tolerant similarity between a whole query and a piece of content: * the mean, over query tokens, of the best Jaccard similarity between that * token and any single content token. * * Comparing token-to-token (instead of query-to-full-content) keeps the * score robust to sentence length — a one-word typo in a long observation * would otherwise be diluted below any useful threshold. * * Only `queryTokens` of trigram-matchable length are scored; shorter tokens * are ignored so they do not drag the mean down for matches they can never * express. Returns 0 — no match — when any such token fails to reach * TYPO_FALLBACK_MIN_TOKEN_SIMILARITY against every content token (the token * is absent, mirroring the AND semantics of the FTS path), or when no query * token qualifies. */ export declare function bestTokenTrigramJaccard(queryTokens: string[], content: string): number; /** * Build an FTS5 MATCH query from search tokens. * * Each token becomes a quoted phrase (`"token"`); phrases are joined with * AND. With the trigram tokenizer each quoted phrase acts as a * case-insensitive substring match, so a multi-token query matches content * containing all tokens anywhere. Embedded double quotes are escaped by * doubling, which is how FTS5 string literals represent a literal quote. * * Returns an empty string when no non-empty tokens are supplied — callers * must guard against that before running a MATCH query. */ export declare function buildFtsMatchQuery(tokens: string[]): string; //# sourceMappingURL=trigrams.d.ts.map