Scenario-Based AI Engineering Questions

Course Content

Scenario-Based AI Engineering Questions

26 sections · 146 lessons

Scenario – 7: Multi-Document Attribution


What you need to know

The scenario: answers combine facts from several documents, and users or auditors need to know which document supports each statement.

Build it into the index

Each chunk needs metadata that survives all the way to the answer: chunk_id, doc_id, title, version, effective date, page or section, and character offsets. Offsets are what let the UI jump to and highlight the exact passage.

Ask for structured citations

JSON
{"segments": [  {"text": "Refunds are processed within 7 business days.", "sources": ["c17"]},  {"text": "Partial refunds require manager approval.", "sources": ["c04", "c22"]}]}

Structured output makes each claim-to-source link machine-checkable, unlike free-text footnotes.

Verify every citation

Models cite plausibly but not always correctly; they often attach the nearest-looking source. Check each segment against its cited chunks:

Python
def verify(segments, chunks):    out = []    for seg in segments:        good = [cid for cid in seg["sources"] if entails(chunks[cid].text, seg["text"])]        if good:            out.append({**seg, "sources": good})        else:            alt = best_supporting_chunk(seg["text"], chunks)          # maybe it cited the wrong one            out.append({**seg, "sources": [alt] if alt else [], "unsupported": alt is None})    return out

An unverified citation is worse than none, because it turns a hallucination into an apparently sourced fact.

Practical details

  1. Deduplicate by document — do not cite five copies of the same boilerplate clause.
  2. Show conflicts — when sources disagree, group them and show both with dates.
  3. Link and highlight — each citation opens the document at the highlighted passage.
  4. Measure — citation precision and coverage on a human-labelled set.

A real-life example

Scenario, numbers made up. A procurement team's assistant answers vendor-contract questions across 3,000 contracts. Legal reviewers find that 18% of citations point to a contract that does not contain the cited clause, often a similar contract from the same vendor.

The team adds offsets and version metadata to chunks, structured per-segment citations, and an entailment check that swaps or removes bad citations. Citation precision on a 250-answer legal review rises from 82% to 97%, and coverage stays at 95%. Clickable, highlighted citations cut the time reviewers spend checking an answer from minutes to seconds, which is what finally gets the tool adopted.

Follow-up questions to expect

  • "What if a claim combines facts from two documents?" — Cite both, and check that the combination is supported; if neither source alone supports it, mark it as the model's inference.
  • "Can you trust the model's own citations for audit?" — Only after verification; store both the model's citations and the verifier's result.
  • "How do you handle scanned PDFs?" — Keep page numbers and bounding boxes from the OCR step so highlights still work.