AI Terminology Course
AI Terminology
/
Advanced

Cosine Similarity

Definition

The most common mathematical metric used to measure how similar two vectors are. It measures the cosine of the angle between two multi-dimensional vectors.

Explain Like I'm New

Imagine two arrows shooting out from the center of a graph. If the arrows point in the exact same direction, they are identical concepts (Score = 1). If they form a 90-degree angle, they are completely unrelated (Score = 0). If they point in exact opposite directions, they are exact opposites (Score = -1).

Real World Example

In a Vector Database, when you ask a question, the database calculates the Cosine Similarity between your Question Vector and every Document Vector. It sorts the list, and the document with a score closest to 1.0 is returned as the best answer.

Common Use Cases

  • •Vector comparisons
  • •Similarity scoring

Interview Questions

basic

  • If two vectors have a Cosine Similarity score of 0.99, are they highly similar or highly different?

intermediate

  • Why is Cosine Similarity generally preferred over 'Euclidean Distance' for text embeddings?

Flash Cards

Question

Similar or different?

Click to reveal answer
Answer

Highly similar. A score of 1.0 is a perfect match.

Question

Why Cosine over Euclidean?

Click to reveal answer
Answer

Euclidean Distance measures the physical distance between the tips of the arrows. If a document mentions 'Apple' 5 times, and another mentions it 500 times, their Euclidean distance is huge. Cosine measures the *angle*. Since both documents point in the 'Apple' direction, Cosine recognizes they are about the same topic, regardless of document length.