Which representation defines the neighborhood?
Hypothetical scenario. Northwind returns from the capstone to a recurring retrieval error: account closure and temporary suspension rank as if they were the same procedure. Maya needs the right evidence, Dev proposes adapting the encoder and Priya asks how the new query vectors would relate to the existing index.
Maya: “The words overlap, but the employee is asking for a different procedure.”
Dev: “Reviewed query-passage examples could teach a more useful matching relationship.”
Priya: “Check the failure first, then plan both evaluation and representation migration.”
This optional depth chapter builds on embeddings, candidate retrieval and case-level evaluation. You will examine relevance labels, contrastive learning and hard negatives, then account for index migration without treating matching dimensions as proof of compatible vector spaces.
First inspect where the failure occurs. If the correct passage never entered the corpus, encoder training cannot retrieve it. If authorization excludes it, changing similarity must not bypass that exclusion. If the query is ambiguous, a clarification step may be preferable to forcing one interpretation. Adapt the representation only when evidence indicates that the similarity function is part of the recurring problem.
Similarity is learned for a relationship, not for every use
A model trained for sentence similarity need not be ideal for query-to-passage evidence retrieval. A query is often short and asks for information absent from its own words; the answer-bearing passage can be longer and differently phrased. Define the relationship that makes a passage useful, including source validity, scope and the question's required detail.
Training pairs express that relationship imperfectly. A positive should be relevant to the actual query rather than merely drawn from the same document. A negative should be an unsuitable alternative under the same task. Treat unlabeled passages cautiously: a collection can contain several valid answers, and sampling another passage does not prove that it is irrelevant.
The Sentence Transformers training overview explicitly distinguishes tasks with different notions of similarity and describes model, data, loss and evaluation components. Its framework is useful here because it prevents the dataset and objective from disappearing behind the phrase “fine-tune the embeddings.”
Migrate embedding space with paired relevance evidence
Hypothetical scenario. A new encoder is trained with relevance pairs and hard negatives. Keep source-level splits so near-duplicate passages from one document do not leak into both training and evaluation. A hard negative is useful only when the label really says it is not the required evidence.
| Artifact | Concrete evidence | Decision boundary |
|---|---|---|
| Training pair | source group, relevance label, provenance | Learning evidence |
| Space identity | encoder/normalization/metric | Compatible query/index |
| Candidate index | source watermark and ACL coverage | Safe migration |
Build a separate compatible index for the candidate encoder and apply coherent source updates and removals. Compare exact relevance and approximate search effects separately. A higher training objective or one successful query cannot establish tenant-filtered retrieval quality. During cutover, queries must use the encoder matching the selected index; rollback also needs current source and permission evidence.
A contrastive objective compares a positive with alternatives
A selected contrastive setup scores a query against one designated positive and several candidate negatives. A softmax turns the scores into relative probabilities; training rewards the designated positive. The temperature controls how score differences enter that comparison. These probabilities describe the selected candidate set, not a calibrated probability that a passage is factually correct.
Hypothetical scenario. Choose scaled scores of 2, 1 and 0 for one positive and two negatives. Their exponentials are approximately 7.3891, 2.7183 and 1. Their sum is 11.1074. The positive probability is 7.3891 / 11.1074 ≈ 0.6652, giving negative log loss −ln(0.6652) ≈ 0.4076.
If the candidate designated as a negative actually supports the query, the objective is asking the encoder to push apart useful evidence. A lower loss can then improve agreement with a mistaken label rather than improve retrieval. Inspect difficult examples and allow multiple relevant passages where the task requires them. Temperature or batch size is not the first correction for false-negative supervision.
Hard negatives are useful only when their labels hold
An easy negative with unrelated vocabulary may teach little about the confusion Northwind actually faces. A hard negative can share wording while describing the wrong procedure, product or policy version. Mine such candidates from a current retrieval system, then verify why they are unsuitable. Preserve that explanation as part of the data review.
In-batch negatives reuse other examples' positives as comparison candidates. This can be efficient, but it assumes those passages are not also valid answers for the current query. Duplicate questions, overlapping policies and broad passages can violate that assumption. Group related examples or choose a loss and sampling scheme that addresses the known relationship.
Do not train the encoder to represent authorization as semantic irrelevance. A passage can be highly relevant yet unavailable to the current caller. Apply enforceable access controls at retrieval and evidence-use boundaries. Otherwise a later model update or query phrasing can turn a supposedly learned restriction into an unauthorized retrieval.
Equal dimensions do not imply a shared coordinate system
A query encoder and document encoder must produce representations compatible under the selected score. Some models deliberately use different query and document processing while learning a compatible relationship. That is a model design, not permission to mix arbitrary encoder versions. Tokenization, pooling, normalization and input prefixes can also affect the vectors.
Consider a toy two-dimensional space. An old relevant document is represented as (1, 0), with old query (1, 0). Their dot product is 1. Suppose a coordinated new representation rotates both to (0, 1); the new query and new document still score 1. But the new query against the old document scores 0. The dimensions stayed equal while the mixed-version score lost its intended meaning.
Version the full representation pipeline and index. Build new document vectors when required, verify corpus coverage and keep the old pair available for rollback. A query encoder deployment without its corresponding document representation can create a retrieval incident even if each model artifact loads successfully.
Measure ranking on answerable queries with a clear denominator
Select a held-out set whose relevant passages were reviewed independently of training. For a chosen top-k depth, recall measures how much designated relevant evidence was retrieved. If each query has one designated relevant passage, an illustrative hit fraction counts queries where that passage appears among the first k results. With several relevant passages, define whether the metric counts passages, queries or complete evidence sets.
In a hypothetical set of 40 answerable queries, choose 28 top-five hits for the baseline and 32 for the adapted system. The hit fractions are 28 / 40 = 70% and 32 / 40 = 80%, a difference of 10 percentage points. These are selected example results, not a measured improvement. The paired query outcomes matter: report which queries improved, regressed or remained unchanged.
Suppose the adapted system gains six previously missed queries but loses two previous hits. The arithmetic is 28 + 6 − 2 = 32. Review the two regressions rather than assuming the larger total makes them harmless. Include difficult near-neighbor procedures, changed policy versions and no-answer cases where the application should abstain.
A representation change has a migration budget
Choose a hypothetical corpus of 100,000 passages, dimension 768 and four bytes per stored coordinate. Raw coordinate payload is 100,000 × 768 × 4 = 307,200,000 bytes. Dividing by 1,048,576 gives approximately 292.97 MiB. Holding two raw coordinate versions requires about 585.94 MiB before index structures, metadata, replicas or temporary build space.
This calculation is not an estimate of total production memory. It identifies one explicit payload that a migration must accommodate. Encoding time, accelerator use, ingestion throughput and index construction need separate measurements. A smaller coordinate type can change payload size while affecting scoring and requiring its own comparison.
In the wild: the training system makes loss choice explicit
Sentence Transformers separates dataset construction, loss functions and evaluators rather than treating every embedding problem as identical. Its documentation is a primary implementation reference for checking which input relationships a chosen loss expects. The transferable lesson is to align representation learning with the intended retrieval relationship.
Hypothetical scenario. Northwind improves offline pair similarity but deploys only the new query encoder. The old passage index remains active, and relevant procedures disappear from the top results. Roll back the mismatched pair, then evaluate a complete new representation and index before another traffic change.
Choose the intervention at the failing stage
Embedding adaptation helps when repeated semantic distinctions are poorly represented and reviewed task data exists. A reranker may help when the correct evidence already appears among candidates but is ordered poorly. Parsing repair is necessary when the meaningful evidence was lost before indexing. Clarifying the query can be the right intervention when the requested procedure remains ambiguous.
These interventions can coexist, but change them separately when diagnosing cause. Simultaneously replacing the parser, encoder and reranker makes an aggregate improvement hard to attribute and rollback difficult. Keep acceptance records for the complete pipeline even when individual stages have their own diagnostic metrics.
Keep representation tuning out of the final test
Repeatedly choosing negatives, pooling or temperature because they improve the same evaluation set turns that set into development evidence. Maintain a final comparison whose cases were not used to choose the representation. Group related query variants and source passages so paraphrases of training evidence do not create an artificially easy retrieval task.
Inspect failures against the original question and source rather than relying only on a relevance identifier. A policy revision can make an old relevance label obsolete even when the passage text and vector remain unchanged. Version those labels with the corpus and preserve the reason for each changed judgment.
Inspect operational thresholds after changing the representation. A score cutoff calibrated for the old encoder may no longer describe the same retrieval behavior. Evaluate abstention and candidate depth again instead of carrying a convenient old threshold into the new index without evidence.
Test the training pair boundary
The new vectors fit the old index dimension. Can readers switch just the query encoder?
Reveal the design reasoning
No. Dimension equality is insufficient. Build and evaluate a compatible index, then switch the query/index pair with permission and source coverage intact.
Decision: Treat adaptation and index migration as one versioned release obligation.
Reason about labels and coordinates
The strongest negative also answers the question. Should training make its score lower?
No. Verify the relevance policy and treat it as another valid positive or exclude the ambiguous comparison. Optimizing the mistaken negative teaches the encoder to reject useful evidence, even if training loss improves.
A new encoder still outputs 768 dimensions. Can it reuse every old document vector?
Not from dimensions alone. The coordinate relationship, normalization and preprocessing may have changed. Evaluate a compatible query/document pair and build a versioned index when needed. The rotation example shows why equal shapes can still yield incompatible scores.
The top-five hit count rises from 28 to 32 of 40. Have all queries improved?
No. Six gains and two regressions give the same total. Inspect paired outcomes and important failure categories before release. The average does not identify which procedures became harder to retrieve.
Northwind decision log
- Train relevance relationships using verified positives and defensible negatives.
- Evaluate query and document representations together with the complete retrieval pipeline.
- Migrate versioned indexes with explicit payload, rollback and regression checks.
Go deeper: learned neighborhoods
- Video lecture: Building makemore Part 2: MLP, Andrej Karpathy. Understand learned vector representations before applying them to a retrieval task.
- Book chapter: Probabilistic Machine Learning: An Introduction, chapter 15: Neural Networks for Sequences, Kevin P. Murphy. Connect contextual representation learning with model structure.
- Book chapter: Probabilistic Machine Learning: An Introduction, chapter 16: Exemplar-based Methods, Kevin P. Murphy. Examine nearest neighbors and learned distance metrics.
- Primary document: Sentence Transformers Training Overview, Sentence Transformers contributors. Match task data, loss and evaluator choices.
Embedding adaptation changes which passages become neighbors; it does not establish relationships between their claims. Page 47 explores graph evidence when the question needs connections across sources. Revisit source identity, retrieval scope and versioned evidence before choosing that representation.