@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.
@@ -2264,6 +2264,10 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2264
2264
  const vectorHits = channels.includes("vector") ? 1 : 0;
2265
2265
  const lexicalHits = channels.includes("lexical") ? 1 : 0;
2266
2266
  const hybridHits = isHybrid ? 1 : 0;
2267
+ const queryOrigin = source.metadata?.retrievalQueryOrigin;
2268
+ const primaryHits = queryOrigin === "primary" ? 1 : 0;
2269
+ const transformedHits = queryOrigin === "transformed" ? 1 : 0;
2270
+ const variantHits = queryOrigin === "variant" ? 1 : 0;
2267
2271
  if (!existing) {
2268
2272
  sections.set(key, {
2269
2273
  bestScore: source.score,
@@ -2274,10 +2278,13 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2274
2278
  lexicalHits,
2275
2279
  parentLabel,
2276
2280
  path,
2281
+ primaryHits,
2277
2282
  sourceSet: new Set(source.source ? [source.source] : []),
2278
2283
  topChunkId: source.chunkId,
2279
2284
  topSource: source.source,
2280
2285
  totalScore: source.score,
2286
+ transformedHits,
2287
+ variantHits,
2281
2288
  vectorHits
2282
2289
  });
2283
2290
  continue;
@@ -2290,6 +2297,9 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2290
2297
  existing.vectorHits += vectorHits;
2291
2298
  existing.lexicalHits += lexicalHits;
2292
2299
  existing.hybridHits += hybridHits;
2300
+ existing.primaryHits += primaryHits;
2301
+ existing.transformedHits += transformedHits;
2302
+ existing.variantHits += variantHits;
2293
2303
  if (source.score > existing.bestScore) {
2294
2304
  existing.bestScore = source.score;
2295
2305
  existing.topChunkId = source.chunkId;
@@ -2298,6 +2308,9 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2298
2308
  }
2299
2309
  const diagnostics = [...sections.values()];
2300
2310
  const strongestBestHit = diagnostics.reduce((highest, section) => Math.max(highest, section.bestScore), 0);
2311
+ const parentLabelByKey = new Map(diagnostics.map((section) => [section.key, section.parentLabel]));
2312
+ const stageSectionCounts = new Map((trace?.steps ?? []).filter((step) => Array.isArray(step.sectionCounts) && step.sectionCounts.length > 0).map((step) => [step.stage, step.sectionCounts ?? []]));
2313
+ const stageSectionScores = new Map((trace?.steps ?? []).filter((step) => Array.isArray(step.sectionScores) && step.sectionScores.length > 0).map((step) => [step.stage, step.sectionScores ?? []]));
2301
2314
  return diagnostics.map((section) => {
2302
2315
  const siblingPool = diagnostics.filter((entry) => entry.parentLabel === section.parentLabel);
2303
2316
  const siblings = siblingPool.filter((entry) => entry.key !== section.key);
@@ -2318,8 +2331,103 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2318
2331
  count: step.sectionCounts?.find((entry) => entry.key === section.key)?.count ?? 0,
2319
2332
  stage: step.stage
2320
2333
  })).filter((entry) => entry.count > 0) ?? [];
