import type { VecHit } from '../contracts/index.js'; /** * Thrown when the WORKER accepted a search but did not answer within * `searchTimeoutMs`. Distinct from every other failure in this file because it * is the one case where the synchronous fallback is known-harmful rather than * merely slow: the query has already proven it exceeds the budget, so running * it on the loop blocks for at least that long. See the file header. * * Exported so callers and tests can distinguish "vector search gave up" from * "the worker is broken" without string-matching a message. */ export declare class VecSearchTimeoutError extends Error { readonly timeoutMs: number; constructor(timeoutMs: number); } /** Structural subset of worker_threads.Worker used here — test seam. */ export interface VecWorkerLike { postMessage(value: unknown): void; on(event: 'message', listener: (msg: unknown) => void): this; on(event: 'error', listener: (err: Error) => void): this; on(event: 'exit', listener: (code: number) => void): this; terminate(): Promise | void; } export interface VecSearchHostOpts { dbPath: string; key?: string; /** Synchronous fallback used whenever the worker path fails. */ fallback: (vec: Float32Array, k: number) => Promise; /** Test seams. */ workerPath?: string; workerFactory?: (path: string, workerData: { dbPath: string; key?: string; }) => VecWorkerLike; spawnTimeoutMs?: number; searchTimeoutMs?: number; } export declare class VecSearchWorkerHost { private readonly opts; private readonly log; private worker; private readyPromise; private nextId; private terminating; private fallbacks; private searchTimeouts; private readonly pending; /** Serializes main-thread fallback scans. A worker crash rejects every * in-flight search at once; without this, N callers would each start a * full synchronous KNN scan back-to-back with no event-loop turns between * them — reproducing the loop-stacking pattern this class exists to * prevent, just crash-triggered. Chaining them lets queued HTTP work run * between scans. (Review MEDIUM on 3c9a81f2.) */ private fallbackChain; constructor(opts: VecSearchHostOpts); /** Total searches served by the sync fallback instead of the worker — * a rising number means the offload is not actually offloading. */ get fallbackCount(): number; /** Searches abandoned because the worker blew `searchTimeoutMs`. Counted * separately from `fallbackCount` because the two mean opposite things: a * fallback is the offload failing to offload, whereas a timeout is the * offload WORKING and the underlying query being too slow. A rising number * here means recall is silently degrading to FTS-only and the vec query * needs a performance fix — not that this class is misbehaving. */ get searchTimeoutCount(): number; search(vec: Float32Array, k: number): Promise; private ensureWorker; private searchOnWorker; private failAll; private teardown; stop(): Promise; }