/** * transformers.js (ONNX, dual-environment) Embeddings adapter battery. * * @module @nhtio/adk/batteries/embeddings/transformers_js/adapter * * @remarks * Embeddings battery backed by transformers.js's `feature-extraction` pipeline. **Environment-neutral** * — runs in Node (via `onnxruntime-node`) and the browser (via `onnxruntime-web` / WebGPU), auto- * selected by the package; there is no WebGPU requirement, so this battery is surfaced from the * environment-neutral `@nhtio/adk/batteries/embeddings` barrel alongside the OpenAI one. * * Same user-facing surface as the OpenAI / WebLLM embeddings batteries (`isAvailable` / `dimensions` / * `preload` / `reset` / `embed` / `embedMany`), same `number[]` return shape, same query/document * prefix handling (the shared `applyEmbeddingPrefix`). * * `@huggingface/transformers` is an optional peer dependency, imported lazily. * * **Cross-runtime vector caveat:** embeddings produced here are not guaranteed bit-identical to those * from a different runtime (WebLLM/MLC, or even node-ONNX vs web-ONNX for the same model). A vector * corpus must be embedded AND queried by one backend. */ import type { EmbedOptions } from "../openai/types"; /** * Embeddings adapter for transformers.js's feature-extraction pipeline. * * @remarks * Reusable: construct once, call {@link TransformersJsEmbeddingsAdapter.embed} / {@link embedMany} as * many times as needed. The pipeline is resolved lazily on first use (or via {@link preload}) and * cached with single-flight semantics so concurrent calls share one load. */ export declare class TransformersJsEmbeddingsAdapter { #private; /** * Whether this battery is available. transformers.js is environment-neutral (Node + browser), so * this is `true` whenever the runtime can import the peer — there is no WebGPU requirement. */ static isAvailable(): boolean; /** * @param options - Constructor options. Validated eagerly. * @throws {@link @nhtio/adk/batteries!E_INVALID_TRANSFORMERS_JS_EMBEDDINGS_OPTIONS} when invalid. */ constructor(options: unknown); /** Declared output dimensionality (from options), or `undefined` if not configured. */ get dimensions(): number | undefined; /** Instance availability probe (honours an injected `isAvailable`). */ isAvailable(): boolean; /** Eagerly loads (and caches) the pipeline so the first `embed` call is fast. Idempotent. */ preload(): Promise; /** Drops the cached pipeline and in-flight load so the next call reloads. */ reset(): void; /** * Release the loaded model's ONNX sessions + GPU/wasm buffers, then drop the cached pipeline. * * @remarks * `reset()` only nulls the JS reference; the native ONNX Runtime sessions and WebGPU/wasm device memory * stay alive until GC. Loading many embedding models back-to-back in one browser session (e.g. a full * matrix run) accumulates those sessions until the heap is exhausted. `FeatureExtractionPipeline` * extends `Pipeline`, which exposes `dispose()` — this awaits it so the memory is reclaimed between * loads, swallows a disposal error (teardown must not throw), and finishes with `reset()`. Idempotent. */ dispose(): Promise; /** * Embeds a single string. * * @param text - The input text. * @param opts - Per-call options (`kind`). * @returns The embedding vector as a plain `number[]`. */ embed(text: string, opts?: EmbedOptions): Promise; /** * Embeds a batch of strings in a single pipeline call. * * @param texts - The input texts. * @param opts - Per-call options (`kind`). Defaults to `kind: 'document'`. * @returns One embedding vector per input, in input order, each a plain `number[]`. * @throws {@link @nhtio/adk/batteries!E_TRANSFORMERS_JS_EMBEDDINGS_ENGINE_ERROR} when the call fails * or returns a malformed result. */ embedMany(texts: string[], opts?: EmbedOptions): Promise; }