# What Is an Embedding?

> What an embedding is, how distance shows similarity, and where embeddings fall short, explained simply for your AI interview.

**In short:** An embedding is a list of numbers that stands for the meaning of a piece of text. Texts with similar meaning get lists that sit close together, so a system can search by meaning instead of exact words.

AI and LLM interview question Q006, LLM fundamentals. Beginner, very common (our estimate). From Venkat R. Murty's free Interview Kit: https://designervenkat.online/interview/ai/what-is-an-embedding

## Say it in 30 seconds

An embedding is a list of numbers that stands for the meaning of a piece of text. Similar meanings get lists that sit close together, so a search can find a burst pipe claim when someone types ceiling leak. The lists come from a trained model, and distance tells you how related two items are. Embeddings can miss exact matches. Codes and names can slip past them, so I pair them with keyword search.

## Say it in 2 minutes

Think of an embedding as a grid reference on a map of meaning. An insurer might hold two hundred thousand past claim notes. A model reads each note and returns a list of numbers, and notes about similar problems land in nearby spots. The list is the embedding, and the map it lives on is the embedding space.

Here is the case I would walk through. A new note says water is coming through a kitchen ceiling. Keyword search only finds notes that share those words, so it can miss a note about an upstairs bathroom leak. An embedding search turns the new note into a list, compares it with the stored lists, and returns the closest ones first. The adjuster sees both water claims before the car claim.

Closeness is measured as distance. Two lists with a small distance are highly related, and a common measure is cosine similarity, which compares the direction of the two lists. Google's course says the distance between two items can be read as a measure of relative similarity. The numbers only compare fairly within one model, so I never mix vectors from two models.

The limits matter most in an interview. Embeddings can miss exact codes like a claim number, so I search those with keywords too. Changing the model means re-embedding everything, because the old lists no longer line up. The quality depends on the model and on your data, so I test on real questions from the team before trusting it.

## What is an embedding, in plain words?

A computer cannot compare two sentences by meaning the way a person does. It can compare two lists of numbers easily. An embedding bridges that gap: a model turns each piece of text into a list of numbers, and it is trained so that texts with similar meaning get similar lists.

Google's machine learning course describes an embedding as a vector representation of data in embedding space. A vector is just an ordered list of numbers. Embedding space is the imagined map those lists live on.

Think of a claims office that shelves files by cause and room, with the claim number only on the label. Two kitchen leaks sit on the same shelf, even when the clerks wrote them differently. An embedding is that shelf position, worked out for meaning.

Here is the problem. An insurer holds two hundred thousand past claim notes. A new note says water is coming through a kitchen ceiling. Keyword search only finds notes that share those words, so it misses a note about an upstairs bathroom leak. An embedding search finds it, because the meaning is close.

- **Embedding:** A list of numbers that stands for the meaning of a piece of data.
- **Vector:** An ordered list of numbers. Every embedding is a vector.
- **Embedding space:** The imagined map that all those lists live on.
- **Vector database:** A store built to find the saved lists nearest to a new one, fast.

## How does an embedding capture meaning?

An embedding model is trained on large amounts of text, so it learns which words and sentences get used in similar ways. Google's course says each item is represented by a fixed count of floating-point numbers, which are decimals such as 0.42 or -0.13. The count is chosen when the model is built, so every item from one model has the same length.

*Diagram, From claim note to closest match: A claim note goes into an embedding model, which returns a list of numbers. That list is saved in a vector database next to the claim. A new search becomes the same kind of list, and the database returns the nearest saved ones first.*
1. The claim note goes into the embedding model.
2. The model returns a list of numbers for it.
3. That list is saved in the database next to the claim.
4. A new search returns the saved lists nearest to it.

> "An embedding is a vector representation of data in embedding space." (Google, Machine Learning Crash Course)
>
> "The distance between two vectors measures their relatedness." (OpenAI)

Distance is how the map measures closeness. OpenAI's guide says small distances suggest high relatedness and large distances suggest low relatedness. So two claim notes about the same kitchen leak should sit closer together than a note about a car.

## How would the search rank three old claims?

Here is a small version with made-up numbers. Each claim has a vector of three numbers, which is far shorter than a real embedding, so the arithmetic is easy to read. The code scores each old claim with cosine similarity, where 1.00 means the same direction and a score near 0 means unrelated.

*Diagram, Old claims, closest first: A new note about a water leak is compared with every saved claim. The closest claims come first, so the adjuster reads the kitchen ceiling leak before the car claim. The scores come from the code below, which uses made-up vectors.*
1. Compared first with the kitchen ceiling leak, the closest match.
2. Next, the burst pipe, which is also water damage.
3. Last, the car claim, which shares almost no meaning.

```python
import math

# Made-up 3-number vectors for three past claims (real embeddings have far more numbers).
claims = {
    "Ceiling leak, kitchen": [0.90, 0.10, 0.20],
    "Pipe burst, upstairs": [0.55, 0.60, 0.15],
    "Car rear-end, no water": [0.10, 0.20, 0.90],
}

def cosine(a, b):
    # 1.00 means the same direction (very alike); near 0 means unrelated.
    dot = sum(x * y for x, y in zip(a, b))
    return dot / (math.hypot(*a) * math.hypot(*b))

# The new claim note, already turned into numbers by the same model.
query = [0.85, 0.20, 0.15]
ranked = sorted(claims.items(), key=lambda item: cosine(query, item[1]), reverse=True)
for name, vector in ranked:
    print(f"{cosine(query, vector):.2f}  {name}")
```