2334
+ const stageWeights = stageCounts.map((entry) => {
2335
+ const previousStageEntry = stageCounts[stageCounts.findIndex((candidate) => candidate.stage === entry.stage) - 1];
2336
+ const stageEntries = stageSectionCounts.get(entry.stage)?.filter((candidate) => candidate.count > 0) ?? [];
2337
+ const stageScoreEntries = stageSectionScores.get(entry.stage)?.filter((candidate) => candidate.totalScore > 0) ?? [];
2338
+ const stageTotal = stageEntries.reduce((sum, candidate) => sum + candidate.count, 0);
2339
+ const stageScoreTotal = stageScoreEntries.reduce((sum, candidate) => sum + candidate.totalScore, 0);
2340
+ const siblingStageEntries = stageEntries.filter((candidate) => candidate.key !== section.key && parentLabelByKey.get(candidate.key) === section.parentLabel);
2341
+ const parentStageEntries = stageEntries.filter((candidate) => parentLabelByKey.get(candidate.key) === section.parentLabel);
2342
+ const siblingStageScoreEntries = stageScoreEntries.filter((candidate) => candidate.key !== section.key && parentLabelByKey.get(candidate.key) === section.parentLabel);
2343
+ const parentStageScoreEntries = stageScoreEntries.filter((candidate) => parentLabelByKey.get(candidate.key) === section.parentLabel);
2344
+ const strongestStageSibling = siblingStageEntries.slice().sort((left, right) => right.count - left.count)[0];
2345
+ const parentStageTotal = parentStageEntries.reduce((sum, candidate) => sum + candidate.count, 0);
2346
+ const activeStageScore = stageScoreEntries.find((candidate) => candidate.key === section.key)?.totalScore;
2347
+ const strongestStageScoreSibling = siblingStageScoreEntries.slice().sort((left, right) => right.totalScore - left.totalScore)[0];
2348
+ const parentStageScoreTotal = parentStageScoreEntries.reduce((sum, candidate) => sum + candidate.totalScore, 0);
2349
+ const stageShare = stageTotal > 0 ? entry.count / stageTotal : 0;
2350
+ const retentionRate = typeof previousStageEntry?.count === "number" && previousStageEntry.count > 0 ? entry.count / previousStageEntry.count : undefined;
2351
+ const countDelta = typeof previousStageEntry?.count === "number" ? entry.count - previousStageEntry.count : undefined;
2352
+ const parentStageShare = parentStageTotal > 0 ? entry.count / parentStageTotal : undefined;
2353
+ const stageScoreShare = typeof activeStageScore === "number" && stageScoreTotal > 0 ? activeStageScore / stageScoreTotal : undefined;
2354
+ const parentStageScoreShare = typeof activeStageScore === "number" && parentStageScoreTotal > 0 ? activeStageScore / parentStageScoreTotal : undefined;
2355
+ const stageShareGap = stageTotal > 0 && strongestStageSibling ? entry.count / stageTotal - strongestStageSibling.count / stageTotal : undefined;
2356
+ const parentStageShareGap = parentStageTotal > 0 && strongestStageSibling ? entry.count / parentStageTotal - strongestStageSibling.count / parentStageTotal : undefined;
2357
+ const stageScoreShareGap = typeof activeStageScore === "number" && stageScoreTotal > 0 && strongestStageScoreSibling ? activeStageScore / stageScoreTotal - strongestStageScoreSibling.totalScore / stageScoreTotal : undefined;
2358
+ const parentStageScoreShareGap = typeof activeStageScore === "number" && parentStageScoreTotal > 0 && strongestStageScoreSibling ? activeStageScore / parentStageScoreTotal - strongestStageScoreSibling.totalScore / parentStageScoreTotal : undefined;
2359
+ const reasons2 = [];
2360
+ if (entry.stage === "rerank" && stageShare > 0.5 && (typeof stageShareGap !== "number" || stageShareGap > 0)) {
2361
+ reasons2.push("rerank_preserved_lead");
2362
+ }
2363
+ if (entry.stage === "finalize" && stageShare >= 0.5) {
2364
+ reasons2.push("final_stage_concentration");
2365
+ }
2366
+ if (entry.stage === "finalize" && typeof parentStageShare === "number" && parentStageShare >= 0.6 && (typeof parentStageShareGap !== "number" || parentStageShareGap > 0)) {
2367
+ reasons2.push("final_stage_dominant_within_parent");
2368
+ }
2369
+ if (strongestStageSibling && (typeof stageShareGap === "number" && stageShareGap <= 0.1 || typeof parentStageShareGap === "number" && parentStageShareGap <= 0.1)) {
2370
+ reasons2.push("stage_runner_up_pressure");
2371
+ }
2372
+ if (typeof countDelta === "number") {
2373
+ if (countDelta > 0) {
2374
+ reasons2.push("stage_expanded");
2375
+ } else if (countDelta < 0) {
2376
+ reasons2.push("stage_narrowed");
2377
+ } else {
2378
+ reasons2.push("stage_held");
2379
+ }
2380
+ }
2381
+ return {
2382
+ count: entry.count,
2383
+ countDelta,
2384
+ parentStageScoreShare,
2385
+ parentStageShare,
2386
+ parentStageShareGap,
2387
+ previousCount: previousStageEntry?.count,
2388
+ previousStage: previousStageEntry?.stage,
2389
+ reasons: reasons2,
2390
+ retentionRate,
2391
+ stage: entry.stage,
2392
+ stageScoreShare,
2393
+ stageScoreShareGap,
2394
+ stageShare,
2395
+ stageShareGap,
2396
+ totalScore: activeStageScore,
2397
+ strongestSiblingCount: strongestStageSibling?.count,
2398
+ strongestSiblingLabel: strongestStageSibling ? diagnostics.find((candidate) => candidate.key === strongestStageSibling.key)?.label ?? strongestStageSibling.key : undefined
2399
+ };
2400
+ });
2321
2401
  const firstSeenStage = stageCounts[0]?.stage;
