zackproser.com · Blueprint Deep Dive002
Semantic geometry · Complete working drawing

The Embedding Space

Applied AI runs on a map where meaning has direction, distance, and neighborhoods. Here is how that map is built and searched.

PROJECT
DEEP DIVES
DRAWING Nº
TDD-002
SUBJECT
EMBEDDINGS
SCALE
1 : 1
DRAWN BY
Z. PROSER
READ TIME
15 MIN
DISTRIBUTION · REVISIONS ISSUED BY EMAILGet the next complete drawing.

Every useful AI system eventually runs into the same question: which things are related? Search needs passages related to a query. A recommender needs products related to a person. A classifier needs examples related to a label. Raw strings can't answer any of that. All a string comparison tells you is whether two sequences of characters happen to match.

Embeddings supply the coordinate system that's missing. An embedding model turns an object into a fixed-length vector and places related objects near each other in a learned space. Once meaning has coordinates, retrieval turns into geometry: compare angles, find neighbors, draw boundaries, cluster points. A surprising amount of applied AI rides on that one abstraction.

This drawing follows the whole load path — text into vectors, training into geometry, cosine into rankings, approximate search into production. It also marks where things break: bad chunks, domain mismatch, stale indexes, model migrations, and the false confidence a tidy similarity score gives you.

§ 01 · SHEET 1 OF 8

Strings match characters, not intent

A lexical search engine is excellent whenever the query already contains the language of the answer. Search for connection timeout and a document with those exact terms should rank well. The trouble starts when the writer and the reader picked different words. The checkout is slow and payment latency increased can describe the same incident without sharing a single useful token.

Exact matching still matters. Product codes, error IDs, names, and quoted phrases often carry more signal as tokens than as semantic vectors.

Synonym tables patch the obvious gaps and then collapse under real language. Bank changes meaning next to river or loan. Jaguar is an animal, a car, or a software release. Intent crosses formats and languages too — a support ticket, a stack trace, and a runbook can all point at one failure while looking nothing alike as strings.

The idea underneath predates neural networks by decades. Zellig Harris argued in 1954 that differences in meaning correspond to differences in linguistic environments[1]. J. R. Firth compressed the same intuition into the line everyone remembers: "You shall know a word by the company it keeps." This distributional hypothesis turns surrounding language into evidence. When physician and doctor keep showing up beside patients, clinics, and treatment, that shared company reveals the relationship without anyone hand-writing a synonym entry.

Harris, "Distributional Structure" (1954), supplied the formal linguistic lineage. Firth's often-quoted formulation appeared in his 1957 essay on linguistic theory.
"checkout is slow""payment latency"ENCODE+ SCORETOKEN OVERLAP: 0SEMANTIC: NEARSAME INCIDENT · DIFFERENT SURFACE FORM
FIG. 1 — LEXICAL MATCHING SEES TOKEN OVERLAP. SEMANTIC MATCHING RECOVERS SHARED INTENT ACROSS DIFFERENT WORDS.

Embeddings go at that mismatch directly. Rather than writing a longer and longer list of linguistic rules, train a model to produce representations where items used in similar ways end up in nearby regions. Search then compares the query vector against document vectors, and whether their characters overlap stops mattering.

That route became practical at scale with word2vec in 2013[2]. Its skip-gram objective learned a word vector by predicting nearby words, and the training procedure was efficient enough to extract useful geometry from enormous text collections[3]. GloVe followed in 2014[4] with an objective built from global co-occurrence counts. Both gave each vocabulary word exactly one vector, which meant bank had to occupy a single location whether the sentence was about money or a river.

Q — Did embeddings begin with modern language models?

No. Researchers have represented words with vectors for decades, and word2vec made the approach widely practical in 2013. Modern transformer encoders add context: the vector for bank can change when the sentence mentions a loan versus a river.

§ 02 · SHEET 2 OF 8

An embedding is a learned address

An embedding is an ordered list of numbers: x ∈ ℝd. The dimension d runs from hundreds to thousands depending on the model. Feed in a sentence, an image, a product, a user history — get back one fixed-width point. None of the coordinates carry hand-written labels. Dimension 417 doesn't mean "medical." Meaning is spread across many directions at once.

A 1,536-dimensional float32 vector occupies 6,144 bytes before index overhead: 1,536 values × 4 bytes. One million raw vectors are about 5.7 GiB.

