Embeddings turn items into comparable vectors.
Embeddings: related things sit nearby.
An embedding model turns an item into learned coordinates. Put many items in the same space, and useful relationships become distances and directions a machine can compare.An embedding gives each word, picture, or product a place on a numerical map. Things used in similar ways tend to land near one another.
compressed prosea readable summarya database IDan exact labela human-readable taxonomya truth detector
A coordinate is useful because of its neighborhood.The useful part is what each item lands near.
No single number means “train” or “romantic.” The representation was learned across many dimensions, and individual axes are usually not clean human concepts. Meaning emerges from relative geometry.You cannot read the numbers like a label. Their value comes from where an item sits compared with everything else on the same map.
- 01
Give the model an item
Text, an image, a product, or another input type the chosen embedding model was trained to accept.Start with a word, picture, product, or another item the mapping model understands.
night train through Europe - 02
Receive a vector
A fixed-length list of numbers: one location in that model’s learned, many-dimensional space.The model returns a numerical location on its hidden map.
[0.12, −0.44, 0.08, …] - 03
Compare locations
A distance or similarity function ranks which other vectors are nearby. The ranking is the useful part.The system checks which other locations are close. Those neighbors are the useful result.
rail pass · sleeper car · Eurail
Compare nearest neighbors for different queries.
Switch the query. The closest items change because similarity is relative to the query’s coordinate. Then try the ambiguous query and see how an ambiguous query mixes two meanings in one result set.
- library study roomquiet + work0.92
- calm coworking spacework + Wi-Fi0.88
- laptop-friendly caféwork + Wi-Fi0.84
Important: this is a hand-authored 2D teaching map. Real embeddings usually have hundreds or thousands of learned dimensions, and a projection can distort which points look close.
The similarity function changes the ranking.
The embedding model makes the map. A similarity function decides how to measure it. These choices can rank the same candidates differently.
Cosine
Do the arrows point the same way?Compares angle and ignores overall length. Common for semantic similarity, especially with normalized vectors.
Dot product
Same direction—and how long are the arrows?Includes vector magnitude. That can be useful, but large norms may influence ranking.
Euclidean
How far apart are the endpoints?Measures straight-line distance. For normalized vectors, its ranking is closely related to cosine.
Use the metric recommended for your embedding model and index. If you normalize vectors, document where it happens. “We use vectors” is not a complete retrieval design.
Three common uses for embeddings.
Find by meaning, not only keywords
“refund after trial” can find a document titled “subscription cancellation policy.”
Cluster an unlabeled pile
Group support tickets into recurring themes before anyone has named the themes.
Generate recommendation candidates
Retrieve items near a user or product vector, then let a ranking system apply business constraints.
Vectors are meaningful only within a compatible embedding space.
A vector has no universal address. Change the model and every item may move—even if the output has the same number of dimensions.
- 01
Embed both sides
Queries and candidates must be represented in a compatible space. For text search, use the same model—or its explicitly paired query/document modes.
- 02
Version the atlas
Store the model name, version, vector dimension, normalization choice, and index metric beside the data.
- 03
Re-index on model change
Coordinates from different embedding models are not safely comparable. A new model means a new coordinate system.
- 04
Evaluate your neighborhood
Measure retrieval on real queries, including confusing negatives. Pretty demos are not recall metrics.
Similarity does not establish truth, safety, or fairness.
An embedding captures patterns useful for the task it learned. It does not certify relevance, correctness, fairness, or safety.
Near is not true
Similarity can surface plausible material that is outdated, factually wrong, or opposed to the query. Retrieval still needs filters, provenance, and verification.
Tiny words can flip intent
Negation, quantities, exact codes, and dates may matter more than their geometric footprint suggests. Hybrid lexical + vector search is often stronger than either alone.
Ambiguity makes split neighborhoods
“Jaguar maintenance” may mean a car or a cat. Add context, classify intent, or retrieve diverse candidates instead of trusting one nearest point.
The map inherits its training
Learned spaces can encode social and cultural biases. Test downstream rankings across groups and domains; do not treat distance as neutral ground truth.
IMPORTANT DISTINCTIONA semantic score is not a confidence score. It says “near in this space,” not “safe to ship.”
Index candidates once, then embed each query in the same space.
A minimal semantic-search path has two phases: index candidates ahead of time, then embed each incoming query into the compatible space.
const contract = {
model: "your-embedding-model@version",
dimensions: EXPECTED_DIMENSIONS,
metric: "cosine",
};
// Offline: map every chunk into this coordinate system.
const documentVectors = await embed(chunks, contract.model);
await index.upsert(documentVectors.map((vector, i) => ({
id: chunks[i].id,
vector,
text: chunks[i].text,
contract,
})));
// Online: put the query in the same space, then look nearby.
const [queryVector] = await embed([query], contract.model);
const candidates = await index.nearest(queryVector, {
metric: contract.metric,
topK: 8,
});MODEL CONTRACTstored
QUERY + DOCUMENT SPACEcompatible
RESULTcandidates, not truth
- Same space before similarity.
- Metric choice changes ranking.
- Exact facts still deserve exact filters.
- Evaluate neighbors on your own data.