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
1{"segments": [2 {"text": "Refunds are processed within 7 business days.", "sources": ["c17"]},3 {"text": "Partial refunds require manager approval.", "sources": ["c04", "c22"]}4]}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:
1def verify(segments, chunks):2 out = []3 for seg in segments:4 good = [cid for cid in seg["sources"] if entails(chunks[cid].text, seg["text"])]5 if good:6 out.append({**seg, "sources": good})7 else:8 alt = best_supporting_chunk(seg["text"], chunks) # maybe it cited the wrong one9 out.append({**seg, "sources": [alt] if alt else [], "unsupported": alt is None})10 return outAn unverified citation is worse than none, because it turns a hallucination into an apparently sourced fact.
Practical details
- Deduplicate by document — do not cite five copies of the same boilerplate clause.
- Show conflicts — when sources disagree, group them and show both with dates.
- Link and highlight — each citation opens the document at the highlighted passage.
- 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.