- Each vector can be thought of as an arrow in n-dimensional space.
- Cosine similarity depends on the angle between vectors, so differences in magnitude (length) do not change the similarity if the direction remains the same.
- When two vectors point in the same direction, their cosine similarity approaches
1. If they are orthogonal, the similarity is0. Opposite directions yield-1.
Cosine similarity focuses on angular alignment between vectors. Differences in magnitude (length) are ignored, which makes it ideal for comparing semantic content across short and long texts.
θ = 0°→ cos =1: vectors point in exactly the same direction (highly similar).θ = 90°→ cos =0: vectors are orthogonal (no directional relationship).θ = 180°→ cos =-1: vectors point in opposite directions (maximally different).
-
Robustness to document length differences
Cosine similarity ignores vector magnitude. For search and retrieval, this means a short query can match a long document based on topic alignment rather than penalizing the longer document for having more words. -
Short vs. long text matching
A short social post and a long article can still be recognized as semantically similar because cosine similarity compares direction (topic) rather than raw count. -
Widely adopted default for text embeddings and semantic search
Many embedding models and vector databases default to cosine similarity because it captures topical alignment across documents of different lengths.

Imagine a user’s short query about “inflation and interest rates” and a full-length economics article on the same topic. Despite a 20-word query and a 1,000-word article, cosine similarity will identify strong topical alignment because the direction of their embedding vectors is similar. Industry adoption
OpenAI’s text embeddings, SentenceTransformers, and many vector databases prefer cosine similarity for semantic search. They all default to cosine similarity for text-based search.

| Metric | What it measures | When to use |
|---|---|---|
| Cosine similarity | Directional alignment (angle) between vectors; ignores magnitude | Best for semantic search, text embeddings, when document length varies |
| Euclidean distance | Absolute distance in vector space (L2 norm) | Useful when magnitude and absolute distances matter (e.g., low-dimensional feature spaces, clustering with scale-sensitive features) |
- OpenAI Embeddings Guide
- SentenceTransformers (SBERT)
- Pinecone Vector Database
- Weaviate
- Fundamentals of RAG