Semantic Similarity Computation
Semantic similarity computation is a quantitative method for measuring how close two pieces of text are at the level of meaning, and is the metric foundation of tasks such as vector retrieval, deduplication, clustering and question answering matching. It looks like just a formula, but choosing the wrong metric makes even the best embedding model underperform, so it is one of the most underrated details in engineering implementation.
Core Principles
The general flow is to first map text into a high-dimensional vector with an embedding model, then compute distance or angle in the vector space. Three metrics are common: cosine similarity looks at the cosine of the angle between two vectors, insensitive to vector length and suited to comparing semantic direction; Euclidean distance looks at straight-line distance in space and is affected by magnitude; dot product is affected by both angle and magnitude, with values amplified by magnitude.
There is a clear equivalence among the three: once all vectors are L2-normalized (magnitude one), cosine similarity equals the dot product exactly, and Euclidean distance corresponds monotonically to cosine, with smaller distance meaning greater similarity. This is why vector databases almost always require normalization before ingestion: after normalization only one computation path is kept, avoiding errors from mixing, and approximate nearest neighbor algorithms on inner product can be used for speed. Conversely, mixing dot product and cosine without normalization severely distorts results, with larger errors especially when document lengths differ greatly.
Note that semantic similarity measures approximation rather than identity: two sentences with similar meaning but opposite sentiment (for example "very good" and "not bad" in some tasks) may get a high score, which must be judged in light of the task definition.
Key Points
First, a similarity score is not a probability. Zero point eight does not mean eighty percent relevant, only relatively close in that model's space; distributions differ greatly across models, and the same model has systematic offsets across domains and languages. Second, thresholds absolutely cannot be reused across models: change the embedding model, change the chunking strategy, or even just change the normalization method, and all historical thresholds are void; a validation set must be re-annotated to set thresholds, using the precision-recall curve to pick the balance point.
Third, in production prioritize ranking over absolute values, evaluating the retrieval pipeline with Recall@K, MRR, NDCG and similar metrics, which is far more reliable than fixating on a single threshold. Fourth, beware of "average semantic dilution" for long documents: embedding a whole document is often dominated by high-frequency words and boilerplate, and chunking then taking the max score or a weighted average works better. Fifth, approximate nearest neighbor indexes (such as HNSW and IVF) sacrifice a little accuracy for speed, so assess whether the recall loss is acceptable, and tune the ef and nprobe parameters by data volume.
Also distinguish symmetric from asymmetric tasks: the similarity between a short query and a long document is naturally low, and a purpose-trained retrieval model is more suitable than a general similarity model, which is the root cause of many "clearly relevant but low score" problems.
Common Misconceptions
First, using similarity as confidence for filtering, causing many correct results to be wrongly killed. Second, believing that vector length affects semantics, when actually without normalization the magnitude pollutes the dot product result, systematically favoring long text. Third, applying one set of thresholds to both a Chinese and an English model, which is bound to be unstable.
Application Scenarios
Semantic retrieval, question answering matching, duplicate content deduplication, text clustering, intent recognition, similar product recommendation, paper plagiarism checking, customer service script matching, log merging.