/** * Retrieval-overhaul Phase 6 (P6b) — deterministic cross-atom linking. * * Codex architecture review: "Relations currently must connect entities * appearing inside the same atom. That is too narrow for conversational * multi-hop evidence... After reduce, deterministically link atoms sharing * normalized entities, session proximity, possession/family relations, or * explicit event participants... Require provenance for every generated * edge." (docs/research/20260720-codex-architecture-reviews.md, "Add * cross-atom links; do not spend first on more extraction".) * * Runs on `ReducedAtom[]` — the output of stage 6 (`06-reduce.ts`), BEFORE * stage 8 assigns real memory ids. Candidates are keyed by `contentHash` * (the stable per-atom identity `reduce()` computes), not a memory id, since * no memory id exists yet at this point in the pipeline — mirrors how * `relations[]` itself rides through the pipeline as atom-shaped data and * is only resolved to real ids at stage 8 (see 08-embed-index.ts's * `entityIdByName` resolution). The caller (pipeline.ts) threads the * returned candidates to `embedAndIndex`, which resolves `contentHash -> * memoryId` once every atom in the batch has been inserted and writes the * final `memory_links` rows (migration 056). * * Deliberately deterministic-only (no LLM call) — this is the "populate the * graph" data-layer track, and the retrieval-overhaul plan's own local-first * rule for this phase is "rules plus local model; a strong offline * extractor is acceptable for extraction, but NO cloud dependency in * recall" (recall-path constraint; this module runs at INGEST time, not * recall time, and adds no network call either way). A narrow offline LLM * enrichment pass for atoms that share NO deterministic signal at all is * explicitly flagged as a follow-up in this module's own doc comment below, * not silently dropped. */ import type { ReducedAtom } from './stages/06-reduce.js'; export type AtomLinkType = 'shared_entity' | 'session_proximity' | 'possession_family' | 'event_participant'; export interface AtomLinkCandidate { contentHashA: string; contentHashB: string; linkType: AtomLinkType; /** Human-readable reason this link was generated (e.g. the shared entity * name, or "adjacent in extraction order") — provenance, never empty. */ evidence: string; confidence: number; } /** * Compute deterministic cross-atom link candidates for one pipeline run's * reduced atoms. Pure function — no DB access, no I/O; the caller resolves * `contentHash` to real memory ids and persists via `MemoryLinkRepo` * (src/storage/memory-links.ts). */ export declare function linkAtoms(atoms: ReducedAtom[]): AtomLinkCandidate[];