@equationalapplications/core-llm-wiki 9.12.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.
@@ -3974,6 +3974,16 @@ function resolveSystemOneEdges(config) {
3974
3974
  }
3975
3975
  return edges ?? "llm";
3976
3976
  }
3977
+ function resolveSystemOneResolve(config) {
3978
+ const resolve = config?.systemOne?.resolve;
3979
+ if (resolve !== void 0 && !isTypingMode(resolve)) {
3980
+ warnOnce(
3981
+ `[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.`
3982
+ );
3983
+ return "llm";
3984
+ }
3985
+ return resolve ?? "llm";
3986
+ }
3977
3987
  var DEFAULT_SHORTLIST_K = 10;
3978
3988
  function resolveShortlistK(config) {
3979
3989
  const k = config?.ontology?.shortlistK;
@@ -4013,6 +4023,15 @@ function resolveEdgesMinConfidence(config) {
4013
4023
  );
4014
4024
  return void 0;
4015
4025
  }
4026
+ function resolveResolveMinConfidence(config) {
4027
+ if (resolveSystemOneResolve(config) !== "auto") return void 0;
4028
+ const floor = config?.systemOne?.minConfidence?.resolve;
4029
+ if (isEdgesFloor(floor)) return floor;
4030
+ warnOnce(
4031
+ 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.`
4032
+ );
4033
+ return void 0;
4034
+ }
4016
4035
 
4017
4036
  // src/utils/classifier.ts
4018
4037
  var isUnit = (v) => typeof v === "number" && Number.isFinite(v) && v >= 0 && v <= 1;
@@ -6682,6 +6701,46 @@ async function gateCandidates(deps, ctx, candidates, cfg) {
6682
6701
  }
6683
6702
 
6684
6703
  // src/services/librarian/ops/resolve.ts
6704
+ async function screenResolveCandidates(ambiguous, mode, floor, ask) {
6705
+ const whole = (warnReason) => warnReason ? { settled: /* @__PURE__ */ new Map(), rest: ambiguous, warnReason } : { settled: /* @__PURE__ */ new Map(), rest: ambiguous };
6706
+ if (mode !== "auto") return whole();
6707
+ if (floor === void 0) return whole("no-floor");
6708
+ if (!ask) return whole("no-classifier");
6709
+ const settled = /* @__PURE__ */ new Map();
6710
+ const rest = [];
6711
+ for (const g of ambiguous) {
6712
+ const best = g.neighbours[0];
6713
+ if (!best) {
6714
+ rest.push(g);
6715
+ continue;
6716
+ }
6717
+ const question = {
6718
+ kind: "binary",
6719
+ instructions: `Does this candidate add NO information beyond neighbour ${best.ref} (a pure duplicate: same claims, no new content)?
6720
+ Neighbour ${best.ref} title: ${best.title}
6721
+ Neighbour ${best.ref} body: ${safeSlice(best.body, 0, OPS_NEIGHBOUR_BODY_CHARS)}`
6722
+ };
6723
+ let response;
6724
+ try {
6725
+ response = await ask({
6726
+ state: classifierStateForFact({ title: g.candidate.fact.title, body: g.candidate.fact.body, tags: [] }),
6727
+ questions: { [best.ref]: question }
6728
+ });
6729
+ } catch (err) {
6730
+ if (err instanceof WikiBudgetExhausted) {
6731
+ return { settled: /* @__PURE__ */ new Map(), rest: ambiguous, budgetStop: { requiredEstimate: err.requiredEstimate } };
6732
+ }
6733
+ return whole("classifier-threw");
6734
+ }
6735
+ const checked = validateClassifierAnswer(response, best.ref, question);
6736
+ if (checked.ok && checked.answer.kind === "binary" && checked.answer.probability >= floor) {
6737
+ settled.set(g, { op: "NOOP", targetId: best.id });
6738
+ } else {
6739
+ rest.push(g);
6740
+ }
6741
+ }
6742
+ return { settled, rest };
6743
+ }
6685
6744
  function validateOp(raw, aliases) {
6686
6745
  if (!raw || typeof raw !== "object") return null;
6687
6746
  const r = raw;
@@ -6701,11 +6760,31 @@ function validateOp(raw, aliases) {
6701
6760
  }
6702
6761
  var aliasMapOf = (g) => new Map(g.neighbours.map((n) => [n.ref, n.id]));
6703
6762
  async function runResolve(deps, ctx, ambiguous, budget) {
6704
- const out = { ops: /* @__PURE__ */ new Map(), rejected: [], failed: [], overflowSkipped: [] };
6763
+ const out = { ops: /* @__PURE__ */ new Map(), rejected: [], failed: [], overflowSkipped: [], classifierSettled: [] };
6705
6764
  if (ambiguous.length === 0) return out;
6706
6765
  const { entityId, trigger } = ctx;
6766
+ const mode = resolveSystemOneResolve(deps.options.config);
6767
+ const floor = resolveResolveMinConfidence(deps.options.config);
6768
+ const provider = deps.options.llmProvider;
6769
+ const ask = mode === "auto" && typeof provider.classify === "function" ? (request) => callClassify(deps.options, { operation: "librarian", entityId, trigger, meter: ctx.meter }, request) : void 0;
6770
+ const screen = await screenResolveCandidates(ambiguous, mode, floor, ask);
6771
+ if (screen.budgetStop) return { ...out, budgetStop: screen.budgetStop };
6772
+ if (screen.warnReason === "no-classifier") {
6773
+ warnOnce(
6774
+ "[core-llm-wiki] systemOne: `systemOne.resolve` is 'auto' but the provider has no classify(); ambiguous candidates fall through to the generative resolve."
6775
+ );
6776
+ } else if (screen.warnReason === "classifier-threw") {
6777
+ warnOnce(
6778
+ "[core-llm-wiki] systemOne: `systemOne.resolve` is 'auto' but classify() threw during the resolve screen; ambiguous candidates fall through to the generative resolve."
6779
+ );
6780
+ }
6781
+ for (const [g, op] of screen.settled) {
6782
+ out.ops.set(g, op);
6783
+ out.classifierSettled.push(g.candidate.index);
6784
+ }
6785
+ if (screen.rest.length === 0) return out;
6707
6786
  const outcome = await runBatched({
6708
- items: ambiguous,
6787
+ items: screen.rest,
6709
6788
  buildPrompt: (batch) => deps.promptService.buildOpsResolvePrompt(
6710
6789
  batch.map((g, i) => ({
6711
6790
  item: i,
@@ -6994,6 +7073,16 @@ var runOpsLibrarianPass = async (deps, ctx) => {
6994
7073
  // (index into the merged extract batch)
6995
7074
  });
6996
7075
  }
7076
+ for (const itemIndex of res.classifierSettled) {
7077
+ diagnostics.push({
7078
+ entityId,
7079
+ operation: "librarian",
7080
+ trigger,
7081
+ code: "fact_deduplicated",
7082
+ detail: { itemIndex, reason: "classifier" }
7083
+ // (index into the merged extract batch)
7084
+ });
7085
+ }
6997
7086
  if (res.budgetStop) {
6998
7087
  diagnostics.discard();
6999
7088
  return { processedThrough: null, factsWritten: 0, budgetStop: res.budgetStop };
@@ -11789,6 +11878,6 @@ var WriteService = class {
11789
11878
  }
11790
11879
  };
11791
11880
 
11792
- export { BaseRepository, CLASSIFIER_MAX_CHOICES, CURRENT_SCHEMA_VERSION, CheckpointIncompleteError, DEFAULT_CHUNK_OVERLAP, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_TYPING_MIN_CONFIDENCE, DiagnosticBuffer, EMBED_CHARS_CEILING, EdgeRepository, EmbeddingService, EraseStepError, FTS5_DRAIN_CHUNK, FTS5_REBUILD_SNAPSHOT_KEY, FTS5_REBUILD_WM_KEY, FTS5_RECLAIM_MERGE_PAGES, FTS5_RETIRED_COUNTER_KEY, FTS5_RETIRED_TABLES_KEY, FTS5_STATE_KEY, FTS5_SWEEP_CURSOR_KEY, HEAL_ANCHORS_PER_CANDIDATE, HEAL_BATCH_SIZE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, HEAL_RECHECK_MS, HOOK_TIMEOUT_MARKER, ImportExportService, IngestionService, JobManager, MAX_EMBED_ATTEMPTS, MIGRATIONS, MaintenanceService, MetadataRepository, ONTOLOGY_ABSTAIN_SENTINEL, ONTOLOGY_BACKFILL_BATCH_SIZE, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_RECHECK_MS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, PromptService, PrunePartialFailureError, RetrievalService, SearchService, SourceStoreService, TemporalService, UnavailableIndexStrategy, UsageMeter, VectorRemovalRepository, VectorRemovalService, WikiBusyError, WikiDraftNotFound, WikiDuplicateHashError, WikiExternalDeletionError, WikiGraphNodeOwnershipConflict, WikiIngestEmptyError, WikiInvalidReadOptions, WikiMigrationRequiredError, WikiParseError, WikiSearchUnavailableError, WikiSourceRefHashCollision, WikiStrictOntologyViolation, WikiSupersedeError, WikiTransactionError, WriteService, __privateAdd, __privateGet, __privateSet, assertEntityId, assertEpochMs, chunkText, configureRandomSource, createLegacySourceTypeIndex, createdAtValue, detectSchemaVersion, drainChunkSql, drainHiSql, edgeTripleAllowed, emitDiagnostic, emptyManifest, entityDrainChunkSql, entityDrainHiSql, entitySummaryMetaKey, extractSqliteCode, factTokenCost, fts5LedgerDropSql, fts5PendingIndexesDdl, fts5TablesDdl, fts5TriggerNames, fts5TriggersDdl, generateId, idDrainChunkSql, idReindexChunkSql, isLiveAt, isReservedAbstainSlug, isRetiredTableName, isUsableDate, isWikiSearchUnavailableError, liveAtSql, nodeTypeReceipts, normalizeSourceHash, normalizeSourceRef, normalizeTitleKey, packFactsByBudget, parseEmbedding, parseJsonArray, parseJsonObject, parseStoredSourcePointer, passageFtsTablesDdl, passageFtsTriggerNames, passageFtsTriggersDdl, probePendingWork, readRebuildProgress, reanchorRebuildFingerprint, resolveContextBudget, resolveContextBudgetOrThrow, resolveDefaultChunkLength, resolveEdgeDefinitions, resolveEdgesMinConfidence, resolveGrounding, resolveLibrarianStrategy, resolveMaxPromptChars, resolveNodeType, resolveNodeTypeMatch, resolveSystemOneEdges, resolveSystemOneTyping, resolveTypingMinConfidence, retiredTableName, runSourceRefNormalize, safeSlice, serializeSourcePointer, setupDatabase, shouldEmitOntologyReceipt, sweepChunkSql, sweepHiSql, typeSatisfies, validUsage, validateInlineEdges, validateManifest, validateSourcePointerValue, warnChangedDefaultsOnce, warnOnce, windowChunkSql, windowHiSql, writeNormalizeStamp, writeRebuildStart };
11793
- //# sourceMappingURL=chunk-KB37MGFF.mjs.map
11794
- //# sourceMappingURL=chunk-KB37MGFF.mjs.map
11881
+ export { BaseRepository, CLASSIFIER_MAX_CHOICES, CURRENT_SCHEMA_VERSION, CheckpointIncompleteError, DEFAULT_CHUNK_OVERLAP, DEFAULT_MAX_CHUNK_LENGTH, DEFAULT_MAX_EMBED_CHARS, DEFAULT_TYPING_MIN_CONFIDENCE, DiagnosticBuffer, EMBED_CHARS_CEILING, EdgeRepository, EmbeddingService, EraseStepError, FTS5_DRAIN_CHUNK, FTS5_REBUILD_SNAPSHOT_KEY, FTS5_REBUILD_WM_KEY, FTS5_RECLAIM_MERGE_PAGES, FTS5_RETIRED_COUNTER_KEY, FTS5_RETIRED_TABLES_KEY, FTS5_STATE_KEY, FTS5_SWEEP_CURSOR_KEY, HEAL_ANCHORS_PER_CANDIDATE, HEAL_BATCH_SIZE, HEAL_MAX_FACT_BODY_CHARS_L3, HEAL_MAX_TASKS, HEAL_RECHECK_MS, HOOK_TIMEOUT_MARKER, ImportExportService, IngestionService, JobManager, MAX_EMBED_ATTEMPTS, MIGRATIONS, MaintenanceService, MetadataRepository, ONTOLOGY_ABSTAIN_SENTINEL, ONTOLOGY_BACKFILL_BATCH_SIZE, ONTOLOGY_BACKFILL_MAX_PROMPT_CHARS, ONTOLOGY_BACKFILL_RECHECK_MS, ONTOLOGY_BACKFILL_SYSTEM_PROMPT, PromptService, PrunePartialFailureError, RetrievalService, SearchService, SourceStoreService, TemporalService, UnavailableIndexStrategy, UsageMeter, VectorRemovalRepository, VectorRemovalService, WikiBusyError, WikiDraftNotFound, WikiDuplicateHashError, WikiExternalDeletionError, WikiGraphNodeOwnershipConflict, WikiIngestEmptyError, WikiInvalidReadOptions, WikiMigrationRequiredError, WikiParseError, WikiSearchUnavailableError, WikiSourceRefHashCollision, WikiStrictOntologyViolation, WikiSupersedeError, WikiTransactionError, WriteService, __privateAdd, __privateGet, __privateSet, assertEntityId, assertEpochMs, chunkText, configureRandomSource, createLegacySourceTypeIndex, createdAtValue, detectSchemaVersion, drainChunkSql, drainHiSql, edgeTripleAllowed, emitDiagnostic, emptyManifest, entityDrainChunkSql, entityDrainHiSql, entitySummaryMetaKey, extractSqliteCode, factTokenCost, fts5LedgerDropSql, fts5PendingIndexesDdl, fts5TablesDdl, fts5TriggerNames, fts5TriggersDdl, generateId, idDrainChunkSql, idReindexChunkSql, isLiveAt, isReservedAbstainSlug, isRetiredTableName, isUsableDate, isWikiSearchUnavailableError, liveAtSql, nodeTypeReceipts, normalizeSourceHash, normalizeSourceRef, normalizeTitleKey, packFactsByBudget, parseEmbedding, parseJsonArray, parseJsonObject, parseStoredSourcePointer, passageFtsTablesDdl, passageFtsTriggerNames, passageFtsTriggersDdl, probePendingWork, readRebuildProgress, reanchorRebuildFingerprint, resolveContextBudget, resolveContextBudgetOrThrow, resolveDefaultChunkLength, resolveEdgeDefinitions, resolveEdgesMinConfidence, resolveGrounding, resolveLibrarianStrategy, resolveMaxPromptChars, resolveNodeType, resolveNodeTypeMatch, resolveResolveMinConfidence, resolveSystemOneEdges, resolveSystemOneResolve, resolveSystemOneTyping, resolveTypingMinConfidence, retiredTableName, runSourceRefNormalize, safeSlice, serializeSourcePointer, setupDatabase, shouldEmitOntologyReceipt, sweepChunkSql, sweepHiSql, typeSatisfies, validUsage, validateInlineEdges, validateManifest, validateSourcePointerValue, warnChangedDefaultsOnce, warnOnce, windowChunkSql, windowHiSql, writeNormalizeStamp, writeRebuildStart };
11882
+ //# sourceMappingURL=chunk-4TG7RQF6.mjs.map
11883
+ //# sourceMappingURL=chunk-4TG7RQF6.mjs.map