AN Alpesh Nakrani
BlogBooksPraiseAbout Work with me →
Book overview
Chapter 4 / Technical Deep Dives

Similar Is Not Correct

A healthcare policy assistant returns the closest paragraph, but the correct paragraph is farther away because it uses a newer name for the program. The failure is not that embeddings are useless.

Key Takeaways

  • Similar is not correct. A nearest vector result can be related to the query and still be the wrong source for the product to show.
  • Similarity becomes risky when drafts, old policies, wrong product lines, or tenant-specific records live near approved evidence.
  • Treat vector search as candidate generation, then decide with metadata, source rules, reranking, and retrieval evals.

Read this beside why RAG pipelines fail in month three, Retrieval That Survives Contact, and the Embeddings, Honestly overview when you turn the chapter into a production retrieval review.

Opening Problem

A healthcare policy assistant returns the closest paragraph, but the correct paragraph is farther away because it uses a newer name for the program. The failure is not that embeddings are useless. The failure is that the team expected the embedding to carry information it was never designed to carry. This is the honest starting point for this chapter: Similarity is not correctness, relevance, authority, authorization, or completeness.

A production embedding system sits between human language and machine ranking. Humans ask questions with missing context, overloaded words, abbreviations, time references, permissions, and expectations about truth. The system converts some object into a vector and then searches for nearby vectors. That conversion is useful because it makes fuzzy language computable. It is dangerous because it quietly removes structure. A vector does not preserve the original document, the author's authority, the approval workflow, the user's permission boundary, or the business rule that says one source should override another. Those things have to be represented somewhere else in the system.

The recurring motif of this book is simple: a vector is a shadow, not the object. A shadow can tell you the rough shape of something. It cannot tell you everything the object is made of, when it was last changed, who owns it, whether it is safe, whether it is current, or whether it is legally binding. Good semantic systems are not built by denying that limitation. They are built by respecting it.

This chapter uses the chapter theme to make that limitation practical. We will look at what the embedding layer contributes, what it cannot contribute, which engineering controls must surround it, and how to recognize the failure pattern before users do. The aim is not to make you suspicious of embeddings. The aim is to make you accurate about them.

Whiteboard-style technical sketch infographic for Similar Is Not Correct.
The nearest vector result is not always the correct, authorized, or freshest answer the product should return.

Plain-English Mental Model

Think of an embedding as a learned address. The model reads an object, such as a sentence, chunk, support ticket, product description, code function, image, or user profile, and places that object somewhere in a geometric map. Objects that the model has learned to treat as related tend to land near one another. This makes a certain kind of search possible: instead of asking only for exact words, the system can ask for nearby meaning.

That is the power. The limitation follows immediately. An address is not the house. If two houses are near one another, they may share a neighborhood, but they do not become the same house. A policy draft and an approved policy may discuss the same subject and therefore land close in vector space. A sales proposal and a binding contract may use nearly identical language and therefore look similar. A support ticket saying "I cannot access my account" and a help article saying "reset your password" may be close enough to be useful. The geometry captures relatedness. It does not certify correctness (see Pinecone Semantic for documentation of what vector search actually returns).

In engineering terms, this means the vector layer should be treated as a candidate-generation layer. It proposes possible neighbors. It should not be treated as the final authority. The final system must decide which candidates are allowed, current, authoritative, safe, complete, and useful.

Technical Explanation

The core pipeline has four movements. First, an object is prepared. In text systems, preparation often includes cleaning, splitting, chunking, preserving structure, and attaching metadata. Second, an embedding model maps the prepared object into a dense vector. Third, an index stores those vectors in a way that supports fast nearest-neighbor search. Fourth, a query is embedded and compared against the indexed vectors so the system can retrieve candidates.

Each movement introduces its own failure mode. If preparation is bad, the vector represents the wrong unit of meaning. If the embedding model is mismatched to the domain, the map itself may be wrong for your use case. If the index uses approximate search with poorly tuned recall, the right neighbor may not be found even when it exists. If the query is ambiguous, the nearest neighbors may answer the wrong intent. If ranking stops at cosine similarity, the system may surface the nearest text instead of the useful, authorized, or current one.

The most important discipline is to separate representation from decision-making. Embeddings represent. Retrieval proposes. Ranking decides. Policy constrains. Evaluation verifies. Monitoring watches. A system that collapses all of those into "vector search" will eventually fail in a way that looks surprising only because the architecture hid the distinction.

Table: What the Vector Layer Contributes and What the System Must Add

ConcernVector layer can helpVector layer cannot guaranteeSystem control required
Semantic similarityFinds nearby meaning and paraphrasesCorrectness, authority, freshnessReranking, metadata, source policy
Fuzzy matchingHandles wording variationExact IDs, SKUs, names, negationKeyword/sparse lane and exact fields
Candidate retrievalProduces a useful top-k listFinal answer qualityEvaluation and answer verification
ClusteringGroups related objectsBusiness category truthHuman labels and taxonomy mapping
RecommendationFinds similar users/itemsDiversity, fairness, safetyExploration, constraints, monitoring
RAG contextSupplies possible evidenceFaithfulness of generated answerCitations, grounded generation, evals

