The problem: comparing a million sentences in milliseconds
You have a million documents. A user types a query. You want to hand back the ten most relevant documents right now.
Real cases:
- Search engine: a billion web pages, find the best ten in under a second
- Deduplication: millions of product records, spot the duplicates
- Recommendation: offer each user items close to the ones they liked
- RAG (Retrieval-Augmented Generation): among tens of thousands of technical passages, find the ones that answer a question
What these four have in common: they all need a way to measure how alike two pieces of text are that is fast enough to run millions of times.
A word embedding is not a sentence embedding
This distinction governs everything that follows, and it is subtler than it looks.
A word embedding is a vector (a list of numbers) attached to a word in the vocabulary. It is the object built by Word2Vec and GloVe, covered in Word2Vec and GloVe and FastText. Its virtue: words with related meanings end up near each other.
A sentence embedding is a single vector attached to a whole utterance, a sentence, a paragraph, a chunk of documentation. Its hoped-for virtue: two utterances that mean the same thing end up near each other, even when they share no words at all.
Why not just average the words?
That is everyone's first idea: a ten-word sentence gives ten vectors, take their average, and there is your sentence vector. It works a little (well enough to serve as an honest baseline) but three flaws stop it going far.
1. An average ignores order. "The dog bit the man" and "The man bit the dog" contain exactly the same words. Their average is therefore exactly the same vector, even though the two sentences say opposite things. All the syntax vanishes in the operation.
2. Function words weigh as much as the rest. In "the commission rate is three percent", the words carrying the meaning (rate, commission, three percent) are in the minority. The average drowns them among the the, is, a. What comes out looks mostly like the vector of an average English sentence.
3. A word does not have one meaning, it has several. A static word embedding assigns a single vector to "bank": the same one in "the bank refused the loan" and "the bank of the river". The average inherits that confusion.
The next trap: averaging BERT's vectors doesn't fix it either
You might expect the problem to disappear if you swap static vectors for BERT's, which are contextual: in BERT, "bank" gets a different vector depending on the sentence it appears in, and word order is genuinely taken into account. The first two flaws look settled.
Except the similarity measure does not improve. The SBERT paper reports that averaging the vectors of an un-finetuned BERT yields similarity scores worse than simply averaging GloVe embeddings, and that using the vector of the [CLS] token (classification, the special token placed at the head of the sequence) is worse still.
The reason is instructive. BERT was trained to guess masked words, never to produce a space in which the angle between two vectors would mean anything. Nothing in its training pushes it to hold two differently-meaning sentences apart. The vectors it produces all bunch into a narrow region of the space, so that almost any two sentences look close. The measuring instrument exists, but it has no graduations.
A detail that often surprises: SBERT, the solution this lesson is about, does average its token vectors. So averaging is not the culprit. What changes is that the encoder is retrained first, with an objective that explicitly rewards putting related sentences close together. Once that training is done, the average becomes a good summary. Before it, the average summarizes a space that means nothing.
The other, expensive approach: asking BERT to compare
There is a way of comparing two sentences with BERT that does work very well: feed them in together.
[CLS] Sentence A [SEP] Sentence B [SEP] β BERT reads the whole thing at once β a small output layer reads the [CLS] vector and returns a similarity score
([SEP], for separator, is the special token marking the boundary between the two sentences.) This architecture is called a cross-encoder: the two texts meet inside the network, every word of A able to look at every word of B. The quality is excellent.
Its flaw is fatal for search: it takes one full pass through the network per pair of sentences. Nothing can be prepared in advance, since A's vector depends on B.
The SBERT paper puts a number on what that costs. Finding the most similar pair in a collection of 10,000 sentences means examining every possible pair:
That formula is the number of ways of choosing two items out of : each of the sentences can be paired with the other , and you divide by 2 because the pair (A, B) is the same as the pair (B, A). At one network pass per pair, the authors report this comes to roughly 65 hours of compute. With SBERT, the same search takes about 5 seconds.
Sentence-BERT: Sentence Embeddings using Siamese BERT-NetworksPlenty of language-processing systems fail not on the quality of their algorithm but on response time. The gap between 65 hours and 5 seconds is not a convenience gain: it is what separates a lab demo from a usable service.
SBERT: the idea that changes everything
SBERT (Sentence-BERT, Reimers and Gurevych, 2019) fine-tunes BERT for a single job: producing sentence vectors that are directly comparable to one another.
The architecture: the bi-encoder
Instead of passing both sentences in together, SBERT passes each sentence on its own:
- Sentence A β BERT β average of the token vectors β vector
- Sentence B β BERT β average of the token vectors β vector
Both passes use exactly the same weights: one and the same copy of BERT, applied twice, which is what makes it a siamese architecture. Worth restating the distinction: the weights are learned parameters, frozen once training ends; and are computed values, produced from the sentences you submit.
The decisive consequence: since A's vector does not depend on B in any way, each document can be encoded once and for all and reduced to its vector.

