Skip to content

fix(rag): eliminate source-backed latency tails#845

Closed
BigSimmo wants to merge 5 commits into
mainfrom
codex/rag-tree4-main-fixes
Closed

fix(rag): eliminate source-backed latency tails#845
BigSimmo wants to merge 5 commits into
mainfrom
codex/rag-tree4-main-fixes

Conversation

@BigSimmo

@BigSimmo BigSimmo commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Apply focused RAG retrieval + answer-generation hardening for two high-impact edge paths:
    • Improve agitation/medication query intent handling in text-search expansion.
    • Skip an unnecessary source-backed fast-path tail for strict generic LAI management queries when deterministic evidence gates already pass.
  • No schema, routing, or feature-scope changes outside retrieval behavior.

Verification

  • git diff --check (pass)
  • npm run verify:pr-local (not run: local dependencies are not installed in this worktree; node_modules/vitest/vitest.mjs missing. Re-run once dependencies are installed.)
  • Verification not run: npm run eval:retrieval:quality (provider/API-required and blocked in this environment without confirmed live credentials)
  • npm run check:production-readiness (not run: no runtime/provider-only production checks requested for this handoff)

Risk and rollout

  • Risk: medium; this expands retrieval fallback terms for agitation-medication paths and may affect low-signal, atypical phrasing.
  • Rollback: revert this PR or revert the two commits if behavior regresses.

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
  • Source metadata, review status, and outdated/unknown-source behavior remain conservative
  • Deployment classification/TGA SaMD impact was checked when clinical decision-support behavior changed

Notes

Summary by CodeRabbit

  • Bug Fixes
    • Improved clinical search results for agitation and arousal medication questions, including dose, route, frequency, and medication-chart requests.
    • Added more relevant fallback terms when medication details are not explicitly specified.
    • Improved internal diagnostics for validated routine recovery responses.

BigSimmo added 2 commits July 18, 2026 18:52
Keep broad agitation retrieval on one lexical RPC, bypass the repeated LAI model timeout only after deterministic quality validation, and align the single-source safety-plan canary with its required source contract.\n\nVerified with the offline RAG contract (21 files, 272 tests) and focused live read-only evaluations.
@supabase

supabase Bot commented Jul 18, 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 ↗︎.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: bbf62ee4-8536-4390-aac0-658d55f357fa

📥 Commits

Reviewing files that changed from the base of the PR and between 53c9902 and 9d6f3c9.

📒 Files selected for processing (1)
  • src/lib/clinical-search.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lib/clinical-search.ts

📝 Walkthrough

Walkthrough

Clinical search recognizes broader medication-chart requests and uses fallback medication vocabulary when explicit dose or route terms are absent. Routine extractive recovery records a specific route reason, while generic LAI-management matching remains unchanged.

Changes

Medication-chart search expansion

Layer / File(s) Summary
Medication-chart intent and token assembly
src/lib/clinical-search.ts
Medication-chart detection accepts broader corrected-query patterns, and the agitation/arousal branch uses explicit evidence terms or a default medication-chart vocabulary.

Extractive recovery route tagging

Layer / File(s) Summary
Recovery route diagnostics
src/lib/rag.ts
Routine extractive recovery appends validated_routine_extractive_recovery to its route reason; generic LAI-management detection retains its existing regex gate.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • BigSimmo/Database#581: Adds related dose, route, and frequency intent detection used in medication evidence handling.
  • BigSimmo/Database#666: Updates the same clinical-search medication-chart intent and token-splicing path.
  • BigSimmo/Database#668: Modifies related agitation/arousal medication-chart detection and evidence-term expansion.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the PR's main retrieval hardening change and clearly mentions the latency-tail removal.
Description check ✅ Passed The description covers summary, verification, risk/rollback, and governance sections, with only minor template details omitted.
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.
✨ 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/rag-tree4-main-fixes

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

@github-actions

github-actions Bot commented Jul 18, 2026

Copy link
Copy Markdown

CI triage

CI failed on this PR. Automated classification of the 2 failed job(s):

  • Unit coverageneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.
  • PR requiredneeds investigation: inspect the failing step and uploaded diagnostics; rerun only after classifying the cause.

Compared with main CI run #3269 (success).

Classification is evidence routing, not permission to ignore a failure. Exact quarantined Playwright identities remain governed by the flake ledger.

@BigSimmo
BigSimmo enabled auto-merge July 18, 2026 12:37
@BigSimmo BigSimmo closed this Jul 18, 2026
auto-merge was automatically disabled July 18, 2026 13:01

Pull request was closed

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