Retrieval-Augmented Generation (RAG) with Python

Lesson 1 of 9

Data Collection

Retrieval-Augmented Generation (RAG) is how you get an LLM to answer questions using your knowledge, not just whatever it happened to memorize during training. Instead of retraining the model, you retrieve relevant pieces of your own data at question-time and hand them to the model as extra context. This course builds a complete, working (if simplified) RAG pipeline in 8 steps, this lesson covers the first: gathering the raw knowledge.

Why RAG at all?

An LLM's knowledge is frozen at training time and limited to its context window, it can't answer questions about your company's private docs, yesterday's support tickets, or a codebase it's never seen. RAG fixes this by retrieving the relevant pieces of your own data and inserting them into the prompt, so the model answers grounded in real, current, specific information instead of guessing from what it half-remembers.

Gathering the raw knowledge

Real sources are typically PDFs, docs, APIs, websites, and databases, a mix of structured and unstructured data. For this course, each "document" is just a Python string with a bit of metadata, so every lesson's code runs directly in your browser with no external files needed:

Pythonshares state with other Python blocks

Structured vs. unstructured

  • Unstructured data (the kind this course focuses on) is free-form text: markdown docs, articles, chat transcripts. There's no fixed schema, just prose.
  • Structured data (rows in a database, JSON API responses) has a predictable shape, you'd typically convert it into descriptive text first (e.g. "Order #4821, shipped 2026-01-03, total $42.50") before it can flow through the same pipeline as unstructured text.

NOTE

The goal of this step is simply to build your knowledge base, a collection of raw text your pipeline can later search through. Nothing here is chunked, embedded, or searchable yet, that's what the next several lessons build.

📝 Data Collection Quiz

Passing score: 70%
  1. 1.What problem does RAG solve for an LLM?

  2. 2.Structured data (like database rows) usually needs to be converted into descriptive text before it flows through the same RAG pipeline as unstructured documents.

  3. 3.The goal of the data collection step is to build your ____ ____, a collection of raw text to search through later.