Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path →
Cross-encoder vs bi-encoder: retrieve fast, or rank well?
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.
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.
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.
Head to head
| Dimension | Bi-Encoder | Cross-Encoder |
|---|---|---|
| Encoding | Query and doc encoded separately | Query and doc encoded together |
| Doc vectors precomputed? | Yes — offline, once | No — there is no standalone doc vector |
| Query-time cost | 1 query encode + fast vector search | 1 model pass per candidate |
| Scales to | Millions–billions of documents | Tens–hundreds of candidates |
| Accuracy | Good | Higher — direct query–doc attention |
| Role | First-stage retrieval | Second-stage reranking |
| Index | ANN (HNSW / IVF) over vectors | None — runs on the shortlist |
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
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.
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.
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.
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.
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.
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: where the query meets the document
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.
| Stage | Work | Approx. FLOPs | When it runs |
|---|---|---|---|
| Embed the corpus (bi-encoder) | 10,000,000 docs × 200 tokens | 4.4 × 10¹⁷ | Once, offline (and again on a model change) |
| Encode the query | 1 × 20 tokens | 4.4 × 10⁹ | Every query |
| Exact scan of every vector | 10,000,000 dot products × 1,536 | 1.5 × 10¹⁰ | Every query, if there is no ANN index |
| Rerank the top 100 (cross-encoder) | 100 pairs × 220 tokens | 4.8 × 10¹² | Every query |
| Cross-encode the whole corpus | 10,000,000 pairs × 220 tokens | 4.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.
Cost and trade-offs at each stage
| Case | Time | Space | Why |
|---|---|---|---|
| Bi-encoder retrieval | 1 query encode + ANN search (sub-linear in N) | N × d vectors plus the index | Document vectors do not depend on the query, so they are computed once and reused. |
| Cross-encoder rerank of top k | k model passes, batched | Nothing beyond the model | Linear in k. k is both the cost dial and the ceiling on what can be fixed. |
| Cross-encoder over the corpus | N model passes per query | Nothing to store | The 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 candidates | One vector per token, not per document: many times a bi-encoder index | A middle ground: precomputable like a bi-encoder, with matching closer to a cross-encoder’s. |
| Distilling the cross-encoder into the bi-encoder | Offline: the cross-encoder scores many training pairs once | Nothing extra at query time | Use 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 model | Bi-encoder: re-embed all N documents. Cross-encoder: deploy the new one | Bi-encoder: a second index during the switch | Changing 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.
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.
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).
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.
A cross-encoder must run the model once per query–document pair, so 20 million documents means 20 million forward passes per query. Its accuracy is real and completely unusable at this stage. Sampling makes it affordable by simply not looking at most of your corpus, which is worse than a cheaper scorer that looks at all of it.
Your vector search returns the right answer, but it sits at position 8 and users only look at the top 3.
This is exactly the measured condition the page says should trigger reranking: the answer is being retrieved but ranked too low. Running the cross-encoder over ~20 candidates is cheap; running it over the corpus is not. Showing more results shifts the burden onto the user instead of fixing the order.
Someone proposes dropping the bi-encoder entirely, since the cross-encoder scores better on your evaluation set.
The two are not competing for the same job: the cheap precomputable scorer shortlists, the expensive accurate one ranks the shortlist. An eval measuring per-pair accuracy never surfaces the cost of applying it corpus-wide. Caching does not help either, because the score depends on the query — which is new every time.
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.
Bi-encoder vs Cross-encoder: skim, then close-read
Explore the topic
See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.
More Handbooks
- The RAG HandbookRetrieval-augmented generation end to end — why LLMs need it, chunking, embeddings and vector search, hybrid retrieval, two-stage reranking, grounded generation with citations, and how to evaluate a RAG system so a quietly-drifting index never fools you.Read →
- The Vector Databases HandbookHow vector search actually works — why brute-force kNN doesn't scale, distance metrics, approximate nearest neighbor, the HNSW, IVF and product-quantization indexes and their recall/latency/memory tradeoffs, metadata filtering, updates, scaling, and when you need a dedicated vector DB vs pgvector.Read →
- RAG vs Fine-TuningThe most common wrong turn in AI engineering — reaching for fine-tuning when you needed retrieval, or vice versa. The one distinction that decides it (knowledge vs behavior), a head-to-head table, when to use each, and why the strongest systems combine them: fine-tune for behavior, RAG for knowledge.Read →
- The Embeddings HandbookMeaning as geometry: how text and images become vectors so that similar meaning lands nearby, why cosine similarity measures direction not length, how L2-normalization makes the dot product equal cosine (so vector databases just take dot products), the curse of dimensionality, and how it all powers semantic search and RAG — with worked math and runnable code.Read →
- The Data Engineering for AI HandbookThe pipeline that turns raw documents into usable data for RAG and training — ingest, chunk, deduplicate, quality-filter. How overlapping chunking works, why deduplication restores diversity, and why the usable dataset is a compounding fraction of the raw pile (raw × dedup-rate × quality-rate) — because quality beats quantity for both retrieval and training. With worked yield math and a runnable pipeline.Read →
- RAG vs Long ContextA 1M-token window makes it tempting to skip retrieval entirely — but bigger context doesn’t mean the model reads it evenly, and it isn’t cheap. The "lost in the middle" attention problem, cost-at-scale math, and the retrieve-then-go-long pattern that combines both.Read →