Last updated

Embeddings Explained

Definition: An embedding turns a piece of text into a list of numbers (a vector) that captures its meaning. Texts with similar meaning get similar vectors — which is what makes searching by meaning possible.

Why turn words into numbers?

Computers cannot compare meaning directly, but they are great at comparing numbers. If "car" and "automobile" map to nearby vectors, the computer can tell they are related — even though they share no letters.

A tiny, simplified embedding

Real embeddings come from trained models and have hundreds of dimensions. But the idea is simple: represent text as numbers. The runnable demo below makes a basic "bag of words" vector — counting how often each vocabulary word appears.

vocab = ["cat", "dog", "fish", "run"]
"cat dog"      -> [1, 1, 0, 0]
"dog dog run"  -> [0, 2, 0, 1]

Run it and change the sentences to see the vectors change.

💡 Real life: you would call an embedding model (from OpenAI, Cohere, or an open-source one) instead of counting words — but it returns the same kind of thing: a vector of numbers.

Try it Yourself
Output

          
Ad · responsive