@sema-agent/core
Version:
Stateless, task-oriented AI agent core
21 lines (20 loc) • 1.73 kB
TypeScript
/**
* design/81 Slice 5 — the shared distance primitives memory search ranks on: one source of truth, so every
* backend scores on the same scale. A score is a cosine distance ∈ [0,2] (0 = identical); the lexical
* `1 - Jaccard ∈ [0,1] ⊂ [0,2]` is the same-zero-point stand-in used when no embedding vector is present
* (fail-open per row). The engine's File backend ranks on the lexical rung (`memory-engine/file-backend.ts`);
* a host backend with vectors scores with {@link cosineDistance} on dimension-matched vectors.
*/
/** Lower-cased lexical term set: alphanumeric runs PLUS CJK character bigrams (a single-character
* run contributes its unigram). CJK scripts have no `a-z0-9` runs at all, so an alphanumeric-only
* tokenizer made every pure-CJK entry an EMPTY set — never a lexical-rung candidate for any query
* — and a pure-CJK query returned nothing; character bigrams are the standard analyzer unit there
* (word boundaries are not written). Bigrams stay within one run: adjacency across an intervening
* non-CJK character is not real adjacency. */
export declare function termSet(s: string): Set<string>;
/** Lexical stand-in distance: `1 - Jaccard(terms)` ∈ [0,1] ⊂ [0,2]; `null` = no overlap (not a candidate). */
export declare function jaccardDistance(query: Set<string>, text: string): number | null;
/** Cosine distance ∈ [0,2] (0 = identical), the scale every memory search score is on. Uses
* `Math.min(a.length,b.length)` — a store MUST only call this on dimension-matched vectors (the row-level
* dimension guard lives at the caller; a mismatch falls open to {@link jaccardDistance}). */
export declare function cosineDistance(a: number[], b: number[]): number;