A similarity metric produces a numerical score describing how closely two items or vector representations are related. In semantic search, it compares a query embedding with document embeddings so related meanings can rank above exact keyword matches. section 3.3 section 4.3
Similarity-based retrieval proceeds through these steps:
- Represent the query and searchable documents as dense vectors. section 4.3
- Measure vector proximity with cosine distance, which emphasizes orientation, or Euclidean distance, which measures straight-line separation. section 4.3
- Sort the resulting scores and return the highest-ranking matches. section 4.3
- Use bi-encoder embeddings for comparison, or a cross-encoder that jointly processes two sentences for a fine-grained similarity score. section 4.3
Cosine search over hotel reviews
Encode the query "Hotel near the Louvre with great food nearby," compute cosine scores against review embeddings, select the five highest scores, and print each hotel, review, and score. A NumPy implementation calculates dot products and vector norms before sorting the scores in descending order. section 4.3
Figure 3.2 Imagine a map where countries are placed based on how similar their names are. This plot is like that map but for words instead of countries. Words close together have similar meanings. For example, China is closer to Russia than France because their names are more related.
Use the vector-space illustration to see why nearby representations indicate related meanings, such as dog, puppies, canines, and pets. section 3.3













