Skip to content
The Plain Paper

Measure

cosine similarity

Cosine similarity measures how closely two nonzero vectors point in the same direction. It is often used to compare vector representations while ignoring differences in their lengths.

What it is

For vectors x and y, cosine similarity is their dot product divided by the product of their lengths: cos(x, y) = (x · y) / (||x|| ||y||). It is the cosine of the angle between the vectors, so it depends on their directions rather than their magnitudes. It is undefined if either vector is zero.12

How it works

To compare two vectors, multiply matching components and add those products to get the dot product. Divide that result by each vector’s length multiplied together. For many vectors, the same calculation can produce a matrix of pairwise scores.1

Multiplying either vector by a positive number does not change the score, because the change in the dot product is canceled by the change in the vector length. On L2-normalized vectors, cosine similarity is the same as the dot product; ranking unit vectors by cosine also gives the same order as ranking them by Euclidean distance.32

Versions and relatives

Centered cosine similarity first subtracts each vector’s mean from its components; it is equivalent to the Pearson correlation coefficient. Soft cosine similarity also accounts for similarities between features, rather than treating every distinct feature as unrelated.4

Strengths and limits

Ignoring positive changes in vector length can be useful when length is not part of the comparison, and the calculation can be efficient for sparse vectors because it only needs nonzero coordinates. Cosine similarity is symmetric, so swapping the two vectors leaves the score unchanged.24

Because cosine similarity ignores vector length, it cannot distinguish vectors that point in the same direction but have different lengths. The score can also be a poor fit when the relation being measured is asymmetric, and anisotropy or hubness in the representation space can affect comparisons.2

The quantity 1 − cosine similarity is often called cosine distance, but it is not generally a metric because it can violate the triangle inequality. Angular distance, calculated as arccos(cosine similarity), is a metric on the unit sphere.32

How recent papers use it

In an entity-conflict resolution pipeline, cosine similarity compares utterance and example embeddings to select retrieval examples.5

For semantic table search, cosine similarity between entity embedding vectors is one of the supported ways to measure entity similarity.6

In the LusoClin dataset work, cosine similarity between sentence-level embeddings is used to assess diversity and privacy.7

In a model of cross-domain media similarity, item-pair similarity is calculated as the cosine between the items’ rating vectors.8

Names and versions

Also written as
item-based cosine similarity
Versions of it
  • Regularized Cosine Similarity (1 paper)
  • cross-dataset cosine similarity (1 paper)

Papers that mention cosine similarity

  1. 19 Nov 2026Used

    Can LLMs Resolve Entity Conflicts in Domain Specific NLU Pipelines?

    Cosine similarity is used to select retrieval examples by comparing utterance and example embeddings.

  2. 19 Nov 2026Used

    Exploring Semantic Table Search in Data Lakes

    Cosine similarity between entity embedding vectors is one supported entity-similarity function.

  3. 17 Nov 2026Used

    LusoClin: A Synthetic Clinical Note Dataset for Medical Information Retrieval in European Portuguese

    Cosine similarity was used to assess diversity and privacy using sentence-level embeddings.

  4. 17 Nov 2026Used

    Learning Cross-Domain Media Similarity from Amazon Reviews

    It calculates item-pair similarity from the cosine between their rating vectors.

Sources

  1. 1cosine_similarity — scikit-learn 1.9.1 documentationscikit-learn.org
  2. 2Semantics at an Angle: When Cosine Similarity Works Until It Doesn’tarxiv.org
  3. 3Cosine Similarity -- from Wolfram MathWorldmathworld.wolfram.com
  4. 4Cosine similarity - Wikipediaen.wikipedia.org
  5. 5Can LLMs Resolve Entity Conflicts in Domain Specific NLU Pipelines?Paper explained on this site
  6. 6Exploring Semantic Table Search in Data LakesPaper explained on this site
  7. 7LusoClin: A Synthetic Clinical Note Dataset for Medical Information Retrieval in European PortuguesePaper explained on this site
  8. 8Learning Cross-Domain Media Similarity from Amazon ReviewsPaper explained on this site

Every paragraph above was checked against the sources it cites before it was published.