Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 8.8 — Playbook: Minimal RAG Service
LLM Engineering · Example 1 of 3

Recipe: a minimal RAG service with two guards

The fake model copies source [1], except for one question where it invents a price on purpose.

Five recipes to copy: a small service that chunks, indexes, retrieves, cites and refuses; a retrieval test set that measures hit rate and picks the refusal threshold from data; an incremental re-index; a prompt template; and the before-you-ship checklist.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 6 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write hit_at_k(results, expected, k) where results is a list of ranked name lists and expected is a list of names; return the number of questions whose expected name is in its first k results. Print it for k = 1 and k = 2 on three questions.

02

Write plan_sync(old, new) where both are dictionaries from name to fingerprint. Return three sorted lists: names to embed (added or changed), names to delete (only in old), and names unchanged. Print them for one example.

Explain it without notes

01

What two guards sit around the model call in a minimal RAG service, and what does each catch?

02

How would you choose the refusal threshold, and why not pick it by feel?

03

Why is ingestion made incremental, and what do you store to make it so?

04

What do hit@1 and hit@3 tell you that a handful of demo questions do not?

Recipe: a minimal RAG service with two guards
Sign in to run this example in your browser.

Expected output

ingested 8 chunks
question: get my money back
  status: ok
  answer: Unused bikes can be returned within 30 days with the receipt for a full refund. [1]
  sources: returns
question: how much is express delivery
  status: ok
  answer: Standard shipping takes 3 to 5 days. Express shipping takes 1 to 2 days and costs 12 dollars. [1]
  sources: shipping
question: how much is a lock
  status: rejected: number 20 is not in the cited source
  answer: Not in the documents.
  sources: none
question: what is the weather today
  status: refused: no evidence
  answer: Not in the documents.
  sources: none
question: does the battery come with a guarantee
  status: ok
  answer: Frames carry a 5 year warranty. Batteries carry a 2 year warranty. [1]
  sources: warranty