/** * memory_links repo (retrieval-overhaul Phase 6 / P6b, migration 056) — * deterministic atom-to-atom (memory-to-memory) links. See * src/distill/link-atoms.ts for how candidates are computed and * migrations/056-memory-links.sql for the schema rationale, including why * this is a SEPARATE table from `entity_relations` (src/storage/ * entity-relations.ts) rather than a new predicate on it. */ import type { DB } from './db.js'; import type { AtomLinkType } from '../distill/link-atoms.js'; export interface MemoryLinkInput { memoryIdA: string; memoryIdB: string; linkType: AtomLinkType; evidence: string; confidence?: number; } export interface MemoryLinkRow { id: string; memory_id_a: string; memory_id_b: string; link_type: AtomLinkType; evidence: string; confidence: number; created_at: number; } export interface MemoryLinkInsertResult { id: string; /** False when the (memory_id_a, memory_id_b, link_type) triple already * existed (canonical order, see below) and the atomic dedup guard * skipped the write. */ inserted: boolean; } export declare class MemoryLinkRepo { private db; constructor(db: DB); /** * Insert-with-dedup-guard, same atomic `INSERT...SELECT...WHERE NOT * EXISTS` shape `EntityRelationRepo.insert()` uses (src/storage/ * entity-relations.ts) — a single prepared statement, no separate * SELECT-then-INSERT round trip, closing the same TOCTOU race under * SQLite's single-writer lock. * * `memoryIdA`/`memoryIdB` are canonicalized to (min, max) by plain string * comparison BEFORE the write — the caller (08-embed-index.ts) does not * need to know or preserve any particular order when resolving link-atoms * candidates to real memory ids; a link is inherently symmetric. */ insert(input: MemoryLinkInput): MemoryLinkInsertResult; /** Every link row touching `memoryId`, in either position. */ getForMemory(memoryId: string, limit?: number): MemoryLinkRow[]; }