LLMS & TRANSFORMERS · INTERVIEW QUESTION
Explain RAG (Retrieval-Augmented Generation). What are the key components and failure modes?
🟡 intermediate · RAG & Agents
Hint: Think about retrieval, context stuffing, and when the retriever fails.
Answer
RAG augments LLM generation with retrieved external knowledge, reducing hallucinations and enabling up-to-date answers.
Pipeline
Documents → Chunk → Embed → Vector DB
↓
User Query → Embed → Search → Top-K Chunks → Prompt → LLM → Answer
Key Components
| Component | Options |
|---|---|
| Embedding model | OpenAI, Cohere, sentence-transformers |
| Vector store | FAISS, Pinecone, Weaviate, Chroma |
| Chunking | Recursive, semantic, fixed-size |
| Reranker | Cross-encoder, Cohere rerank |
Failure Modes
- Poor retrieval: wrong chunks returned for the query
- Lost in the middle: model ignores middle context in long prompts
- Hallucination despite context: model overrides retrieved facts
- Chunk boundary issues: important info split across chunks
python
# Illustrative interface sketch: supply tested retrieval and generation functions.
def answer_question(question, retrieve, generate):
passages = retrieve(question, k=5) # enforce user permissions here
context = "\n\n".join(p["text"] for p in passages)
return generate(question=question, context=context)Improvements: hybrid search (dense + sparse), reranking, query expansion, iterative retrieval.
Related questions
- Design an AI agent system with tool use. What are the key components and challenges?
- Explain the self-attention mechanism in detail. What are Q, K, V and why do we use scaled dot-product attention?
- Explain positional encoding in Transformers. Compare sinusoidal, learned, RoPE, and ALiBi.
- Explain the difference between LoRA, full fine-tuning, and prompt tuning. When would you use each?
- Explain RLHF (Reinforcement Learning from Human Feedback). What are the key steps and challenges?