# Cosine Similarity

- **Canonical URL:** https://getaimath.com/dictionary/cosine-similarity/
- **Topics:** [Context, Memory & Retrieval](https://getaimath.com/dictionary/category/context-memory-and-retrieval/)
- **Last updated:** 2026-11-25

## What is Cosine Similarity?

**In one sentence:** Cosine similarity measures how similar two vectors are by checking the angle between them.

If two vectors point in the same direction, the score is close to 1. If they point at right angles, it is 0. If they point in opposite directions, it is −1. It ignores how long the vectors are and focuses on direction, which works well for meaning.

![Context Window vs. Memory: Your Desk vs. The Filing Cabinet — Simple cartoon comparing the AI Context Window (a small desk that can only fit a few pages right now) with External Memory & Search (a big filing cabinet where a librarian grabs just the 3 pages you need).](https://getaimath.com/diagrams/context-memory-and-retrieval.png)
*Napkin Diagram (Context, Memory & Retrieval): The context window is the small desk the AI can see right now; search grabs the right pages from the filing cabinet.*

### Quick Math / Rule of Thumb

cos(θ) = (A · B) ÷ (‖A‖ × ‖B‖). Scores run from −1 (opposite direction) through 0 (unrelated) to +1 (same direction).

## What is an example of Cosine Similarity?

The embeddings for "happy" and "joyful" might have a cosine similarity of 0.9.

## Why does Cosine Similarity matter?

It is the most common way to compare embeddings.

## Related Concepts

- [Similarity Search](https://getaimath.com/dictionary/similarity-search/): Similarity search finds items that are most like a given item, using a measure of closeness.
- [Euclidean Distance](https://getaimath.com/dictionary/euclidean-distance/): Euclidean distance is the straight-line distance between two points or vectors.
- [Dimensions](https://getaimath.com/dictionary/dimensions/): Dimensions are the number of values in a vector, like the number of directions it can point in.
- [Approximate Nearest Neighbors (ANN)](https://getaimath.com/dictionary/approximate-nearest-neighbors-ann/): Approximate nearest neighbors finds results that are almost certainly the closest matches, much faster than checking every item.
- [Vector](https://getaimath.com/dictionary/vector/): A vector is an ordered list of numbers, often used to represent a point or direction in many dimensions.
- [HNSW](https://getaimath.com/dictionary/hnsw/): HNSW, or Hierarchical Navigable Small World, is a popular ANN method that organizes vectors into layered networks for fast searching.

---
Source: The AI Math Dictionary (https://getaimath.com/dictionary/cosine-similarity/)
