A support assistant answers from the company's help center through retrieval: the question is embedded, the closest passages go into the prompt. A customer asks "How do I turn off two-factor authentication?" The top result is the article on turning it on, and the archived 2022 refund policy keeps outranking the current one. The logs show high similarity scores for both. The team's first instinct is to raise the threshold. It won't help, because the scores are right: those passages really are similar to the question.
The common misconception
"If two texts have close embeddings, they mean the same thing, and the closest passage is the one that answers the question." There are good reasons to believe it:
Semantic search really is better than keyword search at paraphrases: "cancel my plan" finds "end your subscription".
Papers and product pages call these vectors semantic. The Sentence-BERT abstract promises "semantically meaningful" sentence embeddings.
Cosine similarity comes out as a tidy number near 1, which looks like a confidence score.
In demos, the top hit is almost always the right one.
It's a half-truth. Embeddings do capture a lot of meaning; paraphrases land close together. But one number compresses many kinds of relatedness, and "about the same thing" is the strongest one.
What actually happens
An is a list of numbers, a point in a space of a few hundred or thousand dimensions, that a model computes for a piece of text. What "close" means is decided by how that model was trained.
Closeness is defined by the training task
Google's Machine Learning Crash Course uses food to show it. In a model trained around time of day, cereal and breakfast sausage land close together: both are breakfast. In a model trained to separate vegetarian from non-vegetarian food, they land far apart. Neither is wrong. The course stresses that embeddings are usually task-specific and differ when the task differs.
Text embedding models work the same way. Sentence-BERT, a classic design, fine-tunes BERT on about a million sentence pairs labeled as entailment, contradiction or neutral, then compares sentences by the of their vectors. The model learns what its training pairs reward: shared topic, shared situation, shared wording. Nothing in that objective checks whether a sentence is true.
How semantic search uses it
Embed every chunk onceEach passage of your documents goes through the embedding model and its vector is stored in an index.
Embed the questionThe user's question goes through the same model at query time.
Score by closenessThe index compares the question vector with the stored vectors, usually by cosine similarity: the angle between them.
Return the top kThe k closest passages come back, ranked by score, and go into the prompt.
Notice that the last step always returns k passages. Like the next-token loop earlier in this path, there is no "not found": something is always closest.
What one number can't see
Negation and small decisive words. NevIR tested retrieval models on 2,556 pairs of documents that differ only by a negation. Most models, including state-of-the-art ones, ranked them the same as or worse than random; models that read the query and the document together did best.
Truth and freshness. An outdated policy and the current one are about the same topic in nearly the same words. The vector encodes what a text is about, not whether it's still in force.
Answering versus resembling. A question can be closer to another question phrased like it, or to a passage that repeats its words without answering them, than to the passage that holds the answer.
Exact identifiers. Anthropic's Contextual Retrieval post notes that embeddings can miss exact matches such as an error code like "TS-999", which keyword search catches.
The score isn't a confidence
Cosine similarity is geometry, not probability. Its scale depends on the model, so a score that is high for one model is ordinary for another. Steck, Ekanadham and Kallus went further: for some regularized linear models, they showed analytically that cosine similarities can be arbitrary, not even unique, and they caution against using them blindly. There is no universal threshold you can copy from a blog post.
Why we still use embeddings
Speed. Models that read two texts together, called cross-encoders, judge relevance better, but they must run once for every pair. The Sentence-BERT paper puts numbers on it: finding the most similar pair among 10,000 sentences takes about 65 hours with BERT reading pairs, and about 5 seconds with precomputed embeddings. So production systems use both: embeddings to find candidates fast, then a to judge the short list. In Anthropic's retrieval tests, combining contextual embeddings (chunks embedded with a short note about their source document) with keyword search cut the top-20 retrieval failure rate by 49% compared with plain embeddings; adding reranking made it 67%.
From nearest to relevant
Both versions below use the same embedding model and stored vectors. The first trusts closeness; the second treats it as candidate generation.
Python · retrieval.py
import numpy as npfrom vector_index import docs, doc_vecs, embed # your model and vectorsdef retrieve(question, k=3): scores = doc_vecs @ embed(question) # cosine: vectors are normalized best = np.argsort(-scores)[:k] # Always k results: on topic or not, current or not, "do" or "do not" return [docs[i] for i in best]
Python · retrieval.py
import numpy as npfrom vector_index import docs, doc_vecs, embed, rerankdef retrieve(question, min_score, k=50, keep=5): # min_score: calibrated on labeled question/passage pairs for THIS model scores = doc_vecs @ embed(question) hits = [i for i in np.argsort(-scores)[:k] if scores[i] >= min_score] if not hits: return [] # the app says "not in our docs" instead of guessing # A reranker reads the question and each passage together judged = rerank(question, [docs[i] for i in hits]) return [docs[hits[i]] for i in np.argsort(judged)[::-1][:keep]]
The right version can return nothing, pulls a wider net before judging, and lets a model that reads both texts pick the final passages. The LLM still has to answer only from what it was given, and to say when the passages don't answer the question.
Myth
Reality
Close embeddings mean the same thing
They mean related in the way the training rewarded: topic, wording, context
The top passage answers the question
It resembles the question; something that reads both must judge
A high score means the content is right
A wrong or outdated passage on the same topic scores just as high
0.8 is a safe threshold
Score scales differ by model; calibrate on your own labeled pairs
No good match returns nothing
The top k always come back
How to apply it in your project
Treat vector search as candidate generationRetrieve more than you need and judge the short list with a reranker, not with the raw score.
Make "nothing relevant" a real outcomeCalibrate a minimum score per embedding model and handle the empty result, so the assistant can say the docs don't cover it.
Keep truth outside the vectorStore dates, versions and status as metadata, filter out archived or superseded documents, and re-embed when content changes.
Combine search methods for exact termsAdd keyword search for IDs, error codes and product names, and merge its results with the vector results before reranking.
Key takeaways
An embedding's closeness means "related" in the sense its training rewarded, not equivalent, correct or current.
Negation, freshness and exact identifiers are where vector closeness is weakest.
Cosine scores aren't confidences, and their scale differs by model: calibrate on your own data.
Vector search always returns its top k; design for "nothing relevant".
Use embeddings to find candidates fast, and a reranker and the LLM to judge them.
التعليقات (0)