Skip to content

< all problems79 · Level 03, RAG

Decide When Two Documents Disagree

medium · implement · RAG

Retrieval returns two notes about annual leave, one saying 25 days and one saying 26, and the assistant answers around 25 to 26 days. Old policies sit next to new ones and chat messages next to the handbook; deciding which to believe is a rule, and the rule is yours.

Each note is {"id", "text", "source", "date"}. source is "policy" (the official handbook) or "chat" (something somebody said); date is "YYYY-MM-DD". Implement three functions.

disagree(question, a, b) returns True when the two notes give different answers to the question, False when they agree or when one of them does not answer it at all. Saying the same thing in different words is agreement. This needs a model: jev.yes_no(state, statement) returns a probability, or llm.ask(prompt) can be asked for a word. One call per pair.

pick(notes) returns the note to trust, by rule, with no model call: a policy note over a chat note whatever their dates, and among the same source, the latest date.

resolve(question, notes) returns {"answer": ..., "chosen": ..., "conflict": ...}:

  • chosen: the id of the note pick trusts.
  • conflict: True if any other note disagrees with the chosen one (use disagree).
  • answer: one sentence from the chosen note only, written by the model. When there is a conflict it must say which source it is going by: a date, or the word policy or handbook.

Budget: at most one model or Jev call per other note, plus one for the answer.

The tests check properties: the right number in the answer and the wrong one absent, chosen and conflict right for five sets of notes, and the answer naming what it went by when sources conflict.