Sub topic 2
Why bi-encoder similarity is not enough
This chapter assumes you can read basic Python and have used text embeddings for vector search. It also assumes you know roughly what a transformer does and the terms query, document, and relevance. You do not need to have trained any models.
The previous chapter placed reranking after first-stage retrieval. Here you will see why that first stage cannot be the final word on ranking. The cause is how a bi-encoder is built, not how well it is trained.
What a bi-encoder computes
A bi-encoder is a model that encodes the query and each passage separately. Each encoding produces one fixed-size vector, and relevance is a similarity function over the two vectors, usually cosine similarity or dot product.
score(query, passage) = sim(f(query), f(passage))The function f never sees both texts at once. When the model encodes a passage, it does not know which query will be compared against it. When it encodes the query, it does not know which passages exist.
This design is deliberate. Because passage vectors do not depend on the query, you can compute them once, store them, and index them with an approximate nearest neighbor (ANN) structure. A query then costs one forward pass plus a fast index lookup, even over millions of passages.
Where the limits come from
Two structural facts cause nearly every weakness in this section.
- Late interaction at the vector level only. The query and passage tokens never attend to each other. The model cannot check whether a specific word in the query is contradicted or satisfied by a specific phrase in the passage.
- Compression into one vector. A passage of several hundred tokens is squeezed into a vector of, for example, 384 numbers. The vector keeps the dominant topic and loses detail. The same vector must also serve every query anyone might ask about that passage.
Negation and qualifiers
Embedding models learn from data where topic overlap is a strong signal of relevance. A passage that says "refunds are available" and one that says "refunds are not available" are about the same thing, so their vectors are close. For a user asking whether a refund is possible, one of these passages answers the question and the other gives the opposite answer.
Word order and roles
"Company A acquired company B" and "company B acquired company A" contain the same words. A bi-encoder usually places them near each other, although they describe opposite events. The model has some sensitivity to order, but it is rarely enough to separate them by a wide margin.
Specific facts versus general topic
The query "What port does the service listen on?" is answered by one number in a long configuration passage. The passage vector represents the whole configuration topic. A short passage that merely mentions ports in general may land closer to the query than the long passage that contains the answer.
Multi-part queries
A query such as "reset a password without access to my email" has several constraints. A single query vector averages them. Passages that match only "reset a password" can score as high as the one passage that covers the no-email case.
Topical similarity versus answer relevance
Many bi-encoders are trained to place similar texts close together. Relevance for search is different. A question and its answer are often not similar in wording or content. Models trained for retrieval shrink this gap, but they still have to express "answers this query" using only distances between independently computed points.
Seeing it in code
The script below scores a query against three passages. Two of them differ only by the word "not". The third is on the same topic but does not answer the question.
from sentence_transformers import SentenceTransformer, util
model = SentenceTransformer("all-MiniLM-L6-v2")
query = "Can I get a refund after 30 days?"
passages = [
"Refunds are available within 30 days of purchase.",
"Refunds are not available after 30 days of purchase.",
"Our refund team works Monday to Friday.",
]
q = model.encode(query, convert_to_tensor=True, normalize_embeddings=True)
p = model.encode(passages, convert_to_tensor=True, normalize_embeddings=True)
scores = util.cos_sim(q, p)[0]
for passage, score in zip(passages, scores):
print(f"{float(score):.2f} {passage}")
pair = model.encode(
["Company A acquired company B.", "Company B acquired company A."],
convert_to_tensor=True,
normalize_embeddings=True,
)
print("role swap similarity:", round(float(util.cos_sim(pair[0], pair[1])), 2))Exact numbers depend on the model version. With small general-purpose models you will typically see the first two passages scored close together, with only a small gap between them. The role-swapped pair typically scores very high, often above 0.9. If your model separates them more cleanly, try longer passages or add more qualifiers. The point is that the gap is small compared with how different the meanings are.
Why you cannot simply fix it with a bigger embedding
It is tempting to respond with a larger model, longer vectors, or more training. These help, but they do not remove the constraint.
- A bigger encoder still encodes each text alone, so fine-grained matching still has to survive compression into a vector.
- Higher dimensions raise capacity, but also increase index memory and search cost. Research on embedding limits suggests that a fixed vector size caps how many distinct top-k result sets it can express, so some queries stay out of reach.
- Fine-tuning on your domain can make a bi-encoder much better, and is often worth doing. It improves the average case, but a fixed-size independent representation still cannot check each query term against the passage.
What the efficiency buys, and what it costs
| Property | Bi-encoder | Joint (cross-encoder) scoring |
|---|---|---|
| Passage encoding | Once, offline | Repeated for every query |
| Query-time work | One query pass plus index lookup | One model pass per query-passage pair |
| Scales to millions of passages | Yes, with an ANN index | No, too slow to score everything |
| Query tokens see passage tokens | No | Yes |
| Handles negation and roles | Weakly | Much better |
Scoring a pair jointly means a corpus of N passages needs N forward passes for each query. At a million passages, that is unworkable for interactive search. The bi-encoder is therefore the right tool for narrowing a large corpus. It is the wrong tool for deciding the final order of a handful of close candidates.
What this looks like in a real system
The bi-encoder's weaknesses show up in specific patterns. Knowing them helps you tell whether the problem is the first stage or something else.
- The right passage is in the top 50 but not the top 3. The bi-encoder recognized the topic but could not rank the best answer first. This is the case reranking is designed for.
- Near-duplicate wording with opposite meaning ranks above the answer. Negation and role-swap problems.
- Short, precise answers lose to long, topical passages. Compression dilutes the answer.
- Scores for the top 10 are nearly tied. The ordering within the group is close to arbitrary, so small changes in phrasing reshuffle it.
The idea that follows
The limitation comes from separation: the query never meets the passage inside the model. The remedy is to let it. If you feed the query and passage into one transformer as a single input, every query token can attend to every passage token. The model can then notice that "not" modifies "available" and that the query asks about "after 30 days".
That joint input is the defining feature of a cross-encoder, which the next chapter covers. Its cost is the right-hand column of the table above, which is why it is applied only to a small candidate pool that a bi-encoder has already narrowed down.
Exercise
A bi-encoder retriever returns the passage "Passwords cannot be reset by phone" at rank 1 for the query "How can I reset my password by phone?". The passage that explains the phone reset process is at rank 6. Name the two structural properties of a bi-encoder that explain this result, and explain why simply switching to a larger embedding model would not fully remove the problem. Also, what should you check first before adding a reranker?
Show answer
The query and passage are encoded independently, so query tokens never attend to passage tokens and the model cannot see that "cannot" contradicts what the query asks. Each passage is also compressed into one fixed-size vector, so the shared topic (password reset by phone) dominates and the negation is a small signal. A larger model still encodes the texts separately and still compresses each to one vector, so it narrows the gap but does not remove the cause. Before adding a reranker, check that the correct passage is in the candidate pool, which it is here at rank 6, by measuring recall@k of the first stage. A reranker can reorder the pool but cannot add passages that were never retrieved.