Technical Interview Questions

RAG Architecture: How Retrieval-Augmented Generation Actually Works

"Explain RAG architecture. When should you use RAG versus fine-tuning?"

Why Interviewers Ask This

RAG is the dominant pattern for grounding LLMs in proprietary data, and every AI engineering interview in 2026 will ask this. Interviewers want to see you understand the actual pipeline (not just "retrieve and prompt") and the RAG-vs-finetune tradeoff.

How to Answer

  1. 1

    High-level pipeline: (1) chunk your documents; (2) embed each chunk with an embedding model and store vectors in a vector DB; (3) at query time, embed the user query, retrieve top-k similar chunks; (4) optionally rerank; (5) stuff retrieved chunks into the LLM prompt as context; (6) LLM generates grounded on that context.

  2. 2

    Chunking matters: too small → loses context; too large → noisy retrieval. 300–800 tokens with overlap is typical. Semantic chunking (respecting sentence/paragraph boundaries) beats naive fixed-size.

  3. 3

    Retrieval: cosine similarity over embeddings is the basic approach. Hybrid search combines dense (embedding) and sparse (BM25) retrieval to cover both semantic and keyword match. Reranking with a cross-encoder model on the top 20–50 candidates before passing top 3–5 to the LLM dramatically improves quality.

  4. 4

    Prompt construction: typically "Here is some context, use it to answer. Context: ... Question: ..." Guard against hallucination with "if the answer isn't in the context, say you don't know."

  5. 5

    RAG vs. fine-tuning: RAG is for injecting knowledge — facts, documents, domain info — where the knowledge changes often or is too large to fit in training. Fine-tuning is for changing model behavior — style, format, task-specific response patterns. For most enterprise "chat with our docs" use cases, RAG is the right answer because docs change and fine-tuning on them is expensive and stale.

Sample Answer

RAG — retrieval-augmented generation — grounds an LLM in specific documents at query time instead of baking them into model weights. The pipeline has five stages. First, offline indexing: split your document corpus into chunks (typically 300-800 tokens with some overlap), embed each chunk using an embedding model like text-embedding-3-small, bge, or e5, and store the embedding plus the chunk text in a vector database like pgvector, Qdrant, Milvus, or Pinecone. Chunking choices matter — too small and you lose surrounding context that the LLM needs; too large and each chunk dilutes the relevant signal. Semantic chunking that respects sentence or paragraph boundaries generally beats naive fixed-size splits. Second, online retrieval: when the user asks a question, embed the question with the same embedding model, then query the vector DB for the top-k nearest neighbors by cosine similarity. Third, optional reranking: pass the top 20-50 retrieved chunks through a cross-encoder reranker like bge-reranker or Cohere Rerank, which is a smaller model that reads the query and each chunk together and scores relevance more precisely than pure embedding similarity. Keep the top 3-5 reranked chunks. Fourth, hybrid search: in practice, combining dense embedding retrieval with sparse BM25 keyword retrieval (reciprocal rank fusion or weighted sum) catches cases where exact keywords matter — technical terms, names, numbers — that embeddings sometimes miss. Fifth, prompt assembly: construct a prompt like "Use the following context to answer. If the answer is not in the context, say you don't know. Context: [retrieved chunks]. Question: [user query]." Send to the LLM. For when to use RAG versus fine-tuning: they solve different problems. RAG injects knowledge — facts, documents, evolving domain information. Fine-tuning shapes behavior — tone, response format, following specific instructions. For the common "chat with our internal docs" use case, RAG is the right tool because documents change constantly and retraining would be expensive and produce stale results. Fine-tuning is complementary — you might fine-tune on output format while using RAG for the actual facts. The expensive failure mode to watch for: hallucination when retrieval misses. Even with "say you don't know" instructions, models sometimes confabulate. Mitigations include confidence thresholds on retrieval scores, citation requirements in the prompt, and evaluation frameworks like Ragas to monitor faithfulness in production.

Pro Tips

  • Walk through the pipeline end-to-end — "chunk, embed, store, retrieve, rerank, prompt" — it's the skeleton interviewers want.

  • Mention reranking explicitly — most candidates skip it, but it's a huge quality lever in production.

  • The "RAG for knowledge, fine-tuning for behavior" framing is the sharpest summary of the tradeoff.

  • If you blank on vector DB names or reranker names during the interview, HireMe AI can surface Qdrant / Pinecone / bge-reranker / Cohere Rerank.

Frequently Asked Questions

What's the role of the embedding model?

It maps text to vectors where semantic similarity correlates with vector distance. Choice matters — OpenAI text-embedding-3-small is general purpose; bge or e5 are strong open options; domain-specific corpora may benefit from a fine-tuned embedder.

How do I evaluate a RAG system?

Frameworks like Ragas measure faithfulness (does the answer stay within context?), answer relevance, and context precision/recall. Pair with human eval on a golden set.

Is RAG expensive?

Much cheaper than fine-tuning. Main costs: embedding the corpus once, vector DB hosting, and per-query embedding + LLM inference. For dynamic corpora, this is dramatically cheaper than periodic retraining.

Worried About Going Blank in Your Interview?

HireMe AI listens to your interview in real-time, detects questions, and generates instant answer suggestions — so you never freeze up again.

Try HireMe AI Free