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.
Or read this on Hacker News