Three definitions of near
Dot product, cosine, and distance use different geometry.
Embedding Similarity Playground
Edit a query and three candidate vectors. Watch magnitude change dot-product rankings, then normalize the geometry.
Live result
Scroll the diagram sideways. Exact values appear below.
These are synthetic 2D vectors, not learned language embeddings. Position has no assigned semantic meaning. Cosine and unit normalization are undefined for the zero vector; undefined comparisons are excluded from those rankings.
The explanation
Dot product rewards alignment and magnitude together. Cosine divides magnitude away. Euclidean distance measures the straight-line gap between endpoints. Those are different objectives until vectors are normalized. [E1]
In the default example, Q=(1,0). A=(2,1) wins dot product with 2. B=(0.8,0) wins cosine with 1 and distance with 0.2. B points in exactly the query direction even though A has greater magnitude.
Normalize every nonzero vector and dot product becomes cosine. Squared Euclidean distance then equals 2−2cosine, so all three rankings agree, with distance sorted in the opposite numerical direction. [E2]
A zero vector has no direction. Libraries choose different practical conventions; this teaching model marks cosine and normalization undefined. No diagram here pretends that a two-dimensional location is the meaning of a real sentence.
Open Asset Factory
Three independent diagrams. Editable source and high-resolution PNGs, with assumptions printed on the image.
Dot product, cosine, and distance use different geometry.
The unit circle keeps direction and discards magnitude.
Sources checked 2026-09-07
Formula derivations and teaching assumptions are documented separately.
Download claim ledgerThe scikit-learn cosine similarity definition divides dot product by the two L2 norms; it equals the linear kernel on L2-normalized data.
Primary source ↗This demo uses mathematical undefined for zero vectors rather than the library’s zero-fill convention.
L2 normalization rescales each nonzero vector to unit norm.
Primary source ↗Magnitude may contain useful information in a real model; normalization is not universally appropriate.