@equationalapplications/core-llm-wiki 7.7.0 → 7.7.2

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/testing.js CHANGED
@@ -1971,11 +1971,16 @@ var IngestionService = class {
1971
1971
  let ingestedChunks = 0;
1972
1972
  let failedChunks = 0;
1973
1973
  const failures = [];
1974
- const seen = /* @__PURE__ */ new Set();
1975
- const orderedChunkFacts = [];
1976
- const groundingLedger = /* @__PURE__ */ new Map();
1974
+ const winners = /* @__PURE__ */ new Map();
1977
1975
  const diagBuffer = new DiagnosticBuffer();
1978
1976
  const diagBase = { entityId, operation: "ingest", trigger: "call" };
1977
+ const pushDeduplicated = (chunkIndex, itemIndex) => {
1978
+ diagBuffer.push({
1979
+ ...diagBase,
1980
+ code: "fact_deduplicated",
1981
+ detail: { sourceRef, chunkIndex, itemIndex, reason: "exact_title" }
1982
+ });
1983
+ };
1979
1984
  for (const [chunkIndex, slot] of chunkResults.entries()) {
1980
1985
  if (slot.status === "failed") {
1981
1986
  failedChunks++;
@@ -1986,22 +1991,32 @@ var IngestionService = class {
1986
1991
  for (const r of slot.rejected) {
1987
1992
  diagBuffer.push({ ...diagBase, code: "fact_rejected", detail: { sourceRef, chunkIndex, itemIndex: r.itemIndex, reason: r.reason } });
1988
1993
  }
1989
- const dedupedFacts = [];
1990
1994
  slot.facts.forEach((fact, k) => {
1991
- const normalizedTitle = normalizeTitleKey(fact.title);
1992
- if (!seen.has(normalizedTitle)) {
1993
- seen.add(normalizedTitle);
1994
- dedupedFacts.push(fact);
1995
- if (ingestGrounding) groundingLedger.set(fact, { verdict: slot.verdicts[k], chunkIndex, itemIndex: slot.itemIndexes[k] });
1995
+ const key = normalizeTitleKey(fact.title);
1996
+ const candidate = { chunkIndex, k, itemIndex: slot.itemIndexes[k], rank: slot.verdicts[k]?.status === "grounded" ? 1 : 0 };
1997
+ const current = winners.get(key);
1998
+ if (!current) {
1999
+ winners.set(key, candidate);
2000
+ } else if (candidate.rank > current.rank) {
2001
+ pushDeduplicated(current.chunkIndex, current.itemIndex);
2002
+ winners.set(key, candidate);
1996
2003
  } else {
1997
- diagBuffer.push({
1998
- ...diagBase,
1999
- code: "fact_deduplicated",
2000
- detail: { sourceRef, chunkIndex, itemIndex: slot.itemIndexes[k], reason: "exact_title" }
2001
- });
2004
+ pushDeduplicated(candidate.chunkIndex, candidate.itemIndex);
2002
2005
  }
2003
2006
  });
2004
- orderedChunkFacts.push({ facts: dedupedFacts, ontology_updates: slot.ontology_updates });
2007
+ }
2008
+ const orderedChunkFacts = [];
2009
+ const groundingLedger = /* @__PURE__ */ new Map();
2010
+ for (const [chunkIndex, slot] of chunkResults.entries()) {
2011
+ if (slot.status === "failed") continue;
2012
+ const keptFacts = [];
2013
+ slot.facts.forEach((fact, k) => {
2014
+ const winner = winners.get(normalizeTitleKey(fact.title));
2015
+ if (winner?.chunkIndex !== chunkIndex || winner.k !== k) return;
2016
+ keptFacts.push(fact);
2017
+ if (ingestGrounding) groundingLedger.set(fact, { verdict: slot.verdicts[k], chunkIndex, itemIndex: winner.itemIndex });
2018
+ });
2019
+ orderedChunkFacts.push({ facts: keptFacts, ontology_updates: slot.ontology_updates });
2005
2020
  }
2006
2021
  for (const reason of ["parse", "llm"]) {
2007
2022
  const ofReason = failures.filter((f) => f.source === reason);