Welcome! These are the three notebooks from the Packt webinar "Agentic RAG: Architectural Patterns for Knowledge-Driven AI Systems" with Imran Ahmad. Labs 1 and 2 are the exact notebooks from the live demos; Lab 3 is your take-home challenge.
| Notebook | What you build | Time |
|---|---|---|
lab1_router_decomposition.ipynb |
(Live Demo 1) A router + query decomposition agent in LangGraph: the agent classifies incoming questions, splits complex ones into sub-queries, and routes each to the right retriever. | ~15 min self-paced |
lab2_corrective_rag.ipynb |
(Live Demo 2) A CRAG-style corrective loop: the agent grades its own retrieved context, rewrites the query and retries within a retry budget, and optionally falls back to web search. | ~20 min |
lab3_takehome_selfrag_eval.ipynb |
(Take-home) Self-RAG emulation with reflection tokens, multi-hop retrieval, and a RAGAS evaluation harness so you can measure what you built. | ~45–60 min |
Do them in order — each lab builds on concepts from the previous one.
New to the notebooks? Start with LAB_COMPANION.md — a full walkthrough of all three labs: why each exists, how it maps to the webinar slides, a cell-by-cell explanation of the code, and how to read the executed traces.
Option A — Google Colab (recommended), one click:
| Lab | Open |
|---|---|
| Lab 1 — Router + decomposition | |
| Lab 2 — Corrective RAG loop | |
| Lab 3 — Self-RAG + evaluation |
Run the cells top to bottom — the first cell installs everything (pinned versions).
Also in this repo: LAB_COMPANION.md (the full walkthrough), takehome_quiz.md (15 questions + answer key), the one-page pattern cheat sheet, prerun/ — the same three notebooks fully executed, so you can read every trace and score without spending a token — plus the webinar slides and the book chapter the session draws on: Information Retrieval and Knowledge Agents (Ch. 6 of 30 Agents Every AI Engineer Must Build, Packt).
Option B — Locally:
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
jupyter labThe pip install cells are at the top of each notebook — run them inside your venv and you're set. Python 3.11 recommended (matches Colab).
Each install cell pins the exact package set verified working on July 10, 2026 (Python 3.11, same as Colab): langgraph 1.2.9 · langchain 1.3.13 · langchain-openai 1.3.5.
One pin is load-bearing: Lab 3 pins langchain-community==0.3.31 (not the latest 0.4.x) because ragas 0.4.3 imports legacy modules that langchain-community 0.4 removed — with the latest version, ragas crashes on import. Don't "helpfully" upgrade that pin. If you unpin everything and things break, that's the first place to look.
- OpenAI API key — the labs use
gpt-4o-miniandtext-embedding-3-small. Expect a few cents of usage per lab. Get a key at platform.openai.com. - Tavily API key (optional) — only for Lab 2's web-search fallback branch. The lab works fine without it (the fallback is simply skipped); a free tier is available at tavily.com.
- No data downloads. All documents are inline in the notebooks — a small fictional corpus for "Nimbus Analytics", a made-up SaaS company. Everything is self-contained.
Each notebook prompts for your key with getpass in an early cell — paste it there. Never hardcode keys into notebook cells, especially if you plan to share or commit the notebook.
- Rate limits (
429errors): Common on brand-new OpenAI accounts with low tier limits. Wait a minute and re-run the cell — the labs make few calls, so a retry usually resolves it. - Pip resolver hiccups on Colab: If the install cell complains about dependency conflicts or imports fail oddly right after installing, do
Runtime → Restart runtime, then re-run from the top (skip re-installing if it succeeded). This fixes 95% of Colab weirdness. AuthenticationError: Your key wasn't picked up — re-run thegetpasscell and make sure there's no leading/trailing whitespace.- Lab 2 web fallback errors: If you didn't set a Tavily key, that's expected — the notebook detects the missing key and skips the fallback branch.
Papers, docs, Imran's books, the Architecture of RAG video playlist, and neurals.ca — all linked from RESOURCES.md.
Something broken or unclear? Reach out via the Packt webinar follow-up channel or the contact details on the final slide. Happy building — go make your RAG systems think before they retrieve.