@absolutejs/absolute 0.19.0-beta.611 → 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.
@@ -4668,6 +4668,10 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4668
4668
  const vectorHits = channels.includes("vector") ? 1 : 0;
4669
4669
  const lexicalHits = channels.includes("lexical") ? 1 : 0;
4670
4670
  const hybridHits = isHybrid ? 1 : 0;
4671
+ const queryOrigin = source.metadata?.retrievalQueryOrigin;
4672
+ const primaryHits = queryOrigin === "primary" ? 1 : 0;
4673
+ const transformedHits = queryOrigin === "transformed" ? 1 : 0;
4674
+ const variantHits = queryOrigin === "variant" ? 1 : 0;
4671
4675
  if (!existing) {
4672
4676
  sections.set(key, {
4673
4677
  bestScore: source.score,
@@ -4678,10 +4682,13 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4678
4682
  lexicalHits,
4679
4683
  parentLabel,
4680
4684
  path,
4685
+ primaryHits,
4681
4686
  sourceSet: new Set(source.source ? [source.source] : []),
4682
4687
  topChunkId: source.chunkId,
4683
4688
  topSource: source.source,
4684
4689
  totalScore: source.score,
4690
+ transformedHits,
4691
+ variantHits,
4685
4692
  vectorHits
4686
4693
  });
4687
4694
  continue;
@@ -4694,6 +4701,9 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4694
4701
  existing.vectorHits += vectorHits;
4695
4702
  existing.lexicalHits += lexicalHits;
4696
4703
  existing.hybridHits += hybridHits;
4704
+ existing.primaryHits += primaryHits;
4705
+ existing.transformedHits += transformedHits;
4706
+ existing.variantHits += variantHits;
4697
4707
  if (source.score > existing.bestScore) {
4698
4708
  existing.bestScore = source.score;
4699
4709
  existing.topChunkId = source.chunkId;
@@ -4702,6 +4712,9 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4702
4712
  }
4703
4713
  const diagnostics = [...sections.values()];
4704
4714
  const strongestBestHit = diagnostics.reduce((highest, section) => Math.max(highest, section.bestScore), 0);
4715
+ const parentLabelByKey = new Map(diagnostics.map((section) => [section.key, section.parentLabel]));
4716
+ const stageSectionCounts = new Map((trace?.steps ?? []).filter((step) => Array.isArray(step.sectionCounts) && step.sectionCounts.length > 0).map((step) => [step.stage, step.sectionCounts ?? []]));
4717
+ const stageSectionScores = new Map((trace?.steps ?? []).filter((step) => Array.isArray(step.sectionScores) && step.sectionScores.length > 0).map((step) => [step.stage, step.sectionScores ?? []]));
4705
4718
  return diagnostics.map((section) => {
4706
4719
  const siblingPool = diagnostics.filter((entry) => entry.parentLabel === section.parentLabel);
4707
4720
  const siblings = siblingPool.filter((entry) => entry.key !== section.key);
@@ -4722,8 +4735,103 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4722
4735
  count: step.sectionCounts?.find((entry) => entry.key === section.key)?.count ?? 0,
4723
4736
  stage: step.stage
4724
4737
  })).filter((entry) => entry.count > 0) ?? [];
