/** * Content-hash embedding cache (FEAT-492) — decorator over an inner * `EmbedProvider`, ported from cloud's `CachingEmbeddingProvider.cs` * pattern. Local flavor: plain SQLite table (migration 043, * src/storage/embed-cache.ts) instead of an external cache dependency — * Ollama's cost here is wall-clock time on the user's own machine, not * money, but re-embedding unchanged content on every distill/reembed run is * still pure waste. * * DOCUMENT-ROLE ONLY — do not wrap the shared `providers.embed` instance * that `src/search/search.ts`, the MCP/HTTP search routes, and the doctor * embed probe all read from. Wire this ONLY at the call sites that embed * content for storage (src/pipeline/handlers/distill.ts, * distill-events.ts's embedAndIndex, and reembed.ts) — see * src/cli/serve.ts's `extCtx.providers` construction, which builds a * SEPARATE `{ ...providers, embed: cachedEmbed }` object for the worker * context while `providers.embed` (raw, uncached) keeps flowing to * `buildApp` (query-role search routes) and the health-check probes * unchanged. * * Why the split instead of caching at the shared provider (arch review * 2026-07-14): `resolveEmbedQueryPrefix` (src/contracts/embed.ts) resolves * the query-side instruction prefix ONCE at provider-construction time * (src/providers/index.ts's buildEmbedProvider), but the prefix itself is * only ever *applied* to the text handed to `embed()` at exactly one call * site — search.ts's vector-embed call. A query embed is (a) never repeated * verbatim across requests, so caching it buys nothing, and (b) if it WERE * cached through the same table as document embeds, a document whose text * happened to start with the literal prefix string would collide with a * query cache entry — an unnecessary correctness dimension for zero * measured benefit. Scoping the wrapper to document call sites only avoids * both problems by construction, no prefix-sniffing required. */ import type { EmbedHealth, EmbedProvider } from '../../contracts/embed.js'; import type { DB } from '../../storage/db.js'; export interface CachingEmbedProviderOpts { maxEntries?: number; } export declare class CachingEmbedProvider implements EmbedProvider { readonly name: EmbedProvider['name']; readonly model: string; readonly dim: number; readonly queryPrefix?: string; private readonly inner; private readonly db; private readonly maxEntries; constructor(inner: EmbedProvider, db: DB, opts?: CachingEmbedProviderOpts); embed(texts: string[], signal?: AbortSignal): Promise; health(): Promise; }