import { type SharedWorkerLaunch } from "../subprocess/shared-worker.js"; import { type RefCountedWorkerHandle, type SpawnedSubprocess } from "../subprocess/worker-client.js"; import { type MnemopiEmbedCall, type MnemopiEmbedModelId, type MnemopiEmbedServerResponse, type MnemopiEmbedWorkerOutbound } from "./embed-protocol.js"; /** * Transport a {@link MnemopiEmbedClient} drives: in an omp process, the * connection to the machine-shared embedding server for one (model, cache * dir); inside that server, the IPC channel to its private onnxruntime child. */ export type MnemopiEmbedWorkerHandle = RefCountedWorkerHandle; /** * Hidden subcommand on the main CLI that boots the onnxruntime child of the * shared embedding server. Kept in sync with the dispatch in `cli.ts`. */ export declare const MNEMOPI_EMBED_WORKER_ARG = "__omp_worker_mnemopi_embed"; /** * Spawn the onnxruntime embeddings child. Exported for tests and the smoke * probe; the shared server goes through {@link spawnMnemopiEmbedWorker}. The * child inherits the server env — fastembed honours `HF_HUB_*`, * `HTTPS_PROXY`, etc., and `loadFastembed()` reads the same `OMP_*` * runtime-install knobs. */ export declare function createMnemopiEmbedSubprocess(): SpawnedSubprocess; /** Spawn the shared server's onnxruntime child (or an unavailable stand-in when spawning throws). */ export declare function spawnMnemopiEmbedWorker(): MnemopiEmbedWorkerHandle; /** Shared-server name for one (model, cache dir): the model id plus a hash of the resolved cache dir. */ export declare function mnemopiEmbedServerName(model: MnemopiEmbedModelId, cacheDir: string): string; /** How to start the shared embedding server for `model`; `env` overlays the inherited environment. @internal */ export declare function mnemopiEmbedLaunch(model: MnemopiEmbedModelId, env?: Record): SharedWorkerLaunch; /** * Per-model wrapper produced by {@link MnemopiEmbedClient.initialize}. * `embed()` round-trips one batch of texts and yields the resulting vectors in * a single asynchronous batch — fastembed's own iterator was emitting batches * that the child collects anyway, and per-batch round-trips would not improve * throughput. */ export interface MnemopiSubprocessEmbeddingModel { embed(texts: string[], batchSize?: number): AsyncIterable; } /** * Correlates `init`/`embed` calls over one transport per (model, cache dir). * Transport-agnostic: omp processes run it over shared-server connections * ({@link mnemopiEmbedClient}); the shared server runs it over its private * onnxruntime child. */ export declare class MnemopiEmbedClient { #private; constructor(connect?: (model: MnemopiEmbedModelId, cacheDir: string | undefined) => MnemopiEmbedWorkerHandle, requestTimeoutMs?: number); /** * Load the named fastembed model, tracking a first-use download in the * download HUD. Resolves to a thin wrapper whose `embed()` round-trips * through the same transport, or `null` when the model cannot be loaded * (missing peer, native load failure, unreachable server, etc.). */ initialize(model: MnemopiEmbedModelId, cacheDir: string | undefined): Promise; /** Load the model on its transport; resolves `undefined` once ready, else the failure text. Not bounded by the request timeout. */ load(model: MnemopiEmbedModelId, cacheDir: string | undefined): Promise; /** Embed `texts` with the model, bounded by {@link EMBED_REQUEST_TIMEOUT_MS}; rejects on worker error or timeout. */ embed(model: MnemopiEmbedModelId, cacheDir: string | undefined, texts: string[], batchSize: number | undefined): Promise; /** Drop every transport and fail everything in flight. */ terminate(): Promise; } /** This process's embedding client; every (model, cache dir) goes through its machine-shared server. */ export declare const mnemopiEmbedClient: MnemopiEmbedClient; /** Drop this process's server connections; the servers keep serving other omp processes until idle. */ export declare function shutdownMnemopiEmbedClient(): Promise; /** Distribution smoke test: the onnxruntime child ping/pongs over IPC, and the shared server answers its tagged ping. */ export declare function smokeTestMnemopiEmbedWorker({ timeoutMs, }?: { timeoutMs?: number; }): Promise;