Skip to content

M7 solution

The expected, fully-commented artifacts for M7's lab. Peek only after you've tried the lab.

File What it is
rag.py The Q&A app: chunk_documentbuild_index (Chroma) → retrieveanswer (Claude). The retrieve → augment → generate loop in one readable file.
sample_notes.txt A sample document (a café handbook) with clear facts to query, so the app runs before you bring your own.

Run it

With your venv active, chromadb installed (see the vector-store guide), and your M4 .env present:

pip install chromadb          # once (or: pip install -r ../../requirements.txt)
python rag.py                 # first run downloads a small embedding model (one time)
Ask "What time does the café open?" or "Can I get my money back on a coffee?".

How this was verified

  • Chunking was verified for real on sample_notes.txt → 8 chunks (title + 7 sections), runnable on plain Python with no dependencies.
  • The full retrieve → augment → generate flow was verified with Chroma and Claude mocked: a stand-in collection ranked chunks by word overlap, so a question ("what time does the café open?") retrieved the correct Opening hours chunk, the prompt was augmented with Context:/Question:, and the (mocked) model answered from it.

Could not run live Chroma here. The build sandbox has Python 3.14, for which chromadb's dependencies have no wheels yet (the install fails building pandas). The code uses Chroma's documented, stable API and is verified by mock; the live install + real embedding search must be piloted on Python 3.10-3.12 (3.12 recommended). No API key or billed call was used.