Skip to content

TheOracle: relevance floor and explicit no-evidence path - #24

Merged
gaffercode merged 4 commits into
mainfrom
claude/project-thread-uq74yx
Nov 27, 2026
Merged

gaffercode merged 4 commits into
mainfrom
claude/project-thread-uq74yx

Conversation

@gaffercode

@gaffercode gaffercode commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Requested by Gafferness · project thread

Status: REVIEW. Floor value approved by Gaffer (0.35); merge still needs Gaffer's approval.

Problem

retrieveTheOracleGrounding always sent up to 6 top passages to the model, however low their similarity, so an off-topic case was still "grounded" on unrelated guideline text.

Change

  • New THEORACLE_MIN_SIMILARITY = 0.35 (cosine) in src/lib/theoracle-grounding.ts. It applies to case retrieval, the dose-passage swap and targeted therapy retrieval. RetrieveOptions.minSimilarity overrides it; a non-finite value falls back to the default.
  • When no case passage clears the floor, retrieval answers THEORACLE_NO_MATCH: the gateway returns 422 and makes no model call.
  • When no therapy passage clears the floor, the diagnosis is still returned, and the evidence-gate reason says no relevant therapy reference was found (instead of describing an outage).
  • Composer shows "Tidak ada bukti di Oracle" and asks the doctor to add findings. There is no "Coba lagi"; the local SOAP draft stays available.
  • benchmark:oracle gains a relevanceFloor calibration section and no longer crashes on a no-match.
  • Docs updated: docs/architecture.md, docs/testing.md. The bundle contract is unchanged.

Calibration (real index, monorepo benchmark)

Floor Off-topic passed (of 8) On-topic rejected (of 88)
0.20 5 0
0.25 2 0
0.30 0 0
0.35 0 0
0.40 0 2

Weakest on-topic best passage: 0.3725. Strongest off-topic: 0.2597. The synthetic CI index (#25) scores lower (on-topic min 0.250), so its eval must not assert the production floor.

Acceptance criteria

  1. No passage below the floor reaches the model (case, dose, therapy). ✅ tested
  2. No case passage above the floor: THEORACLE_NO_MATCH, no therapy search, no inference. ✅ tested
  3. Therapy no-match returns the diagnosis with a "not relevant enough" reason. ✅ tested
  4. The UI distinguishes no evidence from a failure and offers no pointless retry. ✅ tested
  5. Existing behaviour (cap, dose swap, privacy filter, integrity) is preserved. ✅
  6. On the real index, the floor rejects all off-topic queries and no on-topic query. ✅ (88/8 sample)

Verification

  • vitest run: 834 passed, 23 skipped (private data). 7 new tests went red to green.
  • tsc is clean. eslint shows 0 errors and the same 3 warnings as main.
  • CI is green on the previous head.

Risks

  • The on-topic margin is small (0.3725 vs 0.35), and the off-topic sample is only 8 queries. Re-run the relevanceFloor benchmark after every index rebuild, and grow the off-topic set.
  • The same change must land in the monorepo, or the next export-split overwrites it.

🤖 Generated with Claude Code

https://claude.ai/code/session_012ta9C7XhCnabM5SwJLKnmU

Retrieval sent the top passages to the model whatever their similarity,
so an off-topic case was still "grounded" on unrelated guideline text.

- THEORACLE_MIN_SIMILARITY (provisional 0.30, uncalibrated) drops every
  passage below the floor in case, dose-swap and therapy retrieval;
  nothing above it -> THEORACLE_NO_MATCH (422, no model call).
- Therapy no-match now says "no relevant therapy reference" instead of
  reporting an outage.
- Composer shows "Tidak ada bukti di Oracle" for no-match, without the
  pointless "Coba lagi"; the local SOAP draft stays available.
- benchmark:oracle gains a relevanceFloor calibration section and no
  longer crashes when a query answers no-match.
- Tests: 7 new (red before, green after); docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ta9C7XhCnabM5SwJLKnmU
@vercel

vercel Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
sentrapedia Ready Ready Preview Nov 26, 2026 10:40pm UTC

Request Review

@gaffercode gaffercode self-assigned this Nov 26, 2026
…data

The pinned model on the synthetic CI eval index scored the weakest on-topic
case at 0.250 and the strongest off-topic query at 0.146; 0.30 would have
rejected a genuine case. Still to be confirmed on the real index.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ta9C7XhCnabM5SwJLKnmU
@gaffercode
gaffercode marked this pull request as ready for review November 26, 2026 21:46
…hmark

Real index (88 on-topic, 8 off-topic queries): weakest on-topic 0.3725,
strongest off-topic 0.2597; 0.40 rejects two on-topic queries. Floor
chosen by Gaffer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ta9C7XhCnabM5SwJLKnmU
…oor off

Resolves conflicts with the UI flow changes (mismatch prompt, new warning
actions) while keeping the no-evidence notice. The synthetic eval
(tests/theoracle-eval.test.ts) now retrieves with minSimilarity -1, since
the 0.35 floor is calibrated on the real index, and asserts that on-topic
cases score above off-topic queries instead of only recording them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012ta9C7XhCnabM5SwJLKnmU
@gaffercode
gaffercode merged commit 49444a4 into main Nov 27, 2026
4 checks passed
@gaffercode
gaffercode deleted the claude/project-thread-uq74yx branch November 27, 2026 07:15
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