4738
+ const stageWeights = stageCounts.map((entry) => {
4739
+ const previousStageEntry = stageCounts[stageCounts.findIndex((candidate) => candidate.stage === entry.stage) - 1];
4740
+ const stageEntries = stageSectionCounts.get(entry.stage)?.filter((candidate) => candidate.count > 0) ?? [];
4741
+ const stageScoreEntries = stageSectionScores.get(entry.stage)?.filter((candidate) => candidate.totalScore > 0) ?? [];
4742
+ const stageTotal = stageEntries.reduce((sum, candidate) => sum + candidate.count, 0);
4743
+ const stageScoreTotal = stageScoreEntries.reduce((sum, candidate) => sum + candidate.totalScore, 0);
4744
+ const siblingStageEntries = stageEntries.filter((candidate) => candidate.key !== section.key && parentLabelByKey.get(candidate.key) === section.parentLabel);
4745
+ const parentStageEntries = stageEntries.filter((candidate) => parentLabelByKey.get(candidate.key) === section.parentLabel);
4746
+ const siblingStageScoreEntries = stageScoreEntries.filter((candidate) => candidate.key !== section.key && parentLabelByKey.get(candidate.key) === section.parentLabel);
4747
+ const parentStageScoreEntries = stageScoreEntries.filter((candidate) => parentLabelByKey.get(candidate.key) === section.parentLabel);
4748
+ const strongestStageSibling = siblingStageEntries.slice().sort((left, right) => right.count - left.count)[0];
4749
+ const parentStageTotal = parentStageEntries.reduce((sum, candidate) => sum + candidate.count, 0);
4750
+ const activeStageScore = stageScoreEntries.find((candidate) => candidate.key === section.key)?.totalScore;
4751
+ const strongestStageScoreSibling = siblingStageScoreEntries.slice().sort((left, right) => right.totalScore - left.totalScore)[0];
4752
+ const parentStageScoreTotal = parentStageScoreEntries.reduce((sum, candidate) => sum + candidate.totalScore, 0);
4753
+ const stageShare = stageTotal > 0 ? entry.count / stageTotal : 0;
4754
+ const retentionRate = typeof previousStageEntry?.count === "number" && previousStageEntry.count > 0 ? entry.count / previousStageEntry.count : undefined;
4755
+ const countDelta = typeof previousStageEntry?.count === "number" ? entry.count - previousStageEntry.count : undefined;
4756
+ const parentStageShare = parentStageTotal > 0 ? entry.count / parentStageTotal : undefined;
4757
+ const stageScoreShare = typeof activeStageScore === "number" && stageScoreTotal > 0 ? activeStageScore / stageScoreTotal : undefined;
4758
+ const parentStageScoreShare = typeof activeStageScore === "number" && parentStageScoreTotal > 0 ? activeStageScore / parentStageScoreTotal : undefined;
4759
+ const stageShareGap = stageTotal > 0 && strongestStageSibling ? entry.count / stageTotal - strongestStageSibling.count / stageTotal : undefined;
4760
+ const parentStageShareGap = parentStageTotal > 0 && strongestStageSibling ? entry.count / parentStageTotal - strongestStageSibling.count / parentStageTotal : undefined;
4761
+ const stageScoreShareGap = typeof activeStageScore === "number" && stageScoreTotal > 0 && strongestStageScoreSibling ? activeStageScore / stageScoreTotal - strongestStageScoreSibling.totalScore / stageScoreTotal : undefined;
4762
+ const parentStageScoreShareGap = typeof activeStageScore === "number" && parentStageScoreTotal > 0 && strongestStageScoreSibling ? activeStageScore / parentStageScoreTotal - strongestStageScoreSibling.totalScore / parentStageScoreTotal : undefined;
4763
+ const reasons2 = [];
4764
+ if (entry.stage === "rerank" && stageShare > 0.5 && (typeof stageShareGap !== "number" || stageShareGap > 0)) {
4765
+ reasons2.push("rerank_preserved_lead");
4766
+ }
4767
+ if (entry.stage === "finalize" && stageShare >= 0.5) {
4768
+ reasons2.push("final_stage_concentration");
4769
+ }
4770
+ if (entry.stage === "finalize" && typeof parentStageShare === "number" && parentStageShare >= 0.6 && (typeof parentStageShareGap !== "number" || parentStageShareGap > 0)) {
4771
+ reasons2.push("final_stage_dominant_within_parent");
4772
+ }
4773
+ if (strongestStageSibling && (typeof stageShareGap === "number" && stageShareGap <= 0.1 || typeof parentStageShareGap === "number" && parentStageShareGap <= 0.1)) {
4774
+ reasons2.push("stage_runner_up_pressure");
4775
+ }
4776
+ if (typeof countDelta === "number") {
4777
+ if (countDelta > 0) {
4778
+ reasons2.push("stage_expanded");
4779
+ } else if (countDelta < 0) {
4780
+ reasons2.push("stage_narrowed");
4781
+ } else {
4782
+ reasons2.push("stage_held");
4783
+ }
4784
+ }
4785
+ return {
4786
+ count: entry.count,
4787
+ countDelta,
4788
+ parentStageScoreShare,
4789
+ parentStageShare,
4790
+ parentStageShareGap,
4791
+ previousCount: previousStageEntry?.count,
4792
+ previousStage: previousStageEntry?.stage,
4793
+ reasons: reasons2,
4794
+ retentionRate,
4795
+ stage: entry.stage,
4796
+ stageScoreShare,
4797
+ stageScoreShareGap,
4798
+ stageShare,
4799
+ stageShareGap,
4800
+ totalScore: activeStageScore,
4801
+ strongestSiblingCount: strongestStageSibling?.count,
4802
+ strongestSiblingLabel: strongestStageSibling ? diagnostics.find((candidate) => candidate.key === strongestStageSibling.key)?.label ?? strongestStageSibling.key : undefined
4803
+ };
4804
+ });
4725
4805
  const firstSeenStage = stageCounts[0]?.stage;
