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

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.
@@ -66,6 +66,7 @@ export type RAGSourceSummary = {
66
66
  structure?: RAGChunkStructure;
67
67
  };
68
68
  export type RAGSectionRetrievalReason = 'best_hit' | 'multi_hit_section' | 'dominant_within_parent' | 'only_section_in_parent' | 'concentrated_evidence';
69
+ export type RAGSectionTraceWeightReason = 'rerank_preserved_lead' | 'final_stage_concentration' | 'final_stage_dominant_within_parent' | 'stage_runner_up_pressure';
69
70
  export type RAGSectionRetrievalDiagnostic = {
70
71
  key: string;
71
72
  label: string;
@@ -88,6 +89,23 @@ export type RAGSectionRetrievalDiagnostic = {
88
89
  vectorHits: number;
89
90
  lexicalHits: number;
90
91
  hybridHits: number;
92
+ stageCounts: Array<{
93
+ stage: RAGRetrievalTraceStage;
94
+ count: number;
95
+ }>;
96
+ stageWeights: Array<{
97
+ stage: RAGRetrievalTraceStage;
98
+ count: number;
99
+ stageShare: number;
100
+ parentStageShare?: number;
101
+ stageShareGap?: number;
102
+ parentStageShareGap?: number;
103
+ strongestSiblingLabel?: string;
104
+ strongestSiblingCount?: number;
105
+ reasons: RAGSectionTraceWeightReason[];
106
+ }>;
107
+ firstSeenStage?: RAGRetrievalTraceStage;
108
+ lastSeenStage?: RAGRetrievalTraceStage;
91
109
  retrievalMode?: RAGHybridRetrievalMode;
92
110
  rerankApplied?: boolean;
93
111
  sourceBalanceApplied?: boolean;
@@ -663,6 +681,11 @@ export type RAGRetrievalTraceStep = {
663
681
  label: string;
664
682
  durationMs?: number;
665
683
  count?: number;
684
+ sectionCounts?: Array<{
685
+ key: string;
686
+ label: string;
687
+ count: number;
688
+ }>;
666
689
  metadata?: Record<string, string | number | boolean | null>;
667
690
  };
668
691
  export type RAGRetrievalTrace = {
@@ -4702,6 +4702,8 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4702
4702
  }
4703
4703
  const diagnostics = [...sections.values()];
4704
4704
  const strongestBestHit = diagnostics.reduce((highest, section) => Math.max(highest, section.bestScore), 0);
4705
+ const parentLabelByKey = new Map(diagnostics.map((section) => [section.key, section.parentLabel]));
4706
+ const stageSectionCounts = new Map((trace?.steps ?? []).filter((step) => Array.isArray(step.sectionCounts) && step.sectionCounts.length > 0).map((step) => [step.stage, step.sectionCounts ?? []]));
4705
4707
  return diagnostics.map((section) => {
4706
4708
  const siblingPool = diagnostics.filter((entry) => entry.parentLabel === section.parentLabel);
4707
4709
  const siblings = siblingPool.filter((entry) => entry.key !== section.key);
@@ -4718,6 +4720,48 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4718
4720
  totalScore: entry.totalScore
4719
4721
  })).sort((left, right) => right.totalScore - left.totalScore) : [];
4720
4722
  const reasons = [];
4723
+ const stageCounts = trace?.steps.map((step) => ({
4724
+ count: step.sectionCounts?.find((entry) => entry.key === section.key)?.count ?? 0,
4725
+ stage: step.stage
4726
+ })).filter((entry) => entry.count > 0) ?? [];
4727
+ const stageWeights = stageCounts.map((entry) => {
4728
+ const stageEntries = stageSectionCounts.get(entry.stage)?.filter((candidate) => candidate.count > 0) ?? [];
4729
+ const stageTotal = stageEntries.reduce((sum, candidate) => sum + candidate.count, 0);
4730
+ const siblingStageEntries = stageEntries.filter((candidate) => candidate.key !== section.key && parentLabelByKey.get(candidate.key) === section.parentLabel);
4731
+ const parentStageEntries = stageEntries.filter((candidate) => parentLabelByKey.get(candidate.key) === section.parentLabel);
4732
+ const strongestStageSibling = siblingStageEntries.slice().sort((left, right) => right.count - left.count)[0];
4733
+ const parentStageTotal = parentStageEntries.reduce((sum, candidate) => sum + candidate.count, 0);
4734
+ const stageShare = stageTotal > 0 ? entry.count / stageTotal : 0;
4735
+ const parentStageShare = parentStageTotal > 0 ? entry.count / parentStageTotal : undefined;
4736
+ const stageShareGap = stageTotal > 0 && strongestStageSibling ? entry.count / stageTotal - strongestStageSibling.count / stageTotal : undefined;
4737
+ const parentStageShareGap = parentStageTotal > 0 && strongestStageSibling ? entry.count / parentStageTotal - strongestStageSibling.count / parentStageTotal : undefined;
4738
+ const reasons2 = [];
4739
+ if (entry.stage === "rerank" && stageShare > 0.5 && (typeof stageShareGap !== "number" || stageShareGap > 0)) {
4740
+ reasons2.push("rerank_preserved_lead");
4741
+ }
4742
+ if (entry.stage === "finalize" && stageShare >= 0.5) {
4743
+ reasons2.push("final_stage_concentration");
4744
+ }
4745
+ if (entry.stage === "finalize" && typeof parentStageShare === "number" && parentStageShare >= 0.6 && (typeof parentStageShareGap !== "number" || parentStageShareGap > 0)) {
4746
+ reasons2.push("final_stage_dominant_within_parent");
4747
+ }
4748
+ if (strongestStageSibling && (typeof stageShareGap === "number" && stageShareGap <= 0.1 || typeof parentStageShareGap === "number" && parentStageShareGap <= 0.1)) {
4749
+ reasons2.push("stage_runner_up_pressure");
4750
+ }
4751
+ return {
4752
+ count: entry.count,
4753
+ parentStageShare,
4754
+ parentStageShareGap,
4755
+ reasons: reasons2,
4756
+ stage: entry.stage,
4757
+ stageShare,
4758
+ stageShareGap,
4759
+ strongestSiblingCount: strongestStageSibling?.count,
4760
+ strongestSiblingLabel: strongestStageSibling ? diagnostics.find((candidate) => candidate.key === strongestStageSibling.key)?.label ?? strongestStageSibling.key : undefined
4761
+ };
4762
+ });
4763
+ const firstSeenStage = stageCounts[0]?.stage;
4764
+ const lastSeenStage = stageCounts.at(-1)?.stage;
4721
4765
  if (section.bestScore >= strongestBestHit) {
4722
4766
  reasons.push("best_hit");
4723
4767
  }
@@ -4750,11 +4794,15 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4750
4794
  parentShare,
4751
4795
  parentShareGap: typeof parentShare === "number" && strongestSibling && parentTotal > 0 ? parentShare - strongestSibling.totalScore / parentTotal : undefined,
4752
4796
  path: section.path,
4797
+ firstSeenStage,
4798
+ lastSeenStage,
4753
4799
  retrievalMode: trace?.mode,
4754
4800
  reasons,
4755
4801
  rerankApplied: trace?.steps.some((step) => step.stage === "rerank" && step.metadata?.applied === true),
4756
4802
  scoreShare,
4757
4803
  scoreThresholdApplied: trace?.steps.some((step) => step.stage === "score_filter"),
4804
+ stageCounts,
4805
+ stageWeights,
4758
4806
  siblingCount: siblings.length,
4759
4807
  siblingScoreGap: strongestSibling ? section.totalScore - strongestSibling.totalScore : undefined,
4760
4808
  sourceCount: section.sourceSet.size,
@@ -8061,5 +8109,5 @@ export {
8061
8109
  AIStreamKey
8062
8110
  };
8063
8111
 
8064
- //# debugId=1899685E13726C0C64756E2164756E21
8112
+ //# debugId=E536AFF01F55D6B764756E2164756E21
8065
8113
  //# sourceMappingURL=index.js.map