Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 0.7 — Build: The Corpus and a First Answer
RAG and Vector Search · Example 1 of 1

AskDocs v0: retrieve, prompt, answer or refuse

The whole product as it stands after Phase 0. Each later phase's Build topic replaces the inside of retrieve() and keeps everything else.

AskDocs version 0: the twelve-passage handbook as typed documents, a retrieve function behind a fixed interface, a prompt builder, a stand-in model and a refusal. It answers, cites, refuses, and still gets the login question wrong.

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 5 hands-on exercises with automatic checks.

Practice questions

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

01

Add a function explain_answer(question) that returns the list of (doc_id, score) for every passage scoring at least 1, so a developer can see the near misses below the bar. Print it for the login question.

02

Change build_prompt so sources are numbered [1], [2], … and print a mapping from number to doc id beneath the prompt. When is numbering better than raw ids?

Explain it without notes

01

What does retrieve(question, k) return, and why is it important that its shape stays fixed?

02

Why does version 0 refuse in code instead of asking the model?

03

Explain the trace for "What does the monthly pass cost?". Why is D10 included, and is that a problem?

04

What are the three biggest weaknesses of version 0, and which phase fixes each?

AskDocs v0: retrieve, prompt, answer or refuse
Sign in to run this example in your browser.

Expected output

Q: What does the monthly pass cost?
   sources: D8 (3), D10 (2)
   answer:  The monthly pass costs 25 dollars and includes unlimited rides of up to 45 minutes. [D8]
Q: When do shops close on public holidays?
   sources: D2 (5)
   answer:  Shops open at 7 am and close at 9 pm every day. [D2]
Q: I forgot my login, how do I get back in?
   sources: D1 (2), D10 (2)
   answer:  A ride cancelled at least 2 hours before its start time is refunded in full. [D1]
Q: Do you rent scooters?
   sources: none
   answer:  I can't find that in the handbook.