← All models

sentence-similarity Β· text Β· WASM Β· ~34 MB

bge-small-en-v1.5 β€” rank text by meaning, retrieval-grade

A stronger retrieval embedder than MiniLM: BAAI's BGE turns each sentence into a 384-number vector tuned for search and similarity. Give it a query and a handful of candidates and it ranks them by cosine similarity β€” and it knows a trick MiniLM doesn't: a query instruction that sharpens short-query-to-passage search. Everything runs locally; nothing leaves your device.

At a glance

ModelXenova/bge-small-en-v1.5 (ONNX build of BAAI/bge-small-en-v1.5)
Task / pipelinesentence-similarity, via feature-extraction
ArchitectureBERT-style encoder (12 layers, 33M params) β†’ 384-dimensional sentence embedding
PoolingCLS pooling (the [CLS] token vector β€” not mean pooling), then L2-normalize
Query instructionRepresent this sentence for searching relevant passages: β€” prepended to the query for asymmetric search
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~34 MB, cached after first load
LicenseMIT (BAAI FlagEmbedding)
Web APIsWebAssembly, Web Workers β€” all Baseline widely available

Run it β€” semantic ranking

Type a query and one candidate per line. BGE embeds all of them and ranks the candidates by cosine similarity to the query. Toggle the query instruction to see BGE's asymmetric-search trick: it's prepended to the query only, never to the candidates.

See inside β€” the vector, and the query-instruction effect

BGE emits a 384-number vector for the whole sentence by taking the transformer's first [CLS] token (not an average of all tokens like MiniLM), then L2-normalizing it to unit length. Below left: the real vector for a chosen sentence. Below right: the same ranking run with and without the query instruction β€” proof the prefix actually moves ranks.

The 384-d vector

Rank some sentences to inspect a vector.

Prefix effect: with vs without

Rank sentences to compare rankings.

Why it matters

Embeddings are the workhorse behind search, recommendations, dedup, clustering, and RAG. BGE is a retrieval-tuned embedder β€” on the MTEB benchmark it out-ranks general models like MiniLM for finding the right passage β€” yet at 34 MB it still runs in a tab. So you can ship meaning-based search with no vector database, no API bill, and no user text leaving the device.

Use cases

Basics

Pair similarity felt as one number, plus a demo of why meaning beats keyword overlap.

Practical

Semantic search that beats keywords, and near-duplicate clustering over a pasted corpus.

Wild

An STS "how similar, 0–5?" gauge, paraphrase mining across a pile, and odd-one-out.

Multi-model

BGE retrieves a shortlist, then hands it to the MS-MARCO cross-encoder to rerank.

How the API works

Feature-extraction with CLS pooling is the whole recipe β€” plus the query instruction for asymmetric search:

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

const extract = await pipeline(
  "feature-extraction",
  "Xenova/bge-small-en-v1.5",
); // downloads + caches ~34 MB once

// BGE v1.5 is trained with CLS pooling (NOT mean pooling):
const embed = (texts) => extract(texts, { pooling: "cls", normalize: true });

// Asymmetric search: prefix the QUERY only, leave passages bare.
const INSTR = "Represent this sentence for searching relevant passages:";
const q = await embed([`${INSTR} how to keep a battery healthy`]);
const passages = await embed([
  "Keep lithium-ion charge between 20 and 80 percent.",
  "The best hiking trails in the Lake District.",
]);

// unit vectors β†’ cosine similarity is just the dot product:
const score = (a, b) => a.reduce((s, x, i) => s + x * b[i], 0);
const q0 = q.tolist()[0], ps = passages.tolist();
ps.map((p) => score(q0, p)); // β†’ [0.71, 0.28] β€” battery line wins

This page asks the worker for the un-normalized CLS vectors so "See inside" can show the real pre-normalization magnitude, then normalizes in JS. Inference runs in a Web Worker so ranking never janks the page. Use the instruction for short-query search; for symmetric similarity (STS, dedup, paraphrase) prefix nothing on either side.

References