

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
Let's learn our first method for measuring similarity between embeddings: the dot product.
The dot product measures how much two vectors point in the same direction. It's calculated by multiplying corresponding elements and summing the results. Say we want the dot product of these two vectors:
[.8, .5, .5][.5, .4, .6]First we multiply each pair of corresponding elements:
.8 × .5 = 0.4.5 × .4 = 0.2.5 × .6 = 0.3Then we sum those products:
0.4 + 0.2 + 0.3 = 0.9The final result is 0.9. The more similar the vectors are, the higher the dot product will be. If they point in opposite directions, the dot product will be negative.
Later we'll use NumPy to handle vector math for us. But I want you to do it by hand at least once... for the learnings!
Implement the dot function. It takes two vectors (lists of floats) as input and returns their dot product (a single float).