Vector Spaces and Similarity
What you'll learn: How embeddings use geometric distance measures to determine how similar two pieces of text really are.
The Core Idea
In the previous lesson, you learned that embeddings transform text into lists of numbers (vectors). But why? Because once text becomes a vector, you can measure how "close" two pieces of text are using geometric distance — just like measuring the distance between two points on a map.
Think of it this way: if "king" and "queen" have similar meanings, their embedding vectors should be close together in vector space. If "king" and "banana" are unrelated, their vectors should be far apart.
Two Key Distance Measures
Cosine Similarity
Measures the angle between two vectors. It ranges from -1 to 1, where 1 means identical direction (very similar), 0 means perpendicular (unrelated), and -1 means opposite. This is the most common measure in semantic search because it focuses on direction, not magnitude.
Analogy: Two arrows pointing in nearly the same direction are similar, even if one is longer.
Dot Product
Multiplies corresponding numbers in two vectors and sums them up. Higher values mean more similar. Unlike cosine similarity, dot product considers both direction and magnitude, so longer vectors produce larger scores.
Why This Matters
When you embed the query "machine learning tutorial" and compare it to thousands of documents, you're not doing keyword matching — you're finding vectors that point in similar semantic directions. This captures meaning, synonyms, and context that exact word matching would miss.
Key Takeaway: Embeddings turn semantic similarity into a geometric problem — measuring vector distances reveals how related meanings are, enabling powerful search and retrieval based on concepts, not just keywords.