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.
You build: ingest.py and ask.py over six pages of Parcel Desk policy.
- Python 3.11 or newer and uv
- Ollama
- Docker
- Lab 20 done (the learn-pg container)
-
01Write six short policy pages: refunds, damage, lost parcels, international, time limits, exclusions
ls docs/*.md | wc -lYou pass when: Six files, each under 300 words, with at least one concrete number (days, amounts).
-
02Split each page into chunks and store them with their file name
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.
-
03Fetch the four closest chunks and answer only from them, naming the files
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.
-
04Ask 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.
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.
The check runs on the computer, not on your word: a step passes when its command exits with 0 there.
Computers are not set up on this site yet. Run each command on your own machine and compare with "You pass when".
Commands run in labs/21-rag and may take up to 60 seconds each. Every command starts a new shell: put keys and settings in a .env file there, it is loaded each time.