AI Engineer Path

Concept Lab · Week 4 · Prerequisites

Dot product → cosine similarity

Rotate two vectors and see projection, dot product and cosine update live.

The idea: Dot product and cosine similarity

Algebraically, the dot product multiplies matching coordinates and sums: a⃗⋅b⃗=∑iaibi\vec{a}\cdot\vec{b} = \sum_i a_i b_i. Geometrically, it equals ∥a⃗∥∥b⃗∥cos⁡θ\|\vec{a}\|\|\vec{b}\|\cos\theta: positive when the vectors point the same way, zero when perpendicular, negative when opposed.

Divide by both lengths and you get cosine similarity, which depends only on the angle. This is the standard measure of semantic similarity between embeddings, because direction encodes meaning and length often encodes things you don't care about (like text length).

If embeddings are already normalised to length 1, cosine similarity is the dot product, which is why many vector databases normalise once at insert time and then use the cheaper dot product.

Open the full lesson in week 4

Next simulation: Eigenvectors