Embeddings are often introduced as vectors: long lists of numbers that somehow encode meaning.

That description is correct, but it hides the useful intuition.

When we compare two embeddings, we are often less interested in how large the vectors are than in whether they point in a similar direction.

That is what cosine similarity measures.

Start with two vectors

Imagine two vectors, A and B, starting at the same origin.

If they point in exactly the same direction, the angle between them is .

If they are perpendicular, the angle is 90°.

If they point in opposite directions, the angle is 180°.

Cosine similarity takes that angle and turns it into a number between -1 and 1.

The important word here is direction.

VECTOR GEOMETRY

Move B toward A to increase similarity. Rotate to 90° to approach 0. Keep rotating and the score becomes negative.

cosine similarity0.97aligned
A [ 1.2, 0.6, 2.1 ] B [ 2.4, 1.7, 2.8 ]
1 = aligned0 = orthogonal−1 = opposite
ANGLE θ14.9°
Sim0.97aligned

Adjust B numerically or drag the endpoint to inspect the angle.

The cosine of the angle between two vectors gives a similarity score from −1 to 1.

Try moving vector B.

Bring it closer to the direction of A and watch the similarity move toward 1.

Rotate it until the vectors are perpendicular and the score approaches 0.

Continue rotating toward the opposite direction and the score becomes negative.

The calculation is responding to the angle between the vectors, not simply to the distance between their endpoints.

Why cosine?

For two vectors A and B:

cosineSimilarity(A, B) = (A · B) / (||A|| × ||B||)

At first glance this can look like an arbitrary formula.

It is not.

The dot product has a geometric identity:

A · B = ||A|| × ||B|| × cos(θ)

where θ is the angle between the vectors.

Divide both sides by the two magnitudes:

(A · B) / (||A|| × ||B||) = cos(θ)

And that is cosine similarity.

We are effectively asking:

What is the cosine of the angle between these two vectors?

Magnitude disappears

This normalisation is the important part.

Suppose:

A
[1, 2]
B
[2, 4]
cosine similarity
1

B is twice as long as A, but both vectors point in exactly the same direction.

Now make B ten times longer:

B
[10, 20]
cosine similarity
1

The length changed.

The direction did not.

Cosine similarity deliberately removes magnitude from the comparison.

That makes it useful when the orientation of a vector carries more information than its absolute scale.

What this means for embeddings

An embedding model maps some input — a word, sentence, image, document, product, or something else — into a point in a high-dimensional vector space.

For example, imagine the model produces embeddings for:

The actual vectors may have hundreds or thousands of dimensions, so we cannot meaningfully draw them.

But the geometric idea still applies.

If dog and puppy have embeddings pointing in similar directions, their cosine similarity will be high.

If dog and database point in substantially different directions, their similarity will be lower.

The model has learned a geometry in which relationships between directions can encode useful semantic structure.

Cosine similarity gives us a simple way to query that geometry.

High-dimensional geometry is still geometry

It is easy to think that everything changes once a vector has 768 or 1,536 dimensions.

Mathematically, the same ideas still work.

There is still:

We simply cannot visualise the whole space directly.

The two- or three-dimensional diagram above is therefore not a literal depiction of an embedding space.

It is a projection of the underlying geometry into something our brains can inspect.

That distinction matters.

A visualisation should help us understand the mathematics without pretending the real embedding space looks exactly like the picture.

Cosine similarity is not semantic understanding

There is also an important limitation.

Cosine similarity itself does not understand language.

It has no concept of dogs, databases, similarity, relevance, or meaning.

All it does is compare vectors.

The semantic information comes from the embedding model that produced those vectors.

So when semantic search works well, two separate things are happening:

  1. the embedding model has created a useful geometric representation
  2. cosine similarity is being used to compare positions or directions inside that representation

A poor embedding model cannot be rescued by a clever similarity metric.

Similarity is not relevance

This becomes particularly important in retrieval systems.

Suppose a user asks:

How do I cancel my subscription?

You embed the query and compare it with document chunks.

A chunk with high cosine similarity may be semantically related to subscriptions and cancellation.

But that does not guarantee that it is the best answer.

It could be:

That is why production retrieval systems often do more than vector similarity alone.

They may combine:

Cosine similarity is often one ingredient in retrieval, not the whole retrieval system.

A useful mental model

I find the simplest mental model is this:

Euclidean distance asks: How far apart are these points?

Cosine similarity asks: How similarly are these vectors pointing?

Neither question is universally better.

They describe different geometric relationships.

For embeddings, direction is often useful enough that cosine similarity has become one of the standard tools for comparing them.

The important intuition

You do not need to remember the formula first.

Remember the picture.

Two vectors.

One angle.

As the vectors align, similarity approaches 1.

As they become perpendicular, similarity approaches 0.

As they oppose each other, similarity approaches -1.

The formula is simply the algebra that captures that geometry.