@equationalapplications/core-llm-wiki 9.9.0 → 9.11.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-EN37KODZ.mjs → chunk-QUVPQVJ6.mjs} +126 -60
- package/dist/chunk-QUVPQVJ6.mjs.map +1 -0
- package/dist/index.d.mts +22 -19
- package/dist/index.d.ts +22 -19
- package/dist/index.js +136 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -2
- package/dist/index.mjs.map +1 -1
- package/dist/{testing-CDSfjx8j.d.mts → testing-DFyghdSG.d.mts} +25 -9
- package/dist/{testing-CDSfjx8j.d.ts → testing-DFyghdSG.d.ts} +25 -9
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +124 -58
- package/dist/testing.js.map +1 -1
- package/dist/testing.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-EN37KODZ.mjs.map +0 -1
|
@@ -127,6 +127,11 @@ interface OntologyConfig {
|
|
|
127
127
|
* (no edges are proposed); `'llm'` always uses `generateText`. Default `'llm'`.
|
|
128
128
|
*/
|
|
129
129
|
backfillClassifier?: 'auto' | 'llm';
|
|
130
|
+
/**
|
|
131
|
+
* Maximum number of candidate typed nodes (titles) shortlisted per fact in
|
|
132
|
+
* the backfill shortlist. Must be a finite integer >= 1; anything else throws. Default 10.
|
|
133
|
+
*/
|
|
134
|
+
shortlistK?: number;
|
|
130
135
|
/** Minimum classifier confidence to apply a node type. Finite, in [0, 1]. Default 0.5. */
|
|
131
136
|
classifyMinConfidence?: number;
|
|
132
137
|
/**
|
|
@@ -1634,11 +1639,11 @@ interface WikiInstructions {
|
|
|
1634
1639
|
librarian: string;
|
|
1635
1640
|
heal: string;
|
|
1636
1641
|
/**
|
|
1637
|
-
* Template only: the run-time prompt additionally carries
|
|
1638
|
-
* of the entity's typed node
|
|
1639
|
-
*
|
|
1640
|
-
*
|
|
1641
|
-
*
|
|
1642
|
+
* Template only: the run-time user prompt additionally carries per-fact
|
|
1643
|
+
* CANDIDATE TARGETS sections (a top-k shortlist of the entity's typed node
|
|
1644
|
+
* titles, after the Facts JSON) — see `buildCandidateSections` and the
|
|
1645
|
+
* Errata in `specs/backfill-shortlist-wiring/spec.md`, which supersede the
|
|
1646
|
+
* earlier title-catalog data-scope note (PR #425).
|
|
1642
1647
|
*/
|
|
1643
1648
|
ontologyBackfill: string;
|
|
1644
1649
|
}
|
|
@@ -2321,6 +2326,17 @@ declare class EntryRepository extends BaseRepository {
|
|
|
2321
2326
|
title: string;
|
|
2322
2327
|
okf_type: string | null;
|
|
2323
2328
|
}>>;
|
|
2329
|
+
/**
|
|
2330
|
+
* Shortlist scoring rows (id, title, okf_type, body) over all live typed
|
|
2331
|
+
* facts. Same filters as findTitleIndexByEntityId; okf_type is never NULL
|
|
2332
|
+
* in results because the query excludes untyped rows.
|
|
2333
|
+
*/
|
|
2334
|
+
findShortlistRowsByEntityId(entityId: string, tx?: SQLiteAdapter): Promise<Array<{
|
|
2335
|
+
id: string;
|
|
2336
|
+
title: string;
|
|
2337
|
+
okf_type: string;
|
|
2338
|
+
body: string;
|
|
2339
|
+
}>>;
|
|
2324
2340
|
/** Counts live mutable facts: eligible (past cooldown) vs deferred (in cooldown). */
|
|
2325
2341
|
countHealCandidatesByEntityId(entityId: string, recheckCutoff: number, tx?: SQLiteAdapter): Promise<{
|
|
2326
2342
|
eligible: number;
|
|
@@ -3552,7 +3568,7 @@ declare class PromptService {
|
|
|
3552
3568
|
degraded: DegradedRecord[];
|
|
3553
3569
|
groundingCorpus?: string[];
|
|
3554
3570
|
};
|
|
3555
|
-
buildOntologyBackfillPrompt(facts: unknown[], runtimeOverride?: string, ontologyContext?: OntologyPromptContext | null,
|
|
3571
|
+
buildOntologyBackfillPrompt(facts: unknown[], runtimeOverride?: string, ontologyContext?: OntologyPromptContext | null, candidateSections?: string): {
|
|
3556
3572
|
systemPrompt: string;
|
|
3557
3573
|
userPrompt: string;
|
|
3558
3574
|
};
|
|
@@ -3973,7 +3989,7 @@ interface LibrarianResult {
|
|
|
3973
3989
|
}
|
|
3974
3990
|
|
|
3975
3991
|
declare const ONTOLOGY_BACKFILL_BATCH_SIZE = 25;
|
|
3976
|
-
|
|
3992
|
+
|
|
3977
3993
|
declare const ONTOLOGY_BACKFILL_RECHECK_MS: number;
|
|
3978
3994
|
/**
|
|
3979
3995
|
* Upper bound on one classifier choice question (specs/system-one-config §5):
|
|
@@ -5236,5 +5252,5 @@ declare class WikiMemory {
|
|
|
5236
5252
|
setGeneratedByTask(taskId: string, entityId: string, actor: string): Promise<void>;
|
|
5237
5253
|
}
|
|
5238
5254
|
|
|
5239
|
-
export {
|
|
5240
|
-
export type { DegradedRecord as D, EmbedFactResult as E, FormatContextOptions as F, GraphNeighborhood as G, HealResult as I, ImportDumpResult as J, IngestDocumentResult as K, LLMProvider as L, MemoryBundle as M, LibrarianConfig as N, OntologyMode as O, LibrarianGateConfig as P, LockedMaintenanceJob as Q, ReadOptions as R, SQLiteAdapter as S, MaintenanceJob as T, MaintenanceStopReason as U, MemoryDumpEntity as V, WikiConfig as W, MigrationPolicy as X, MemoryDump as a,
|
|
5255
|
+
export { HEAL_RECHECK_MS as A, HOOK_TIMEOUT_MARKER as B, CLASSIFIER_MAX_CHOICES as C, HEAL_BATCH_SIZE as H, ONTOLOGY_ABSTAIN_SENTINEL as Y, ONTOLOGY_BACKFILL_BATCH_SIZE as Z, ONTOLOGY_BACKFILL_RECHECK_MS as _, ImportExportService as a$, PromptService as a9, WikiDraftNotFound as aA, WikiDuplicateHashError as aB, WikiExternalDeletionError as aE, WikiGraphNodeOwnershipConflict as aG, WikiIngestEmptyError as aH, WikiInvalidReadOptions as aJ, WikiMigrationRequiredError as aM, WikiParseError as aO, WikiSearchUnavailableError as aP, WikiSourceRefHashCollision as aR, WikiStrictOntologyViolation as aS, WikiSupersedeError as aT, WikiTransactionError as aW, isReservedAbstainSlug as aX, isWikiSearchUnavailableError as aY, validateManifest as aZ, EmbeddingService as a_, PrunePartialFailureError as aa, WikiBusyError as ar, IngestionService as b0, JobManager as b1, MaintenanceService as b2, RetrievalService as b3, SearchService as b4, WriteService as b5, WikiMemory as e, CheckpointIncompleteError as f, EraseStepError as r };
|
|
5256
|
+
export type { OntologyBackfillResult as $, DegradedRecord as D, EmbedFactResult as E, FormatContextOptions as F, GraphNeighborhood as G, HealResult as I, ImportDumpResult as J, IngestDocumentResult as K, LLMProvider as L, MemoryBundle as M, LibrarianConfig as N, OntologyMode as O, LibrarianGateConfig as P, LockedMaintenanceJob as Q, ReadOptions as R, SQLiteAdapter as S, MaintenanceJob as T, MaintenanceStopReason as U, MemoryDumpEntity as V, WikiConfig as W, MigrationPolicy as X, MemoryDump as a, OntologyEdgeType as a0, OntologyManifest as a1, OntologyNodeType as a2, OntologyPromptContext as a3, OntologyUpdates as a4, PendingMaintenance as a5, PendingMigrationWork as a6, PendingSourceStatus as a7, PromptOverrides as a8, WikiEdge as aC, WikiEvent as aD, WikiFact as aF, WikiInstructions as aI, WikiLintReport as aK, WikiMemoryTestAccess as aL, WikiOutboxEvent as aN, WikiSourcePointer as aQ, WikiSupersedeReason as aU, WikiTask as aV, ReembedResult as ab, RememberInput as ac, RunPendingMaintenanceOptions as ad, RunPendingMaintenanceResult as ae, SourcePassage as af, StoreSourceResult as ag, StoredSource as ah, StoredSourceDump as ai, StoredSourceSummary as aj, SupersedeReplacement as ak, SystemOneConfig as al, SystemOneThresholdSite as am, VectorRanker as an, VectorRankerFallback as ao, VectorRankerRankArgs as ap, VectorRankerSemanticResult as aq, WikiBusyOperation as as, WikiCheckpoint as at, WikiDiagnostic as au, WikiDiagnosticCode as av, WikiDiagnosticDetail as aw, WikiDiagnosticOperation as ax, WikiDiagnosticSeverity as ay, WikiDiagnosticTrigger as az, FormattedMemoryDump as b, OntologyConfig as c, WikiOptions as d, ChunkFailure as g, ClassifierAnswer as h, ClassifierQuestion as i, ClassifyRequest as j, ClassifyResponse as k, DraftPage as l, EmbedFailureKind as m, EmbeddingMarkerKind as n, EntityMaintenanceReport as o, EntityStatus as p, EraseReport as q, ExtractedFact as s, ExtractedFactEdge as t, ExtractedFactWithOntology as u, ExtractedTask as v, ForgetParams as w, ForgetResult as x, GraphTraversalOptions as y, GroundingConfig as z };
|
|
@@ -127,6 +127,11 @@ interface OntologyConfig {
|
|
|
127
127
|
* (no edges are proposed); `'llm'` always uses `generateText`. Default `'llm'`.
|
|
128
128
|
*/
|
|
129
129
|
backfillClassifier?: 'auto' | 'llm';
|
|
130
|
+
/**
|
|
131
|
+
* Maximum number of candidate typed nodes (titles) shortlisted per fact in
|
|
132
|
+
* the backfill shortlist. Must be a finite integer >= 1; anything else throws. Default 10.
|
|
133
|
+
*/
|
|
134
|
+
shortlistK?: number;
|
|
130
135
|
/** Minimum classifier confidence to apply a node type. Finite, in [0, 1]. Default 0.5. */
|
|
131
136
|
classifyMinConfidence?: number;
|
|
132
137
|
/**
|
|
@@ -1634,11 +1639,11 @@ interface WikiInstructions {
|
|
|
1634
1639
|
librarian: string;
|
|
1635
1640
|
heal: string;
|
|
1636
1641
|
/**
|
|
1637
|
-
* Template only: the run-time prompt additionally carries
|
|
1638
|
-
* of the entity's typed node
|
|
1639
|
-
*
|
|
1640
|
-
*
|
|
1641
|
-
*
|
|
1642
|
+
* Template only: the run-time user prompt additionally carries per-fact
|
|
1643
|
+
* CANDIDATE TARGETS sections (a top-k shortlist of the entity's typed node
|
|
1644
|
+
* titles, after the Facts JSON) — see `buildCandidateSections` and the
|
|
1645
|
+
* Errata in `specs/backfill-shortlist-wiring/spec.md`, which supersede the
|
|
1646
|
+
* earlier title-catalog data-scope note (PR #425).
|
|
1642
1647
|
*/
|
|
1643
1648
|
ontologyBackfill: string;
|
|
1644
1649
|
}
|
|
@@ -2321,6 +2326,17 @@ declare class EntryRepository extends BaseRepository {
|
|
|
2321
2326
|
title: string;
|
|
2322
2327
|
okf_type: string | null;
|
|
2323
2328
|
}>>;
|
|
2329
|
+
/**
|
|
2330
|
+
* Shortlist scoring rows (id, title, okf_type, body) over all live typed
|
|
2331
|
+
* facts. Same filters as findTitleIndexByEntityId; okf_type is never NULL
|
|
2332
|
+
* in results because the query excludes untyped rows.
|
|
2333
|
+
*/
|
|
2334
|
+
findShortlistRowsByEntityId(entityId: string, tx?: SQLiteAdapter): Promise<Array<{
|
|
2335
|
+
id: string;
|
|
2336
|
+
title: string;
|
|
2337
|
+
okf_type: string;
|
|
2338
|
+
body: string;
|
|
2339
|
+
}>>;
|
|
2324
2340
|
/** Counts live mutable facts: eligible (past cooldown) vs deferred (in cooldown). */
|
|
2325
2341
|
countHealCandidatesByEntityId(entityId: string, recheckCutoff: number, tx?: SQLiteAdapter): Promise<{
|
|
2326
2342
|
eligible: number;
|
|
@@ -3552,7 +3568,7 @@ declare class PromptService {
|
|
|
3552
3568
|
degraded: DegradedRecord[];
|
|
3553
3569
|
groundingCorpus?: string[];
|
|
3554
3570
|
};
|
|
3555
|
-
buildOntologyBackfillPrompt(facts: unknown[], runtimeOverride?: string, ontologyContext?: OntologyPromptContext | null,
|
|
3571
|
+
buildOntologyBackfillPrompt(facts: unknown[], runtimeOverride?: string, ontologyContext?: OntologyPromptContext | null, candidateSections?: string): {
|
|
3556
3572
|
systemPrompt: string;
|
|
3557
3573
|
userPrompt: string;
|
|
3558
3574
|
};
|
|
@@ -3973,7 +3989,7 @@ interface LibrarianResult {
|
|
|
3973
3989
|
}
|
|
3974
3990
|
|
|
3975
3991
|
declare const ONTOLOGY_BACKFILL_BATCH_SIZE = 25;
|
|
3976
|
-
|
|
3992
|
+
|
|
3977
3993
|
declare const ONTOLOGY_BACKFILL_RECHECK_MS: number;
|
|
3978
3994
|
/**
|
|
3979
3995
|
* Upper bound on one classifier choice question (specs/system-one-config §5):
|
|
@@ -5236,5 +5252,5 @@ declare class WikiMemory {
|
|
|
5236
5252
|
setGeneratedByTask(taskId: string, entityId: string, actor: string): Promise<void>;
|
|
5237
5253
|
}
|
|
5238
5254
|
|
|
5239
|
-
export {
|
|
5240
|
-
export type { DegradedRecord as D, EmbedFactResult as E, FormatContextOptions as F, GraphNeighborhood as G, HealResult as I, ImportDumpResult as J, IngestDocumentResult as K, LLMProvider as L, MemoryBundle as M, LibrarianConfig as N, OntologyMode as O, LibrarianGateConfig as P, LockedMaintenanceJob as Q, ReadOptions as R, SQLiteAdapter as S, MaintenanceJob as T, MaintenanceStopReason as U, MemoryDumpEntity as V, WikiConfig as W, MigrationPolicy as X, MemoryDump as a,
|
|
5255
|
+
export { HEAL_RECHECK_MS as A, HOOK_TIMEOUT_MARKER as B, CLASSIFIER_MAX_CHOICES as C, HEAL_BATCH_SIZE as H, ONTOLOGY_ABSTAIN_SENTINEL as Y, ONTOLOGY_BACKFILL_BATCH_SIZE as Z, ONTOLOGY_BACKFILL_RECHECK_MS as _, ImportExportService as a$, PromptService as a9, WikiDraftNotFound as aA, WikiDuplicateHashError as aB, WikiExternalDeletionError as aE, WikiGraphNodeOwnershipConflict as aG, WikiIngestEmptyError as aH, WikiInvalidReadOptions as aJ, WikiMigrationRequiredError as aM, WikiParseError as aO, WikiSearchUnavailableError as aP, WikiSourceRefHashCollision as aR, WikiStrictOntologyViolation as aS, WikiSupersedeError as aT, WikiTransactionError as aW, isReservedAbstainSlug as aX, isWikiSearchUnavailableError as aY, validateManifest as aZ, EmbeddingService as a_, PrunePartialFailureError as aa, WikiBusyError as ar, IngestionService as b0, JobManager as b1, MaintenanceService as b2, RetrievalService as b3, SearchService as b4, WriteService as b5, WikiMemory as e, CheckpointIncompleteError as f, EraseStepError as r };
|
|
5256
|
+
export type { OntologyBackfillResult as $, DegradedRecord as D, EmbedFactResult as E, FormatContextOptions as F, GraphNeighborhood as G, HealResult as I, ImportDumpResult as J, IngestDocumentResult as K, LLMProvider as L, MemoryBundle as M, LibrarianConfig as N, OntologyMode as O, LibrarianGateConfig as P, LockedMaintenanceJob as Q, ReadOptions as R, SQLiteAdapter as S, MaintenanceJob as T, MaintenanceStopReason as U, MemoryDumpEntity as V, WikiConfig as W, MigrationPolicy as X, MemoryDump as a, OntologyEdgeType as a0, OntologyManifest as a1, OntologyNodeType as a2, OntologyPromptContext as a3, OntologyUpdates as a4, PendingMaintenance as a5, PendingMigrationWork as a6, PendingSourceStatus as a7, PromptOverrides as a8, WikiEdge as aC, WikiEvent as aD, WikiFact as aF, WikiInstructions as aI, WikiLintReport as aK, WikiMemoryTestAccess as aL, WikiOutboxEvent as aN, WikiSourcePointer as aQ, WikiSupersedeReason as aU, WikiTask as aV, ReembedResult as ab, RememberInput as ac, RunPendingMaintenanceOptions as ad, RunPendingMaintenanceResult as ae, SourcePassage as af, StoreSourceResult as ag, StoredSource as ah, StoredSourceDump as ai, StoredSourceSummary as aj, SupersedeReplacement as ak, SystemOneConfig as al, SystemOneThresholdSite as am, VectorRanker as an, VectorRankerFallback as ao, VectorRankerRankArgs as ap, VectorRankerSemanticResult as aq, WikiBusyOperation as as, WikiCheckpoint as at, WikiDiagnostic as au, WikiDiagnosticCode as av, WikiDiagnosticDetail as aw, WikiDiagnosticOperation as ax, WikiDiagnosticSeverity as ay, WikiDiagnosticTrigger as az, FormattedMemoryDump as b, OntologyConfig as c, WikiOptions as d, ChunkFailure as g, ClassifierAnswer as h, ClassifierQuestion as i, ClassifyRequest as j, ClassifyResponse as k, DraftPage as l, EmbedFailureKind as m, EmbeddingMarkerKind as n, EntityMaintenanceReport as o, EntityStatus as p, EraseReport as q, ExtractedFact as s, ExtractedFactEdge as t, ExtractedFactWithOntology as u, ExtractedTask as v, ForgetParams as w, ForgetResult as x, GraphTraversalOptions as y, GroundingConfig as z };
|
package/dist/testing.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
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-DFyghdSG.mjs';
|
|
2
2
|
import '@equationalapplications/core-okf';
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
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-DFyghdSG.js';
|
|
2
2
|
import '@equationalapplications/core-okf';
|
package/dist/testing.js
CHANGED
|
@@ -2486,46 +2486,29 @@ Return ONLY a valid JSON object matching this schema:
|
|
|
2486
2486
|
}
|
|
2487
2487
|
If 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).
|
|
2488
2488
|
When 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.`;
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2498
|
-
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
if (listed.length >= TITLE_CATALOG_MAX_ENTRIES) break;
|
|
2505
|
-
if (used + line.length + 1 > CHAR_BUDGET) continue;
|
|
2506
|
-
listed.push(r);
|
|
2507
|
-
used += line.length + 1;
|
|
2508
|
-
}
|
|
2509
|
-
const truncated = typed.length > listed.length;
|
|
2510
|
-
if (typed.length === 0) {
|
|
2511
|
-
return [
|
|
2512
|
-
"TITLE CATALOG: this memory contains no typed nodes yet.",
|
|
2513
|
-
'A fact classified in this same response is a valid "target_title" once typed. Otherwise omit "edges" rather than invent a target_title.'
|
|
2514
|
-
].join("\n");
|
|
2489
|
+
function formatCatalogLine(r) {
|
|
2490
|
+
return `- ${JSON.stringify(r.title)} (${r.okf_type})`;
|
|
2491
|
+
}
|
|
2492
|
+
function buildCandidateSections(facts, rowsByFact) {
|
|
2493
|
+
const footer = 'A "target_title" may be copied verbatim from the candidates above for its fact, or be another fact classified in this same response. Any other existing typed node in this memory is also a valid "target_title", even if not listed here. If no valid target exists, omit "edges" rather than invent a target_title.';
|
|
2494
|
+
const sections = [];
|
|
2495
|
+
for (const fact of facts) {
|
|
2496
|
+
const rows = rowsByFact.get(fact.id);
|
|
2497
|
+
if (!rows || rows.length === 0) continue;
|
|
2498
|
+
sections.push(
|
|
2499
|
+
[
|
|
2500
|
+
`CANDIDATE TARGETS for fact ${JSON.stringify(fact.id)}: typed nodes in this memory, ranked by title overlap:`,
|
|
2501
|
+
...rows.map(formatCatalogLine)
|
|
2502
|
+
].join("\n")
|
|
2503
|
+
);
|
|
2515
2504
|
}
|
|
2516
|
-
if (
|
|
2505
|
+
if (sections.length === 0) {
|
|
2517
2506
|
return [
|
|
2518
|
-
"
|
|
2507
|
+
"CANDIDATE TARGETS: this memory contains no typed nodes yet.",
|
|
2519
2508
|
'A fact classified in this same response is a valid "target_title" once typed. Otherwise omit "edges" rather than invent a target_title.'
|
|
2520
2509
|
].join("\n");
|
|
2521
2510
|
}
|
|
2522
|
-
|
|
2523
|
-
return [
|
|
2524
|
-
"TITLE CATALOG: existing typed nodes in this memory include:",
|
|
2525
|
-
catalog,
|
|
2526
|
-
...truncated ? ["(This list is truncated; more typed nodes exist than are shown here.)"] : [],
|
|
2527
|
-
'A "target_title" may be copied verbatim from this catalog, or be another fact classified in this same response. If no valid target exists, omit "edges" rather than invent a target_title.'
|
|
2528
|
-
].join("\n");
|
|
2511
|
+
return [...sections, footer].join("\n\n");
|
|
2529
2512
|
}
|
|
2530
2513
|
var GROUNDING_SOURCE = {
|
|
2531
2514
|
ingest: { key: "facts", source: "the document chunk" },
|
|
@@ -2857,7 +2840,7 @@ The following document anchors are provided for contradiction detection only. Do
|
|
|
2857
2840
|
...corpusField
|
|
2858
2841
|
};
|
|
2859
2842
|
}
|
|
2860
|
-
buildOntologyBackfillPrompt(facts, runtimeOverride, ontologyContext,
|
|
2843
|
+
buildOntologyBackfillPrompt(facts, runtimeOverride, ontologyContext, candidateSections) {
|
|
2861
2844
|
const template = runtimeOverride ?? this.globalOverrides?.ontologyBackfillSystemPrompt ?? ONTOLOGY_BACKFILL_SYSTEM_PROMPT;
|
|
2862
2845
|
const hasFacts = /\{\{\s*facts\s*\}\}/.test(template);
|
|
2863
2846
|
if (hasFacts || this.hasOntologyPlaceholders(template)) {
|
|
@@ -2867,13 +2850,13 @@ The following document anchors are provided for contradiction detection only. Do
|
|
|
2867
2850
|
${JSON.stringify(facts, null, 2)}`
|
|
2868
2851
|
};
|
|
2869
2852
|
}
|
|
2870
|
-
const
|
|
2871
|
-
|
|
2872
|
-
${titleCatalog}` : template;
|
|
2853
|
+
const factsBlock = `Facts:
|
|
2854
|
+
${JSON.stringify(facts, null, 2)}`;
|
|
2873
2855
|
return {
|
|
2874
|
-
systemPrompt: this.appendOntology(
|
|
2875
|
-
userPrompt:
|
|
2876
|
-
|
|
2856
|
+
systemPrompt: this.appendOntology(template, ontologyContext),
|
|
2857
|
+
userPrompt: candidateSections !== void 0 ? `${factsBlock}
|
|
2858
|
+
|
|
2859
|
+
${candidateSections}` : factsBlock
|
|
2877
2860
|
};
|
|
2878
2861
|
}
|
|
2879
2862
|
/** Ops extract (spec §5.2): events only — no existing facts. */
|
|
@@ -2962,6 +2945,7 @@ var DEFAULT_CHUNK_OVERLAP = 400;
|
|
|
2962
2945
|
|
|
2963
2946
|
// src/utils/contextCaps.ts
|
|
2964
2947
|
var OPS_RESOLVE_MAX_PROMPT_CHARS = 4e4;
|
|
2948
|
+
var ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS = 4e4;
|
|
2965
2949
|
var HEAL_MAX_PROMPT_CHARS = 4e4;
|
|
2966
2950
|
var OPS_MAX_EXTRACT_CHARS = 24e3;
|
|
2967
2951
|
|
|
@@ -2972,7 +2956,8 @@ var DEFAULT_OUTPUT_RESERVE_TOKENS = 4e3;
|
|
|
2972
2956
|
var OP_FLOOR = {
|
|
2973
2957
|
resolve: OPS_RESOLVE_MAX_PROMPT_CHARS,
|
|
2974
2958
|
heal: HEAL_MAX_PROMPT_CHARS,
|
|
2975
|
-
extract: OPS_MAX_EXTRACT_CHARS
|
|
2959
|
+
extract: OPS_MAX_EXTRACT_CHARS,
|
|
2960
|
+
backfill: ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS
|
|
2976
2961
|
};
|
|
2977
2962
|
function bad(key, value, why) {
|
|
2978
2963
|
return new Error(`[core-llm-wiki] config.context.${key} must be ${why}; received ${JSON.stringify(value)}`);
|
|
@@ -3010,12 +2995,11 @@ function declaredPromptCap(budget, op) {
|
|
|
3010
2995
|
const derived = Math.floor(
|
|
3011
2996
|
(budget.contextWindowTokens - budget.outputReserveTokens) * budget.safetyFraction * budget.charsPerToken
|
|
3012
2997
|
);
|
|
3013
|
-
|
|
3014
|
-
return Math.max(OP_FLOOR.heal, derived);
|
|
2998
|
+
return Math.max(OP_FLOOR[op], derived);
|
|
3015
2999
|
}
|
|
3016
3000
|
function resolveMaxPromptChars(budget, op) {
|
|
3017
3001
|
if (budget.mode !== "declared") {
|
|
3018
|
-
return
|
|
3002
|
+
return OP_FLOOR[op];
|
|
3019
3003
|
}
|
|
3020
3004
|
if (op === "extract") {
|
|
3021
3005
|
const resolveDerived = declaredPromptCap(budget, "resolve");
|
|
@@ -3915,6 +3899,52 @@ function classifierStateForFact(fact) {
|
|
|
3915
3899
|
return parts.join("\n\n");
|
|
3916
3900
|
}
|
|
3917
3901
|
|
|
3902
|
+
// src/utils/shortlist.ts
|
|
3903
|
+
function shortlistScore(factTitle, factBody, row) {
|
|
3904
|
+
const factTokens = /* @__PURE__ */ new Set([...titleTokens(factTitle), ...titleTokens(factBody)]);
|
|
3905
|
+
const rowTokens = /* @__PURE__ */ new Set([...titleTokens(row.title), ...titleTokens(row.body ?? "")]);
|
|
3906
|
+
return jaccardScore(factTokens, rowTokens);
|
|
3907
|
+
}
|
|
3908
|
+
function createShortlistScorer(rows) {
|
|
3909
|
+
const rowTokens = /* @__PURE__ */ new Map();
|
|
3910
|
+
const tokensOfRow = (row) => {
|
|
3911
|
+
let t = rowTokens.get(row);
|
|
3912
|
+
if (!t) {
|
|
3913
|
+
t = /* @__PURE__ */ new Set([...titleTokens(row.title), ...titleTokens(row.body ?? "")]);
|
|
3914
|
+
rowTokens.set(row, t);
|
|
3915
|
+
}
|
|
3916
|
+
return t;
|
|
3917
|
+
};
|
|
3918
|
+
for (const r of rows) tokensOfRow(r);
|
|
3919
|
+
const factTokens = /* @__PURE__ */ new WeakMap();
|
|
3920
|
+
return (fact, row) => {
|
|
3921
|
+
let ft = factTokens.get(fact);
|
|
3922
|
+
if (!ft) {
|
|
3923
|
+
ft = /* @__PURE__ */ new Set([...titleTokens(fact.title), ...titleTokens(fact.body)]);
|
|
3924
|
+
factTokens.set(fact, ft);
|
|
3925
|
+
}
|
|
3926
|
+
return jaccardScore(ft, tokensOfRow(row));
|
|
3927
|
+
};
|
|
3928
|
+
}
|
|
3929
|
+
function buildShortlist(fact, rows, k, score = (f, r) => shortlistScore(f.title, f.body, r)) {
|
|
3930
|
+
if (typeof k !== "number" || Number.isNaN(k) || !Number.isInteger(k)) {
|
|
3931
|
+
throw new Error(`buildShortlist: k must be a non-negative integer, got ${String(k)}`);
|
|
3932
|
+
}
|
|
3933
|
+
if (k <= 0) return [];
|
|
3934
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
3935
|
+
for (const r of rows) {
|
|
3936
|
+
if (typeof r.title !== "string" || r.title.length === 0) continue;
|
|
3937
|
+
if (typeof r.okf_type !== "string" || r.okf_type.length === 0) continue;
|
|
3938
|
+
byKey.set(normalizeTitleKey(r.title), r);
|
|
3939
|
+
}
|
|
3940
|
+
const scored = [...byKey.values()].map((row) => ({ row, score: score(fact, row) }));
|
|
3941
|
+
scored.sort((a, b) => {
|
|
3942
|
+
if (a.score !== b.score) return b.score - a.score;
|
|
3943
|
+
return a.row.title < b.row.title ? -1 : a.row.title > b.row.title ? 1 : 0;
|
|
3944
|
+
});
|
|
3945
|
+
return scored.slice(0, k).map((s) => s.row);
|
|
3946
|
+
}
|
|
3947
|
+
|
|
3918
3948
|
// src/utils/temporal.ts
|
|
3919
3949
|
function liveAtSql(mode, alias = "") {
|
|
3920
3950
|
const from = mode === "asOf" ? `COALESCE(${alias}valid_from, ${alias}created_at) <= ?` : `(${alias}valid_from IS NULL OR ${alias}valid_from <= ?)`;
|
|
@@ -4086,6 +4116,17 @@ function resolveSystemOneTyping(config, classifierCallOption) {
|
|
|
4086
4116
|
}
|
|
4087
4117
|
return classifierCallOption ?? (systemOneValid ? systemOne.typing : void 0) ?? (legacyValid ? legacy : void 0) ?? "llm";
|
|
4088
4118
|
}
|
|
4119
|
+
var DEFAULT_SHORTLIST_K = 10;
|
|
4120
|
+
function resolveShortlistK(config) {
|
|
4121
|
+
const k = config?.ontology?.shortlistK;
|
|
4122
|
+
if (k === void 0) return DEFAULT_SHORTLIST_K;
|
|
4123
|
+
if (typeof k !== "number" || !Number.isInteger(k) || k < 1) {
|
|
4124
|
+
throw new Error(
|
|
4125
|
+
`[core-llm-wiki] \`ontology.shortlistK\` is ${formatConfigValue(k)}, which is not a finite integer >= 1.`
|
|
4126
|
+
);
|
|
4127
|
+
}
|
|
4128
|
+
return k;
|
|
4129
|
+
}
|
|
4089
4130
|
var DEFAULT_TYPING_MIN_CONFIDENCE = 0.5;
|
|
4090
4131
|
function resolveTypingMinConfidence(config) {
|
|
4091
4132
|
const systemOneFloor = config?.systemOne?.minConfidence?.typing;
|
|
@@ -5887,7 +5928,6 @@ async function runLibrarianStrategy(deps, ctx) {
|
|
|
5887
5928
|
// src/services/MaintenanceService.ts
|
|
5888
5929
|
var CHAIN_TRUNCATED_NOTICE = `includeChain walk stopped at the depth cap (${HISTORY_MAX_DEPTH} links per direction); the chain is longer than the ids listed. Run forget again on a remaining chain id to continue.`;
|
|
5889
5930
|
var ONTOLOGY_BACKFILL_BATCH_SIZE = 25;
|
|
5890
|
-
var ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS = 4e4;
|
|
5891
5931
|
var ONTOLOGY_BACKFILL_RECHECK_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
5892
5932
|
var CLASSIFIER_MAX_CHOICES = 255;
|
|
5893
5933
|
var HEAL_ANCHOR_SEARCH_OVERFETCH = 4;
|
|
@@ -7363,6 +7403,8 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7363
7403
|
if (options?.classifier !== void 0 && options.classifier !== "auto" && options.classifier !== "llm") {
|
|
7364
7404
|
throw new TypeError(`Invalid classifier option: ${JSON.stringify(options.classifier)} \u2014 must be 'auto' or 'llm'`);
|
|
7365
7405
|
}
|
|
7406
|
+
const shortlistK = resolveShortlistK(this.options.config);
|
|
7407
|
+
const maxPromptChars = resolveMaxPromptChars(resolveContextBudget(this.options.config), "backfill");
|
|
7366
7408
|
const trigger = options?.trigger ?? "call";
|
|
7367
7409
|
const now = Date.now();
|
|
7368
7410
|
const recheckCutoff = options?.recheckCheckedBefore ?? now - ONTOLOGY_BACKFILL_RECHECK_MS;
|
|
@@ -7410,7 +7452,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7410
7452
|
meter: options?.meter,
|
|
7411
7453
|
trigger,
|
|
7412
7454
|
batchSize: escalated.length,
|
|
7413
|
-
recheckCutoff
|
|
7455
|
+
recheckCutoff,
|
|
7456
|
+
shortlistK,
|
|
7457
|
+
maxPromptChars
|
|
7414
7458
|
});
|
|
7415
7459
|
return {
|
|
7416
7460
|
scanned: classifierRun.result.scanned,
|
|
@@ -7431,7 +7475,9 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7431
7475
|
promptOverride: options?.promptOverride,
|
|
7432
7476
|
meter: options?.meter,
|
|
7433
7477
|
trigger,
|
|
7434
|
-
recheckCutoff
|
|
7478
|
+
recheckCutoff,
|
|
7479
|
+
shortlistK,
|
|
7480
|
+
maxPromptChars
|
|
7435
7481
|
});
|
|
7436
7482
|
}
|
|
7437
7483
|
/**
|
|
@@ -7459,19 +7505,39 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7459
7505
|
*/
|
|
7460
7506
|
async _runGenerativeBackfill(entityId, candidates, runOpts) {
|
|
7461
7507
|
runOpts.batchSize ?? ONTOLOGY_BACKFILL_BATCH_SIZE;
|
|
7508
|
+
const shortlistK = runOpts.shortlistK;
|
|
7509
|
+
if (shortlistK === void 0) {
|
|
7510
|
+
throw new Error("_runGenerativeBackfill: runOpts.shortlistK is required (resolved at doRunOntologyBackfill entry)");
|
|
7511
|
+
}
|
|
7512
|
+
const maxPromptChars = runOpts.maxPromptChars;
|
|
7513
|
+
if (maxPromptChars === void 0) {
|
|
7514
|
+
throw new Error("_runGenerativeBackfill: runOpts.maxPromptChars is required (resolved at doRunOntologyBackfill entry)");
|
|
7515
|
+
}
|
|
7462
7516
|
const ontologyService = this.ontologyService;
|
|
7463
7517
|
const now = Date.now();
|
|
7464
7518
|
const recheckCutoff = runOpts.recheckCutoff;
|
|
7465
7519
|
const ontologyContext = await ontologyService.buildPromptContext(entityId);
|
|
7466
|
-
const
|
|
7467
|
-
const titleCatalog = buildTitleCatalogBlock(titleRows);
|
|
7520
|
+
const shortlistRows = await this.entryRepo.findShortlistRowsByEntityId(entityId);
|
|
7468
7521
|
const toPromptShape = (f) => ({ id: f.id, title: f.title, body: f.body, tags: f.tags });
|
|
7469
|
-
const
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7522
|
+
const shortlistScorer = createShortlistScorer(shortlistRows);
|
|
7523
|
+
const shortlistCache = /* @__PURE__ */ new Map();
|
|
7524
|
+
const buildPrompt = (facts) => {
|
|
7525
|
+
const rowsByFact = /* @__PURE__ */ new Map();
|
|
7526
|
+
for (const f of facts) {
|
|
7527
|
+
let rows = shortlistCache.get(f.id);
|
|
7528
|
+
if (!rows) {
|
|
7529
|
+
rows = buildShortlist({ title: f.title, body: f.body }, shortlistRows, shortlistK, shortlistScorer);
|
|
7530
|
+
shortlistCache.set(f.id, rows);
|
|
7531
|
+
}
|
|
7532
|
+
rowsByFact.set(f.id, rows);
|
|
7533
|
+
}
|
|
7534
|
+
return this.promptService.buildOntologyBackfillPrompt(
|
|
7535
|
+
facts.map(toPromptShape),
|
|
7536
|
+
runOpts.promptOverride,
|
|
7537
|
+
ontologyContext,
|
|
7538
|
+
buildCandidateSections(facts, rowsByFact)
|
|
7539
|
+
);
|
|
7540
|
+
};
|
|
7475
7541
|
const outcome = await runBatched({
|
|
7476
7542
|
items: candidates,
|
|
7477
7543
|
buildPrompt,
|
|
@@ -7485,7 +7551,7 @@ DROP TRIGGER IF EXISTS ${ad};`);
|
|
|
7485
7551
|
};
|
|
7486
7552
|
},
|
|
7487
7553
|
maxOutputTokens: this.options.llmProvider.maxOutputTokens,
|
|
7488
|
-
maxPromptChars
|
|
7554
|
+
maxPromptChars,
|
|
7489
7555
|
onSkip: (fact, err) => {
|
|
7490
7556
|
if (isContextOverflowError(err)) {
|
|
7491
7557
|
emitDiagnostic(this.options, {
|