@absolutejs/absolute 0.19.0-beta.612 → 0.19.0-beta.613

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/ai/rag/ui.js CHANGED
@@ -1486,6 +1486,10 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
1486
1486
  const vectorHits = channels.includes("vector") ? 1 : 0;
1487
1487
  const lexicalHits = channels.includes("lexical") ? 1 : 0;
1488
1488
  const hybridHits = isHybrid ? 1 : 0;
1489
+ const queryOrigin = source.metadata?.retrievalQueryOrigin;
1490
+ const primaryHits = queryOrigin === "primary" ? 1 : 0;
1491
+ const transformedHits = queryOrigin === "transformed" ? 1 : 0;
1492
+ const variantHits = queryOrigin === "variant" ? 1 : 0;
1489
1493
  if (!existing) {
1490
1494
  sections.set(key, {
1491
1495
  bestScore: source.score,
@@ -1496,10 +1500,13 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
1496
1500
  lexicalHits,
1497
1501
  parentLabel,
1498
1502
  path,
1503
+ primaryHits,
1499
1504
  sourceSet: new Set(source.source ? [source.source] : []),
1500
1505
  topChunkId: source.chunkId,
1501
1506
  topSource: source.source,
1502
1507
  totalScore: source.score,
1508
+ transformedHits,
1509
+ variantHits,
1503
1510
  vectorHits
1504
1511
  });
1505
1512
  continue;
@@ -1512,6 +1519,9 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
1512
1519
  existing.vectorHits += vectorHits;
1513
1520
  existing.lexicalHits += lexicalHits;
1514
1521
  existing.hybridHits += hybridHits;
1522
+ existing.primaryHits += primaryHits;
1523
+ existing.transformedHits += transformedHits;
1524
+ existing.variantHits += variantHits;
1515
1525
  if (source.score > existing.bestScore) {
1516
1526
  existing.bestScore = source.score;
1517
1527
  existing.topChunkId = source.chunkId;
@@ -1522,6 +1532,7 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
1522
1532
  const strongestBestHit = diagnostics.reduce((highest, section) => Math.max(highest, section.bestScore), 0);
1523
1533
  const parentLabelByKey = new Map(diagnostics.map((section) => [section.key, section.parentLabel]));
1524
1534
  const stageSectionCounts = new Map((trace?.steps ?? []).filter((step) => Array.isArray(step.sectionCounts) && step.sectionCounts.length > 0).map((step) => [step.stage, step.sectionCounts ?? []]));
1535
+ const stageSectionScores = new Map((trace?.steps ?? []).filter((step) => Array.isArray(step.sectionScores) && step.sectionScores.length > 0).map((step) => [step.stage, step.sectionScores ?? []]));
1525
1536
  return diagnostics.map((section) => {
1526
1537
  const siblingPool = diagnostics.filter((entry) => entry.parentLabel === section.parentLabel);
1527
1538
  const siblings = siblingPool.filter((entry) => entry.key !== section.key);
@@ -1543,16 +1554,30 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
1543
1554
  stage: step.stage
1544
1555
  })).filter((entry) => entry.count > 0) ?? [];
1545
1556
  const stageWeights = stageCounts.map((entry) => {
1557
+ const previousStageEntry = stageCounts[stageCounts.findIndex((candidate) => candidate.stage === entry.stage) - 1];
1546
1558
  const stageEntries = stageSectionCounts.get(entry.stage)?.filter((candidate) => candidate.count > 0) ?? [];
1559
+ const stageScoreEntries = stageSectionScores.get(entry.stage)?.filter((candidate) => candidate.totalScore > 0) ?? [];
1547
1560
  const stageTotal = stageEntries.reduce((sum, candidate) => sum + candidate.count, 0);
1561
+ const stageScoreTotal = stageScoreEntries.reduce((sum, candidate) => sum + candidate.totalScore, 0);
1548
1562
  const siblingStageEntries = stageEntries.filter((candidate) => candidate.key !== section.key && parentLabelByKey.get(candidate.key) === section.parentLabel);
1549
1563
  const parentStageEntries = stageEntries.filter((candidate) => parentLabelByKey.get(candidate.key) === section.parentLabel);
1564
+ const siblingStageScoreEntries = stageScoreEntries.filter((candidate) => candidate.key !== section.key && parentLabelByKey.get(candidate.key) === section.parentLabel);
1565
+ const parentStageScoreEntries = stageScoreEntries.filter((candidate) => parentLabelByKey.get(candidate.key) === section.parentLabel);
1550
1566
  const strongestStageSibling = siblingStageEntries.slice().sort((left, right) => right.count - left.count)[0];
1551
1567
  const parentStageTotal = parentStageEntries.reduce((sum, candidate) => sum + candidate.count, 0);
1568
+ const activeStageScore = stageScoreEntries.find((candidate) => candidate.key === section.key)?.totalScore;
1569
+ const strongestStageScoreSibling = siblingStageScoreEntries.slice().sort((left, right) => right.totalScore - left.totalScore)[0];
1570
+ const parentStageScoreTotal = parentStageScoreEntries.reduce((sum, candidate) => sum + candidate.totalScore, 0);
1552
1571
  const stageShare = stageTotal > 0 ? entry.count / stageTotal : 0;
1572
+ const retentionRate = typeof previousStageEntry?.count === "number" && previousStageEntry.count > 0 ? entry.count / previousStageEntry.count : undefined;
1573
+ const countDelta = typeof previousStageEntry?.count === "number" ? entry.count - previousStageEntry.count : undefined;
1553
1574
  const parentStageShare = parentStageTotal > 0 ? entry.count / parentStageTotal : undefined;
1575
+ const stageScoreShare = typeof activeStageScore === "number" && stageScoreTotal > 0 ? activeStageScore / stageScoreTotal : undefined;
1576
+ const parentStageScoreShare = typeof activeStageScore === "number" && parentStageScoreTotal > 0 ? activeStageScore / parentStageScoreTotal : undefined;
1554
1577
  const stageShareGap = stageTotal > 0 && strongestStageSibling ? entry.count / stageTotal - strongestStageSibling.count / stageTotal : undefined;
1555
1578
  const parentStageShareGap = parentStageTotal > 0 && strongestStageSibling ? entry.count / parentStageTotal - strongestStageSibling.count / parentStageTotal : undefined;
1579
+ const stageScoreShareGap = typeof activeStageScore === "number" && stageScoreTotal > 0 && strongestStageScoreSibling ? activeStageScore / stageScoreTotal - strongestStageScoreSibling.totalScore / stageScoreTotal : undefined;
1580
+ const parentStageScoreShareGap = typeof activeStageScore === "number" && parentStageScoreTotal > 0 && strongestStageScoreSibling ? activeStageScore / parentStageScoreTotal - strongestStageScoreSibling.totalScore / parentStageScoreTotal : undefined;
1556
1581
  const reasons2 = [];
1557
1582
  if (entry.stage === "rerank" && stageShare > 0.5 && (typeof stageShareGap !== "number" || stageShareGap > 0)) {
1558
1583
  reasons2.push("rerank_preserved_lead");
@@ -1566,20 +1591,65 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
1566
1591
  if (strongestStageSibling && (typeof stageShareGap === "number" && stageShareGap <= 0.1 || typeof parentStageShareGap === "number" && parentStageShareGap <= 0.1)) {
1567
1592
  reasons2.push("stage_runner_up_pressure");
1568
1593
  }
1594
+ if (typeof countDelta === "number") {
1595
+ if (countDelta > 0) {
1596
+ reasons2.push("stage_expanded");
1597
+ } else if (countDelta < 0) {
1598
+ reasons2.push("stage_narrowed");
1599
+ } else {
1600
+ reasons2.push("stage_held");
1601
+ }
1602
+ }
1569
1603
  return {
1570
1604
  count: entry.count,
1605
+ countDelta,
1606
+ parentStageScoreShare,
1571
1607
  parentStageShare,
1572
1608
  parentStageShareGap,
1609
+ previousCount: previousStageEntry?.count,
1610
+ previousStage: previousStageEntry?.stage,
1573
1611
  reasons: reasons2,
1612
+ retentionRate,
1574
1613
  stage: entry.stage,
1614
+ stageScoreShare,
1615
+ stageScoreShareGap,
1575
1616
  stageShare,
1576
1617
  stageShareGap,
1618
+ totalScore: activeStageScore,
1577
1619
  strongestSiblingCount: strongestStageSibling?.count,
1578
1620
  strongestSiblingLabel: strongestStageSibling ? diagnostics.find((candidate) => candidate.key === strongestStageSibling.key)?.label ?? strongestStageSibling.key : undefined
1579
1621
  };
1580
1622
  });
1581
1623
  const firstSeenStage = stageCounts[0]?.stage;
1582
1624
  const lastSeenStage = stageCounts.at(-1)?.stage;
1625
+ const peakStageEntry = stageCounts.reduce((highest, entry) => !highest || entry.count > highest.count ? entry : highest, undefined);
1626
+ const finalStageEntry = stageCounts.at(-1);
1627
+ const peakCount = peakStageEntry?.count ?? section.count;
1628
+ const finalCount = finalStageEntry?.count;
1629
+ const finalRetentionRate = typeof finalCount === "number" && peakCount > 0 ? finalCount / peakCount : undefined;
1630
+ const dropFromPeak = typeof finalCount === "number" ? peakCount - finalCount : undefined;
1631
+ const queryAttributionReasons = [];
1632
+ const queryAttributionMode = section.primaryHits > 0 && section.transformedHits === 0 && section.variantHits === 0 ? "primary" : section.transformedHits > 0 && section.primaryHits === 0 && section.variantHits === 0 ? "transformed" : section.variantHits > 0 && section.primaryHits === 0 && section.transformedHits === 0 ? "variant" : "mixed";
1633
+ if (queryAttributionMode === "primary") {
1634
+ queryAttributionReasons.push("base_query_only");
1635
+ }
1636
+ if (queryAttributionMode === "transformed") {
1637
+ queryAttributionReasons.push("transformed_query_only");
1638
+ queryAttributionReasons.push("transform_introduced");
1639
+ }
1640
+ if (queryAttributionMode === "variant") {
1641
+ queryAttributionReasons.push("variant_only");
1642
+ queryAttributionReasons.push("variant_supported");
1643
+ }
1644
+ if (queryAttributionMode === "mixed") {
1645
+ queryAttributionReasons.push("mixed_query_sources");
1646
+ if (section.variantHits > 0) {
1647
+ queryAttributionReasons.push("variant_supported");
1648
+ }
1649
+ if (section.transformedHits > 0 && section.primaryHits === 0) {
1650
+ queryAttributionReasons.push("transform_introduced");
1651
+ }
1652
+ }
1583
1653
  if (section.bestScore >= strongestBestHit) {
1584
1654
  reasons.push("best_hit");
1585
1655
  }
@@ -1613,7 +1683,19 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
1613
1683
  parentShareGap: typeof parentShare === "number" && strongestSibling && parentTotal > 0 ? parentShare - strongestSibling.totalScore / parentTotal : undefined,
1614
1684
  path: section.path,
1615
1685
  firstSeenStage,
1686
+ finalCount,
1687
+ finalRetentionRate,
1616
1688
  lastSeenStage,
1689
+ dropFromPeak,
1690
+ peakCount,
1691
+ peakStage: peakStageEntry?.stage,
1692
+ queryAttribution: {
1693
+ mode: queryAttributionMode,
1694
+ primaryHits: section.primaryHits,
1695
+ reasons: queryAttributionReasons,
1696
+ transformedHits: section.transformedHits,
1697
+ variantHits: section.variantHits
1698
+ },
1617
1699
  retrievalMode: trace?.mode,
1618
1700
  reasons,
1619
1701
  rerankApplied: trace?.steps.some((step) => step.stage === "rerank" && step.metadata?.applied === true),
@@ -2472,5 +2554,5 @@ export {
2472
2554
  buildRAGAdminActionPresentation
2473
2555
  };
2474
2556
 
2475
- //# debugId=6FA78F50EB1D56B164756E2164756E21
2557
+ //# debugId=731B1F9EA877A62664756E2164756E21
2476
2558
  //# sourceMappingURL=ui.js.map