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 has to answer 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 cannot answer any of those questions. They only tell you whether two sequences of characters match.

Embeddings supply the missing coordinate system. An embedding model turns an object into a fixed-length vector, placing related objects near one another in a learned space. Once meaning has coordinates, retrieval becomes geometry: compare angles, find neighbors, draw boundaries, and cluster points. That abstraction carries a surprising amount of applied AI.

This drawing follows the full load path — text into vectors, training into geometry, cosine into rankings, and approximate search into production. It also marks the failure lines: bad chunks, domain mismatch, stale indexes, model migrations, and the false confidence of a tidy similarity score.

§ 01 · SHEET 1 OF 8

Strings match characters, not intent

A lexical search engine is excellent when the query contains the language of the answer. Search for connection timeout and a document containing those exact terms should rank well. The trouble starts when the writer and reader choose different words. The checkout is slow and payment latency increased can describe the same incident while sharing no 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, then collapse under real language. Bank changes meaning beside river or loan. Jaguar may be an animal, a car, or a software release. Intent also crosses languages and formats: a support ticket, stack trace, and runbook can all point to one failure without looking alike as strings.

The underlying idea predates neural networks. Zellig Harris argued in 1954 that differences in meaning correspond to differences in linguistic environments[1]. J. R. Firth compressed the intuition into the line most people remember: "You shall know a word by the company it keeps." This distributional hypothesis turns surrounding language into evidence. If physician and doctor repeatedly appear beside patients, clinics, and treatment, their shared company reveals a relationship without a hand-written 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 attack this mismatch directly. Instead of designing a longer list of linguistic rules, train a model to produce representations where items used in similar ways occupy nearby regions. Search then compares the query vector with document vectors, regardless of whether their characters overlap.

That route became practical at scale with word2vec in 2013[2]. Its skip-gram objective learned a word vector by predicting nearby words; the efficient training procedure produced useful geometry from huge text collections[3]. GloVe followed in 2014[4] with an objective built from global word co-occurrence counts. Both assigned one vector to each vocabulary word, so bank had to occupy one location whether the sentence concerned 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 might be hundreds or thousands, depending on the model. Feed in a sentence, image, product, or user history; receive one fixed-width point. The coordinates have no hand-written labels. Dimension 417 does not mean "medical." Meaning is distributed across many directions.

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 the important part. A text embedding model tokenizes the input, runs it through a transformer, pools token representations into one vector, and often normalizes that vector. Both sides of a comparison must follow the model's documented encoding contract — some retrieval models pair a query encoder with a document encoder trained together, and instruction prefixes are part of that contract. Coordinates from unrelated models live in unrelated spaces, even when their vectors have the same length.

Contextual language models changed the unit being represented. Instead of looking up one permanent vector per word, the encoder produces token representations conditioned on the whole sentence. Sentence-BERT, published in 2019, adapted BERT with siamese and triplet training so a sentence could be encoded once and compared efficiently with other sentence vectors[5]. That distinction matters operationally: ordinary cross-encoded BERT can compare a pair carefully, but it cannot precompute one reusable vector per corpus item for fast nearest-neighbor search.

Pooling decides how many contextual token vectors become one object vector. Mean pooling averages the eligible token states; other models use a designated token or a learned pooling layer. A title plus body may be encoded together, or separately and combined downstream. These choices alter the coordinate system, which is why the model name alone is insufficient 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. A database can store every vector in one column. A search service can accept a query vector and return IDs. A downstream classifier can train on the same representation. The original objects stay complicated; the interface between systems becomes 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 properties the training objective rewarded. Animal words may form a neighborhood. Vehicle words may form another. Directions can encode relationships, which is why vector arithmetic sometimes produces the familiar king − man + woman ≈ queen result. It is a useful intuition, not a universal algebra of concepts.

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, and −1 means opposite directions. When vectors are normalized to unit length, cosine similarity equals their dot product and ranking becomes especially 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 does not explain itself. A score of 0.82 can be excellent in one corpus and mediocre in another. Thresholds must be calibrated against labeled pairs from the actual task. For ranking, relative order often matters more than an absolute cutoff.

