Modeladvanced
Dual encoder retrieval model
Also called bi-encoder, two-tower model.
Encodes queries and items separately into one vector space, so item vectors are precomputed and retrieval is a nearest neighbor search.
A dual encoder scores a query and an item by , where and are two encoders into that never see each other's input. Because does not depend on the query, all item vectors are computed once, offline, and answering a query is one call of followed by a maximum inner product search over the stored vectors. The maximum-inner-product-search and HNSW pages are about that search; this page is about the scoring model that produces the vectors: what it costs, what scores it can and cannot express, and how it relates to the other neural ranking models. Dense passage retrieval is one way to train a dual encoder. The encoders themselves, and how good their vectors are, lie outside this model.
The machine
The model has three parts.
- Two encoders. maps a query and maps an item to a vector in . They may share weights (a Siamese encoder) or not. Any function is allowed, but it sees only its own input.
- A similarity. Usually the inner product ; the cosine similarity is the inner product of the normalized vectors. Some systems divide by a temperature during training, which does not change the order of the scores.
- An index. The item vectors are stored, and a query asks for the items of largest score. An exact search scans all vectors; an approximate nearest neighbor index such as HNSW or product quantization answers faster with some recall loss.
The model splits the work into an offline phase, encoding all items and building the index, and an online phase, encoding one query and searching.
What it counts
The model counts encoder calls, vector operations and stored numbers.
- Offline: calls of , and stored numbers, plus the index.
- Per query: one call of , and the search, which costs for an exact scan plus to keep the top , or less with an index.
- Per new item: one call of and one insertion into the index. Nothing else changes.
A cross-encoder, which reads the query and the item together, needs encoder calls per query for the same full ranking, since nothing can be computed before the query arrives. This gap, one call against , is what makes dual encoders the standard first stage of neural retrieval.
A worked case. Take and three items with , , .
| item | inner product | cosine |
|---|---|---|
| a | 2.0 | 0.8944 |
| b | 1.5 | 0.9487 |
| c | 1.0 | 0.4472 |
By inner product the order is a, b, c; by cosine it is b, a, c. The norm of an item vector acts as a query-independent prior on the item, which the inner product keeps and the cosine removes. A system must train and search with the same similarity.
Relation to other models
- Vector space model and BM25. Classic lexical retrieval is a dual encoder with hand-made sparse vectors: a query vector with one entry per query term and a document vector of term weights, and the inverted index is its search structure. BM25 is the inner product of a query vector of IDF weights and a document vector of saturated term frequencies.
- SPLADE. A learned sparse dual encoder: both encoders output vectors over the vocabulary, most entries zero, scored by the inner product on an inverted index.
- ColBERT. Keeps the separate encoders but outputs one vector per token and scores by a sum of maxima. This is late interaction: more expressive than one inner product, at the cost of storing one vector per token.
- Cross-encoder. Reads query and item together and can use any interaction between them. It is more expressive and cannot precompute anything, so it is used to rerank a short list from a dual encoder.
- Knowledge distillation. Dual encoders are often trained to match the scores of a cross-encoder, which links the two models in practice.
Known results in the model
Low rank. For queries and items, the matrix of scores has rank at most . Conversely, any matrix of rank at most is the score matrix of some dual encoder of dimension on these queries and items: factor it as , for example by the singular value decomposition, and let the encoders output the rows of and . So the dimension bounds exactly which score tables a dual encoder can reproduce on a fixed set of inputs.
Few orders of the items. Fix item vectors in . The order of the items for a query vector changes only when crosses one of the hyperplanes , all through the origin. So the number of distinct orders is at most the number of regions of this arrangement. For there are at most 2 orders: the items sorted by their single coordinate, upward or downward. For , the direction of moves on a circle, which the lines cut into at most arcs, so there are at most orders. For items that is at most 12 of the 24 orders, and 4 random points in the plane give exactly 12. For general , the standard count of regions of hyperplanes through the origin bounds the number of orders by , which is polynomial in for fixed , while is not. A dual encoder of small dimension therefore cannot give every query its own arbitrary order of the items, whatever the encoders are. A query-dependent model such as a cross-encoder has no such limit.
Exact search is a reduction. Retrieval under the model is exactly maximum inner product search over fixed vectors; any guarantee of the search structure, exact or approximate, carries over to the retrieval step and no further, since the vectors may rank relevant items low.
Measured effectiveness. How well trained dual encoders retrieve relevant items is an empirical matter. For example, Karpukhin et al. (2020), Table 2, measured a top-20 retrieval accuracy of 78.4 for their dual encoder against 59.1 for BM25 on the Natural Questions test set.
References
- Po-Sen Huang, Xiaodong He, Jianfeng Gao, Li Deng, Alex Acero and Larry Heck, Learning deep structured semantic models for web search using clickthrough data, Proceedings of the 22nd ACM CIKM, 2013, pp. 2333-2338 (an early neural model that maps queries and documents separately to vectors and scores them by their similarity)
- Vladimir Karpukhin, Barlas Oguz, Sewon Min, Patrick Lewis, Ledell Wu, Sergey Edunov, Danqi Chen and Wen-tau Yih, Dense passage retrieval for open-domain question answering, Proceedings of EMNLP 2020, pp. 6769-6781; Section 3.1 and Equation (1) (the inner product of a question vector and a passage vector), Section 5.4 (an index over precomputed passage vectors)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag FHA02A Edit this page History Report an error Markdown