Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

Handbooks  /  Cross-Encoder vs Bi-Encoder
AI~9 min readComparison
Head to Head

Cross-encoder vs bi-encoder: retrieve fast, or rank well?

Bi-EncodervsCross-Encoder

Both turn text into relevance, but they meet the query and the document at different moments — and that timing is everything. One lets you precompute and search millions of documents in milliseconds; the other reads a query and a document together for a far sharper judgment it can only make a few dozen times per query.

01

The one distinction that decides everything

A bi-encoder passes the query and each document through the model separately, turning each into its own vector; relevance is just the similarity between two independent vectors. Because a document’s vector doesn’t depend on the query, you can precompute all document vectors offline and, at query time, encode only the query and search the index. A cross-encoder feeds the query and a document through the model together, in one pass, and outputs a single relevance score — the two texts attend to each other directly, which is far more accurate, but the score exists only for that specific pair and can’t be precomputed.

→ The rule

Separate encoding (bi-encoder) buys scale: precompute once, search millions fast. Joint encoding (cross-encoder) buys accuracy: the model sees both texts at once — but must run per query–document pair, so it can’t scan a whole corpus.

02

Head to head

DimensionBi-EncoderCross-Encoder
EncodingQuery and doc encoded separatelyQuery and doc encoded together
Doc vectors precomputed?Yes — offline, onceNo — there is no standalone doc vector
Query-time cost1 query encode + fast vector search1 model pass per candidate
Scales toMillions–billions of documentsTens–hundreds of candidates
AccuracyGoodHigher — direct query–doc attention
RoleFirst-stage retrievalSecond-stage reranking
IndexANN (HNSW / IVF) over vectorsNone — runs on the shortlist
03

When to use each

Reach for a bi-encoder

  • Retrieving from a large corpus (thousands to billions of docs)
  • You need millisecond latency at query time
  • Document embeddings can be computed offline and indexed
  • The first stage of a RAG or search pipeline
  • Powering nearest-neighbor recommendations or dedup

Reach for a cross-encoder

  • Reranking a small shortlist for maximum precision
  • The top-k from retrieval must be ordered accurately
  • You can afford a model pass per candidate (tens, not millions)
  • Subtle relevance matters — the query and doc interact
  • Final ranking before showing results or feeding an LLM
04

The answer is "retrieve with one, rerank with the other"

You don’t choose — you stage them. The standard production pattern is retrieve-then-rerank: a bi-encoder retrieves a broad shortlist (say the top 100) from the whole corpus in milliseconds, then a cross-encoder rescoring reorders just those 100 into the final top 10. The bi-encoder does the impossible-at-scale part (scanning everything); the cross-encoder does the impossible-at-scale-but-cheap-on-100 part (reading each candidate carefully). You get the bi-encoder’s reach and most of the cross-encoder’s accuracy, for the cost of ~100 extra model passes per query.

→ The cheap default

Start with bi-encoder retrieval alone — it’s often good enough. Add a cross-encoder reranker when you can measure that the right answer is being retrieved but ranked too low for the top few results (or the LLM’s context) to see it.

05

Why you can’t just cross-encode everything

If cross-encoders are more accurate, why not use one for the whole search? Arithmetic. A cross-encoder produces a score only for a specific query–document pair, so ranking a corpus of one million documents against one query would require one million model forward passes — per query. That’s seconds to minutes of GPU time for a single search, which no interactive system can afford. The bi-encoder sidesteps this entirely: every document is encoded once, offline, into a vector; at query time you encode just the query and let an approximate-nearest-neighbor index find the closest vectors in milliseconds, never touching the model per document.

The cross-encoder’s accuracy comes from the same thing that makes it unscalable — the query and document attending to each other inside the model. You can’t precompute that interaction, because it doesn’t exist until the query arrives. So the two aren’t really competitors: the bi-encoder makes the search possible, and the cross-encoder makes the top of it sharp.

→ The trade you’re actually making

Bi-encoder trades a little accuracy for the ability to precompute and search at scale. Cross-encoder trades scalability for query–document interaction. Reranking is how you buy back the accuracy on just the few candidates that matter.

06

A worked scenario: semantic search over 10M documents

You’re building search over 10 million support articles. Encoding all 10M with a cross-encoder per query is a non-starter — that’s 10M passes for one search. So you embed all 10M documents once with a bi-encoder and store the vectors in an ANN index. A query comes in; you encode it once and the index returns the top 100 candidates in a few milliseconds. Good — but the true best answer might be sitting at rank 40, because separate encoding missed a subtle interaction.

