Skip to content

feat(extensions): add LatticeWasmEmbeddings provider#651

Open
ohdearquant wants to merge 1 commit into
ruvnet:mainfrom
ohdearquant:feat/lattice-wasm-embedding-provider
Open

feat(extensions): add LatticeWasmEmbeddings provider#651
ohdearquant wants to merge 1 commit into
ruvnet:mainfrom
ohdearquant:feat/lattice-wasm-embedding-provider

Conversation

@ohdearquant

Copy link
Copy Markdown
Contributor

Summary

Adds LatticeWasmEmbeddings, a local embeddings provider for ruvector-extensions backed by @khive-ai/lattice-embed-wasm, a pure-Rust BERT-family text embedder compiled to WebAssembly (source: ohdearquant/lattice/npm/lattice-embed-wasm). It plugs into the existing EmbeddingProvider seam next to the OpenAI, Cohere, Anthropic, and HuggingFace providers, giving a native-Rust local-embedding option that does not depend on @xenova/transformers. Offered as a convenience alternative at parity with the existing HuggingFaceEmbeddings local path, not a faster or higher-quality replacement.

What it does

  • getMaxBatchSize() returns 1. The wasm package has no batch API (one embed(text, model) call per text), so this reports that honestly instead of simulating a larger batch.
  • getDimension() returns 384 for both supported models (minilm, bge-small); the constructor throws immediately for any other model name.
  • embedTexts() dynamic-imports the package (mirroring how HuggingFaceEmbeddings imports @xenova/transformers), with an install-hint error if missing. A null result from the wasm layer (unknown model, unsupported over wasm, or unresolvable weights) is a real thrown error for an explicitly-selected provider, never a silent skip.
  • Output is L2-normalized and symmetric (no query/passage prefixing at the wasm layer).
  • @khive-ai/lattice-embed-wasm is an optional peer dependency (peerDependenciesMeta.optional), matching the openai/cohere convention. Not a hard dependency.

Test plan

  • Construction throws for an unknown model name
  • getDimension() returns 384 for minilm (default) and bge-small
  • getMaxBatchSize() returns 1
  • Live embed test (real package + real weights): asserts exact 384-length output and L2 norm ~1.0; self-skips when the optional package or its weights are unavailable (e.g. a fresh CI checkout with no local model cache).

Note (limitation of the underlying package, not this PR): the wasm package's release-asset weight-fetch tier is not live yet, so a user with no local model cache and no model-dir override currently gets a thrown error on first embed. Local-cache and env-override paths work today.

Adds LatticeWasmEmbeddings, a local embeddings provider backed by the
published @khive-ai/lattice-embed-wasm package (a pure-Rust BERT-family
text embedder compiled to WebAssembly). It plugs into the existing
EmbeddingProvider seam alongside OpenAI/Cohere/Anthropic/HuggingFace,
giving a native-Rust local embedder option with no @xenova/transformers
dependency.

- getMaxBatchSize() honestly returns 1: the wasm package has no batch
  API, so this does not simulate a larger batch.
- getDimension() returns 384 for both supported models (minilm,
  bge-small).
- embedTexts() dynamic-imports the optional peer dependency (mirrors
  the existing HuggingFaceEmbeddings pattern) and treats a null result
  from the wasm layer as a real error for an explicitly-selected
  provider, never a silent skip.
- Added as an optional peerDependency (peerDependenciesMeta.optional),
  matching the existing openai/cohere-ai convention.
- Tests mirror the existing per-provider style: construction,
  dimension, batch size, and a live-embed assertion (exact 384 dim,
  L2 norm) gated behind package/model-weight availability.
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.

1 participant