What Is Cosine Similarity?

Flavio AmielWritten byFlavio Amiel Founder, Roborank
Updated July 15, 2026

Cosine similarity is a measure of how alike two vectors are, calculated as the cosine of the angle between them. It ranges from -1 to 1: a value near 1 means the vectors point in almost the same direction, 0 means they are unrelated, and -1 means they point opposite ways. Because it depends only on direction, it ignores vector length entirely.

Key Takeaways

How Cosine Similarity Works

Cosine similarity answers a narrow question: do these two vectors point in the same direction? It takes the angle between two vectors and returns its cosine. When the angle is zero — the vectors point exactly the same way — the cosine is 1. When they are perpendicular, meaning unrelated, it is 0. When they point in opposite directions, it is -1. Because only the angle matters, the length of each vector is irrelevant, which is the property that makes cosine similarity well suited to comparing meaning.

That property matters for AI search because a vector embedding encodes meaning as direction in a high-dimensional space. A short passage and a long one about the same subject may have very different vector lengths but nearly the same direction, and cosine similarity correctly scores them as highly similar. This is why it is the default metric for comparing embeddings and for measuring semantic similarity between a query and a candidate passage.

Formula

Cosine similarity of two vectors A and B is their dot product divided by the product of their magnitudes:

                    A · B              Σ (Aᵢ × Bᵢ)
cos(θ)  =  ───────────────────  =  ─────────────────────────
                 ‖A‖ × ‖B‖          √(Σ Aᵢ²) × √(Σ Bᵢ²)

The numerator multiplies the vectors component by component and sums the results. The denominator divides by each vector’s length, which is what strips out magnitude and leaves pure direction. If both vectors are already normalized to length 1, the denominator equals 1 and the whole formula collapses to just the dot product A · B.

Example of Cosine Similarity

OpenAI’s embeddings documentation is a clean worked example of cosine similarity in production. The docs explicitly recommend it: “We recommend cosine similarity” as the way to measure how related two embedding vectors are. They also note a practical shortcut that follows directly from the formula. Because OpenAI embeddings are normalized to length 1, the denominator in the equation is already 1, so cosine similarity can be computed “slightly faster using just a dot product,” and cosine similarity and Euclidean distance “will result in the identical rankings.”

Sentence-BERT shows the same metric doing the heavy lifting in retrieval. In the 2019 SBERT paper, each passage is embedded once, and comparing 10,000 of those embeddings to find the most similar pair takes about 0.01 seconds — because the comparison is nothing more than cosine similarity between precomputed vectors. That is the whole point: embeddings make meaning comparable, and cosine similarity is the cheap arithmetic that does the comparing. Every time an AI answer engine decides which passage best matches a question, a cosine score is what ranks the candidates.

The thing people get wrong

The thing people misread is the sign range. They assume similarity runs 0 to 1 and treat 0.2 as "a bit similar." It isn’t — cosine similarity runs -1 to 1, and for typical text embeddings the interesting action lives in a narrow band up near the top. Real passages are rarely opposite in meaning, so you almost never see negative scores in practice; what separates a strong retrieval match from a weak one is often the difference between 0.82 and 0.71, not between 0.9 and -0.9. If you are eyeballing similarity scores to judge whether your content got matched to a query, calibrate to the distribution the model actually produces, not to an imagined 0-to-100 percentage. The absolute number means little; the ranking against competing passages is what decides retrieval.

Frequently Asked Questions

What is cosine similarity?
It is a measure of similarity between two vectors, equal to the cosine of the angle between them. It ranges from -1 to 1, where 1 means the vectors point the same direction, 0 means they are unrelated, and -1 means opposite. It compares direction, ignoring length.
Why is cosine similarity used for embeddings?
Because embeddings encode meaning as direction in vector space, and cosine similarity measures exactly that while ignoring magnitude. A short passage and a long one about the same topic can still score as highly similar, which is what semantic retrieval needs.
What is the range of cosine similarity?
From -1 to 1. A score of 1 means identical direction, 0 means perpendicular and unrelated, and -1 means opposite direction. For real text embeddings, scores usually cluster in a positive band, so meaningful differences are often small.
Is cosine similarity the same as dot product?
Not in general, but they match when vectors are normalized to length 1. Cosine similarity divides the dot product by the vectors’ lengths; when both lengths are 1, that division does nothing, so cosine similarity equals the dot product and produces identical rankings.

The Bottom Line

Cosine similarity reduces "how alike are these two things" to "how small is the angle between their vectors," scored from -1 to 1. It is the arithmetic that turns embeddings into retrieval: a query vector is compared against every passage vector, and the closest directions win. What matters is not the raw score but where your passage ranks against the others competing for the same query.

Sources

  1. Vector embeddings (embeddings guide — cosine similarity recommendation)OpenAI
  2. Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks (Reimers & Gurevych, 2019)arXiv / EMNLP 2019

Rank & Cash — the weekly SEO breakdown

One practical teardown a week on ranking in search and getting cited by AI. No fluff.