Now a cross-encoder rescoring reads the query together with each of those 100 candidates — 100 model passes, entirely affordable — and reorders them, pulling that rank-40 answer up to the top 3 where the user (or an LLM building an answer) will actually see it. Same two models, staged: retrieve broad and fast, then rerank narrow and sharp.

→ The pattern generalizes

Whenever you must find a few great items in a huge set: use a cheap, precomputable scorer to shortlist, then an expensive, accurate scorer to rank the shortlist. Bi-encoder then cross-encoder is that pattern for text.

The picture

The picture: where the query meets the document

bi-encodercross-encoder query encoder q vec doc encoder d vec offline, once cosine doc vectors reusedfor every query query doc encoderboth at once score per pair, at query time 10M 100 10 corpusbi-enccross
On the left, the document side never sees the query, so its vector can be computed once and reused for every search. On the right, the model reads the pair together, so there is nothing to reuse: the score exists only once the query arrives. The funnel at the bottom is the page’s 10M-document scenario: the bi-encoder cuts the corpus to 100, the cross-encoder orders those into the final 10.
By the numbers

Worked example: the compute bill for the 10M-document funnel

Put numbers on the page’s scenario. Assume both encoders are BERT-base-sized (about 110M parameters), documents are 200 tokens, queries are 20, a query–document pair is 220, and vectors have 768 dimensions. A transformer forward pass costs roughly 2 × parameters × tokens FLOPs, and a dot product of two 768-dim vectors costs 1,536. These sizes are illustrative; the ratios between rows are what matter.

StageWorkApprox. FLOPsWhen it runs
Embed the corpus (bi-encoder)10,000,000 docs × 200 tokens4.4 × 10¹⁷Once, offline (and again on a model change)
Encode the query1 × 20 tokens4.4 × 10⁹Every query
Exact scan of every vector10,000,000 dot products × 1,5361.5 × 10¹⁰Every query, if there is no ANN index
Rerank the top 100 (cross-encoder)100 pairs × 220 tokens4.8 × 10¹²Every query
Cross-encode the whole corpus10,000,000 pairs × 220 tokens4.8 × 10¹⁷Every query — so never

Read the ratios, not the absolutes. Cross-encoding the corpus for one query costs 1.1× embedding the entire corpus, a job you do once. Reranking 100 candidates is 100,000× cheaper than that, but it is still 1,100× the cost of encoding the query, so in this pipeline the reranker, not retrieval, is the per-query compute bill. That makes the shortlist size the main cost dial: cutting 100 to 50 halves it. The exact-scan row looks cheap in FLOPs, but it means reading 30.72 GB of float32 vectors (10M × 768 × 4 bytes) on every query, and that memory traffic is what an ANN index exists to avoid. Scale it up: at 100,000 queries a day, reranking 100 each is 10,000,000 cross-encoder passes a day, as many model passes as embedding the whole corpus, every day.

Trade-offs

Cost and trade-offs at each stage

CaseTimeSpaceWhy
Bi-encoder retrieval1 query encode + ANN search (sub-linear in N)N × d vectors plus the indexDocument vectors do not depend on the query, so they are computed once and reused.
Cross-encoder rerank of top kk model passes, batchedNothing beyond the modelLinear in k. k is both the cost dial and the ceiling on what can be fixed.
Cross-encoder over the corpusN model passes per queryNothing to storeThe score depends on the query, so no work carries over from one query to the next.
Late interaction (ColBERT-style)1 query encode + token-level max-similarity over candidatesOne vector per token, not per document: many times a bi-encoder indexA middle ground: precomputable like a bi-encoder, with matching closer to a cross-encoder’s.
Distilling the cross-encoder into the bi-encoderOffline: the cross-encoder scores many training pairs onceNothing extra at query timeUse the accurate model as a teacher and train the fast one to imitate its scores. It narrows the accuracy gap without adding per-query cost.
Upgrading the modelBi-encoder: re-embed all N documents. Cross-encoder: deploy the new oneBi-encoder: a second index during the switchChanging the reranker is cheap. Changing the retriever is a backfill and a migration.

The practical consequence: iterate on the reranker freely, because nothing is stored that depends on it, and plan a retriever upgrade like a database migration, because every stored vector does. Distillation is the bridge between the two rows: the cross-encoder’s judgement gets baked into the bi-encoder during training, which is paid once, instead of at query time, which is paid forever.