4726
4806
  const lastSeenStage = stageCounts.at(-1)?.stage;
4807
+ const peakStageEntry = stageCounts.reduce((highest, entry) => !highest || entry.count > highest.count ? entry : highest, undefined);
4808
+ const finalStageEntry = stageCounts.at(-1);
4809
+ const peakCount = peakStageEntry?.count ?? section.count;
4810
+ const finalCount = finalStageEntry?.count;
4811
+ const finalRetentionRate = typeof finalCount === "number" && peakCount > 0 ? finalCount / peakCount : undefined;
4812
+ const dropFromPeak = typeof finalCount === "number" ? peakCount - finalCount : undefined;
4813
+ const queryAttributionReasons = [];
4814
+ 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";
4815
+ if (queryAttributionMode === "primary") {
4816
+ queryAttributionReasons.push("base_query_only");
4817
+ }
4818
+ if (queryAttributionMode === "transformed") {
4819
+ queryAttributionReasons.push("transformed_query_only");
4820
+ queryAttributionReasons.push("transform_introduced");
4821
+ }
4822
+ if (queryAttributionMode === "variant") {
4823
+ queryAttributionReasons.push("variant_only");
4824
+ queryAttributionReasons.push("variant_supported");
4825
+ }
4826
+ if (queryAttributionMode === "mixed") {
4827
+ queryAttributionReasons.push("mixed_query_sources");
4828
+ if (section.variantHits > 0) {
4829
+ queryAttributionReasons.push("variant_supported");
4830
+ }
4831
+ if (section.transformedHits > 0 && section.primaryHits === 0) {
4832
+ queryAttributionReasons.push("transform_introduced");
4833
+ }
4834
+ }
4727
4835
  if (section.bestScore >= strongestBestHit) {
4728
4836
  reasons.push("best_hit");
4729
4837
  }
@@ -4757,13 +4865,26 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4757
4865
  parentShareGap: typeof parentShare === "number" && strongestSibling && parentTotal > 0 ? parentShare - strongestSibling.totalScore / parentTotal : undefined,
4758
4866
  path: section.path,
4759
4867
  firstSeenStage,
4868
+ finalCount,
4869
+ finalRetentionRate,
4760
4870
  lastSeenStage,
4871
+ dropFromPeak,
4872
+ peakCount,
4873
+ peakStage: peakStageEntry?.stage,
4874
+ queryAttribution: {
4875
+ mode: queryAttributionMode,
4876
+ primaryHits: section.primaryHits,
4877
+ reasons: queryAttributionReasons,
4878
+ transformedHits: section.transformedHits,
4879
+ variantHits: section.variantHits
4880
+ },
4761
4881
  retrievalMode: trace?.mode,
4762
4882
  reasons,
4763
4883
  rerankApplied: trace?.steps.some((step) => step.stage === "rerank" && step.metadata?.applied === true),
4764
4884
  scoreShare,
4765
4885
  scoreThresholdApplied: trace?.steps.some((step) => step.stage === "score_filter"),
4766
4886
  stageCounts,
4887
+ stageWeights,
4767
4888
  siblingCount: siblings.length,
4768
4889
  siblingScoreGap: strongestSibling ? section.totalScore - strongestSibling.totalScore : undefined,
4769
4890
  sourceCount: section.sourceSet.size,
@@ -8099,5 +8220,5 @@ export {
8099
8220
  createAIStream
8100
8221
  };
8101
8222
 
8102
- //# debugId=2E85D191A5FE00B864756E2164756E21
8223
+ //# debugId=6D07F2B76E9A078764756E2164756E21
8103
8224
  //# sourceMappingURL=index.js.map