Cosine distance measures how differently two vectors point. In natural language processing, comparing the directions of encoded messages can estimate similarity in meaning more effectively than comparing individual words or raw vector lengths. section 1.6 section 3.3
Euclidean distance measures the length of the difference between vectors. Cosine distance instead tracks the angle between them: larger angles produce values closer to 1, and vectors 90 degrees apart have distance 1. Its bounded range makes it practical for high-dimensional representations. section 3.3
Cosine distance supports several stages of language-vector analysis:
- Represent words or messages with continuous vector dimensions such as topic, sentiment, or question-likelihood. section 1.6
- Compare high-dimensional vectors when Euclidean distance would produce unwieldy values. section 3.3
- Use cosine similarity, calculated as 1 minus cosine distance, when a larger score should mean greater closeness. section 3.3
- Apply the metric to natural-language representations such as bag-of-words, n-grams, and TF–IDF vectors. section 3.10
A small NumPy comparison
For vectors v1 = (1, 0) and v2 = (2, 1), subtracting v1 from v2 gives (-1, -1), whose Euclidean length illustrates ordinary vector distance. With much larger vectors, compare their directions using cosine distance; the result remains bounded by 1 regardless of dimensionality. section 3.3
Figure 3.2 2D Euclidean distance
Inspect the two-dimensional diagram to visualize how vector subtraction produces a difference arrow and an ordinary Euclidean distance. section 3.3





