Skip to content

Cosine similarity explained (with embeddings)

What cosine similarity measures, the formula, how it compares to Euclidean distance and the dot product, why it's the default for embeddings, and how to read the numbers.

Open the Calculator →

What cosine similarity measures

Cosine similarity is the cosine of the angle between two vectors. It cares about direction, not length: scaling a vector up or down doesn't change it. The value runs from 1 (same direction) through 0 (at right angles — unrelated) to -1 (opposite directions).

The formula

cos(A, B) = (A · B) / (‖A‖ × ‖B‖)

A · B  = Σ Aᵢ Bᵢ            (dot product)
‖A‖    = √(Σ Aᵢ²)           (magnitude / L2 norm)

In words: take the dot product of the two vectors, then divide by the product of their magnitudes. The calculator shows each of these intermediate values too.

Why it's used for embeddings

Embedding models turn text, images or audio into high-dimensional vectors where direction encodes meaning. Two passages about the same topic point the same way even if one is much longer, so cosine similarity — which ignores length — is usually more meaningful than raw Euclidean distance. It powers semantic search, clustering, deduplication and retrieval-augmented generation (RAG).

Cosine vs Euclidean vs dot product

  • Cosine similarity — angle only; invariant to vector length.
  • Euclidean distance (L2) — straight-line distance; sensitive to length.
  • Dot product — combines angle and magnitude. If vectors are normalized to unit length, dot product equals cosine similarity.

Tip: if your embeddings are already L2-normalized, ranking by cosine similarity, dot product or Euclidean distance gives the same order.

Interpreting the value

Thresholds depend on the model, but as a rough guide: above ~0.8 is strongly similar, ~0.5–0.8 related, near 0 unrelated, and negative means opposite. Calibrate on your own data rather than trusting a universal cutoff.

Privacy

Embeddings can encode private content, so this tool computes everything locally in your browser — nothing you paste is uploaded.

FAQ

What is cosine similarity?

The cosine of the angle between two vectors — 1 is identical direction, 0 unrelated, -1 opposite.

Why not just use Euclidean distance?

Cosine ignores length, which is usually what you want for embeddings of different sizes.

Is my data uploaded?

No — everything runs locally in your browser.

Ready to try it? Open the Calculator →

Related guides