Glossary

Semantic similarity

Semantic similarity is a measure of how close two pieces of content are in meaning, regardless of the exact words they use.

Semantic similarity is a measure of how close two pieces of content are in meaning, regardless of whether they share any words. “How do I reset my password?” and “I forgot my login details” are semantically similar even though they have almost no vocabulary in common, while “bank” in a river sentence and “bank” in a loan sentence share a word and very little meaning. In AI systems, semantic similarity is usually computed by turning each text into an embedding vector and comparing the vectors, most often with cosine similarity. It is the basis of semantic search, deduplication, clustering and much of retrieval for RAG, and it is a strong signal for relevance without being the same thing.

How semantic similarity is measured

The standard method has two steps. First, an embedding model maps each text to an embedding: a list of a few hundred to a few thousand numbers, trained so that texts with similar meanings land near each other. Second, a similarity function compares the two vectors. Cosine similarity measures the angle between them and is the most common choice. Dot product similarity gives the same ordering when vectors are normalised to unit length, and Euclidean distance measures straight-line distance, where smaller means closer.

Models that embed each text separately are called bi-encoders. They are fast because every document can be embedded once and stored, so comparing a query against millions of documents only needs one new embedding and a vector search. The alternative is a cross-encoder, which reads both texts together and outputs a score. Cross-encoders capture finer distinctions, such as which entity a sentence is about, but they have to run once for every pair, so they are used to rescore shortlists. The trade-off is covered in bi-encoder vs cross-encoder.

A third option is to ask a language model to rate similarity directly, often on a scale from 0 to 5. This is slow and costly at scale, but it is useful for building evaluation sets, because the model can explain its rating and handle subtle cases that embeddings miss.

Similarity measures compared

Approach

What it compares

Speed

Typical use

Lexical overlap (BM25, Jaccard)

Shared words and their weights

Very fast

Exact terms, names, codes

Bi-encoder embeddings

Meaning, via vectors compared with cosine

Fast at scale

First-stage semantic search

Cross-encoder

Meaning of the pair read together

Slow per pair

Reranking a shortlist

LLM rating

Meaning, with reasoning

Slowest

Building test sets, audits

Semantic similarity and lexical similarity

Lexical similarity counts shared words. Keyword search and scoring functions such as BM25 are built on it, and they excel at exact matches: product codes, error messages, surnames and rare technical terms. They fail when people describe the same thing in different words. Semantic similarity covers that gap, which is why “car insurance excess” can find a document about “motor policy deductibles”. The two are complementary, and hybrid search runs both and merges the results. The case for each is set out in semantic search vs keyword search and illustrated with real queries in when keyword beats semantic.

In vector terms, lexical methods produce sparse vectors with one dimension per vocabulary term, mostly zeros. Embedding models produce dense vectors where every dimension carries some signal and no single dimension maps to a word. Learned sparse models sit between the two, expanding a text with related terms so that keyword-style indexes gain some semantic reach.

Similarity, relatedness and relevance

Three ideas are often blurred together. Similarity means two texts say much the same thing. Relatedness means they are connected: “doctor” and “hospital” are related without being similar. Embedding models tend to reward both, so a query about a symptom can pull in passages about the treatment, the clinic and the insurance claim, all of which score well.

Relevance is narrower again. Search relevance asks whether a result answers the question or meets the need behind the query. A paragraph that restates the question in different words is highly similar to it and contains no answer at all. A chunk about Q3 revenue is very similar to a question about Q3 projections, while the projection figure sits elsewhere. This gap is why similarity isn’t relevance has become a common warning in RAG work, and why a relevance score from a similarity function should be treated as an estimate.

Where semantic similarity is used

Search is the obvious case. Semantic search ranks documents by how close they are in meaning to a query, and retrieval augmented generation uses the same ranking to choose which passages a model reads before answering. Techniques such as query expansion and contextual embeddings exist mainly to make that similarity signal more reliable.

Beyond search, similarity drives deduplication and near-duplicate detection, where two support articles or two uploaded contracts that say the same thing can be merged or flagged. It drives clustering and topic discovery, grouping thousands of customer messages into themes. A semantic cache uses it to reuse an earlier answer when a new question means the same as an old one. In agent memory, entity resolution uses similarity as one signal for deciding that “Sam from Acme” and “Samantha Ortiz” are the same person.

The idea also extends past text. Multimodal embeddings such as CLIP place images and text in a shared space, so the caption “a red bicycle against a brick wall” sits near photos of that scene. That makes text-to-image search and image-to-image similarity possible with the same machinery.

Where semantic similarity misleads

Negation is the classic failure. “The plan includes SSO” and “The plan does not include SSO” differ by one word, and many embedding models place them very close together. For an agent answering a sales question, that closeness is dangerous. Numbers, dates and identifiers cause similar trouble: “invoice 4471” and “invoice 4417” look nearly identical to an embedding model, and so do two versions of a policy that differ only in a figure.

