knowledge · intermediate · 45 min

Answer from your documents, with sources

Build a question answerer that reads your own documents, names the file each answer came from, and says so when the answer is not there.

HANDS-ON LAB · YOU RUN IT ON YOUR MACHINE · 4 STEPS
  1. Step 1 of 4

    Write six short policy pages: refunds, damage, lost parcels, international, time limits, exclusions

    Run this to check

    ls docs/*.md | wc -l

    You pass when

    Six files, each under 300 words, with at least one concrete number (days, amounts).

    Files you write

    • docs/
  2. Step 2 of 4

    Split each page into chunks and store them with their file name

    Run this to check

    uv run --with requests --with "psycopg[binary]" ingest.py docs/

    You pass when

    It prints how many chunks it stored per file. Running it twice does not double the rows.

    Files you write

    • ingest.py
  3. Step 3 of 4

    Fetch the four closest chunks and answer only from them, naming the files

    Run this to check

    uv run --with openai --with requests --with "psycopg[binary]" ask.py "How many days do I have to report a damaged parcel?"

    You pass when

    The number from your damage page, followed by the file name it came from.

    Files you write

    • ask.py
  4. Step 4 of 4

    Ask something the pages do not cover

    An answerer that guesses is worse than no answerer. This refusal is the most important line in your prompt.

    Run this to check

    uv run --with openai --with requests --with "psycopg[binary]" ask.py "Do you ship live animals to Mars?"

    You pass when

    It says the documents do not cover this. It does not make up a policy.

    Files you write

    • ask.py
No transcript here on purpose. This page does not show terminal output, because model answers differ from run to run. Each step says what a pass looks like; your own terminal is the proof.