ruvector/fixtures/lattice-embed
OceanLi 629f63af1b
fix(embeddings): reconcile bge-small convention between Lattice providers (#663)
* fix(embeddings): reconcile bge-small convention between Lattice providers

Aligns the WASM (LatticeWasmEmbeddings, #651) and native Rust
(LatticeEmbedding, #648) Lattice-backed embedding providers with
lattice-embed's own native convention for bge-small (#662):

- LatticeWasmEmbeddings gains embedQuery(), which applies BGE-v1.5's
  retrieval-instruction prefix on the query side (documents/passages
  stay raw via embedText/embedTexts), matching
  EmbeddingModel::query_instruction() in lattice-embed and
  LatticeEmbedding::embed_query() in ruvector-core.
- LatticeWasmEmbeddings now accepts the same bge-small alias surface
  as lattice-embed's EmbeddingModel::from_str (bge-small,
  bge-small-en, bge-small-en-v1.5, small, BAAI/... ids,
  case/underscore-insensitive), normalized to a canonical model name
  via getModel().
- Documents, on both providers, that native BERT-family encoding
  (BGE/E5/MiniLM) is unconditionally L2-normalized, citing
  BertModel::encode/encode_batch's l2_normalize call in
  lattice-inference.

Adds a query/passage prefix-asymmetry test and an alias-parsing test
for the WASM provider, plus a bge-small alias regression test for the
Rust provider.

Closes #662.

Co-Authored-By: Leo <noreply@khive.ai>

* test(embeddings): pin cross-provider query/passage prefix contract (#662)

Follow-up requested during review of #663: a shared-fixture contract
test so the Rust `LatticeEmbedding` provider (crates/ruvector-core,
delegates to lattice_embed::EmbeddingService::embed_query, which
prepends EmbeddingModel::query_instruction() internally) and the
TS/WASM `LatticeWasmEmbeddings` provider (npm/packages/ruvector-
extensions, hardcodes the same prefix as a TS literal since the wasm
binding exposes no prefix concept) cannot silently re-diverge on which
retrieval-instruction prefix a model gets.

- fixtures/lattice-embed/query-prefixes.json: the shared fixture, keyed
  by the canonical model alias both providers accept ("bge-small",
  "minilm"), pinning query_prefix / passage_prefix per model.
- crates/ruvector-core/src/embeddings.rs: new
  cross_provider_query_prefix_contract test, asserting
  lattice_embed::EmbeddingModel::query_instruction()/
  document_instruction() -- both documented "Stable" in lattice-embed's
  own API-stability convention -- against the fixture. No model
  weights or network access required.
- npm/packages/ruvector-extensions/tests/lattice-prefix-contract.test.ts:
  the TS sibling, asserting applyLatticeWasmQueryPrefix() against the
  same fixture. No model weights or the optional
  @khive-ai/lattice-embed-wasm peer package required.

Mutation-verified in both directions: changing the fixture's
query_prefix fails both suites independently; changing
LATTICE_WASM_QUERY_INSTRUCTIONS in src/embeddings.ts fails the TS test
alone; and (verified against a scratch lattice-embed build with
EmbeddingModel::query_instruction()'s bge-small branch changed, patched
in via a temporary [patch.crates-io] override and reverted afterward)
an upstream lattice-embed convention change fails the Rust test even
with an untouched fixture -- the property this test exists to
guarantee.

Co-Authored-By: Leo <noreply@khive.ai>

---------

Co-authored-by: Leo <noreply@khive.ai>
2026-07-12 13:50:54 -04:00
..
query-prefixes.json fix(embeddings): reconcile bge-small convention between Lattice providers (#663) 2026-07-12 13:50:54 -04:00