What is Cosine Similarity?
Cosine similarity measures how similar two vectors are by computing the cosine of the angle between them, ignoring their magnitudes.
It is calculated as the dot product of the two vectors divided by the product of their lengths (magnitudes). The result ranges from -1 to 1, where 1 means identical direction, 0 means no similarity, and -1 means opposite directions.
The key idea is that it focuses purely on orientation rather than vector length, making it robust for high-dimensional or sparse data where absolute sizes vary.
It is commonly applied in data science to compare items like documents or user preferences represented as feature vectors.
Example
Two movie review vectors might share many positive words like 'great' and 'acting'; their cosine similarity of 0.85 shows they point in similar directions even if one review is much longer.
Why it matters
It powers modern search engines, recommendation systems, and clustering algorithms by efficiently finding similar items in large datasets without being skewed by document length.
Frequently asked questions
It means the two vectors point in exactly the same direction and are perfectly aligned.
Related terms
An embedding (or vector embedding) is a way to represent words, sentences, or other data as dense numerical vectors in a high-dimensional space so that similar items end up close together.
Batch size is the number of training examples processed together in a single forward and backward pass during model training.
Chunking is the process of breaking large datasets, documents, or files into smaller, fixed-size or semantically meaningful segments. It is a common data preprocessing step in AI/ML pipelines to manage memory and enable efficient processing.
Data augmentation is a technique that artificially increases the size and diversity of a training dataset by creating modified versions of existing data samples.
Data labeling is the process of adding tags or annotations to raw data so that machine learning models can learn from it during training.
A dataset is a structured collection of data points used to train, validate, or test machine learning models.