← All models

reranker (text-classification) · text · WASM · ~270 MB

BGE-reranker — rank passages by relevance, across languages

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.

At a glance

ModelXenova/bge-reranker-base (ONNX of BAAI/bge-reranker-base)
Task / pipelinetext-classification used as a cross-encoder reranker (num_labels = 1)
Inputa (query, passage) pair encoded together → one relevance logit
ArchitectureXLM-RoBERTa-base (multilingual, 100 languages) fine-tuned for passage reranking
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~270 MB, cached after first load
LicenseMIT
Web APIsWebAssembly, Web Workers — all Baseline widely available

Run it

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.

See inside — before vs after, and why it isn't word-matching

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.

Rerank some passages above to compare.

Cross-encoder vs. lexical overlap

Why it matters

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.

Use cases

Basics

Rank a handful of passages against a query by cross-encoder relevance.

Practical

Two-stage RAG: retrieve a shortlist, then rerank — including a cross-language corpus.

Wild

Adversarial hard negatives: distractors that fool keyword and embedding search.

Multi-model

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.

How the API works

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.

References