AI engineering glossary · RAG vector search
What is embedding?
Embedding: A list of numbers that represents a piece of content such as text or an image so that similar content has nearby lists. Models learn these vectors from data, and search systems compare them to find related items by meaning rather than exact words.
Embedding: an example
The sentences 'cheap flights to Goa' and 'low-cost air tickets to Goa' receive vectors with cosine similarity around 0.9.
Embedding in Python
A short example you can run (Python 3.11, NumPy). The output below is what it really prints.
import numpy as np
# Toy 4-dimensional embeddings (real models give 384 to 3,072 numbers per text)
emb = {
"refund my order": np.array([0.9, 0.1, 0.0, 0.2]),
"money back please": np.array([0.8, 0.2, 0.1, 0.3]),
"how to train a CNN": np.array([0.0, 0.9, 0.8, 0.1]),
}
q = emb["refund my order"]
for text, v in emb.items():
sim = q @ v / (np.linalg.norm(q) * np.linalg.norm(v))
print(f"{text:20s} {sim:.3f}")Output
refund my order 1.000 money back please 0.977 how to train a CNN 0.098
Related terms
More RAG vector search terms
- Embedding cache
- Embedding drift
- Exact nearest neighbour search
- FAISS
- Faithfulness
- Fixed-size chunking
- Flat index
- Full-text search
Where you learn it
Embedding is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.