/** * Local in-process embedding provider backed by transformers.js (@huggingface/transformers v3+, ONNX). * * Goal (roadmap A5): a fully offline, no-server, no-API-key embedding backend * that composes with the existing EmbeddingProvider machinery (priority-ordered * fallback chain, CachedEmbeddingProvider, rate limiter). This removes the hard * runtime dependency on an external model server (Ollama) for a default install * and sidesteps the documented "thinking model degrades structured output" bug. * * The model is loaded lazily on first use and cached by transformers.js in the * local HuggingFace cache directory, so after the first run the provider needs * no network access. Instantiation itself is cheap (no model I/O); the heavy * ONNX load happens inside `ensureModel()` and is memoized via a single promise * so concurrent embed calls share one load. * * The transformers.js dependency is optional at the type level: we import it * dynamically (`await import("@huggingface/transformers")`) so the package only * has to be present when this provider is actually selected. This keeps the dep * cost off the default install path and lets tests mock the pipeline without * pulling a multi-megabyte ONNX runtime. * * Migration note (@xenova/transformers v2 → @huggingface/transformers v3): * the v3 package dropped the `quantized` pipeline option in favor of `dtype`. * We pass `dtype: "q8"` to preserve the v2 `quantized: true` behavior * (8-bit weights → ~25MB download, negligible retrieval-quality loss). The * `pipeline`, `env`, and Tensor `.data` (typed Float32Array) surfaces are * otherwise API-compatible. */ import type { EmbeddingProvider } from "../provider.js"; import type { EmbeddingProviderConfig } from "../config.js"; /** * Default transformers.js model. all-MiniLM-L6-v2 is a small (~25MB ONNX), * general-purpose sentence embedding model with 384 dimensions and solid * semantic-search quality for its size. It is a reasonable offline default for * code+text retrieval; users can override via TRANSFORMERS_EMBEDDING_MODEL. * * The `Xenova/...` model id remains resolvable by @huggingface/transformers v3 * (the weights live on the Hugging Face Hub under the Xenova org); changing it * would be an out-of-scope behavioral change. */ export declare const DEFAULT_LOCAL_MODEL = "Xenova/all-MiniLM-L6-v2"; /** Known dimension for the default model, used when not declared in config. */ export declare const DEFAULT_LOCAL_DIMENSIONS = 384; /** * Local in-process embedding provider using transformers.js (ONNX runtime). * * Implements the same EmbeddingProvider interface as AISDKEmbeddingProvider so * it transparently composes with CachedEmbeddingProvider and the fallback * selection chain in embeddings/index.ts. */ export declare class LocalTransformersEmbeddingProvider implements EmbeddingProvider { readonly id: string; readonly model: string; readonly dimensions: number; /** Max characters to send per text (model context limit). */ private readonly maxChars; /** Memoized model-load promise so concurrent embeds share a single load. */ private modelPromise; constructor(config: EmbeddingProviderConfig, providerId: string); /** * Lazily load the transformers.js feature-extraction pipeline. * * The import is dynamic so the (sizeable) ONNX runtime is only pulled in when * this provider is actually selected. The load is memoized: the first caller * triggers the ONNX/model load, all concurrent callers await the same promise. */ private ensureModel; /** Truncate text to the configured per-call character limit. */ private truncateText; embedQuery(text: string): Promise; embedBatch(texts: string[]): Promise; /** * Availability check. For the local provider this confirms the model can be * loaded (which triggers the one-time ONNX/model download on first run). * Cheap on subsequent calls because the load is memoized. */ isAvailable(): Promise; getConfig(): EmbeddingProviderConfig; } //# sourceMappingURL=local-transformers.d.ts.map