How are embeddings usually compared in semantic search?
Options
- By checking that the same words appear in both texts
- By sorting the vectors alphabetically
- By the length of each text
- By the cosine similarity (or dot product) between the vectors: the nearest vectors are the most similar texts (Correct option)
Answer
By the cosine similarity (or dot product) between the vectors: the nearest vectors are the most similar texts
Why
Embeddings are vectors, so "similar" becomes "close". Cosine similarity measures the angle between two vectors; the closer to 1, the more alike the meaning.
When vectors are normalized to length 1, cosine similarity and the dot product give the same ranking.
This is what lets a search for "cheap flights" find a page about "low-cost airlines".
Remember
Nearest vectors = most similar meaning.