/** * local-memory-ranking.ts * * Backend-neutral memory ranking layer for Coppermind. * * Extracts the canonical scoring/sorting logic from the SurrealDB backend * assumptions so it can run on SurrealDB (and any future backend) without * modification. * * Scoring formula (per entry): * score = (retrievalPriority×50 + lexicalWeight×25 + recencyScore + importance×100) * × (isAuthoritative ? 5 : 1) * * - retrievalPriority: integer 0+, pre-ranked hot-set hint * - lexicalWeight: token overlap between query and content+tags+metadata JSON * - recencyScore: 50/(1 + ageHours/24) — recency decay over 24h half-life * - importance: 0–1, weighted ×100 * - isAuthoritative: memoryType ∈ {goal, fact, stable_profile_detail, preference} * * Hard constraint: a record that supersedes another must not rank below it. */ import type { CachedMemoryEntry } from "./types.js"; import type { LocalMemoryFragment } from "./local-memory.js"; /** * Memory types that represent authoritative ground truth. * These records get a 5× score multiplier so they outrank non-authoritative * records even when they have lower lexical overlap or retrieval priority. */ export declare const AUTHORITATIVE_MEMORY_TYPES: Set; export declare const SCORING_WEIGHTS: Readonly<{ readonly retrievalPriority: 50; readonly lexical: 25; readonly recencyMax: 50; readonly importanceMax: 100; readonly authoritativeMultiplier: 5; readonly authoritativeBoost: 60; readonly transcriptNoisePenalty: 0.12; }>; export declare function tokenize(text: string): Set; export declare function overlapScore(queryTokens: Set, text: string): number; export declare function recencyScore(updatedAt: string): number; /** * Sort entries by relevance score, then apply the supersession hard * constraint (superseding records must rank above the records they supersede). * * Returns sorted array with scores — caller applies limit and converts to * LocalMemoryFragment. */ export declare function sortEntries(entries: CachedMemoryEntry[], query: string): Array<{ entry: CachedMemoryEntry; score: number; }>; /** * Rank LocalMemoryFragments by relevance score. * Converts fragments to CachedMemoryEntry (normalizing metadata fields), * calls sortEntries, then converts back to fragments with scores attached. */ export declare function rankLocalMemoryFragments(fragments: LocalMemoryFragment[], query: string): Array<{ fragment: LocalMemoryFragment; score: number; }>; //# sourceMappingURL=local-memory-ranking.d.ts.map