Scale is the second problem. As a collection grows into millions of chunks, more of them sit close to any query, and similarity scores bunch into a narrow band. Ranking within that band becomes close to arbitrary, an effect known as semantic collapse and described in more detail in why vector search breaks at scale. Domain shift is the third: a general-purpose model trained on web text may not know that two internal product names mean the same thing, or that a legal term has a precise meaning. Comparing models on your own data, using a survey such as best embedding models as a starting list, helps here. Finally, when the embedding model changes, old and new vectors stop being comparable, a form of embedding drift that requires re-embedding the corpus.

Most fixes combine signals rather than replacing similarity. Hybrid search adds exact matching for names and numbers. Metadata filtering narrows candidates by date, type or owner before similarity is computed. A cross-encoder reranker separates passages that answer the question from those that only discuss it.

A worked example

A research agent keeps notes on a set of papers and is asked “which studies found that retrieval quality drops as corpus size grows?”. Pure semantic similarity returns six notes, all scoring between 0.78 and 0.83: three studies that found exactly that, one that found the opposite, one about corpus construction and one that restates the research question. The contrary study scores well because it discusses the same variables with the same vocabulary.

Adding a cross-encoder pass separates the confirming studies (scores above 0.85) from the rest, and the agent’s answer cites the three correct papers. Without it, the contrary study would likely have been summarised as support. The figures are illustrative, but the pattern is common: similarity finds the neighbourhood, and a second signal picks out the answer.

Semantic similarity in agent memory

Memory makes the limits of similarity especially visible. If a user said “I live in Toronto” in March and “I’ve moved to Berlin” in June, both statements are similar to the question “where does the user live?”. A vector store returns both and leaves the model to guess which is current. A memory system needs to know that the second fact replaced the first, which is contradiction resolution rather than similarity, and to avoid the slow accumulation of conflicting facts known as memory drift.

How Exabase uses semantic similarity

Exabase Deep Search uses semantic similarity as one part of hybrid search. Every text query combines semantic matching with typo-tolerant keyword matching by default, and wrapping a phrase in double quotes forces an exact match, which handles the names, codes and numbers that embeddings blur. Results come back at the sub-document level, with a score per hit and per chunk and a page number or timestamp, and a precision parameter from 0 to 1 sets how strict matching is. Deep Search also supports similarity queries beyond text: an image to find visually similar images, a colour, or an existing resource as the query to find content like it. Indexing happens when content is stored, so there is no embedding pipeline to build. The searching resources guide covers the options, and the asset search solution shows how this works across images, audio and video.

Exabase Memory goes further than similarity. Its M-1 engine builds an ontology of concepts and relationships, resolves contradictions when facts change and consolidates duplicates, so a user who moves from Toronto to Berlin has one current city. Retrieval combines semantic and keyword search with recency bias, with optional query expansion and reranking, as described in retrieving memories. For teams whose RAG answers are on topic but wrong, the RAG accuracy solution explains how sub-document retrieval and memory address the gap between similarity and relevance. A comparison of hosted options is in best semantic search API.

Frequently asked questions

What is semantic similarity in simple terms?

It is how close two pieces of text are in meaning. Two sentences with different words can be highly similar if they say the same thing, and two sentences with the same words can be dissimilar if they mean different things.

How is semantic similarity calculated?

Usually by converting each text into an embedding vector with an embedding model and comparing the vectors with cosine similarity. Cross-encoders and language models can also score pairs directly, with more accuracy and much more cost.

What is a good semantic similarity score?

There is no universal threshold. Scores depend on the embedding model, and many models place most text pairs in a narrow band. Set thresholds by scoring labelled examples from your own data and seeing where similar and dissimilar pairs separate.

What is the difference between semantic and lexical similarity?

Lexical similarity counts shared words; semantic similarity compares meaning. Lexical methods are better for exact names, codes and rare terms, semantic methods for paraphrases and synonyms, and hybrid search combines both.

Is semantic similarity the same as relevance?

No. Similarity says two texts are about the same thing. Relevance says a result answers the question. A passage can be very similar to a query and still lack the fact the user needs.

Why does semantic similarity struggle with negation?

Sentences that differ only by “not” share almost all their words and context, so embedding models often place them close together. Exact matching, rerankers or a language model check are needed when the difference matters.

Does Exabase use semantic similarity?

Yes, as part of hybrid search. Deep Search combines semantic and keyword matching for text, supports image, colour and resource similarity queries, and returns sub-document results with scores.

Related pages: Relevance score, cosine similarity, embedding, semantic search, semantic search vs keyword search, hybrid search, semantic collapse, cross-encoder, Deep Search, RAG accuracy, multimodal search, reverse image search

Cut your token spend and give your agent precise context.

Get started in minutes.

Cut your token spend and give your agent precise context.

Get started in minutes.