Skip to Content

Embeddings

An embedding turns a word, sentence or image into a list of numbers, so that similar things get similar numbers. Explore a map of words and measure meaning as distance.

9 minFree

Meaning as distance
  1. Map
  2. Vector
  3. Neighbours
  4. Far apart
  5. Directions
  6. Explore
Embedding map (tap a word)
dosaidlisambarvada pavpav bhajipizzaChennaiMaduraiMumbaiPunerainmonsoonhumidsunnytrainbusmetroauto
foodplaceweathertransport
“dosa” as 8 numbers
0.90food
0.00weather
0.00travel
0.00place
0.60TN
0.00MH
0.10dim 7
0.20dim 8
Cosine similarity to “dosa”
  • Press Play, or tap a word.
Map

An embedding turns each word into a list of numbers: a point in space. Here every word has 8 numbers, squashed onto this 2D map. Words used in similar ways end up near each other. Press Play.

The 8 numbers per word are made up so the dimensions can be labelled. Real embeddings have hundreds of unlabelled dimensions (256 to 1024 is common for words). Cosine similarity and the vector arithmetic are the real maths, and the map was computed from these vectors.

Background: the idea in plain words1 min read

A computer can't compare "dosa" and "idli" as words. To a program they're just different strings (pieces of text). It has no idea that both are things you eat.

An embedding fixes that: it turns each item into a vector (a list of numbers) so that items with similar meanings get similar numbers. Each vector is a point in an embedding space (think of a map), and the distance between two points tells you how related they are.

Nobody types these numbers in by hand. A model learns them during training. Words that are used in similar contexts end up close together.

A tiny example: on the map below, "idli" sits close to "dosa" and far from "Mumbai". So a program can now work out that idli and dosa are related, just by comparing numbers.

You've seen embeddings already: inside an LLM, every token becomes an embedding before the transformer runs (see What is an LLM?). The same idea powers semantic search (search by meaning, not by exact words), recommendations and the "retrieval" step that grounds an agent in your documents.

The usual way to compare two embeddings is cosine similarity: how closely the two vectors point in the same direction. Picture two arrows starting from the same spot. Close to 1 means very similar. Close to 0 means unrelated.

Press Play to walk through the map. Afterwards, tap any word to see its nearest neighbours.

What to notice

  1. Meaning becomes geometry. Foods cluster together, cities cluster together, weather words cluster together. Nobody drew those groups: they fall out of the numbers.
  2. There's structure inside a cluster too. Chennai sits nearer Madurai than Mumbai, and idli nearer dosa than vada pav, because the vectors also carry a sense of region.
  3. Directions can mean something. Subtracting Chennai and adding Mumbai moves "idli" towards Mumbai's food. Real embedding models show patterns like this, though they're never this neat.
  4. Real dimensions have no names. The toy example labels its 8 dimensions so you can read them. Real word embeddings typically have 256, 512 or 1024 dimensions, learned during training, and single dimensions rarely mean anything a person could name.
  5. Similarity is a choice of maths. Google's guide describes three common measures: Euclidean distance, cosine and dot product. Cosine ignores the length of the vectors; dot product doesn't. When vectors are normalised to length 1, all three rank neighbours the same way.

Keyword search

Matches the exact letters. A search for "monsoon" misses a document that only says "rain".

Embedding search

Matches meaning. "monsoon" and "rain" have nearby embeddings, so the document is found.

Go deeper

Words to know

1 min read
WordMeaning in simple words
EmbeddingA list of numbers that stands for a word, sentence or image, so that similar things get similar numbers
VectorA list of numbers. You can picture it as a point, or as an arrow
Embedding spaceThe "map" where every embedding is a point
DimensionOne of the numbers in a vector. Real embeddings have hundreds of them
Cosine similarityA score for how closely two vectors point the same way. Close to 1 means very similar
Semantic searchSearch that matches meaning instead of exact words

Check your understanding

1. Two words have a cosine similarity of 0.97. What does that tell you?
2. Why can embedding search find a document about “rain” when you search for “monsoon”?
3. Can you read off what dimension 37 of a real embedding means, like “food-ness”?
Sources: the official documentation3 links

Something wrong or unclear in this lesson? Tell us, it gets fixed.