Skip to content

Fix clinical-subject dose retrieval#571

Merged
BigSimmo merged 2 commits into
mainfrom
codex/opioid-dose-retrieval-gate
Jul 13, 2026
Merged

Fix clinical-subject dose retrieval#571
BigSimmo merged 2 commits into
mainfrom
codex/opioid-dose-retrieval-gate

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

Summary

  • require dose evidence to carry the question's clinical subject before the fast path can be accepted
  • treat dose-only questions separately from route questions and recognise plural dose wording
  • include the clinical subject in medication-dose retrieval selection so unrelated numeric tables cannot outrank subject-matched guidance
  • add focused regression coverage for entity-crossing evidence, route handling, ranking, and selection

Verification

  • npx vitest run tests/smart-rag-api.test.ts tests/retrieval-query-variants.test.ts tests/retrieval-selection.test.ts tests/clinical-search.test.ts tests/eval-search.test.ts (122 passed)
  • npm run eval:rag:offline (21 files, 265 tests passed)
  • npm run verify:cheap (210 files passed, 1 skipped; 1,934 tests passed, 1 skipped)
  • live production-corpus case opioid-withdrawal-doses: document recall 1.0, content recall 1.0, nDCG@10 0.9912, irrelevant-source rate 0, required-signal coverage 1.0

Safety

  • no dependency or schema changes in this PR
  • production ranking weights are unchanged; the new signal is scoped to explicit medication dose/route/frequency queries
  • no secret values are printed or committed

@supabase

supabase Bot commented Jul 13, 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 enabled auto-merge (squash) July 13, 2026 09:56
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e55ac631-1d81-430e-959e-cf966aaa196c

📥 Commits

Reviewing files that changed from the base of the PR and between cc6bfc1 and b8c5cb7.

📒 Files selected for processing (4)
  • src/lib/clinical-search.ts
  • src/lib/rag.ts
  • src/lib/retrieval-selection.ts
  • tests/retrieval-query-variants.test.ts

📝 Walkthrough

Summary by CodeRabbit

  • Improvements
    • Improved medication dose and risk search results by matching evidence to the specific medication or clinical subject in the query.
    • Prioritized dose information associated with the requested medication over unrelated numeric dosage content.
    • Refined route and frequency handling so only relevant evidence is required for each question.
    • Reduced the chance of accepting dose or route information from an unrelated medication context.

Walkthrough

Medication dose and risk retrieval now extracts clinical-subject terms, matches them against evidence, adjusts ranking, and requires contextual dose or route support in coverage gating. Tests cover co-located evidence, unrelated medication contexts, and subject-aware result ranking.

Changes

Medication dose context

Layer / File(s) Summary
Subject context and scoring
src/lib/clinical-search.ts
Adds subject-token extraction and query-result context matching, then applies matching boosts or mismatch penalties to clinical ranking.
Retrieval subject selection
src/lib/retrieval-selection.ts
Expands dose/route detection, adds conditional clinical_subject signals, and boosts candidates with matching clinical context.
Contextual coverage gate and validation
src/lib/rag.ts, tests/retrieval-query-variants.test.ts
Requires contextual dose and route evidence where applicable and tests matching, entity isolation, and ranking behavior.

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

Sequence Diagram(s)

sequenceDiagram
  participant Query
  participant RetrievalSelection
  participant ClinicalSearch
  participant RAGCoverageGate
  participant Evidence
  Query->>RetrievalSelection: build medication dose retrieval intent
  RetrievalSelection->>ClinicalSearch: match clinical subject against Evidence
  ClinicalSearch-->>RetrievalSelection: return subject signal and score adjustment
  RetrievalSelection->>RAGCoverageGate: evaluate selected evidence
  RAGCoverageGate->>ClinicalSearch: check contextual dose and route match
  ClinicalSearch->>Evidence: inspect extracted evidence text
  Evidence-->>RAGCoverageGate: return contextual match status
  RAGCoverageGate-->>Query: accept or reject evidence
Loading
✨ 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 codex/opioid-dose-retrieval-gate
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch codex/opioid-dose-retrieval-gate

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

@BigSimmo
BigSimmo merged commit cd25178 into main Jul 13, 2026
14 of 15 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8c5cb785e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib/rag.ts
@BigSimmo
BigSimmo deleted the codex/opioid-dose-retrieval-gate branch July 13, 2026 16:33
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.

1 participant