AI systemscosine distancedot productsimilarity scoresimilarity threshold

Cosine similarity

Definition

Cosine similarity is the dot product of two vectors divided by the product of their lengths; for normalised vectors it equals the dot product, and cosine distance is 1 minus it.

In practice

Vector databases and semantic caches rank candidates by a similarity metric, and cosine is the usual choice for text embeddings because it ignores vector length and compares direction. Many embedding models output normalised vectors, so systems compute a plain dot product, which is cheaper and gives the same ranking.

Scores are not probabilities and are not comparable across models: 0.85 may mean near-identical for one model and loosely related for another. Thresholds, such as a semantic cache's hit threshold, must be tuned on labelled pairs from your own domain and re-tuned whenever the embedding model changes.

Example

"How do I reset my password?" and "I forgot my password, what now?" score 0.91 with the current model, above the cache threshold of 0.88; "How do I change my email?" scores 0.74.