Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
210 lines
8.0 KiB
TypeScript
210 lines
8.0 KiB
TypeScript
// SciEval -- native TS port of MultiVerS + SciFact scientific claim verification.
|
||
//
|
||
// Faithful mapping to backend/engines/multivers:
|
||
// - data.py segments the abstract into sentences; the model scores each abstract
|
||
// sentence as a rationale candidate. We segment natively (splitAbstract) so the
|
||
// rationale space is exactly "sentences of THIS abstract".
|
||
// - model.py::decode maps the label head to {CONTRADICT, NEI, SUPPORT} and emits the
|
||
// selected rationale sentence indices. We ask Claude for the label + the rationale
|
||
// sentences (the one learned step MultiVerS trained a Longformer for), validated by Zod.
|
||
// - predict.py drops the rationale when the label is NEI. We enforce the inverse trust
|
||
// invariant too: a non-NEI label whose rationales are all ungroundable is downgraded
|
||
// to NEI -- a label we can't ground to a real abstract sentence is not asserted.
|
||
//
|
||
// Deterministic parts (segmentation, grounding, NEI logic) are native and pure; only the
|
||
// label/rationale assignment uses Claude.
|
||
|
||
import { CLAUDE_MODEL, callClaudeForJson } from "../claude";
|
||
import { locateSpan } from "../grounding";
|
||
import { retrieveSources } from "../agents/retrievalAgent";
|
||
import {
|
||
ScievalModelOutputSchema,
|
||
type GroundedRationale,
|
||
type ScievalLabel,
|
||
type ScievalOutcome,
|
||
type ScievalSourceRef,
|
||
type ScievalVerification,
|
||
} from "./schemas";
|
||
|
||
const SYSTEM = `You are a scientific claim verification model in the style of MultiVerS / SciFact.
|
||
|
||
You are given:
|
||
- CLAIM: a single scientific claim.
|
||
- ABSTRACT: the abstract of a paper, presented as a numbered list of its sentences.
|
||
|
||
Assign exactly ONE label describing how the ABSTRACT relates to the CLAIM:
|
||
- "SUPPORTS": the abstract provides evidence that the claim is true.
|
||
- "REFUTES": the abstract provides evidence that the claim is false or contradicts it.
|
||
- "NEI": not enough information; the abstract neither supports nor refutes the claim.
|
||
|
||
Then select the RATIONALE sentences: the minimal set of abstract sentences that justify your label.
|
||
Rules:
|
||
- Base the label ONLY on the ABSTRACT's content, not outside knowledge.
|
||
- For SUPPORTS or REFUTES, "rationale_sentences" MUST contain one or more sentences, each copied EXACTLY and verbatim (character-for-character) from the ABSTRACT. Do not paraphrase, merge, renumber, or add ellipses.
|
||
- For NEI, "rationale_sentences" MUST be an empty array.
|
||
- If no abstract sentence actually justifies SUPPORTS or REFUTES, label NEI instead of forcing a weak rationale.
|
||
|
||
Respond with ONLY a JSON object:
|
||
{"label": "...", "rationale_sentences": ["...", "..."], "reasoning": "..."}`;
|
||
|
||
// A sentinel that cannot occur in normal source text. splitAbstract masks the periods of
|
||
// abbreviations/decimals with it before splitting on sentence boundaries, then restores
|
||
// them -- this keeps the segmentation deterministic without a heavyweight tokenizer.
|
||
const PERIOD_SENTINEL = " |