Sub topic 2
Why Bi-Encoder Similarity Is Not Enough
This chapter assumes you know basic Python, text embeddings, vector similarity search, and the terms query, document, and relevance. It explains what a bi-encoder cannot represent. That limit is the reason rerankers exist.
How a bi-encoder scores a pair
A bi-encoder is a model that encodes the query and the passage separately. Each text becomes one fixed-size vector, and relevance is the cosine similarity between the two vectors.
Passage vectors do not depend on the query, so you compute them once and store them in an index. At query time you encode only the query and run a nearest-neighbor search. This is why bi-encoders scale to millions of passages.
Where the limits come from
The query and passage never see each other inside the model. Three limits follow from that.
- Compression. A whole passage is squeezed into one vector, often 384 to 1024 numbers. Details that matter for one specific query can be lost in that summary.
- No token-level interaction. The model cannot check whether a word in the query is answered by a particular phrase in the passage. It only compares overall meaning.
- Query-independent representation. The passage vector is the same for every query. It cannot emphasize the part of the passage that a given query asks about.
Common error patterns
These patterns appear often in bi-encoder results.
| Pattern | Example query | Likely wrong match |
|---|---|---|
| Topic match without an answer | How do I rotate an API key? | "Our API supports JSON and XML." |
| Negation and qualifiers | Which plans do not include SSO? | A passage listing plans that include SSO |
| Role reversal | Who acquired the startup? | A passage about the startup acquiring another company |
| Exact details | Error code E1042 | A passage about a similar error code |
In each row the wrong passage shares vocabulary and topic with the query. The vectors are close because the topics are close. Relevance depends on a finer relationship that one vector per text does not capture.
What a cross-encoder changes
A cross-encoder takes the query and passage as one input sequence. Every query token can attend to every passage token inside the transformer. The output is a single relevance score for that pair.
The cost is that nothing can be precomputed. Each (query, passage) pair needs a full model pass. Scoring a whole corpus per query is too slow, so cross-encoders handle only a short candidate list from a bi-encoder or lexical search. The next chapters build on this.
Seeing the gap in code
This script compares a bi-encoder with a cross-encoder on a negation query. Exact scores vary by model version, but the ordering shows the point.
from sentence_transformers import SentenceTransformer, CrossEncoder, util
query = "Which plans do not include SSO?"
passages = [
"The Enterprise and Business plans include SSO.",
"The Free and Starter plans do not include SSO.",
]
bi = SentenceTransformer("all-MiniLM-L6-v2")
q_emb = bi.encode(query, normalize_embeddings=True)
p_emb = bi.encode(passages, normalize_embeddings=True)
print("bi-encoder:", util.cos_sim(q_emb, p_emb)[0].tolist())
ce = CrossEncoder("cross-encoder/ms-marco-MiniLM-L-6-v2")
print("cross-encoder:", ce.predict([(query, p) for p in passages]).tolist())Expect the two bi-encoder similarities to be close together, since both passages talk about plans and SSO. A cross-encoder usually separates them more clearly. If your versions disagree, that is itself a useful reminder to measure rather than assume.
Exercise
A user asks "Who sued the supplier?" The bi-encoder returns a passage saying "The supplier sued the customer" at rank 1. Give two reasons from this chapter that explain why this happens.
Show answer
The passage is compressed into one vector that mostly captures its topic (a lawsuit involving a supplier), so word roles are weakly represented. Also, the query and passage are encoded separately, so no token of the query is compared with the passage's subject and object. A cross-encoder reads both together and can notice the role reversal.