Rendered Source Note

scikit-learn — Cosine Similarity

Generated HTML view. Markdown remains canonical.

scikit-learn — Cosine Similarity

Type: official-doc Tier: 1 (Official Doc) Author(s): scikit-learn developers Date: Accessed 2026-06-01 URL: https://scikit-learn.org/stable/modules/metrics.html#cosine-similarity Accessed: 2026-06-01

Why This Source Matters

Cosine similarity is the metric that turns embedding vectors into a usable similarity number — it is the operational core of Project 02's similarity calculator and every retrieval project after it. This source gives the precise formula and, critically, the geometric meaning (angle, not distance) and the magnitude-invariance property that the learner must internalize to avoid the most common embedding bug: confusing "similar" with "close in magnitude."

Key Claims

Definition / formula

k(x, y) = (x · yᵀ) / (‖x‖ · ‖y‖)

i.e. the dot product divided by the product of the two vectors' L2 norms (magnitudes).

What it measures

Range

Why it's used for text/embeddings

Relevant To

Notes