Vectors as Representations
A vector is useful only through the contract that produced its coordinates and the downstream behavior those coordinates preserve.
- Authorship
- InterviewsVector
- Published / updated
- 2026-08-14 / 2026-08-14
- Review status
- Artifact tests passing · primary sources recorded
Original InterviewsVector material. Code examples are covered by repository tests and primary references are recorded. No named human reviewer is claimed.
The decision in one pass
A vector is an ordered coordinate representation, not the thing being represented. Its dimension, basis, scale, model revision, preprocessing, and intended comparisons define what operations mean. A coordinated change of basis can preserve downstream behavior even while every coordinate changes; an uncoordinated transform, truncation, or quantization can keep the same type while destroying the information a consumer needs. Migrate representations by testing declared invariants on stable item identities, not by comparing coordinate columns by eye.
Why this matters
Representation migrations are deceptively compatible. Two services may exchange finite arrays with the same dimension while using different model revisions or coordinate conventions. Conversely, a safe basis rotation can make raw coordinates look completely different. Without behavioral invariants, teams either approve a breaking change or block a valid one for the wrong reason.
You will be able to
- Distinguish an object, its vector representation, and the coordinate system used to encode it.
- Derive how downstream linear probes and distances behave under coordinate transforms.
- Identify when projection, truncation, normalization, or quantization discards task-relevant information.
- Build a representation migration audit with stable identities, finite-number checks, and explicit drift tolerances.
- Version representation semantics across producers, stores, indexes, and downstream consumers.
Prerequisite contract
- — Algebra and coordinate pairs
- Data Contracts for Models →
Your Vector Loop for this lab
- 01
Model
Name the represented objects, coordinate contract, and downstream questions.
- 02
Derive
Relate basis changes, transformed probes, geometric invariants, and information loss.
- 03
Build
Capture stable item identities and audit a declared linear representation migration.
- 04
Stress
Reuse stale probes, collapse dimensions, corrupt values, and swap representation IDs.
- 05
Operate
Version producers and consumers, shadow migrations, and monitor behavior by slice.
- 06
Defend
Explain which properties must remain invariant and which changes are intentional.
Model the vector as a contract
An entity such as a support request, image, token, or user is not a vector. An encoder maps that entity and its context into coordinates. Those coordinates become meaningful only when paired with a representation ID that fixes the encoder revision, preprocessing, pooling, dimension order, scale, and intended uses. The same entity can have several valid representations for different decisions.
| Contract field | Question it answers | Silent failure |
|---|---|---|
| item identity | which real object is this? | rows are compared after reorder |
| representation ID | which encoder and semantics produced it? | equal dimensions are treated as compatibility |
| dimension and axes | how are coordinates shaped and interpreted? | a pooled vector is mistaken for token states |
| scale or normalization | what should magnitude influence? | norm becomes accidental rank signal |
| invariants | which downstream behavior must survive? | coordinate similarity substitutes for product evidence |
Derive what a coordinate change must preserve
x′ = A x
A linear coordinate transform maps a source vector x into target coordinates x′. Its row count is the target dimension and its column count must equal the source dimension.
w′ = A⁻ᵀw ⇒ w′ᵀx′ = wᵀx
For an invertible change, a downstream linear probe must transform contragrediently. Reusing source weights against target coordinates changes the score even if both vectors have the same length. For an orthogonal A, A⁻ᵀ = A.
‖Ax − Ay‖₂ = ‖x − y‖₂ only when A preserves Euclidean geometry
Orthogonal rotations and reflections preserve L2 distance. General scaling, shearing, projection, or truncation does not. Decide whether distance is an invariant before treating drift as an error.
When a transform maps a higher-dimensional space into fewer coordinates, distinct source vectors can collide. That is information loss, but not automatically a defect: a projection may deliberately discard nuisance variation. The engineering obligation is to show that the lost distinctions are irrelevant to named downstream decisions on representative slices.
Move the basis and watch behavior
Vector basis explorer
Compare full-rank and rank-one transforms, move an input and collision twin, then use rank, determinant, and output separation to judge recoverability and information loss.
See when a transform forgets
Change the input and compare it with a deliberately different twin. A full-rank map changes coordinates without losing a degree of freedom; a rank-one map makes the two inputs indistinguishable.
The twin is always (2 + 1, 1 − 1). Its coordinate sum matches the original, exposing the erased direction in the rank-one map.
- Rank / determinant
- 2 / 1
- Input output
- (2.50, 1)
- Twin output
- (3, 0)
The outputs stay 1.12 units apart. The transform can be inverted even though angles and lengths may change.
Make a prediction, then check it against the current evidence.
Build a representation invariance audit
The reference artifact snapshots item IDs, vectors, transform rows, and source/target probe weights into immutable tuples. It rejects duplicate identities, empty or ragged shapes, booleans disguised as numbers, NaN, infinity, source-ID mismatches, and missing probes. The report compares declared linear scores, pairwise distances, and source-distinct items that collapse in the target representation.
1if __name__ == "__main__":2 report = audit_invariance(3 EXAMPLE_REPRESENTATIONS, EXAMPLE_ROTATION, EXAMPLE_PROBES4 )5 print(6 f"representation={report.source_representation_id}"7 f"->{report.target_representation_id}"8 )9 print(f"dimensions={report.source_dimension}->{report.target_dimension}")10 print(f"max_score_drift={report.max_score_drift:.6f}")11 print(f"max_distance_drift={report.max_distance_drift:.6f}")12 print(f"collisions={len(report.collisions)}")Expected output
representation=support-intent-v3->support-intent-v4
dimensions=2->2
max_score_drift=0.000000
max_distance_drift=0.000000
collisions=0Verify: Run python3 -m unittest discover courses/ai-engineering/reference-impl/vector_representation.
- 01Join by stable identityCompare the same canonical items across versions; row position, filenames, or arrival order are not identity contracts.
- 02Declare behavioral probesChoose scores, neighbors, classifications, or task outputs that consumers actually depend on, and migrate each probe explicitly.
- 03Separate intended from unintended driftA dimensional reduction may intentionally alter distance. Record the accepted property and evaluate task utility rather than forcing every numeric invariant to pass.
Stress the assumptions that arrays conceal
- 01Keep the dimension, change the modelReject the payload unless the representation ID matches. An equal-length output from another encoder is syntactically compatible and semantically unrelated.
- 02Rotate coordinates, keep stale weightsRaw vectors remain valid, but a downstream linear probe now asks a different question. The audit should expose score drift by item.
- 03Project away one coordinateSearch for distinct items that become identical and inspect whether the lost distinction matters on rare, safety-critical, or high-cost slices.
- 04Quantize near a decision boundaryAggregate error can look small while small coordinate perturbations flip high-impact decisions. Measure margin-conditioned behavior, not only mean squared drift.
- 05Inject non-finite valuesFail before storage or scoring. NaN can poison comparisons and sorting while still occupying an otherwise valid numeric container.
Operate representation changes as migrations
| Control | Evidence | Rollback unit |
|---|---|---|
| versioned producer | resolved model, preprocessing, pooling, dimension | encoder release |
| canonical comparison set | stable item IDs plus protected slices | evaluation snapshot |
| shadow consumers | old/new score, neighbor, and decision diffs | consumer configuration |
| dual index or store | coverage, freshness, delete, and ACL parity | index alias |
| drift budget | task-specific tolerance and collision review | migration gate |
- Record vector norm and invalid-value distributions by representation version and data slice.
- Keep old and new coordinates out of the same namespace unless every read is version-filtered.
- Shadow representative traffic before cutover and retain the source objects needed to rebuild either version.
- Evaluate retrieval or decision utility after approximate indexing, filtering, and thresholds—not just at the encoder boundary.
- Treat a normalization or truncation change as a representation change even when the base model name is unchanged.
Operate at three altitudes
Production lens
- — Propagate representation identity through storage, cache keys, indexes, traces, and offline datasets.
- — Evaluate both numeric invariants and task-level behavior on stable identities and operational slices.
- — Reject non-finite and mismatched vectors before they enter a shared corpus or online index.
- — Isolate encoder, preprocessing, normalization, index, and consumer changes so each can be shadowed and rolled back.
Staff lens
- — Define representation compatibility as an organization-level contract rather than a convention inside one model team.
- — Require downstream owners to name which geometric or decision properties they depend on before approving compression.
- — Fund canonical rebuild inputs and evaluation identities; without them a representation store becomes irreversible state.
Interview defense
A new embedding model returns vectors with the same dimension as the old model. How would you determine whether an in-place rollout is safe?
I would treat the model and preprocessing revision as a new representation identity despite the equal shape. I would rebuild a shadow corpus from canonical objects, join old and new outputs by stable item ID, validate finite values and norm distributions, and compare declared downstream behavior: exact and approximate neighbors, task recall, thresholds, and protected slices. I would never mix versions in one unfiltered index. After dual writes and shadow reads, I would canary an index alias with separate rollback for encoder, index, and consumer policy.
Expect the interviewer to press on
- — When can every coordinate change without changing behavior?
- — What evidence would justify truncating an embedding?
- — Why can a low average drift still hide a severe regression?
Misconceptions to remove
“A vector's coordinates have stable meaning by themselves.”
Coordinates are defined relative to a representation contract; learned axes can rotate or redistribute information without human-readable labels.
“Equal dimensions make two embedding versions compatible.”
Dimension is only a shape check. Model revision, preprocessing, basis, scale, and downstream behavior must also agree.
“Reducing dimension merely makes a vector less precise.”
Projection can erase entire distinctions and create collisions. Whether that loss is acceptable is a task- and slice-specific claim.
Check your model
1. If x′ = Ax under an invertible change of coordinates, why should a source linear probe w usually not be applied directly to x′?
Because the coordinates changed. To preserve wᵀx, the target probe must be w′ = A⁻ᵀw; reusing w generally computes a different score.
2. Why can an orthogonal rotation produce large coordinate differences while preserving retrieval geometry?
Orthogonal transforms preserve dot products, norms, angles, and pairwise L2 distances. Individual coordinate values change because the basis changed, not because the geometry changed.
3. What does a collision after projection prove?
It proves the transform discarded a distinction between those source vectors. It does not alone prove product harm; the lost distinction must be evaluated against downstream tasks and slices.
Prove the mechanism
Add a non-orthogonal but invertible transform and migrate a linear probe with A⁻ᵀ. Show that probe scores remain stable while pairwise Euclidean distances change, then explain which result should gate a real migration.
Add a production constraint
Extend the artifact with top-k neighbor overlap and a protected-slice report that refuses approval when a small global drift hides a large slice regression.
Artifact: Representation invariance audit
courses/ai-engineering/reference-impl/vector_representation/representation_invariance.py
Download reference implementationPrimary references and next links
References
- 1. Efficient Estimation of Word Representations in Vector Space
Mikolov, Chen, Corrado, and Dean. Primary paper establishing learned continuous vectors as task-tested word representations.
- 2. Matryoshka Representation Learning
Kusupati et al.. Primary paper showing that useful nested dimensionalities can be learned, rather than assumed for arbitrary truncation.
- 3. Python Array API vecdot specification
Consortium for Python Data API Standards. Official cross-library specification for vector dot-product dimensions and numeric behavior.
Continue through the graph
- Similarity Is a Retrieval Policy →
Continue from representation contracts to the ranking policy imposed by vector metrics.
- Data Contracts for Models →
Connect numeric representation identity to schema, meaning, time, lineage, and use.
- Academy roadmap →
Place representation math inside the complete engineering capability spine.
Glossary: vector · coordinate · basis · linear probe · projection · invariant · representation identity