2322
2402
  const lastSeenStage = stageCounts.at(-1)?.stage;
2403
+ const peakStageEntry = stageCounts.reduce((highest, entry) => !highest || entry.count > highest.count ? entry : highest, undefined);
2404
+ const finalStageEntry = stageCounts.at(-1);
2405
+ const peakCount = peakStageEntry?.count ?? section.count;
2406
+ const finalCount = finalStageEntry?.count;
2407
+ const finalRetentionRate = typeof finalCount === "number" && peakCount > 0 ? finalCount / peakCount : undefined;
2408
+ const dropFromPeak = typeof finalCount === "number" ? peakCount - finalCount : undefined;
2409
+ const queryAttributionReasons = [];
2410
+ 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";
2411
+ if (queryAttributionMode === "primary") {
2412
+ queryAttributionReasons.push("base_query_only");
2413
+ }
2414
+ if (queryAttributionMode === "transformed") {
2415
+ queryAttributionReasons.push("transformed_query_only");
2416
+ queryAttributionReasons.push("transform_introduced");
2417
+ }
2418
+ if (queryAttributionMode === "variant") {
2419
+ queryAttributionReasons.push("variant_only");
2420
+ queryAttributionReasons.push("variant_supported");
2421
+ }
2422
+ if (queryAttributionMode === "mixed") {
2423
+ queryAttributionReasons.push("mixed_query_sources");
2424
+ if (section.variantHits > 0) {
2425
+ queryAttributionReasons.push("variant_supported");
2426
+ }
2427
+ if (section.transformedHits > 0 && section.primaryHits === 0) {
2428
+ queryAttributionReasons.push("transform_introduced");
2429
+ }
2430
+ }
2323
2431
  if (section.bestScore >= strongestBestHit) {
2324
2432
  reasons.push("best_hit");
2325
2433
  }
@@ -2353,13 +2461,26 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
2353
2461
  parentShareGap: typeof parentShare === "number" && strongestSibling && parentTotal > 0 ? parentShare - strongestSibling.totalScore / parentTotal : undefined,
2354
2462
  path: section.path,
2355
2463
  firstSeenStage,
2464
+ finalCount,
2465
+ finalRetentionRate,
2356
2466
  lastSeenStage,
2467
+ dropFromPeak,
2468
+ peakCount,
2469
+ peakStage: peakStageEntry?.stage,
2470
+ queryAttribution: {
2471
+ mode: queryAttributionMode,
2472
+ primaryHits: section.primaryHits,
2473
+ reasons: queryAttributionReasons,
2474
+ transformedHits: section.transformedHits,
2475
+ variantHits: section.variantHits
2476
+ },
2357
2477
  retrievalMode: trace?.mode,
2358
2478
  reasons,
2359
2479
  rerankApplied: trace?.steps.some((step) => step.stage === "rerank" && step.metadata?.applied === true),
2360
2480
  scoreShare,
2361
2481
  scoreThresholdApplied: trace?.steps.some((step) => step.stage === "score_filter"),
2362
2482
  stageCounts,
2483
+ stageWeights,
2363
2484
  siblingCount: siblings.length,
2364
2485
  siblingScoreGap: strongestSibling ? section.totalScore - strongestSibling.totalScore : undefined,
2365
2486
  sourceCount: section.sourceSet.size,
@@ -4549,5 +4670,5 @@ export {
4549
4670
  AIStreamService
4550
4671
  };
4551
4672
 
4552
- //# debugId=458F3E73F2A0F43C64756E2164756E21
4673
+ //# debugId=DA2522AA9A6EF6C664756E2164756E21
4553
4674
  //# sourceMappingURL=index.js.map