/** * MemoryConsolidator — ADR-125 Phase 4 * * Periodic maintenance for the in-memory state owned by {@link UnifiedMemoryService}. * * Operations: * - `sweepExpired()` — drop entries past `expiresAt` from all indexes (including HNSW). * - `dedup(strategy)` — collapse content-hash duplicates per strategy. * - `compactHnsw()` — rebuild the HNSW index from current `entries`. * - `runAll()` — sweep → dedup → compact in order. * * Invoked from two paths: * 1. {@link UnifiedMemoryService}'s lifecycle (background timer when * `consolidator.autoRun === true`, plus `close()`). * 2. The AgentDB `nightlyLearner` controller (`src/controller-registry.ts`) * delegates to `runAll()` instead of hitting AgentDB directly. * * Phase 3 placeholder lives in this file too — it provides the typed * surface that {@link UnifiedMemoryService.getConsolidator} resolves to. * The real implementation lands with Phase 4. * * @module v3/memory/consolidator */ import type { MemoryEntry } from './types.js'; /** * Strategy for resolving content-hash duplicates inside {@link MemoryConsolidator.dedup}. */ export type DedupStrategy = 'keep-newest' | 'keep-oldest' | 'merge-tags'; export interface ConsolidatorOptions { /** Default strategy when `dedup()` is invoked with no argument. */ dedupStrategy?: DedupStrategy; /** Used by `MemoryService` when scheduling automatic runs (ms). */ intervalMs?: number; } export interface SweepResult { removed: number; remaining: number; hnswRemoved: number; } export interface DedupResult { merged: number; groups: number; } export interface CompactResult { before: number; after: number; durationMs: number; } export interface ConsolidationResult { sweep: SweepResult; dedup: DedupResult; compact: CompactResult; totalDurationMs: number; } /** * Minimal surface the consolidator needs from `UnifiedMemoryService`. Avoids * a circular type import. */ interface ServiceLike { getAdapter(): { entries: Map; namespaceIndex: Map>; keyIndex: Map; tagIndex: Map>; [key: string]: any; }; } export declare class MemoryConsolidator { private readonly service; private readonly opts; constructor(service: ServiceLike, opts?: ConsolidatorOptions); /** * Drop all entries whose `expiresAt` is in the past. */ sweepExpired(): Promise; /** * Collapse content-hash duplicates across all namespaces per `strategy`. * * - `keep-newest`: keep the entry with the highest `updatedAt`, drop the rest. * - `keep-oldest`: keep the entry with the lowest `createdAt`, drop the rest. * - `merge-tags`: keep newest, but union the tag sets of the duplicates first. */ dedup(strategy?: DedupStrategy): Promise; /** * Rebuild the HNSW index from the current set of entries with embeddings. * Returns a count snapshot + duration. */ compactHnsw(): Promise; /** * Sweep → dedup → compact. Used by the background timer and by the * `nightlyLearner` AgentDB controller. */ runAll(): Promise; } export default MemoryConsolidator; //# sourceMappingURL=consolidator.d.ts.map