sentence-similarity · text · WASM q8 · 337.70 MB · 1024-d · MIT

E5-large-v2 — 24-layer 1024-d sentence-similarity & asymmetric retrieval

Microsoft's flagship 24-layer English E5 encoder (~335M parameters, 1024-d unit vectors) trained via weakly-supervised contrastive pre-training with a strict "query: " / "passage: " asymmetric prefix protocol — running completely locally in WebAssembly.

At a glance

Model card metadata, architecture, prefix protocol, quantisation and runtime
Upstream model intfloat/e5-large-v2
Browser ONNX build Xenova/e5-large-v2 · onnx/model_quantized.onnx
Task / pipeline sentence-similarity via pipeline("feature-extraction", …, { device: "wasm", dtype: "q8" }) with { pooling: "mean", normalize: true } → 1024-d unit vector
Architecture BertModel · 24 layers · 16 heads · 1024 hidden · 4,096 FFN · ~335M params · 30,522 uncased WordPiece vocab ([CLS]=101, [SEP]=102)
Prefix protocol Mandatory prefixes: "query: " for retrieval queries & symmetric tasks; "passage: " for corpus documents. InfoNCE temperature 0.01 puts typical cosines in 0.70–1.00.
Sequence limit 512 tokens (max_position_embeddings: 512; English-only)
Quantisation & download q8 · 336.98 MB ONNX (336,983,104 B) + 0.71 MB tokenizer (711,396 B) + configs (913 B) = 337.70 MB decimal total
Backend & runtime CPU WebAssembly (wasm) via shared Transformers.js 3.7.5 inside a dedicated Web Worker
License MIT

1. Live asymmetric retrieval & 1024-d cosine studio

Because e5-large-v2 was trained contrastively with low temperature (0.01), unrelated passages still score ~0.70–0.78 while true matches climb toward 0.85–0.94 — relative rank order and prefix roles are what drive retrieval quality. Toggle between query:/passage:, symmetric query:, and unprefixed raw text below.
Or drag & drop a file or paste lines anywhere outside text boxes.
Query-vs-corpus cosine similarity ranking with E5 prefix roles
Rank Passage Prefix role Cosine q · d WordPiece tok
Initialise e5-large-v2 above to compute live 1024-d embeddings.

2. See inside: pairwise similarity matrix, 2-D PCA & WordPiece prefix tokens

Left: N×N pairwise cosine similarity across candidate passages (diagonal = 1.00). Right: deterministic 2-D principal component projection of 1024-d embeddings showing the query (★) and dashed rays to its Top-3 nearest neighbors.

Pairwise cosine matrix

2-D PCA semantic space

Prefixed query WordPiece tokenization (uncased 30,522-token vocab)

Run inference to inspect [CLS], E5 prefix tokens, WordPiece subwords (##), and [SEP].

Why 24-layer E5-large-v2 matters

Use-case ladder

How the API works

import { pipeline } from "@huggingface/transformers";

const extractor = await pipeline("feature-extraction", "Xenova/e5-large-v2", {
  device: "wasm",
  dtype: "q8",
});

// Asymmetric retrieval requires "query: " and "passage: " prefixes:
const inputs = [
  "query: how much protein should an adult woman eat?",
  "passage: CDC guidelines suggest roughly 46 grams per day for adult women.",
];
const out = await extractor(inputs, { pooling: "mean", normalize: true });
// out.dims = [2, 1024]; cosine similarity == dot product

Show the code

Show the code: epoch-safe pipeline("feature-extraction", "Xenova/e5-large-v2") loader (worker.js)
Show the code: E5 query:/passage: prefix formatter (e5-core.mjs)
Show the code: deterministic 2-D PCA over 1024-d embeddings (e5-core.mjs)