Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

🏠 Back to Blog

Vector Similarity

Models

Cosign Similarity

  • Measures the angle between vectors
  • Ignores magnitude, focuses on directoin
  • Cosign similarity only cares about direction, not length

Euclidean Distance

  • How far apart are they?
  • Measures straight line distance?
  • How far apart are the vectors?

Dot Product

  • “Direction + Strength” combined
  • Combines directoin and magnitude
  • Rewards aligned, strong vectors

Visual Comparison

How sensitive each metric is to magnitude vs. direction:

quadrantChart
    title Similarity Metric Sensitivity
    x-axis Low Magnitude Sensitivity --> High Magnitude Sensitivity
    y-axis Low Direction Sensitivity --> High Direction Sensitivity
    quadrant-1 Direction only
    quadrant-2 Direction + Magnitude
    quadrant-3 Neither emphasized
    quadrant-4 Magnitude only
    Cosine Similarity: [0.15, 0.85]
    Dot Product: [0.75, 0.75]
    Euclidean Distance: [0.85, 0.2]

Cosine Similarity — only the angle between vectors matters:

graph LR
    O((Origin)) -->|Vector A| A((A))
    O -->|Vector B| B((B))
    A -.angle θ: cos θ.- B

Euclidean Distance — straight-line distance between the vector endpoints:

graph LR
    A((Point A)) ---|"straight-line distance"| B((Point B))

Dot Product — direction alignment scaled by magnitude:

graph LR
    A((Vector A)) -->|"magnitude x cos θ"| B((Vector B))
    B -.projected onto.-> A

Which model should I use?