Zenaique

Bi-encoders vs cross-encoders, where does attention cross the query and document?

MCQ·Medium·4.0 · 0·~1 min·Asked atKore AiRazorpayTesla·Relevant atAi4bharatCerebrasDeepseekMicrosoft
Attempt it
TL;DR

Bi-encoder encodes query and document independently and scores by dot product; cross-encoder concatenates them into one sequence and runs full self-attention across the boundary.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Imagine matching job applicants to job postings. A bi-encoder is like having an interviewer write a one-paragraph summary of each applicant and each job, then matching them by comparing summaries side by side, fast, because you only need to write each summary once. A cross-encoder is like making the interviewer sit down with each applicant-job pair, read both together, and write a fresh assessment for that specific pair, slow, because every pair needs its own assessment, but the assessments are far more accurate. Production search stacks use both: the fast bi-encoder narrows millions of jobs down to a hundred, then the slow cross-encoder picks the best ten.

Concept explanation~2 min read

Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.

Bi-encoders and cross-encoders are the two foundational architectures for neural retrieval, and the distinction between them is one of the most consequential design choices in any RAG or search system. The split is purely structural, where attention crosses (or does not cross) the boundary between query and document, and it determines whether documents can be precomputed and indexed or whether every query-document pair requires a fresh forward pass.

This card walks the two architectures, the cost model each implies, why production stacks combine them in a two-stage pipeline, and the modern variants (ColBERT, hybrid sparse-dense, LLM-as-reranker) that fill the cost-accuracy spectrum between pure bi-encoder and pure cross-encoder. By the end you should be able to design a retrieval stack from scratch and reason about which component runs at which scale.

The structural split

Both architectures use the same transformer encoder backbone (BERT, RoBERTa, ModernBERT, or a modern embedding LLM like E5-Mistral). The split is where attention runs.

Bi-encoder

code
Query     ->  [CLS] q1 q2 ... qm [SEP]  -> Encoder -> pool -> e_q (768 dim)
Document  ->  [CLS] d1 d2 ... dn [SEP]  -> Encoder -> pool -> e_d (768 dim)
Score     =   e_q . e_d

Two independent forward passes through the same encoder weights. No attention ever crosses between query tokens and document tokens because they never share a sequence. The relevance score is a dot product (or cosine, after L2 normalization).

Cross-encoder

code
Input  -> [CLS] q1 q2 ... qm [SEP] d1 d2 ... dn [SEP]
       -> Encoder (full self-attention) -> pool -> [CLS] hidden state
Score  = classification_head([CLS] hidden state)

One sequence containing query and document tokens, separated by [SEP]. Full self-attention runs over the entire sequence, so every query token can attend to every document token and vice versa. The relevance score comes from a classification (or regression) head on the [CLS] hidden state.

The boundary visibility

The word 'boundary' is the key. In the bi-encoder, there is no shared sequence, so there is no boundary for attention to cross. In the cross-encoder, the boundary is the [SEP] token in the middle of the sequence, and attention crosses it freely just as it would cross any other position. The bi-encoder structurally CANNOT model query-document token interactions because the two halves are never in the same forward pass.

Cost model: why one scales and the other doesn't
The two-stage retrieval pipeline
Modern variants on the cost-accuracy spectrum
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.
PropertyBi-encoderCross-encoder
Input structureQuery and document encoded separatelyConcatenated into one sequence
Cross-modal attentionNoneFull self-attention across the boundary
ScoringDot product of pooled embeddingsClassification head on [CLS]
Document precomputationYes (one forward pass per document offline)No (every query-document pair needs fresh pass)
Inference cost per query1 forward pass + N dot productsN forward passes
ScalabilityBillions of documents with ANN indexThousands at most
AccuracyLower (pooled embeddings lose token-level signal)Higher (full token-level interaction)
Typical roleFirst-stage recallSecond-stage rerank

Real products, models, and research that use this idea.

  • OpenAI text-embedding-3-large and Cohere embed-v4 are bi-encoder embedding models powering first-stage retrieval in 2026 production RAG stacks.
  • bge-reranker-v2.5 and Cohere rerank-v3 are cross-encoder rerankers used for second-stage precision over top-100 candidates from bi-encoder recall.
Sign in to see more production examples.

What an interviewer would ask next. Try answering before peeking at the approach.

QHow does ColBERT's late-interaction architecture sit between bi-encoder and cross-encoder?
A

ColBERT encodes query and document into per-token embeddings (not pooled), so storage is more expensive than bi-encoder. Scoring uses MaxSim: for each query token, find the max similarity to any document token, then sum. This captures some cross attention like interaction without rerunning the model per pair. Documents can be precomputed (storing per-token embeddings) and queries score against them with MaxSim, sub-quadratic cost. Accuracy lands between bi-encoder and cross-encoder, latency lands closer to bi-encoder.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

Mistaking the bi-encoder for using cross-attention between query and document. Bi-encoders run independent forward passes with zero cross-modal attention; the dot product between pooled embeddings is what couples them at scoring time.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • Describe the bi-encoder architecture and how it produces a score

  • Describe the cross-encoder architecture and what it concatenates

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Explain scaled dot product attention.
Short answer·Medium