Get the latest tech news

How does cosine similarity work?


When working with LLM embeddings, it is often important to be able to compare them. Cosine similarity is the recommended way to do this.

The general concept of "embeddings" is an offshoot of the Large Language Model (LLM) technology that makes tools like ChatGPT work. 2D vectors (that is to say, arrays with only 2 numbers) are much less useful in the context of embeddings, but the same principles apply, and we can use them to illustrate how cosine similarity works. Now that we've unpicked all the parts of the formula, we can put them together to create a JavaScript function that calculates the cosine similarity of any two vectors.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Work

Work

Photo of Cosine Similarity

Cosine Similarity

Related news:

News photo

The work you do, the person you are (2017)

News photo

Amazon bans its drivers from moving their own lips too much at work

News photo

Amazon Drivers Complain Their Ability to Sing Along the Radio Is Being Stifled