/** * Structural write-time dedupe for the `facts` table: before a fact insert, * find an existing row with the same normalized text in the same * room + entity scope so `runtime.createMemory` can skip the write and return * the existing row's id — after folding any stronger metadata the new * occurrence carries (higher confidence, an explicit kind, a fresher validity * timestamp) into the kept row, so a dedupe hit never drops new information. * * This guard exists because nothing else structurally prevents duplicate fact * rows. The adapter-level similarity check requires an embedding (facts * writers have none inline — embeddings are backfilled asynchronously) and is * bypassed entirely when callers pass an explicit `unique` flag, and the * per-turn LLM dedupe pool is advisory (the model can and does miss). The * live failure this closes: one extraction turn persisted the same claim * twice, milliseconds apart — a fact row plus a relationship-echo row — and * the FACTS reader surfaced both. * * Equivalence is text + scope equality after canonicalization, not semantic * similarity: paraphrase-level dedupe stays with the LLM pool and the * reflection pass. The candidate pool is bounded to the same recent window * the FACTS provider reads, so the check degrades to a plain insert (never an * error) on rooms with very deep fact history. */ import type { Memory, MemoryMetadata } from "../types/memory.js"; import type { IAgentRuntime } from "../types/runtime.js"; /** * Returns the existing `facts` row equivalent to `memory` (same normalized * text, same room, same entity), or null when the write should proceed. Rows * sharing `memory.id` are ignored — same-id idempotence is the adapter's * contract, not a duplicate. */ export declare function findEquivalentFact(runtime: Pick, memory: Memory): Promise; /** * Field-wise "stronger metadata" merge for a dedupe hit: returns the kept * row's full metadata with the incoming occurrence's stronger fields applied, * or null when the incoming occurrence adds nothing (plain skip). Stronger * means, per field: * * - `confidence` — strictly higher (or present where the kept row has none). * - `kind` — present where the kept row has none. The FACTS reader defaults a * missing kind to `durable`, so an explicit stamp is always more precise; * an already-set kind is never flipped here (durable/current transitions * belong to the reflection pass). * - `validAt` / `lastConfirmedAt` — strictly more recent (or newly present): * a re-asserted `current` fact should not keep decaying from its first * observation's timestamp. */ export declare function mergeStrongerFactMetadata(existing: Memory, incoming: Memory): MemoryMetadata | null;