Similarity also depends on how hard the candidate set is. A query against ten unrelated policy documents may show a large gap between first and second place. The same query against ten near-duplicate policy revisions can yield several scores packed into a narrow band. Calibration should include the confusable cases the production system will face, because those are where a threshold has to do real work.

Real spaces can be anisotropic: vectors occupy a few preferred directions instead of spreading evenly around the sphere. Some points then become hubs that appear in many unrelated neighbor lists. Normalization does not automatically remove this structure. A quick operational check is to count how often each corpus item appears across top-k results for a broad query sample; a handful of generic chunks dominating the lists often signals 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 should be close: a query and its clicked result, two translations, a caption and its image, or two views of the same item. Negatives say which inputs should separate. Training adjusts encoder weights so positives gain similarity relative to negatives in the batch.

Contrastive training turned this into a reusable recipe. Put related examples together, place many alternatives beside them, and ask the encoder to identify the matching partner. Work on contrastive predictive coding supplied the InfoNCE form used below[6]; later systems applied related losses across images, sentences[7], and query-passage pairs at much larger batch and dataset scales. The resulting model learns a comparison space directly, rather than hoping a representation trained for another 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 the batch. The temperature τ controls how sharply similarity differences are penalized. Larger batches provide more in-batch negatives, though their quality matters: trivial negatives teach little, while false negatives punish genuinely related pairs.

EQ. 4.1

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

Training data defines "similar." A general model may group documents by topic; a support-search model may learn that an error message and its resolution belong together. Fine-tuning can improve one retrieval contract while damaging another. Evaluation has to mirror the intended use.

Negative selection often determines whether the model learns a useful boundary. Random passages from unrelated topics become easy after a few training steps. Hard negatives look plausible but are wrong: a different refund policy, a sibling product manual, or a passage returned highly by an earlier retriever. They force the model to represent the distinction the application cares about. They also raise the cost of labeling, since an apparent negative may contain another valid answer.

§ 05 · SHEET 5 OF 8

The unit hypersphere removes magnitude

Normalize x by dividing it by ‖x‖₂ and every vector lands on the surface of a unit hypersphere. Magnitude disappears; only direction remains. This is common for semantic retrieval because the encoder's vector length is rarely the signal the application wants.

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. Cosine ignores magnitude. Euclidean distance measures straight-line separation. After unit normalization, they induce 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 expects, and record that choice beside the index. A silent metric mismatch can make a healthy index look semantically broken.

Normalization can also erase useful signal when magnitude was part of the training contract. Some models train dot-product scores where vector norms help express confidence or popularity. Projecting those vectors onto the sphere changes every score. The database setting, stored vectors, and query preprocessing must agree as one operation, ideally tested with a few known pairs during deployment.

§ 06 · SHEET 6 OF 8

Nearest neighbors without scanning everything

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

HNSW — Hierarchical Navigable Small World — builds a graph. Upper layers contain sparse long-range links; lower layers contain dense local links. Search enters high, makes greedy jumps toward the query, then descends and explores a candidate frontier. Parameters controlling construction quality, graph degree, and search breadth trade memory and latency for recall.

Malkov and Yashunin's design joins two useful ideas[8]. Navigable small-world graphs provide short paths across a neighborhood graph, while hierarchy gives the search coarse entry points before it spends work locally. During insertion, the index connects a new vector to selected neighbors and prunes connections to control degree. During search, a wider candidate frontier improves the chance of escaping a locally attractive route, at the price of more distance calculations.

