Skip to main content
All Labs
๐Ÿง Core AI Intuitions ยท Lesson 02.01

Similarity With Dot Product

The one operation behind embeddings, search, and attention.

Lesson02.01
TrackCore AI Intuitions
AccessFree

๐Ÿ’ก The intuition

Two people rate pizza, hiking, and jazz. Multiply their ratings category by category and add it all up. Shared loves make the total big; opposite tastes make it small. That single number is the dot product โ€” a score for how aligned two vectors are.

Query concept

king = [0.9, 0.8, 0.1]

Most similar to โ€œkingโ€ (by cosine)

queen
cos 0.992
man
cos 0.880
apple
cos 0.518
car
cos 0.228

Step by step: king ยท queen

dot = 0.9ร—0.8 + 0.8ร—0.9 + 0.1ร—0.15 = 1.455

|king| = 1.208 , |queen| = 1.213

cosine = dot / (|king|ยท|queen|) = 0.992

Cosine near 1 = same direction (very similar); near 0 = unrelated; toward โˆ’1 = opposite.

A tiny worked example

A = [1, 2, 3], B = [2, 0, 4]

dot = (1ร—2) + (2ร—0) + (3ร—4) = 2 + 0 + 12 = 14

|A| = โˆš14 โ‰ˆ 3.742, |B| = โˆš20 โ‰ˆ 4.472

cosine = 14 / (3.742 ร— 4.472) โ‰ˆ 0.837 โ†’ close to 1 โ†’ similar direction

Free lesson complete

Continue with the complete Core AI Intuitions path.

Pro unlocks the surrounding lessons, runnable practice, and the full build-ready sequence.

Why it matters in AI

  • โ–ธSemantic search ranks documents by cosine similarity to your query.
  • โ–ธAttention scores are query ยท key โ€” how much one token should attend to another.
  • โ–ธDeduplication and clustering use cosine โ‰ˆ 1 to find near-identical items.
  • โ–ธRecommendations match a user vector against item vectors with a dot product.

Things people get wrong

โœ— A bigger dot product always means more similar.

โœ“ Only if magnitudes are comparable. Cosine normalizes out length so direction is what counts.

โœ— Cosine and dot product are the same thing.

โœ“ Cosine is the dot product of two length-1 vectors. They only match after normalizing.

โœ— Similarity can't be negative.

โœ“ Cosine ranges from โˆ’1 to +1. 0 means unrelated; negative means opposing direction.