Cosine similarity

Cosine similarity measures how similar two vectors are by the angle between them, ignoring their lengths. It is the most common way to compare embeddings, scoring 1 for identical directions, 0 for unrelated ones, and -1 for opposites.

What is cosine similarity?

Cosine similarity compares two vectors by asking how aligned their directions are. It computes the cosine of the angle between them: vectors pointing the same way score near 1, unrelated vectors score near 0, and opposed vectors score negative. Because it ignores vector length, it measures what the vectors are about rather than how strongly.
For embeddings, where direction carries the meaning, this makes cosine the natural and most widely used similarity measure.

Key takeaways

  • Cosine similarity measures the angle between two vectors.
  • It ranges from -1 to 1, with higher meaning more similar.
  • It is the default metric for comparing embeddings.

How it works

The score is the dot product of the two vectors divided by the product of their lengths. When embeddings are normalized to unit length, as many models do by default, cosine similarity and dot product coincide, which is why the two are often used interchangeably in vector search. Distance metrics like Euclidean distance rank neighbors identically on normalized vectors.

Why it matters

Every find-similar query, near-duplicate check, and semantic search ultimately reduces to similarity scores, and cosine is usually that score. Knowing what it measures, and that it should match how the embedding model was trained, helps debug why a search returns the neighbors it does.

Frequently asked questions

Why use cosine similarity instead of Euclidean distance?

For normalized embeddings they rank neighbors the same way. Cosine is preferred because embedding direction, not magnitude, carries the meaning.

What is a good cosine similarity threshold?

It depends on the model and task. Thresholds are usually chosen empirically by inspecting matches at different score levels.

Related terms

black and white photo of Jesse Mostipak
Jesse Mostipak
SEO & Content
Jesse Mostipak is the SEO and Content Manager at Voxel51, where the work is helping humans find and trust what the brand knows, and teaching the Google knowledge graph and the LLMs answering on their behalf to do the same. That question, how knowledge gets built inside a system, is one Jesse has been chasing for years. Earlier versions of it ran through a New York City high school science classroom, data science and machine learning, and developer relations at Kaggle, Posit (formerly RStudio), and Baseten. The answer doesn't change much depending on whether the learner is a teenager, a software engineer, or a knowledge graph. Jesse holds a Master's in Education from CUNY Hunter College. LinkedIn
See all articles by Jesse Mostipak
Last updated July 9, 2026

Building visual or physical AI?

Let's talk.