/** * CoRetrievalHook — Hebbian co-retrieval reinforcement * * When two session memories are stored in the same search session, they * co-occur semantically. This hook creates or strengthens a RELATES_TO * edge between them in the GraphStore, making those memories surface * together in future neighborhood queries (optimized_context). * * Architecture decisions vs. the original spec: * - Uses GraphStore (PostgreSQL) not Prisma — edges already live there. * - Uses MemoryRelationType.RELATES_TO — no new edge type/migration. * - Weights in [0, 1] — consistent with GraphStore design. * - Only the "retrieved" signal — richer signals (used_in_answer, * task_succeeded) have no emitter in the current system. * - No decay job — out of scope for MVP; edges are bounded by the * saturation cap instead. * - Opt-in via MASSA_TH0TH_CO_RETRIEVAL_HOOK=true — safe rollout. * * Timing: * SearchSessionHook stores Memory(B), then emits "memory:session-stored". * At that point Memory(B) is already in the DB. This hook receives the * event, queries recent session memories → finds Memory(A), links A↔B. */ import { MemoryRelationType } from "@massa-th0th/shared"; import type { MemoryRepositoryPg } from "../../data/memory/memory-repository-pg.js"; /** * Subset of `IGraphStore` used by CoRetrievalHook — injectable for testing. * All methods are async to match the backend-agnostic `IGraphStore` contract * (structural gap #14). */ export interface IGraphStoreEdges { getEdge(sourceId: string, targetId: string, relationType: MemoryRelationType): Promise; createEdge(edge: { sourceId: string; targetId: string; relationType: MemoryRelationType; weight?: number; evidence?: string; autoExtracted?: boolean; }): Promise; incrementEdgeWeight(sourceId: string, targetId: string, relationType: MemoryRelationType, delta: number, maxWeight?: number): Promise; } export declare class CoRetrievalHook { private static instance; private unsubscribe; private readonly graphStore; private constructor(); static getInstance(): CoRetrievalHook; /** Create an isolated instance with injected dependencies — for testing only. */ static createForTest(graphStore: IGraphStoreEdges, repo?: { findRecentByTag: MemoryRepositoryPg["findRecentByTag"]; }): CoRetrievalHook; /** Register the hook. Safe to call multiple times — only registers once. */ register(): void; /** Unregister the hook (useful in tests). */ unregisterHook(): void; /** Reset singleton (test utility). */ static reset(): void; private handleMemoryStored; private findPeers; } export declare const coRetrievalHook: CoRetrievalHook; //# sourceMappingURL=co-retrieval-hook.d.ts.map