A distance function quantifies proximity or dissimilarity between vectors. In semantic search, it compares a query embedding with document embeddings so results can be ranked by relevance. section 4.3
Choose the metric according to the relationship the search should emphasize:
- Cosine distance measures the angle between vectors, emphasizing orientation rather than magnitude. section 4.3
- Euclidean distance measures the straight-line distance between points in a multidimensional space. section 4.3
- The selected metric can change both the quality and interpretability of search results. section 4.3
Cosine ranking for hotel search
Encode the query "Hotel near the Louvre with great food nearby," compute dot products against review embeddings, normalize by the query and review vector norms, sort similarities in descending order, and return the top five hotels with their scores.











