Skip to content

feat(embeddings): expose Transformers.js runtime options - #17

Merged
harlan-zw merged 2 commits into
skilld-dev:mainfrom
mrrobertkent:feat/transformers-device-dtype
Aug 12, 2026
Merged

feat(embeddings): expose Transformers.js runtime options#17
harlan-zw merged 2 commits into
skilld-dev:mainfrom
mrrobertkent:feat/transformers-device-dtype

Conversation

@mrrobertkent

@mrrobertkent mrrobertkent commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

❓ Type of change

  • 📖 Documentation
  • 🐞 Bug fix
  • 👌 Enhancement
  • ✨ New feature
  • 🧹 Chore
  • ⚠️ Breaking change

📚 Description

Expose Transformers.js device and data type settings, including per-file maps, without changing default device selection. Unknown models now probe dimensions, and the bge-large-en-v1.5 preset resolves to published weights. Supersedes #18.

The transformers.js provider pinned `dtype: 'fp32'`, never passed a `device`,
and threw for any model outside the dimension registry. Three changes, all
backward compatible:

Expose `device` and `dtype`. Transformers.js defaults `device` to `cpu` under
Node, leaving the accelerated backends that onnxruntime-node already bundles
unreachable. `device` is only forwarded when set, and `dtype` keeps its `fp32`
default, so device resolution is unchanged when both are omitted.

Probe dimensions when the registry has no entry, instead of throwing
"Unknown dimensions for model X". The Ollama provider already did this; without
it any Hugging Face repo outside the registry was unusable even though the
pipeline loaded fine. Registry hits and an explicit `dimensions` option skip
the probe.

Repoint the `bge-large-en-v1.5` preset from `onnx-community/bge-large-en-v1.5`,
whose weights return 401, to `Xenova/bge-large-en-v1.5`, which carries the same
weights plus quantized and fp16 variants. `resolveModelForPreset` and
`getModelDimensions` both succeeded for the broken preset, so nothing surfaced
it until the model failed to load.

Benchmarked on an Apple M5 Max, 120 documents, best of 3 after warm-up
(docs/sec):

  model                       cpu   coreml   webgpu
  bge-small-en-v1.5           664      198     1713
  bge-base-en-v1.5            198       68      580
  Xenova/bge-large-en-v1.5     71        9      201

webgpu is 2.6-2.9x faster than cpu at every size; coreml is 3-8x slower because
it falls back to CPU for unsupported ops, and coreml+fp16 fails to load on this
onnxruntime build. The ranking is hardware-specific, which is why this is a
caller choice rather than a new default. The README documents the measurements
so `device` does not get cargo-culted.
@mrrobertkent
mrrobertkent force-pushed the feat/transformers-device-dtype branch from 08b70a6 to 9c7f27d Compare August 11, 2026 20:43
@harlan-zw harlan-zw changed the title feat(embeddings): expose device and dtype for transformers.js feat(embeddings): expose Transformers.js runtime options Aug 12, 2026
@harlan-zw
harlan-zw merged commit df92a9c into skilld-dev:main Aug 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants