HomeGlossaryCosine Similarity
RAG & Retrieval

Cosine Similarity

A metric that measures similarity between two vectors based on the cosine of the angle between them, commonly used for embeddings.

Cosine similarity measures how aligned two vectors are in direction, independent of their magnitude. Values range from -1 (opposite) to 1 (identical). It's the most common similarity metric in vector search because it focuses on semantic direction rather than length.

For normalized embeddings, cosine similarity is equivalent to the dot product. Vector databases use it to find the most semantically similar chunks to a query embedding.

Formula: cos(θ) = (A · B) / (||A|| × ||B||). For normalized vectors, this simplifies to just the dot product.

Most embedding models output normalized vectors so cosine similarity can be computed efficiently as a dot product. This is why vector databases optimize heavily for this operation.

Related Terms

← Back to Glossary