Bi-encoder retrieval is the architecture behind most modern semantic search, and it works by encoding the query and each document separately into vectors, then comparing those vectors. The short answer to why it matters is speed: because document vectors are computed once and stored, a query needs only one encoding and a fast nearest-neighbour lookup, however large the collection grows. That is what makes semantic search practical at scale.
The design was crystallised by Reimers and Gurevych in their 2019 Sentence-BERT paper, which showed that a siamese BERT network could produce sentence embeddings comparable with cosine similarity. Their headline result was striking: finding the most similar pair among 10,000 sentences took about 65 hours with a BERT cross-encoder but only about 5 seconds with the bi-encoder approach. Bi-encoders have been the default first-stage retriever for semantic search and RAG ever since.
Key takeaways
- A bi-encoder encodes the query and each document independently into fixed-size vectors.
- Similarity is a cheap vector comparison, usually cosine similarity or dot product.
- Document vectors are precomputed once, so query-time cost stays low at any collection size.
- Bi-encoders handle paraphrases and synonyms well but blur exact terms and fine detail.
- Pair a bi-encoder with a cross-encoder reranker when ranking precision matters.
How bi-encoder retrieval works
A bi-encoder, also called a dual encoder, has two sides that share the same model. One side reads the query and produces a vector; the other reads a document and produces a vector. The relevance score is the similarity between the two vectors, most often cosine similarity or a dot product.
The crucial property is independence. The document encoder never sees the query, and the query encoder never sees the document. That means every document in the collection can be encoded once, offline, and stored in a vector index. At query time the system encodes only the query, then asks the index for the nearest document vectors.
Training teaches the model to place relevant pairs close together and irrelevant pairs far apart. Typical training uses contrastive pairs: a query with a relevant passage and one or more irrelevant passages, with the loss pushing the relevant pair together and the others apart. Hard negatives, passages that look relevant but are not, are the most valuable training examples.
Best for: semantic search, RAG first-stage retrieval, duplicate detection and any task where a query must be matched against a large collection quickly.
From text to vector
The encoder is usually a transformer such as BERT or a smaller model built on the same idea. It reads the text and produces a vector for each token, then pools those token vectors into a single fixed-size representation, often by averaging them or by taking the vector of a special [CLS] token. That pooled vector is the embedding.
The pooling step is where information is lost. A passage of several hundred words is compressed into a few hundred numbers, and fine detail, such as a single name or number, may not survive. That compression is the fundamental trade-off of the bi-encoder: it buys speed by giving up the token-level detail that a cross-encoder keeps.
Embedding dimension matters. Larger vectors carry more information but cost more storage and slower search. Common sizes range from a few hundred to over a thousand dimensions, and the choice is usually dictated by the model rather than tuned by the user.
Similarity and nearest-neighbour search
Once the vectors exist, retrieval is a nearest-neighbour problem: find the document vectors closest to the query vector. Exact search compares the query against every document vector, which is fast enough for small collections but too slow for millions of documents.
Large collections therefore use approximate nearest-neighbour, or ANN, indexes. These indexes organise vectors into structures such as graphs or clusters so that a query can find good neighbours without scanning everything. The approximation costs a little accuracy, typically a small loss in recall, in exchange for a large gain in speed.
Our guide to approximate nearest neighbour search explains the main index types, and the HNSW index guide covers the graph-based method most vector databases use.
Bi-encoder retrieval vs sparse retrieval
Bi-encoders and sparse methods such as BM25 fail in opposite ways. The bi-encoder understands meaning but blurs exact terms; BM25 matches exact terms but cannot understand meaning. A query for a specific error code is a BM25 job, while a query describing a problem in everyday language is a bi-encoder job.
Most production systems therefore use both, merging the results in a hybrid retriever. Our comparison of dense retrieval vs sparse retrieval covers that trade-off in detail, and the guide to hybrid search in RAG explains how to combine the two scores.
Best for: paraphrase-heavy queries, natural-language questions and collections where users describe what they want rather than naming it.
Bi-encoder retrieval vs cross-encoder reranking
The cross-encoder is the bi-encoder’s accurate but slow counterpart. It reads the query and passage together and scores them with full attention, which makes it better at close calls. But it cannot precompute anything, so it can only rerank a shortlist.
The standard architecture uses both: the bi-encoder retrieves a shortlist of candidates quickly, and the cross-encoder reranks them accurately. Our guide to cross-encoder reranking explains the second stage, and ColBERT retrieval covers the middle ground, where token-level vectors preserve more detail than a single bi-encoder vector.
| Dimension | Bi-encoder | Cross-encoder | BM25 |
|---|---|---|---|
| Encoding | Query and document separately | Query and document together | No model; term counts |
| Precompute documents | Yes | No | Yes, inverted index |
| Query cost | One encoding plus lookup | One pass per candidate | Very low |
| Synonyms and paraphrase | Handled well | Handled well | Missed |
| Exact terms and codes | Often blurred | Good | Excellent |
| Explainability | Low | Low | High |
| Typical role | First-stage retrieval | Second-stage reranking | First stage or hybrid half |
Choosing an embedding model
The embedding model is the single most important choice in a bi-encoder system, because it decides what “similar” means. Models differ in size, language coverage, training data and the tasks they were tuned for. A model trained for general semantic similarity may perform poorly on retrieval, where the query and the document are different kinds of text.
Start with a well-known retrieval-tuned model and evaluate it on your own queries. Public benchmarks are a useful filter, but they do not predict performance on your documents. Build a small test set of real queries with labelled relevant passages and measure recall before committing to a model.
Our guide to RAG embedding models covers model selection and tuning in more depth, including how to compare models fairly on the same test set.
Best for: teams that need a proven starting point; pick a retrieval-tuned model, measure on your own data, and change only when the measurements justify it.
Fine-tuning a bi-encoder
Fine-tuning adapts a general embedding model to your domain. It needs labelled pairs of queries and relevant passages, plus hard negatives. The most useful hard negatives come from your own system’s mistakes: passages your current retriever ranked highly that annotators judged irrelevant.
Fine-tuning is powerful but easy to get wrong. Training on too little data, or on data that does not match real queries, can make the model worse. A common safe pattern is to start with the public model, collect failure cases for a few weeks, and only then fine-tune on those cases. If the public model already performs well, the gain from fine-tuning may not justify the effort.

