EasyDeepLearn

How does Retrieval-Augmented Generation (RAG) work?

medium

Answer

  • Index a knowledge corpus as embeddings in a vector database.
  • At query time, embed the user question, retrieve the top-k most similar chunks, and feed them as context to the LLM alongside the question.
  • The LLM generates an answer grounded in the retrieved passages, often with citations.
  • Key knobs: chunking strategy, embedding model, retriever (dense + BM25 hybrid), reranker, and prompt template.
Check yourself — multiple choice
  • RAG replaces the transformer with a retrieval index
  • RAG retrieves relevant chunks and injects them into the prompt
  • RAG does not use embeddings
  • RAG works only on structured databases

Retrieve top-k chunks    stuff\mathrm{chunks}\; \to \;\mathrm{stuff} into prompt    LLM\mathrm{prompt}\; \to \;\mathrm{LLM} answers grounded in them.

#rag#retrieval

Practise LLMs & GenAI

214 interview questions in this topic.

Related questions