

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Semantic Search
incomplete
2: Embeddings
incomplete
3: Embedding Models
incomplete
4: Model Selection
incomplete
5: Vector Operations
incomplete
6: Dimensions
incomplete
7: Dot Product Similarity
incomplete
8: Cosine Similarity
incomplete
9: Why Cosine Similarity?
incomplete
10: Generating Text Embeddings
incomplete
11: Document Embeddings
incomplete
12: Query Embeddings
incomplete
13: Same Model
incomplete
14: Implementing Semantic Search
incomplete
15: Locality-Sensitive Hashing
incomplete
16: Vector Databases
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
You might wonder: why cosine similarity specifically? Why not some other similarity metric?
The answer is that we want to use the same metric that our embedding model was trained on.
Embedding models learn to create vectors during training. The training process determines which similarity metric usually works best.
"We fine-tune the model using a contrastive objective. Formally, we compute the cosine similarity from each possible sentence pair from the batch."
Because our model was trained using cosine similarity, we should also use cosine similarity for search.
Good news – many sentence embedding models are trained with cosine similarity:
all-MiniLM-L6-v2: cosine similarityall-mpnet-base-v2: cosine similaritysentence-transformers models typically use cosine similarity.When using other embedding models in the future, double-check their documentation to be sure!