# Embedding

URL: https://softwaredictionary.org/terms/embedding
Category: AI & Machine Learning
Last updated: 2026-09-29

In short: An embedding is a list of numbers, called a vector, that represents the meaning of text, images, or other data so that similar items end up close together.

## What is an embedding?

An embedding turns something a computer can't easily compare, such as a sentence or a photo, into a fixed-length list of numbers called a vector. An embedding model is trained so that items with similar meaning get similar vectors. For example, 'How do I reset my password?' and 'I forgot my login' produce vectors that are close together, even though they share almost no words.

You can picture embeddings as points on a map, except the map has hundreds or thousands of dimensions instead of two. To measure how related two items are, you compare their vectors, most often with cosine similarity, which looks at the angle between them. A score close to 1 means very similar meaning, while a score near 0 means the items are unrelated.

Embeddings power semantic search, recommendations, duplicate detection, clustering, and RAG systems. They are typically stored in a vector database, or in a regular database with a vector index, which can quickly find the stored vectors nearest to a query vector.

Semantic search with embeddings is different from keyword search. Keyword search matches exact words, while embedding search matches meaning, so it can find relevant results even when they use different wording. Many systems combine both approaches, which is called hybrid search.

## Key takeaways

- An embedding is a vector of numbers that captures meaning.
- Items with similar meaning have vectors that are close together.
- Cosine similarity is a common way to compare two embeddings.
- Embeddings enable semantic search, recommendations, and RAG.
- Only compare embeddings produced by the same model.

## Example: Comparing embeddings with cosine similarity

```python
import math

def cosine_similarity(a, b):
    # 1.0 = same direction (similar meaning), near 0 = unrelated
    dot = sum(x * y for x, y in zip(a, b))
    return dot / (math.hypot(*a) * math.hypot(*b))

# Tiny made-up embeddings (real ones have hundreds of dimensions)
cat = [0.9, 0.1, 0.3]
kitten = [0.85, 0.15, 0.35]
car = [0.1, 0.9, 0.2]

print(cosine_similarity(cat, kitten))  # about 0.996 (very similar)
print(cosine_similarity(cat, car))     # about 0.27 (not similar)
```

## Frequently asked questions

**What is a vector database?**

A vector database stores embeddings and can quickly find the vectors closest to a query vector, which is called similarity or nearest-neighbor search. It is a core building block of semantic search and RAG applications.

**What is the difference between an embedding and a token?**

A token is a chunk of text that a language model reads, while an embedding is a vector of numbers that represents meaning. Inside an LLM each token is converted into an embedding, and dedicated embedding models produce a single vector for a whole sentence or document.

**How many dimensions does an embedding have?**

It depends on the model; common sizes range from a few hundred to a few thousand numbers. More dimensions can capture more nuance but need more storage and computing power.

## Sources

- [Mikolov et al.: Efficient Estimation of Word Representations in Vector Space (2013)](https://arxiv.org/abs/1301.3781)

---

Software Dictionary: https://softwaredictionary.org/ · https://softwaredictionary.org/llms.txt
