Cosine similarity
How similar two vectors are by direction, ignoring how long they are — 1 is identical, 0 is unrelated.
Think of it like
Two people pointing: it’s whether they point the same way that matters, not how far their arms reach.
Example
Semantic search ranks results by cosine similarity between your query’s embedding and each document’s.
How it actually works
It’s the dot product divided by both vectors’ lengths, which strips out magnitude and leaves only angle. That makes it robust when vectors have different scales. It’s the default similarity metric for embeddings because meaning tends to live in direction, not length.
For product teams
It’s the math that decides which stored items count as “closest” to a query in most vector search.
For engineers
cosθ = ⟨a,b⟩ / (‖a‖‖b‖); angle-based similarity invariant to vector magnitude.
Related
- Dot product — Built from the dot product.
- Embeddings — Used to compare embeddings.
- Vector database — Powers search over a vector database.
Read anything AI without the jargon
Look up any term in plain English, or save terms as you read with the free Chrome extension.
Open DecoderAdd to Chrome