CourseAI Engineering: The Complete Course · Module 8: Retrieval-Augmented Generation (RAG) · part 65 of 105
Part 65 · Module 8: Retrieval-Augmented Generation (RAG)

Lab: Build rag_answer, grounded and cited

19 min read·13 Oct 2026
Module 8 · Lab · About 60 minutes · Needs: lessons 1 to 5 of this module (ingestion, storage, retrieval, generation, evaluation)

What you are building

RAG_ANSWER(QUESTION, LABEL): THE FINISHED PIECE chunk 300 chars embed MiniLM store Chroma retrieve + filter context [ids], edges answer + citations check ids, numbers cited reply refusal
Your code (blue) does everything except write the answer (amber, the model); a reply that passes the check goes out with citations (green), anything else becomes the refusal (grey).

This lab joins the module's five lessons into one function, rag_answer(question, label): answers grounded in the help centre, with citations. A question goes in; a checked reply comes out with the chunk ids it used, or the fixed sentence "I don't know, let me get a person." On the way: Lesson 1's 300-character chunks with a content hash, Lesson 2's MiniLM vectors in Chroma, Lesson 3's winner (dense search plus the category filter), and Lesson 4's grounded prompt, citation check and refusal gates. You finish with a scorecard on Lesson 5's ten golden questions. A full run makes 11 hosted calls.

The rest of this course is yours to keep

This course is bought on its own, once, and stays readable afterwards, including the parts added to it later.