The encoder is where the interesting work happens. A text embedding model tokenizes the input, runs it through a transformer, pools the token representations into one vector, and usually normalizes it. Both sides of a comparison have to follow the model's documented encoding contract — some retrieval models pair a query encoder with a document encoder that were trained together, and instruction prefixes are part of the contract too. Coordinates from unrelated models live in unrelated spaces, no matter how neatly their vector lengths happen to match.

Contextual language models changed what's being represented. Instead of looking up one permanent vector per word, the encoder produces token representations conditioned on the entire sentence. Sentence-BERT, published in 2019, adapted BERT with siamese and triplet training so a sentence could be encoded once and then compared cheaply against other sentence vectors[5]. That difference is operational as much as theoretical: an ordinary cross-encoded BERT can compare a pair very carefully, and it can't precompute one reusable vector per corpus item for fast nearest-neighbor search.

Pooling decides how a pile of contextual token vectors becomes one object vector. Mean pooling averages the eligible token states; other models use a designated token or a learned pooling layer. A title and body might be encoded together, or separately and combined downstream. Every one of those choices alters the coordinate system, which is why the model name by itself is not sufficient version metadata.

TEXT / IMAGE / ITEMENCODERfθ(·)POOLx ∈ ℝᵈ[ 0.12−0.07 0.31 … ]VARIABLE LENGTHFIXED WIDTH · d COORDINATES
FIG. 2 — THE EMBEDDING PIPELINE: VARIABLE-LENGTH INPUT BECOMES ONE FIXED-WIDTH COORDINATE IN ℝᵈ.

That fixed-width contract is what makes embeddings composable across a stack. A database stores every vector in one column. A search service accepts a query vector and returns IDs. A downstream classifier trains on the same representation. The original objects stay as complicated as they ever were; the interface between systems collapses to an array of numbers.

Q — Why can't I compare vectors from two models if both have 1,536 numbers?

The coordinates learned by each model have different meanings, much like two maps that use different origins and rotations. Coordinate 12 in one model has no agreed relationship to coordinate 12 in the other. Equal length only lets the dot product run; it does not make the score meaningful.

§ 03 · SHEET 3 OF 8

Geometry becomes a language for meaning

Nearby points tend to share whatever properties the training objective rewarded. Animal words form a neighborhood. Vehicle words form another. Directions can encode relationships, which is where the familiar king − man + woman ≈ queen result comes from. Treat that as a useful intuition rather than a universal algebra of concepts, because it isn't one.

Two dimensions make the drawing legible. Production embeddings use far more dimensions, and any 2D projection distorts some distances.

Cosine similarity measures the angle between two nonzero vectors. A score of 1 means the same direction, 0 means perpendicular, −1 means opposite. Normalize the vectors to unit length and cosine similarity becomes the dot product, which makes ranking very cheap.

EQ. 3.1

cos(θ) = x · y‖x‖₂ ‖y‖₂

INTERACTIVE — SELECT A WORD · QUERY = ⟨king
x₁x₂0θ(king, queen) = 12.4°kingqueenmanwomandogpuppycartruck
RANK · COS(θ)
FIG. 3 — COSINE COMPARES DIRECTION FROM THE ORIGIN. COORDINATES ARE A HAND-DRAWN 2D TEACHING EXAMPLE.

Distance doesn't explain itself. A score of 0.82 can be excellent in one corpus and mediocre in another, so any threshold has to be calibrated against labeled pairs from the actual task. For ranking, relative order usually carries more weight than an absolute cutoff does.

Similarity also depends on how hard the candidate set is. Run a query against ten unrelated policy documents and you'll see a comfortable gap between first and second place. Run the same query against ten near-duplicate revisions of one policy and several scores pack into a narrow band. So calibrate on the confusable cases the production system will meet, because that's where a threshold actually has to do work.

Real spaces can be anisotropic — vectors pile into a few preferred directions instead of spreading evenly over the sphere. Some points then become hubs that turn up in many unrelated neighbor lists. Normalization doesn't automatically remove that structure. A quick operational check: count how often each corpus item appears across top-k results for a broad sample of queries. A handful of generic chunks dominating the lists usually means poor content, a mismatched encoder, or hubness.

Q — Does the nearest vector mean the answer is correct?