Watch for

Common mistakes

  • Tuning a reranker the shortlist cannot help

    A reranker only reorders what retrieval handed it. If the right document is not in the top 100, no cross-encoder will find it. Measure stage-one recall@k first (is the answer anywhere in the shortlist?), and only then measure whether the reranker lifts it to the top.

  • Using cross-encoder scores as a fixed threshold

    A cross-encoder is trained to put candidates in the right order. Its raw score is not necessarily calibrated across queries, so “drop anything under 0.5” can cut good results for one query and keep junk for another. If you need a “nothing relevant” cut-off, calibrate it on labelled data.

  • Feeding whole documents to the reranker

    Query and document share one input, and BERT-style models stop at 512 tokens. Anything past that is truncated, so the paragraph that answers the question may never be read. Rerank passages, the same chunks you retrieved, not whole documents.

  • Scoring candidates one call at a time

    A hundred sequential calls pay a hundred round trips and leave the accelerator mostly idle. Send the pairs as one batch (or a few) through a single forward pass. The FLOPs are the same; the wall-clock time is not.

  • Re-embedding only new documents after a fine-tune

    Fine-tune the bi-encoder, embed new documents with it, and leave the old vectors alone: now half the index lives in a different vector space and similarities across the two halves mean nothing. Nothing errors. Version the index and re-embed everything.

In the wild

Where this shows up in production and interviews

  • RAG pipelines

    Retrieve a few dozen to a hundred chunks, rerank, and pass only the top handful into the prompt. The reranker decides what the LLM actually reads, and fewer, better chunks also mean fewer input tokens on every call.

  • Why Sentence-BERT exists

    The SBERT paper made this trade concrete: finding the most similar pair among 10,000 sentences is 10,000 × 9,999 / 2 = 49,995,000 pairs, about 65 hours of BERT cross-encoding, against about 5 seconds with sentence embeddings. That gap is the whole reason bi-encoders became the retrieval stage.

  • Recommenders, same shape

    Large recommender systems use the identical two-stage funnel: a cheap candidate generator (often a two-tower model, which is a bi-encoder over users and items) picks hundreds of items from millions, and a heavier ranking model orders them. YouTube’s 2016 recommendations paper describes exactly this split.

  • The interview version

    Expect “why not cross-encode everything?” (do the arithmetic out loud: N passes per query), “how big should the shortlist be?” (it is a recall-versus-cost dial; measure recall@k), and “what breaks when you upgrade the embedding model?” (a full re-embed; the reranker can change freely).

Your call

Which would you pick?

Three situations. Pick the side you'd actually build — the explanation follows.

You must search 20 million documents and return results in under 100ms.

Your vector search returns the right answer, but it sits at position 8 and users only look at the top 3.

Someone proposes dropping the bi-encoder entirely, since the cross-encoder scores better on your evaluation set.

Frequently asked

Quick answers

What's the difference between a bi-encoder and a cross-encoder?

A bi-encoder encodes the query and each document separately into vectors, so document vectors can be precomputed and searched at scale, but it never sees the two texts together. A cross-encoder feeds the query and a document through the model together for a much more accurate relevance score, but must run once per query-document pair, so it cannot scan a whole corpus. Bi-encoders retrieve; cross-encoders rerank.

Which is more accurate?

The cross-encoder, because the query and document attend to each other directly inside the model instead of being compressed into separate vectors first. That interaction is exactly what a bi-encoder gives up in exchange for the ability to precompute document embeddings and search millions of them quickly.

Why not use a cross-encoder for the whole search?

Because it produces a score only for a specific pair, ranking a million-document corpus would need a million model passes per query — far too slow for interactive search. A bi-encoder encodes each document once offline, so query time is a single query encode plus a fast nearest-neighbor lookup.

What is retrieve-then-rerank?

The standard two-stage pattern: a bi-encoder retrieves a broad shortlist (say top 100) from the whole corpus in milliseconds, then a cross-encoder rescoring reorders just those candidates into the final ranking. You get the bi-encoder’s scale and most of the cross-encoder’s accuracy for the cost of a few dozen extra model passes.

▶  Watch it explained

Bi-encoder vs Cross-encoder: skim, then close-read

Cross-Encoder vs Bi-Encoder · Vibe Engines · 2026
Finished this one? 0 / 209 Handbooks done
NextSQL vs Vector Database Next on the “Retrieval” ladder · rung 5 of 7

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Handbooks