Skip to content

LearnRepresent

Bi-encoder

Dual encoder · Two-tower model

A retrieval model that encodes the query and each passage separately into vectors, so passage vectors can be computed once at ingest and compared by similarity.

In DocSlurpGlossary entry

On this page

A bi-encoder runs the query and each passage through an encoder separately, producing one vector for each, and scores the pair by comparing the vectors, usually with cosine similarity. “Bi” refers to the two independent passes. The query and passage encoders are often the same model.

The independence is the point. Passage vectors don’t depend on the query, so you compute them once at ingest and store them. At query time you embed one short question, about one model call, then compare it with millions of stored vectors through a vector index. That’s what makes semantic search fast.

Compare a cross-encoder, which reads query and passage together in one pass. It sees how every word of the question relates to every word of the passage, so it’s more accurate, but nothing can be precomputed: scoring 1,000 candidates means 1,000 model calls at query time.

Bi-encoder Cross-encoder
Passages processed once, at ingest again for every query
Query-time cost one embedding plus vector search one model call per candidate
Sees word-to-word interactions no yes
Typical role first-stage retrieval reranking a shortlist

The standard design uses both: a bi-encoder retrieves the top 50 or 100 candidates, and a cross-encoder reorders them. Late interaction is a middle path that keeps per-token vectors.

The gotcha: some bi-encoders are asymmetric and expect different prefixes for queries and passages, such as query: and passage: for E5 models. Leaving the prefixes off, or using the same one on both sides, quietly lowers quality. Check the model card.

In DocSlurp

In DocSlurp

Text search is bi-encoder retrieval: the embed stage encodes chunks at ingest (core/worker/src/stages/embed.ts) and search embeds the query with the same model, caching it per organization (core/server/src/search/embedding-cache.ts).

Sources

Jump to