Measuring Embedding Similarity
Understand the distance and similarity metrics that power vector search and how to choose the right one.
From Vectors to Meaning
An embedding maps text to a list of numbers in high-dimensional space. Texts with similar meaning land close together. To rank results we need a way to measure that closeness.
Cosine Similarity
Cosine similarity measures the angle between two vectors, ignoring their length. It ranges from -1 (opposite) to 1 (identical direction).
import numpy as np
def cosine(a, b):
a, b = np.array(a), np.array(b)
return a.dot(b) / (np.linalg.norm(a) * np.linalg.norm(b))
print(cosine([1, 0], [1, 1])) # ~0.707All lessons in this course
- Understanding Text Embeddings
- Introduction to Vector Databases
- Storing and Retrieving Embeddings
- Measuring Embedding Similarity