Generative AI

Retrieval-Augmented Generation (RAG)

Lesson 4 · Generative AI

Retrieval-Augmented Generation (RAG)

9 min

You'll be able to

  • Explain why models need external knowledge
  • Understand embeddings and vector search
  • Describe the RAG retrieval + generation loop

Models only know what they saw in training. To answer questions about your own documents, we add retrieval: RAG fetches the most relevant passages and feeds them to the model as context, grounding its answer in real source material.

Retrieval works through embeddings — vectors that capture meaning. Text with similar meaning maps to nearby points in vector space, so a vector database can quickly find passages semantically close to a query.

The RAG loop

  • Index: split documents and embed each chunk into a vector database.
  • Retrieve: embed the user's question and find the closest chunks.
  • Augment: insert those chunks into the prompt as context.
  • Generate: the model answers using the provided context.

RAG is how AI assistants answer questions about private or up-to-date information they were never trained on.

Challenge

Design a RAG app

Outline a RAG pipeline that answers questions about your company's internal handbook. Name the documents, the chunking, and what the model should be told in its system prompt.

Knowledge Check

RAG

0/2 answered

In RAG, what is retrieved and added to the prompt?

Embeddings represent text as vectors that preserve semantic similarity.

Answer all questions to submit.

Search AmineX

Search courses, lessons, projects and concepts