/** * WebLLM (WebGPU, in-process) Embeddings adapter battery. * * @module @nhtio/adk/batteries/embeddings/webllm/adapter * * @remarks * Embeddings battery backed by WebLLM's in-process `engine.embeddings.create()` (the OpenAI-style * embeddings API exposed by `@mlc-ai/web-llm`). Runs entirely in the browser on WebGPU — no * network round-trip, no API key. * * This class is the **same battery** as {@link @nhtio/adk/batteries/embeddings/openai!OpenAIEmbeddingsAdapter} * in every user-facing respect — identical method surface (`isAvailable` / `dimensions` / * `preload` / `reset` / `embed` / `embedMany`), identical `number[]` return shape, identical * query/document prefix handling (the shared `applyEmbeddingPrefix` helper) — differing only in * the engine. Construction validates eagerly and throws * {@link @nhtio/adk/batteries/embeddings/webllm/exceptions!E_INVALID_WEBLLM_EMBEDDINGS_OPTIONS} on failure. * * `@mlc-ai/web-llm` is an optional peer dependency, imported lazily so non-WebGPU consumers pay * nothing for it. */ import type { EmbedOptions } from "../openai/types"; /** * Embeddings adapter for WebLLM's in-process embeddings API. * * @remarks * Reusable: construct once, call {@link WebLLMEmbeddingsAdapter.embed} / {@link embedMany} as many * times as needed. The engine 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 WebLLMEmbeddingsAdapter { #private; /** * Whether WebGPU — and therefore this battery — is available in the current runtime. */ static isAvailable(): boolean; /** * @param options - Constructor options. Validated eagerly. * @throws {@link @nhtio/adk/batteries/embeddings/webllm/exceptions!E_INVALID_WEBLLM_EMBEDDINGS_OPTIONS} when `options` does not satisfy * {@link @nhtio/adk/batteries/embeddings/webllm/validation!webLLMEmbeddingsOptionsSchema} (e.g. missing `model`). */ constructor(options: unknown); /** Declared output dimensionality (from options), or `undefined` if not configured. */ get dimensions(): number | undefined; /** Whether WebGPU is available, honoring an injected `isWebGPUAvailable` probe. */ isAvailable(): boolean; /** * Eagerly loads (and caches) the engine so the first `embed` call is fast. Idempotent. * * @throws {@link @nhtio/adk/batteries/embeddings/webllm/exceptions!E_INVALID_WEBLLM_EMBEDDINGS_OPTIONS} when no WebGPU is available and no engine * was injected. * @throws {@link @nhtio/adk/batteries/embeddings/webllm/exceptions!E_WEBLLM_EMBEDDINGS_ENGINE_ERROR} when engine creation fails. */ preload(): Promise; /** Drops the cached engine and in-flight load so the next call reloads. */ reset(): void; /** * 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 engine 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/embeddings/webllm/exceptions!E_WEBLLM_EMBEDDINGS_ENGINE_ERROR} when the engine call fails or returns a * malformed result. */ embedMany(texts: string[], opts?: EmbedOptions): Promise; }