/** * FEAT-507 — shared oversize-atom constants/helpers. * * `reembed` jobs were poisoning at a steady rate in production (~16/hr, * observed 2026-07-15): every failure was `Ollama embed failed: HTTP 500 — * {"error":"the input length exceeds the context length"}` after 3 retry * attempts. The content exceeds the embed model's context window, so the * failure is deterministic — retrying is pure waste, and the memory * permanently poisons instead of ever getting an embedding. * * This module is the single source of truth for "oversize" — both * `handlers/reembed.ts` (truncate-before-embed + reclassify) and * `oversize-scanner.ts` (find already-poisoned candidates) import from here * rather than each carrying its own threshold, per FEAT-507's requirement * that "oversize" be defined from one explicit, named constant. */ /** * The character budget `reembedHandler` truncates to before calling the * embed provider, and the threshold `oversize-scanner.ts` uses to find * already-poisoned candidates. 85% margin below the hard token ceiling — the * chars/4 estimate is rough, and truncating a little early is cheap; a * repeat "context length exceeded" 500 after "fixing" it is not. */ export declare const EMBED_MAX_INPUT_CHARS: number; /** True when `text` would exceed the embed context budget unmodified. */ export declare function isOversizeText(text: string): boolean; /** * Truncate to the embed budget. This is the "cheap default" FEAT-507 AC-1 * calls for — chunk-and-average was considered and explicitly deferred * pending retrieval-quality evidence (see FEAT-507 spec notes); a truncated * embedding beats a poisoned job with none. */ export declare function truncateForEmbedding(text: string): { text: string; truncated: boolean; }; /** * FEAT-507 AC-2: Ollama's embed endpoint returns a 500 with this exact * message shape when input exceeds the model's context window — matches the * observed production error verbatim ("the input length exceeds the context * length"). `OllamaEmbedProvider` (src/providers/embed/ollama.ts — out of * this slice's scope, owned by the ONNX-provider slice) classifies every * >=500 as `TransientError`, which is correct for a genuinely transient 500 * but wrong for this deterministic one: no retry will ever make an oversize * input smaller. `reembedHandler` uses this to reclassify the failure * BEFORE it reaches the worker's retry router (`failure-classifier.ts`), * rather than editing the provider's own classification. */ export declare function isContextLengthExceededError(err: unknown): boolean; /** * Wraps a single-text embed call so a deterministic context-length overflow * (see `isContextLengthExceededError`) is reclassified as `DeterministicError` * before it reaches the worker — every other failure (network, 429, a * genuinely transient 500) passes through unchanged. */ export declare function embedWithOversizeGuard(text: string, embed: { embed(texts: string[]): Promise; }, memoryId: string, originalLength: number): Promise;