What is Cosine Similarity
Measure of similarity between two vectors. Learn what cosine similarity is and learn about the technology powering AI systems.
By AI Glossary Team
Published: May 19, 2026
What is Cosine Similarity?
Cosine similarity is a way to measure how similar two things are, usually words or documents. It works by turning each piece of text into a vector, which is like a list of numbers that represent what the text is about. The vectors are then compared using a formula that looks at the angle between them. When the angle is small, the vectors are similar, and when it’s large, they’re not. This is where the “cosine” part comes in - it’s a mathematical function that helps calculate this angle. The result is a number between 0 and 1, where 1 means the vectors are identical and 0 means they’re completely different. This concept is often used in machine learning and natural language processing to understand how similar or different two pieces of text are.
Think of It Like This
Imagine you’re at a party and you meet two people, John and Jane. You start talking to them and realize that John likes hiking, reading, and traveling, while Jane likes shopping, watching movies, and playing video games. You could say that John and Jane are not very similar because they have different interests. But what if you met someone else, let’s call him Bob, who likes hiking, reading, and watching movies? You could say that Bob is somewhat similar to John because they share two common interests, but also somewhat similar to Jane because they share one common interest. This is similar to how cosine similarity works - it measures the similarity between two vectors by looking at the angle between them, just like you’re looking at the similarity between John, Jane, and Bob’s interests.
Why Should You Care?
Cosine similarity matters because it’s used in many applications that we use every day. For example, when you search for something on Google, the search engine uses cosine similarity to determine which results are most relevant to your query. It’s also used in recommendation systems, like Netflix or Spotify, to suggest movies or songs that you might like based on what you’ve watched or listened to before. This is because these systems can analyze the vectors of your past behavior and compare them to the vectors of other users or items, to find the ones that are most similar. By understanding how similar or different two pieces of text are, these systems can provide more accurate and personalized recommendations.
Where You’ve Already Seen It
You’ve probably already seen cosine similarity in action, even if you didn’t realize it. For example, when you type a query into Google, the search engine uses cosine similarity to rank the results. It’s also used in Facebook’s news feed algorithm, which tries to show you posts that are most relevant to your interests. Another example is Amazon’s product recommendation system, which uses cosine similarity to suggest products that you might like based on your past purchases and browsing history. These systems all rely on cosine similarity to understand how similar or different two pieces of text are, and to provide more accurate and personalized results.
The One Thing to Remember
The key thing to remember about cosine similarity is that it measures the angle between two vectors, not their magnitude. This means that two vectors can have very different lengths, but still be very similar if they point in the same direction. This is an important concept to understand, because it’s what allows cosine similarity to be used in so many different applications. By focusing on the angle between the vectors, rather than their length, cosine similarity can provide a more nuanced and accurate measure of similarity.
Related Terms
natural-language-processing, vector-space-model, recommendation-systems
Related Terms
None