Vectors and embeddings
Before a database can find "similar" things, those things need to become numbers. This chapter explains what a vector is, how an embedding model turns text or images into vectors, and why that works.
A vector is just a list of numbers
A vector is an ordered list of numbers. [3, 4] is a vector with two numbers — two dimensions. You can draw it as an arrow from the origin to the point (3, 4) on a graph.
Vectors can describe anything you can measure. A house could be [bedrooms, area_in_100_sqft, age_in_years] = [3, 12, 5]. Two houses with similar vectors are similar houses.
Embeddings: vectors that capture meaning
Hand-picking features works for houses, but not for sentences — what would the "features" of "my card got declined" be? This is where embedding models come in. An embedding model is a neural network trained on huge amounts of data so that:
- items with similar meaning get vectors that are close together, and
- items with different meaning end up far apart.
The vector the model produces is called an embedding.
Real embeddings don't have two dimensions — they typically have hundreds or thousands — but the principle is exactly what the picture shows: meaning becomes position.
What do the dimensions mean?
In the house example, each number had a clear meaning. In a learned embedding, individual dimensions usually don't have a human-readable meaning. Meaning is spread across all of them together. You can't point at dimension 417 and say "this is the animal-ness dimension." What matters is the overall position, and therefore distance to other vectors.
Common embedding sizes are in the hundreds to a few thousand dimensions. More dimensions can capture finer detail but cost more storage and compute; we cover this trade-off in Sizing and scaling.
What can be embedded?
| Input | Example embedding models do |
|---|---|
| Text | Sentences, paragraphs, document chunks, queries |
| Images | Photos, screenshots, product images |
| Text + images together | Multimodal models put both in the same space, so text can find images |
| Code | Functions and snippets, for code search |
| Audio | Clips of speech or music |
| Users and items | Learned from behaviour, for recommendations |
Getting embeddings in practice
You send text to an embedding model — via a hosted API or a model you run yourself — and get a vector back:
// Illustrative: the exact client and model name depend on your provider.
const response = await embeddings.create({
model: "your-embedding-model",
input: "My card got declined at the shop",
});
const vector: number[] = response.data[0].embedding; // e.g. [0.012, -0.044, 0.31, ...]
Rules that save you pain later
- Use the same model for storing and querying. Vectors from different models live in different spaces and can't be compared — like measuring one house in feet and another in metres, but worse.
- Record which model (and version) produced each vector. If you change models, you must re-embed everything. See Operations.
- Embed the right unit. A whole 50-page manual squeezed into one vector loses detail; split long content into chunks first. The RAG Handbook covers chunking in depth.
- Respect the model's input limit. Text beyond the maximum length is truncated or rejected.
An embedding model is a translator from "meaning" to "position in space". A vector database is the system that stores those positions and finds neighbours quickly.