Lesson 4.4 · 4 of 10 · 4 min read · Reviewed 24 Nov 2026
Where embeddings show up in real systems
By the end, you can
- Recognise where embeddings appear in real systems.
- Connect embeddings to later parts of the course.
Common uses
| Use | How embeddings help | Where in this course |
|---|---|---|
| Semantic search | Find documents by meaning | 4.3 |
| RAG retrieval | Find passages to ground answers | Part 4 |
| Agent memory | Recall relevant past notes and episodes | Part 10 |
| Deduplication | Spot near-identical tickets or documents | |
| Clustering | Group items into themes without labels | |
| Classification | Train a light classifier on embeddings | |
| Recommendations | “Similar articles” or “people also read” | |
| Example selection | Pick the most similar few-shot examples for a query | Chapter 12 |
| Tool selection | Narrow a large tool list to relevant ones | Chapter 34 |
A clustering sketch
tickets --> embed --> cluster (for example k-means, 20 groups)
--> for each cluster, ask Claude: "Name the common theme of these 10 tickets"
This mixes both kinds of model: embeddingsEmbedding: A list of numbers (a vector) that represents the meaning of a piece of text, so similar meanings land close together. to group, Claude to explain.
Costs and upkeep
Embedding every item costs a little per item and must be redone if you change the embedding modelEmbedding model: A model trained to turn text (or images) into embeddings for search and comparison, rather than to generate text., because vectors from different models aren’t comparable. Store the model nameModel id: The exact string that names a model in an API request, such as a specific model version. and version with every vector.
Key points
- Embeddings power semantic search, RAG retrieval, deduplication, clustering, classification and recommendations.
- In agents, they help recall relevant memories and pick relevant tools or examples.
- They are a building block: useful alone, and essential inside RAG and memory systems.
Cluster support tickets into themes
Group unlabelled tickets by embedding similarity and name each group.
You will have: A script that clusters nine toy-embedded tickets into three themes with k-means and prints each cluster.
Steps
- Run the starter: every ticket lands in cluster 0.
- Fill in assign(): put each ticket in the cluster whose centre is most similar (cosine).
- Fill in update(): move each centre to the mean of its tickets.
- Run five rounds from the fixed starting centres and print the clusters.
- Write a one-word theme name for each cluster, as you would ask a model to do.
Done when
- Three clusters of three tickets each.
- Each cluster holds only one theme (account, billing or shipping).
- The script prints 'sizes: [3, 3, 3]'.
Open in the Playground No API key needed.
Starter code (Python)
import math
# Toy embedding: 5 named dimensions. Real models learn hundreds you can't name.
DIMS = ["account", "billing", "shipping", "device", "pets"]
WORDS = {
"password": [1, 0, 0, 0, 0], "login": [1, 0, 0, 0, 0], "locked": [0.8, 0, 0, 0, 0], "code": [0.6, 0, 0, 0.2, 0],
"charged": [0, 1, 0, 0, 0], "invoice": [0, 1, 0, 0, 0], "refund": [0, 0.8, 0.3, 0, 0], "twice": [0, 0.4, 0, 0, 0],
"parcel": [0, 0, 1, 0, 0], "delivery": [0, 0, 1, 0, 0], "late": [0, 0, 0.6, 0, 0], "courier": [0, 0, 0.9, 0, 0],
"laptop": [0, 0, 0, 1, 0], "screen": [0, 0, 0, 0.9, 0], "battery": [0, 0, 0, 0.9, 0], "power": [0, 0, 0, 0.7, 0],
"cat": [0, 0, 0, 0, 1], "kitten": [0, 0, 0, 0, 1], "nap": [0, 0, 0, 0, 0.6], "sleeps": [0, 0, 0, 0, 0.6],
}
TICKETS = ["password reset failed", "login code not arriving", "account locked again",
"charged twice this month", "refund still missing", "wrong invoice total",
"parcel never arrived", "courier left it outside", "delivery late again"]
def embed(t):
v = [0.0] * len(DIMS)
for w in t.lower().split():
for i, x in enumerate(WORDS.get(w, [0] * len(DIMS))):
v[i] += x
return v
def cosine(a, b):
dot = sum(x * y for x, y in zip(a, b))
la, lb = math.sqrt(sum(x * x for x in a)), math.sqrt(sum(x * x for x in b))
return dot / (la * lb) if la and lb else 0.0
vecs = [embed(t) for t in TICKETS]
centres = [vecs[0], vecs[3], vecs[6]] # fixed start, so the result is deterministic
def assign(vecs, centres):
return [0 for v in vecs] # TODO: index of the most similar centre for each vector
def update(vecs, labels, k):
return centres # TODO: mean vector of each cluster
for _ in range(5):
labels = assign(vecs, centres)
centres = update(vecs, labels, 3)
for c in range(3):
print(c, [t for t, l in zip(TICKETS, labels) if l == c])
Show a solution
import math
# Toy embedding: 5 named dimensions. Real models learn hundreds you can't name.
DIMS = ["account", "billing", "shipping", "device", "pets"]
WORDS = {
"password": [1, 0, 0, 0, 0], "login": [1, 0, 0, 0, 0], "locked": [0.8, 0, 0, 0, 0], "code": [0.6, 0, 0, 0.2, 0],
"charged": [0, 1, 0, 0, 0], "invoice": [0, 1, 0, 0, 0], "refund": [0, 0.8, 0.3, 0, 0], "twice": [0, 0.4, 0, 0, 0],
"parcel": [0, 0, 1, 0, 0], "delivery": [0, 0, 1, 0, 0], "late": [0, 0, 0.6, 0, 0], "courier": [0, 0, 0.9, 0, 0],
"laptop": [0, 0, 0, 1, 0], "screen": [0, 0, 0, 0.9, 0], "battery": [0, 0, 0, 0.9, 0], "power": [0, 0, 0, 0.7, 0],
"cat": [0, 0, 0, 0, 1], "kitten": [0, 0, 0, 0, 1], "nap": [0, 0, 0, 0, 0.6], "sleeps": [0, 0, 0, 0, 0.6],
}
TICKETS = ["password reset failed", "login code not arriving", "account locked again",
"charged twice this month", "refund still missing", "wrong invoice total",
"parcel never arrived", "courier left it outside", "delivery late again"]
def embed(t):
v = [0.0] * len(DIMS)
for w in t.lower().split():
for i, x in enumerate(WORDS.get(w, [0] * len(DIMS))):
v[i] += x
return v
def cosine(a, b):
dot = sum(x * y for x, y in zip(a, b))
la, lb = math.sqrt(sum(x * x for x in a)), math.sqrt(sum(x * x for x in b))
return dot / (la * lb) if la and lb else 0.0
vecs = [embed(t) for t in TICKETS]
centres = [vecs[0], vecs[3], vecs[6]]
def assign(vecs, centres):
return [max(range(len(centres)), key=lambda c: (cosine(v, centres[c]), -c)) for v in vecs]
def update(vecs, labels, k):
out = []
for c in range(k):
members = [v for v, l in zip(vecs, labels) if l == c]
out.append([sum(col) / len(members) for col in zip(*members)] if members else centres[c])
return out
for _ in range(5):
labels = assign(vecs, centres)
centres = update(vecs, labels, 3)
for c in range(3):
print(c, [t for t, l in zip(TICKETS, labels) if l == c])
print("sizes:", [labels.count(c) for c in range(3)])