Embedding Retrieval

Embedding retrieval maps queries and documents into vectors, then retrieves nearby documents according to a similarity score.

For query embedding and document embedding :

Top-k retrieval returns:

In practice, retrieval is a two-part contract:

The system must retrieve units that are not only similar to the query, but sufficient to support the downstream claim.

Chunking changes the retrieval task. The retrieval unit can be:

The unit should match the evidence granularity needed by downstream generation.

Embedding Space

Embedding retrieval depends on what the embedding model was trained to consider similar.

Similarity typeGood forFailure mode
Semantic paraphrasenatural language questions and explanationsmisses exact identifiers
Domain conceptrelated scientific or technical conceptsretrieves broad background instead of evidence
Instruction-query alignmentquestion-answer retrievalweak for raw tables, code, formulas
Code/text mixed spacecode search and API examplescan over-rank names without semantic support

The embedding function should match the corpus and retrieval goal:

Changing changes the meaning of nearest neighbors, so embedding model, corpus version, and chunking policy should be versioned together.

Retrieval Evaluation

Retrieval quality is not the same as answer quality, but bad retrieval usually bounds answer quality.

For a query with relevant set :

MetricUse whenTrap
Recall@kmissing evidence is costlyhigh recall can still include noisy context
Precision@kcontext window is tightmay punish useful supporting background
MRRone best answer document mattersweak when evidence is distributed
nDCGgraded relevance existsrelevance labels can be subjective
answer groundingRAG output is evaluated end-to-endmay hide retrieval failures behind generation

Filtering and Metadata

Vector similarity should not replace scope filters. If the task has known constraints, filter before ranking.

FilterWhy
source typepaper, code, docs, private note, public note have different trust
date or versionstale docs can be semantically close but wrong
section or fieldtitle, abstract, method, table, code block serve different claims
privacy boundaryprivate or internal documents should not enter public output
domainAI, infra, computational biology, agents may share terms with different meanings

The useful pattern is:

then rank only inside .

Checks

  • What is embedded: page, paragraph, chunk, title, code block, or metadata?
  • Are chunks small enough to retrieve precisely but large enough to preserve context?
  • Is retrieval evaluated with recall, precision, or downstream answer quality?
  • Are stale or private documents excluded from public retrieval?
  • Are embeddings versioned when the corpus or model changes?
  • Does the retrieved unit contain enough context to support a claim?
  • Are metadata filters used before vector similarity when scope matters?
  • Is retrieval being evaluated separately from generation?
  • Does the top result support the exact claim, or only the general topic?