Command Palette

Search for a command to run...

Hectal
Phase 8: Generation with Sources
RAG and Vector Search · Exercise 2 of 5 PreviousNext
Beginner

Verify citations against the retrieved sources

Write check_citations(answer, n_sources) that returns three sorted lists of ints: (cited, invalid, unused).

cited is every distinct number inside square brackets like [2]. invalid are cited numbers below 1 or above n_sources. unused are source numbers from 1 to n_sources that were never cited. Brackets with text, such as [sic], are ignored.

What Check tests

  1. Cited numbers are found and sorted
  2. Unused sources are reported
  3. A repeated marker counts once
  4. A number outside 1..N is invalid
  5. No citations at all
  6. Brackets with text are ignored

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.