Skip to content

fix(rag): break saturated selection ties by query-term coverage, not rank score#987

Merged
BigSimmo merged 3 commits into
mainfrom
claude/clinical-kb-pwa-review-asi3wb
Jul 20, 2026
Merged

fix(rag): break saturated selection ties by query-term coverage, not rank score#987
BigSimmo merged 3 commits into
mainfrom
claude/clinical-kb-pwa-review-asi3wb

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

Verification

Risk and rollout

Clinical Governance Preflight

  • Source-backed claims still require linked source verification before clinical use
  • No patient-identifiable document workflow was introduced or expanded without explicit governance approval
  • Supabase target remains Clinical KB Database (sjrfecxgysukkwxsowpy)
  • Service-role keys and private document access remain server-only
  • Demo/synthetic content remains clearly separated from real clinical sources (new fixtures are test-only synthetic text)
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative (governance penalties in clamped keys are untouched; the tie-break cannot promote a candidate past any governance demotion)
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed (ordering-only refinement within existing retrieval behavior; no new clinical output surface)

Notes

🤖 Generated with Claude Code

https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9


Generated by Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved retrieval result ordering when candidates have identical top-level scores.
    • Prioritizes content coverage and query-term relevance in saturated ties, with stable ID ordering as a final fallback.
    • Improved fast-path results to ensure relevant threshold-related content appears in the top results.
  • Documentation

    • Added a review record documenting the fix and validation results.

claude added 2 commits July 20, 2026 11:54
…rank score

The 2026-07-20 post-merge golden run (eval-canary #50, 35/36) showed the
#982 tie-break regressing alcohol-ciwa-threshold: keying saturated ties on
the boost-laden rankScore let generic clinicalSignalBoost stacking promote
screening/monitoring chunks over the chunk containing the queried terms —
the same failure mode the clamped-score contract exists to prevent. The
tie-break key is now the clinical rank's lexicalCoverageScore (query-term
coverage, immune to boost stacking), renamed contentCoverageScore; ties on
coverage still fall back to the stable chunk-id order. The saturated-tie
contract test now pins coverage winning against a HIGHER rankScore, and
the fast-path CIWA guard adds the screening-chunk shape from run #50.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EXsJcLrbZUXwnBeG91cVo9
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The retrieval candidate tie-break changed from rank score to lexical coverage for saturated primary-score ties. Candidate types, selection tests, fast-path ordering fixtures, and the review ledger were updated to reflect and validate coverage-first ordering.

Changes

Retrieval coverage tie-break

Layer / File(s) Summary
Coverage tie-break contract
src/lib/types.ts, src/lib/retrieval-selection.ts
RetrievalCandidate now carries contentCoverageScore, sourced from lexical coverage and used as the final descending tie-break.
Saturated-tie regression tests
tests/retrieval-selection.test.ts
Tests verify coverage-first ordering and stable chunk-id ordering when coverage is identical.
Fast-path validation and ledger
tests/rag-fast-path-ordering.test.ts, docs/branch-review-ledger.md
Fast-path fixtures and assertions validate answer-bearing top-five results, while the ledger records the follow-up evaluation and correction.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • BigSimmo/Database#982: Both changes update saturated-tie retrieval ordering and its associated candidate metadata and tests.

Suggested reviewers: claude

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed It clearly summarizes the main change: using query-term coverage for saturated tie-breaking instead of rank score.
Description check ✅ Passed The description is well structured and covers summary, verification, risk, governance, and notes; the required retrieval eval is acknowledged as not run.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/clinical-kb-pwa-review-asi3wb

Comment @coderabbitai help to get the list of available commands.

@supabase

supabase Bot commented Jul 20, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@BigSimmo
BigSimmo marked this pull request as ready for review July 20, 2026 12:02
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@BigSimmo
BigSimmo merged commit 33ecd62 into main Jul 20, 2026
18 checks passed
@BigSimmo
BigSimmo deleted the claude/clinical-kb-pwa-review-asi3wb branch July 20, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants