Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/lib/rag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
} from "@/lib/rag-cache";
import { buildRagSourceBlock, compactContextText } from "@/lib/rag-source-block";
export { buildRagSourceBlock, truncateForModel } from "@/lib/rag-source-block";
import { extractNumericTokens, VERIFY_AGAINST_SOURCE_NOTE, verifyAnswerNumbers } from "@/lib/answer-verification";

Check warning on line 88 in src/lib/rag.ts

View workflow job for this annotation

GitHub Actions / verify

'verifyAnswerNumbers' is defined but never used

Check warning on line 88 in src/lib/rag.ts

View workflow job for this annotation

GitHub Actions / verify

'VERIFY_AGAINST_SOURCE_NOTE' is defined but never used

Check warning on line 88 in src/lib/rag.ts

View workflow job for this annotation

GitHub Actions / verify

'extractNumericTokens' is defined but never used
import {
buildClinicalTextSearchQuery,
classifyRagQuery,
Expand All @@ -110,18 +110,18 @@
hasAdversarialManipulationIntent,
hasDirectTitleSupport,
shouldRetryWithStrongAfterFast,
appendRoutingReason,

Check warning on line 113 in src/lib/rag.ts

View workflow job for this annotation

GitHub Actions / verify

'appendRoutingReason' is defined but never used
} from "@/lib/rag-routing";
import { fetchRelatedDocumentMetadata, fetchRelatedDocuments } from "@/lib/document-enrichment";
import { boldHighYieldClinicalText, boldRagAnswerHighYieldText, rankAnswerEvidence } from "@/lib/answer-ranking";
import { applyMemoryCardBoosts, fetchMemoryCardsForQuery, ragDeepMemoryVersion } from "@/lib/deep-memory";
import {
cleanClinicalSummaryText,
fenceSourceEvidence,

Check warning on line 120 in src/lib/rag.ts

View workflow job for this annotation

GitHub Actions / verify

'fenceSourceEvidence' is defined but never used
isLowYieldClinicalText,
neutralizePromptInstructions,

Check warning on line 122 in src/lib/rag.ts

View workflow job for this annotation

GitHub Actions / verify

'neutralizePromptInstructions' is defined but never used
sourceTextForDisplay,
sourceTextForModel,

Check warning on line 124 in src/lib/rag.ts

View workflow job for this annotation

GitHub Actions / verify

'sourceTextForModel' is defined but never used
} from "@/lib/source-text-sanitizer";
import {
hasClinicalAnswerQualityIssue,
Expand Down Expand Up @@ -794,9 +794,11 @@
// chunk loader, and table-fact signal matches), not a real cosine. Those fabrications routinely
// clear the 0.82 bar (memory-card hybrid reaches 0.89, document-lookup 0.94), which let a
// lexical-only citation mint "high" confidence. Synthetic-origin evidence is therefore capped at
// "medium": "high" requires at least one cited result whose similarity is a genuine cosine.
// Ordering, routing, and coverage gates are untouched — this only stops the fabricated scale
// from masquerading as strong semantic evidence in the clinician-facing confidence label.
// "medium": "high" requires at least one cited result whose score is NOT a fabricated synthetic
// similarity. (`strongestNonSynthetic` below excludes `synthetic_text` origins but is still the
// hybrid score via scoreValue, not a pure cosine — a stricter pure-`similarity` gate would change
// behaviour and needs eval validation.) Ordering, routing, and coverage gates are untouched — this
// only stops the fabricated scale from masquerading as strong semantic evidence in the label.
export function deriveConfidence(
results: SearchResult[],
acceptedCitations: Array<Pick<Citation, "chunk_id">>,
Expand All @@ -805,11 +807,11 @@
const citedIds = new Set(acceptedCitations.map((citation) => citation.chunk_id));
const citedResults = results.filter((result) => citedIds.has(result.id));
const strongest = citedResults.reduce((max, result) => Math.max(max, scoreValue(result)), 0);
const strongestCosine = citedResults.reduce(
const strongestNonSynthetic = citedResults.reduce(
(max, result) => (result.similarity_origin === "synthetic_text" ? max : Math.max(max, scoreValue(result))),
0,
);
if (strongestCosine >= 0.82 && acceptedCitations.length >= 2) return "high";
if (strongestNonSynthetic >= 0.82 && acceptedCitations.length >= 2) return "high";
if (strongest >= 0.64) return "medium";
return "low";
}
Expand Down
3 changes: 1 addition & 2 deletions src/lib/universal-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ export type UniversalSearchResponse = {
domainOrder?: UniversalSearchDomain[];
topHit?: UniversalSearchTopHit;
answerAction?: UniversalSearchAnswerAction;
demoMode?: boolean;
publicAccess?: boolean;
// demoMode / publicAccess are attached by the route to its JSON response, not by runUniversalSearch.
};

export type RunUniversalSearchArgs = {
Expand Down
Loading