What is a bi-encoder?
A bi-encoder is a retrieval model architecture that encodes the query and the document independently and measures relevance by the similarity of the two vectors, so document vectors can be computed and indexed ahead of time.
It differs from a cross-encoder in the speed and accuracy trade-off: a cross-encoder reads query and document together, more accurate but computed per pair, while a bi-encoder computes document vectors once and encodes only the query at search time. Dense retrieval is built on this architecture.
- Topic
- Embeddings, document processing and RAG
- Also known as
- Dual encoder, two-tower model
How a bi-encoder works
- During ingestion documents pass through the encoder and are written to a vector index.
- When a query arrives only the query is encoded; most setups use the same model for both.
- The query vector is searched in the index with approximate nearest neighbour search.
- The model is trained with contrastive learning, pulling matching query and document pairs together while pushing others apart.
In more detail
The single-vector bottleneck and hybrid search
Compression into a single dense vector creates an information bottleneck for long documents, exact identifiers (part numbers, legal article IDs) and multi-faceted queries. In production RAG, bi-encoders are therefore commonly paired with sparse retrieval (BM25 or SPLADE) in hybrid search and optionally with late-interaction models (ColBERT) or a cross-encoder reranker.
Hard negatives and InfoNCE training
Bi-encoder training typically uses contrastive objectives (such as InfoNCE) with in-batch negatives and mined hard negatives, documents that look lexically close to the query yet do not answer it. Without hard negatives, models often over-rely on surface keyword overlap and underperform on domain-specific distinctions.
Matryoshka truncation and multimodal bi-encoders
Modern bi-encoders increasingly support Matryoshka Representation Learning (MRL), allowing embeddings to be truncated (e.g., from 1024 to 256 dimensions) at search time with modest accuracy loss. They are also often multimodal (such as CLIP or SigLIP) aligning text and images in a shared vector space.
Commonly confused terms
| Term | How it differs |
|---|---|
| Late-interaction model (ColBERT) | Late-interaction models (such as ColBERT) pre-compute token-level embeddings independently like a bi-encoder, but preserve one vector per token rather than pooling into a single vector, computing MaxSim at query time for finer matching. |
| Sparse encoder (BM25 and SPLADE) | Sparse encoders (such as BM25 or SPLADE) represent text over vocabulary-sized term weights and excel at exact codes, product SKUs and rare acronyms, whereas dense bi-encoders capture semantic similarity in low-dimensional continuous vectors. |
Why a bi-encoder matters for on-premises AI
The bi-encoder is the architecture enabling fast search over large company archives, with heavy computation done once at ingestion. Since query and document never see each other, it can miss subtle relevance differences, so in-house RAG often retrieves first with a bi-encoder and ranks last with a cross-encoder. Fine-tuning on the organisation's own question and document pairs can raise accuracy on domain terms. Changing the model means recomputing all document vectors.
A manufacturer embeds its maintenance manuals with a bi-encoder; an operator's question is encoded once and relevant sections are found quickly across the whole manual archive.
Common questions
How does a bi-encoder differ from a cross-encoder?
A bi-encoder turns query and document into separate vectors; it is fast and suits first-stage retrieval. A cross-encoder reads both together; it is more accurate but slower, so it is used for reranking.
Is the same model used for queries and documents?
In most setups, yes. Some models use separate encoders or different prefixes for queries and documents; follow the format stated in the model's documentation.
Related terms
- Cross-encoder
- Dense retrieval
- Embedding model
- Vector index
- Approximate nearest neighbour search
- Contrastive learning
- Sentence embedding
Sources
- Reimers and Gurevych, Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks, 2019
- Karpukhin et al., Dense Passage Retrieval for Open-Domain Question Answering, 2020
In the glossary: Glossary, A to C