transparent-confidence 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE +183 -0
- package/README.md +537 -0
- package/dist/index.cjs +561 -0
- package/dist/index.d.cts +256 -0
- package/dist/index.d.ts +256 -0
- package/dist/index.js +533 -0
- package/package.json +60 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single retrieved chunk/section from the RAG pipeline.
|
|
3
|
+
* Pass all candidates that were used to generate the answer.
|
|
4
|
+
*/
|
|
5
|
+
interface Candidate {
|
|
6
|
+
/**
|
|
7
|
+
* Scores from each retrieval method that found this candidate.
|
|
8
|
+
* Keys are user-defined method names (e.g. "semantic", "keyword", "graph").
|
|
9
|
+
* A candidate is counted as "confirmed" when 2+ methods have score > 0.
|
|
10
|
+
*/
|
|
11
|
+
retrievalScores: Record<string, number>;
|
|
12
|
+
/**
|
|
13
|
+
* Final combined relevance score after any fusion/re-ranking. Range 0–1.
|
|
14
|
+
* Used for magnitude scoring and variance calculation.
|
|
15
|
+
*/
|
|
16
|
+
combinedScore: number;
|
|
17
|
+
/** Unique identifier for the source document this chunk came from. */
|
|
18
|
+
documentId?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Human-readable document type (e.g. "CC&Rs", "policy", "handbook").
|
|
21
|
+
* Used for authority rank inference when authorityRank is not provided.
|
|
22
|
+
*/
|
|
23
|
+
documentType?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Numeric authority rank for this document. Lower = higher authority.
|
|
26
|
+
* Maps to user-defined AuthorityTier ranks in ScoringConfig.authority.
|
|
27
|
+
* Required for accurate Authority extension scoring.
|
|
28
|
+
*/
|
|
29
|
+
authorityRank?: number;
|
|
30
|
+
/**
|
|
31
|
+
* True if this chunk comes from an amendment to another document.
|
|
32
|
+
* When present, the amended version controls over original language.
|
|
33
|
+
*/
|
|
34
|
+
isAmendment?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Quality of source content extraction. Range 0–1.
|
|
37
|
+
* Applies as a multiplier on combinedScore in the magnitude sub-signal.
|
|
38
|
+
* Use when documents were OCR'd, scraped, or otherwise imperfectly extracted.
|
|
39
|
+
*/
|
|
40
|
+
extractionQuality?: number;
|
|
41
|
+
/**
|
|
42
|
+
* When this document was last updated. Required for Freshness extension.
|
|
43
|
+
* Scoring uses the median lastUpdated across all candidates.
|
|
44
|
+
*/
|
|
45
|
+
lastUpdated?: Date;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* All inputs required to compute a confidence scorecard.
|
|
49
|
+
* Fields marked required must always be provided.
|
|
50
|
+
* All other fields are optional enhanced signals — provide what your pipeline has.
|
|
51
|
+
*/
|
|
52
|
+
interface ScoringInputs {
|
|
53
|
+
/** The LLM's self-assessed confidence in its answer. Required. */
|
|
54
|
+
confidenceLevel: 'high' | 'medium' | 'low';
|
|
55
|
+
/**
|
|
56
|
+
* Free-text description of ambiguity in the source documents.
|
|
57
|
+
* Set to null if confidenceLevel is high and no ambiguity exists.
|
|
58
|
+
*/
|
|
59
|
+
ambiguityNotes?: string | null;
|
|
60
|
+
/** True if the LLM flagged that expert/legal review is recommended. */
|
|
61
|
+
requiresExpertReview?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Note about external laws, regulations, or standards not in the corpus
|
|
64
|
+
* that may affect the answer (e.g. "State statute may impose requirements").
|
|
65
|
+
*/
|
|
66
|
+
externalConstraintNote?: string | null;
|
|
67
|
+
/**
|
|
68
|
+
* True when the corpus contains no content addressing the question.
|
|
69
|
+
* When true, Grounding scores 0 and all other Grounding logic is skipped.
|
|
70
|
+
*/
|
|
71
|
+
documentsSilent?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* True when the LLM detected conflicting information across retrieved sections.
|
|
74
|
+
* Use conflictingCandidateCount for a more precise penalty when count is known.
|
|
75
|
+
*/
|
|
76
|
+
hasConflict?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* How many of the provided candidates contain conflicting information.
|
|
79
|
+
* More precise than the boolean hasConflict. When provided, hasConflict is ignored.
|
|
80
|
+
*/
|
|
81
|
+
conflictingCandidateCount?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Structural complexity of the question being answered.
|
|
84
|
+
* Applies a ceiling on the Grounding score — complex questions cannot
|
|
85
|
+
* score as high even with perfect retrieval.
|
|
86
|
+
*/
|
|
87
|
+
queryComplexity?: 'direct' | 'inferential' | 'multi-hop' | 'comparative';
|
|
88
|
+
/**
|
|
89
|
+
* External faithfulness evaluation score. Range 0–1.
|
|
90
|
+
* Measures whether the answer stays within what the retrieved content supports.
|
|
91
|
+
* Produced by frameworks like RAGAS, TruLens, or DeepEval.
|
|
92
|
+
* When provided, acts as a significant modifier on the Grounding score.
|
|
93
|
+
*/
|
|
94
|
+
faithfulnessScore?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Number of retrieved sections explicitly cited in the answer.
|
|
97
|
+
* Rewards answers that demonstrate grounding in specific retrieved content.
|
|
98
|
+
* Requires structured LLM output that tracks citations.
|
|
99
|
+
*/
|
|
100
|
+
citationCount?: number;
|
|
101
|
+
/**
|
|
102
|
+
* All candidate chunks/sections used to generate the answer. Required.
|
|
103
|
+
* Include all candidates passed to the LLM context, not just the top result.
|
|
104
|
+
* An empty array is valid and scores 0 on retrieval-dependent dimensions.
|
|
105
|
+
*/
|
|
106
|
+
candidates: Candidate[];
|
|
107
|
+
/**
|
|
108
|
+
* How many distinct document types are currently loaded in the corpus.
|
|
109
|
+
* Required when config.corpus is active. Ignored otherwise.
|
|
110
|
+
*/
|
|
111
|
+
corpusDocCount?: number;
|
|
112
|
+
/**
|
|
113
|
+
* True when the document type most relevant to this question is not in the corpus.
|
|
114
|
+
* Applies a penalty to the Corpus Completeness score.
|
|
115
|
+
*/
|
|
116
|
+
missingRelevantType?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A single authority tier in a user-defined document hierarchy.
|
|
120
|
+
* Lower rank numbers = higher authority.
|
|
121
|
+
*/
|
|
122
|
+
interface AuthorityTier {
|
|
123
|
+
/** Display name for this tier (e.g. "Declaration", "Policy", "Guideline"). */
|
|
124
|
+
name: string;
|
|
125
|
+
/**
|
|
126
|
+
* Numeric authority rank. Lower = higher authority.
|
|
127
|
+
* Recommended convention: 10 = primary, 20 = secondary, 30 = supporting.
|
|
128
|
+
*/
|
|
129
|
+
rank: number;
|
|
130
|
+
/**
|
|
131
|
+
* Substrings to match against Candidate.documentType for automatic rank inference.
|
|
132
|
+
* Case-insensitive. Matched when authorityRank is not directly provided.
|
|
133
|
+
*/
|
|
134
|
+
keywords?: string[];
|
|
135
|
+
}
|
|
136
|
+
/** Configuration for the Document Freshness extension. */
|
|
137
|
+
interface FreshnessConfig {
|
|
138
|
+
/** Documents updated within this many days receive the full freshness score. Default: 90. */
|
|
139
|
+
maxAgeForFullScore?: number;
|
|
140
|
+
/** Points deducted per 30-day period beyond maxAgeForFullScore. Default: 1.5. */
|
|
141
|
+
penaltyPerMonth?: number;
|
|
142
|
+
/** Documents older than this many days score 0 for freshness. Default: 730. */
|
|
143
|
+
hardCutoffAge?: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Optional extensions that add domain-specific dimensions to the scorecard.
|
|
147
|
+
* Each active extension adds weight to the total and is renormalized to 0–100.
|
|
148
|
+
* All extensions are opt-in — omit any you do not need.
|
|
149
|
+
*/
|
|
150
|
+
interface ScoringConfig {
|
|
151
|
+
/**
|
|
152
|
+
* Source Authority extension (+20 pts to maxPossible).
|
|
153
|
+
* Scores how authoritative the source documents are based on a user-defined hierarchy.
|
|
154
|
+
* Omit tiers to use the default 3-tier generic hierarchy (ranks 10, 20, 30).
|
|
155
|
+
*/
|
|
156
|
+
authority?: {
|
|
157
|
+
tiers?: AuthorityTier[];
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Corpus Completeness extension (+15 pts to maxPossible).
|
|
161
|
+
* Scores how complete the knowledge base is relative to its expected composition.
|
|
162
|
+
* Requires corpusDocCount in ScoringInputs.
|
|
163
|
+
*/
|
|
164
|
+
corpus?: {
|
|
165
|
+
/** Total number of distinct document types expected in a complete corpus. */
|
|
166
|
+
expectedDocCount: number;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Document Freshness extension (+15 pts to maxPossible).
|
|
170
|
+
* Scores how current the source documents are.
|
|
171
|
+
* Requires lastUpdated on at least one Candidate.
|
|
172
|
+
*/
|
|
173
|
+
freshness?: FreshnessConfig;
|
|
174
|
+
}
|
|
175
|
+
/** Score breakdown for a single dimension. */
|
|
176
|
+
interface DimensionScore {
|
|
177
|
+
/** Raw points earned before normalization. */
|
|
178
|
+
raw: number;
|
|
179
|
+
/** Maximum raw points possible for this dimension. */
|
|
180
|
+
max: number;
|
|
181
|
+
/** Dimension score normalized to 0–100 independently. */
|
|
182
|
+
normalized: number;
|
|
183
|
+
/** Human-readable explanation of why this score was assigned. */
|
|
184
|
+
explanation: string;
|
|
185
|
+
}
|
|
186
|
+
/** Tier 1 — Answer Confidence display (Grounding + Retrieval + Consistency + Authority). */
|
|
187
|
+
interface Tier1Result {
|
|
188
|
+
/** Normalized 0–100 score for answer quality dimensions. */
|
|
189
|
+
score: number;
|
|
190
|
+
label: 'Strong' | 'Moderate' | 'Limited' | 'Insufficient' | 'Not Addressed';
|
|
191
|
+
color: 'green' | 'amber' | 'orange' | 'red' | 'gray';
|
|
192
|
+
}
|
|
193
|
+
/** Tier 2 — System Readiness display (Corpus + Freshness). Null when no system extensions active. */
|
|
194
|
+
interface Tier2Result {
|
|
195
|
+
/** Normalized 0–100 score for system health dimensions. */
|
|
196
|
+
score: number;
|
|
197
|
+
label: 'Complete' | 'Good' | 'Partial' | 'Thin';
|
|
198
|
+
color: 'green' | 'amber' | 'orange' | 'red';
|
|
199
|
+
}
|
|
200
|
+
/** The complete confidence scorecard returned by computeConfidence. */
|
|
201
|
+
interface ConfidenceScorecard {
|
|
202
|
+
/** Final normalized confidence score. Integer in range 0–100. */
|
|
203
|
+
total: number;
|
|
204
|
+
/** Composite label derived from total score. */
|
|
205
|
+
label: 'Strong' | 'Moderate' | 'Limited' | 'Insufficient';
|
|
206
|
+
/** Color token for the composite label. */
|
|
207
|
+
labelColor: 'green' | 'amber' | 'orange' | 'red';
|
|
208
|
+
/**
|
|
209
|
+
* Tier 1: Answer Confidence.
|
|
210
|
+
* Combines Grounding, Retrieval, Consistency, and Authority (if active).
|
|
211
|
+
* Null only when documentsSilent is true and no candidates were provided.
|
|
212
|
+
*/
|
|
213
|
+
tier1: Tier1Result | null;
|
|
214
|
+
/**
|
|
215
|
+
* Tier 2: System Readiness.
|
|
216
|
+
* Combines Corpus and Freshness (if active).
|
|
217
|
+
* Null when neither Corpus nor Freshness extension is configured.
|
|
218
|
+
*/
|
|
219
|
+
tier2: Tier2Result | null;
|
|
220
|
+
/** Per-dimension breakdown. Optional dimensions present only when their extension is active. */
|
|
221
|
+
dimensions: {
|
|
222
|
+
grounding: DimensionScore;
|
|
223
|
+
retrieval: DimensionScore;
|
|
224
|
+
consistency: DimensionScore;
|
|
225
|
+
authority?: DimensionScore;
|
|
226
|
+
corpus?: DimensionScore;
|
|
227
|
+
freshness?: DimensionScore;
|
|
228
|
+
};
|
|
229
|
+
/** Internal scoring metadata for debugging and transparency. */
|
|
230
|
+
meta: {
|
|
231
|
+
/** Sum of all dimension raw scores before normalization. */
|
|
232
|
+
rawTotal: number;
|
|
233
|
+
/** Maximum possible raw score based on active extensions. */
|
|
234
|
+
maxPossible: number;
|
|
235
|
+
/** Names of active optional extensions, e.g. ["authority", "freshness"]. */
|
|
236
|
+
activeExtensions: string[];
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Computes a structured confidence scorecard for a RAG answer.
|
|
242
|
+
*
|
|
243
|
+
* Always scores the three core dimensions (grounding, retrieval, consistency).
|
|
244
|
+
* Optional extensions are activated by passing the corresponding config key.
|
|
245
|
+
* The total is always normalized to 0–100 regardless of which extensions are active.
|
|
246
|
+
*/
|
|
247
|
+
declare function computeConfidence(inputs: ScoringInputs, config?: ScoringConfig): ConfidenceScorecard;
|
|
248
|
+
/**
|
|
249
|
+
* Creates a pre-configured scorer bound to the given config.
|
|
250
|
+
* Useful when scoring many answers against the same corpus setup.
|
|
251
|
+
*/
|
|
252
|
+
declare function createScorer(config: ScoringConfig): {
|
|
253
|
+
compute: (inputs: ScoringInputs) => ConfidenceScorecard;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export { type AuthorityTier, type Candidate, type ConfidenceScorecard, type DimensionScore, type FreshnessConfig, type ScoringConfig, type ScoringInputs, type Tier1Result, type Tier2Result, computeConfidence, createScorer };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single retrieved chunk/section from the RAG pipeline.
|
|
3
|
+
* Pass all candidates that were used to generate the answer.
|
|
4
|
+
*/
|
|
5
|
+
interface Candidate {
|
|
6
|
+
/**
|
|
7
|
+
* Scores from each retrieval method that found this candidate.
|
|
8
|
+
* Keys are user-defined method names (e.g. "semantic", "keyword", "graph").
|
|
9
|
+
* A candidate is counted as "confirmed" when 2+ methods have score > 0.
|
|
10
|
+
*/
|
|
11
|
+
retrievalScores: Record<string, number>;
|
|
12
|
+
/**
|
|
13
|
+
* Final combined relevance score after any fusion/re-ranking. Range 0–1.
|
|
14
|
+
* Used for magnitude scoring and variance calculation.
|
|
15
|
+
*/
|
|
16
|
+
combinedScore: number;
|
|
17
|
+
/** Unique identifier for the source document this chunk came from. */
|
|
18
|
+
documentId?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Human-readable document type (e.g. "CC&Rs", "policy", "handbook").
|
|
21
|
+
* Used for authority rank inference when authorityRank is not provided.
|
|
22
|
+
*/
|
|
23
|
+
documentType?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Numeric authority rank for this document. Lower = higher authority.
|
|
26
|
+
* Maps to user-defined AuthorityTier ranks in ScoringConfig.authority.
|
|
27
|
+
* Required for accurate Authority extension scoring.
|
|
28
|
+
*/
|
|
29
|
+
authorityRank?: number;
|
|
30
|
+
/**
|
|
31
|
+
* True if this chunk comes from an amendment to another document.
|
|
32
|
+
* When present, the amended version controls over original language.
|
|
33
|
+
*/
|
|
34
|
+
isAmendment?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Quality of source content extraction. Range 0–1.
|
|
37
|
+
* Applies as a multiplier on combinedScore in the magnitude sub-signal.
|
|
38
|
+
* Use when documents were OCR'd, scraped, or otherwise imperfectly extracted.
|
|
39
|
+
*/
|
|
40
|
+
extractionQuality?: number;
|
|
41
|
+
/**
|
|
42
|
+
* When this document was last updated. Required for Freshness extension.
|
|
43
|
+
* Scoring uses the median lastUpdated across all candidates.
|
|
44
|
+
*/
|
|
45
|
+
lastUpdated?: Date;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* All inputs required to compute a confidence scorecard.
|
|
49
|
+
* Fields marked required must always be provided.
|
|
50
|
+
* All other fields are optional enhanced signals — provide what your pipeline has.
|
|
51
|
+
*/
|
|
52
|
+
interface ScoringInputs {
|
|
53
|
+
/** The LLM's self-assessed confidence in its answer. Required. */
|
|
54
|
+
confidenceLevel: 'high' | 'medium' | 'low';
|
|
55
|
+
/**
|
|
56
|
+
* Free-text description of ambiguity in the source documents.
|
|
57
|
+
* Set to null if confidenceLevel is high and no ambiguity exists.
|
|
58
|
+
*/
|
|
59
|
+
ambiguityNotes?: string | null;
|
|
60
|
+
/** True if the LLM flagged that expert/legal review is recommended. */
|
|
61
|
+
requiresExpertReview?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Note about external laws, regulations, or standards not in the corpus
|
|
64
|
+
* that may affect the answer (e.g. "State statute may impose requirements").
|
|
65
|
+
*/
|
|
66
|
+
externalConstraintNote?: string | null;
|
|
67
|
+
/**
|
|
68
|
+
* True when the corpus contains no content addressing the question.
|
|
69
|
+
* When true, Grounding scores 0 and all other Grounding logic is skipped.
|
|
70
|
+
*/
|
|
71
|
+
documentsSilent?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* True when the LLM detected conflicting information across retrieved sections.
|
|
74
|
+
* Use conflictingCandidateCount for a more precise penalty when count is known.
|
|
75
|
+
*/
|
|
76
|
+
hasConflict?: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* How many of the provided candidates contain conflicting information.
|
|
79
|
+
* More precise than the boolean hasConflict. When provided, hasConflict is ignored.
|
|
80
|
+
*/
|
|
81
|
+
conflictingCandidateCount?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Structural complexity of the question being answered.
|
|
84
|
+
* Applies a ceiling on the Grounding score — complex questions cannot
|
|
85
|
+
* score as high even with perfect retrieval.
|
|
86
|
+
*/
|
|
87
|
+
queryComplexity?: 'direct' | 'inferential' | 'multi-hop' | 'comparative';
|
|
88
|
+
/**
|
|
89
|
+
* External faithfulness evaluation score. Range 0–1.
|
|
90
|
+
* Measures whether the answer stays within what the retrieved content supports.
|
|
91
|
+
* Produced by frameworks like RAGAS, TruLens, or DeepEval.
|
|
92
|
+
* When provided, acts as a significant modifier on the Grounding score.
|
|
93
|
+
*/
|
|
94
|
+
faithfulnessScore?: number;
|
|
95
|
+
/**
|
|
96
|
+
* Number of retrieved sections explicitly cited in the answer.
|
|
97
|
+
* Rewards answers that demonstrate grounding in specific retrieved content.
|
|
98
|
+
* Requires structured LLM output that tracks citations.
|
|
99
|
+
*/
|
|
100
|
+
citationCount?: number;
|
|
101
|
+
/**
|
|
102
|
+
* All candidate chunks/sections used to generate the answer. Required.
|
|
103
|
+
* Include all candidates passed to the LLM context, not just the top result.
|
|
104
|
+
* An empty array is valid and scores 0 on retrieval-dependent dimensions.
|
|
105
|
+
*/
|
|
106
|
+
candidates: Candidate[];
|
|
107
|
+
/**
|
|
108
|
+
* How many distinct document types are currently loaded in the corpus.
|
|
109
|
+
* Required when config.corpus is active. Ignored otherwise.
|
|
110
|
+
*/
|
|
111
|
+
corpusDocCount?: number;
|
|
112
|
+
/**
|
|
113
|
+
* True when the document type most relevant to this question is not in the corpus.
|
|
114
|
+
* Applies a penalty to the Corpus Completeness score.
|
|
115
|
+
*/
|
|
116
|
+
missingRelevantType?: boolean;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* A single authority tier in a user-defined document hierarchy.
|
|
120
|
+
* Lower rank numbers = higher authority.
|
|
121
|
+
*/
|
|
122
|
+
interface AuthorityTier {
|
|
123
|
+
/** Display name for this tier (e.g. "Declaration", "Policy", "Guideline"). */
|
|
124
|
+
name: string;
|
|
125
|
+
/**
|
|
126
|
+
* Numeric authority rank. Lower = higher authority.
|
|
127
|
+
* Recommended convention: 10 = primary, 20 = secondary, 30 = supporting.
|
|
128
|
+
*/
|
|
129
|
+
rank: number;
|
|
130
|
+
/**
|
|
131
|
+
* Substrings to match against Candidate.documentType for automatic rank inference.
|
|
132
|
+
* Case-insensitive. Matched when authorityRank is not directly provided.
|
|
133
|
+
*/
|
|
134
|
+
keywords?: string[];
|
|
135
|
+
}
|
|
136
|
+
/** Configuration for the Document Freshness extension. */
|
|
137
|
+
interface FreshnessConfig {
|
|
138
|
+
/** Documents updated within this many days receive the full freshness score. Default: 90. */
|
|
139
|
+
maxAgeForFullScore?: number;
|
|
140
|
+
/** Points deducted per 30-day period beyond maxAgeForFullScore. Default: 1.5. */
|
|
141
|
+
penaltyPerMonth?: number;
|
|
142
|
+
/** Documents older than this many days score 0 for freshness. Default: 730. */
|
|
143
|
+
hardCutoffAge?: number;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Optional extensions that add domain-specific dimensions to the scorecard.
|
|
147
|
+
* Each active extension adds weight to the total and is renormalized to 0–100.
|
|
148
|
+
* All extensions are opt-in — omit any you do not need.
|
|
149
|
+
*/
|
|
150
|
+
interface ScoringConfig {
|
|
151
|
+
/**
|
|
152
|
+
* Source Authority extension (+20 pts to maxPossible).
|
|
153
|
+
* Scores how authoritative the source documents are based on a user-defined hierarchy.
|
|
154
|
+
* Omit tiers to use the default 3-tier generic hierarchy (ranks 10, 20, 30).
|
|
155
|
+
*/
|
|
156
|
+
authority?: {
|
|
157
|
+
tiers?: AuthorityTier[];
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Corpus Completeness extension (+15 pts to maxPossible).
|
|
161
|
+
* Scores how complete the knowledge base is relative to its expected composition.
|
|
162
|
+
* Requires corpusDocCount in ScoringInputs.
|
|
163
|
+
*/
|
|
164
|
+
corpus?: {
|
|
165
|
+
/** Total number of distinct document types expected in a complete corpus. */
|
|
166
|
+
expectedDocCount: number;
|
|
167
|
+
};
|
|
168
|
+
/**
|
|
169
|
+
* Document Freshness extension (+15 pts to maxPossible).
|
|
170
|
+
* Scores how current the source documents are.
|
|
171
|
+
* Requires lastUpdated on at least one Candidate.
|
|
172
|
+
*/
|
|
173
|
+
freshness?: FreshnessConfig;
|
|
174
|
+
}
|
|
175
|
+
/** Score breakdown for a single dimension. */
|
|
176
|
+
interface DimensionScore {
|
|
177
|
+
/** Raw points earned before normalization. */
|
|
178
|
+
raw: number;
|
|
179
|
+
/** Maximum raw points possible for this dimension. */
|
|
180
|
+
max: number;
|
|
181
|
+
/** Dimension score normalized to 0–100 independently. */
|
|
182
|
+
normalized: number;
|
|
183
|
+
/** Human-readable explanation of why this score was assigned. */
|
|
184
|
+
explanation: string;
|
|
185
|
+
}
|
|
186
|
+
/** Tier 1 — Answer Confidence display (Grounding + Retrieval + Consistency + Authority). */
|
|
187
|
+
interface Tier1Result {
|
|
188
|
+
/** Normalized 0–100 score for answer quality dimensions. */
|
|
189
|
+
score: number;
|
|
190
|
+
label: 'Strong' | 'Moderate' | 'Limited' | 'Insufficient' | 'Not Addressed';
|
|
191
|
+
color: 'green' | 'amber' | 'orange' | 'red' | 'gray';
|
|
192
|
+
}
|
|
193
|
+
/** Tier 2 — System Readiness display (Corpus + Freshness). Null when no system extensions active. */
|
|
194
|
+
interface Tier2Result {
|
|
195
|
+
/** Normalized 0–100 score for system health dimensions. */
|
|
196
|
+
score: number;
|
|
197
|
+
label: 'Complete' | 'Good' | 'Partial' | 'Thin';
|
|
198
|
+
color: 'green' | 'amber' | 'orange' | 'red';
|
|
199
|
+
}
|
|
200
|
+
/** The complete confidence scorecard returned by computeConfidence. */
|
|
201
|
+
interface ConfidenceScorecard {
|
|
202
|
+
/** Final normalized confidence score. Integer in range 0–100. */
|
|
203
|
+
total: number;
|
|
204
|
+
/** Composite label derived from total score. */
|
|
205
|
+
label: 'Strong' | 'Moderate' | 'Limited' | 'Insufficient';
|
|
206
|
+
/** Color token for the composite label. */
|
|
207
|
+
labelColor: 'green' | 'amber' | 'orange' | 'red';
|
|
208
|
+
/**
|
|
209
|
+
* Tier 1: Answer Confidence.
|
|
210
|
+
* Combines Grounding, Retrieval, Consistency, and Authority (if active).
|
|
211
|
+
* Null only when documentsSilent is true and no candidates were provided.
|
|
212
|
+
*/
|
|
213
|
+
tier1: Tier1Result | null;
|
|
214
|
+
/**
|
|
215
|
+
* Tier 2: System Readiness.
|
|
216
|
+
* Combines Corpus and Freshness (if active).
|
|
217
|
+
* Null when neither Corpus nor Freshness extension is configured.
|
|
218
|
+
*/
|
|
219
|
+
tier2: Tier2Result | null;
|
|
220
|
+
/** Per-dimension breakdown. Optional dimensions present only when their extension is active. */
|
|
221
|
+
dimensions: {
|
|
222
|
+
grounding: DimensionScore;
|
|
223
|
+
retrieval: DimensionScore;
|
|
224
|
+
consistency: DimensionScore;
|
|
225
|
+
authority?: DimensionScore;
|
|
226
|
+
corpus?: DimensionScore;
|
|
227
|
+
freshness?: DimensionScore;
|
|
228
|
+
};
|
|
229
|
+
/** Internal scoring metadata for debugging and transparency. */
|
|
230
|
+
meta: {
|
|
231
|
+
/** Sum of all dimension raw scores before normalization. */
|
|
232
|
+
rawTotal: number;
|
|
233
|
+
/** Maximum possible raw score based on active extensions. */
|
|
234
|
+
maxPossible: number;
|
|
235
|
+
/** Names of active optional extensions, e.g. ["authority", "freshness"]. */
|
|
236
|
+
activeExtensions: string[];
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Computes a structured confidence scorecard for a RAG answer.
|
|
242
|
+
*
|
|
243
|
+
* Always scores the three core dimensions (grounding, retrieval, consistency).
|
|
244
|
+
* Optional extensions are activated by passing the corresponding config key.
|
|
245
|
+
* The total is always normalized to 0–100 regardless of which extensions are active.
|
|
246
|
+
*/
|
|
247
|
+
declare function computeConfidence(inputs: ScoringInputs, config?: ScoringConfig): ConfidenceScorecard;
|
|
248
|
+
/**
|
|
249
|
+
* Creates a pre-configured scorer bound to the given config.
|
|
250
|
+
* Useful when scoring many answers against the same corpus setup.
|
|
251
|
+
*/
|
|
252
|
+
declare function createScorer(config: ScoringConfig): {
|
|
253
|
+
compute: (inputs: ScoringInputs) => ConfidenceScorecard;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export { type AuthorityTier, type Candidate, type ConfidenceScorecard, type DimensionScore, type FreshnessConfig, type ScoringConfig, type ScoringInputs, type Tier1Result, type Tier2Result, computeConfidence, createScorer };
|