@equationalapplications/core-llm-wiki 9.11.0 → 9.12.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/dist/{chunk-QUVPQVJ6.mjs → chunk-KB37MGFF.mjs} +196 -22
- package/dist/chunk-KB37MGFF.mjs.map +1 -0
- package/dist/index.d.mts +17 -3
- package/dist/index.d.ts +17 -3
- package/dist/index.js +195 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{testing-DFyghdSG.d.mts → testing-imNjsm-X.d.mts} +26 -6
- package/dist/{testing-DFyghdSG.d.ts → testing-imNjsm-X.d.ts} +26 -6
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +193 -19
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-QUVPQVJ6.mjs.map +0 -1
|
@@ -4,20 +4,33 @@ import { OkfSource, OkfVerifiedEntry, OkfSourceUsageWindow } from '@equationalap
|
|
|
4
4
|
* System-One config surface (specs/system-one-config §1, §10).
|
|
5
5
|
*
|
|
6
6
|
* Boundary: S1-0 owns exactly `typing`, `minConfidence` (with the `'typing'`
|
|
7
|
-
* member), and `onLowConfidence
|
|
8
|
-
*
|
|
7
|
+
* member), and `onLowConfidence`; the edge-suggestions step adds `edges` and
|
|
8
|
+
* the `'edges'` member. Later PRs add more threshold sites
|
|
9
|
+
* (`'resolve'`, `'healScreen'`) — each as one new line in
|
|
9
10
|
* `SystemOneThresholdSite`, so sibling PRs merge cleanly. Nothing outside
|
|
10
11
|
* that boundary belongs here.
|
|
11
12
|
*/
|
|
12
|
-
/** Sites a System-One threshold can apply to. Exactly
|
|
13
|
-
type SystemOneThresholdSite = 'typing';
|
|
13
|
+
/** Sites a System-One threshold can apply to. Exactly two members today: `'typing'` and `'edges'` (§10 fence). */
|
|
14
|
+
type SystemOneThresholdSite = 'typing' | 'edges';
|
|
14
15
|
interface SystemOneConfig {
|
|
15
16
|
/**
|
|
16
17
|
* Typing mode for ontology backfill. `'auto'` uses
|
|
17
|
-
* `llmProvider.classify` when present (no edges proposed); `'llm'`
|
|
18
|
+
* `llmProvider.classify` when present (no edges proposed, unless `systemOne.edges: 'auto'`); `'llm'`
|
|
18
19
|
* always uses the generative path. Default `'llm'`.
|
|
19
20
|
*/
|
|
20
21
|
typing?: 'auto' | 'llm';
|
|
22
|
+
/**
|
|
23
|
+
* Edge mode for ontology backfill. `'llm'` (default) keeps edge proposal
|
|
24
|
+
* on the generative path exactly as today. `'auto'` engages the classifier
|
|
25
|
+
* edge screen (§4) when the classifier step runs AND an explicit
|
|
26
|
+
* `minConfidence.edges` floor is set (§3 — missing floor under `'auto'`
|
|
27
|
+
* warns once and the site resolves `'llm'`); answers at or above the
|
|
28
|
+
* floor apply the edge, confident "no" answers are terminal, and facts
|
|
29
|
+
* whose edge answers land in the uncertain band fall through to the
|
|
30
|
+
* generative step of the same pass (§3, §5). There is no `'off'`: this PR
|
|
31
|
+
* adds no configuration that can silently discard a model-proposed edge.
|
|
32
|
+
*/
|
|
33
|
+
edges?: 'auto' | 'llm';
|
|
21
34
|
/** Per-site minimum confidence. Only the classifier path reads a floor. */
|
|
22
35
|
minConfidence?: Partial<Record<SystemOneThresholdSite, number>>;
|
|
23
36
|
/**
|
|
@@ -4328,7 +4341,14 @@ declare class MaintenanceService {
|
|
|
4328
4341
|
* untyped fact over the effective manifest's node-type slugs plus the
|
|
4329
4342
|
* reserved abstain sentinel. Accepted answers go through
|
|
4330
4343
|
* `_applyOntologyBackfillBatch` exactly like LLM classifications. No edges
|
|
4331
|
-
* are proposed.
|
|
4344
|
+
* are proposed unless `systemOne.edges` is `'auto'`; under `'auto'` the
|
|
4345
|
+
* classifier screens per-fact edge questions against
|
|
4346
|
+
* `systemOne.minConfidence.edges` (an explicit floor; missing → warn and
|
|
4347
|
+
* `'llm'`). Confident "yes" answers (`p > 0.5 && p >= floor`) apply,
|
|
4348
|
+
* confident "no" answers (`p < 0.5 && 1 - p >= floor`) are terminal, and
|
|
4349
|
+
* everything else (including exactly `p = 0.5`) plus invalid edge answers
|
|
4350
|
+
* fall through to the generative step. Edge outcomes are evaluated only for
|
|
4351
|
+
* typing-ACCEPTED facts. Abstains and low-confidence answers are cooldown-stamped
|
|
4332
4352
|
* omissions under `onLowConfidence: 'leave'`; under `'llm'` they are
|
|
4333
4353
|
* returned un-stamped in `escalated` for the generative step. Always
|
|
4334
4354
|
* returns the `OntologyBackfillResult` for its step plus escalation state.
|
|
@@ -4,20 +4,33 @@ import { OkfSource, OkfVerifiedEntry, OkfSourceUsageWindow } from '@equationalap
|
|
|
4
4
|
* System-One config surface (specs/system-one-config §1, §10).
|
|
5
5
|
*
|
|
6
6
|
* Boundary: S1-0 owns exactly `typing`, `minConfidence` (with the `'typing'`
|
|
7
|
-
* member), and `onLowConfidence
|
|
8
|
-
*
|
|
7
|
+
* member), and `onLowConfidence`; the edge-suggestions step adds `edges` and
|
|
8
|
+
* the `'edges'` member. Later PRs add more threshold sites
|
|
9
|
+
* (`'resolve'`, `'healScreen'`) — each as one new line in
|
|
9
10
|
* `SystemOneThresholdSite`, so sibling PRs merge cleanly. Nothing outside
|
|
10
11
|
* that boundary belongs here.
|
|
11
12
|
*/
|
|
12
|
-
/** Sites a System-One threshold can apply to. Exactly
|
|
13
|
-
type SystemOneThresholdSite = 'typing';
|
|
13
|
+
/** Sites a System-One threshold can apply to. Exactly two members today: `'typing'` and `'edges'` (§10 fence). */
|
|
14
|
+
type SystemOneThresholdSite = 'typing' | 'edges';
|
|
14
15
|
interface SystemOneConfig {
|
|
15
16
|
/**
|
|
16
17
|
* Typing mode for ontology backfill. `'auto'` uses
|
|
17
|
-
* `llmProvider.classify` when present (no edges proposed); `'llm'`
|
|
18
|
+
* `llmProvider.classify` when present (no edges proposed, unless `systemOne.edges: 'auto'`); `'llm'`
|
|
18
19
|
* always uses the generative path. Default `'llm'`.
|
|
19
20
|
*/
|
|
20
21
|
typing?: 'auto' | 'llm';
|
|
22
|
+
/**
|
|
23
|
+
* Edge mode for ontology backfill. `'llm'` (default) keeps edge proposal
|
|
24
|
+
* on the generative path exactly as today. `'auto'` engages the classifier
|
|
25
|
+
* edge screen (§4) when the classifier step runs AND an explicit
|
|
26
|
+
* `minConfidence.edges` floor is set (§3 — missing floor under `'auto'`
|
|
27
|
+
* warns once and the site resolves `'llm'`); answers at or above the
|
|
28
|
+
* floor apply the edge, confident "no" answers are terminal, and facts
|
|
29
|
+
* whose edge answers land in the uncertain band fall through to the
|
|
30
|
+
* generative step of the same pass (§3, §5). There is no `'off'`: this PR
|
|
31
|
+
* adds no configuration that can silently discard a model-proposed edge.
|
|
32
|
+
*/
|
|
33
|
+
edges?: 'auto' | 'llm';
|
|
21
34
|
/** Per-site minimum confidence. Only the classifier path reads a floor. */
|
|
22
35
|
minConfidence?: Partial<Record<SystemOneThresholdSite, number>>;
|
|
23
36
|
/**
|
|
@@ -4328,7 +4341,14 @@ declare class MaintenanceService {
|
|
|
4328
4341
|
* untyped fact over the effective manifest's node-type slugs plus the
|
|
4329
4342
|
* reserved abstain sentinel. Accepted answers go through
|
|
4330
4343
|
* `_applyOntologyBackfillBatch` exactly like LLM classifications. No edges
|
|
4331
|
-
* are proposed.
|
|
4344
|
+
* are proposed unless `systemOne.edges` is `'auto'`; under `'auto'` the
|
|
4345
|
+
* classifier screens per-fact edge questions against
|
|
4346
|
+
* `systemOne.minConfidence.edges` (an explicit floor; missing → warn and
|
|
4347
|
+
* `'llm'`). Confident "yes" answers (`p > 0.5 && p >= floor`) apply,
|
|
4348
|
+
* confident "no" answers (`p < 0.5 && 1 - p >= floor`) are terminal, and
|
|
4349
|
+
* everything else (including exactly `p = 0.5`) plus invalid edge answers
|
|
4350
|
+
* fall through to the generative step. Edge outcomes are evaluated only for
|
|
4351
|
+
* typing-ACCEPTED facts. Abstains and low-confidence answers are cooldown-stamped
|
|
4332
4352
|
* omissions under `onLowConfidence: 'leave'`; under `'llm'` they are
|
|
4333
4353
|
* returned un-stamped in `escalated` for the generative step. Always
|
|
4334
4354
|
* returns the `OntologyBackfillResult` for its step plus escalation state.
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a_ as EmbeddingService, a$ as ImportExportService, b0 as IngestionService, b1 as JobManager, b1 as JobManagerType, b2 as MaintenanceService, b3 as RetrievalService, b4 as SearchService, b4 as SearchServiceType, aL as WikiMemoryTestAccess, b5 as WriteService } from './testing-
|
|
1
|
+
export { a_ as EmbeddingService, a$ as ImportExportService, b0 as IngestionService, b1 as JobManager, b1 as JobManagerType, b2 as MaintenanceService, b3 as RetrievalService, b4 as SearchService, b4 as SearchServiceType, aL as WikiMemoryTestAccess, b5 as WriteService } from './testing-imNjsm-X.mjs';
|
|
2
2
|
import '@equationalapplications/core-okf';
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a_ as EmbeddingService, a$ as ImportExportService, b0 as IngestionService, b1 as JobManager, b1 as JobManagerType, b2 as MaintenanceService, b3 as RetrievalService, b4 as SearchService, b4 as SearchServiceType, aL as WikiMemoryTestAccess, b5 as WriteService } from './testing-
|
|
1
|
+
export { a_ as EmbeddingService, a$ as ImportExportService, b0 as IngestionService, b1 as JobManager, b1 as JobManagerType, b2 as MaintenanceService, b3 as RetrievalService, b4 as SearchService, b4 as SearchServiceType, aL as WikiMemoryTestAccess, b5 as WriteService } from './testing-imNjsm-X.js';
|
|
2
2
|
import '@equationalapplications/core-okf';
|
package/dist/testing.js
CHANGED
|
@@ -4116,6 +4116,16 @@ function resolveSystemOneTyping(config, classifierCallOption) {
|
|
|
4116
4116
|
}
|
|
4117
4117
|
return classifierCallOption ?? (systemOneValid ? systemOne.typing : void 0) ?? (legacyValid ? legacy : void 0) ?? "llm";
|
|
4118
4118
|
}
|
|
4119
|
+
function resolveSystemOneEdges(config) {
|
|
4120
|
+
const edges = config?.systemOne?.edges;
|
|
4121
|
+
if (edges !== void 0 && !isTypingMode(edges)) {
|
|
4122
|
+
warnOnce(
|
|
4123
|
+
`[core-llm-wiki] systemOne: \`systemOne.edges\` is ${formatConfigValue(edges)}, which is not 'auto' or 'llm'. The key is treated as unset; the default ('llm') applies.`
|
|
4124
|
+
);
|
|
4125
|
+
return "llm";
|
|
4126
|
+
}
|
|
4127
|
+
return edges ?? "llm";
|
|
4128
|
+
}
|
|
4119
4129
|
var DEFAULT_SHORTLIST_K = 10;
|
|
4120
4130
|
function resolveShortlistK(config) {
|
|
4121
4131
|
const k = config?.ontology?.shortlistK;
|
|
@@ -4145,6 +4155,16 @@ function resolveTypingMinConfidence(config) {
|
|
|
4145
4155
|
}
|
|
4146
4156
|
return (systemOneValid ? systemOneFloor : void 0) ?? (legacyValid ? legacyFloor : void 0) ?? DEFAULT_TYPING_MIN_CONFIDENCE;
|
|
4147
4157
|
}
|
|
4158
|
+
var isEdgesFloor = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0.5 && v <= 1;
|
|
4159
|
+
function resolveEdgesMinConfidence(config) {
|
|
4160
|
+
if (resolveSystemOneEdges(config) !== "auto") return void 0;
|
|
4161
|
+
const floor = config?.systemOne?.minConfidence?.edges;
|
|
4162
|
+
if (isEdgesFloor(floor)) return floor;
|
|
4163
|
+
warnOnce(
|
|
4164
|
+
floor === void 0 ? "[core-llm-wiki] systemOne: `systemOne.minConfidence.edges` is required when `systemOne.edges` is 'auto'. The edge screen is off for this site; edges stay on the generative path." : `[core-llm-wiki] systemOne: \`systemOne.minConfidence.edges\` is ${formatConfigValue(floor)}, which is not a finite number in [0.5, 1]. The edge screen is off for this site; edges stay on the generative path.`
|
|
4165
|
+
);
|
|
4166
|
+
return void 0;
|
|
4167
|
+
}
|
|
4148
4168
|
|
|
4149
4169
|
// src/utils/embedding.ts
|
|
4150
4170
|
function parseEmbedding(blob, text) {
|
|
@@ -7424,7 +7444,10 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7424
7444
|
return { ...zeroed, remaining: counts.eligible, deferred: counts.deferred };
|
|
7425
7445
|
}
|
|
7426
7446
|
const classifierMode = resolveSystemOneTyping(this.options.config, options?.classifier);
|
|
7447
|
+
const edgeMode = resolveSystemOneEdges(this.options.config);
|
|
7427
7448
|
const classify = this.options.llmProvider.classify;
|
|
7449
|
+
const edgeMinConfidence = edgeMode === "auto" && classifierMode === "auto" && typeof classify === "function" ? resolveEdgesMinConfidence(this.options.config) : void 0;
|
|
7450
|
+
const edgeSiteMode = edgeMode === "auto" && typeof edgeMinConfidence === "number" ? "auto" : "llm";
|
|
7428
7451
|
if (classifierMode === "auto" && typeof classify === "function") {
|
|
7429
7452
|
const slugs = effectiveManifest.node_types.map((n) => n.type);
|
|
7430
7453
|
if (slugs.length > 0 && slugs.length + 1 <= CLASSIFIER_MAX_CHOICES && !slugs.some((s) => isReservedAbstainSlug(s))) {
|
|
@@ -7435,16 +7458,29 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7435
7458
|
now,
|
|
7436
7459
|
recheckCutoff,
|
|
7437
7460
|
options?.meter,
|
|
7438
|
-
trigger
|
|
7461
|
+
trigger,
|
|
7462
|
+
shortlistK,
|
|
7463
|
+
edgeSiteMode,
|
|
7464
|
+
edgeMinConfidence
|
|
7439
7465
|
);
|
|
7440
7466
|
if (classifierRun.abortedOntologyOff || classifierRun.result.budgetStop) {
|
|
7441
7467
|
return classifierRun.result;
|
|
7442
7468
|
}
|
|
7443
|
-
if (classifierRun.escalated.length > 0
|
|
7469
|
+
if (classifierRun.escalated.length > 0) {
|
|
7444
7470
|
const { mode: liveMode } = await ontologyService.getEffectiveState(entityId);
|
|
7445
7471
|
if (liveMode === "off") {
|
|
7446
7472
|
const counts = await this.entryRepo.countUntypedByEntityId(entityId, recheckCutoff);
|
|
7447
|
-
|
|
7473
|
+
const committed = classifierRun.result;
|
|
7474
|
+
return {
|
|
7475
|
+
scanned: committed.scanned,
|
|
7476
|
+
typed: committed.typed,
|
|
7477
|
+
failedValidation: committed.failedValidation,
|
|
7478
|
+
edgesAdded: committed.edgesAdded,
|
|
7479
|
+
abstained: committed.abstained,
|
|
7480
|
+
skipped: committed.skipped,
|
|
7481
|
+
remaining: 0,
|
|
7482
|
+
deferred: counts.deferred
|
|
7483
|
+
};
|
|
7448
7484
|
}
|
|
7449
7485
|
const escalated = classifierRun.escalated;
|
|
7450
7486
|
const generative = await this._runGenerativeBackfill(entityId, escalated, {
|
|
@@ -7454,7 +7490,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7454
7490
|
batchSize: escalated.length,
|
|
7455
7491
|
recheckCutoff,
|
|
7456
7492
|
shortlistK,
|
|
7457
|
-
maxPromptChars
|
|
7493
|
+
maxPromptChars,
|
|
7494
|
+
edgeSiteMode,
|
|
7495
|
+
edgeMinConfidence
|
|
7458
7496
|
});
|
|
7459
7497
|
return {
|
|
7460
7498
|
scanned: classifierRun.result.scanned,
|
|
@@ -7477,7 +7515,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7477
7515
|
trigger,
|
|
7478
7516
|
recheckCutoff,
|
|
7479
7517
|
shortlistK,
|
|
7480
|
-
maxPromptChars
|
|
7518
|
+
maxPromptChars,
|
|
7519
|
+
edgeSiteMode,
|
|
7520
|
+
edgeMinConfidence
|
|
7481
7521
|
});
|
|
7482
7522
|
}
|
|
7483
7523
|
/**
|
|
@@ -7513,6 +7553,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7513
7553
|
if (maxPromptChars === void 0) {
|
|
7514
7554
|
throw new Error("_runGenerativeBackfill: runOpts.maxPromptChars is required (resolved at doRunOntologyBackfill entry)");
|
|
7515
7555
|
}
|
|
7556
|
+
if (runOpts.edgeSiteMode === void 0) {
|
|
7557
|
+
throw new Error("_runGenerativeBackfill: runOpts.edgeSiteMode is required (resolved at doRunOntologyBackfill entry)");
|
|
7558
|
+
}
|
|
7516
7559
|
const ontologyService = this.ontologyService;
|
|
7517
7560
|
const now = Date.now();
|
|
7518
7561
|
const recheckCutoff = runOpts.recheckCutoff;
|
|
@@ -7640,12 +7683,19 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7640
7683
|
* untyped fact over the effective manifest's node-type slugs plus the
|
|
7641
7684
|
* reserved abstain sentinel. Accepted answers go through
|
|
7642
7685
|
* `_applyOntologyBackfillBatch` exactly like LLM classifications. No edges
|
|
7643
|
-
* are proposed.
|
|
7686
|
+
* are proposed unless `systemOne.edges` is `'auto'`; under `'auto'` the
|
|
7687
|
+
* classifier screens per-fact edge questions against
|
|
7688
|
+
* `systemOne.minConfidence.edges` (an explicit floor; missing → warn and
|
|
7689
|
+
* `'llm'`). Confident "yes" answers (`p > 0.5 && p >= floor`) apply,
|
|
7690
|
+
* confident "no" answers (`p < 0.5 && 1 - p >= floor`) are terminal, and
|
|
7691
|
+
* everything else (including exactly `p = 0.5`) plus invalid edge answers
|
|
7692
|
+
* fall through to the generative step. Edge outcomes are evaluated only for
|
|
7693
|
+
* typing-ACCEPTED facts. Abstains and low-confidence answers are cooldown-stamped
|
|
7644
7694
|
* omissions under `onLowConfidence: 'leave'`; under `'llm'` they are
|
|
7645
7695
|
* returned un-stamped in `escalated` for the generative step. Always
|
|
7646
7696
|
* returns the `OntologyBackfillResult` for its step plus escalation state.
|
|
7647
7697
|
*/
|
|
7648
|
-
async _runClassifierBackfill(entityId, candidates, manifest, now, recheckCutoff, meter, trigger) {
|
|
7698
|
+
async _runClassifierBackfill(entityId, candidates, manifest, now, recheckCutoff, meter, trigger, shortlistK, edgeSiteMode, edgeMinConfidence) {
|
|
7649
7699
|
const minConfidence = resolveTypingMinConfidence(this.options.config);
|
|
7650
7700
|
const rawConcurrency = this.options.config?.chunkConcurrency ?? 1;
|
|
7651
7701
|
const concurrency = Number.isFinite(rawConcurrency) && rawConcurrency >= 1 ? Math.floor(rawConcurrency) : 1;
|
|
@@ -7655,17 +7705,65 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7655
7705
|
instructions: `Choose the ontology node type that best describes this fact, or choose "${ONTOLOGY_ABSTAIN_SENTINEL}" if none of the listed types fits.
|
|
7656
7706
|
` + manifest.node_types.map((n) => `- ${n.type}: ${n.description}`).join("\n")
|
|
7657
7707
|
};
|
|
7708
|
+
const edgeScreen = /* @__PURE__ */ new Map();
|
|
7709
|
+
if (edgeSiteMode === "auto" && (manifest.edge_types ?? []).length > 0) {
|
|
7710
|
+
const pool = await this.entryRepo.findShortlistRowsByEntityId(entityId);
|
|
7711
|
+
const poolTitleCounts = /* @__PURE__ */ new Map();
|
|
7712
|
+
for (const r of pool) {
|
|
7713
|
+
const k = normalizeTitleKey(r.title);
|
|
7714
|
+
poolTitleCounts.set(k, (poolTitleCounts.get(k) ?? 0) + 1);
|
|
7715
|
+
}
|
|
7716
|
+
const batchTitleKeys = new Set(candidates.map((f) => normalizeTitleKey(f.title)));
|
|
7717
|
+
const collides = (title) => {
|
|
7718
|
+
const k = normalizeTitleKey(title);
|
|
7719
|
+
return (poolTitleCounts.get(k) ?? 0) > 1 || batchTitleKeys.has(k);
|
|
7720
|
+
};
|
|
7721
|
+
const scorer = createShortlistScorer(pool);
|
|
7722
|
+
const edgeTypeNames = [...new Set(manifest.edge_types.map((e) => e.type))];
|
|
7723
|
+
for (const fact of candidates) {
|
|
7724
|
+
const ranked = buildShortlist({ title: fact.title, body: fact.body }, pool, shortlistK, scorer).filter((row) => !collides(row.title));
|
|
7725
|
+
const questions = {};
|
|
7726
|
+
const keyMap = /* @__PURE__ */ new Map();
|
|
7727
|
+
for (const row of ranked) {
|
|
7728
|
+
for (const edgeType of edgeTypeNames) {
|
|
7729
|
+
const definitions = manifest.edge_types.filter(
|
|
7730
|
+
(e) => e.type === edgeType && typeSatisfies(e.target_type, row.okf_type, manifest)
|
|
7731
|
+
);
|
|
7732
|
+
if (definitions.length === 0) continue;
|
|
7733
|
+
const key = `edge:${edgeType}:${row.id}`;
|
|
7734
|
+
const descriptions = [...new Set(definitions.map((d) => d.description))].join(" / ");
|
|
7735
|
+
questions[key] = {
|
|
7736
|
+
kind: "binary",
|
|
7737
|
+
instructions: `Does this fact have the "${edgeType}" relationship (${descriptions}) to the existing fact titled "${row.title}"?`
|
|
7738
|
+
};
|
|
7739
|
+
keyMap.set(key, { definitions, candidate: { id: row.id, title: row.title, okf_type: row.okf_type } });
|
|
7740
|
+
}
|
|
7741
|
+
}
|
|
7742
|
+
if (keyMap.size > 0) edgeScreen.set(fact.id, { questions, keyMap });
|
|
7743
|
+
}
|
|
7744
|
+
}
|
|
7658
7745
|
let stopped;
|
|
7746
|
+
const retriedFacts = /* @__PURE__ */ new Set();
|
|
7659
7747
|
const outcomes = await withConcurrency(
|
|
7660
7748
|
candidates.map((fact) => async () => {
|
|
7661
7749
|
if (stopped) return { fact, kind: "unattempted" };
|
|
7750
|
+
const edgeEntry = edgeScreen.get(fact.id);
|
|
7751
|
+
const ask = (questions) => callClassify(
|
|
7752
|
+
this.options,
|
|
7753
|
+
{ operation: "ontologyBackfill", entityId, trigger, meter },
|
|
7754
|
+
{ state: classifierStateForFact(fact), questions }
|
|
7755
|
+
);
|
|
7662
7756
|
let response;
|
|
7757
|
+
let screened = edgeEntry !== void 0;
|
|
7663
7758
|
try {
|
|
7664
|
-
|
|
7665
|
-
|
|
7666
|
-
|
|
7667
|
-
|
|
7668
|
-
|
|
7759
|
+
try {
|
|
7760
|
+
response = await ask({ okf_type: question, ...edgeEntry?.questions ?? {} });
|
|
7761
|
+
} catch (err) {
|
|
7762
|
+
if (!edgeEntry || err instanceof WikiBudgetExhausted || !isContextOverflowError(err)) throw err;
|
|
7763
|
+
response = await ask({ okf_type: question });
|
|
7764
|
+
screened = false;
|
|
7765
|
+
retriedFacts.add(fact.id);
|
|
7766
|
+
}
|
|
7669
7767
|
} catch (err) {
|
|
7670
7768
|
if (err instanceof WikiBudgetExhausted) {
|
|
7671
7769
|
stopped ?? (stopped = err);
|
|
@@ -7679,17 +7777,54 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7679
7777
|
if (checked.answer.kind !== "choice") return { fact, kind: "invalid", reason: "kind_mismatch" };
|
|
7680
7778
|
if (isReservedAbstainSlug(checked.answer.choice)) return { fact, kind: "abstain" };
|
|
7681
7779
|
if (checked.answer.confidence < minConfidence) return { fact, kind: "low_confidence" };
|
|
7682
|
-
|
|
7780
|
+
const okfType = checked.answer.choice;
|
|
7781
|
+
if (!screened || !edgeEntry || typeof edgeMinConfidence !== "number") return { fact, kind: "accepted", okfType };
|
|
7782
|
+
const floor = edgeMinConfidence;
|
|
7783
|
+
const edges = [];
|
|
7784
|
+
const edgeCandidateIds = /* @__PURE__ */ Object.create(null);
|
|
7785
|
+
let evaluated = 0;
|
|
7786
|
+
let uncertain = 0;
|
|
7787
|
+
let invalid = 0;
|
|
7788
|
+
let missing = 0;
|
|
7789
|
+
for (const [key, { definitions, candidate }] of edgeEntry.keyMap) {
|
|
7790
|
+
if (!definitions.some((d) => typeSatisfies(d.source_type, okfType, manifest))) continue;
|
|
7791
|
+
evaluated++;
|
|
7792
|
+
const answer = validateClassifierAnswer(response, key, edgeEntry.questions[key]);
|
|
7793
|
+
if (!answer.ok) {
|
|
7794
|
+
if (answer.reason === "missing_answer") missing++;
|
|
7795
|
+
else invalid++;
|
|
7796
|
+
continue;
|
|
7797
|
+
}
|
|
7798
|
+
if (answer.answer.kind !== "binary") {
|
|
7799
|
+
invalid++;
|
|
7800
|
+
continue;
|
|
7801
|
+
}
|
|
7802
|
+
const p = answer.answer.probability;
|
|
7803
|
+
if (p > 0.5 && p >= floor) {
|
|
7804
|
+
edges.push({ edge_type: definitions[0].type, target_title: candidate.title });
|
|
7805
|
+
edgeCandidateIds[normalizeTitleKey(candidate.title)] = candidate.id;
|
|
7806
|
+
} else if (p < 0.5 && 1 - p >= floor) continue;
|
|
7807
|
+
else uncertain++;
|
|
7808
|
+
}
|
|
7809
|
+
const edgeStats = { uncertain, invalid, missing, allMissing: evaluated > 0 && missing === evaluated };
|
|
7810
|
+
if (edgeStats.allMissing) return { fact, kind: "accepted", okfType, edgeStats };
|
|
7811
|
+
if (uncertain > 0 || invalid > 0 || missing > 0) return { fact, kind: "accepted", okfType, fallthrough: true, edgeStats };
|
|
7812
|
+
return { fact, kind: "accepted", okfType, ...edges.length > 0 ? { edges, edgeCandidateIds } : {} };
|
|
7683
7813
|
}),
|
|
7684
7814
|
concurrency
|
|
7685
7815
|
);
|
|
7686
7816
|
const escalate = this.resolveSystemOneOnLowConfidence() === "llm";
|
|
7687
|
-
const
|
|
7688
|
-
const
|
|
7817
|
+
const isEscalated = (o) => o.kind === "accepted" && o.fallthrough === true || escalate && (o.kind === "abstain" || o.kind === "low_confidence");
|
|
7818
|
+
const escalated = outcomes.filter(isEscalated).map((o) => o.fact);
|
|
7689
7819
|
const attempted = outcomes.filter((o) => o.kind !== "threw" && o.kind !== "unattempted" && !isEscalated(o)).map((o) => o.fact);
|
|
7690
7820
|
const unattemptedCount = outcomes.filter((o) => o.kind === "unattempted").length;
|
|
7691
7821
|
const skipped = outcomes.filter((o) => o.kind === "threw" || o.kind === "overflow_skip").length;
|
|
7692
|
-
const classifications = outcomes.filter((o) => o.kind === "accepted").map((o) => ({
|
|
7822
|
+
const classifications = outcomes.filter((o) => o.kind === "accepted" && o.fallthrough !== true).map((o) => ({
|
|
7823
|
+
id: o.fact.id,
|
|
7824
|
+
okf_type: o.okfType,
|
|
7825
|
+
// An outcome carries `edges` only when the site is 'auto'.
|
|
7826
|
+
...o.edges && o.edges.length > 0 ? { edges: o.edges, edgeCandidateIds: o.edgeCandidateIds } : {}
|
|
7827
|
+
}));
|
|
7693
7828
|
const invalidCount = outcomes.filter((o) => o.kind === "invalid").length;
|
|
7694
7829
|
const abstainCount = outcomes.filter((o) => o.kind === "abstain" && !isEscalated(o)).length;
|
|
7695
7830
|
let typed = 0;
|
|
@@ -7714,7 +7849,21 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7714
7849
|
const diagBuffer = new DiagnosticBuffer();
|
|
7715
7850
|
const diagBase = { entityId, operation: "ontologyBackfill", trigger };
|
|
7716
7851
|
for (const o of outcomes) {
|
|
7717
|
-
if (o.
|
|
7852
|
+
if (retriedFacts.has(o.fact.id)) {
|
|
7853
|
+
diagBuffer.push({ ...diagBase, code: "context_overflow_skipped", detail: { factId: o.fact.id, reason: "edge_screen_overflow_retry" } });
|
|
7854
|
+
}
|
|
7855
|
+
if (o.kind === "accepted" && o.edgeStats) {
|
|
7856
|
+
const { invalid, missing, allMissing } = o.edgeStats;
|
|
7857
|
+
const code = allMissing || invalid > 0 || missing > 0 ? "classification_invalid" : "classification_low_confidence";
|
|
7858
|
+
diagBuffer.push({
|
|
7859
|
+
...diagBase,
|
|
7860
|
+
code,
|
|
7861
|
+
detail: {
|
|
7862
|
+
factId: o.fact.id,
|
|
7863
|
+
reason: allMissing ? "edge_answers_missing" : code === "classification_invalid" ? "edge_answer_invalid" : "edge_uncertain"
|
|
7864
|
+
}
|
|
7865
|
+
});
|
|
7866
|
+
} else if (o.kind === "abstain") {
|
|
7718
7867
|
if (isEscalated(o)) continue;
|
|
7719
7868
|
diagBuffer.push({ ...diagBase, code: "classification_abstained", detail: { factId: o.fact.id, writer: "classifier" } });
|
|
7720
7869
|
} else if (o.kind === "low_confidence") {
|
|
@@ -7849,16 +7998,41 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7849
7998
|
});
|
|
7850
7999
|
titleIndex.set(normalizeTitleKey(fact.title), { id: fact.id, okf_type: normalized.okf_type });
|
|
7851
8000
|
if (normalized.edges.length > 0) {
|
|
7852
|
-
pendingEdges.push({
|
|
8001
|
+
pendingEdges.push({
|
|
8002
|
+
sourceId: fact.id,
|
|
8003
|
+
sourceType: normalized.okf_type,
|
|
8004
|
+
edges: normalized.edges,
|
|
8005
|
+
candidateIds: classification.edgeCandidateIds
|
|
8006
|
+
});
|
|
7853
8007
|
}
|
|
7854
8008
|
}
|
|
7855
8009
|
for (const item of pendingEdges) {
|
|
7856
8010
|
const resolveDrops = [];
|
|
8011
|
+
let edgesToResolve = item.edges;
|
|
8012
|
+
const screenedIds = item.candidateIds;
|
|
8013
|
+
if (screenedIds) {
|
|
8014
|
+
edgesToResolve = [];
|
|
8015
|
+
for (const edge of item.edges) {
|
|
8016
|
+
const key = normalizeTitleKey(edge.target_title);
|
|
8017
|
+
const screened = screenedIds[key];
|
|
8018
|
+
if (screened !== void 0 && titleIndex.get(key)?.id !== screened) {
|
|
8019
|
+
resolveDrops.push({
|
|
8020
|
+
reason: "target_not_found",
|
|
8021
|
+
sourceId: item.sourceId,
|
|
8022
|
+
edgeType: edge.edge_type,
|
|
8023
|
+
sourceNodeType: item.sourceType,
|
|
8024
|
+
targetNodeType: null
|
|
8025
|
+
});
|
|
8026
|
+
} else {
|
|
8027
|
+
edgesToResolve.push(edge);
|
|
8028
|
+
}
|
|
8029
|
+
}
|
|
8030
|
+
}
|
|
7857
8031
|
const added = await ontologyService.resolveAndPersistEdges(
|
|
7858
8032
|
entityId,
|
|
7859
8033
|
item.sourceId,
|
|
7860
8034
|
item.sourceType,
|
|
7861
|
-
|
|
8035
|
+
edgesToResolve,
|
|
7862
8036
|
manifest,
|
|
7863
8037
|
titleIndex,
|
|
7864
8038
|
tx,
|