Topic 1 of 5 · 3 min read
Turning text into meaning vectors
Goal: Explain in plain words what an embedding is and predict which of several sentences will sit closest together.
An embedding is a list of numbers that stands for the meaning of a piece of text, built so that texts about the same thing get similar lists. An embedding model reads a sentence and returns that list. You never read the numbers yourself. You only compare them.
Check yourself · 1 of 3
What does an embedding model return for a sentence?
Why it matters
Computers are good at exact matches and poor at meaning. A plain text search for "cancel my plan" will miss a help article titled "How to end your subscription". The words differ, but a person sees the same idea. Embeddings give software a way to see it too. They are behind semantic search, "similar articles" boxes, duplicate detection and the lookup step in many chatbots that answer from your documents.
How it works
Think of a map. Every sentence gets a place on the map, and sentences about the same thing sit near each other. A real map has two numbers per place (latitude and longitude). An embedding has hundreds or thousands of numbers per sentence, so the "map" has that many directions. Nobody can draw it, but the idea is the same: near means similar in meaning.
The steps:
- You send a text, such as a product review, to an embedding model. Examples include models from OpenAI, Google, Cohere and open-weight ones you can run yourself.
- The model returns a list of numbers, called a vector. Its length is fixed by the model, for example the same length for every text.
- You store that vector next to the text.
- Later, you embed a new text the same way and look for stored vectors that are close to it.
The model learned this from huge amounts of text. Sentences used in similar situations ended up with similar vectors.
Before and after
Before: A keyword search for "laptop won't turn on" returns only pages that contain those exact words.
After: The same query, embedded, also finds "notebook does not start", "computer dead, no power light" and "battery drained and screen black". The words differ, the meaning is close, so the vectors are close.
Close also works across topics. "The cat sat on the mat" and "A kitten rested on the rug" sit near each other. "Quarterly revenue grew 8%" sits far from both.
What goes wrong
- Treating the numbers as readable. Single numbers in the vector do not mean "animal" or "money". Only the whole vector, compared with another, carries meaning.
- Expecting one kind of closeness. "Close" depends on what the model was trained to do. A model may treat "hot" and "cold" as close, because both are about temperature, even though they are opposites.
- Mixing models. Vectors from different models live on different maps. Comparing a vector from one model with a vector from another gives nonsense.
Remember the picture: an embedding is a place on a meaning map. Its only job is to tell you what is near.
Examples
Which sentence is closest?
Query: How do I reset my password?
| Sentence | Closeness to the query |
|---|---|
| I forgot my login details and cannot sign in | Close |
| Steps to change your account password | Very close |
| Our office is open 9 to 5 on weekdays | Far |
The first two share the idea of access to an account. The last is about opening hours, so it sits somewhere else on the map.
Optional code: get one embedding
For engineers. The call shape is similar across providers.
from openai import OpenAI
client = OpenAI()
resp = client.embeddings.create(
model="text-embedding-3-small",
input="How do I reset my password?",
)
vector = resp.data[0].embedding # a list of floats
print(len(vector))
Store vector with the text. Always record which model produced it.
Key points
- An embedding is a fixed-length list of numbers that represents the meaning of a text.
- Texts with similar meaning get vectors that sit close together, even when they share no words.
- The individual numbers in a vector are not readable; only comparisons between whole vectors carry meaning.
- Vectors from different embedding models are on different maps and cannot be compared with each other.
- Close means similar in topic or use, which is not always the same as having the same meaning.
Common mistakes
- Thinking each number in the vector means something, such as one number for sentiment.
- Comparing vectors made by two different embedding models.
- Assuming close always means the same meaning; opposite ideas about one topic can also be close.
Check yourself · 2 of 3
Which pair of texts would an embedding model most likely place closest together?
Check yourself · 3 of 3
A teammate embeds product reviews with one model and the new search query with a second model, then compares them. What is the likely result?
Practice items, not counted towards your mastery.
Start here
- Embeddings (Google Machine Learning Crash Course) (opens in a new tab)CourseFree
A free, visual course lesson on how embeddings place similar items close together in a vector space.
- Vector embeddings guide (OpenAI API docs) (opens in a new tab)DocsFree
Shows how to request embeddings, compare them with cosine similarity and use them for search and clustering.
- Sentence Transformers documentation (opens in a new tab)DocsFree
Open-weight embedding models you can run yourself, with semantic search and similarity examples.
More for this topic
- Efficient Estimation of Word Representations in Vector Space (opens in a new tab)PaperFree
The 2013 word2vec paper that showed word vectors capture meaning, the root of today's embeddings.