Course contents · Lesson 9 of 15

What Are Embeddings? Meaning as Numbers, Explained

Retrieval-Augmented Generation · Lesson 9 of 15 · 8 min Foundations

You type "cheap cab to the airport" into a travel app, and the top result is a page called "Low-cost taxi rides to the terminal". Apart from "to the", the two phrases share no words, yet the app knew you meant the same thing. The idea that makes this work is called an embedding. This lesson answers the question what are embeddings, and shows how a computer can turn the meaning of a sentence into numbers it can compare.

Every piece of text gets a place on a map

Think of a city map. Every shop has a location you can write as two numbers: how far east and how far north it is. Shops of the same kind often cluster, such as jewellers on one street or phone repair stalls in one market. If you know where one sweet shop is, looking nearby is a good way to find another.

An embedding does the same for text. It gives every word, sentence or paragraph a location, but the location is chosen by meaning rather than by street. Texts about animals end up in one neighbourhood, texts about vehicles in another, and texts about fruit somewhere else. The map below is a tiny, flattened sketch of that idea.

A 2D map where cat, kitten, dog and puppy form one cluster, car, bus, truck, taxi and cab form another with taxi and cab almost touching, and banana, apple and mango sit far away in a third
Nobody labelled these groups: they appear because the model places texts with similar meanings near each other, which is why "taxi" and "cab" almost touch.

What an embedding actually is

An embedding is a list of numbers that describes a piece of text. Mathematicians call such a list a vector, so you will hear "embedding" and "vector" used for the same thing. On a city map the list has two numbers. A real embedding has hundreds or thousands, for example 384, 768 or 1,536. Each extra number gives the model one more direction in which meanings can differ.

The list comes from an embedding model: a neural network (the team of tiny voters from What Is a Neural Network?) trained for one job, turning text into a vector. During training it sees huge numbers of related text pairs, such as a question and its answer, or two sentences that say the same thing. It adjusts its weights until related texts come out with nearby vectors and unrelated texts come out far apart.

No single number has a human meaning such as "is an animal" or "is about money". The meaning lives in the whole pattern, which is why you never read an embedding yourself; you only compare it with other embeddings. One rule follows from this: only compare vectors that the same model made. Two different models build two different maps, and their coordinates do not line up.

Flowchart: a sentence goes into an embedding model, which outputs a vector of numbers; the vector is then stored for later search or compared with other vectors from the same model
Whatever the length of the text, the model returns a list of the same length, ready to be stored or compared with lists from the same model.

Why similar meanings land close together

Because the model was trained to place related texts near each other, closeness on the map means closeness in meaning. "How do I reset my password?" and "I forgot my login details" share no words, yet a good embedding model puts them side by side. "How do I reset my router?" shares most of its words with the first question, but it usually lands further away, because it is about a different problem.

This is the big change from older search. A keyword search asks "which documents contain these exact words?" An embedding search asks "which documents mean something close to this?" Synonyms, different phrasing and, with a model trained on many languages, even the same idea written in Hindi or Spanish can match.

Measuring closeness: distance and angle

Once every text is a vector, "how similar are these two?" becomes a measurement. The simplest one is distance: imagine a straight line between two pins and measure its length. A short line means similar meaning, a long line means different meaning.

The more common measure is cosine similarity. Draw an arrow from the centre of the map to each pin. Cosine similarity ignores how long the arrows are and looks only at the angle between them. Arrows that point the same way score 1, arrows at a right angle score 0, and arrows that point in opposite directions score −1.

Two panels: arrows for taxi and cab are 10 degrees apart with cosine similarity about 0.98; arrows for taxi and banana are 80 degrees apart with cosine similarity about 0.17
Cosine similarity only looks at direction: a small angle between two arrows means two texts with a similar meaning.

Real scores depend on the model, so you mostly use them to rank: the text with the highest score is the closest match. Many embedding models also scale every vector to the same length. When they do, distance and cosine similarity put results in exactly the same order, so the choice between them matters less than it first seems.

What embeddings are used for, and where they fall short

Embeddings sit quietly behind many everyday features:

  • Semantic search: finding documents by meaning rather than exact words, like the taxi example.
  • Recommendations: suggesting films, songs or products whose vectors sit near the ones you liked.
  • Grouping: sorting thousands of customer comments into themes without reading each one.
  • Finding the right pages for a chatbot: picking the few passages an AI should read before it answers.

They also have limits. Embeddings capture general meaning, and they are weak at small details that flip the meaning. "The parcel arrived" and "The parcel has not arrived" can land very close, because both are about the same topic. Order numbers and error codes behave the same way: "INC-4821" and "INC-4812" look almost identical to an embedding model.

When the exact word or number matters, a classic keyword search still wins, which is why real systems often run both. Embeddings also inherit the gaps of the text the model learned from, so a model trained mostly on English may place other languages, slang or specialist terms poorly.

Check yourself

How can "I forgot my login details" match an article titled "Reset your password"?

Their embeddings sit close together because the model learned that they mean similar things; shared words are not needed.

Why shouldn't you compare a vector from one embedding model with a vector from another?

Each model builds its own map, so the same numbers point to different places, and the two lists may not even have the same length.

A customer searches for order "A-1047". Why might an embedding search alone return the wrong order?

Embeddings capture general meaning, so near-identical codes land close together; an exact keyword match is what finds the right one.