papertrail/scripts/smoke/rerank-claude.ts
caelum0x ac1eb7562e docs: per-engine architecture diagrams + enable Claude reranker by default
Add docs/engine-architecture.md: a Mermaid data-flow diagram for each of the 17
vendored OSS engines (grouped verification / retrieval-research / bio-kg-nlp /
sources-screening-meta), each marking exactly where the Claude API runs vs. where
the path is deterministic, plus a Claude-usage map (engine -> route -> Claude step
-> feature). Reinforces the moat: no LLM in any numeric/verdict/scoring path.

Enable the Loki/OpenFactVerification reranker's grounded Claude relevance pass by
default on /api/retrieval/rerank (llm defaults true; pass llm:false for the pure
deterministic ranking). The numeric frame-overlap rank stays deterministic; Claude
only tags on/off-topic and every tag must ground to a verbatim source span.

Add scripts/smoke/rerank-claude.ts: a live smoke proving the Claude relevance pass
actually fires (on-topic source grounded, off-topic source rejected).
2026-07-11 04:14:33 +03:00

58 lines
2.0 KiB
TypeScript

// Live smoke: proves the Loki reranker's grounded Claude relevance pass actually
// fires at full capacity. One source is deliberately off-topic (wrong drug/outcome)
// so a real model call is needed to tag on-topic vs off-topic — a deterministic-only
// run would leave every `relevance` tag null.
//
// npx tsx -r dotenv/config scripts/smoke/rerank-claude.ts
// (loads ANTHROPIC_API_KEY from .env.local via dotenv/config)
import { rankByClaimFrame } from "../../lib/agents/contextualRank";
async function main(): Promise<void> {
const claim = "Empagliflozin reduced cardiovascular death in patients with type 2 diabetes.";
const sources = [
{
id: "empa-reg",
text:
"In the EMPA-REG OUTCOME trial, empagliflozin reduced the risk of cardiovascular " +
"death by 38% (hazard ratio 0.62, 95% CI 0.49-0.77) compared with placebo in " +
"patients with type 2 diabetes and established cardiovascular disease.",
},
{
id: "off-topic",
text:
"Atorvastatin lowered LDL cholesterol levels in a cohort of otherwise healthy " +
"adults over a 12-week period, with no cardiovascular outcomes reported.",
},
];
const result = await rankByClaimFrame(claim, sources, { llm: true });
const summary = result.ranked.map((r) => ({
id: r.id,
score: Number(r.score.toFixed(3)),
claudeOnTopic: r.relevance ? r.relevance.onTopic : null,
groundedQuote: r.relevance?.groundedQuote ?? null,
}));
// ids/counts only — no full source text dumped to logs.
process.stdout.write(
JSON.stringify(
{
frameSubject: result.frame.subject,
frameObject: result.frame.object,
droppedIds: result.droppedIds,
relevanceUngroundedCount: result.relevanceUngroundedCount,
ranked: summary,
claudeActuallyRan: summary.some((s) => s.claudeOnTopic !== null),
},
null,
2
) + "\n"
);
}
main().catch((err) => {
process.stderr.write("smoke failed: " + String(err) + "\n");
process.exit(1);
});