← All models

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

MS MARCO MiniLM — rank passages by how well they answer

This is a cross-encoder: instead of turning a query and a passage into separate vectors and comparing them, it reads both together and outputs a single relevance score. Attention flows across the query and the passage, so it catches relevance that word-matching and even embeddings miss. Give it a query and some candidate passages and watch it sort them — then look inside at the raw logit it assigns each pair. Nothing leaves your device.

At a glance

ModelXenova/ms-marco-MiniLM-L-6-v2
Task / pipelinetext-classification used as a cross-encoder reranker (num_labels = 1)
Inputa (query, passage) pair encoded together → one relevance logit
Architecture6-layer MiniLM (BERT family) fine-tuned on the MS MARCO passage-ranking data
Quantizationq8 (8-bit) ONNX
BackendWebAssembly (runs anywhere; no WebGPU needed)
Download~90 MB, cached after first load
LicenseApache-2.0
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 ranks them by relevance logit (higher = more relevant).

See inside — cross-encoder vs. lexical overlap

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% bar). The interesting part is what it does that keyword matching can't: below, the same passages are ranked by the cross-encoder on the left and by naive shared-word overlap on the right. Where the two columns disagree, the cross-encoder is using meaning — rewarding a passage that answers the query even when it barely shares any words with it.

Rerank some passages above to compare.

Why it matters

Rerankers are the second stage of modern search. A fast retriever (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 precision. That two-stage pattern powers RAG, site search, and recommendations — and at 90 MB the reranker 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 search: see why reranking a shortlist beats embedding scores alone.

Wild

Answer selection: find the one true answer hidden among plausible distractors.

Multi-model

MiniLM embeddings retrieve, this cross-encoder reranks — the classic retrieve-then-rerank.

Pairs naturally with the MiniLM embeddings model, which does the fast first-stage retrieval this reranker refines.

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/ms-marco-MiniLM-L-6-v2";
const tokenizer = await AutoTokenizer.from_pretrained(model_id);
const model = await AutoModelForSequenceClassification.from_pretrained(model_id);

// 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

This page loads the model through the shared question-answering-style loader as a text-classification pipeline, then reuses pipe.model + pipe.tokenizer to get 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