Math for ML - Beginner - 8 min

Learn Dot Product & Similarity

A free visual AI and machine learning lesson with an interactive 3D visualization, plain-English theory, and quiz.

Last updated: 2026-05-13.

The dot product answers one question: how similar are two vectors? Two arrows pointing in the same direction have a high dot product. Two arrows pointing opposite ways have a negative one. Two arrows at 90° have zero. This single number drives recommendation systems, search engines, and attention in transformers.

The formula

Dot product of [a₁, a₂, a₃] and [b₁, b₂, b₃] = a₁b₁ + a₂b₂ + a₃b₃. Multiply element-by-element, then sum. Geometrically, it equals |A| × |B| × cos(θ) — where θ is the angle between the two vectors.

Where it shows up in ML

Every dot product in a neural network is computing similarity — how much does this input match this pattern? The attention mechanism in transformers is literally dot products between query and key vectors to find which words are most relevant to each other.

Practice questions

  1. What does a dot product of 0 mean geometrically?
  2. What is the dot product of [1, 2, 3] and [4, 5, 6]?
  3. Netflix uses dot products to recommend movies. What are the two vectors being compared?
  4. In the transformer attention mechanism, what does a high dot product between a query and a key indicate?

Related AI learning resources

Premium lesson notes and simulations | AI project templates | More Math for ML lessons