Inside the Machine

Retrieval That Fails: Why Cosine Similarity Is Not Relevance

Vector search returns what is semantically near your query. Near is not useful, and the gap between them is where most retrieval systems quietly break.

A working retrieval pipeline that returns plausible-looking chunks and the wrong answer is the most common failure in applied AI, and the cause is almost never the generation prompt. Vector search retrieves what sits near your query in embedding space. Near encodes topic, not relevance, not logic and not precision. Everything below is the gap between those.

Where recall is actually lost

  • Asymmetry. Queries are short questions; documents are long statements. They occupy different regions of the space. Many open embedding models require prefixes on each side — a query marker and a passage marker — and omitting them degrades recall measurably. Read the model card. This is the most common silent misuse in production retrieval.
  • Chunk boundaries. A chunk that splits a definition from its subject is unretrievable by either half. Overlap chunks, and prepend the document title and section heading to every chunk so it carries its own context.
  • Lexical misses. Dense vectors are poor at exact identifiers: part numbers, error codes, surnames, ticker symbols, statute references. Keyword search finds them trivially. Hybrid retrieval beats either method alone consistently enough that it should be your default, not an optimisation.
  • Negation and constraints. Embeddings encode subject matter, not logic. A query for contracts without an arbitration clause retrieves contracts about arbitration clauses. Constraints belong in metadata filters, enforced by code.
  • Duplicates. The top ten results are frequently one document in ten formats. Dedupe before you spend context on it, or you have retrieved one fact and paid for ten.

The two-stage shape that works

  1. Retrieve widehybrid dense plus keyword, top 50-100 candidates
  2. Rerank narrowcross-encoder scores query and candidate together, down to 5-8
  3. Compress and citekeep the passage and its source, discard the rest

The reason this split exists is mechanical. A bi-encoder embeds query and document separately, which is what makes the index precomputable and cheap over millions of chunks — and also what limits its accuracy, because it never compares the two directly. A cross-encoder reads the query and one candidate together and scores far more accurately, which is why it cannot be precomputed and why you only run it on a shortlist. In most pipelines the large precision gain comes from adding this stage, not from upgrading the embedding model.

50 → 8

retrieve wide, rerank narrow — the precision win in most pipelines comes from the reranker, not a better embedding model

Measure the stages separately

Build a set of 50 to 200 real questions paired with the chunk identifiers that genuinely answer them. Then measure retrieval recall separately from answer quality. Without that split you cannot tell whether a wrong answer was a retrieval miss or a generation failure, and teams burn weeks rewriting prompts to fix a retrieval problem. The diagnosis is blunt: if the evidence never arrived in the context, no wording change will produce it.

Read the two numbers together. Low recall at the wide stage means the evidence is not reaching the model and the prompt is irrelevant. High recall at the wide stage with wrong answers means your problem is reranking, ordering, or a context budget so full that the right chunk is buried mid-prompt where the model reads it least carefully.

The cost arithmetic nobody does up front

A 1,536-dimension float32 vector is about 6 KB. A million chunks is therefore roughly 6 GB of raw vectors before any index overhead, which is why int8 quantisation (four times smaller) and binary quantisation (thirty-two times smaller) exist. Both trade a reported modest recall loss that you should measure on your own set rather than take on faith, usually alongside a rescoring pass over full-precision vectors for the shortlist. The other cost is operational: embeddings are a versioned dependency. Change the model and every vector in the store must be recomputed, so store the model identifier and the chunking parameters on every row from day one.

Where the honest uncertainty sits

Established: hybrid beats single-method retrieval, reranking substantially improves precision, and query and passage asymmetry matters for models trained with prefixes. Not established and frequently stated as if it were: a universally correct chunk size. Working ranges tend to land in the low hundreds of tokens with overlap, but it depends on how your documents are structured and the only way to know is to measure recall on your own question set.

Key takeaways

1Check whether your embedding model wants query and passage prefixes — omitting them silently costs recall
2Default to hybrid retrieval plus a cross-encoder reranker; the reranker is usually the bigger win
3Constraints and negation belong in metadata filters, because embeddings encode topic and not logic
4Measure retrieval recall separately from answer quality, or you will debug the wrong stage

This is one lesson of 541.

The whole Foundation is free — 16 subjects, beginner to advanced. Sign in to track what you have read, take the end-of-module quizzes, and use the terminal.