What precomputation changes
The work splits into two moments, and that is the whole trick.
Once, offline: encode the documents. One network pass per document, and you store the resulting vector. This work is proportional to the number of documents ( passes for documents) not to the number of pairs.
On every query: a single network pass, for the query. Then a comparison of vectors against the stored ones, which is arithmetically trivial next to a pass through a neural network.
| Cross-encoder | Bi-encoder (SBERT) | |
|---|---|---|
| Network passes to index documents | 0 (nothing can be prepared) | , once |
| Network passes per query | 1 | |
| What gets compared to the query | nothing reusable | already-computed vectors |
Network passes per query drop from to 1. That, and nothing else, is where the 65 hours turned into 5 seconds.
Training: learning what counts as alike
What remains is to obtain that encoder whose average means something. You fine-tune it on annotated sentence pairs, following one of these recipes.
Recipe 1, Semantic Textual Similarity (STS): start from pairs of sentences scored by humans on a 0-to-5 scale. The loss is mean squared error (MSE: the average of the squared gaps) between the cosine the model produces and the human score. The model thus learns to grade resemblance.
Recipe 2, Natural Language Inference (NLI): start from pairs labelled according to whether the second sentence follows from the first (entailment), contradicts it, or is unrelated. During training you encode the two sentences separately into and , then string together , and , the component-by-component difference in absolute value, which shows on which dimensions the two sentences diverge, and put a three-class classifier on top.
Recipe 3, contrastive learning: within a batch of examples, pull the pairs that belong together closer and push the others apart. This is the principle most recent models rely on.

