Cosine similarity is a metric that measures the cosine of the angle between two non-zero vectors in an inner product space, quantifying their directional alignment irrespective of their magnitudes. In vector search and semantic retrieval, it is the predominant method for gauging the semantic similarity between text embeddings, where a value of 1 indicates identical direction, 0 indicates orthogonality (no similarity), and -1 indicates opposite direction. This magnitude-invariant property makes it ideal for comparing dense embeddings from models like BERT or GPT, where the vector length (norm) is often not semantically meaningful.
