androidengineers.Book a session

Making models useful

Embeddings: meaning as numbers

article6 min

Computers cannot compare meanings directly — but they are very good at comparing numbers. An embedding turns a piece of text into a list of numbers (a vector) so that texts with similar meanings get similar numbers.

Similar meaning, nearby numbers

An embedding model might turn sentences into vectors like these (real ones have hundreds or thousands of numbers; these are shortened toy examples):

"How do I reset my password?"      →  [0.81, 0.10, 0.32]
"I forgot my login details"        →  [0.78, 0.15, 0.30]
"What time does the shop open?"    →  [0.05, 0.90, 0.12]

The first two sentences share almost no words, but their vectors are close because their meaning is close. That is what makes embeddings so useful: they find related text even when the wording is different.

Measuring "close"

The most common measure is cosine similarity: it compares the direction of two vectors. 1 means pointing the same way (very similar), 0 means unrelated.

# academy-check
import math

def cosine(a, b):
    dot = sum(x * y for x, y in zip(a, b))
    return dot / (math.sqrt(sum(x * x for x in a)) * math.sqrt(sum(y * y for y in b)))

reset = [0.81, 0.10, 0.32]
login = [0.78, 0.15, 0.30]
hours = [0.05, 0.90, 0.12]
print(round(cosine(reset, login), 2))  # 1.0  (very similar)
print(round(cosine(reset, hours), 2))  # 0.21 (unrelated)
assert cosine(reset, login) > cosine(reset, hours)

What embeddings are used for

  • Semantic search: find the help articles most related to a question, even without matching keywords.
  • Grounding answers (RAG): find the right documents to give the model — the next lesson.
  • Grouping and recommendations: cluster similar tickets, suggest related content.

One thing to remember

"Similar" is not the same as "correct" or "allowed". A very similar document can still be outdated, or belong to a different customer. Real systems combine similarity with checks on freshness and permissions.

Try it: write three sentences — two that mean the same thing in different words, and one about something else. Predict which pair an embedding model would score as most similar.

Quick check: why can embeddings find "I forgot my login details" when someone searches "reset password"? (Because they compare meaning as vectors, not exact words.)

YOUR LEARNING JOURNEY

0 of 15 available lessons completed

Progress saved in this browser. No account needed.