Embeddings
An embedding is an array of numbers that stands for the meaning of a piece of data, something like [0.91, 0.15, 0.83, ...]. Representing data as vectors captures the semantic nature of unstructured data (text, images), which keyword matching cannot.
Meaning as distance
An embedding model turns text into a vector so that texts with similar meaning land close together. Searching by meaning then becomes a distance calculation. Cosine similarity is the usual one.
from math import sqrt def cosine(a, b): dot = sum(x * y for x, y in zip(a, b)) return dot / (sqrt(sum(x * x for x in a)) * sqrt(sum(y * y for y in b))) # Toy vectors with three numbers. Real embeddings have hundreds or thousands.refund = [0.91, 0.15, 0.83]money_back = [0.88, 0.20, 0.79]weather = [0.05, 0.93, 0.10] print(cosine(refund, money_back)) # close to 1: similar meaningprint(cosine(refund, weather)) # much lower: unrelatedSimilar meaning scores near 1, unrelated meaning scores lower. The vectors here are made up and tiny, to show the idea only.
Embedding models
| Model | Embeds | How it learns |
|---|---|---|
| Word2Vec | Words | CBOW predicts a word from its context, skip-gram predicts the surrounding words from a word |
| GloVe | Words | Global word-word co-occurrence counts over a corpus |
| CLIP | Images and text | Image-caption pairs, so both land in one shared space |
These are the classic examples. Word2Vec and GloVe give one vector per word, while RAG over documents needs a model that embeds a whole chunk. The query and the chunks must be embedded by the same model, or the distances mean nothing. The vectors are stored and searched in a vector databaseVector databasesStores for embeddings that find the nearest ones fast, by trading a little accuracy for speed.Opens in a new tab.
Sources
- Retrieval, Docs by LangChain · accessed October 5, 2026
- Efficient Estimation of Word Representations in Vector Space, arXiv · accessed October 5, 2026
- GloVe: Global Vectors for Word Representation, Stanford NLP · accessed October 5, 2026
- Learning Transferable Visual Models From Natural Language Supervision, arXiv · accessed October 5, 2026