Output:

```text
0.99  Ceiling leak, kitchen
0.83  Pipe burst, upstairs
0.32  Car rear-end, no water
```

The pipe claim scores high too. It shares water damage with the kitchen leak, even though the room and floor are different. The map groups by meaning, so the same water damage lands close together across rooms.

> **Tip:** In an interview, call the score a similarity measure. It shows closeness, and a high score can still be a poor match, so check results against real cases.

## Where do the numbers come from?

Google's course gives two main routes. One is a dimensionality reduction technique such as PCA, which squeezes many features into fewer numbers. The other is to train the embedding as part of a neural network (a model that learns patterns from many examples), so the layer's numbers are learned for the task.

In that second route, the weights of the embedding layer are tuned during training so that similar examples land near each other. That is why an embedding made for support tickets can differ from one made for legal contracts.

Word2vec is the classic teaching example, though it is an older method that newer models have largely superseded. A 2013 paper titled Efficient Estimation of Word Representations in Vector Space, posted to arXiv on 16 January 2013, showed how to learn word vectors from very large text sets at much lower computational cost.

Word2vec gives each word one point, so the word bank gets the same spot whether it means a river edge or a bank account. Google's course calls this a limitation in some cases. Newer contextual models give a word a different vector depending on the words around it.

### How would you search 40,000 contracts by meaning?

A legal team wants every contract that limits liability for a data breach. Keyword search misses clauses that describe a breach in other words, so the team uses embeddings with a safety net.

1. **Split each contract into clauses:** Long contracts are cut into clause-sized pieces, so one clause can be matched on its own.
2. **Embed each piece once:** Store each vector with its contract ID, clause number and page, so every hit can be opened.
3. **Add keyword search for exact terms:** Clause numbers, party names and defined terms are matched by keyword, because embeddings can miss exact codes.
4. **Filter by access first:** Each lawyer only sees contracts they are allowed to read, so the access filter runs before ranking.
5. **Measure with real questions:** A list of questions from the team shows what the search misses. Switch models only after re-running that list.

## What does the interviewer want to hear?

**A strong answer covers**

- [ ] A plain definition: a list of numbers that stands for meaning.
- [ ] How closeness is measured: distance or cosine similarity, and what a high score means.
- [ ] Where the numbers come from: a trained model that learns from data.
- [ ] The limits: exact codes, model changes and data quality.
- [ ] Hybrid search: embeddings plus keywords, with access rules applied first.
- [ ] A test plan with real questions from the team, not a guess.

**Common traps**

- Trap: "Embeddings are a kind of exact search." Better: They match meaning. Keep keyword search for codes and names.
- Trap: "A bigger embedding always gives better search." Better: Quality depends on the model, the text and your test questions. Measure before you pay for size.
- Trap: "Vectors from two models can be compared." Better: Each model draws its own map. Switch models and run the whole collection through the new one again (re-embed it).

## Can you pick the right search setup?

**Spot the setup:** Claims staff must find claim CL-88213 exactly, and also find similar water claims. Which setup fits?

A. Embedding search only, for every query, including claim numbers
B. Keyword search only, so a burst pipe note never matches a ceiling leak
C. Keyword search for the exact claim number, embedding search for similar claims, results merged
D. A bigger embedding model, with the same single search for every query

**Answer:** C. Exact codes like CL-88213 need keyword matching, and similar meaning needs embeddings. Running both and merging the results covers each weakness. A bigger model does not fix a search that cannot match codes.

**Quick check:** The team switches to a newer embedding model. What must happen to the stored vectors?

A. Nothing, the new model can read the old vectors
B. Re-embed every stored item with the new model
C. Add the new model's vectors next to the old ones
D. Shorten every chunk before the search runs

**Answer:** B. Each model draws its own map, so old and new vectors cannot be compared. Re-embed the whole collection with the new model, then switch the search over.

## Can you answer these from memory?

**Flash cards**

- **What is an embedding?** A list of numbers that stands for the meaning of a piece of data.
- **What does a small distance mean?** High relatedness: the two items are close in meaning.
- **Where do embedding numbers come from?** A trained model, or a method like PCA that works from the data.
- **Can embeddings find exact codes well?** Not well. Pair them with keyword search for codes and names.
- **What is a vector database?** A store that finds the saved lists nearest to a new one.
- **What if you change the model?** Re-embed everything. Old and new vectors are not on the same map.

## Likely follow-up questions

- Q007 Word embeddings vs sentence embeddings? https://designervenkat.online/interview/ai/word-embeddings-vs-sentence-embeddings
- Q113 What is chunking, and why does size matter? https://designervenkat.online/interview/ai/what-is-chunking-in-rag
- Q116 How do you choose an embedding model? https://designervenkat.online/interview/ai/how-do-you-choose-an-embedding-model
- Q117 What is a vector database? https://designervenkat.online/interview/ai/what-is-a-vector-database
- Q123 What is hybrid search (BM25 + vectors)? https://designervenkat.online/interview/ai/what-is-hybrid-search
- Q147 When must you re-embed everything? (full answer coming)

## Learn it in depth

- [Embeddings](https://designervenkat.online/learn/machine-learning/embeddings)
- [Embeddings for builders](https://designervenkat.online/learn/ai-engineering/embeddings)
- [Choosing an embedding model](https://designervenkat.online/learn/ai-engineering/embedding-models)
