Command Palette

Search for a command to run...

Hectal
Phase 0: Start Here: What RAG Is and What You Will Build
RAG and Vector Search · Exercise 3 of 5 PreviousNext
Beginner

Build a prompt with sources

Write build_prompt(question, hits) where hits is a list of (doc_id, title, text) tuples.

Return one string with these lines, joined by \n: first Answer using only the sources. Cite the source id in square brackets., then one line per hit [<doc_id>] <title>: <text> in the given order, then Question: <question>.

What Check tests

  1. One source gives three lines
  2. Sources keep their order
  3. The question is the last line
  4. No sources still gives a valid prompt

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.