It means the encoder and metric ranked that item closest among the candidates searched. The item can still be irrelevant, stale, or only topically related. Treat similarity as one ranking signal and validate the returned content against the task.

§ 04 · SHEET 4 OF 8

Training pulls positives together

The geometry comes from examples. A positive pair says these two inputs belong close together: a query and its clicked result, two translations, a caption and its image, two views of one item. Negatives say which inputs should push apart. Training nudges encoder weights so the positives gain similarity relative to the negatives in the batch.

Contrastive training turned that into a reusable recipe. Put related examples together, surround them with plausible alternatives, and ask the encoder to pick out the matching partner. Work on contrastive predictive coding gave us the InfoNCE form below[6]; later systems applied related losses across images, sentences[7], and query-passage pairs at far larger batch and dataset scales. The model ends up learning a comparison space on purpose, instead of anyone hoping a representation trained for some other objective happens to rank well.

QUERY: RESET CACHEDOC: INVALIDATIONPOSITIVENEGATIVENEGATIVENEGATIVEPULLPUSH
FIG. 4 — CONTRASTIVE TRAINING: POSITIVE PAIRS PULL TOGETHER; NEGATIVES SUPPLY THE PRESSURE THAT SHAPES THE REST OF THE SPACE.

A simplified InfoNCE objective treats the matching item as the correct class among everything in the batch. Temperature τ controls how sharply similarity differences get penalized. Larger batches supply more in-batch negatives, and their quality is what matters: trivial negatives teach nothing, while false negatives actively punish genuinely related pairs.

EQ. 4.1

Li = −log exp(sim(qi, pi) / τ)Σj exp(sim(qi, pj) / τ)

Training data is what defines "similar," and different data defines it differently. A general model groups documents by topic. A support-search model learns that an error message and its resolution belong together. Fine-tuning for one retrieval contract can degrade another, so evaluation has to mirror the use you have in mind rather than the one the benchmark had.

Negative selection is usually what decides whether the model learns a boundary worth having. Random passages from unrelated topics become easy after a few hundred steps. Hard negatives are the plausible-but-wrong ones: a different refund policy, a sibling product's manual, a passage an earlier retriever ranked highly. Those force the model to represent the distinction the application actually cares about. They also cost more to label, since something that looks like a negative may contain a second valid answer.

§ 05 · SHEET 5 OF 8

The unit hypersphere removes magnitude

Divide x by ‖x‖₂ and every vector lands on the surface of a unit hypersphere. Magnitude vanishes; only direction survives. That's standard for semantic retrieval, because the encoder's vector length is rarely the signal the application wanted in the first place.

raw x · ‖x‖ > 1x / ‖x‖normalized yORIGINFOR UNIT VECTORS: COSINE SIMILARITY = DOT PRODUCT · EUCLIDEAN DISTANCE GIVES THE SAME ORDERING
FIG. 5 — L2 NORMALIZATION PROJECTS DIFFERENT MAGNITUDES ONTO THE UNIT SPHERE. ANGLE, NOT LENGTH, DETERMINES COSINE RANK.

Dot product, cosine, and Euclidean distance are not interchangeable on arbitrary vectors. Dot product rewards alignment and magnitude together. Cosine ignores magnitude. Euclidean distance measures straight-line separation. Once vectors are unit-normalized, all three produce equivalent nearest-neighbor rankings, because ‖x−y‖² = 2−2(x·y).

The practical rule is mechanical. Use the similarity function the model was trained and documented for, normalize exactly where its contract says to, and record that choice next to the index. A silent metric mismatch will make a perfectly healthy index look semantically broken, and you'll spend a day looking at the wrong thing.

Normalization can also destroy useful signal when magnitude was part of the training contract. Some models train dot-product scores where vector norms help express confidence or popularity. Project those onto the sphere and every score changes. The database setting, the stored vectors, and the query preprocessing have to agree as one operation — worth testing against a few known pairs at deploy time.

§ 06 · SHEET 6 OF 8

Nearest neighbors without scanning everything

Exact search computes the query's similarity against every stored vector. Simple, correct, and the work grows right along with the collection. Approximate nearest-neighbor indexes trade a controlled amount of recall for far fewer comparisons and lower latency.

