Skip to content
Tech Interview Prep
Technical interview guide

Retrieval-Augmented Generation (RAG)

Grounding an LLM's output in retrieved external documents instead of relying purely on its trained-in knowledge.

Minutes to read
3
Practice MCQs
25
Interview Q&A
25
Edition
v5
Editorial status
Reviewed

Scope: RAG, DPR, Sentence-BERT, ColBERT, FAISS, HNSW, BEIR, MTEB, long-context, HyDE, RAGAS, NIST AI RMF, and OWASP prompt-injection references reviewed 2026-09-04.

Overview

Curated: · Written: · Reviewed:

Retrieval-Augmented Generation (RAG)

In one line

RAG retrieves passages from an external corpus at query time and has the generator answer from them, with citations. Reach for it when the corpus changes often, is private or per-tenant, or answers must trace back to a source.

Key definitions

  • Candidate generation: the retrieval stage that decides which documents the reranker and generator can ever see.
  • Hybrid retrieval: dense and BM25 candidate lists fused, usually by reciprocal rank fusion (RRF).
  • ACL predicate: an authorization filter applied inside the search, before top-k is cut.
  • Parent-child retrieval: match on small chunks, return the parent section to the generator.
  • Entailment check: an NLI test that the cited span supports the claim it is attached to.

Formulas and complexity

RRF(d)=∑i1k+ranki(d)\text{RRF}(d)=\sum_i \frac{1}{k+\text{rank}_i(d)} recall@k=∣relevant∩top-k∣∣relevant∣\text{recall@}k=\frac{|\text{relevant}\cap\text{top-}k|}{|\text{relevant}|}

Hypothetical figures:

  • Relevant set {A,B,C,D}, top 5 = A,E,B,F,C: recall@5 = 3/4 = 0.75.
  • With k=60, a document ranked 1st by dense and 3rd by BM25 scores 1/61 + 1/63 ≈ 0.0323.
  • Reranking cost grows with the candidate count N, so cap N before the cross-encoder.

How it works

Ingest stores owner, ACL, version, checksum and timestamp on every chunk. The query is rewritten, and the original is kept for the reranker and the logs. Dense and BM25 retrieve candidates under the ACL predicate. RRF fuses the two lists, a cross-encoder reranks the top candidates, and duplicates are dropped before the context budget is applied. The generator receives instructions separately from the passages, cites span IDs, and abstains when support is missing. Each citation then gets an entailment check and an authorization check.

Index with ACL, version, checksum S Query Rewrite, keep original RRF fusion Cross-encoder rerank to top 5 Generate with cited span IDs Entailment and authorization check

When to use and when not to

SituationChoose
Corpus changes, is private, per-tenant, or must be citedRAG: re-index without retraining
Skill or output format must change, not factsFine-tuning: no retrieval cost, no provenance
Corpus small and staticLong-context: paste it, but cost scales with corpus size
Parametric knowledge suffices, no verification neededPrompt-only
Query typeDenseBM25
Paraphrasestrongweak, no term overlap
Exact identifier (error code, part number)weak, rare tokens embed poorlystrong

At scale, the ACL predicate has to stay selective. A filter that matches a small share of the index can make approximate search slow or return fewer hits than top-k. Deletions need tombstones so removed chunks stop surfacing before the purge runs. Expect quality to drift when embedding model versions differ between the index and the query path.

Traps interviewers probe

  1. Raising k to fix recall. More chunks add distraction, conflicts and injection surface. Fix candidate generation, and tune k as a context budget per question type.
  2. Expecting the reranker to find a missed document. It only reorders what retrieval returned. Fix: measure recall@N of the candidate set first, then rank.
  3. Post-filtering by ACL. Unauthorized high-similarity chunks displace permitted evidence and can leak through scores or caches. Fix: apply the ACL predicate inside the search. Similarity is not authorization.
  4. Swapping the query encoder alone. Query and document vectors must share one space. Fix: build a parallel index or do an atomic versioned rebuild, then run retrieval eval on both.
  5. Caching answers under the query text alone. Fix: key on tenant, ACL snapshot, index version and prompt version, and purge on permission change.

Misconceptions to correct out loud: RAG does not eliminate hallucination, because a real passage can still be misread, so the entailment check exists. A citation proves retrieval, not correctness. Vector search alone does not handle identifiers; hybrid retrieval does.

Interview tips

Open with: "Retrieval decides what the model can see, so I debug it first."

Follow-ups to expect:

  • Sudden quality drop: segment evals by tenant, freshness and question type; check index and embedding versions; then recall; then the reranker.
  • Conflicting sources: apply governance precedence, show dates and versions, or abstain.
  • No-answer path: abstain or return an explicit missing-evidence message. Never answer silently from model memory.
  • Indirect injection: treat retrieved text as untrusted, use least-privilege tools, and require confirmation for consequential actions.
  • What changes at scale: ACL selectivity, index memory, reranker latency at N, and re-index time per tenant.

30-second outline:

  1. Name the pipeline and say that errors propagate forward.
  2. Check whether the gold passage reached candidates, then whether it was ranked.
  3. Enforce ACL inside search, and verify each citation for entailment and authorization.
  4. Measure recall@k and grounded-answer rate, segmented by question type and tenant.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.