@jungjaehoon/mama-core 1.4.2 → 1.6.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/README.md +48 -10
- package/db/migrations/026-create-canonical-entity-tables.sql +99 -0
- package/db/migrations/027-create-entity-review-support.sql +44 -0
- package/db/migrations/028-create-entity-audit-tables.sql +45 -0
- package/db/migrations/029-extend-entity-observations-observation-type.sql +60 -0
- package/db/migrations/030-case-first-memory-substrate.sql +901 -0
- package/db/migrations/031-wiki-page-index-provenance-columns.sql +2 -0
- package/db/migrations/032-add-memory-provenance-columns.sql +21 -0
- package/db/migrations/033-create-model-runs-and-tool-traces.sql +53 -0
- package/db/migrations/034-add-connector-event-scope-columns.sql +14 -0
- package/db/migrations/035-create-twin-edges.sql +63 -0
- package/db/migrations/036-create-agent-situation-packets.sql +61 -0
- package/dist/agent-graph/alias-write.d.ts +3 -0
- package/dist/agent-graph/alias-write.js +231 -0
- package/dist/agent-graph/entity-resolve.d.ts +3 -0
- package/dist/agent-graph/entity-resolve.js +275 -0
- package/dist/agent-graph/errors.d.ts +4 -0
- package/dist/agent-graph/errors.js +11 -0
- package/dist/agent-graph/graph-query.d.ts +5 -0
- package/dist/agent-graph/graph-query.js +359 -0
- package/dist/agent-graph/index.d.ts +6 -0
- package/dist/agent-graph/index.js +22 -0
- package/dist/agent-graph/types.d.ts +162 -0
- package/dist/agent-graph/types.js +3 -0
- package/dist/agent-situation/builder.d.ts +8 -0
- package/dist/agent-situation/builder.js +239 -0
- package/dist/agent-situation/cache-key.d.ts +4 -0
- package/dist/agent-situation/cache-key.js +64 -0
- package/dist/agent-situation/index.d.ts +7 -0
- package/dist/agent-situation/index.js +28 -0
- package/dist/agent-situation/packet-store.d.ts +27 -0
- package/dist/agent-situation/packet-store.js +228 -0
- package/dist/agent-situation/ranking-policy.d.ts +18 -0
- package/dist/agent-situation/ranking-policy.js +75 -0
- package/dist/agent-situation/source-readers.d.ts +52 -0
- package/dist/agent-situation/source-readers.js +300 -0
- package/dist/agent-situation/types.d.ts +195 -0
- package/dist/agent-situation/types.js +3 -0
- package/dist/canonicalize.d.ts +38 -0
- package/dist/canonicalize.js +106 -0
- package/dist/cases/case-links.d.ts +116 -0
- package/dist/cases/case-links.js +794 -0
- package/dist/cases/composition-overrides.d.ts +90 -0
- package/dist/cases/composition-overrides.js +724 -0
- package/dist/cases/corrections.d.ts +156 -0
- package/dist/cases/corrections.js +1045 -0
- package/dist/cases/freshness.d.ts +57 -0
- package/dist/cases/freshness.js +283 -0
- package/dist/cases/live-state.d.ts +48 -0
- package/dist/cases/live-state.js +256 -0
- package/dist/cases/membership-explain.d.ts +56 -0
- package/dist/cases/membership-explain.js +140 -0
- package/dist/cases/membership-matcher.d.ts +23 -0
- package/dist/cases/membership-matcher.js +193 -0
- package/dist/cases/merge-split.d.ts +61 -0
- package/dist/cases/merge-split.js +368 -0
- package/dist/cases/role-inference.d.ts +10 -0
- package/dist/cases/role-inference.js +85 -0
- package/dist/cases/search-rollup.d.ts +27 -0
- package/dist/cases/search-rollup.js +309 -0
- package/dist/cases/sqlite-transaction.d.ts +10 -0
- package/dist/cases/sqlite-transaction.js +62 -0
- package/dist/cases/store.d.ts +74 -0
- package/dist/cases/store.js +816 -0
- package/dist/cases/target-ref.d.ts +25 -0
- package/dist/cases/target-ref.js +22 -0
- package/dist/cases/timeline-range.d.ts +6 -0
- package/dist/cases/timeline-range.js +322 -0
- package/dist/cases/tombstone-sweeper.d.ts +13 -0
- package/dist/cases/tombstone-sweeper.js +128 -0
- package/dist/cases/types.d.ts +244 -0
- package/dist/cases/types.js +47 -0
- package/dist/cases/wiki-page-index.d.ts +50 -0
- package/dist/cases/wiki-page-index.js +350 -0
- package/dist/connectors/event-index.d.ts +45 -0
- package/dist/connectors/event-index.js +381 -0
- package/dist/connectors/raw-query.d.ts +18 -0
- package/dist/connectors/raw-query.js +305 -0
- package/dist/connectors/types.d.ts +109 -0
- package/dist/connectors/types.js +3 -0
- package/dist/db-adapter/node-sqlite-adapter.d.ts +6 -0
- package/dist/db-adapter/node-sqlite-adapter.js +131 -0
- package/dist/db-manager.d.ts +12 -1
- package/dist/db-manager.js +60 -5
- package/dist/decision-formatter.d.ts +2 -0
- package/dist/decision-formatter.js +11 -8
- package/dist/edges/ref-validation.d.ts +8 -0
- package/dist/edges/ref-validation.js +262 -0
- package/dist/edges/store.d.ts +10 -0
- package/dist/edges/store.js +343 -0
- package/dist/edges/types.d.ts +86 -0
- package/dist/edges/types.js +18 -0
- package/dist/embedding-server/mobile/daemon.d.ts +1 -0
- package/dist/embedding-server/mobile/daemon.js +11 -1
- package/dist/embeddings.js +13 -0
- package/dist/entities/audit-metrics.d.ts +73 -0
- package/dist/entities/audit-metrics.js +128 -0
- package/dist/entities/candidate-generator.d.ts +9 -0
- package/dist/entities/candidate-generator.js +436 -0
- package/dist/entities/entity-impact.d.ts +41 -0
- package/dist/entities/entity-impact.js +140 -0
- package/dist/entities/entity-linked-decision-counts.d.ts +2 -0
- package/dist/entities/entity-linked-decision-counts.js +29 -0
- package/dist/entities/entity-list.d.ts +23 -0
- package/dist/entities/entity-list.js +99 -0
- package/dist/entities/entity-orphan-list.d.ts +26 -0
- package/dist/entities/entity-orphan-list.js +91 -0
- package/dist/entities/entity-search.d.ts +21 -0
- package/dist/entities/entity-search.js +150 -0
- package/dist/entities/errors.d.ts +65 -0
- package/dist/entities/errors.js +124 -0
- package/dist/entities/exact-merge-backfill.d.ts +11 -0
- package/dist/entities/exact-merge-backfill.js +161 -0
- package/dist/entities/lineage-backfill.d.ts +12 -0
- package/dist/entities/lineage-backfill.js +101 -0
- package/dist/entities/lineage-store.d.ts +51 -0
- package/dist/entities/lineage-store.js +308 -0
- package/dist/entities/normalization.d.ts +14 -0
- package/dist/entities/normalization.js +63 -0
- package/dist/entities/policy-store.d.ts +17 -0
- package/dist/entities/policy-store.js +263 -0
- package/dist/entities/policy-types.d.ts +72 -0
- package/dist/entities/policy-types.js +59 -0
- package/dist/entities/projection.d.ts +8 -0
- package/dist/entities/projection.js +82 -0
- package/dist/entities/provenance-query.d.ts +33 -0
- package/dist/entities/provenance-query.js +167 -0
- package/dist/entities/read-identity.d.ts +31 -0
- package/dist/entities/read-identity.js +264 -0
- package/dist/entities/recall-bridge.d.ts +5 -0
- package/dist/entities/recall-bridge.js +171 -0
- package/dist/entities/resolution-engine.d.ts +15 -0
- package/dist/entities/resolution-engine.js +69 -0
- package/dist/entities/rollback-preview.d.ts +39 -0
- package/dist/entities/rollback-preview.js +235 -0
- package/dist/entities/source-locator.d.ts +3 -0
- package/dist/entities/source-locator.js +32 -0
- package/dist/entities/store.d.ts +75 -0
- package/dist/entities/store.js +465 -0
- package/dist/entities/types.d.ts +162 -0
- package/dist/entities/types.js +30 -0
- package/dist/index.d.ts +62 -3
- package/dist/index.js +116 -26
- package/dist/mama-api.d.ts +53 -35
- package/dist/mama-api.js +437 -78
- package/dist/memory/api.d.ts +26 -38
- package/dist/memory/api.js +772 -68
- package/dist/memory/event-store.d.ts +3 -0
- package/dist/memory/event-store.js +21 -2
- package/dist/memory/provenance-audit.d.ts +22 -0
- package/dist/memory/provenance-audit.js +112 -0
- package/dist/memory/provenance-query.d.ts +11 -0
- package/dist/memory/provenance-query.js +193 -0
- package/dist/memory/provenance.d.ts +29 -0
- package/dist/memory/provenance.js +136 -0
- package/dist/memory/scope-backfill.d.ts +17 -0
- package/dist/memory/scope-backfill.js +77 -0
- package/dist/memory/types.d.ts +97 -16
- package/dist/model-runs/store.d.ts +13 -0
- package/dist/model-runs/store.js +457 -0
- package/dist/model-runs/tool-trace-store.d.ts +4 -0
- package/dist/model-runs/tool-trace-store.js +114 -0
- package/dist/model-runs/types.d.ts +69 -0
- package/dist/model-runs/types.js +5 -0
- package/dist/runtime/trusted-provenance.d.ts +3 -0
- package/dist/runtime/trusted-provenance.js +6 -0
- package/dist/search/feedback-store.d.ts +59 -0
- package/dist/search/feedback-store.js +211 -0
- package/dist/search/question-type.d.ts +5 -0
- package/dist/search/question-type.js +41 -0
- package/dist/search/ranker-features.d.ts +23 -0
- package/dist/search/ranker-features.js +104 -0
- package/dist/search/ranker-rescore.d.ts +31 -0
- package/dist/search/ranker-rescore.js +226 -0
- package/dist/search/ranker-trainer.d.ts +94 -0
- package/dist/search/ranker-trainer.js +860 -0
- package/dist/search/search-quality.d.ts +36 -0
- package/dist/search/search-quality.js +29 -0
- package/dist/test-utils.d.ts +14 -0
- package/dist/test-utils.js +52 -0
- package/package.json +28 -3
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.loadActiveSearchRankerModel = loadActiveSearchRankerModel;
|
|
4
|
+
exports.isSearchRankerEnabled = isSearchRankerEnabled;
|
|
5
|
+
exports.rescoreSearchResults = rescoreSearchResults;
|
|
6
|
+
exports.logisticScoreForRow = logisticScoreForRow;
|
|
7
|
+
const ranker_features_js_1 = require("./ranker-features.js");
|
|
8
|
+
const ranker_trainer_js_1 = require("./ranker-trainer.js");
|
|
9
|
+
const question_type_js_1 = require("./question-type.js");
|
|
10
|
+
function parseJsonObject(value) {
|
|
11
|
+
const parsed = JSON.parse(value);
|
|
12
|
+
if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
|
|
13
|
+
throw new Error('Expected JSON object');
|
|
14
|
+
}
|
|
15
|
+
return parsed;
|
|
16
|
+
}
|
|
17
|
+
function parseNumberArray(value) {
|
|
18
|
+
if (!Array.isArray(value))
|
|
19
|
+
return [];
|
|
20
|
+
return value.map((item) => (typeof item === 'number' && Number.isFinite(item) ? item : 0));
|
|
21
|
+
}
|
|
22
|
+
function parseQuestionWeights(value, fallback) {
|
|
23
|
+
const object = typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
24
|
+
? value
|
|
25
|
+
: {};
|
|
26
|
+
return {
|
|
27
|
+
correction: parseNumberArray(object.correction).length > 0
|
|
28
|
+
? parseNumberArray(object.correction)
|
|
29
|
+
: [...fallback],
|
|
30
|
+
artifact: parseNumberArray(object.artifact).length > 0
|
|
31
|
+
? parseNumberArray(object.artifact)
|
|
32
|
+
: [...fallback],
|
|
33
|
+
timeline: parseNumberArray(object.timeline).length > 0
|
|
34
|
+
? parseNumberArray(object.timeline)
|
|
35
|
+
: [...fallback],
|
|
36
|
+
status: parseNumberArray(object.status).length > 0 ? parseNumberArray(object.status) : [...fallback],
|
|
37
|
+
decision_reason: parseNumberArray(object.decision_reason).length > 0
|
|
38
|
+
? parseNumberArray(object.decision_reason)
|
|
39
|
+
: [...fallback],
|
|
40
|
+
how_to: parseNumberArray(object.how_to).length > 0 ? parseNumberArray(object.how_to) : [...fallback],
|
|
41
|
+
unknown: parseNumberArray(object.unknown).length > 0
|
|
42
|
+
? parseNumberArray(object.unknown)
|
|
43
|
+
: [...fallback],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function modelFromRow(row) {
|
|
47
|
+
const payload = parseJsonObject(row.coefficients_json);
|
|
48
|
+
const coefficients = parseNumberArray(payload.coefficients);
|
|
49
|
+
const intercept = typeof payload.intercept === 'number' ? payload.intercept : 0;
|
|
50
|
+
const trainingRowsCount = typeof payload.training_rows_count === 'number' ? payload.training_rows_count : 0;
|
|
51
|
+
return {
|
|
52
|
+
model_id: row.model_id,
|
|
53
|
+
feature_set_version: row.feature_set_version,
|
|
54
|
+
trained_at: row.trained_at,
|
|
55
|
+
training_rows_count: trainingRowsCount,
|
|
56
|
+
coefficients,
|
|
57
|
+
intercept,
|
|
58
|
+
question_type_weights: parseQuestionWeights(payload.question_type_weights, coefficients),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function loadActiveRow(adapter) {
|
|
62
|
+
const row = adapter
|
|
63
|
+
.prepare(`
|
|
64
|
+
SELECT model_id, feature_set_version, coefficients_json, quality_gate_status, trained_at
|
|
65
|
+
FROM ranker_model_versions
|
|
66
|
+
WHERE active = 1
|
|
67
|
+
ORDER BY trained_at DESC
|
|
68
|
+
LIMIT 1
|
|
69
|
+
`)
|
|
70
|
+
.get();
|
|
71
|
+
return row ?? null;
|
|
72
|
+
}
|
|
73
|
+
function logSkipped(reason, modelId) {
|
|
74
|
+
console.warn(JSON.stringify({
|
|
75
|
+
event: 'search_ranker_skipped',
|
|
76
|
+
skipped_reason: reason,
|
|
77
|
+
model_id: modelId,
|
|
78
|
+
feature_set_version: ranker_features_js_1.SEARCH_RANKER_FEATURE_SET_VERSION,
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
function loadActiveSearchRankerModel(adapter) {
|
|
82
|
+
const row = loadActiveRow(adapter);
|
|
83
|
+
if (!row) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
if (row.feature_set_version !== ranker_features_js_1.SEARCH_RANKER_FEATURE_SET_VERSION) {
|
|
87
|
+
logSkipped('feature_set_mismatch', row.model_id);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
return modelFromRow(row);
|
|
91
|
+
}
|
|
92
|
+
function isSearchRankerEnabled(adapter) {
|
|
93
|
+
const row = adapter
|
|
94
|
+
.prepare(`
|
|
95
|
+
SELECT value_json
|
|
96
|
+
FROM search_ranker_settings
|
|
97
|
+
WHERE key = 'search_ranker_enabled'
|
|
98
|
+
`)
|
|
99
|
+
.get();
|
|
100
|
+
if (!row?.value_json) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
const parsed = JSON.parse(row.value_json);
|
|
104
|
+
return parsed !== false;
|
|
105
|
+
}
|
|
106
|
+
function baseScore(row) {
|
|
107
|
+
const candidates = [
|
|
108
|
+
row.final_score,
|
|
109
|
+
row.retrieval_score,
|
|
110
|
+
row.score,
|
|
111
|
+
row.similarity,
|
|
112
|
+
row.confidence,
|
|
113
|
+
row.case_rollup_score,
|
|
114
|
+
row.vector_score,
|
|
115
|
+
row.bm25_score,
|
|
116
|
+
];
|
|
117
|
+
for (const candidate of candidates) {
|
|
118
|
+
if (typeof candidate === 'number' && Number.isFinite(candidate)) {
|
|
119
|
+
return candidate;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
function resultId(row, fallback) {
|
|
125
|
+
const id = row.id ?? row.source_id ?? row.result_source_id;
|
|
126
|
+
return id === undefined || id === null ? String(fallback) : String(id);
|
|
127
|
+
}
|
|
128
|
+
function rescoreSearchResults(adapter, options) {
|
|
129
|
+
const passthrough = options.results;
|
|
130
|
+
if (options.useReranking) {
|
|
131
|
+
return {
|
|
132
|
+
results: passthrough,
|
|
133
|
+
model_id: null,
|
|
134
|
+
skipped_reason: 'llm_reranking_requested',
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
if (options.featureEnabled === false) {
|
|
138
|
+
return {
|
|
139
|
+
results: passthrough,
|
|
140
|
+
model_id: null,
|
|
141
|
+
skipped_reason: 'feature_disabled',
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
if (options.results.length < 2) {
|
|
145
|
+
return {
|
|
146
|
+
results: passthrough,
|
|
147
|
+
model_id: null,
|
|
148
|
+
skipped_reason: 'insufficient_result_count',
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
const row = loadActiveRow(adapter);
|
|
152
|
+
if (!row) {
|
|
153
|
+
return {
|
|
154
|
+
results: passthrough,
|
|
155
|
+
model_id: null,
|
|
156
|
+
skipped_reason: 'no_active_model',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (row.feature_set_version !== ranker_features_js_1.SEARCH_RANKER_FEATURE_SET_VERSION) {
|
|
160
|
+
logSkipped('feature_set_mismatch', row.model_id);
|
|
161
|
+
return {
|
|
162
|
+
results: passthrough,
|
|
163
|
+
model_id: row.model_id,
|
|
164
|
+
skipped_reason: 'feature_set_mismatch',
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
if (row.quality_gate_status === 'failed') {
|
|
168
|
+
return {
|
|
169
|
+
results: passthrough,
|
|
170
|
+
model_id: row.model_id,
|
|
171
|
+
skipped_reason: 'quality_gate_failed',
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
if (row.quality_gate_status !== 'passed') {
|
|
175
|
+
return {
|
|
176
|
+
results: passthrough,
|
|
177
|
+
model_id: row.model_id,
|
|
178
|
+
skipped_reason: 'quality_gate_failed',
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
const model = modelFromRow(row);
|
|
182
|
+
const questionType = (0, question_type_js_1.classifyQuestionType)(options.query);
|
|
183
|
+
const scored = options.results.map((result, index) => {
|
|
184
|
+
const scoreBeforeRanker = baseScore(result);
|
|
185
|
+
const rankerScore = (0, ranker_trainer_js_1.scoreWithRankerModel)(model, result, options.query, questionType);
|
|
186
|
+
const finalScore = 0.8 * scoreBeforeRanker + 0.2 * rankerScore;
|
|
187
|
+
return {
|
|
188
|
+
result: {
|
|
189
|
+
...result,
|
|
190
|
+
ranker_score: rankerScore,
|
|
191
|
+
score_before_ranker: scoreBeforeRanker,
|
|
192
|
+
final_score: finalScore,
|
|
193
|
+
},
|
|
194
|
+
index,
|
|
195
|
+
id: resultId(result, index),
|
|
196
|
+
finalScore,
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
scored.sort((left, right) => {
|
|
200
|
+
const diff = right.finalScore - left.finalScore;
|
|
201
|
+
if (Math.abs(diff) > 1e-12)
|
|
202
|
+
return diff;
|
|
203
|
+
if (left.index !== right.index)
|
|
204
|
+
return left.index - right.index;
|
|
205
|
+
return left.id.localeCompare(right.id);
|
|
206
|
+
});
|
|
207
|
+
return {
|
|
208
|
+
results: scored.map((entry) => entry.result),
|
|
209
|
+
model_id: model.model_id,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
function logisticScoreForRow(model, row, query) {
|
|
213
|
+
const questionType = (0, question_type_js_1.classifyQuestionType)(query);
|
|
214
|
+
const features = (0, ranker_features_js_1.serializeFeatures)((0, ranker_features_js_1.extractFeatures)(row, query, { question_type: questionType }));
|
|
215
|
+
const coefficients = model.question_type_weights[questionType] ?? model.coefficients;
|
|
216
|
+
let score = model.intercept;
|
|
217
|
+
for (let index = 0; index < Math.min(coefficients.length, features.length); index += 1) {
|
|
218
|
+
score += coefficients[index] * features[index];
|
|
219
|
+
}
|
|
220
|
+
if (score >= 35)
|
|
221
|
+
return 1;
|
|
222
|
+
if (score <= -35)
|
|
223
|
+
return 0;
|
|
224
|
+
return 1 / (1 + Math.exp(-score));
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=ranker-rescore.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { RunResult } from '../db-adapter/statement.js';
|
|
2
|
+
import { featureSetVersion as currentFeatureSetVersion, SEARCH_RANKER_FEATURE_SET_VERSION } from './ranker-features.js';
|
|
3
|
+
import { type QuestionType } from './question-type.js';
|
|
4
|
+
export interface SearchRankerModel {
|
|
5
|
+
model_id: string;
|
|
6
|
+
feature_set_version: string;
|
|
7
|
+
trained_at: string;
|
|
8
|
+
training_rows_count: number;
|
|
9
|
+
coefficients: number[];
|
|
10
|
+
intercept: number;
|
|
11
|
+
question_type_weights: Record<QuestionType, number[]>;
|
|
12
|
+
training_window?: EffectiveTrainingWindow;
|
|
13
|
+
}
|
|
14
|
+
export interface RankerTrainerInput {
|
|
15
|
+
adapter: RankerTrainerAdapter;
|
|
16
|
+
since?: string;
|
|
17
|
+
until?: string;
|
|
18
|
+
minFeedbackRows?: number;
|
|
19
|
+
minDistinctQueries?: number;
|
|
20
|
+
featureSetVersion?: string;
|
|
21
|
+
now?: Date;
|
|
22
|
+
}
|
|
23
|
+
export interface EffectiveTrainingWindow {
|
|
24
|
+
since: string;
|
|
25
|
+
until: string;
|
|
26
|
+
retention_cutoff_at: string;
|
|
27
|
+
retention_days_at_train_time: number;
|
|
28
|
+
retention_warning: boolean;
|
|
29
|
+
}
|
|
30
|
+
export interface TrainOfflineRankerResult {
|
|
31
|
+
status: 'trained' | 'insufficient_data';
|
|
32
|
+
model?: SearchRankerModel;
|
|
33
|
+
effectiveWindow: EffectiveTrainingWindow;
|
|
34
|
+
counts: {
|
|
35
|
+
feedbackRows: number;
|
|
36
|
+
distinctQueries: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export interface BaselineMetrics {
|
|
40
|
+
ndcg: number;
|
|
41
|
+
mrr: number;
|
|
42
|
+
per_query: Record<string, {
|
|
43
|
+
ndcg: number;
|
|
44
|
+
mrr: number;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
export interface RankerEvaluation {
|
|
48
|
+
bm25: BaselineMetrics;
|
|
49
|
+
vector: BaselineMetrics;
|
|
50
|
+
rrf: BaselineMetrics;
|
|
51
|
+
logistic: BaselineMetrics;
|
|
52
|
+
learned: BaselineMetrics;
|
|
53
|
+
passes: boolean;
|
|
54
|
+
}
|
|
55
|
+
export interface RankerTrainerAdapter {
|
|
56
|
+
prepare(sql: string): {
|
|
57
|
+
run(...params: unknown[]): RunResult;
|
|
58
|
+
get(...params: unknown[]): unknown;
|
|
59
|
+
all(...params: unknown[]): unknown[];
|
|
60
|
+
};
|
|
61
|
+
transaction?<T>(fn: () => T): T | (() => T);
|
|
62
|
+
}
|
|
63
|
+
interface QualityCandidate {
|
|
64
|
+
id: string;
|
|
65
|
+
source_type: string;
|
|
66
|
+
bm25_score: number;
|
|
67
|
+
vector_score: number;
|
|
68
|
+
case_rollup_score: number;
|
|
69
|
+
recency_score: number;
|
|
70
|
+
relevance: number;
|
|
71
|
+
}
|
|
72
|
+
interface QualityFixture {
|
|
73
|
+
query: string;
|
|
74
|
+
question_type: QuestionType;
|
|
75
|
+
candidates: QualityCandidate[];
|
|
76
|
+
}
|
|
77
|
+
export declare const RANKER_QUALITY_FIXTURES: readonly QualityFixture[];
|
|
78
|
+
export declare function trainOfflineRanker(input: RankerTrainerInput): Promise<TrainOfflineRankerResult>;
|
|
79
|
+
export declare function scoreWithRankerModel(model: SearchRankerModel, row: Record<string, unknown>, query: string, questionType: QuestionType): number;
|
|
80
|
+
export declare function evaluateAgainstBaselines(_input: RankerTrainerInput, model: SearchRankerModel): Promise<RankerEvaluation>;
|
|
81
|
+
export declare function insertRankerModelVersion(adapter: RankerTrainerAdapter, model: SearchRankerModel, evaluation: RankerEvaluation): Promise<{
|
|
82
|
+
model_id: string;
|
|
83
|
+
active: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
export declare function activateRankerModel(adapter: RankerTrainerAdapter, model_id: string): Promise<'activated' | 'quality_gate_failed' | 'feature_set_mismatch' | 'not_found'>;
|
|
86
|
+
export declare function ndcgAtK<T extends {
|
|
87
|
+
id: string;
|
|
88
|
+
}>(results: readonly T[], relevanceMap: Map<string, number>, k: number): number;
|
|
89
|
+
export declare function mrr<T extends {
|
|
90
|
+
id: string;
|
|
91
|
+
}>(results: readonly T[], relevantSet: Set<string>): number;
|
|
92
|
+
export declare function seedQualityFixtureFeedback(adapter: RankerTrainerAdapter, createdAt?: string): void;
|
|
93
|
+
export { SEARCH_RANKER_FEATURE_SET_VERSION, currentFeatureSetVersion as featureSetVersion };
|
|
94
|
+
//# sourceMappingURL=ranker-trainer.d.ts.map
|