HNSW — Hierarchical Navigable Small World — builds a graph. Upper layers hold sparse long-range links; lower layers hold dense local ones. A search enters high, makes greedy jumps toward the query, then descends and explores a candidate frontier. The parameters controlling construction quality, graph degree, and search breadth are all trading memory and latency against recall.

Malkov and Yashunin's design joins two ideas that work well together[8]. Navigable small-world graphs give you short paths across a neighborhood graph; the hierarchy gives the search coarse entry points before it starts spending effort locally. On insertion, the index connects a new vector to selected neighbors and prunes connections to keep the degree in check. On search, a wider candidate frontier improves the odds of escaping a locally attractive dead end, and costs more distance calculations to do it.

The graph is approximate because search only ever visits a fraction of the stored points. It can enter the wrong neighborhood, or prune the route that led to an exact top result. Turning search breadth up raises recall and latency together. Turning construction effort up improves graph quality and slows indexing. Pick those knobs off measured recall-versus-latency curves rather than copying a default config from a blog post.

ANN recall should be measured against exact top-k results on a representative query set. Search latency alone cannot reveal neighbors the index missed.

Memory planning goes well beyond the raw vector arithmetic in §02. HNSW stores neighbor links and per-node bookkeeping on top of the vector values and metadata. Replication multiplies all of it, and deleted nodes can keep occupying space until compaction or a rebuild. Float16, scalar quantization, and product quantization all reduce vector memory, and each one adds another accuracy comparison you owe against the original float representation.

Quantization changes how coordinates are stored or approximated. It doesn't change the embedding model's semantic contract. A sensible benchmark keeps encoder quality and index quality apart: evaluate exact search over full-precision vectors first, then compare the compressed or approximate index against that baseline. Skip the baseline and a missed passage leaves you with two suspects and no way to tell them apart.

L2L1L0QUERY NEIGHBORHOOD
FIG. 6 — HNSW INTUITION: LONG JUMPS ON SPARSE UPPER LAYERS, LOCAL REFINEMENT ON THE DENSE BASE GRAPH.
INTERACTIVE — ANN SEARCH · 16 CANDIDATES PROBED
TRUE #1
FOUND
TRUE #2
FOUND
TRUE #3
FOUND
TRUE #4
MISSED
TRUE #5
MISSED
RECALL@5 = 60%RELATIVE SEARCH COST = 2×
FIG. 7 — MORE SEARCH WORK RAISES RECALL AND COST. LATENCY UNITS AND RESULTS ARE ILLUSTRATIVE, NOT A BENCHMARK.

The database still needs filters, deletes, replication, and persistence. Metadata filtering happens before or during graph traversal depending on the engine, and a highly selective filter can starve the search of candidates entirely. Production vector search is a retrieval system with operational constraints, not a floating-point party trick.

Q — Why use approximate search if exact search is correct?

Exact search is often the right baseline and can remain fast for modest collections or optimized batches. At tens of millions of vectors, comparing every point for every request can consume too much time and compute. ANN spends a small, measured amount of recall to avoid most comparisons.

§ 07 · SHEET 7 OF 8

The space inherits every upstream mistake

Chunking decides what a single point represents, and it decides a lot. Embed a whole manual and the one useful paragraph gets averaged into everything around it. Embed isolated sentences and the pronouns, headings, and definitions lose the context that made them meaningful. Overlap protects boundary facts at the cost of index size and duplicate results. The right unit is usually the smallest chunk that can answer a likely question on its own.

You can play with those tradeoffs in the interactive embeddings demo, then test them against your own corpus. Toy clusters teach the geometry; real evaluation is the only thing that tells you whether your retrieval unit carries enough evidence.

CHUNKING[too small][or onegiant document]DOMAIN SHIFTLEGAL → MEDICALCROWDINGDISTANCES CONVERGEVERSION DRIFTINDEX: MODEL AQUERY: MODEL BMEASURE ON REAL QUERIES
FIG. 8 — FOUR COMMON FAILURE LINES: BAD RETRIEVAL UNITS, DOMAIN SHIFT, HIGH-DIMENSION CROWDING, AND INCOMPATIBLE MODEL VERSIONS.

High dimension behaves in ways intuition doesn't prepare you for. Data is sparse, volume concentrates far from the center, and distance distributions bunch up. That whole family of effects usually travels under the name curse of dimensionality. Learned embeddings stay useful anyway, because their data occupies structured manifolds rather than filling the space uniformly — and index tuning and evaluation still matter.

