Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Blog › Explore in 3D

25 November 2026 · 3 min readInteractive 3D

Colourful abstract 3D shapes, an artwork about learning patterns
Photo by Google DeepMind on Unsplash

What is cosine similarity? How alike two things are

Search engines, recommendations and chatbots all ask “how similar are these?” The answer is an angle. See it between words in 3D.

If two things are described by lists of numbers, how do you measure how alike they are? One popular answer ignores how long the lists are and looks only at the direction they point. That measure is cosine similarity.

The numbers under the model are cosine similarities between the chosen word and its neighbours.

The recipe

  1. Take the dot product: multiply matching numbers and add.
  2. Divide by the length of each list.
  3. The result is the cosine of the angle between the two arrows.
  • 1 means pointing exactly the same way: very similar.
  • 0 means at right angles: unrelated.
  • −1 means pointing opposite ways.

Why direction and not distance?

Two documents about cricket might be very different lengths. A long one has bigger numbers everywhere, so it sits far from a short one. But both point in the same direction, towards “cricket”. Cosine similarity sees that they are about the same thing.

When you search for something online, your question is often turned into an embedding, and the results are the pages whose embeddings have the highest cosine similarity to it.

A worked example

Two students rate three films out of 5. Asha gives [5, 1, 4] and Ben gives [4, 2, 5]. How similar is their taste?

  1. Dot product: 5×4 + 1×2 + 4×5 = 42
  2. Length of Asha’s list: √(25 + 1 + 16) = √42 ≈ 6.48
  3. Length of Ben’s list: √(16 + 4 + 25) = √45 ≈ 6.71
  4. Cosine similarity = 42 ÷ (6.48 × 6.71) ≈ 0.97, very similar

Reading the number

  • 1: exactly the same direction (same taste, maybe stronger).
  • 0: unrelated (at right angles).
  • −1: opposite (one loves what the other hates).

Ratings that are all positive can never point in opposite directions, so in practice values sit between 0 and 1. Centring the ratings (subtracting each person’s average) lets disagreement show up as negative values.

Why not just use distance?

A long article and a short summary about the same topic can be far apart in distance, simply because the long one has bigger word counts. Their directions are almost the same, so cosine similarity correctly calls them alike. That is why search engines and recommendation systems use it.

Cosine similarity = dot product ÷ (length × length). It is the cosine of the angle between the two arrows.

Search with embeddings

A modern search system stores an embedding for every document. When you search, your query becomes an embedding and the system returns the documents with the highest cosine similarity. Special databases called vector databases make this fast across millions of documents.

Glossary

  • Cosine: the trigonometric ratio linked to the angle between arrows.
  • Normalise: scale a vector to length 1.
  • Vector database: storage designed for fast similarity search.

Try these yourself

  1. Q1. [1, 0] and [0, 1]: 0, unrelated
  2. Q2. [2, 2] and [5, 5]: 1, same direction
  3. Q3. [1, 2] and [−1, −2]: −1, opposite
  4. Q4. [3, 4] and [4, 3]: 24 ÷ 25 = 0.96

Common mistakes

  • Forgetting to divide by both lengths.
  • Thinking a high score means equal size; it only means the same direction.
  • Comparing vectors made by different models; their numbers do not match up.

In short

Cosine similarity compares direction, not size, so it measures how alike two things are regardless of scale. It is the backbone of search and recommendations.

Keep going

  • Glossary: cosine similarity
  • What is a dot product?
  • Word embeddings in 3D
  • How can random dots find π? Monte Carlo
  • What does an artificial neuron do?
  • Sigmoid or ReLU: which activation function?

Read and listen in

Indian languages

World languages

Questions people ask

What is cosine similarity used for?

Comparing documents, words, songs or users by the direction of their number lists, regardless of size. It is central to search and recommendations.

What is a good cosine similarity score?

It depends on the data, but values above about 0.8 usually mean very similar, and values near 0 mean unrelated.

How is cosine similarity calculated?

Divide the dot product of the two vectors by the product of their lengths.

More articles

  • How can random dots find π? Monte Carlo
  • What does an artificial neuron do?
  • Sigmoid or ReLU: which activation function?