Admission/discharge comparison: pick the two stages' evidence jointly across documents

Merged
BI
1mo ago
+90-21

User description

RAG impact: behaviour change — canary pair 38383361787 -> 38419027058 (post-merge on main 039b05c5d). Retrieval: doc/content recall@5 1.0/1.0 both, 0 failed cases, zero per-case rr regressions (mrr@10 +0.019, ndcg@10 +0.004). Answer-quality subset: 41 passed / 4 failed in both runs, the same four cases (assessment-documentation, best-practice-prescribing, admission-discharge-coverage-paraphrase, clozapine-missed-dose-table); both runs are red for those pre-existing failures, so this shows no regression rather than a green result.

Follow-up to #3523, which merged before this fix was pushed.

Bug

For an admission vs discharge requirements comparison, the fallback answer needs one admission fact and one discharge fact taken from two different documents. withAdmissionDischargeSideEvidence (added in #3523) topped up each stage separately:

  • If the selected document A already had an admission fact, the admission side was skipped and the discharge side refused any chunk from A. So when A also had an eligible discharge chunk and document B had an eligible admission chunk, nothing was added, even though B (admission) + A (discharge) is a valid pair. The answer then failed closed unnecessarily.
  • Each side was capped at three chunks before checking documents, so chunks from one document could fill both caps and hide the only other document.

(Flagged by qodo on #3523: threads "Available cross-document answers fail" and "Three chunks hide a usable source".)

Fix

Search both stages together over the selected evidence plus the governed eligible candidates, and choose the admission/discharge fact pair from two different documents that needs the fewest added chunks (ties keep retrieval order). At most one chunk is added per stage. The candidate pool and the claim-support gate are unchanged, so a stage with no bound requirement still fails closed.

Tests

tests/rag-admission-discharge-comparison-fallback.test.ts: two new regression tests, both failing on the #3523 code and passing here. All 11 tests in the file pass, and lint is clean.


CodeAnt-AI Description

Restore admission/discharge comparisons using evidence from separate documents

What Changed

  • Admission/discharge comparisons can now combine supported facts from different documents, even when selected evidence already contains one stage.
  • The comparison adds only the missing evidence needed to form a cross-document pair; it still fails closed when either stage lacks a supported fact.

Impact

✅ Fewer missing admission/discharge comparisons
✅ Cross-document requirements can be compared
✅ Unsupported comparisons remain unavailable

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.