Skip to main content

Pattern · Retrieval and RAG

RAG pipeline

Answer from your own documents: retrieve the right passages at question time and make the model answer only from them, with citations.

Say it in the interview

I would use a RAG pipeline: index the documents in structure-aware chunks, retrieve with hybrid search and a reranker, and make the model answer only from numbered passages with citations. I would measure retrieval recall separately from answer faithfulness, so I know which half broke.

When to use it

  • The answer lives in documents that change (policies, manuals, tickets)
  • You need citations a person can check
  • The data is too big or too private to fine-tune on

How it works

  1. Documents → Parse and chunk
  2. Parse and chunk → Embed
  3. Embed → Vector index
  4. Question → Retrieve top k
  5. Retrieve top k → Vector index
  6. Retrieve top k → Rerank
  7. Rerank → Prompt with numbered passages
  8. Prompt with numbered passages → Answer with citations

Trade-offs

  • Cheap to update: re-index instead of retraining
  • Every answer can be traced to a source
  • Quality is capped by retrieval: if the passage is not found, the model cannot use it
  • Adds latency and a store to run

Pitfalls interviewers probe

  • Skipping evaluation of retrieval itself
  • Chunks that cut tables and topics in half
  • Letting the model answer when nothing relevant was found

Practise it on these questions

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.