Sentence Embedding
Word embeddings give every word a position in space, which is useful until the thing you need to compare is a whole sentence. A sentence embedding is a single fixed-length vector standing in for an entire sentence, paragraph or short document, placed so that texts meaning similar things sit close together.
How the vector is produced
Collapsing a variable number of tokens into one vector is the whole design problem:
- Averaging the word vectors is the cheap baseline — fast, and blind to word order and negation.
- Pooling a transformer’s token outputs (mean pooling, or the [CLS] position) uses contextual vectors, but raw BERT pooling yields a badly shaped space in which almost every pair looks similar.
- Trained sentence encoders repair that. Sentence-BERT fine-tunes a bi-encoder on sentence pairs with a contrastive or regression objective, so cosine distance in the resulting space lines up with human similarity judgements.
What it unlocks
One vector per text turns comparison into arithmetic, and arithmetic scales. A million sentences can be embedded once, stored in a vector index such as FAISS, and searched in milliseconds — which is what makes semantic search, retrieval for question answering, deduplication, clustering and topic discovery practical. A cross-encoder judges any single pair more accurately, but it has to run per pair and cannot be precomputed.
Why it matters
Keyword matching fails the moment the reader’s words differ from the document’s. Sentence embeddings move retrieval from shared vocabulary to shared meaning, and because they are precomputable they do it at the scale of a real corpus. The cost is compression: fine distinctions — negation above all — get squeezed out of a single vector, which is why a reranking step follows retrieval in systems that need precision.
A sentence embedding is a single fixed-length vector representing a sentence or short passage, positioned so that semantically similar texts lie close together under cosine distance. It is produced by pooling a transformer’s token vectors or, far more reliably, by a purpose-trained encoder such as Sentence-BERT. Because the vectors are precomputable and comparable by simple arithmetic, they make semantic search, clustering, deduplication and retrieval feasible at corpus scale.
Think of a library where every book is shelved by what it is about rather than by its title, so books on the same subject end up side by side even when nothing on their covers matches.
A sentence embedding puts sentences on shelves like that. Software turns each sentence into a list of numbers — in effect a position — chosen so that sentences meaning similar things land near one another. Once text is stored that way, a computer can find the closest match to your question among millions of sentences almost instantly. It is why modern search can hand you the right answer even when you phrased the question in your own words.