Bi-encoders vs cross-encoders, where does attention cross the query and document?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
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.
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.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
7 min: bi-encoder vs cross-encoder structural split, document precomputation property, scoring mechanisms, accuracy vs throughput trade-off, two-stage retrieval pipeline, ColBERT as a middle-ground architecture, hybrid sparse-dense first-stage retrieval.
| Property | Bi-encoder | Cross-encoder |
|---|---|---|
| Input structure | Query and document encoded separately | Concatenated into one sequence |
| Cross-modal attention | None | Full self-attention across the boundary |
| Scoring | Dot product of pooled embeddings | Classification head on [CLS] |
| Document precomputation | Yes (one forward pass per document offline) | No (every query-document pair needs fresh pass) |
| Inference cost per query | 1 forward pass + N dot products | N forward passes |
| Scalability | Billions of documents with ANN index | Thousands at most |
| Accuracy | Lower (pooled embeddings lose token-level signal) | Higher (full token-level interaction) |
| Typical role | First-stage recall | Second-stage rerank |
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
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.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.