reranker (text-classification) · text · WASM · ~270 MB
This is a multilingual cross-encoder from BAAI. Instead of turning a query and a passage into separate vectors and comparing them, it reads both together and outputs a single relevance score. Its backbone is XLM-RoBERTa, trained on 100 languages — so it can rank a Spanish or Japanese passage against an English query, something bilingual embeddings routinely get wrong. Give it a query and some candidates and watch it re-sort them; then look inside at the raw logit per pair. Nothing leaves your device.
| Model | Xenova/bge-reranker-base (ONNX of BAAI/bge-reranker-base) |
|---|---|
| Task / pipeline | text-classification used as a cross-encoder reranker (num_labels = 1) |
| Input | a (query, passage) pair encoded together → one relevance logit |
| Architecture | XLM-RoBERTa-base (multilingual, 100 languages) fine-tuned for passage reranking |
| Quantization | q8 (8-bit) ONNX |
| Backend | WebAssembly (runs anywhere; no WebGPU needed) |
| Download | ~270 MB, cached after first load |
| License | MIT |
| Web APIs | WebAssembly, Web Workers — all Baseline widely available |
Type a query and one candidate passage per line. The model scores each passage against the query and re-sorts them by relevance logit (higher = more relevant). The default set mixes English and Spanish so you can see cross-language ranking.
The one number the model emits per pair is a relevance logit — unbounded, higher is more relevant (we also show its sigmoid as a 0–100% probability). First, the before/after view: the candidates in their original (retrieval) order on the left, and the cross-encoder's reordering on the right — arrows mark what moved. Then a second contrast ranks the same passages by naive shared-word overlap; where the columns disagree, the cross-encoder is using meaning, and it does so across languages — a word-overlap score can't match an English query to a Spanish answer at all.
Rerankers are the precision stage of modern search. A fast retriever (a keyword index or embeddings) casts a wide net and returns, say, the top 50 candidates; a cross-encoder then reads each candidate against the query and reorders them with far higher accuracy. BGE-reranker adds the part global products need most: it works across languages out of one model, so a query in one language can surface the best answer written in another — no per-language pipeline, no translation round-trip. At ~270 MB it runs in a tab, so the precise, expensive step happens on-device with nothing sent anywhere.
Rank a handful of passages against a query by cross-encoder relevance.
Two-stage RAG: retrieve a shortlist, then rerank — including a cross-language corpus.
Adversarial hard negatives: distractors that fool keyword and embedding search.
MiniLM embeddings retrieve, BGE-reranker reorders — the classic retrieve-then-rerank.
Contrast with the English-only MS MARCO MiniLM reranker: same cross-encoder idea, but BGE trades size for multilingual reach.
A cross-encoder scores query–passage pairs; we read the raw logit off the model directly:
import { AutoTokenizer, AutoModelForSequenceClassification } from "@huggingface/transformers";
const model_id = "Xenova/bge-reranker-base";
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
const model = await AutoModelForSequenceClassification.from_pretrained(model_id, { dtype: "q8" });
// Encode the query with each passage AS A PAIR — [CLS] query [SEP] passage [SEP]:
const inputs = tokenizer(
passages.map(() => query),
{ text_pair: passages, padding: true, truncation: true },
);
const { logits } = await model(inputs); // one relevance logit per pair — higher = more relevant
// sort the passages by logits.data — that's your reranking (works even when query and passage
// are in different languages, because the backbone is multilingual XLM-RoBERTa)
This page loads the model through the shared loader as a text-classification pipeline,
then reuses pipe.model + pipe.tokenizer to read the raw logits (the pipeline
would squash them through a sigmoid). All inference runs in a Web Worker so ranking never janks the page.