Cosine distance measures vector dissimilarity through angular separation; cosine similarity is commonly expressed as one minus this distance. section 3.4 section 4.0
In semantic search, encode a query and documents as embeddings, calculate cosine distance for each pair, and identify the smallest distance as the closest match. section 3.4
Ranking encoded sentences
Sentence Transformers encodes six example sentences into vectors with shape (6, 384). SciPy computes each cosine distance; converting scores with 1 - distance yields similarity. For the query “Machine learning,” the matching sentence scores 0.6723 and ranks first. section 3.4
Figure 3.4 A graphical demonstration of cosine similarity using two dimensions ("pet" and "furry"). Three words are drawn as vectors into the coordinate system. θ 1 denotes the angle between bird and dog, θ 2 depicts the angle between dog and cat, respectively. The smaller angle θ 2 illustrates a higher similarity of dogs with cats compared to birds.’
A two-dimensional vector diagram relates smaller angular separation to higher cosine similarity. section 3.4