The natural-language-inference corpora (SNLI (Stanford Natural Language Inference) and MultiNLI) had been built for an entirely different task, and hold hundreds of thousands of sentence pairs already labelled by humans. SBERT repurposes them: a label saying "the second follows from the first" is a perfectly usable signal of closeness in meaning. Reusing an existing annotation for a purpose it was never designed for is a very common move in this field.
Technical corner: cosine similarity
This is the comparison measure used everywhere in the field:
Reading the symbols:
- and : the two vectors being compared, each a list of a few hundred numbers
- : the dot product, the sum of the term-by-term products
- : the norm of , that is, its length, the square root of the sum of the squares of its components
In one sentence: you divide the dot product by the lengths of the two vectors, which amounts to keeping only the angle between them and forgetting how long they are. These notions are laid out in norms and distances.
The result is a number between and :
- : same direction
- : perpendicular directions, no relation
- : opposite directions
Careful how you read the values
You often see rules of thumb like "above 0.9 it's a paraphrase, below 0.3 it's unrelated". These are empirical habits, specific to each model, not universal thresholds: two different embedding models do not place their scores on remotely the same range. A model may well never drop below 0.6, even between two texts that have nothing to do with each other. The only honest way to set a threshold is to calibrate it on your own data with the model you actually use. What is comparable is the ranking of the scores, not their absolute value.
The normalization shortcut
Many models return vectors that are already normalized, that is, rescaled to length 1. Both norms in the denominator are then equal to 1, and the formula collapses to:
A plain dot product, then: no division, no square root. Across millions of vectors that is compute saved for nothing lost, which is why the trick is worth knowing.
The semantic search pipeline
- Indexing: encode every document, store the vectors
- Query: encode the question
- Search: find the vectors closest to the query's
- Results: return the top
Past a few million vectors, comparing the query against every single one gets too slow. You then move to Approximate Nearest Neighbors (ANN) search, which accepts occasionally missing the best candidate in exchange for a far faster search. That is the business of vector databases, and the choice between vector search and keyword search is covered in dense, sparse or hybrid.
The matter of dimensions
A sentence vector typically holds a few hundred to a few thousand numbers. That choice is not neutral: more dimensions means a finer measure, but also more memory and a slower search, both multiplied by the number of documents. There is a way of training a model so that one and the same vector stays usable once truncated, which lets you settle this trade-off after the fact rather than at indexing time: see Matryoshka embeddings.
RAG, the main application of sentence embeddings
RAG means having a Large Language Model (LLM) answer by first handing it the relevant passages from a document base, instead of letting it answer from memory. The full mechanism, its variants and its evaluation have a lesson of their own: RAG: principle and architecture.
What matters here is the place sentence embeddings occupy in it. You cut the documentation into passages, encode each passage once, and on every question encode the question and retrieve the passages whose vector is closest. In other words, it is the quality of the embedding that decides what the model gets to look at.
A RAG system is never better than its retrieval. If the passages that come back do not contain the answer, no language model, however good, can produce it: at best it says it does not know, at worst it fills the gap itself. Choosing and fine-tuning the embedding model therefore matters far more than polishing the instructions you give the model.
Today's models
SBERT set the pattern, and the models used in production in 2026 are no longer SBERT itself: E5 (Microsoft), BGE (BAAI General Embedding, from the Beijing Academy of Artificial Intelligence), and the embedding models offered through the interfaces of OpenAI, Cohere or Mistral. The principle (a bi-encoder fine-tuned by contrastive learning so that the cosine means something) is still SBERT's; what changed is scale, data, and multilingual coverage. The up-to-date comparison is in text embeddings: models and choices.
To compare these models against one another, the shared reference is MTEB (Massive Text Embedding Benchmark), a collection of dozens of evaluation tasks on which everyone publishes their scores.
The two-stage strategy
In production you almost never stop at a cosine. You combine the two architectures seen above, each where it is good.

Stage one, the bi-encoder: the query is encoded, and approximate search brings back around a hundred candidate documents out of the indexed million. Fast, but coarse.
Stage two, the cross-encoder: you take only those hundred candidates, and for each you push the (query, document) pair through the model together, which yields a far finer relevance score. A hundred network passes is affordable; a million would not have been.
| Aspect | Bi-encoder (retrieval) | Cross-encoder (reranking) |
|---|---|---|
| How the two texts are handled | separately | together |
| Speed | fast, everything precomputed | slow, one pass per pair |
| Precision of the score | good | excellent |
| Job | cast a wide net | pick between the finalists |
The idea is to let the cheap component do the bulk of the sorting, and spend the expensive one only on the few dozen candidates where it changes the outcome. That second stage is detailed in reranking: cross-encoders and ColBERT.
Why this matters
Sentence embeddings solve a very concrete problem: comparing a million documents in a few milliseconds. They are the foundation of semantic search, RAG and recommendation systems.
The methodological lesson lies elsewhere. SBERT proposes no new architecture: it takes BERT, keeps the average of the token vectors, and changes only what the model is asked to do during training. That alone was enough to turn a space where the cosine meant nothing into a space where it measures meaning. When a measure does not work, the cause is often in the training objective, not in the formula.
And that is why, in 2026, choosing your embedding model matters as much as choosing your language model: the latter can only reason over what the former brought back.
1. Why does averaging the vectors of a non-fine-tuned BERT give poor similarity scores?
2. Where do SBERT's 65 hours turned into 5 seconds on 10,000 sentences come from?
3. Does a cosine score of 0.75 between two texts mean the same thing from one embedding model to another?
4. In production, how are bi-encoder and cross-encoder combined?