Skip to content
4 min read · 745 words

Interface: TransformersJsEmbeddingsAdapterOptions ​

Defined in: src/batteries/embeddings/transformers_js/types.ts:96

Constructor options for the transformers.js Embeddings adapter.

Remarks ​

Extends the shared BaseEmbeddingsAdapterOptions (required model + prefix options) with transformers.js pipeline fields. model accepts any ONNX feature-extraction model id (e.g. onnx-community/all-MiniLM-L6-v2-ONNX) — there is no default.

Extends ​

Properties ​

PropertyTypeDescriptionInherited fromDefined in
createPipeline?CreateTransformersJsEmbeddingsPipelineOverride the pipeline factory. Default: pipeline('feature-extraction', …) via dynamic import.-src/batteries/embeddings/transformers_js/types.ts:101
device?| "auto" | "gpu" | "cpu" | "wasm" | "webgpu" | "cuda" | "dml" | "coreml" | "webnn" | "webnn-npu" | "webnn-gpu" | "webnn-cpu"Inference device forwarded to pipeline(). Default: transformers.js environment default.-src/batteries/embeddings/transformers_js/types.ts:103
dimensions?numberDeclared output dimensionality, surfaced via adapter.dimensions. Optional metadata for callers that pre-allocate buffers; the battery does not enforce it against responses.BaseEmbeddingsAdapterOptions.dimensionssrc/batteries/embeddings/openai/types.ts:84
documentPrefix?stringInstruction prefix prepended to inputs embedded with kind: 'document'. Unset → no prefix. Most asymmetric models (including Arctic) use no document prefix; exposed for symmetry and the models that do.BaseEmbeddingsAdapterOptions.documentPrefixsrc/batteries/embeddings/openai/types.ts:79
dtype?| "auto" | "fp32" | "fp16" | "q8" | "int8" | "uint8" | "q4" | "bnb4" | "q4f16" | "q2" | "q2f16" | "q1" | "q1f16"Quantization/precision dtype forwarded to pipeline().-src/batteries/embeddings/transformers_js/types.ts:105
isAvailable?() => booleanOverride the availability probe. Default: true whenever the peer is importable (env-neutral).-src/batteries/embeddings/transformers_js/types.ts:125
modelstringModel id to embed with. Required, no default. For OpenAI this is e.g. text-embedding-3-small; for WebLLM it is an MLC embedding model id (e.g. snowflake-arctic-embed-m-q0f32-MLC).BaseEmbeddingsAdapterOptions.modelsrc/batteries/embeddings/openai/types.ts:67
modelSource?TransformersJsEmbeddingsModelSourceCustom model-source resolver (OPFS / separate source / bundled bytes). When set, model files load through it behind the global-env mutex; otherwise straight from HF (unchanged). See TransformersJsEmbeddingsModelSource.-src/batteries/embeddings/transformers_js/types.ts:121
normalize?booleanL2-normalise the embeddings (default true).-src/batteries/embeddings/transformers_js/types.ts:109
onCompiling?BatteryLifecycleCallbackEngine/graph/shader compilation after download, before the first token. A COARSE marker: the on-device runtimes (LiteRT Engine.create, transformers.js from_pretrained) expose the boundary — download done, opaque WebGPU/WASM graph build about to run — but NOT a progress stream, so progress is usually absent. Often the slowest part of a cold start; without this it was invisible.BatteryLifecycleHooks.onCompilingsrc/batteries/llm/chat_common/lifecycle.ts:95
onComplete?BatteryLifecycleCallbackAfter the turn's output is parsed + persisted, before ack (fires per turn).BatteryLifecycleHooks.onCompletesrc/batteries/llm/chat_common/lifecycle.ts:105
onError?BatteryLifecycleCallbackA load or generation failure (paired with nack).BatteryLifecycleHooks.onErrorsrc/batteries/llm/chat_common/lifecycle.ts:107
onGenerating?BatteryLifecycleCallbackThe generate call is in progress (fires per turn). Fires once immediately before the provider call for most engines; engines that stream per-step generation progress (e.g. a diffusion denoise loop) fire it REPEATEDLY during generation, each carrying a progress in 0..1.BatteryLifecycleHooks.onGeneratingsrc/batteries/llm/chat_common/lifecycle.ts:103
onInitProgress?ProgressCallbackCalled with model-load progress reports while weights download/compile.-src/batteries/embeddings/transformers_js/types.ts:123
onLifecycle?BatteryLifecycleCallbackFires on EVERY phase transition (the firehose).BatteryLifecycleHooks.onLifecyclesrc/batteries/llm/chat_common/lifecycle.ts:86
onLoading?BatteryLifecycleCallbackWeights/runtime loading — may fire repeatedly with progress as the provider reports it.BatteryLifecycleHooks.onLoadingsrc/batteries/llm/chat_common/lifecycle.ts:88
onReady?BatteryLifecycleCallbackEngine/pipeline resolved and cached, before the first generation.BatteryLifecycleHooks.onReadysrc/batteries/llm/chat_common/lifecycle.ts:97
pipeline?FeatureExtractionPipelineA pre-built pipeline. When provided, the battery uses it directly and skips lazy creation.-src/batteries/embeddings/transformers_js/types.ts:99
pooling?TransformersJsPoolingPooling method (default 'mean').-src/batteries/embeddings/transformers_js/types.ts:107
poolingOwner?TransformersJsPoolingOwnerWho pools + normalizes (default 'engine' — today's behavior, byte-identical). Set 'battery' to pool + L2-normalize in deterministic shared JS for tighter node↔browser parity. See TransformersJsPoolingOwner.-src/batteries/embeddings/transformers_js/types.ts:115
queryPrefix?stringInstruction prefix prepended to inputs embedded with kind: 'query'. Unset → no prefix. For Snowflake Arctic Embed, the documented value is 'Represent this sentence for searching relevant passages: '.BaseEmbeddingsAdapterOptions.queryPrefixsrc/batteries/embeddings/openai/types.ts:73