The graph is approximate because search visits only a fraction of the stored points. It may enter the wrong neighborhood or prune a route that leads to an exact top result. Increasing search breadth usually raises recall and latency together. Increasing construction effort can improve graph quality but makes indexing slower. Those knobs should be chosen from measured recall-versus-latency curves, not copied from a default configuration.

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 extends beyond the raw vector arithmetic in §02. HNSW stores neighbor links and per-node bookkeeping in addition to vector values and metadata. Replication multiplies that footprint, while deleted nodes may continue occupying space until compaction or rebuild. Float16, scalar quantization, or product quantization can reduce vector memory, but each introduces another accuracy comparison against the original float representation.

Quantization changes the storage or approximation of coordinates; it does not change the embedding model's semantic contract. A sensible benchmark separates encoder quality from index quality: first evaluate exact search over full-precision vectors, then compare the compressed or approximate index against that result. Otherwise a missed passage leaves two suspects and no clean diagnosis.

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 also needs filters, deletes, replication, and persistence. Metadata filtering can happen before or during graph traversal depending on the engine; highly selective filters may starve the search of candidates. 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 one point represents. Embed an entire manual and the useful paragraph gets averaged into everything around it. Embed isolated sentences and pronouns, headings, and definitions lose their context. Overlap protects boundary facts while increasing index size and duplicate results. The right unit is usually the smallest chunk that can answer a likely question on its own.

You can inspect those tradeoffs in the interactive embeddings demo, then test them against your own corpus. Toy clusters teach the geometry; real evaluation reveals whether the 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 brings unintuitive behavior. Data is sparse, volume concentrates far from the center, and distance distributions can bunch together. This family of effects is often called the curse of dimensionality. Modern learned embeddings remain useful because their data occupies structured manifolds rather than filling space uniformly, but 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 is more immediate. Change the model, pooling method, normalization, instruction prefix, or preprocessing and the coordinate system changes. Old document vectors compared with new query vectors produce meaningless scores. Store model ID, dimensions, metric, preprocessing version, and index build ID as one deployable contract.

Domain shift can break an unchanged model too. A general encoder may treat two oncology terms as close because both occur in medical text, while a clinical search task needs their difference to dominate. New acronyms, catalog codes, and organization-specific meanings may be absent from training. A labeled slice of production queries is the only reliable way to see whether the inherited geometry matches local relevance.

Inputs can fail before semantics enter the picture. Truncation may silently remove the paragraph containing the answer. Boilerplate navigation can dominate a short page. Unicode normalization, OCR errors, and markup stripping can make the query and corpus see 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 old and new encoders on the same evaluation queries, compare relevance and operational cost, then move traffic with an explicit version switch. Trying to transform old vectors into the new space is a separate learned alignment problem and rarely offers the clean audit trail of re-embedding.

§ 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 with class prototypes or trains a small head over frozen vectors. Clustering exposes themes for exploration, though cluster labels still need human judgment.

The shared abstraction does not make these applications identical. 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 a question; a dedup system may care about precision at one strict threshold.

Offline evaluation should preserve that distinction. For retrieval, label which corpus items answer each query and measure recall at the candidate depth the application can afford. For classification, use per-class precision and recall so a large easy class does not hide a weak rare class. For recommendation, delayed behavior and exposure bias matter: users can only click items the earlier system showed them. A single cosine histogram cannot stand in for any of these outcomes.

Latency belongs in the same report. A model that improves relevance but doubles vector width raises embedding time, network payload, index memory, and distance-computation cost. A graph setting that wins one recall point may miss the service budget at peak concurrency. Compare quality and cost on the same query distribution, then keep the old index available until the new contract proves stable.

Recommendation also shows why "nearby" has no universal meaning. A user vector and an item vector can be trained in compatible spaces even though they represent different kinds of objects. A classification prototype may be written as a label description, while a clustering pipeline has no labels during grouping. The geometry earns its interpretation from the training and evaluation contract around it.

Deduplication illustrates threshold economics. A false positive can merge two records that only share boilerplate; a false negative leaves redundant storage or repeated search results. Systems commonly use a high-similarity candidate stage followed by a second check over text, metadata, or a pairwise model. The vector narrows the comparison set, while the application defines what counts as the same object.

The enduring design is simple: 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, index, and evaluation 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