AI builder glossary
Cosine similarity
A measure of how closely two vectors point in the same direction, the standard way to score how similar two embeddings are in meaning.
Cosine similarity compares the angle between two vectors and ignores their length. Vectors pointing the same way score near 1, unrelated ones score near 0, and opposite ones score negative. For embeddings, a higher score means the two pieces of content are closer in meaning. Many systems work with cosine distance instead, which is one minus the similarity, so lower is closer.
It's the default metric for most text embedding models, and many models produce normalized vectors, where cosine similarity and inner product give the same ranking. Use whatever metric your embedding model's documentation recommends, and make sure your index is built for that same metric, or results will be quietly worse.
The common mistake is treating scores as universal. A similarity of 0.8 can mean a strong match with one model and a mediocre one with another, and typical score ranges differ between short queries and long passages. Thresholds, such as a minimum score below which you say no good match, have to be calibrated on your own data and model, and rechecked whenever either changes.
Rankings are more reliable than absolute scores, which is one reason rank-based fusion and rerankers are popular downstream.
A semantic cache only reuses a stored answer when a new question's cosine similarity to a cached one clears a threshold the team tuned on a few hundred labeled pairs, rather than a number copied from a blog post.
Learn more in the course
Related terms
Go from definitions to doing
Learn to build AI-powered apps in 132 practical lessons.