Lesson 1 of 3 · Embeddings & Semantic Search
What Embeddings Are
A customer support team at a SaaS company had a knowledge base with 3,000 articles. Their search was keyword-based. When a customer typed "my dashboard is not loading," the search returned articles containing the words "dashboard," "not," and "loading" -- including an article about "Loading Custom Dashboard Themes" that was completely irrelevant. Meanwhile, the article titled "Troubleshooting Blank Screens After Login" -- the exact solution to the customer's problem -- did not appear because it never used the word "loading."
They switched to semantic search powered by embeddings. The same query now returns the blank screen troubleshooting article first, because the system understands that "dashboard is not loading" and "blank screen after login" mean the same thing.
That is what embeddings do. They turn text into meaning.
1536
Dimensions in a text-embedding-3-small vector -- each one captures a facet of meaning
What You Will Learn
- What embeddings are and why they matter
- How high-dimensional vectors capture semantic meaning
- Why cosine similarity works for comparing meanings
- The fundamental limitation of keyword search that embeddings solve
From Words to Numbers
An embedding is a list of numbers that represents the meaning of a piece of text. Not the characters, not the word count, not the sentiment score -- the meaning.
When you send the sentence "The patient has a fever" to an embedding model, you get back something like this:
Each number captures one dimension of the text's meaning. No single number means anything on its own -- just like no single pixel defines a photograph. But together, these 1,536 numbers create a rich representation of what the text is about.
The critical insight: texts with similar meanings produce similar numbers. "The patient has a fever" and "The sick person has an elevated temperature" generate vectors that are close together in this 1,536-dimensional space. "The stock market crashed today" generates a vector that is far away.
High-Dimensional Space
Why 1,536 dimensions? Because meaning is complex.
Consider just two dimensions. You could place "happy" and "sad" on an x-axis (emotion valence) and "calm" and "excited" on a y-axis (energy level). That gives you four quadrants:
- Happy + Calm = Content
- Happy + Excited = Ecstatic
- Sad + Calm = Melancholic
- Sad + Excited = Distressed
But two dimensions cannot capture that "nostalgic" is a bittersweet emotion that is both happy and sad. Or that "anxious" is different from "excited" even though both are high-energy. Or that "professional" and "casual" are a separate axis entirely.
Real language has thousands of meaning dimensions: topic, tone, formality, domain, intent, time reference, certainty level, audience, complexity, and hundreds more. Each of the 1,536 dimensions in an embedding captures some blend of these semantic properties.
Cosine Similarity
Once you have two vectors, you need a way to measure how similar they are. The standard metric is cosine similarity.
Cosine similarity measures the angle between two vectors, ignoring their length. It returns a value between -1 and 1:
- 1.0: Identical meaning (or very close)
- 0.7-0.9: Related, similar topic
- 0.3-0.6: Loosely related
- 0.0: Unrelated
- Negative: Opposite or very different
Euclidean distance (straight-line distance between two points) is affected by vector magnitude. If one text is represented by a longer vector purely due to how the model processed it, Euclidean distance will say the texts are far apart even if they point in the same direction (same meaning). Cosine similarity only cares about the angle -- the direction of meaning, not the magnitude. This makes it more robust for comparing embeddings.
Why Keyword Search Fails
Keyword search matches character patterns. "Running" matches "running" but not "jogging." "Car" matches "car" but not "automobile." This creates two failure modes:
False negatives (missed results): The user searches for "how to fix a slow computer" but the best article is titled "Optimizing PC Performance" -- no keyword overlap.
False positives (irrelevant results): The user searches for "apple stock price" and gets articles about apple farming because the word "apple" matches.
Semantic search does not replace keyword search entirely -- it complements it. The most effective search systems combine both, as we will see in Chapter 2.
Explore the Embedding Space
beginnerUse embeddings when your users describe problems in their own words rather than using your exact terminology. Combine semantic search with keyword search for best results. Measure search quality with real user queries before and after switching to embeddings.
Assume embeddings are always better than keywords. For exact-match queries (product SKUs, error codes, proper names), keyword search is faster and more accurate. Do not use semantic search as a complete replacement without benchmarking against your actual query patterns.
Use ← → to navigate, Space to mark complete