Never mix model versions in one search space. Re-embed the corpus into a new index, evaluate it, then switch query traffic atomically or by an explicit migration plan.

Embedding drift bites faster than any of that. Change the model, the pooling method, the normalization, the instruction prefix, or the preprocessing, and the coordinate system changes underneath you. Old document vectors compared against new query vectors produce scores that mean nothing at all. Store model ID, dimensions, metric, preprocessing version, and index build ID together as one deployable contract.

Domain shift can break a model you never touched. A general encoder can treat two oncology terms as close because both live in medical text, while the clinical search task needs their difference to dominate everything else. New acronyms, catalog codes, and organization-specific meanings may be entirely absent from training. A labeled slice of production queries is the only reliable way to find out whether the inherited geometry matches your local sense of relevance.

Inputs fail before semantics even enters the picture, more often than people expect. Truncation silently removes the paragraph with the answer in it. Boilerplate navigation dominates a short page. Unicode normalization, OCR errors, and markup stripping leave the query and the corpus looking at different text. Store the exact embedded text, or a reproducible pointer to it — debugging from the polished source document hides what the encoder actually received.

Migration should build a parallel index from the original source objects. Run the old and new encoders over the same evaluation queries, compare relevance and operational cost, then move traffic with an explicit version switch. Transforming old vectors into the new space is a separate learned alignment problem, and it rarely gives you the clean audit trail that re-embedding does.

§ 08 · SHEET 8 OF 8

One abstraction, many systems

In RAG, query embeddings retrieve passages for a generator. In deduplication, neighbor search finds paraphrases and near-copies. Recommendation embeds users and items into compatible spaces. Classification compares an input against class prototypes, or trains a small head over frozen vectors. Clustering surfaces themes for exploration, with the caveat that naming the clusters is still a human job.

Sharing an abstraction doesn't make those applications the same. Each needs its own positive pairs, relevance judgments, thresholds, latency budget, and failure policy. A recommender optimizes behavior over time. A RAG retriever optimizes evidence for one question. A dedup system may care about precision at exactly one strict threshold and nothing else.

Offline evaluation should preserve those distinctions. For retrieval, label which corpus items answer each query and measure recall at whatever candidate depth the application can afford. For classification, report per-class precision and recall, so one big easy class can't hide a weak rare one. For recommendation, delayed behavior and exposure bias both matter, because users can only click the items the previous system chose to show them. A single cosine histogram substitutes for none of that.

Latency belongs in the same report as quality. A model that improves relevance and doubles vector width raises embedding time, network payload, index memory, and distance-computation cost all at once. A graph setting that buys one recall point can miss the service budget at peak concurrency. Compare quality and cost on the same query distribution, and keep the old index around until the new contract has proven itself stable.

Recommendation is also where "nearby" stops having any universal meaning. A user vector and an item vector can be trained into compatible spaces while representing completely different kinds of object. A classification prototype might be written as a label description. A clustering pipeline has no labels at all while it's grouping. The geometry earns its interpretation from the training and evaluation contract wrapped around it, and from nothing else.

Deduplication shows the threshold economics clearly. A false positive merges two records that only shared boilerplate. A false negative leaves you redundant storage or repeated search results. Most systems run a high-similarity candidate stage followed by a second check over text, metadata, or a pairwise model. The vector narrows the comparison set; the application decides what counts as the same object.

The enduring design is simple enough to state in a sentence: turn complicated objects into coordinates, define the neighborhood your task needs, and measure whether the geometry serves it. The vector is the interface. The training data, the index, and the evaluation are what make it useful.

APPENDIX A — RFI DESK · REQUEST FOR INFORMATIONTDD-002-A

Anything on this sheet still unclear — or anything you were too polite to ask out loud? File an RFI. Answers come from the drawing itself and cite their sheet numbers, and every question is recorded in the drawing log so the next revision can answer it in print.

IN PRODUCTION · TDD-004 · THE TOKENIZERTDD-002-D
GET THE NEXT DRAWING

One complete technical schematic, issued by email when it is ready. Free; one-click unsubscribe.

END OF DRAWING · TDD-002 · REV A · JUL 2026
✓ CHECKED — YOU ARE NOW AN EXPERT