@equationalapplications/core-llm-wiki 9.11.0 → 9.13.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-4TG7RQF6.mjs} +287 -24
- package/dist/chunk-4TG7RQF6.mjs.map +1 -0
- package/dist/index.d.mts +32 -3
- package/dist/index.d.ts +32 -3
- package/dist/index.js +288 -21
- 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-DkKZcrhE.d.mts} +41 -6
- package/dist/{testing-DFyghdSG.d.ts → testing-DkKZcrhE.d.ts} +41 -6
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +284 -21
- 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
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-
|
|
2
|
-
export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as LLMProvider, N as LibrarianConfig, P as LibrarianGateConfig, Q as LockedMaintenanceJob, T as MaintenanceJob, U as MaintenanceStopReason, V as MemoryDumpEntity, X as MigrationPolicy, Y as ONTOLOGY_ABSTAIN_SENTINEL, Z as ONTOLOGY_BACKFILL_BATCH_SIZE, _ as ONTOLOGY_BACKFILL_RECHECK_MS, $ as OntologyBackfillResult, a0 as OntologyEdgeType, a1 as OntologyManifest, a2 as OntologyNodeType, a3 as OntologyPromptContext, a4 as OntologyUpdates, a5 as PendingMaintenance, a6 as PendingMigrationWork, a7 as PendingSourceStatus, a8 as PromptOverrides, a9 as PromptService, aa as PrunePartialFailureError, ab as ReembedResult, ac as RememberInput, ad as RunPendingMaintenanceOptions, ae as RunPendingMaintenanceResult, af as SourcePassage, ag as StoreSourceResult, ah as StoredSource, ai as StoredSourceDump, aj as StoredSourceSummary, ak as SupersedeReplacement, al as SystemOneConfig, am as SystemOneThresholdSite, an as VectorRanker, ao as VectorRankerFallback, ap as VectorRankerRankArgs, aq as VectorRankerSemanticResult, ar as WikiBusyError, as as WikiBusyOperation, at as WikiCheckpoint, au as WikiDiagnostic, av as WikiDiagnosticCode, aw as WikiDiagnosticDetail, ax as WikiDiagnosticOperation, ay as WikiDiagnosticSeverity, az as WikiDiagnosticTrigger, aA as WikiDraftNotFound, aB as WikiDuplicateHashError, aC as WikiEdge, aD as WikiEvent, aE as WikiExternalDeletionError, aF as WikiFact, aG as WikiGraphNodeOwnershipConflict, aH as WikiIngestEmptyError, aI as WikiInstructions, aJ as WikiInvalidReadOptions, aK as WikiLintReport, aL as WikiMemoryTestAccess, aM as WikiMigrationRequiredError, aN as WikiOutboxEvent, aO as WikiParseError, aP as WikiSearchUnavailableError, aQ as WikiSourcePointer, aR as WikiSourceRefHashCollision, aS as WikiStrictOntologyViolation, aT as WikiSupersedeError, aU as WikiSupersedeReason, aV as WikiTask, aW as WikiTransactionError, aX as isReservedAbstainSlug, aY as isWikiSearchUnavailableError, aZ as validateManifest } from './testing-
|
|
1
|
+
import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-DkKZcrhE.mjs';
|
|
2
|
+
export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as LLMProvider, N as LibrarianConfig, P as LibrarianGateConfig, Q as LockedMaintenanceJob, T as MaintenanceJob, U as MaintenanceStopReason, V as MemoryDumpEntity, X as MigrationPolicy, Y as ONTOLOGY_ABSTAIN_SENTINEL, Z as ONTOLOGY_BACKFILL_BATCH_SIZE, _ as ONTOLOGY_BACKFILL_RECHECK_MS, $ as OntologyBackfillResult, a0 as OntologyEdgeType, a1 as OntologyManifest, a2 as OntologyNodeType, a3 as OntologyPromptContext, a4 as OntologyUpdates, a5 as PendingMaintenance, a6 as PendingMigrationWork, a7 as PendingSourceStatus, a8 as PromptOverrides, a9 as PromptService, aa as PrunePartialFailureError, ab as ReembedResult, ac as RememberInput, ad as RunPendingMaintenanceOptions, ae as RunPendingMaintenanceResult, af as SourcePassage, ag as StoreSourceResult, ah as StoredSource, ai as StoredSourceDump, aj as StoredSourceSummary, ak as SupersedeReplacement, al as SystemOneConfig, am as SystemOneThresholdSite, an as VectorRanker, ao as VectorRankerFallback, ap as VectorRankerRankArgs, aq as VectorRankerSemanticResult, ar as WikiBusyError, as as WikiBusyOperation, at as WikiCheckpoint, au as WikiDiagnostic, av as WikiDiagnosticCode, aw as WikiDiagnosticDetail, ax as WikiDiagnosticOperation, ay as WikiDiagnosticSeverity, az as WikiDiagnosticTrigger, aA as WikiDraftNotFound, aB as WikiDuplicateHashError, aC as WikiEdge, aD as WikiEvent, aE as WikiExternalDeletionError, aF as WikiFact, aG as WikiGraphNodeOwnershipConflict, aH as WikiIngestEmptyError, aI as WikiInstructions, aJ as WikiInvalidReadOptions, aK as WikiLintReport, aL as WikiMemoryTestAccess, aM as WikiMigrationRequiredError, aN as WikiOutboxEvent, aO as WikiParseError, aP as WikiSearchUnavailableError, aQ as WikiSourcePointer, aR as WikiSourceRefHashCollision, aS as WikiStrictOntologyViolation, aT as WikiSupersedeError, aU as WikiSupersedeReason, aV as WikiTask, aW as WikiTransactionError, aX as isReservedAbstainSlug, aY as isWikiSearchUnavailableError, aZ as validateManifest } from './testing-DkKZcrhE.mjs';
|
|
3
3
|
import { OkfFile } from '@equationalapplications/core-okf';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -234,6 +234,18 @@ declare function warnOnce(message: string): void;
|
|
|
234
234
|
* `??` throughout — falsy config values never participate by accident.
|
|
235
235
|
*/
|
|
236
236
|
declare function resolveSystemOneTyping(config: WikiConfig | undefined, classifierCallOption?: 'auto' | 'llm'): 'auto' | 'llm';
|
|
237
|
+
/**
|
|
238
|
+
* Edge-mode resolution (specs/edge-suggestions-system-one §2): `systemOne.edges`
|
|
239
|
+
* → `'llm'`. A present non-`'auto'`/non-`'llm'` value warns once and is treated
|
|
240
|
+
* as unset. No legacy chain and no call option.
|
|
241
|
+
*/
|
|
242
|
+
declare function resolveSystemOneEdges(config: WikiConfig | undefined): 'auto' | 'llm';
|
|
243
|
+
/**
|
|
244
|
+
* Resolve-mode resolution (specs/resolution-system-one §2): `systemOne.resolve`
|
|
245
|
+
* → `'llm'`. A present non-`'auto'`/non-`'llm'` value warns once and is treated
|
|
246
|
+
* as unset. No legacy chain and no call option.
|
|
247
|
+
*/
|
|
248
|
+
declare function resolveSystemOneResolve(config: WikiConfig | undefined): 'auto' | 'llm';
|
|
237
249
|
/** Engine default confidence floor for classifier typing. */
|
|
238
250
|
declare const DEFAULT_TYPING_MIN_CONFIDENCE: 0.5;
|
|
239
251
|
/**
|
|
@@ -243,10 +255,27 @@ declare const DEFAULT_TYPING_MIN_CONFIDENCE: 0.5;
|
|
|
243
255
|
* typing path reads this; call it there, never on the generative path.
|
|
244
256
|
*/
|
|
245
257
|
declare function resolveTypingMinConfidence(config: WikiConfig | undefined): number;
|
|
258
|
+
/**
|
|
259
|
+
* Edge-screen floor (specs/edge-suggestions-system-one §3): returns the
|
|
260
|
+
* `systemOne.minConfidence.edges` floor only when the edge mode resolves
|
|
261
|
+
* `'auto'` and the floor is a finite number in [0.5, 1]. There is no default
|
|
262
|
+
* floor: a missing or out-of-domain value warns once and returns `undefined`
|
|
263
|
+
* (the site then resolves `'llm'`). Under `'llm'` or unset it reads nothing.
|
|
264
|
+
*/
|
|
265
|
+
declare function resolveEdgesMinConfidence(config: WikiConfig | undefined): number | undefined;
|
|
266
|
+
/**
|
|
267
|
+
* Resolution-screen floor (specs/resolution-system-one §3): returns the
|
|
268
|
+
* `systemOne.minConfidence.resolve` floor only when the resolve mode resolves
|
|
269
|
+
* `'auto'` and the floor is a finite number in [0.5, 1]. There is no default
|
|
270
|
+
* floor: a missing or out-of-domain value warns once and returns `undefined`
|
|
271
|
+
* (the site then resolves `'llm'`). Under `'llm'` or unset it reads nothing.
|
|
272
|
+
* The floor is mandatory because a wrong NOOP drops a live fact.
|
|
273
|
+
*/
|
|
274
|
+
declare function resolveResolveMinConfidence(config: WikiConfig | undefined): number | undefined;
|
|
246
275
|
|
|
247
276
|
declare const ONTOLOGY_BACKFILL_SYSTEM_PROMPT = "You are a knowledge classification agent. You will receive existing memory facts that currently have no ontology type. For each input fact { \"id\", \"title\", \"body\", \"tags\" }, assign the best matching okf_type from the ontology manifest and optionally propose edges to related facts by title.\nReturn ONLY a valid JSON object matching this schema:\n{\n \"classifications\": [\n { \"id\": \"string (input fact id, copied verbatim)\", \"okf_type\": \"string (manifest node type slug)\", \"edges\": [{ \"edge_type\": \"string\", \"target_title\": \"string\" }] }\n ]\n}\nIf no manifest type fits a fact, assign the closest type the fact is an example of; omit that fact from \"classifications\" only when no type applies even broadly. Use the manifest slug EXACTLY as spelled (spelling variants are folded to the manifest form).\nWhen echoing an existing fact's title verbatim into \"target_title\", preserve every JSON escape sequence (\\\", \\n, \\\\, \\/) exactly as it appeared in the input body \u2014 do not strip backslashes, do not add unescaped quotes. Do not return markdown, just raw JSON.";
|
|
248
277
|
|
|
249
278
|
declare function createWiki(db: SQLiteAdapter, options: WikiOptions): WikiMemory;
|
|
250
279
|
|
|
251
|
-
export { DEFAULT_CHUNK_OVERLAP, DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_ONTOLOGY_JOB_BATCH_SIZE, DEFAULT_SETUP_BUDGET_MS, DEFAULT_TYPING_MIN_CONFIDENCE, EMBED_CHARS_CEILING, FormatContextOptions, FormattedMemoryDump, GraphNeighborhood, HEAL_ANCHORS_PER_CANDIDATE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, MemoryBundle, MemoryDump, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, OntologyConfig, OntologyMode, ReadOptions, SQLiteAdapter, WikiConfig, WikiMemory, WikiOptions, buildOntologyPromptAppendix, chunkText, configureRandomSource, createWiki, estimateTokensWith, formatContext, formatGraphContext, formatMemoryDump, formatOkfBundle, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, parseEmbedding, parseOkfBundle, resolveContextBudget, resolveDefaultChunkLength, resolveMaxPromptChars, resolveOntologyJobDefaults, resolveSystemOneTyping, resolveTypingMinConfidence, safeSlice, validUsage, validateLibrarianPromptTemplate, warnOnce };
|
|
280
|
+
export { DEFAULT_CHUNK_OVERLAP, DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_ONTOLOGY_JOB_BATCH_SIZE, DEFAULT_SETUP_BUDGET_MS, DEFAULT_TYPING_MIN_CONFIDENCE, EMBED_CHARS_CEILING, FormatContextOptions, FormattedMemoryDump, GraphNeighborhood, HEAL_ANCHORS_PER_CANDIDATE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, MemoryBundle, MemoryDump, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, OntologyConfig, OntologyMode, ReadOptions, SQLiteAdapter, WikiConfig, WikiMemory, WikiOptions, buildOntologyPromptAppendix, chunkText, configureRandomSource, createWiki, estimateTokensWith, formatContext, formatGraphContext, formatMemoryDump, formatOkfBundle, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, parseEmbedding, parseOkfBundle, resolveContextBudget, resolveDefaultChunkLength, resolveEdgesMinConfidence, resolveMaxPromptChars, resolveOntologyJobDefaults, resolveResolveMinConfidence, resolveSystemOneEdges, resolveSystemOneResolve, resolveSystemOneTyping, resolveTypingMinConfidence, safeSlice, validUsage, validateLibrarianPromptTemplate, warnOnce };
|
|
252
281
|
export type { ContextBudget, FormatOkfBundleOptions, LibrarianOptions, LibrarianPromptVariables, OkfFormatProfile, OkfImportOptions };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-
|
|
2
|
-
export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as LLMProvider, N as LibrarianConfig, P as LibrarianGateConfig, Q as LockedMaintenanceJob, T as MaintenanceJob, U as MaintenanceStopReason, V as MemoryDumpEntity, X as MigrationPolicy, Y as ONTOLOGY_ABSTAIN_SENTINEL, Z as ONTOLOGY_BACKFILL_BATCH_SIZE, _ as ONTOLOGY_BACKFILL_RECHECK_MS, $ as OntologyBackfillResult, a0 as OntologyEdgeType, a1 as OntologyManifest, a2 as OntologyNodeType, a3 as OntologyPromptContext, a4 as OntologyUpdates, a5 as PendingMaintenance, a6 as PendingMigrationWork, a7 as PendingSourceStatus, a8 as PromptOverrides, a9 as PromptService, aa as PrunePartialFailureError, ab as ReembedResult, ac as RememberInput, ad as RunPendingMaintenanceOptions, ae as RunPendingMaintenanceResult, af as SourcePassage, ag as StoreSourceResult, ah as StoredSource, ai as StoredSourceDump, aj as StoredSourceSummary, ak as SupersedeReplacement, al as SystemOneConfig, am as SystemOneThresholdSite, an as VectorRanker, ao as VectorRankerFallback, ap as VectorRankerRankArgs, aq as VectorRankerSemanticResult, ar as WikiBusyError, as as WikiBusyOperation, at as WikiCheckpoint, au as WikiDiagnostic, av as WikiDiagnosticCode, aw as WikiDiagnosticDetail, ax as WikiDiagnosticOperation, ay as WikiDiagnosticSeverity, az as WikiDiagnosticTrigger, aA as WikiDraftNotFound, aB as WikiDuplicateHashError, aC as WikiEdge, aD as WikiEvent, aE as WikiExternalDeletionError, aF as WikiFact, aG as WikiGraphNodeOwnershipConflict, aH as WikiIngestEmptyError, aI as WikiInstructions, aJ as WikiInvalidReadOptions, aK as WikiLintReport, aL as WikiMemoryTestAccess, aM as WikiMigrationRequiredError, aN as WikiOutboxEvent, aO as WikiParseError, aP as WikiSearchUnavailableError, aQ as WikiSourcePointer, aR as WikiSourceRefHashCollision, aS as WikiStrictOntologyViolation, aT as WikiSupersedeError, aU as WikiSupersedeReason, aV as WikiTask, aW as WikiTransactionError, aX as isReservedAbstainSlug, aY as isWikiSearchUnavailableError, aZ as validateManifest } from './testing-
|
|
1
|
+
import { M as MemoryBundle, F as FormatContextOptions, G as GraphNeighborhood, a as MemoryDump, b as FormattedMemoryDump, O as OntologyMode, W as WikiConfig, R as ReadOptions, c as OntologyConfig, S as SQLiteAdapter, d as WikiOptions, e as WikiMemory } from './testing-DkKZcrhE.js';
|
|
2
|
+
export { C as CLASSIFIER_MAX_CHOICES, f as CheckpointIncompleteError, g as ChunkFailure, h as ClassifierAnswer, i as ClassifierQuestion, j as ClassifyRequest, k as ClassifyResponse, D as DegradedRecord, l as DraftPage, E as EmbedFactResult, m as EmbedFailureKind, n as EmbeddingMarkerKind, o as EntityMaintenanceReport, p as EntityStatus, q as EraseReport, r as EraseStepError, s as ExtractedFact, t as ExtractedFactEdge, u as ExtractedFactWithOntology, v as ExtractedTask, w as ForgetParams, x as ForgetResult, y as GraphTraversalOptions, z as GroundingConfig, H as HEAL_BATCH_SIZE, A as HEAL_RECHECK_MS, B as HOOK_TIMEOUT_MARKER, I as HealResult, J as ImportDumpResult, K as IngestDocumentResult, L as LLMProvider, N as LibrarianConfig, P as LibrarianGateConfig, Q as LockedMaintenanceJob, T as MaintenanceJob, U as MaintenanceStopReason, V as MemoryDumpEntity, X as MigrationPolicy, Y as ONTOLOGY_ABSTAIN_SENTINEL, Z as ONTOLOGY_BACKFILL_BATCH_SIZE, _ as ONTOLOGY_BACKFILL_RECHECK_MS, $ as OntologyBackfillResult, a0 as OntologyEdgeType, a1 as OntologyManifest, a2 as OntologyNodeType, a3 as OntologyPromptContext, a4 as OntologyUpdates, a5 as PendingMaintenance, a6 as PendingMigrationWork, a7 as PendingSourceStatus, a8 as PromptOverrides, a9 as PromptService, aa as PrunePartialFailureError, ab as ReembedResult, ac as RememberInput, ad as RunPendingMaintenanceOptions, ae as RunPendingMaintenanceResult, af as SourcePassage, ag as StoreSourceResult, ah as StoredSource, ai as StoredSourceDump, aj as StoredSourceSummary, ak as SupersedeReplacement, al as SystemOneConfig, am as SystemOneThresholdSite, an as VectorRanker, ao as VectorRankerFallback, ap as VectorRankerRankArgs, aq as VectorRankerSemanticResult, ar as WikiBusyError, as as WikiBusyOperation, at as WikiCheckpoint, au as WikiDiagnostic, av as WikiDiagnosticCode, aw as WikiDiagnosticDetail, ax as WikiDiagnosticOperation, ay as WikiDiagnosticSeverity, az as WikiDiagnosticTrigger, aA as WikiDraftNotFound, aB as WikiDuplicateHashError, aC as WikiEdge, aD as WikiEvent, aE as WikiExternalDeletionError, aF as WikiFact, aG as WikiGraphNodeOwnershipConflict, aH as WikiIngestEmptyError, aI as WikiInstructions, aJ as WikiInvalidReadOptions, aK as WikiLintReport, aL as WikiMemoryTestAccess, aM as WikiMigrationRequiredError, aN as WikiOutboxEvent, aO as WikiParseError, aP as WikiSearchUnavailableError, aQ as WikiSourcePointer, aR as WikiSourceRefHashCollision, aS as WikiStrictOntologyViolation, aT as WikiSupersedeError, aU as WikiSupersedeReason, aV as WikiTask, aW as WikiTransactionError, aX as isReservedAbstainSlug, aY as isWikiSearchUnavailableError, aZ as validateManifest } from './testing-DkKZcrhE.js';
|
|
3
3
|
import { OkfFile } from '@equationalapplications/core-okf';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -234,6 +234,18 @@ declare function warnOnce(message: string): void;
|
|
|
234
234
|
* `??` throughout — falsy config values never participate by accident.
|
|
235
235
|
*/
|
|
236
236
|
declare function resolveSystemOneTyping(config: WikiConfig | undefined, classifierCallOption?: 'auto' | 'llm'): 'auto' | 'llm';
|
|
237
|
+
/**
|
|
238
|
+
* Edge-mode resolution (specs/edge-suggestions-system-one §2): `systemOne.edges`
|
|
239
|
+
* → `'llm'`. A present non-`'auto'`/non-`'llm'` value warns once and is treated
|
|
240
|
+
* as unset. No legacy chain and no call option.
|
|
241
|
+
*/
|
|
242
|
+
declare function resolveSystemOneEdges(config: WikiConfig | undefined): 'auto' | 'llm';
|
|
243
|
+
/**
|
|
244
|
+
* Resolve-mode resolution (specs/resolution-system-one §2): `systemOne.resolve`
|
|
245
|
+
* → `'llm'`. A present non-`'auto'`/non-`'llm'` value warns once and is treated
|
|
246
|
+
* as unset. No legacy chain and no call option.
|
|
247
|
+
*/
|
|
248
|
+
declare function resolveSystemOneResolve(config: WikiConfig | undefined): 'auto' | 'llm';
|
|
237
249
|
/** Engine default confidence floor for classifier typing. */
|
|
238
250
|
declare const DEFAULT_TYPING_MIN_CONFIDENCE: 0.5;
|
|
239
251
|
/**
|
|
@@ -243,10 +255,27 @@ declare const DEFAULT_TYPING_MIN_CONFIDENCE: 0.5;
|
|
|
243
255
|
* typing path reads this; call it there, never on the generative path.
|
|
244
256
|
*/
|
|
245
257
|
declare function resolveTypingMinConfidence(config: WikiConfig | undefined): number;
|
|
258
|
+
/**
|
|
259
|
+
* Edge-screen floor (specs/edge-suggestions-system-one §3): returns the
|
|
260
|
+
* `systemOne.minConfidence.edges` floor only when the edge mode resolves
|
|
261
|
+
* `'auto'` and the floor is a finite number in [0.5, 1]. There is no default
|
|
262
|
+
* floor: a missing or out-of-domain value warns once and returns `undefined`
|
|
263
|
+
* (the site then resolves `'llm'`). Under `'llm'` or unset it reads nothing.
|
|
264
|
+
*/
|
|
265
|
+
declare function resolveEdgesMinConfidence(config: WikiConfig | undefined): number | undefined;
|
|
266
|
+
/**
|
|
267
|
+
* Resolution-screen floor (specs/resolution-system-one §3): returns the
|
|
268
|
+
* `systemOne.minConfidence.resolve` floor only when the resolve mode resolves
|
|
269
|
+
* `'auto'` and the floor is a finite number in [0.5, 1]. There is no default
|
|
270
|
+
* floor: a missing or out-of-domain value warns once and returns `undefined`
|
|
271
|
+
* (the site then resolves `'llm'`). Under `'llm'` or unset it reads nothing.
|
|
272
|
+
* The floor is mandatory because a wrong NOOP drops a live fact.
|
|
273
|
+
*/
|
|
274
|
+
declare function resolveResolveMinConfidence(config: WikiConfig | undefined): number | undefined;
|
|
246
275
|
|
|
247
276
|
declare const ONTOLOGY_BACKFILL_SYSTEM_PROMPT = "You are a knowledge classification agent. You will receive existing memory facts that currently have no ontology type. For each input fact { \"id\", \"title\", \"body\", \"tags\" }, assign the best matching okf_type from the ontology manifest and optionally propose edges to related facts by title.\nReturn ONLY a valid JSON object matching this schema:\n{\n \"classifications\": [\n { \"id\": \"string (input fact id, copied verbatim)\", \"okf_type\": \"string (manifest node type slug)\", \"edges\": [{ \"edge_type\": \"string\", \"target_title\": \"string\" }] }\n ]\n}\nIf no manifest type fits a fact, assign the closest type the fact is an example of; omit that fact from \"classifications\" only when no type applies even broadly. Use the manifest slug EXACTLY as spelled (spelling variants are folded to the manifest form).\nWhen echoing an existing fact's title verbatim into \"target_title\", preserve every JSON escape sequence (\\\", \\n, \\\\, \\/) exactly as it appeared in the input body \u2014 do not strip backslashes, do not add unescaped quotes. Do not return markdown, just raw JSON.";
|
|
248
277
|
|
|
249
278
|
declare function createWiki(db: SQLiteAdapter, options: WikiOptions): WikiMemory;
|
|
250
279
|
|
|
251
|
-
export { DEFAULT_CHUNK_OVERLAP, DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_ONTOLOGY_JOB_BATCH_SIZE, DEFAULT_SETUP_BUDGET_MS, DEFAULT_TYPING_MIN_CONFIDENCE, EMBED_CHARS_CEILING, FormatContextOptions, FormattedMemoryDump, GraphNeighborhood, HEAL_ANCHORS_PER_CANDIDATE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, MemoryBundle, MemoryDump, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, OntologyConfig, OntologyMode, ReadOptions, SQLiteAdapter, WikiConfig, WikiMemory, WikiOptions, buildOntologyPromptAppendix, chunkText, configureRandomSource, createWiki, estimateTokensWith, formatContext, formatGraphContext, formatMemoryDump, formatOkfBundle, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, parseEmbedding, parseOkfBundle, resolveContextBudget, resolveDefaultChunkLength, resolveMaxPromptChars, resolveOntologyJobDefaults, resolveSystemOneTyping, resolveTypingMinConfidence, safeSlice, validUsage, validateLibrarianPromptTemplate, warnOnce };
|
|
280
|
+
export { DEFAULT_CHUNK_OVERLAP, DEFAULT_LIBRARIAN_SYNTHESIS_PROMPT, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_ONTOLOGY_JOB_BATCH_SIZE, DEFAULT_SETUP_BUDGET_MS, DEFAULT_TYPING_MIN_CONFIDENCE, EMBED_CHARS_CEILING, FormatContextOptions, FormattedMemoryDump, GraphNeighborhood, HEAL_ANCHORS_PER_CANDIDATE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, MemoryBundle, MemoryDump, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, OntologyConfig, OntologyMode, ReadOptions, SQLiteAdapter, WikiConfig, WikiMemory, WikiOptions, buildOntologyPromptAppendix, chunkText, configureRandomSource, createWiki, estimateTokensWith, formatContext, formatGraphContext, formatMemoryDump, formatOkfBundle, hydrateLibrarianPrompt, mapLibrarianOptionsToReadOptions, parseEmbedding, parseOkfBundle, resolveContextBudget, resolveDefaultChunkLength, resolveEdgesMinConfidence, resolveMaxPromptChars, resolveOntologyJobDefaults, resolveResolveMinConfidence, resolveSystemOneEdges, resolveSystemOneResolve, resolveSystemOneTyping, resolveTypingMinConfidence, safeSlice, validUsage, validateLibrarianPromptTemplate, warnOnce };
|
|
252
281
|
export type { ContextBudget, FormatOkfBundleOptions, LibrarianOptions, LibrarianPromptVariables, OkfFormatProfile, OkfImportOptions };
|
package/dist/index.js
CHANGED
|
@@ -9163,6 +9163,26 @@ function resolveSystemOneTyping(config, classifierCallOption) {
|
|
|
9163
9163
|
}
|
|
9164
9164
|
return classifierCallOption ?? (systemOneValid ? systemOne.typing : void 0) ?? (legacyValid ? legacy : void 0) ?? "llm";
|
|
9165
9165
|
}
|
|
9166
|
+
function resolveSystemOneEdges(config) {
|
|
9167
|
+
const edges = config?.systemOne?.edges;
|
|
9168
|
+
if (edges !== void 0 && !isTypingMode(edges)) {
|
|
9169
|
+
warnOnce(
|
|
9170
|
+
`[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.`
|
|
9171
|
+
);
|
|
9172
|
+
return "llm";
|
|
9173
|
+
}
|
|
9174
|
+
return edges ?? "llm";
|
|
9175
|
+
}
|
|
9176
|
+
function resolveSystemOneResolve(config) {
|
|
9177
|
+
const resolve = config?.systemOne?.resolve;
|
|
9178
|
+
if (resolve !== void 0 && !isTypingMode(resolve)) {
|
|
9179
|
+
warnOnce(
|
|
9180
|
+
`[core-llm-wiki] systemOne: \`systemOne.resolve\` is ${formatConfigValue(resolve)}, which is not 'auto' or 'llm'. The key is treated as unset; the default ('llm') applies.`
|
|
9181
|
+
);
|
|
9182
|
+
return "llm";
|
|
9183
|
+
}
|
|
9184
|
+
return resolve ?? "llm";
|
|
9185
|
+
}
|
|
9166
9186
|
var DEFAULT_SHORTLIST_K = 10;
|
|
9167
9187
|
function resolveShortlistK(config) {
|
|
9168
9188
|
const k = config?.ontology?.shortlistK;
|
|
@@ -9192,6 +9212,25 @@ function resolveTypingMinConfidence(config) {
|
|
|
9192
9212
|
}
|
|
9193
9213
|
return (systemOneValid ? systemOneFloor : void 0) ?? (legacyValid ? legacyFloor : void 0) ?? DEFAULT_TYPING_MIN_CONFIDENCE;
|
|
9194
9214
|
}
|
|
9215
|
+
var isEdgesFloor = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0.5 && v <= 1;
|
|
9216
|
+
function resolveEdgesMinConfidence(config) {
|
|
9217
|
+
if (resolveSystemOneEdges(config) !== "auto") return void 0;
|
|
9218
|
+
const floor = config?.systemOne?.minConfidence?.edges;
|
|
9219
|
+
if (isEdgesFloor(floor)) return floor;
|
|
9220
|
+
warnOnce(
|
|
9221
|
+
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.`
|
|
9222
|
+
);
|
|
9223
|
+
return void 0;
|
|
9224
|
+
}
|
|
9225
|
+
function resolveResolveMinConfidence(config) {
|
|
9226
|
+
if (resolveSystemOneResolve(config) !== "auto") return void 0;
|
|
9227
|
+
const floor = config?.systemOne?.minConfidence?.resolve;
|
|
9228
|
+
if (isEdgesFloor(floor)) return floor;
|
|
9229
|
+
warnOnce(
|
|
9230
|
+
floor === void 0 ? "[core-llm-wiki] systemOne: `systemOne.minConfidence.resolve` is required when `systemOne.resolve` is 'auto'. A wrong NOOP drops a live fact, so there is no default floor. The resolution screen is off; resolution stays on the generative path." : `[core-llm-wiki] systemOne: \`systemOne.minConfidence.resolve\` is ${formatConfigValue(floor)}, which is not a finite number in [0.5, 1]. A wrong NOOP drops a live fact, so the resolution screen is off; resolution stays on the generative path.`
|
|
9231
|
+
);
|
|
9232
|
+
return void 0;
|
|
9233
|
+
}
|
|
9195
9234
|
|
|
9196
9235
|
// src/repositories/VectorRemovalRepository.ts
|
|
9197
9236
|
var CHUNK2 = 500;
|
|
@@ -10472,6 +10511,46 @@ async function gateCandidates(deps, ctx, candidates, cfg) {
|
|
|
10472
10511
|
}
|
|
10473
10512
|
|
|
10474
10513
|
// src/services/librarian/ops/resolve.ts
|
|
10514
|
+
async function screenResolveCandidates(ambiguous, mode, floor, ask) {
|
|
10515
|
+
const whole = (warnReason) => warnReason ? { settled: /* @__PURE__ */ new Map(), rest: ambiguous, warnReason } : { settled: /* @__PURE__ */ new Map(), rest: ambiguous };
|
|
10516
|
+
if (mode !== "auto") return whole();
|
|
10517
|
+
if (floor === void 0) return whole("no-floor");
|
|
10518
|
+
if (!ask) return whole("no-classifier");
|
|
10519
|
+
const settled = /* @__PURE__ */ new Map();
|
|
10520
|
+
const rest = [];
|
|
10521
|
+
for (const g of ambiguous) {
|
|
10522
|
+
const best = g.neighbours[0];
|
|
10523
|
+
if (!best) {
|
|
10524
|
+
rest.push(g);
|
|
10525
|
+
continue;
|
|
10526
|
+
}
|
|
10527
|
+
const question = {
|
|
10528
|
+
kind: "binary",
|
|
10529
|
+
instructions: `Does this candidate add NO information beyond neighbour ${best.ref} (a pure duplicate: same claims, no new content)?
|
|
10530
|
+
Neighbour ${best.ref} title: ${best.title}
|
|
10531
|
+
Neighbour ${best.ref} body: ${safeSlice(best.body, 0, OPS_NEIGHBOUR_BODY_CHARS)}`
|
|
10532
|
+
};
|
|
10533
|
+
let response;
|
|
10534
|
+
try {
|
|
10535
|
+
response = await ask({
|
|
10536
|
+
state: classifierStateForFact({ title: g.candidate.fact.title, body: g.candidate.fact.body, tags: [] }),
|
|
10537
|
+
questions: { [best.ref]: question }
|
|
10538
|
+
});
|
|
10539
|
+
} catch (err) {
|
|
10540
|
+
if (err instanceof WikiBudgetExhausted) {
|
|
10541
|
+
return { settled: /* @__PURE__ */ new Map(), rest: ambiguous, budgetStop: { requiredEstimate: err.requiredEstimate } };
|
|
10542
|
+
}
|
|
10543
|
+
return whole("classifier-threw");
|
|
10544
|
+
}
|
|
10545
|
+
const checked = validateClassifierAnswer(response, best.ref, question);
|
|
10546
|
+
if (checked.ok && checked.answer.kind === "binary" && checked.answer.probability >= floor) {
|
|
10547
|
+
settled.set(g, { op: "NOOP", targetId: best.id });
|
|
10548
|
+
} else {
|
|
10549
|
+
rest.push(g);
|
|
10550
|
+
}
|
|
10551
|
+
}
|
|
10552
|
+
return { settled, rest };
|
|
10553
|
+
}
|
|
10475
10554
|
function validateOp(raw, aliases) {
|
|
10476
10555
|
if (!raw || typeof raw !== "object") return null;
|
|
10477
10556
|
const r = raw;
|
|
@@ -10491,11 +10570,31 @@ function validateOp(raw, aliases) {
|
|
|
10491
10570
|
}
|
|
10492
10571
|
var aliasMapOf = (g) => new Map(g.neighbours.map((n) => [n.ref, n.id]));
|
|
10493
10572
|
async function runResolve(deps, ctx, ambiguous, budget) {
|
|
10494
|
-
const out = { ops: /* @__PURE__ */ new Map(), rejected: [], failed: [], overflowSkipped: [] };
|
|
10573
|
+
const out = { ops: /* @__PURE__ */ new Map(), rejected: [], failed: [], overflowSkipped: [], classifierSettled: [] };
|
|
10495
10574
|
if (ambiguous.length === 0) return out;
|
|
10496
10575
|
const { entityId, trigger } = ctx;
|
|
10576
|
+
const mode = resolveSystemOneResolve(deps.options.config);
|
|
10577
|
+
const floor = resolveResolveMinConfidence(deps.options.config);
|
|
10578
|
+
const provider = deps.options.llmProvider;
|
|
10579
|
+
const ask = mode === "auto" && typeof provider.classify === "function" ? (request) => callClassify(deps.options, { operation: "librarian", entityId, trigger, meter: ctx.meter }, request) : void 0;
|
|
10580
|
+
const screen = await screenResolveCandidates(ambiguous, mode, floor, ask);
|
|
10581
|
+
if (screen.budgetStop) return { ...out, budgetStop: screen.budgetStop };
|
|
10582
|
+
if (screen.warnReason === "no-classifier") {
|
|
10583
|
+
warnOnce(
|
|
10584
|
+
"[core-llm-wiki] systemOne: `systemOne.resolve` is 'auto' but the provider has no classify(); ambiguous candidates fall through to the generative resolve."
|
|
10585
|
+
);
|
|
10586
|
+
} else if (screen.warnReason === "classifier-threw") {
|
|
10587
|
+
warnOnce(
|
|
10588
|
+
"[core-llm-wiki] systemOne: `systemOne.resolve` is 'auto' but classify() threw during the resolve screen; ambiguous candidates fall through to the generative resolve."
|
|
10589
|
+
);
|
|
10590
|
+
}
|
|
10591
|
+
for (const [g, op] of screen.settled) {
|
|
10592
|
+
out.ops.set(g, op);
|
|
10593
|
+
out.classifierSettled.push(g.candidate.index);
|
|
10594
|
+
}
|
|
10595
|
+
if (screen.rest.length === 0) return out;
|
|
10497
10596
|
const outcome = await runBatched({
|
|
10498
|
-
items:
|
|
10597
|
+
items: screen.rest,
|
|
10499
10598
|
buildPrompt: (batch) => deps.promptService.buildOpsResolvePrompt(
|
|
10500
10599
|
batch.map((g, i) => ({
|
|
10501
10600
|
item: i,
|
|
@@ -10784,6 +10883,16 @@ var runOpsLibrarianPass = async (deps, ctx) => {
|
|
|
10784
10883
|
// (index into the merged extract batch)
|
|
10785
10884
|
});
|
|
10786
10885
|
}
|
|
10886
|
+
for (const itemIndex of res.classifierSettled) {
|
|
10887
|
+
diagnostics.push({
|
|
10888
|
+
entityId,
|
|
10889
|
+
operation: "librarian",
|
|
10890
|
+
trigger,
|
|
10891
|
+
code: "fact_deduplicated",
|
|
10892
|
+
detail: { itemIndex, reason: "classifier" }
|
|
10893
|
+
// (index into the merged extract batch)
|
|
10894
|
+
});
|
|
10895
|
+
}
|
|
10787
10896
|
if (res.budgetStop) {
|
|
10788
10897
|
diagnostics.discard();
|
|
10789
10898
|
return { processedThrough: null, factsWritten: 0, budgetStop: res.budgetStop };
|
|
@@ -12334,7 +12443,10 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12334
12443
|
return { ...zeroed, remaining: counts.eligible, deferred: counts.deferred };
|
|
12335
12444
|
}
|
|
12336
12445
|
const classifierMode = resolveSystemOneTyping(this.options.config, options?.classifier);
|
|
12446
|
+
const edgeMode = resolveSystemOneEdges(this.options.config);
|
|
12337
12447
|
const classify = this.options.llmProvider.classify;
|
|
12448
|
+
const edgeMinConfidence = edgeMode === "auto" && classifierMode === "auto" && typeof classify === "function" ? resolveEdgesMinConfidence(this.options.config) : void 0;
|
|
12449
|
+
const edgeSiteMode = edgeMode === "auto" && typeof edgeMinConfidence === "number" ? "auto" : "llm";
|
|
12338
12450
|
if (classifierMode === "auto" && typeof classify === "function") {
|
|
12339
12451
|
const slugs = effectiveManifest.node_types.map((n) => n.type);
|
|
12340
12452
|
if (slugs.length > 0 && slugs.length + 1 <= CLASSIFIER_MAX_CHOICES && !slugs.some((s) => isReservedAbstainSlug(s))) {
|
|
@@ -12345,16 +12457,29 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12345
12457
|
now,
|
|
12346
12458
|
recheckCutoff,
|
|
12347
12459
|
options?.meter,
|
|
12348
|
-
trigger
|
|
12460
|
+
trigger,
|
|
12461
|
+
shortlistK,
|
|
12462
|
+
edgeSiteMode,
|
|
12463
|
+
edgeMinConfidence
|
|
12349
12464
|
);
|
|
12350
12465
|
if (classifierRun.abortedOntologyOff || classifierRun.result.budgetStop) {
|
|
12351
12466
|
return classifierRun.result;
|
|
12352
12467
|
}
|
|
12353
|
-
if (classifierRun.escalated.length > 0
|
|
12468
|
+
if (classifierRun.escalated.length > 0) {
|
|
12354
12469
|
const { mode: liveMode } = await ontologyService.getEffectiveState(entityId);
|
|
12355
12470
|
if (liveMode === "off") {
|
|
12356
12471
|
const counts = await this.entryRepo.countUntypedByEntityId(entityId, recheckCutoff);
|
|
12357
|
-
|
|
12472
|
+
const committed = classifierRun.result;
|
|
12473
|
+
return {
|
|
12474
|
+
scanned: committed.scanned,
|
|
12475
|
+
typed: committed.typed,
|
|
12476
|
+
failedValidation: committed.failedValidation,
|
|
12477
|
+
edgesAdded: committed.edgesAdded,
|
|
12478
|
+
abstained: committed.abstained,
|
|
12479
|
+
skipped: committed.skipped,
|
|
12480
|
+
remaining: 0,
|
|
12481
|
+
deferred: counts.deferred
|
|
12482
|
+
};
|
|
12358
12483
|
}
|
|
12359
12484
|
const escalated = classifierRun.escalated;
|
|
12360
12485
|
const generative = await this._runGenerativeBackfill(entityId, escalated, {
|
|
@@ -12364,7 +12489,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12364
12489
|
batchSize: escalated.length,
|
|
12365
12490
|
recheckCutoff,
|
|
12366
12491
|
shortlistK,
|
|
12367
|
-
maxPromptChars
|
|
12492
|
+
maxPromptChars,
|
|
12493
|
+
edgeSiteMode,
|
|
12494
|
+
edgeMinConfidence
|
|
12368
12495
|
});
|
|
12369
12496
|
return {
|
|
12370
12497
|
scanned: classifierRun.result.scanned,
|
|
@@ -12387,7 +12514,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12387
12514
|
trigger,
|
|
12388
12515
|
recheckCutoff,
|
|
12389
12516
|
shortlistK,
|
|
12390
|
-
maxPromptChars
|
|
12517
|
+
maxPromptChars,
|
|
12518
|
+
edgeSiteMode,
|
|
12519
|
+
edgeMinConfidence
|
|
12391
12520
|
});
|
|
12392
12521
|
}
|
|
12393
12522
|
/**
|
|
@@ -12423,6 +12552,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12423
12552
|
if (maxPromptChars === void 0) {
|
|
12424
12553
|
throw new Error("_runGenerativeBackfill: runOpts.maxPromptChars is required (resolved at doRunOntologyBackfill entry)");
|
|
12425
12554
|
}
|
|
12555
|
+
if (runOpts.edgeSiteMode === void 0) {
|
|
12556
|
+
throw new Error("_runGenerativeBackfill: runOpts.edgeSiteMode is required (resolved at doRunOntologyBackfill entry)");
|
|
12557
|
+
}
|
|
12426
12558
|
const ontologyService = this.ontologyService;
|
|
12427
12559
|
const now = Date.now();
|
|
12428
12560
|
const recheckCutoff = runOpts.recheckCutoff;
|
|
@@ -12550,12 +12682,19 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12550
12682
|
* untyped fact over the effective manifest's node-type slugs plus the
|
|
12551
12683
|
* reserved abstain sentinel. Accepted answers go through
|
|
12552
12684
|
* `_applyOntologyBackfillBatch` exactly like LLM classifications. No edges
|
|
12553
|
-
* are proposed.
|
|
12685
|
+
* are proposed unless `systemOne.edges` is `'auto'`; under `'auto'` the
|
|
12686
|
+
* classifier screens per-fact edge questions against
|
|
12687
|
+
* `systemOne.minConfidence.edges` (an explicit floor; missing → warn and
|
|
12688
|
+
* `'llm'`). Confident "yes" answers (`p > 0.5 && p >= floor`) apply,
|
|
12689
|
+
* confident "no" answers (`p < 0.5 && 1 - p >= floor`) are terminal, and
|
|
12690
|
+
* everything else (including exactly `p = 0.5`) plus invalid edge answers
|
|
12691
|
+
* fall through to the generative step. Edge outcomes are evaluated only for
|
|
12692
|
+
* typing-ACCEPTED facts. Abstains and low-confidence answers are cooldown-stamped
|
|
12554
12693
|
* omissions under `onLowConfidence: 'leave'`; under `'llm'` they are
|
|
12555
12694
|
* returned un-stamped in `escalated` for the generative step. Always
|
|
12556
12695
|
* returns the `OntologyBackfillResult` for its step plus escalation state.
|
|
12557
12696
|
*/
|
|
12558
|
-
async _runClassifierBackfill(entityId, candidates, manifest, now, recheckCutoff, meter, trigger) {
|
|
12697
|
+
async _runClassifierBackfill(entityId, candidates, manifest, now, recheckCutoff, meter, trigger, shortlistK, edgeSiteMode, edgeMinConfidence) {
|
|
12559
12698
|
const minConfidence = resolveTypingMinConfidence(this.options.config);
|
|
12560
12699
|
const rawConcurrency = this.options.config?.chunkConcurrency ?? 1;
|
|
12561
12700
|
const concurrency = Number.isFinite(rawConcurrency) && rawConcurrency >= 1 ? Math.floor(rawConcurrency) : 1;
|
|
@@ -12565,17 +12704,65 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12565
12704
|
instructions: `Choose the ontology node type that best describes this fact, or choose "${ONTOLOGY_ABSTAIN_SENTINEL}" if none of the listed types fits.
|
|
12566
12705
|
` + manifest.node_types.map((n) => `- ${n.type}: ${n.description}`).join("\n")
|
|
12567
12706
|
};
|
|
12707
|
+
const edgeScreen = /* @__PURE__ */ new Map();
|
|
12708
|
+
if (edgeSiteMode === "auto" && (manifest.edge_types ?? []).length > 0) {
|
|
12709
|
+
const pool = await this.entryRepo.findShortlistRowsByEntityId(entityId);
|
|
12710
|
+
const poolTitleCounts = /* @__PURE__ */ new Map();
|
|
12711
|
+
for (const r of pool) {
|
|
12712
|
+
const k = normalizeTitleKey(r.title);
|
|
12713
|
+
poolTitleCounts.set(k, (poolTitleCounts.get(k) ?? 0) + 1);
|
|
12714
|
+
}
|
|
12715
|
+
const batchTitleKeys = new Set(candidates.map((f) => normalizeTitleKey(f.title)));
|
|
12716
|
+
const collides = (title) => {
|
|
12717
|
+
const k = normalizeTitleKey(title);
|
|
12718
|
+
return (poolTitleCounts.get(k) ?? 0) > 1 || batchTitleKeys.has(k);
|
|
12719
|
+
};
|
|
12720
|
+
const scorer = createShortlistScorer(pool);
|
|
12721
|
+
const edgeTypeNames = [...new Set(manifest.edge_types.map((e) => e.type))];
|
|
12722
|
+
for (const fact of candidates) {
|
|
12723
|
+
const ranked = buildShortlist({ title: fact.title, body: fact.body }, pool, shortlistK, scorer).filter((row) => !collides(row.title));
|
|
12724
|
+
const questions = {};
|
|
12725
|
+
const keyMap = /* @__PURE__ */ new Map();
|
|
12726
|
+
for (const row of ranked) {
|
|
12727
|
+
for (const edgeType of edgeTypeNames) {
|
|
12728
|
+
const definitions = manifest.edge_types.filter(
|
|
12729
|
+
(e) => e.type === edgeType && typeSatisfies(e.target_type, row.okf_type, manifest)
|
|
12730
|
+
);
|
|
12731
|
+
if (definitions.length === 0) continue;
|
|
12732
|
+
const key = `edge:${edgeType}:${row.id}`;
|
|
12733
|
+
const descriptions = [...new Set(definitions.map((d) => d.description))].join(" / ");
|
|
12734
|
+
questions[key] = {
|
|
12735
|
+
kind: "binary",
|
|
12736
|
+
instructions: `Does this fact have the "${edgeType}" relationship (${descriptions}) to the existing fact titled "${row.title}"?`
|
|
12737
|
+
};
|
|
12738
|
+
keyMap.set(key, { definitions, candidate: { id: row.id, title: row.title, okf_type: row.okf_type } });
|
|
12739
|
+
}
|
|
12740
|
+
}
|
|
12741
|
+
if (keyMap.size > 0) edgeScreen.set(fact.id, { questions, keyMap });
|
|
12742
|
+
}
|
|
12743
|
+
}
|
|
12568
12744
|
let stopped;
|
|
12745
|
+
const retriedFacts = /* @__PURE__ */ new Set();
|
|
12569
12746
|
const outcomes = await withConcurrency(
|
|
12570
12747
|
candidates.map((fact) => async () => {
|
|
12571
12748
|
if (stopped) return { fact, kind: "unattempted" };
|
|
12749
|
+
const edgeEntry = edgeScreen.get(fact.id);
|
|
12750
|
+
const ask = (questions) => callClassify(
|
|
12751
|
+
this.options,
|
|
12752
|
+
{ operation: "ontologyBackfill", entityId, trigger, meter },
|
|
12753
|
+
{ state: classifierStateForFact(fact), questions }
|
|
12754
|
+
);
|
|
12572
12755
|
let response;
|
|
12756
|
+
let screened = edgeEntry !== void 0;
|
|
12573
12757
|
try {
|
|
12574
|
-
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12758
|
+
try {
|
|
12759
|
+
response = await ask({ okf_type: question, ...edgeEntry?.questions ?? {} });
|
|
12760
|
+
} catch (err) {
|
|
12761
|
+
if (!edgeEntry || err instanceof WikiBudgetExhausted || !isContextOverflowError(err)) throw err;
|
|
12762
|
+
response = await ask({ okf_type: question });
|
|
12763
|
+
screened = false;
|
|
12764
|
+
retriedFacts.add(fact.id);
|
|
12765
|
+
}
|
|
12579
12766
|
} catch (err) {
|
|
12580
12767
|
if (err instanceof WikiBudgetExhausted) {
|
|
12581
12768
|
stopped ?? (stopped = err);
|
|
@@ -12589,17 +12776,54 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12589
12776
|
if (checked.answer.kind !== "choice") return { fact, kind: "invalid", reason: "kind_mismatch" };
|
|
12590
12777
|
if (isReservedAbstainSlug(checked.answer.choice)) return { fact, kind: "abstain" };
|
|
12591
12778
|
if (checked.answer.confidence < minConfidence) return { fact, kind: "low_confidence" };
|
|
12592
|
-
|
|
12779
|
+
const okfType = checked.answer.choice;
|
|
12780
|
+
if (!screened || !edgeEntry || typeof edgeMinConfidence !== "number") return { fact, kind: "accepted", okfType };
|
|
12781
|
+
const floor = edgeMinConfidence;
|
|
12782
|
+
const edges = [];
|
|
12783
|
+
const edgeCandidateIds = /* @__PURE__ */ Object.create(null);
|
|
12784
|
+
let evaluated = 0;
|
|
12785
|
+
let uncertain = 0;
|
|
12786
|
+
let invalid = 0;
|
|
12787
|
+
let missing = 0;
|
|
12788
|
+
for (const [key, { definitions, candidate }] of edgeEntry.keyMap) {
|
|
12789
|
+
if (!definitions.some((d) => typeSatisfies(d.source_type, okfType, manifest))) continue;
|
|
12790
|
+
evaluated++;
|
|
12791
|
+
const answer = validateClassifierAnswer(response, key, edgeEntry.questions[key]);
|
|
12792
|
+
if (!answer.ok) {
|
|
12793
|
+
if (answer.reason === "missing_answer") missing++;
|
|
12794
|
+
else invalid++;
|
|
12795
|
+
continue;
|
|
12796
|
+
}
|
|
12797
|
+
if (answer.answer.kind !== "binary") {
|
|
12798
|
+
invalid++;
|
|
12799
|
+
continue;
|
|
12800
|
+
}
|
|
12801
|
+
const p = answer.answer.probability;
|
|
12802
|
+
if (p > 0.5 && p >= floor) {
|
|
12803
|
+
edges.push({ edge_type: definitions[0].type, target_title: candidate.title });
|
|
12804
|
+
edgeCandidateIds[normalizeTitleKey(candidate.title)] = candidate.id;
|
|
12805
|
+
} else if (p < 0.5 && 1 - p >= floor) continue;
|
|
12806
|
+
else uncertain++;
|
|
12807
|
+
}
|
|
12808
|
+
const edgeStats = { uncertain, invalid, missing, allMissing: evaluated > 0 && missing === evaluated };
|
|
12809
|
+
if (edgeStats.allMissing) return { fact, kind: "accepted", okfType, edgeStats };
|
|
12810
|
+
if (uncertain > 0 || invalid > 0 || missing > 0) return { fact, kind: "accepted", okfType, fallthrough: true, edgeStats };
|
|
12811
|
+
return { fact, kind: "accepted", okfType, ...edges.length > 0 ? { edges, edgeCandidateIds } : {} };
|
|
12593
12812
|
}),
|
|
12594
12813
|
concurrency
|
|
12595
12814
|
);
|
|
12596
12815
|
const escalate = this.resolveSystemOneOnLowConfidence() === "llm";
|
|
12597
|
-
const
|
|
12598
|
-
const
|
|
12816
|
+
const isEscalated = (o) => o.kind === "accepted" && o.fallthrough === true || escalate && (o.kind === "abstain" || o.kind === "low_confidence");
|
|
12817
|
+
const escalated = outcomes.filter(isEscalated).map((o) => o.fact);
|
|
12599
12818
|
const attempted = outcomes.filter((o) => o.kind !== "threw" && o.kind !== "unattempted" && !isEscalated(o)).map((o) => o.fact);
|
|
12600
12819
|
const unattemptedCount = outcomes.filter((o) => o.kind === "unattempted").length;
|
|
12601
12820
|
const skipped = outcomes.filter((o) => o.kind === "threw" || o.kind === "overflow_skip").length;
|
|
12602
|
-
const classifications = outcomes.filter((o) => o.kind === "accepted").map((o) => ({
|
|
12821
|
+
const classifications = outcomes.filter((o) => o.kind === "accepted" && o.fallthrough !== true).map((o) => ({
|
|
12822
|
+
id: o.fact.id,
|
|
12823
|
+
okf_type: o.okfType,
|
|
12824
|
+
// An outcome carries `edges` only when the site is 'auto'.
|
|
12825
|
+
...o.edges && o.edges.length > 0 ? { edges: o.edges, edgeCandidateIds: o.edgeCandidateIds } : {}
|
|
12826
|
+
}));
|
|
12603
12827
|
const invalidCount = outcomes.filter((o) => o.kind === "invalid").length;
|
|
12604
12828
|
const abstainCount = outcomes.filter((o) => o.kind === "abstain" && !isEscalated(o)).length;
|
|
12605
12829
|
let typed = 0;
|
|
@@ -12624,7 +12848,21 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12624
12848
|
const diagBuffer = new DiagnosticBuffer();
|
|
12625
12849
|
const diagBase = { entityId, operation: "ontologyBackfill", trigger };
|
|
12626
12850
|
for (const o of outcomes) {
|
|
12627
|
-
if (o.
|
|
12851
|
+
if (retriedFacts.has(o.fact.id)) {
|
|
12852
|
+
diagBuffer.push({ ...diagBase, code: "context_overflow_skipped", detail: { factId: o.fact.id, reason: "edge_screen_overflow_retry" } });
|
|
12853
|
+
}
|
|
12854
|
+
if (o.kind === "accepted" && o.edgeStats) {
|
|
12855
|
+
const { invalid, missing, allMissing } = o.edgeStats;
|
|
12856
|
+
const code = allMissing || invalid > 0 || missing > 0 ? "classification_invalid" : "classification_low_confidence";
|
|
12857
|
+
diagBuffer.push({
|
|
12858
|
+
...diagBase,
|
|
12859
|
+
code,
|
|
12860
|
+
detail: {
|
|
12861
|
+
factId: o.fact.id,
|
|
12862
|
+
reason: allMissing ? "edge_answers_missing" : code === "classification_invalid" ? "edge_answer_invalid" : "edge_uncertain"
|
|
12863
|
+
}
|
|
12864
|
+
});
|
|
12865
|
+
} else if (o.kind === "abstain") {
|
|
12628
12866
|
if (isEscalated(o)) continue;
|
|
12629
12867
|
diagBuffer.push({ ...diagBase, code: "classification_abstained", detail: { factId: o.fact.id, writer: "classifier" } });
|
|
12630
12868
|
} else if (o.kind === "low_confidence") {
|
|
@@ -12759,16 +12997,41 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
12759
12997
|
});
|
|
12760
12998
|
titleIndex.set(normalizeTitleKey(fact.title), { id: fact.id, okf_type: normalized.okf_type });
|
|
12761
12999
|
if (normalized.edges.length > 0) {
|
|
12762
|
-
pendingEdges.push({
|
|
13000
|
+
pendingEdges.push({
|
|
13001
|
+
sourceId: fact.id,
|
|
13002
|
+
sourceType: normalized.okf_type,
|
|
13003
|
+
edges: normalized.edges,
|
|
13004
|
+
candidateIds: classification.edgeCandidateIds
|
|
13005
|
+
});
|
|
12763
13006
|
}
|
|
12764
13007
|
}
|
|
12765
13008
|
for (const item of pendingEdges) {
|
|
12766
13009
|
const resolveDrops = [];
|
|
13010
|
+
let edgesToResolve = item.edges;
|
|
13011
|
+
const screenedIds = item.candidateIds;
|
|
13012
|
+
if (screenedIds) {
|
|
13013
|
+
edgesToResolve = [];
|
|
13014
|
+
for (const edge of item.edges) {
|
|
13015
|
+
const key = normalizeTitleKey(edge.target_title);
|
|
13016
|
+
const screened = screenedIds[key];
|
|
13017
|
+
if (screened !== void 0 && titleIndex.get(key)?.id !== screened) {
|
|
13018
|
+
resolveDrops.push({
|
|
13019
|
+
reason: "target_not_found",
|
|
13020
|
+
sourceId: item.sourceId,
|
|
13021
|
+
edgeType: edge.edge_type,
|
|
13022
|
+
sourceNodeType: item.sourceType,
|
|
13023
|
+
targetNodeType: null
|
|
13024
|
+
});
|
|
13025
|
+
} else {
|
|
13026
|
+
edgesToResolve.push(edge);
|
|
13027
|
+
}
|
|
13028
|
+
}
|
|
13029
|
+
}
|
|
12767
13030
|
const added = await ontologyService.resolveAndPersistEdges(
|
|
12768
13031
|
entityId,
|
|
12769
13032
|
item.sourceId,
|
|
12770
13033
|
item.sourceType,
|
|
12771
|
-
|
|
13034
|
+
edgesToResolve,
|
|
12772
13035
|
manifest,
|
|
12773
13036
|
titleIndex,
|
|
12774
13037
|
tx,
|
|
@@ -18227,8 +18490,12 @@ exports.parseEmbedding = parseEmbedding;
|
|
|
18227
18490
|
exports.parseOkfBundle = parseOkfBundle;
|
|
18228
18491
|
exports.resolveContextBudget = resolveContextBudget;
|
|
18229
18492
|
exports.resolveDefaultChunkLength = resolveDefaultChunkLength;
|
|
18493
|
+
exports.resolveEdgesMinConfidence = resolveEdgesMinConfidence;
|
|
18230
18494
|
exports.resolveMaxPromptChars = resolveMaxPromptChars;
|
|
18231
18495
|
exports.resolveOntologyJobDefaults = resolveOntologyJobDefaults;
|
|
18496
|
+
exports.resolveResolveMinConfidence = resolveResolveMinConfidence;
|
|
18497
|
+
exports.resolveSystemOneEdges = resolveSystemOneEdges;
|
|
18498
|
+
exports.resolveSystemOneResolve = resolveSystemOneResolve;
|
|
18232
18499
|
exports.resolveSystemOneTyping = resolveSystemOneTyping;
|
|
18233
18500
|
exports.resolveTypingMinConfidence = resolveTypingMinConfidence;
|
|
18234
18501
|
exports.safeSlice = safeSlice;
|