What This Course Builds
Imagine a member of a community workshop asks: "Can I cut PVC on the laser cutter?" The answer is in the workshop's own documents, which no language model was trained on. A retrieval-augmented generation (RAG) system answers by first retrieving the passages most likely to contain the answer, then asking a language model to generate an answer from those passages only, citing them. If the passages do not contain the answer, it should say so.
Retrieval needs a fast way to find passages whose meaning is close to the question. Text is turned into lists of numbers called vectors (or embeddings), and the passages whose vectors are nearest to the question's vector are returned. A vector database stores those vectors with their text and metadata and finds the nearest ones quickly, even among millions.
This course builds that system piece by piece on your own computer, measures each piece, and makes it safe to use. You will work with a fictional organisation, Alder Lane Makerspace, whose documents were written for the course. Because no model has seen them, you can always tell whether an answer came from the documents or from the model's imagination.
The Journey

Each stage depends on the ones before it.
Read the path from left to right:
- Foundations. You set up the tools, watch a small RAG system answer a question, learn how the two RAG pipelines fit together and when RAG is the wrong tool, then turn text into vectors and write exact search yourself.
- Indexes and databases. You measure approximate indexes (HNSW, IVF and product quantisation) against your exact search, then store, filter, tune, back up and secure vectors in Qdrant, and compare PostgreSQL with pgvector.
- Documents and measurement. You turn documents into clean, traceable chunks, build a labelled question set and measure retrieval, then improve it with keyword search, fusion and reranking.
- Answers. You generate cited answers with a small local model and evaluate them honestly.
- Production concerns. You enforce permissions, test prompt injection, delete data completely, trace requests and change models without downtime.
The final challenge combines everything in one assistant that must pass stated checks.
What Runs Where
Everything runs on your computer. Python scripts in ~/rag-practice call
three local services: Ollama, which runs the language model, and two
databases in containers, Qdrant and PostgreSQL. All three listen only on
127.0.0.1, so nothing is reachable from other computers, and Ollama's
cloud features are turned off so prompts never leave your machine. After the
one-time downloads in the next lesson the course needs no account, API key or
payment.
How Lessons Work
Every lesson has three views. Full Course teaches the topic with worked examples and a practical task. Revision helps you reconstruct the main ideas later. Quick Reference collects commands, patterns and checks.
Practical lessons follow the same shape: what you will build, the concepts it needs, the code explained block by block, commands to run and what success looks like, what a different result means, a small task of your own, and cleanup. You will often be asked to predict a result before running code; write your prediction down, because the gap between prediction and result is where most learning happens.
Sample output is labelled illustrative: timings, scores and generated answers differ between computers and runs. Language models in particular can answer differently on another machine even with the same settings, so the course never checks an answer by its exact words. It checks properties instead: does every citation point at a retrieved source, does an unanswerable question get the agreed refusal sentence, did the right document come first.
Completing a lesson in the reader records that you read it. It does not grade your work or certify a skill; the checks in each lesson are for you.
Check Your Starting Point
The course assumes four things. Try each task; the answers follow.
1. A terminal. Make a folder, save a file in it and run it. On macOS and Linux:
mkdir -p ~/rag-practice/readiness
cd ~/rag-practice/readiness
(In PowerShell: mkdir $HOME\rag-practice\readiness and
cd $HOME\rag-practice\readiness.) You do not need the course environment
yet; any Python 3 runs this task.
2. Python. Save this as readiness.py in ~/rag-practice/readiness:
"""Readiness task: group documents by site, then count them."""
DOCUMENTS = [
{"id": "membership-plans", "site": "alder-lane", "access": "public"},
{"id": "laser-materials", "site": "alder-lane", "access": "members"},
{"id": "bench-rules", "site": "riverside", "access": "members"},
]
def group_by(records, key):
groups = {}
for record in records:
groups.setdefault(record[key], []).append(record["id"])
return groups
groups = group_by(DOCUMENTS, "sites")
for site, ids in sorted(groups.items()):
print(f"{site} ({len(ids)}): {', '.join(ids)}")
Run it with python3 readiness.py (py readiness.py on Windows). It
stops with a traceback. Read the last line, find the mistake and fix it, then
predict the output before running it again.
3. JSON and NumPy. Without running anything, answer: for
a = numpy.zeros((5, 3)), what are the shapes of a[0], a[:, 0] and
a[1:3]? And what does json.loads('{"id": "refunds", "words": 42}')["words"]
return?
4. Language models. Which of these statements are true?
- A language model produces text one token at a time, each chosen from what is likely to come next.
- If an answer sounds confident and fluent, it is correct.
- A model knows nothing about documents written after its training unless they are given to it in the prompt.
- The same question can get different answers on different runs.
Answers
Python. The last line is KeyError: 'sites', raised on the line inside
group_by that reads record[key]. The documents have a site key,
not sites, so the call should be group_by(DOCUMENTS, "site"). The
fixed script prints:
alder-lane (2): membership-plans, laser-materials
riverside (1): bench-rules
If you could fix this from the traceback and explain setdefault, your
Python is ready. If not, study Python first (for example, Python for AI and
Machine Learning); this course does not teach Python syntax.
JSON and NumPy. (3,), (5,) and (2, 3); and 42, an
integer. Vector maths is taught from scratch in the embeddings module, so
shapes are all you need now.
Language models. 1, 3 and 4 are true; 2 is false. Fluency is not evidence: a model can produce a confident, well-formed and wrong answer. RAG reduces this by giving the model the right passages and asking for citations you can check, but it does not remove it, which is why the course measures answers instead of trusting them.
Safety Rules You Will See Throughout
- Services listen only on
127.0.0.1; Ollama's cloud features stay off. - Course data is written for the course about a fictional organisation. Any "secret" in a document is fake and labelled as such. Never put real personal or confidential data into the practice system.
- Prompt-injection examples target only the course's own model and data.
- Commands that delete anything name exactly what the course created, with
the
rag-courseprefix. The course never uses broad clean-up commands. - Generated answers are model output to be checked, never facts.
What the Course Does Not Cover
Training or fine-tuning models, agents and tool calling, multimodal and PDF-heavy RAG, orchestration frameworks, other vector databases beyond a dated comparison, managed cloud deployment and user interfaces. The course builds each component in plain Python so you can see what it does; once you understand them, frameworks become much easier to judge.
Cleanup
Delete the readiness folder when you are done:
rm -r ~/rag-practice/readiness
(In PowerShell: Remove-Item -Recurse $HOME\rag-practice\readiness.)
The next lesson creates the rest of ~/rag-practice.