Using bi-encoder retrieval in RAG
In a RAG pipeline, the bi-encoder is usually the first stage. It retrieves the top candidates, often 50 or 100 passages, which are then reranked and passed to the language model. The quality of those candidates sets a ceiling on the final answer: if the right passage is not retrieved, the generator cannot use it.
Chunking shapes what the bi-encoder can find. A passage that mixes several topics produces a vector that is a blend of them, and may not match any single query well. Short, focused chunks give cleaner vectors and better retrieval. Our guide to RAG chunking strategies covers how to choose chunk size and overlap.
Index freshness is another operational concern. When documents change, their vectors must be recomputed, and when the model changes, the whole collection must be re-indexed, because vectors from different models cannot be compared. Plan re-indexing as a regular job, not as an afterthought. Our guide to RAG incremental indexing explains how to keep an index fresh without rebuilding it from scratch.
When a bi-encoder struggles
Bi-encoders struggle with long documents, because a single vector cannot represent everything a long text says. They struggle with exact matching, because a name or code is a small part of the overall meaning. And they struggle with queries that are very different in form from the documents, such as a short keyword query against long prose.
Each of these has a remedy. Long documents need smaller chunks. Exact matching needs BM25 alongside. Mismatched query forms need query rewriting or expansion, covered in our guide to RAG query rewriting. The skill is recognising which failure you are seeing, because each points to a different fix.
Implementation checklist
- Choose a retrieval-tuned embedding model and test it on your own labelled queries.
- Index focused chunks, not whole documents, so each vector represents one idea.
- Use an ANN index for collections beyond a few tens of thousands of passages.
- Measure recall at the depth your reranker and generator actually read.
- Pair the bi-encoder with BM25 in a hybrid retriever when exact terms matter.
- Add a cross-encoder reranker when ranking precision decides answer quality.
- Plan full re-indexing whenever the embedding model changes.
Common mistakes to avoid
The most common mistake is comparing vectors from different models. Embeddings are only comparable within the space of the model that produced them, so mixing models, or forgetting to re-encode the collection after a model change, silently breaks retrieval. Version your model and your index together.
Another mistake is judging the bi-encoder by the generator’s answers. A strong language model can answer from its own knowledge even when retrieval failed, which hides the problem. Measure retrieval recall separately, with labelled data, so you know what the retriever is doing.
A third mistake is using the wrong similarity measure. Cosine similarity and dot product give different rankings when vectors are not normalised, and the choice should match how the model was trained. Check the model’s documentation rather than assuming one or the other.
Frequently asked questions
What is a bi-encoder?
A bi-encoder, also called a dual encoder, encodes a query and a document separately into vectors and scores them by vector similarity. Because documents are encoded once and stored, it can search large collections quickly.
How is a bi-encoder different from a cross-encoder?
A bi-encoder encodes the two texts independently and compares vectors, which is fast and scalable. A cross-encoder reads them together with full attention, which is more accurate but too slow to search a whole collection, so it is used to rerank a shortlist.
What similarity measure do bi-encoders use?
Usually cosine similarity or dot product. The right choice depends on the model and whether its vectors are normalised, so check the model’s documentation before choosing.
Do bi-encoders need a GPU?
Encoding a large collection is much faster on a GPU, but query-time encoding of a single question is fast on a CPU. Small collections can be indexed on a CPU if you are patient.
Why does my bi-encoder miss exact matches?
Because a single vector summarises the whole passage, and a specific name, code or number can be lost in that summary. Pair the bi-encoder with BM25 in a hybrid retriever to cover exact matching.
When should I fine-tune a bi-encoder?
Fine-tune when a public model shows systematic errors on your domain that your own labelled pairs could fix. Start with the public model, collect failure cases, and fine-tune only when the evidence justifies it.







