Xenova Brings ms-marco-MiniLM Reranking Directly Into Your Browser
A tiny cross-encoder reranker, ported to ONNX and Transformers.js, lets you run search relevance scoring directly in the browser with no server.
ProTakeaways
- Xenova/ms-marco-MiniLM-L-6-v2 ports the popular MS MARCO cross-encoder reranker to ONNX for Transformers.js.
- Runs in browser, Node, or edge workers with no Python or GPU required.
- Base model scores 74.30 NDCG@10 on TREC DL 19 at 1800 docs per second on V100.
- Quantized weights track full precision closely, keeping bundle size small for web apps.
- Limits: 512-token pairs, English only, throughput drops sharply past a few hundred candidates.
- Ideal for client-side RAG, privacy-sensitive search, and pipelines wanting one JavaScript runtime.
Retrieval augmented generation pipelines almost always need a reranker: a small model that takes a query plus a shortlist of candidate passages and re-scores them for relevance. Rerankers typically live on a server with a Python stack and a GPU. The Hugging Face repo Xenova/ms-marco-MiniLM-L-6-v2 sidesteps that by shipping the classic MS MARCO MiniLM cross-encoder as ONNX weights wired up for Transformers.js, so the entire reranking step can run inside a browser tab or a Node process.
A Familiar Model, Repackaged for the Web
The underlying model is a conversion of cross-encoder/ms-marco-MiniLM-L6-v2, a six-layer MiniLM trained on the MS MARCO passage ranking task. What Xenova adds is packaging: ONNX weights in both full-precision and quantized variants, compatible with Transformers.js. No Python runtime, no CUDA, no server round trip. Just a JavaScript import and a WASM or WebGPU backend.
A cross-encoder differs from the embedding models most people use for semantic search. Rather than encoding query and document separately and comparing vectors, it feeds the pair into a single transformer and outputs one relevance score. That approach is more accurate but too expensive to run across an entire corpus, which is why cross-encoders are typically used as second-stage rerankers over the top few dozen or hundred hits from a cheaper retriever.
The Numbers Behind Its Popularity
The base model has become something of a default in the RAG stack because of its size-to-quality ratio. Fine-tuned on MS MARCO passage ranking, it achieves 74.30 NDCG@10 on TREC DL 19 with 1,800 docs-per-second throughput on a V100 GPU. Independent evaluations back up the reputation:
- In a recent knowledge-graph RAG benchmark, ms-marco-MiniLM-L-6-v2 was selected for the final pipeline based on superior Hit@5 and Recall@20 performance relative to alternatives.
- In a scientific claim retrieval study of seven rerankers, only ms-marco-MiniLM-L-6-v2 and a T5 model improved upon the initial BM25 baseline.
- Practitioners report performance nearly matching the 12-layer ms-marco-MiniLM-L-12-v2 at roughly twice the speed.
Using It from JavaScript
Installation is a single npm command and the API mirrors the Python transformers library. Tokenize the query and document as a pair, then read the logit as a relevance score.
import { AutoTokenizer, AutoModelForSequenceClassification } from '@huggingface/transformers';
const model = await AutoModelForSequenceClassification.from_pretrained('Xenova/ms-marco-MiniLM-L-6-v2');
const tokenizer = await AutoTokenizer.from_pretrained('Xenova/ms-marco-MiniLM-L-6-v2');
const features = tokenizer(
['How many people live in Berlin?', 'How many people live in Berlin?'],
{ text_pair: [
'Berlin has a population of 3,520,031 registered inhabitants in an area of 891.82 square kilometers.',
'New York City is famous for the Metropolitan Museum of Art.',
], padding: true, truncation: true }
);
const scores = await model(features);
// quantized: [ 8.66, -11.24 ]
// unquantized: [ 8.84, -11.24 ]
Higher logit means more relevant. To rerank, batch the query against each candidate, sort by score, and slice the top K. The quantized weights land within a few hundredths of the full-precision output on the sample above, so most applications can safely ship the smaller file.
Where It Fits and Where It Breaks Down
The natural home for this build is client-side RAG and search: a Chrome extension that reranks results locally, a desktop app built on Electron or Tauri that avoids a Python sidecar, an edge worker doing cheap reranking without a GPU model, or a Node service that wants one runtime for both retrieval and reranking. Privacy-sensitive applications also benefit, since documents never leave the device.
The limits follow from the model itself: 22 million parameters, English only, trained on MS MARCO. Each query-document pair is capped at 512 tokens, so long documents need chunking. Multilingual corpora will want bge-reranker or a comparable model. Cross-encoding is also quadratic-ish in candidate count, so throughput drops quickly at scale. Users reranking the top 1,000 results reported around 2 to 2.5 seconds per query on a GPU; pushing to 3,000 candidates stretched that to 6 to 7 seconds. Over WASM in a browser, think dozens of candidates rather than thousands.
Why the Packaging Matters
The repo has quietly accumulated hundreds of thousands of monthly downloads and appears in a growing list of Hugging Face Spaces doing RAG entirely in the browser. It also illustrates a pattern worth copying: ONNX weights belong in an onnx subfolder, converted with Optimum, keeping a clean separation from the original model weights until broader WebML support makes the distinction moot.
For anyone who has been postponing a reranker because it meant standing up another Python service, this removes that friction. Pair it with a WASM BM25 or a small embedding model like all-MiniLM-L6-v2 and you have a full two-stage retrieval pipeline that fits in a static site.