/** * Background embedding: the write-time embed of a new memory row (T5387) and * the bounded backfill of rows without a current vector (T13126). * * A one-shot process stores memory rows unembedded (see `brain-host.ts`). * This helper embeds a bounded batch of them, loading the model once for the * batch instead of once per observe. It runs from: * - the detached `cleo session end` worker, once per session; * - the sentient tick, in an opted-in long-lived host. * * It does nothing when no row is pending: the pending count is a plain * SQL read, so the model is never loaded for an empty backlog. It runs under * the governor's `background-autonomous` class, which grants a slot only when * memory pressure is `ok`. A deferral skips the batch, and the next session end * or tick retries. * * @module * @task T13126 */ /** Memory rows embedded per bounded batch unless the caller says otherwise. */ export declare const DEFAULT_EMBEDDING_BACKFILL_LIMIT = 50; /** Outcome of {@link runBoundedEmbeddingBackfill}. */ export interface BoundedEmbeddingBackfillResult { /** Whether a batch ran (the model was asked to embed). */ readonly ran: boolean; /** Why no batch ran, when {@link ran} is `false`. */ readonly skipped?: 'none-pending' | 'deferred' | 'unavailable'; /** Memory rows without a current vector found before the batch. */ readonly pending: number; /** Rows embedded by this batch. */ readonly processed: number; /** Rows that failed to embed in this batch. */ readonly errors: number; } /** Options for {@link runBoundedEmbeddingBackfill}. */ export interface BoundedEmbeddingBackfillOptions { /** * Maximum memory rows to embed, newest first. * @defaultValue {@link DEFAULT_EMBEDDING_BACKFILL_LIMIT} */ readonly limit?: number; } /** * SQL selecting every current memory row that needs a vector: observations, * decisions, learnings and patterns with no embedding, or one from a model * other than the bound `?` (T13740). Columns: `id`, `text`, `created_at`. * * The texts match what `searchSimilar` shows for each kind, so a hit is * judged on the text it was embedded from. * * @returns The SELECT, with one `?` parameter: the current model tag. * @task T13740 */ export declare function pendingEmbeddingsSql(): string; /** * Count current memory rows that have no embedding from the current model. * * A plain SQL read: registering the provider is free, and the model is never * loaded here. * * @param projectRoot - Project root directory. * @returns The pending count, or `0` when the brain store or its vector table * is unavailable. */ export declare function countUnembeddedMemories(projectRoot: string): Promise; /** * Embed a bounded batch of memory rows without a current vector, when any exist and the * governor admits background work. * * Never throws: the backfill is best-effort enrichment of rows that are already * stored and findable by BM25. * * @param projectRoot - Project root directory. * @param options - Batch bound. * @returns What ran and how many rows were embedded. * * @example * ```ts * const r = await runBoundedEmbeddingBackfill('/my/project', { limit: 50 }); * if (r.ran) console.log(`embedded ${r.processed} of ${r.pending}`); * ``` */ export declare function runBoundedEmbeddingBackfill(projectRoot: string, options?: BoundedEmbeddingBackfillOptions): Promise; /** * Embed one freshly written memory row in the background — long-lived hosts only. * * T13126: loading the local embedding model costs ~280 MB, and a one-shot * process paid it on every write for a single vector. A one-shot process * leaves the row unembedded; `populateEmbeddings` fills it later (an opted-in * host's tick, the `cleo session end` background batch, or `cleo backfill`). * Until then the row is found by BM25/FTS5 only. * * @param projectRoot - Project whose brain holds the row. * @param id - Row id (`O-…`, `D…`, `L-…`, `P-…`). * @param text - Text to embed. * @task T5387 * @task T13740 */ export declare function scheduleEmbedding(projectRoot: string, id: string, text: string): void; /** * Stop scheduling embeddings in this isolate and wait for the ones in flight * (T14069). The brain writer worker calls it before it is terminated: an * embedding loads `@huggingface/transformers` and its native onnxruntime addon, * and terminating the isolate mid-load or mid-inference can abort the WHOLE * process (`terminate called after throwing an instance of Napi::Error`). * * @returns Once every scheduled embedding has settled. * * @task T14069 */ export declare function drainScheduledEmbeddings(): Promise; //# sourceMappingURL=embedding-backfill.d.ts.map