/** * Memory consolidation window (Phase 1, P1-CONSOLIDATE, borrowed from * ai-memory ConsolidatedBatch). * * Two-stage: * 1. Rule-based prefilter: cluster a candidate set by `project_id` and * pairwise embedding cosine >= 0.65, bounding the window to top-N (8) * most recent. No LLM. Returns null if no cluster of >= 2 exists. * 2. LLM merge: produce a `ConsolidatedBatch` via `generateObject` + a zod * schema enforcing type/level enums. Returns null if the LLM is disabled * or fails (caller's rule-based path proceeds). * * Pure over its inputs + the injected `llm` handle — no DB, no global state. */ import { z } from "zod"; import type { MemoryRow } from "../../data/memory/memory-repository.js"; /** Tunable prefilter constants. */ export declare const CONSOLIDATE_COSINE_THRESHOLD = 0.65; export declare const CONSOLIDATE_MAX_WINDOW = 8; declare const MEMORY_TYPE_VALUES: readonly ["critical", "conversation", "code", "decision", "pattern"]; declare const MEMORY_LEVEL_VALUES: readonly [0, 1, 2, 3, 4]; /** Zod schema enforcing type/level enums — rejects malformed LLM output. */ export declare const ConsolidatedBatchSchema: z.ZodObject<{ summary: z.ZodString; type: z.ZodEnum<{ code: "code"; pattern: "pattern"; decision: "decision"; critical: "critical"; conversation: "conversation"; }>; level: z.ZodUnion, z.ZodLiteral<1>, z.ZodLiteral<2>, z.ZodLiteral<3>, z.ZodLiteral<4>]>; rationale: z.ZodString; sourceIds: z.ZodArray; }, z.core.$strip>; export type ConsolidatedBatchInput = z.infer; export interface ConsolidatedBatch { id: string; sourceIds: string[]; summary: string; type: (typeof MEMORY_TYPE_VALUES)[number]; level: (typeof MEMORY_LEVEL_VALUES)[number]; rationale: string; } /** Candidate memory shape needed by the prefilter. */ export interface ConsolidateCandidate { id: string; projectId?: string | null; importance: number; /** Embedding as stored: Buffer/Uint8Array (DB BLOB), Float32Array, or number[]. */ embedding?: Buffer | Uint8Array | number[] | Float32Array | null; createdAt?: number; } /** Injectable LLM surface (matches the `llm` export from llm-client.ts). */ export interface LlmSurface { object(prompt: string, schema: z.ZodSchema, opts?: { timeoutMs?: number; modelRole?: "instruct" | "code"; }): Promise<{ ok: boolean; value?: T; error?: string; }>; isEnabled(): boolean; } export declare function cosineSimilarity(a: number[], b: number[]): number; /** * Prefilter: pick the best cluster of >= 2 near-duplicate memories. * Returns the window (source candidates) or null if none qualifies. */ export declare function pickConsolidationWindow(candidates: ConsolidateCandidate[], opts?: { threshold?: number; maxWindow?: number; }): ConsolidateCandidate[] | null; /** * Run the full two-stage consolidation over a candidate set. Returns a * ConsolidatedBatch on success, or null when: * - no qualifying cluster exists (prefilter), * - the LLM is disabled, * - the LLM fails or returns an invalid object. * * `idFactory` is injected so callers/tests can control the batch id. */ export declare function consolidateWindow(candidates: ConsolidateCandidate[], llm: LlmSurface, opts?: { threshold?: number; maxWindow?: number; idFactory?: () => string; }): Promise; /** Convenience: convert MemoryRow[] to candidates (embedding preserved as Buffer). */ export declare function rowsToCandidates(rows: MemoryRow[]): ConsolidateCandidate[]; export {}; //# sourceMappingURL=consolidator.d.ts.map