Engineering Pattern

The practical pattern is to build a retrieval stack that keeps each responsibility explicit:

  1. Prepare the object with structure preserved.
  2. Embed the correct unit of meaning, not arbitrary blobs.
  3. Store metadata beside the vector, not in a separate forgotten spreadsheet.
  4. Retrieve more candidates than you plan to show.
  5. Filter by tenant, permission, status, date, locale, and product before anything is exposed.
  6. Combine dense vectors with sparse/keyword search when exact terms matter.
  7. Rerank candidates using a stronger relevance model when quality matters.
  8. Evaluate retrieval separately from answer generation.
  9. Monitor drift, freshness, latency, cost, and failure cases after launch.

The pattern is intentionally boring. Production retrieval quality usually improves less from a heroic model choice than from disciplined object preparation, metadata, evaluation, hybrid search, and reranking.

Code / Config Example

# separate retrieval score from correctness controls
def final_rank(candidate):
 return (0.55 * candidate["semantic_score"]
 + 0.20 * candidate["freshness_score"]
 + 0.15 * candidate["source_authority"]
 + 0.10 * candidate["business_priority"])
# This ranking is still not truth; it is a controlled decision policy.

The point of this example is not to prescribe a vendor or framework. The point is to expose the decision boundary. Wherever your production code hides this boundary, future debugging becomes forensic archaeology (see RAG Eval Survey and ERAG for evaluation frameworks that quantify how often the pipeline finds the right document).

Failure Pattern

The most common failure in this chapter's territory is semantic over-trust. The system retrieves something that sounds right, and because it sounds right, the product treats it as right. This is especially dangerous in legal, healthcare, finance, HR, customer support, and internal knowledge-base systems where similar documents often coexist across versions, departments, jurisdictions, and approval states.

A good incident review does not stop at "the embedding returned the wrong result." It asks which missing control allowed the wrong result to become user-visible. Was the chunk boundary wrong? Was there no metadata filter? Did the index include drafts? Was there no freshness rule? Did the query need keyword matching for an exact identifier? Was the reranker absent? Did evaluation fail to include this class of query? The answer is rarely one thing. It is usually a chain of skipped controls.

Checklist

  • Can we state exactly what object is being embedded?
  • Do we know which facts are intentionally stored outside the vector?
  • Are permissions, freshness, status, tenant, source, and version represented as metadata?
  • Is vector similarity treated as candidate generation rather than final truth?
  • Do exact identifiers have a keyword or structured-search path?
  • Do we evaluate retrieval with realistic user queries?
  • Do we monitor failures after launch instead of trusting the demo?

One-Sentence Takeaway

A vector is a shadow, not the object. The system must decide what the shadow is allowed to mean.

Deep Dive: Nearest Neighbor Is Not the Same as Best Answer

Nearest-neighbor search answers a narrow question: which indexed vectors are nearest to the query vector under the chosen metric and index configuration? Users ask a broader question: which result best satisfies my intent under the rules of this product? Those are not the same question.

A closest document may be wrong because it is outdated. It may be incomplete because it contains only one part of a multi-step answer. It may be unauthorized because the user has no right to see it. It may be misleading because it states a discontinued rule in confident language. It may be low-authority because it is a discussion thread rather than an approved policy. It may be similar but not relevant because it shares vocabulary with the query while answering a different need.

This is why retrieval systems have stages. Candidate generation values recall. Ranking values relevance. Filtering values policy. Reranking values deeper semantic judgment. Generation values answer construction. Evaluation values whether the entire pipeline actually helped users. A single cosine score cannot do all of that work.

Practical Failure Review

When a user says "the AI gave me the wrong answer, " split the incident into layers. Did the right document exist in the corpus? Was it chunked correctly? Was it embedded with the current model? Was it retrieved in top-k? Was it filtered out? Was it below the reranker threshold? Was it present in the prompt? Did the generator ignore it? Did the answer cite it? Each question points to a different fix.

SymptomLikely layerFix
Right doc never appearsRetrieval recallHybrid search, larger k, model eval
Right doc appears but lowRankingReranker or domain boost
Old doc appears firstFreshnessMetadata filter/boost
User sees restricted docSecurityPermission prefilter
Answer ignores evidenceGenerationPrompting, citations, verifier

The mature system makes these layers observable. The immature system says "vector search failed" and has no more detail.

Additional Production Notes for Chapter 4

In production, the chapter's principle should be converted into a named design review item. The team should not rely on tribal knowledge or on the memory of the engineer who built the first prototype. A named review item creates accountability. It also creates a place where research, product constraints, security requirements, and operational evidence can meet before launch.

Share