<aside> ๐Ÿ“…

Date: Tuesday, October 6, 2026 ยท Week 2, Day 9 ยท Type: Build Day

</aside>

Learning Manual

9.1 The RAG Architecture โ€” Retrieval-Augmented Generation = Search Engine + Context Injector + Generative Model.

9.2 The Prompt Template โ€” structuring prompts to instruct the LLM: "Answer the question ONLY using the facts provided below."

9.3 Grounding & Hallucination Mitigation โ€” forcing factual attribution to retrieved context passages.

The Daily Build

Build a complete end-to-end RAG script: load a multi-page document, chunk it (Day 8), embed and store it in TinyVectorDB (Day 5), retrieve top 3 chunks for a user question, inject them into a prompt, and generate a factual answer.

Architecture Diagram

[User Question] --------+
                        | (Query)
                        v
               [TinyVectorDB Index] ---> [Top 3 Chunks Retrieved]
                                                  |
                                                  v
[LLM Prompt: Question + Retrieved Chunks] ---> [Grounded Answer Generated]

Interview Questions

  1. Walk me through the four core steps of a standard RAG pipeline.
  2. What are the three most common reasons a RAG system provides an incorrect answer?
  3. How do you prevent an LLM from using its pre-trained knowledge when you want it to answer strictly from proprietary documents?

Problem Statement

Problem 09. Write a Python prompt builder function build_rag_prompt(user_query: str, retrieved_chunks: list[str]) -> str that formats the retrieved context into a clean, delimited system prompt with explicit guardrail instructions against outside speculation.

AI-DSA Primitive

Data Structure: Inverted String Buffer (Prompt Context Assembly).

Mechanics: Dynamic string joining with delimiters to construct structured context payloads within strict token bounds.

Real-World Production Use: Deployed inside all enterprise RAG orchestrators to assemble dynamic LLM prompts.

Software Design Pattern