

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
Now we'll combine everything we've learned to build a complete semantic search engine. It will find movies based on meaning rather than exact keyword matches. Our semantic search system has five main steps:
For semantic search, we use cosine similarity to compare vectors. It measures the angle between two vectors and gives us a score from -1.0 to 1.0:
1.0: Vectors point in the same direction (identical meaning)0.0: Vectors are perpendicular (unrelated)-1.0: Vectors point in opposite directions (opposite meaning)Build a complete semantic search system that finds movies by meaning. You'll combine all the pieces you've built in previous lessons.
import numpy as np
def cosine_similarity(vec1: np.ndarray, vec2: np.ndarray) -> float:
dot_product = np.dot(vec1, vec2)
norm1 = np.linalg.norm(vec1)
norm2 = np.linalg.norm(vec2)
if norm1 == 0 or norm2 == 0:
return 0.0
return dot_product / (norm1 * norm2)
"No embeddings loaded. Call `load_or_create_embeddings` first."
score: The cosine similarity scoretitle: The movie titledescription: The movie description1. Spaceflight IC-1: An Adventure in Space (score: 0.4406)
The opening narrative is given by a man in a high ranking military uniform. He tells us the film is ...
2. Adventureland (score: 0.4150)
In 1987, James Brennan (Jesse Eisenberg) has two plans. The first plan is to have a summer vacation ...
3. Odyssey 5 (score: 0.4038)
The story follows six people on a routine flight of the space shuttle Odyssey, on August 7, 2007: fo...
Run and submit the CLI tests.