@absolutejs/absolute 0.19.0-beta.643 → 0.19.0-beta.644

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/index.js CHANGED
@@ -2965,6 +2965,18 @@ var buildComparisonOverviewPresentation = (input) => {
2965
2965
  value: input.resolveLabel(input.summary.bestByMultivectorVectorHitCases)
2966
2966
  });
2967
2967
  }
2968
+ if (input.summary.bestByLowestRuntimeCandidateBudgetExhaustedCases) {
2969
+ rows.push({
2970
+ label: "Lowest runtime budget exhaustion",
2971
+ value: input.resolveLabel(input.summary.bestByLowestRuntimeCandidateBudgetExhaustedCases)
2972
+ });
2973
+ }
2974
+ if (input.summary.bestByLowestRuntimeUnderfilledTopKCases) {
2975
+ rows.push({
2976
+ label: "Lowest runtime underfilled TopK",
2977
+ value: input.resolveLabel(input.summary.bestByLowestRuntimeUnderfilledTopKCases)
2978
+ });
2979
+ }
2968
2980
  return {
2969
2981
  rows,
2970
2982
  winnerLabel,
@@ -3017,6 +3029,9 @@ var buildRAGComparisonTraceSummaryRows = (entry) => {
3017
3029
  }, {
3018
3030
  label: "Multivector",
3019
3031
  value: `${formatTraceRatio(trace.multiVectorCases, trace.totalCases)} \xB7 collapse ${formatTraceRatio(trace.multiVectorCollapsedCases, trace.totalCases)} \xB7 lexical ${formatTraceRatio(trace.multiVectorLexicalHitCases, trace.totalCases)} \xB7 vector ${formatTraceRatio(trace.multiVectorVectorHitCases, trace.totalCases)}`
3032
+ }, {
3033
+ label: "Runtime",
3034
+ value: `budget ${formatTraceRatio(trace.runtimeCandidateBudgetExhaustedCases, trace.totalCases)} \xB7 underfilled ${formatTraceRatio(trace.runtimeUnderfilledTopKCases, trace.totalCases)}`
3020
3035
  }, {
3021
3036
  label: "TopK",
3022
3037
  value: `${trace.averageCandidateTopK.toFixed(1)} / ${trace.averageLexicalTopK.toFixed(1)}`
@@ -3121,6 +3136,12 @@ var buildRAGComparisonTraceDiffRows = (entry, leader) => {
3121
3136
  }, {
3122
3137
  label: "Round robin delta",
3123
3138
  value: formatTraceCountDelta(trace.roundRobinCases - leaderTrace.roundRobinCases)
3139
+ }, {
3140
+ label: "Runtime budget delta",
3141
+ value: formatTraceCountDelta(trace.runtimeCandidateBudgetExhaustedCases - leaderTrace.runtimeCandidateBudgetExhaustedCases)
3142
+ }, {
3143
+ label: "Runtime underfilled delta",
3144
+ value: formatTraceCountDelta(trace.runtimeUnderfilledTopKCases - leaderTrace.runtimeUnderfilledTopKCases)
3124
3145
  });
3125
3146
  if (stageDelta) {
3126
3147
  rows.push({ label: "Stage delta", value: stageDelta });
@@ -3572,6 +3593,77 @@ var buildRAGEvaluationSuiteSnapshotHistoryPresentation = (history) => ({
3572
3593
  snapshots: buildRAGEvaluationSuiteSnapshotPresentations(history),
3573
3594
  summary: history?.latestSnapshot ? `v${history.latestSnapshot.version}` : "No saved suite snapshots yet."
3574
3595
  });
3596
+ var isRuntimeGateReason = (reason) => /runtime|candidate-budget|underfilled/i.test(reason);
3597
+ var buildRAGRetrievalReleaseHistoryRunPresentation = (run) => {
3598
+ const runtimeGateReasons = (run.decisionSummary?.gate?.reasons ?? run.releaseVerdict?.gate?.reasons ?? []).filter(isRuntimeGateReason);
3599
+ const rows = [
3600
+ { label: "Finished", value: formatDateLabel(run.finishedAt) },
3601
+ {
3602
+ label: "Passing-rate winner",
3603
+ value: run.comparison.summary.bestByPassingRate ?? "n/a"
3604
+ },
3605
+ {
3606
+ label: "Average F1 winner",
3607
+ value: run.comparison.summary.bestByAverageF1 ?? "n/a"
3608
+ }
3609
+ ];
3610
+ if (run.comparison.summary.bestByLowestRuntimeCandidateBudgetExhaustedCases) {
3611
+ rows.push({
3612
+ label: "Lowest runtime budget exhaustion",
3613
+ value: run.comparison.summary.bestByLowestRuntimeCandidateBudgetExhaustedCases
3614
+ });
3615
+ }
3616
+ if (run.comparison.summary.bestByLowestRuntimeUnderfilledTopKCases) {
3617
+ rows.push({
3618
+ label: "Lowest runtime underfilled TopK",
3619
+ value: run.comparison.summary.bestByLowestRuntimeUnderfilledTopKCases
3620
+ });
3621
+ }
3622
+ rows.push({
3623
+ label: "Gate status",
3624
+ value: run.decisionSummary?.gate?.status ?? run.releaseVerdict?.gate?.status ?? "n/a"
3625
+ }, {
3626
+ label: "Runtime gate failures",
3627
+ value: runtimeGateReasons.length > 0 ? runtimeGateReasons.join("; ") : "none"
3628
+ });
3629
+ return {
3630
+ label: run.label,
3631
+ rows,
3632
+ runId: run.id,
3633
+ summary: runtimeGateReasons.length > 0 ? `${run.label} \xB7 runtime gate blocked` : `${run.label} \xB7 ${run.comparison.summary.bestByPassingRate ?? "n/a"} leads passing rate`
3634
+ };
3635
+ };
3636
+ var buildRAGRetrievalReleaseGroupHistoryPresentation = (input) => {
3637
+ const recentRuns = (input.runs ?? []).map(buildRAGRetrievalReleaseHistoryRunPresentation);
3638
+ const runtimeBlockedRuns = recentRuns.filter((entry) => entry.rows.some((row) => row.label === "Runtime gate failures" && row.value !== "none")).length;
3639
+ const rows = [
3640
+ {
3641
+ label: "Latest decision",
3642
+ value: input.timeline?.latestDecisionKind ?? "none"
3643
+ },
3644
+ {
3645
+ label: "Latest decision at",
3646
+ value: formatDateLabel(input.timeline?.latestDecisionAt)
3647
+ },
3648
+ {
3649
+ label: "Last promoted",
3650
+ value: formatDateLabel(input.timeline?.lastPromotedAt)
3651
+ },
3652
+ {
3653
+ label: "Last reverted",
3654
+ value: formatDateLabel(input.timeline?.lastRevertedAt)
3655
+ },
3656
+ {
3657
+ label: "Recent runtime-blocked runs",
3658
+ value: String(runtimeBlockedRuns)
3659
+ }
3660
+ ];
3661
+ return {
3662
+ recentRuns,
3663
+ rows,
3664
+ summary: input.timeline?.latestDecisionKind ? `${input.timeline.latestDecisionKind} \xB7 ${recentRuns.length} recent runs` : recentRuns.length > 0 ? `${recentRuns.length} recent runs` : "No release history yet."
3665
+ };
3666
+ };
3575
3667
  var buildRAGAnswerGroundingCaseSnapshotPresentations = (history) => {
3576
3668
  if (!history?.caseSnapshots.length) {
3577
3669
  return [];
@@ -4082,6 +4174,12 @@ var evaluateRetrievalComparisonGate = ({
4082
4174
  if (typeof policy.minMultiVectorVectorHitCasesDelta === "number" && (delta.multiVectorVectorHitCasesDelta ?? 0) < policy.minMultiVectorVectorHitCasesDelta) {
4083
4175
  reasons.push(`multivector vector-hit delta ${delta.multiVectorVectorHitCasesDelta ?? 0} is below ${policy.minMultiVectorVectorHitCasesDelta}`);
4084
4176
  }
4177
+ if (typeof policy.maxRuntimeCandidateBudgetExhaustedCasesDelta === "number" && (delta.runtimeCandidateBudgetExhaustedCasesDelta ?? 0) > policy.maxRuntimeCandidateBudgetExhaustedCasesDelta) {
4178
+ reasons.push(`runtime candidate-budget-exhausted delta ${delta.runtimeCandidateBudgetExhaustedCasesDelta ?? 0} exceeds ${policy.maxRuntimeCandidateBudgetExhaustedCasesDelta}`);
4179
+ }
4180
+ if (typeof policy.maxRuntimeUnderfilledTopKCasesDelta === "number" && (delta.runtimeUnderfilledTopKCasesDelta ?? 0) > policy.maxRuntimeUnderfilledTopKCasesDelta) {
4181
+ reasons.push(`runtime underfilled-topk delta ${delta.runtimeUnderfilledTopKCasesDelta ?? 0} exceeds ${policy.maxRuntimeUnderfilledTopKCasesDelta}`);
4182
+ }
4085
4183
  if (reasons.length === 0) {
4086
4184
  return {
4087
4185
  policy,
@@ -4612,6 +4710,20 @@ var buildTraceSummaryAggregate = ({
4612
4710
  direction: "flat",
4613
4711
  metric: "multiVectorCollapsedCases",
4614
4712
  previous: 0
4713
+ },
4714
+ {
4715
+ current: 0,
4716
+ delta: 0,
4717
+ direction: "flat",
4718
+ metric: "runtimeCandidateBudgetExhaustedCases",
4719
+ previous: 0
4720
+ },
4721
+ {
4722
+ current: 0,
4723
+ delta: 0,
4724
+ direction: "flat",
4725
+ metric: "runtimeUnderfilledTopKCases",
4726
+ previous: 0
4615
4727
  }
4616
4728
  ];
4617
4729
  return {
@@ -4734,6 +4846,20 @@ var buildTraceSummaryAggregate = ({
4734
4846
  direction: buildTraceSummaryDirection(latest.multiVectorCollapsedCases - previous.multiVectorCollapsedCases),
4735
4847
  metric: "multiVectorCollapsedCases",
4736
4848
  previous: previous.multiVectorCollapsedCases
4849
+ },
4850
+ {
4851
+ current: latest.runtimeCandidateBudgetExhaustedCases,
4852
+ delta: latest.runtimeCandidateBudgetExhaustedCases - previous.runtimeCandidateBudgetExhaustedCases,
4853
+ direction: buildTraceSummaryDirection(latest.runtimeCandidateBudgetExhaustedCases - previous.runtimeCandidateBudgetExhaustedCases),
4854
+ metric: "runtimeCandidateBudgetExhaustedCases",
4855
+ previous: previous.runtimeCandidateBudgetExhaustedCases
4856
+ },
4857
+ {
4858
+ current: latest.runtimeUnderfilledTopKCases,
4859
+ delta: latest.runtimeUnderfilledTopKCases - previous.runtimeUnderfilledTopKCases,
4860
+ direction: buildTraceSummaryDirection(latest.runtimeUnderfilledTopKCases - previous.runtimeUnderfilledTopKCases),
4861
+ metric: "runtimeUnderfilledTopKCases",
4862
+ previous: previous.runtimeUnderfilledTopKCases
4737
4863
  }
4738
4864
  ];
4739
4865
  const absoluteSorted = [...aggregate].sort((left, right) => Math.abs(right.delta) - Math.abs(left.delta) || left.metric.localeCompare(right.metric));
@@ -4788,12 +4914,15 @@ var summarizeRetrievalTraces = (traces) => {
4788
4914
  let multiVectorVectorHitCases = 0;
4789
4915
  let multiVectorLexicalHitCases = 0;
4790
4916
  let multiVectorCollapsedCases = 0;
4917
+ let runtimeCandidateBudgetExhaustedCases = 0;
4918
+ let runtimeUnderfilledTopKCases = 0;
4791
4919
  let finalCountSum = 0;
4792
4920
  let vectorCountSum = 0;
4793
4921
  let lexicalCountSum = 0;
4794
4922
  let candidateTopKSum = 0;
4795
4923
  let lexicalTopKSum = 0;
4796
4924
  for (const trace of traces) {
4925
+ const vectorSearchMetadata = trace.steps.find((step) => step.stage === "vector_search")?.metadata;
4797
4926
  modeSet.add(trace.mode);
4798
4927
  sourceBalanceStrategySet.add(trace.sourceBalanceStrategy ?? "cap");
4799
4928
  if (trace.runVector) {
@@ -4826,6 +4955,18 @@ var summarizeRetrievalTraces = (traces) => {
4826
4955
  if ((trace.multiVector?.collapsedParents ?? 0) > 0) {
4827
4956
  multiVectorCollapsedCases += 1;
4828
4957
  }
4958
+ if (vectorSearchMetadata?.sqliteQueryCandidateBudgetExhausted) {
4959
+ runtimeCandidateBudgetExhaustedCases += 1;
4960
+ }
4961
+ if (vectorSearchMetadata?.postgresQueryCandidateBudgetExhausted) {
4962
+ runtimeCandidateBudgetExhaustedCases += 1;
4963
+ }
4964
+ if (vectorSearchMetadata?.sqliteQueryUnderfilledTopK) {
4965
+ runtimeUnderfilledTopKCases += 1;
4966
+ }
4967
+ if (vectorSearchMetadata?.postgresQueryUnderfilledTopK) {
4968
+ runtimeUnderfilledTopKCases += 1;
4969
+ }
4829
4970
  finalCountSum += trace.resultCounts.final;
4830
4971
  vectorCountSum += trace.resultCounts.vector;
4831
4972
  lexicalCountSum += trace.resultCounts.lexical;
@@ -4851,6 +4992,8 @@ var summarizeRetrievalTraces = (traces) => {
4851
4992
  multiVectorVectorHitCases,
4852
4993
  multiVectorLexicalHitCases,
4853
4994
  multiVectorCollapsedCases,
4995
+ runtimeCandidateBudgetExhaustedCases,
4996
+ runtimeUnderfilledTopKCases,
4854
4997
  vectorCases
4855
4998
  };
4856
4999
  };
@@ -8436,7 +8579,9 @@ var buildRAGRetrievalComparisonDecisionSummary = ({
8436
8579
  passingRateDelta: candidateEntry.response.passingRate - baselineEntry.response.passingRate,
8437
8580
  multiVectorCollapsedCasesDelta: (candidateEntry.traceSummary?.multiVectorCollapsedCases ?? 0) - (baselineEntry.traceSummary?.multiVectorCollapsedCases ?? 0),
8438
8581
  multiVectorLexicalHitCasesDelta: (candidateEntry.traceSummary?.multiVectorLexicalHitCases ?? 0) - (baselineEntry.traceSummary?.multiVectorLexicalHitCases ?? 0),
8439
- multiVectorVectorHitCasesDelta: (candidateEntry.traceSummary?.multiVectorVectorHitCases ?? 0) - (baselineEntry.traceSummary?.multiVectorVectorHitCases ?? 0)
8582
+ multiVectorVectorHitCasesDelta: (candidateEntry.traceSummary?.multiVectorVectorHitCases ?? 0) - (baselineEntry.traceSummary?.multiVectorVectorHitCases ?? 0),
8583
+ runtimeCandidateBudgetExhaustedCasesDelta: (candidateEntry.traceSummary?.runtimeCandidateBudgetExhaustedCases ?? 0) - (baselineEntry.traceSummary?.runtimeCandidateBudgetExhaustedCases ?? 0),
8584
+ runtimeUnderfilledTopKCasesDelta: (candidateEntry.traceSummary?.runtimeUnderfilledTopKCases ?? 0) - (baselineEntry.traceSummary?.runtimeUnderfilledTopKCases ?? 0)
8440
8585
  } : undefined;
8441
8586
  return {
8442
8587
  baseline: baselineEntry ? {
@@ -8446,6 +8591,8 @@ var buildRAGRetrievalComparisonDecisionSummary = ({
8446
8591
  multiVectorCollapsedCases: baselineEntry.traceSummary?.multiVectorCollapsedCases,
8447
8592
  multiVectorLexicalHitCases: baselineEntry.traceSummary?.multiVectorLexicalHitCases,
8448
8593
  multiVectorVectorHitCases: baselineEntry.traceSummary?.multiVectorVectorHitCases,
8594
+ runtimeCandidateBudgetExhaustedCases: baselineEntry.traceSummary?.runtimeCandidateBudgetExhaustedCases,
8595
+ runtimeUnderfilledTopKCases: baselineEntry.traceSummary?.runtimeUnderfilledTopKCases,
8449
8596
  passingRate: baselineEntry.response.passingRate,
8450
8597
  retrievalId: baselineEntry.retrievalId
8451
8598
  } : undefined,
@@ -8457,6 +8604,8 @@ var buildRAGRetrievalComparisonDecisionSummary = ({
8457
8604
  multiVectorCollapsedCases: candidateEntry.traceSummary?.multiVectorCollapsedCases,
8458
8605
  multiVectorLexicalHitCases: candidateEntry.traceSummary?.multiVectorLexicalHitCases,
8459
8606
  multiVectorVectorHitCases: candidateEntry.traceSummary?.multiVectorVectorHitCases,
8607
+ runtimeCandidateBudgetExhaustedCases: candidateEntry.traceSummary?.runtimeCandidateBudgetExhaustedCases,
8608
+ runtimeUnderfilledTopKCases: candidateEntry.traceSummary?.runtimeUnderfilledTopKCases,
8460
8609
  passingRate: candidateEntry.response.passingRate,
8461
8610
  retrievalId: candidateEntry.retrievalId
8462
8611
  } : undefined,
@@ -8468,7 +8617,9 @@ var buildRAGRetrievalComparisonDecisionSummary = ({
8468
8617
  winnerByPassingRate: comparison.summary.bestByPassingRate,
8469
8618
  winnerByMultivectorCollapsedCases: comparison.summary.bestByMultivectorCollapsedCases,
8470
8619
  winnerByMultivectorLexicalHitCases: comparison.summary.bestByMultivectorLexicalHitCases,
8471
- winnerByMultivectorVectorHitCases: comparison.summary.bestByMultivectorVectorHitCases
8620
+ winnerByMultivectorVectorHitCases: comparison.summary.bestByMultivectorVectorHitCases,
8621
+ winnerByLowestRuntimeCandidateBudgetExhaustedCases: comparison.summary.bestByLowestRuntimeCandidateBudgetExhaustedCases,
8622
+ winnerByLowestRuntimeUnderfilledTopKCases: comparison.summary.bestByLowestRuntimeUnderfilledTopKCases
8472
8623
  };
8473
8624
  };
8474
8625
  var loadRAGSearchTracePruneHistory = async ({
@@ -9156,6 +9307,24 @@ var selectComparisonEntryByTraceMetric = (entries, idKey, metric) => {
9156
9307
  }
9157
9308
  return typeof winner[idKey] === "string" ? winner[idKey] : undefined;
9158
9309
  };
9310
+ var selectComparisonEntryByLowestTraceMetric = (entries, idKey, metric) => {
9311
+ const ranked = [...entries].sort((left, right) => {
9312
+ const leftMetric = left.traceSummary?.[metric] ?? 0;
9313
+ const rightMetric = right.traceSummary?.[metric] ?? 0;
9314
+ if (leftMetric !== rightMetric) {
9315
+ return leftMetric - rightMetric;
9316
+ }
9317
+ if (right.response.passingRate !== left.response.passingRate) {
9318
+ return right.response.passingRate - left.response.passingRate;
9319
+ }
9320
+ if (right.response.summary.averageF1 !== left.response.summary.averageF1) {
9321
+ return right.response.summary.averageF1 - left.response.summary.averageF1;
9322
+ }
9323
+ return left.response.summary.averageLatencyMs - right.response.summary.averageLatencyMs;
9324
+ });
9325
+ const winner = ranked[0];
9326
+ return typeof winner?.[idKey] === "string" ? winner[idKey] : undefined;
9327
+ };
9159
9328
  var resolveRetrievalMode = (candidate) => {
9160
9329
  if (!candidate.retrieval) {
9161
9330
  return "vector";
@@ -9249,7 +9418,9 @@ var compareRAGRetrievalTraceSummaries = (current, previous) => ({
9249
9418
  multiVectorCasesDelta: current.multiVectorCases - previous.multiVectorCases,
9250
9419
  multiVectorVectorHitCasesDelta: current.multiVectorVectorHitCases - previous.multiVectorVectorHitCases,
9251
9420
  multiVectorLexicalHitCasesDelta: current.multiVectorLexicalHitCases - previous.multiVectorLexicalHitCases,
9252
- multiVectorCollapsedCasesDelta: current.multiVectorCollapsedCases - previous.multiVectorCollapsedCases
9421
+ multiVectorCollapsedCasesDelta: current.multiVectorCollapsedCases - previous.multiVectorCollapsedCases,
9422
+ runtimeCandidateBudgetExhaustedCasesDelta: current.runtimeCandidateBudgetExhaustedCases - previous.runtimeCandidateBudgetExhaustedCases,
9423
+ runtimeUnderfilledTopKCasesDelta: current.runtimeUnderfilledTopKCases - previous.runtimeUnderfilledTopKCases
9253
9424
  });
9254
9425
  var buildSearchTraceResultSnapshots = (results) => results.map((result) => ({
9255
9426
  chunkId: result.chunkId,
@@ -9611,6 +9782,63 @@ var generateRAGEvaluationSuiteFromDocuments = ({
9611
9782
  metadata
9612
9783
  });
9613
9784
  };
9785
+ var DEFAULT_NATIVE_PLANNER_BENCHMARK_SUITE_ID = "rag-native-planner-larger-corpus";
9786
+ var DEFAULT_NATIVE_PLANNER_BENCHMARK_LABEL = "Adaptive Native Planner Benchmark";
9787
+ var DEFAULT_NATIVE_PLANNER_BENCHMARK_QUERY = "Which launch checklist phrase is exact wording?";
9788
+ var DEFAULT_NATIVE_PLANNER_BENCHMARK_FILTER = {
9789
+ lane: "focus"
9790
+ };
9791
+ var createRAGAdaptiveNativePlannerBenchmarkSuite = (input) => createRAGEvaluationSuite({
9792
+ description: input?.description ?? "Stress-tests larger-corpus native planner selection, candidate-budget pressure, and transformed-query recovery on filtered retrieval.",
9793
+ id: input?.id ?? DEFAULT_NATIVE_PLANNER_BENCHMARK_SUITE_ID,
9794
+ input: {
9795
+ cases: [
9796
+ {
9797
+ expectedDocumentIds: ["focus-target"],
9798
+ filter: { ...DEFAULT_NATIVE_PLANNER_BENCHMARK_FILTER },
9799
+ hardNegativeDocumentIds: [
9800
+ "focus-distractor-0",
9801
+ "focus-distractor-1",
9802
+ "focus-distractor-2"
9803
+ ],
9804
+ id: "planner-pressure-exact-phrase",
9805
+ label: "Exact phrase survives larger-corpus native pressure",
9806
+ query: DEFAULT_NATIVE_PLANNER_BENCHMARK_QUERY,
9807
+ topK: input?.topK ?? 1
9808
+ }
9809
+ ],
9810
+ filter: { ...DEFAULT_NATIVE_PLANNER_BENCHMARK_FILTER },
9811
+ retrieval: "vector",
9812
+ topK: input?.topK ?? 1
9813
+ },
9814
+ label: input?.label ?? DEFAULT_NATIVE_PLANNER_BENCHMARK_LABEL,
9815
+ metadata: {
9816
+ benchmarkKind: "adaptive_native_planner",
9817
+ benchmarkScope: "larger_corpus",
9818
+ expectedSignals: [
9819
+ "selected native planner profile",
9820
+ "candidate-budget exhaustion",
9821
+ "underfilled topk"
9822
+ ],
9823
+ recommendedGroupKey: "runtime-native-planner",
9824
+ recommendedTags: ["runtime", "native", "planner"],
9825
+ ...input?.metadata
9826
+ }
9827
+ });
9828
+ var createRAGAdaptiveNativePlannerBenchmarkSnapshot = (input) => {
9829
+ const suite = input?.suite ?? createRAGAdaptiveNativePlannerBenchmarkSuite();
9830
+ return createRAGEvaluationSuiteSnapshot({
9831
+ createdAt: input?.createdAt,
9832
+ id: input?.id,
9833
+ metadata: {
9834
+ artifactKind: "adaptive_native_planner_benchmark",
9835
+ persistForReleaseHistory: true,
9836
+ ...input?.metadata
9837
+ },
9838
+ suite,
9839
+ version: input?.version
9840
+ });
9841
+ };
9614
9842
  var createRAGEvaluationSuiteSnapshot = ({
9615
9843
  suite,
9616
9844
  id,
@@ -9818,7 +10046,9 @@ var summarizeRAGRetrievalComparison = (entries) => ({
9818
10046
  ...summarizeEvaluationResponseComparison(entries, "retrievalId"),
9819
10047
  bestByMultivectorCollapsedCases: selectComparisonEntryByTraceMetric(entries, "retrievalId", "multiVectorCollapsedCases"),
9820
10048
  bestByMultivectorLexicalHitCases: selectComparisonEntryByTraceMetric(entries, "retrievalId", "multiVectorLexicalHitCases"),
9821
- bestByMultivectorVectorHitCases: selectComparisonEntryByTraceMetric(entries, "retrievalId", "multiVectorVectorHitCases")
10049
+ bestByMultivectorVectorHitCases: selectComparisonEntryByTraceMetric(entries, "retrievalId", "multiVectorVectorHitCases"),
10050
+ bestByLowestRuntimeCandidateBudgetExhaustedCases: selectComparisonEntryByLowestTraceMetric(entries, "retrievalId", "runtimeCandidateBudgetExhaustedCases"),
10051
+ bestByLowestRuntimeUnderfilledTopKCases: selectComparisonEntryByLowestTraceMetric(entries, "retrievalId", "runtimeUnderfilledTopKCases")
9822
10052
  });
9823
10053
  // src/ai/providers/openai.ts
9824
10054
  var DEFAULT_BASE_URL = "https://api.openai.com";
@@ -16903,6 +17133,9 @@ var prepareRAGDirectoryDocuments = async (input) => prepareRAGDocuments(await lo
16903
17133
 
16904
17134
  // src/ai/rag/collection.ts
16905
17135
  var DEFAULT_TOP_K2 = 6;
17136
+ var AUTO_BALANCED_NATIVE_ROW_ESTIMATE = 5000;
17137
+ var AUTO_RECALL_NATIVE_ROW_ESTIMATE = 20000;
17138
+ var AUTO_RECALL_FILTER_CLAUSE_COUNT = 3;
16906
17139
  var MULTIVECTOR_VARIANT_CHUNK_DELIMITER = "__mv__";
16907
17140
  var MULTIVECTOR_PARENT_CHUNK_ID = "absoluteMultivectorParentChunkId";
16908
17141
  var MULTIVECTOR_VARIANT_ID = "absoluteMultivectorVariantId";
@@ -16910,6 +17143,40 @@ var MULTIVECTOR_VARIANT_LABEL = "absoluteMultivectorVariantLabel";
16910
17143
  var MULTIVECTOR_VARIANT_TEXT = "absoluteMultivectorVariantText";
16911
17144
  var MULTIVECTOR_VARIANT_METADATA = "absoluteMultivectorVariantMetadata";
16912
17145
  var MULTIVECTOR_PRIMARY = "absoluteMultivectorPrimary";
17146
+ var isObjectRecord2 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
17147
+ var countSearchFilterClauses = (filter) => {
17148
+ if (!filter) {
17149
+ return 0;
17150
+ }
17151
+ let count = 0;
17152
+ for (const [key, value] of Object.entries(filter)) {
17153
+ if (key === "$and" || key === "$or") {
17154
+ if (Array.isArray(value)) {
17155
+ count += value.reduce((total, entry) => total + (isObjectRecord2(entry) ? countSearchFilterClauses(entry) : 0), 0);
17156
+ }
17157
+ continue;
17158
+ }
17159
+ if (key === "$not") {
17160
+ count += isObjectRecord2(value) ? countSearchFilterClauses(value) : 0;
17161
+ continue;
17162
+ }
17163
+ count += 1;
17164
+ }
17165
+ return count;
17166
+ };
17167
+ var getNativeCorpusRowEstimate = (store) => {
17168
+ const status = store.getStatus?.();
17169
+ if (!status?.native || !("mode" in status.native)) {
17170
+ return;
17171
+ }
17172
+ if (status.backend === "postgres" && status.native.mode === "pgvector" && typeof status.native.estimatedRowCount === "number" && Number.isFinite(status.native.estimatedRowCount)) {
17173
+ return Math.max(0, Math.floor(status.native.estimatedRowCount));
17174
+ }
17175
+ if (status.backend === "sqlite" && status.native.mode === "vec0" && typeof status.native.rowCount === "number" && Number.isFinite(status.native.rowCount)) {
17176
+ return Math.max(0, Math.floor(status.native.rowCount));
17177
+ }
17178
+ return;
17179
+ };
16913
17180
  var resolveNativeQueryProfile = (input) => {
16914
17181
  if (!input.profile) {
16915
17182
  return;
@@ -16941,6 +17208,45 @@ var resolveNativeQueryProfile = (input) => {
16941
17208
  queryMultiplier: 4
16942
17209
  };
16943
17210
  };
17211
+ var resolveNativeQueryProfileSelection = (input) => {
17212
+ if (input.explicitProfile) {
17213
+ return {
17214
+ filterClauseCount: countSearchFilterClauses(input.filter),
17215
+ profile: input.explicitProfile,
17216
+ reason: undefined,
17217
+ resolved: resolveNativeQueryProfile({
17218
+ candidateTopK: input.candidateTopK,
17219
+ profile: input.explicitProfile,
17220
+ topK: input.topK
17221
+ }),
17222
+ rowEstimate: getNativeCorpusRowEstimate(input.store),
17223
+ selectionMode: "explicit"
17224
+ };
17225
+ }
17226
+ const rowEstimate = getNativeCorpusRowEstimate(input.store);
17227
+ const filterClauseCount = countSearchFilterClauses(input.filter);
17228
+ let profile;
17229
+ let reason;
17230
+ if (typeof rowEstimate === "number" && rowEstimate >= AUTO_RECALL_NATIVE_ROW_ESTIMATE && (filterClauseCount >= AUTO_RECALL_FILTER_CLAUSE_COUNT || input.variantQueryCount > 0 || input.retrievalMode === "hybrid")) {
17231
+ profile = "recall";
17232
+ reason = "larger corpus with complex or expanded retrieval benefits from deeper candidate recovery";
17233
+ } else if (typeof rowEstimate === "number" && rowEstimate >= AUTO_BALANCED_NATIVE_ROW_ESTIMATE) {
17234
+ profile = "balanced";
17235
+ reason = "larger native corpus benefits from balanced candidate expansion and backfill";
17236
+ }
17237
+ return {
17238
+ filterClauseCount,
17239
+ profile,
17240
+ reason,
17241
+ resolved: resolveNativeQueryProfile({
17242
+ candidateTopK: input.candidateTopK,
17243
+ profile,
17244
+ topK: input.topK
17245
+ }),
17246
+ rowEstimate,
17247
+ selectionMode: profile ? "auto" : "default"
17248
+ };
17249
+ };
16944
17250
  var VARIANT_RESULT_WEIGHT = 0.92;
16945
17251
  var normalizeTraceCueText = (value) => value.toLowerCase().replace(/[^a-z0-9]+/g, " ").trim().replace(/\s+/g, " ");
16946
17252
  var queryIncludesTraceCue = (query, value) => {
@@ -17598,12 +17904,30 @@ var createRAGCollection = (options) => {
17598
17904
  stage: "routing"
17599
17905
  });
17600
17906
  }
17601
- const resultGroups = await Promise.all(searchQueries.map(async (query, queryIndex) => {
17602
- const nativeQueryProfile = resolveNativeQueryProfile({
17603
- candidateTopK,
17604
- profile: input.nativeQueryProfile,
17605
- topK
17907
+ const nativeQueryProfileSelection = resolveNativeQueryProfileSelection({
17908
+ candidateTopK,
17909
+ explicitProfile: input.nativeQueryProfile,
17910
+ filter: input.filter,
17911
+ retrievalMode: retrieval.mode,
17912
+ store: options.store,
17913
+ topK,
17914
+ variantQueryCount: Math.max(0, searchQueries.length - 1)
17915
+ });
17916
+ const nativeQueryProfile = nativeQueryProfileSelection.resolved;
17917
+ if (runVector && nativeQueryProfileSelection.selectionMode === "auto" && nativeQueryProfileSelection.profile) {
17918
+ steps.push({
17919
+ label: "Selected native planner profile",
17920
+ metadata: {
17921
+ autoSelected: true,
17922
+ filterClauseCount: nativeQueryProfileSelection.filterClauseCount,
17923
+ reason: nativeQueryProfileSelection.reason ?? null,
17924
+ rowEstimate: nativeQueryProfileSelection.rowEstimate ?? null,
17925
+ selectedProfile: nativeQueryProfileSelection.profile
17926
+ },
17927
+ stage: "routing"
17606
17928
  });
17929
+ }
17930
+ const resultGroups = await Promise.all(searchQueries.map(async (query, queryIndex) => {
17607
17931
  const [vectorResults2, lexicalResults2] = await Promise.all([
17608
17932
  runVector ? embed({
17609
17933
  model,
@@ -18124,7 +18448,7 @@ var renderRetrievalGovernancePanel = (retrievalComparisons) => {
18124
18448
  const latest = retrievalComparisons.latest;
18125
18449
  const alerts = (retrievalComparisons.alerts ?? []).slice(0, 3);
18126
18450
  const releaseGroups = (retrievalComparisons.releaseGroups ?? []).slice(0, 2);
18127
- const formatClassification = (classification) => classification === "multivector" ? "multivector regression" : classification === "general" ? "general regression" : undefined;
18451
+ const formatClassification = (classification) => classification === "multivector" ? "multivector regression" : classification === "runtime" ? "runtime regression" : classification === "general" ? "general regression" : undefined;
18128
18452
  return `<section class="rag-status-governance"><h3>Retrieval governance</h3>` + (latest ? `<dl class="rag-status">` + `<div><dt>Latest comparison</dt><dd>${escapeHtml2(latest.label)}</dd></div>` + (latest.bestByPassingRate ? `<div><dt>Best passing rate</dt><dd>${escapeHtml2(latest.bestByPassingRate)}</dd></div>` : "") + (latest.bestByAverageF1 ? `<div><dt>Best average F1</dt><dd>${escapeHtml2(latest.bestByAverageF1)}</dd></div>` : "") + (latest.bestByMultivectorCollapsedCases ? `<div><dt>Best multivector collapse</dt><dd>${escapeHtml2(latest.bestByMultivectorCollapsedCases)}</dd></div>` : "") + (latest.bestByMultivectorLexicalHitCases ? `<div><dt>Best multivector lexical hits</dt><dd>${escapeHtml2(latest.bestByMultivectorLexicalHitCases)}</dd></div>` : "") + (latest.bestByMultivectorVectorHitCases ? `<div><dt>Best multivector vector hits</dt><dd>${escapeHtml2(latest.bestByMultivectorVectorHitCases)}</dd></div>` : "") + (latest.decisionSummary?.gate?.status ? `<div><dt>Gate</dt><dd>${escapeHtml2(latest.decisionSummary.gate.status)}</dd></div>` : "") + (latest.releaseVerdict?.status ? `<div><dt>Verdict</dt><dd>${escapeHtml2(latest.releaseVerdict.status)}</dd></div>` : "") + `</dl>` : "") + `<h4>Active alerts</h4>` + (alerts.length > 0 ? `<ul class="rag-status-capabilities">${alerts.map((alert) => `<li><strong>${escapeHtml2(alert.kind)}</strong>${formatClassification(alert.classification) ? ` <span>${escapeHtml2(formatClassification(alert.classification) ?? "")}</span>` : ""} ${escapeHtml2(alert.message)}</li>`).join("")}</ul>` : `<p class="rag-empty">No active retrieval comparison alerts.</p>`) + (releaseGroups.length > 0 ? `<h4>Release groups</h4><ul class="rag-status-capabilities">${releaseGroups.map((group) => {
18129
18453
  const reasons = group.recommendedActionReasons?.slice(0, 2).join("; ") ?? "No recommended action.";
18130
18454
  return `<li><strong>${escapeHtml2(group.groupKey)}</strong>${formatClassification(group.classification) ? ` <span>${escapeHtml2(formatClassification(group.classification) ?? "")}</span>` : ""} ${escapeHtml2(group.recommendedAction ?? "monitor")} \xB7 ${escapeHtml2(reasons)}</li>`;
@@ -18451,25 +18775,25 @@ var defaultParseProvider2 = (content) => {
18451
18775
  };
18452
18776
  var normalizeScore = (value) => Number.isFinite(value) ? value : 0;
18453
18777
  var isHTMXRequest = (request) => request.headers.get("HX-Request") === "true";
18454
- var isObjectRecord2 = (value) => Boolean(value) && typeof value === "object";
18778
+ var isObjectRecord3 = (value) => Boolean(value) && typeof value === "object";
18455
18779
  var getStringProperty = (value, key) => {
18456
- if (!isObjectRecord2(value)) {
18780
+ if (!isObjectRecord3(value)) {
18457
18781
  return;
18458
18782
  }
18459
18783
  return typeof value[key] === "string" ? value[key] : undefined;
18460
18784
  };
18461
18785
  var getObjectProperty = (value, key) => {
18462
- if (!isObjectRecord2(value)) {
18786
+ if (!isObjectRecord3(value)) {
18463
18787
  return;
18464
18788
  }
18465
- return isObjectRecord2(value[key]) ? value[key] : undefined;
18789
+ return isObjectRecord3(value[key]) ? value[key] : undefined;
18466
18790
  };
18467
18791
  var getNumberProperty = (value, key) => {
18468
- const candidate = isObjectRecord2(value) ? value[key] : undefined;
18792
+ const candidate = isObjectRecord3(value) ? value[key] : undefined;
18469
18793
  return typeof candidate === "number" ? candidate : undefined;
18470
18794
  };
18471
18795
  var getIntegerLikeProperty = (value, key) => {
18472
- const candidate = isObjectRecord2(value) ? value[key] : undefined;
18796
+ const candidate = isObjectRecord3(value) ? value[key] : undefined;
18473
18797
  if (typeof candidate === "number" && Number.isFinite(candidate)) {
18474
18798
  return candidate;
18475
18799
  }
@@ -18479,7 +18803,7 @@ var getIntegerLikeProperty = (value, key) => {
18479
18803
  const parsed = Number(candidate);
18480
18804
  return Number.isFinite(parsed) ? parsed : undefined;
18481
18805
  };
18482
- var isMetadataMap = (value) => isObjectRecord2(value);
18806
+ var isMetadataMap = (value) => isObjectRecord3(value);
18483
18807
  var markMaintenancePanelOutOfBand = (html) => html.replace('<div id="rag-status-maintenance-panel"', '<div id="rag-status-maintenance-panel" hx-swap-oob="outerHTML"');
18484
18808
  var normalizeStringArray2 = (value) => {
18485
18809
  if (!Array.isArray(value)) {
@@ -18492,7 +18816,7 @@ var parseRAGSearchTracePruneInput = (value) => {
18492
18816
  if (value === undefined) {
18493
18817
  return;
18494
18818
  }
18495
- if (!isObjectRecord2(value)) {
18819
+ if (!isObjectRecord3(value)) {
18496
18820
  return null;
18497
18821
  }
18498
18822
  const pruneInput = {};
@@ -18533,7 +18857,7 @@ var parseRAGSearchTracePruneInput = (value) => {
18533
18857
  }
18534
18858
  return pruneInput;
18535
18859
  };
18536
- var getOwnProperty = (value, key) => isObjectRecord2(value) ? Object.prototype.hasOwnProperty.call(value, key) : false;
18860
+ var getOwnProperty = (value, key) => isObjectRecord3(value) ? Object.prototype.hasOwnProperty.call(value, key) : false;
18537
18861
  var parseRetrievalMode = (value) => {
18538
18862
  if (value === "vector" || value === "lexical" || value === "hybrid") {
18539
18863
  return value;
@@ -18641,31 +18965,43 @@ var parseRAGRetrieval = (value) => {
18641
18965
  return retrieval;
18642
18966
  };
18643
18967
  var getNumericStatus = (status) => typeof status === "number" ? status : HTTP_STATUS_OK;
18644
- var classifyGovernanceReasons = (reasons) => (reasons ?? []).some((reason) => reason.toLowerCase().includes("multivector")) ? "multivector" : "general";
18645
- var buildRegressionRemediationLabel = (classification) => classification === "multivector" ? "Inspect multivector coverage deltas, variant-hit traces, and collapsed-parent recovery before promotion." : "Inspect the latest retrieval comparison deltas and resolve the gate failure before promotion.";
18968
+ var classifyGovernanceReasons = (reasons) => {
18969
+ const normalized = (reasons ?? []).map((reason) => reason.toLowerCase());
18970
+ if (normalized.some((reason) => reason.includes("multivector"))) {
18971
+ return "multivector";
18972
+ }
18973
+ if (normalized.some((reason) => reason.includes("runtime ") || reason.includes("planner") || reason.includes("candidate-budget-exhausted") || reason.includes("underfilled-topk"))) {
18974
+ return "runtime";
18975
+ }
18976
+ return "general";
18977
+ };
18978
+ var buildRegressionRemediationLabel = (classification) => classification === "multivector" ? "Inspect multivector coverage deltas, variant-hit traces, and collapsed-parent recovery before promotion." : classification === "runtime" ? "Inspect planner-profile shifts, candidate-budget exhaustion, and underfilled native retrieval before promotion." : "Inspect the latest retrieval comparison deltas and resolve the gate failure before promotion.";
18646
18979
  var summarizeIncidentClassifications = (incidents) => {
18647
18980
  const allIncidents = incidents ?? [];
18648
18981
  const countBy = (status, classification) => allIncidents.filter((entry) => entry.status === status && (entry.classification ?? "general") === classification).length;
18649
18982
  return {
18650
18983
  openGeneralCount: countBy("open", "general"),
18651
18984
  openMultiVectorCount: countBy("open", "multivector"),
18985
+ openRuntimeCount: countBy("open", "runtime"),
18652
18986
  resolvedGeneralCount: countBy("resolved", "general"),
18653
18987
  resolvedMultiVectorCount: countBy("resolved", "multivector"),
18988
+ resolvedRuntimeCount: countBy("resolved", "runtime"),
18654
18989
  totalGeneralCount: allIncidents.filter((entry) => (entry.classification ?? "general") === "general").length,
18655
- totalMultiVectorCount: allIncidents.filter((entry) => (entry.classification ?? "general") === "multivector").length
18990
+ totalMultiVectorCount: allIncidents.filter((entry) => (entry.classification ?? "general") === "multivector").length,
18991
+ totalRuntimeCount: allIncidents.filter((entry) => (entry.classification ?? "general") === "runtime").length
18656
18992
  };
18657
18993
  };
18658
18994
  var getBooleanProperty = (value, key) => {
18659
- if (!isObjectRecord2(value)) {
18995
+ if (!isObjectRecord3(value)) {
18660
18996
  return;
18661
18997
  }
18662
18998
  return typeof value[key] === "boolean" ? value[key] : undefined;
18663
18999
  };
18664
- var isRAGDocumentChunk = (value) => isObjectRecord2(value) && typeof value.chunkId === "string" && typeof value.text === "string";
18665
- var isRAGDocument = (value) => isObjectRecord2(value) && typeof value.text === "string";
18666
- var isRAGDocumentUrl = (value) => isObjectRecord2(value) && typeof value.url === "string" && value.url.trim().length > 0;
19000
+ var isRAGDocumentChunk = (value) => isObjectRecord3(value) && typeof value.chunkId === "string" && typeof value.text === "string";
19001
+ var isRAGDocument = (value) => isObjectRecord3(value) && typeof value.text === "string";
19002
+ var isRAGDocumentUrl = (value) => isObjectRecord3(value) && typeof value.url === "string" && value.url.trim().length > 0;
18667
19003
  var isRAGDocumentArray = (value) => Array.isArray(value) && value.every((entry) => isRAGDocument(entry));
18668
- var isRAGDocumentUpload = (value) => isObjectRecord2(value) && typeof value.name === "string" && typeof value.content === "string";
19004
+ var isRAGDocumentUpload = (value) => isObjectRecord3(value) && typeof value.name === "string" && typeof value.content === "string";
18669
19005
  var isRAGDocumentUploadArray = (value) => Array.isArray(value) && value.every((entry) => isRAGDocumentUpload(entry));
18670
19006
  var isRAGDocumentUrlArray = (value) => Array.isArray(value) && value.every((entry) => isRAGDocumentUrl(entry));
18671
19007
  var isRAGDocumentChunkArray = (value) => Array.isArray(value) && value.every((entry) => isRAGDocumentChunk(entry));
@@ -19336,18 +19672,18 @@ var ragChat = (config) => {
19336
19672
  store: ragStore
19337
19673
  }) : null);
19338
19674
  const toRAGEvaluationInput = (body) => {
19339
- if (!isObjectRecord2(body) || !Array.isArray(body.cases)) {
19675
+ if (!isObjectRecord3(body) || !Array.isArray(body.cases)) {
19340
19676
  return null;
19341
19677
  }
19342
19678
  const parsedCases = body.cases.map((candidate, caseIndex) => {
19343
- if (!isObjectRecord2(candidate)) {
19679
+ if (!isObjectRecord3(candidate)) {
19344
19680
  return null;
19345
19681
  }
19346
19682
  const query = getStringProperty(candidate, "query")?.trim() ?? "";
19347
19683
  if (!query) {
19348
19684
  return null;
19349
19685
  }
19350
- const caseMetadata = isObjectRecord2(candidate.metadata) ? candidate.metadata : undefined;
19686
+ const caseMetadata = isObjectRecord3(candidate.metadata) ? candidate.metadata : undefined;
19351
19687
  const expectedChunkIds = normalizeStringArray2(candidate.expectedChunkIds);
19352
19688
  const expectedSources = normalizeStringArray2(candidate.expectedSources);
19353
19689
  const expectedDocumentIds = normalizeStringArray2(candidate.expectedDocumentIds);
@@ -19436,11 +19772,11 @@ var ragChat = (config) => {
19436
19772
  };
19437
19773
  const toRAGRetrievalComparisonRequest = (body) => {
19438
19774
  const input = toRAGEvaluationInput(body);
19439
- if (!input || !isObjectRecord2(body) || !Array.isArray(body.retrievals)) {
19775
+ if (!input || !isObjectRecord3(body) || !Array.isArray(body.retrievals)) {
19440
19776
  return null;
19441
19777
  }
19442
19778
  const retrievals = body.retrievals.map((candidate, index) => {
19443
- if (!isObjectRecord2(candidate)) {
19779
+ if (!isObjectRecord3(candidate)) {
19444
19780
  return null;
19445
19781
  }
19446
19782
  const id = getStringProperty(candidate, "id") ?? `retrieval-${index + 1}`;
@@ -19472,7 +19808,7 @@ var ragChat = (config) => {
19472
19808
  };
19473
19809
  };
19474
19810
  const toRAGRetrievalBaselinePromotionRequest = (body) => {
19475
- if (!isObjectRecord2(body)) {
19811
+ if (!isObjectRecord3(body)) {
19476
19812
  return null;
19477
19813
  }
19478
19814
  const groupKey = getStringProperty(body, "groupKey");
@@ -19501,7 +19837,7 @@ var ragChat = (config) => {
19501
19837
  };
19502
19838
  };
19503
19839
  const toRAGRetrievalBaselinePromotionFromRunRequest = (body) => {
19504
- if (!isObjectRecord2(body)) {
19840
+ if (!isObjectRecord3(body)) {
19505
19841
  return null;
19506
19842
  }
19507
19843
  const groupKey = getStringProperty(body, "groupKey");
@@ -19528,7 +19864,7 @@ var ragChat = (config) => {
19528
19864
  };
19529
19865
  };
19530
19866
  const toRAGRetrievalBaselineRevertRequest = (body) => {
19531
- if (!isObjectRecord2(body)) {
19867
+ if (!isObjectRecord3(body)) {
19532
19868
  return null;
19533
19869
  }
19534
19870
  const groupKey = getStringProperty(body, "groupKey");
@@ -19552,7 +19888,7 @@ var ragChat = (config) => {
19552
19888
  };
19553
19889
  };
19554
19890
  const toRAGRetrievalReleaseDecisionActionRequest = (body) => {
19555
- if (!isObjectRecord2(body)) {
19891
+ if (!isObjectRecord3(body)) {
19556
19892
  return null;
19557
19893
  }
19558
19894
  const groupKey = getStringProperty(body, "groupKey");
@@ -19576,7 +19912,7 @@ var ragChat = (config) => {
19576
19912
  };
19577
19913
  };
19578
19914
  const toRAGRetrievalLaneHandoffDecisionRequest = (body) => {
19579
- if (!isObjectRecord2(body)) {
19915
+ if (!isObjectRecord3(body)) {
19580
19916
  return null;
19581
19917
  }
19582
19918
  const groupKey = getStringProperty(body, "groupKey");
@@ -19601,7 +19937,7 @@ var ragChat = (config) => {
19601
19937
  };
19602
19938
  };
19603
19939
  const toRAGRetrievalReleaseIncidentAcknowledgeRequest = (body) => {
19604
- if (!isObjectRecord2(body)) {
19940
+ if (!isObjectRecord3(body)) {
19605
19941
  return null;
19606
19942
  }
19607
19943
  const incidentId = getStringProperty(body, "incidentId");
@@ -19616,7 +19952,7 @@ var ragChat = (config) => {
19616
19952
  };
19617
19953
  };
19618
19954
  const toRAGRetrievalReleaseIncidentUnacknowledgeRequest = (body) => {
19619
- if (!isObjectRecord2(body)) {
19955
+ if (!isObjectRecord3(body)) {
19620
19956
  return null;
19621
19957
  }
19622
19958
  const incidentId = getStringProperty(body, "incidentId");
@@ -19626,7 +19962,7 @@ var ragChat = (config) => {
19626
19962
  return { incidentId };
19627
19963
  };
19628
19964
  const toRAGRetrievalReleaseIncidentResolveRequest = (body) => {
19629
- if (!isObjectRecord2(body)) {
19965
+ if (!isObjectRecord3(body)) {
19630
19966
  return null;
19631
19967
  }
19632
19968
  const incidentId = getStringProperty(body, "incidentId");
@@ -19641,7 +19977,7 @@ var ragChat = (config) => {
19641
19977
  };
19642
19978
  };
19643
19979
  const toRAGRemediationAction = (value) => {
19644
- if (!isObjectRecord2(value)) {
19980
+ if (!isObjectRecord3(value)) {
19645
19981
  return;
19646
19982
  }
19647
19983
  const kind = getStringProperty(value, "kind");
@@ -19660,7 +19996,7 @@ var ragChat = (config) => {
19660
19996
  };
19661
19997
  };
19662
19998
  const toRAGRetrievalIncidentRemediationDecisionRequest = (body) => {
19663
- if (!isObjectRecord2(body)) {
19999
+ if (!isObjectRecord3(body)) {
19664
20000
  return null;
19665
20001
  }
19666
20002
  const incidentId = getStringProperty(body, "incidentId");
@@ -19680,7 +20016,7 @@ var ragChat = (config) => {
19680
20016
  };
19681
20017
  };
19682
20018
  const toRAGRetrievalIncidentRemediationExecutionRequest = (body) => {
19683
- if (!isObjectRecord2(body)) {
20019
+ if (!isObjectRecord3(body)) {
19684
20020
  return null;
19685
20021
  }
19686
20022
  const action = toRAGRemediationAction(getObjectProperty(body, "action"));
@@ -19700,7 +20036,7 @@ var ragChat = (config) => {
19700
20036
  };
19701
20037
  };
19702
20038
  const toRAGRetrievalIncidentRemediationBulkExecutionRequest = (body) => {
19703
- if (!isObjectRecord2(body) || !Array.isArray(body.items)) {
20039
+ if (!isObjectRecord3(body) || !Array.isArray(body.items)) {
19704
20040
  return null;
19705
20041
  }
19706
20042
  const items = body.items.map((entry) => toRAGRetrievalIncidentRemediationExecutionRequest(entry)).filter((entry) => Boolean(entry));
@@ -20366,7 +20702,7 @@ var ragChat = (config) => {
20366
20702
  return existing.find((entry) => entry.groupKey === groupKey && typeof entry.corpusGroupKey === "string")?.corpusGroupKey ?? comparisonRunCorpusGroups.find((entry) => entry.groupKey === groupKey && typeof entry.corpusGroupKey === "string")?.corpusGroupKey ?? baselineCorpusGroups.find((entry) => entry.groupKey === groupKey && typeof entry.corpusGroupKey === "string")?.corpusGroupKey ?? releaseDecisionCorpusGroups.find((entry) => entry.groupKey === groupKey && typeof entry.corpusGroupKey === "string")?.corpusGroupKey;
20367
20703
  };
20368
20704
  const nextByKey = new Map;
20369
- const classifyPromotionIncident = (reasons) => (reasons ?? []).some((reason) => reason.toLowerCase().includes("multivector")) ? "multivector" : "general";
20705
+ const classifyPromotionIncident = (reasons) => classifyGovernanceReasons(reasons);
20370
20706
  for (const candidate of input.promotionCandidates) {
20371
20707
  if (!candidate.groupKey || !candidate.targetRolloutLabel) {
20372
20708
  continue;
@@ -21375,12 +21711,54 @@ var ragChat = (config) => {
21375
21711
  store: retrievalComparisonHistoryStore
21376
21712
  }) : undefined;
21377
21713
  const latest = decisions?.[0];
21714
+ const adaptiveNativePlannerBenchmark = await (async () => {
21715
+ const suite = createRAGAdaptiveNativePlannerBenchmarkSuite();
21716
+ const recommendedGroupKey = typeof suite.metadata?.recommendedGroupKey === "string" ? suite.metadata.recommendedGroupKey : undefined;
21717
+ const recommendedTags = Array.isArray(suite.metadata?.recommendedTags) ? suite.metadata.recommendedTags.filter((entry) => typeof entry === "string") : undefined;
21718
+ if (!config.evaluationSuiteSnapshotHistoryStore) {
21719
+ return {
21720
+ recommendedGroupKey,
21721
+ recommendedTags,
21722
+ suiteId: suite.id,
21723
+ suiteLabel: suite.label ?? suite.id
21724
+ };
21725
+ }
21726
+ const snapshotHistory = await loadRAGEvaluationSuiteSnapshotHistory({
21727
+ limit: getIntegerLikeProperty(queryInput, "benchmarkLimit") ?? 5,
21728
+ store: config.evaluationSuiteSnapshotHistoryStore,
21729
+ suite
21730
+ });
21731
+ return {
21732
+ recommendedGroupKey,
21733
+ recommendedTags,
21734
+ snapshotHistory,
21735
+ snapshotHistoryPresentation: buildRAGEvaluationSuiteSnapshotHistoryPresentation(snapshotHistory),
21736
+ suiteId: suite.id,
21737
+ suiteLabel: suite.label ?? suite.id
21738
+ };
21739
+ })();
21740
+ const presentation = buildRAGRetrievalReleaseGroupHistoryPresentation({
21741
+ runs,
21742
+ timeline: {
21743
+ corpusGroupKey: corpusGroupKey ?? decisions?.[0]?.corpusGroupKey ?? baselines?.[0]?.corpusGroupKey ?? runs?.[0]?.corpusGroupKey,
21744
+ groupKey,
21745
+ lastApprovedAt: decisions?.find((entry) => entry.kind === "approve")?.decidedAt,
21746
+ lastPromotedAt: decisions?.find((entry) => entry.kind === "promote")?.decidedAt,
21747
+ lastRejectedAt: decisions?.find((entry) => entry.kind === "reject")?.decidedAt,
21748
+ lastRevertedAt: decisions?.find((entry) => entry.kind === "revert")?.decidedAt,
21749
+ latestDecisionAt: latest?.decidedAt,
21750
+ latestDecisionFreshnessStatus: latest?.freshnessStatus,
21751
+ latestDecisionKind: latest?.kind
21752
+ }
21753
+ });
21378
21754
  return {
21755
+ adaptiveNativePlannerBenchmark,
21379
21756
  baselines,
21380
21757
  corpusGroupKey: corpusGroupKey ?? decisions?.[0]?.corpusGroupKey ?? baselines?.[0]?.corpusGroupKey ?? runs?.[0]?.corpusGroupKey,
21381
21758
  decisions,
21382
21759
  groupKey,
21383
21760
  ok: true,
21761
+ presentation,
21384
21762
  runs,
21385
21763
  timeline: {
21386
21764
  corpusGroupKey: corpusGroupKey ?? decisions?.[0]?.corpusGroupKey ?? baselines?.[0]?.corpusGroupKey ?? runs?.[0]?.corpusGroupKey,
@@ -21395,6 +21773,69 @@ var ragChat = (config) => {
21395
21773
  }
21396
21774
  };
21397
21775
  };
21776
+ const handleAdaptiveNativePlannerBenchmark = async (queryInput) => {
21777
+ const suite = createRAGAdaptiveNativePlannerBenchmarkSuite({
21778
+ description: getStringProperty(queryInput, "description"),
21779
+ label: getStringProperty(queryInput, "label")
21780
+ });
21781
+ const snapshotHistory = config.evaluationSuiteSnapshotHistoryStore ? await loadRAGEvaluationSuiteSnapshotHistory({
21782
+ limit: getIntegerLikeProperty(queryInput, "limit") ?? 5,
21783
+ store: config.evaluationSuiteSnapshotHistoryStore,
21784
+ suite
21785
+ }) : undefined;
21786
+ return {
21787
+ ok: true,
21788
+ snapshotHistory,
21789
+ snapshotHistoryPresentation: buildRAGEvaluationSuiteSnapshotHistoryPresentation(snapshotHistory),
21790
+ suite
21791
+ };
21792
+ };
21793
+ const handlePersistAdaptiveNativePlannerBenchmarkSnapshot = async (bodyInput, request) => {
21794
+ if (request) {
21795
+ const decision = await checkAuthorization(request, "manage_retrieval_admin");
21796
+ if (!decision.allowed) {
21797
+ return {
21798
+ error: decision.reason ?? "Forbidden",
21799
+ ok: false
21800
+ };
21801
+ }
21802
+ }
21803
+ if (!config.evaluationSuiteSnapshotHistoryStore) {
21804
+ return {
21805
+ error: "Evaluation suite snapshot history store is not configured",
21806
+ ok: false
21807
+ };
21808
+ }
21809
+ const suite = createRAGAdaptiveNativePlannerBenchmarkSuite({
21810
+ description: getStringProperty(bodyInput, "description"),
21811
+ label: getStringProperty(bodyInput, "label"),
21812
+ metadata: getObjectProperty(bodyInput, "metadata")
21813
+ });
21814
+ const previousHistory = await loadRAGEvaluationSuiteSnapshotHistory({
21815
+ limit: 1,
21816
+ store: config.evaluationSuiteSnapshotHistoryStore,
21817
+ suite
21818
+ });
21819
+ const snapshot = createRAGAdaptiveNativePlannerBenchmarkSnapshot({
21820
+ createdAt: getNumberProperty(bodyInput, "createdAt"),
21821
+ metadata: getObjectProperty(bodyInput, "snapshotMetadata"),
21822
+ suite,
21823
+ version: getIntegerLikeProperty(bodyInput, "version") ?? (previousHistory.latestSnapshot?.version ?? 0) + 1
21824
+ });
21825
+ await config.evaluationSuiteSnapshotHistoryStore.saveSnapshot(snapshot);
21826
+ const snapshotHistory = await loadRAGEvaluationSuiteSnapshotHistory({
21827
+ limit: getIntegerLikeProperty(bodyInput, "limit") ?? 5,
21828
+ store: config.evaluationSuiteSnapshotHistoryStore,
21829
+ suite
21830
+ });
21831
+ return {
21832
+ ok: true,
21833
+ snapshot,
21834
+ snapshotHistory,
21835
+ snapshotHistoryPresentation: buildRAGEvaluationSuiteSnapshotHistoryPresentation(snapshotHistory),
21836
+ suite
21837
+ };
21838
+ };
21398
21839
  const handleRetrievalLaneHandoffList = async (queryInput, request) => {
21399
21840
  const result = await buildOperationsPayload();
21400
21841
  const accessScope = await loadAccessScope(request);
@@ -22586,7 +23027,7 @@ var ragChat = (config) => {
22586
23027
  };
22587
23028
  };
22588
23029
  const handlePromoteRetrievalBaselineToLane = async (body) => {
22589
- if (!isObjectRecord2(body)) {
23030
+ if (!isObjectRecord3(body)) {
22590
23031
  return {
22591
23032
  error: "Expected payload shape: { groupKey, retrievalId, rolloutLabel }",
22592
23033
  ok: false
@@ -22668,7 +23109,7 @@ var ragChat = (config) => {
22668
23109
  };
22669
23110
  };
22670
23111
  const handleIngest = async (body) => {
22671
- if (!isObjectRecord2(body)) {
23112
+ if (!isObjectRecord3(body)) {
22672
23113
  return { error: "Invalid payload", ok: false };
22673
23114
  }
22674
23115
  if (!ragStore) {
@@ -22770,7 +23211,7 @@ var ragChat = (config) => {
22770
23211
  }
22771
23212
  };
22772
23213
  const handleSearch = async (body, request) => {
22773
- if (!isObjectRecord2(body)) {
23214
+ if (!isObjectRecord3(body)) {
22774
23215
  return { error: "Invalid payload", ok: false };
22775
23216
  }
22776
23217
  const query = (getStringProperty(body, "query") ?? "").trim();
@@ -22801,7 +23242,7 @@ var ragChat = (config) => {
22801
23242
  };
22802
23243
  const persistTrace = getBooleanProperty(body, "persistTrace") === true;
22803
23244
  const traceGroupKey = getStringProperty(body, "traceGroupKey");
22804
- const traceTags = normalizeStringArray2(isObjectRecord2(body) ? body.traceTags : undefined);
23245
+ const traceTags = normalizeStringArray2(isObjectRecord3(body) ? body.traceTags : undefined);
22805
23246
  const hasSearchRetrieval = getOwnProperty(body, "retrieval");
22806
23247
  const parsedSearchRetrieval = parseRAGRetrieval(body.retrieval);
22807
23248
  if (hasSearchRetrieval && parsedSearchRetrieval === null) {
@@ -23388,6 +23829,29 @@ var ragChat = (config) => {
23388
23829
  });
23389
23830
  const latestRejectedCandidate = enrichedRecentRetrievalReleaseDecisions?.find((entry) => entry.kind === "reject");
23390
23831
  const latestRetrievalComparisonRun = recentRetrievalComparisonRuns?.[0];
23832
+ const adaptiveNativePlannerBenchmarkSuite = createRAGAdaptiveNativePlannerBenchmarkSuite();
23833
+ const adaptiveNativePlannerBenchmark = config.evaluationSuiteSnapshotHistoryStore ? {
23834
+ recommendedGroupKey: typeof adaptiveNativePlannerBenchmarkSuite.metadata?.recommendedGroupKey === "string" ? adaptiveNativePlannerBenchmarkSuite.metadata.recommendedGroupKey : undefined,
23835
+ recommendedTags: Array.isArray(adaptiveNativePlannerBenchmarkSuite.metadata?.recommendedTags) ? adaptiveNativePlannerBenchmarkSuite.metadata.recommendedTags.filter((entry) => typeof entry === "string") : undefined,
23836
+ snapshotHistory: await loadRAGEvaluationSuiteSnapshotHistory({
23837
+ limit: 5,
23838
+ store: config.evaluationSuiteSnapshotHistoryStore,
23839
+ suite: adaptiveNativePlannerBenchmarkSuite
23840
+ }),
23841
+ snapshotHistoryPresentation: undefined,
23842
+ suiteId: adaptiveNativePlannerBenchmarkSuite.id,
23843
+ suiteLabel: adaptiveNativePlannerBenchmarkSuite.label ?? adaptiveNativePlannerBenchmarkSuite.id
23844
+ } : {
23845
+ recommendedGroupKey: typeof adaptiveNativePlannerBenchmarkSuite.metadata?.recommendedGroupKey === "string" ? adaptiveNativePlannerBenchmarkSuite.metadata.recommendedGroupKey : undefined,
23846
+ recommendedTags: Array.isArray(adaptiveNativePlannerBenchmarkSuite.metadata?.recommendedTags) ? adaptiveNativePlannerBenchmarkSuite.metadata.recommendedTags.filter((entry) => typeof entry === "string") : undefined,
23847
+ snapshotHistory: undefined,
23848
+ snapshotHistoryPresentation: undefined,
23849
+ suiteId: adaptiveNativePlannerBenchmarkSuite.id,
23850
+ suiteLabel: adaptiveNativePlannerBenchmarkSuite.label ?? adaptiveNativePlannerBenchmarkSuite.id
23851
+ };
23852
+ if (adaptiveNativePlannerBenchmark.snapshotHistory) {
23853
+ adaptiveNativePlannerBenchmark.snapshotHistoryPresentation = buildRAGEvaluationSuiteSnapshotHistoryPresentation(adaptiveNativePlannerBenchmark.snapshotHistory);
23854
+ }
23391
23855
  const latestPromotionReadiness = latestRetrievalComparisonRun ? (() => {
23392
23856
  const activeTargetRolloutLabel = activeRetrievalBaselines?.find((entry) => entry.groupKey === latestRetrievalComparisonRun.groupKey)?.rolloutLabel;
23393
23857
  const state = getPromotionCandidateState({
@@ -23526,7 +23990,7 @@ var ragChat = (config) => {
23526
23990
  return {
23527
23991
  ...group,
23528
23992
  acknowledgedOpenIncidentCount,
23529
- classification: groupOpenIncidents.some((entry) => entry.classification === "multivector") ? "multivector" : group.classification,
23993
+ classification: groupOpenIncidents.some((entry) => entry.classification === "runtime") ? "runtime" : groupOpenIncidents.some((entry) => entry.classification === "multivector") ? "multivector" : group.classification,
23530
23994
  openIncidentCount: groupOpenIncidents.length,
23531
23995
  unacknowledgedOpenIncidentCount: groupOpenIncidents.length - acknowledgedOpenIncidentCount
23532
23996
  };
@@ -23734,7 +24198,7 @@ var ragChat = (config) => {
23734
24198
  ] : candidate?.ready ? [
23735
24199
  "latest candidate is ready to promote"
23736
24200
  ] : ["continue monitoring release state"];
23737
- const classification = candidate?.reasons?.length ? classifyGovernanceReasons(candidate.reasons) : (recentIncidents ?? []).some((entry) => entry.groupKey === group.groupKey && entry.targetRolloutLabel === targetRolloutLabel && entry.classification === "multivector") ? "multivector" : "general";
24201
+ const classification = candidate?.reasons?.length ? classifyGovernanceReasons(candidate.reasons) : (recentIncidents ?? []).some((entry) => entry.groupKey === group.groupKey && entry.targetRolloutLabel === targetRolloutLabel && entry.classification === "runtime") ? "runtime" : (recentIncidents ?? []).some((entry) => entry.groupKey === group.groupKey && entry.targetRolloutLabel === targetRolloutLabel && entry.classification === "multivector") ? "multivector" : "general";
23738
24202
  summaries.push({
23739
24203
  baselineRetrievalId: candidate?.baselineRetrievalId,
23740
24204
  candidateRetrievalId: candidate?.candidateRetrievalId,
@@ -24194,7 +24658,24 @@ var ragChat = (config) => {
24194
24658
  if (!latestRetrievalComparisonRun) {
24195
24659
  return alerts;
24196
24660
  }
24197
- const classifyRetrievalRegression = (input) => (input.reasons ?? []).some((reason) => reason.toLowerCase().includes("multivector")) || typeof input.delta?.multiVectorCollapsedCasesDelta === "number" || typeof input.delta?.multiVectorLexicalHitCasesDelta === "number" || typeof input.delta?.multiVectorVectorHitCasesDelta === "number" ? "multivector" : "general";
24661
+ const classifyRetrievalRegression = (input) => classifyGovernanceReasons([
24662
+ ...input.reasons ?? [],
24663
+ ...(input.delta?.multiVectorCollapsedCasesDelta ?? 0) < 0 ? [
24664
+ `multivector collapsed delta ${input.delta?.multiVectorCollapsedCasesDelta ?? 0}`
24665
+ ] : [],
24666
+ ...(input.delta?.multiVectorLexicalHitCasesDelta ?? 0) < 0 ? [
24667
+ `multivector lexical-hit delta ${input.delta?.multiVectorLexicalHitCasesDelta ?? 0}`
24668
+ ] : [],
24669
+ ...(input.delta?.multiVectorVectorHitCasesDelta ?? 0) < 0 ? [
24670
+ `multivector vector-hit delta ${input.delta?.multiVectorVectorHitCasesDelta ?? 0}`
24671
+ ] : [],
24672
+ ...(input.delta?.runtimeCandidateBudgetExhaustedCasesDelta ?? 0) > 0 ? [
24673
+ `runtime candidate-budget-exhausted delta ${input.delta?.runtimeCandidateBudgetExhaustedCasesDelta ?? 0}`
24674
+ ] : [],
24675
+ ...(input.delta?.runtimeUnderfilledTopKCasesDelta ?? 0) > 0 ? [
24676
+ `runtime underfilled-topk delta ${input.delta?.runtimeUnderfilledTopKCasesDelta ?? 0}`
24677
+ ] : []
24678
+ ]);
24198
24679
  const latestWinner = latestRetrievalComparisonRun.comparison.summary.bestByPassingRate;
24199
24680
  if (latestWinner && stableWinnerByPassingRate?.retrievalId && stableWinnerByPassingRate.retrievalId !== latestWinner) {
24200
24681
  alerts.push({
@@ -24371,12 +24852,15 @@ var ragChat = (config) => {
24371
24852
  ok: true,
24372
24853
  readiness: buildReadiness(),
24373
24854
  retrievalComparisons: {
24855
+ adaptiveNativePlannerBenchmark,
24374
24856
  configured: Boolean(retrievalComparisonHistoryStore),
24375
24857
  latest: latestRetrievalComparisonRun ? {
24376
24858
  bestByAverageF1: latestRetrievalComparisonRun.comparison.summary.bestByAverageF1,
24377
24859
  bestByMultivectorCollapsedCases: latestRetrievalComparisonRun.comparison.summary.bestByMultivectorCollapsedCases,
24378
24860
  bestByMultivectorLexicalHitCases: latestRetrievalComparisonRun.comparison.summary.bestByMultivectorLexicalHitCases,
24379
24861
  bestByMultivectorVectorHitCases: latestRetrievalComparisonRun.comparison.summary.bestByMultivectorVectorHitCases,
24862
+ bestByLowestRuntimeCandidateBudgetExhaustedCases: latestRetrievalComparisonRun.comparison.summary.bestByLowestRuntimeCandidateBudgetExhaustedCases,
24863
+ bestByLowestRuntimeUnderfilledTopKCases: latestRetrievalComparisonRun.comparison.summary.bestByLowestRuntimeUnderfilledTopKCases,
24380
24864
  bestByPassingRate: latestRetrievalComparisonRun.comparison.summary.bestByPassingRate,
24381
24865
  corpusGroupKey: latestRetrievalComparisonRun.corpusGroupKey,
24382
24866
  elapsedMs: latestRetrievalComparisonRun.elapsedMs,
@@ -24539,7 +25023,7 @@ var ragChat = (config) => {
24539
25023
  ok: false
24540
25024
  };
24541
25025
  }
24542
- if (!isObjectRecord2(body)) {
25026
+ if (!isObjectRecord3(body)) {
24543
25027
  return {
24544
25028
  error: "Invalid payload",
24545
25029
  ok: false
@@ -25292,6 +25776,36 @@ var ragChat = (config) => {
25292
25776
  });
25293
25777
  }
25294
25778
  return result;
25779
+ }).get(`${path}/compare/retrieval/benchmarks/adaptive-native-planner`, async ({ query, request, set }) => {
25780
+ const result = await handleAdaptiveNativePlannerBenchmark(query);
25781
+ if (!result.ok) {
25782
+ set.status = HTTP_STATUS_BAD_REQUEST;
25783
+ }
25784
+ if (config.htmx && isHTMXRequest(request)) {
25785
+ if (!result.ok) {
25786
+ return toHTMXResponse(workflowRenderers.error(result.error ?? "Adaptive native planner benchmark failed"), getNumericStatus(set.status));
25787
+ }
25788
+ return new Response("", {
25789
+ headers: HTML_HEADERS,
25790
+ status: getNumericStatus(set.status)
25791
+ });
25792
+ }
25793
+ return result;
25794
+ }).post(`${path}/compare/retrieval/benchmarks/adaptive-native-planner/snapshots`, async ({ body, request, set }) => {
25795
+ const result = await handlePersistAdaptiveNativePlannerBenchmarkSnapshot(body, request);
25796
+ if (!result.ok) {
25797
+ set.status = HTTP_STATUS_BAD_REQUEST;
25798
+ }
25799
+ if (config.htmx && isHTMXRequest(request)) {
25800
+ if (!result.ok) {
25801
+ return toHTMXResponse(workflowRenderers.error(result.error ?? "Adaptive native planner benchmark snapshot failed"), getNumericStatus(set.status));
25802
+ }
25803
+ return new Response("", {
25804
+ headers: HTML_HEADERS,
25805
+ status: getNumericStatus(set.status)
25806
+ });
25807
+ }
25808
+ return result;
25295
25809
  }).get(`${path}/compare/retrieval/baselines`, async ({ query, request, set }) => {
25296
25810
  const result = await handleRetrievalBaselineList(query, request);
25297
25811
  if (!result.ok) {
@@ -29825,7 +30339,7 @@ var querySimilarity = (left, right) => {
29825
30339
  init_constants();
29826
30340
 
29827
30341
  // src/ai/rag/adapters/filtering.ts
29828
- var isObjectRecord3 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
30342
+ var isObjectRecord4 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
29829
30343
  var valuesMatch = (expected, actual) => {
29830
30344
  if (actual === expected) {
29831
30345
  return true;
@@ -29835,12 +30349,12 @@ var valuesMatch = (expected, actual) => {
29835
30349
  }
29836
30350
  return false;
29837
30351
  };
29838
- var isFilterOperatorRecord = (value) => isObjectRecord3(value) && Object.keys(value).some((key) => key.startsWith("$"));
30352
+ var isFilterOperatorRecord = (value) => isObjectRecord4(value) && Object.keys(value).some((key) => key.startsWith("$"));
29839
30353
  var getPathValue = (record, path) => {
29840
30354
  const segments = path.split(".").filter(Boolean);
29841
30355
  let current = record;
29842
30356
  for (const segment of segments) {
29843
- if (!isObjectRecord3(current)) {
30357
+ if (!isObjectRecord4(current)) {
29844
30358
  return;
29845
30359
  }
29846
30360
  current = current[segment];
@@ -29876,7 +30390,7 @@ var matchesOperatorFilter = (actual, filter) => Object.entries(filter).every(([o
29876
30390
  }
29877
30391
  });
29878
30392
  var matchesMetadataFilterValue = (actual, expected) => isFilterOperatorRecord(expected) ? matchesOperatorFilter(actual, expected) : Array.isArray(actual) ? actual.some((entry) => valuesMatch(expected, entry)) : valuesMatch(expected, actual);
29879
- var isNestedFilterArray = (value) => Array.isArray(value) && value.every((entry) => isObjectRecord3(entry));
30393
+ var isNestedFilterArray = (value) => Array.isArray(value) && value.every((entry) => isObjectRecord4(entry));
29880
30394
  var matchesLogicalFilter = (record, key, value) => {
29881
30395
  switch (key) {
29882
30396
  case "$and":
@@ -29884,7 +30398,7 @@ var matchesLogicalFilter = (record, key, value) => {
29884
30398
  case "$or":
29885
30399
  return isNestedFilterArray(value) ? value.some((entry) => matchesMetadataFilterRecord(record, entry)) : false;
29886
30400
  case "$not":
29887
- return isObjectRecord3(value) ? !matchesMetadataFilterRecord(record, value) : false;
30401
+ return isObjectRecord4(value) ? !matchesMetadataFilterRecord(record, value) : false;
29888
30402
  default:
29889
30403
  return false;
29890
30404
  }
@@ -30053,6 +30567,22 @@ var planNativeCandidateSearchK = (input) => {
30053
30567
  }
30054
30568
  return Math.min(base, filtered);
30055
30569
  };
30570
+ var resolveAdaptiveNativeCandidateLimit = (input) => {
30571
+ const clamp = (value) => Math.min(input.defaultCandidateLimit, Math.max(1, Math.floor(value)));
30572
+ const filteredCap = typeof input.filteredCandidateCount === "number" && Number.isFinite(input.filteredCandidateCount) ? Math.max(0, Math.floor(input.filteredCandidateCount)) : undefined;
30573
+ if (typeof input.explicitCandidateLimit === "number" && Number.isFinite(input.explicitCandidateLimit)) {
30574
+ return filteredCap === undefined ? clamp(input.explicitCandidateLimit) : Math.min(clamp(input.explicitCandidateLimit), filteredCap);
30575
+ }
30576
+ const baseFloor = Math.max(input.topK, input.topK * Math.max(1, Math.floor(input.queryMultiplier)));
30577
+ let tuned = input.plannerProfile === "latency" ? clamp(Math.max(input.topK * 2, baseFloor)) : input.plannerProfile === "recall" ? clamp(Math.max(input.topK * 12, baseFloor * 4)) : clamp(Math.max(input.topK * 6, baseFloor * 2));
30578
+ if (filteredCap !== undefined) {
30579
+ if (filteredCap === 0) {
30580
+ return 0;
30581
+ }
30582
+ tuned = Math.min(tuned, filteredCap);
30583
+ }
30584
+ return tuned;
30585
+ };
30056
30586
  var planNativeCandidateSearchBackfillK = (input) => {
30057
30587
  if (typeof input.maxBackfills === "number" && Number.isFinite(input.maxBackfills) && (input.backfillCount ?? 0) >= Math.max(0, Math.floor(input.maxBackfills))) {
30058
30588
  return input.currentSearchK;
@@ -30373,12 +30903,6 @@ var normalizeQueryMultiplier = (value) => {
30373
30903
  }
30374
30904
  return Math.min(MAX_QUERY_MULTIPLIER, Math.max(1, Math.floor(value)));
30375
30905
  };
30376
- var normalizeCandidateLimit = (value) => {
30377
- if (value === undefined || !Number.isFinite(value)) {
30378
- return RAG_NATIVE_QUERY_CANDIDATE_LIMIT;
30379
- }
30380
- return Math.min(RAG_NATIVE_QUERY_CANDIDATE_LIMIT, Math.max(1, Math.floor(value)));
30381
- };
30382
30906
  var normalizeMaxBackfills = (value) => {
30383
30907
  if (value === undefined || !Number.isFinite(value)) {
30384
30908
  return;
@@ -30733,7 +31257,6 @@ var createPostgresRAGStore = (options = {}) => {
30733
31257
  await init();
30734
31258
  const queryVector = normalizeVector(input.queryVector);
30735
31259
  const queryMultiplier2 = normalizeQueryMultiplier(input.queryMultiplier ?? options.queryMultiplier);
30736
- const candidateLimit = normalizeCandidateLimit(input.candidateLimit);
30737
31260
  const maxBackfills = normalizeMaxBackfills(input.maxBackfills);
30738
31261
  const minResults = normalizeMinResults(input.minResults, input.topK);
30739
31262
  const fillTarget = resolveFillTarget({
@@ -30756,6 +31279,14 @@ var createPostgresRAGStore = (options = {}) => {
30756
31279
  pushdownFilter: effectivePushdownFilter
30757
31280
  };
30758
31281
  const totalRows = parseCountValue(totalRowsResult?.[0]?.count);
31282
+ const candidateLimit = resolveAdaptiveNativeCandidateLimit({
31283
+ defaultCandidateLimit: RAG_NATIVE_QUERY_CANDIDATE_LIMIT,
31284
+ explicitCandidateLimit: input.candidateLimit,
31285
+ filteredCandidateCount: totalRows,
31286
+ plannerProfile: input.plannerProfile,
31287
+ queryMultiplier: queryMultiplier2,
31288
+ topK: input.topK
31289
+ });
30759
31290
  const hasPushdownFilter = Boolean(effectivePushdownFilter);
30760
31291
  const plannedFilteredCandidateCount = hasPushdownFilter && totalRows === 0 ? undefined : totalRows;
30761
31292
  const initialSearchK = planNativeCandidateSearchK({
@@ -31098,9 +31629,9 @@ var DEFAULT_QUERY_MULTIPLIER2 = 4;
31098
31629
  var MAX_QUERY_MULTIPLIER2 = 16;
31099
31630
  var IDENTIFIER_RE2 = /^[a-zA-Z_][a-zA-Z0-9_]*$/;
31100
31631
  var isParsedMetadata = (value) => Boolean(value) && typeof value === "object";
31101
- var isObjectRecord4 = (value) => Boolean(value) && typeof value === "object";
31102
- var isStoredRow = (value) => isObjectRecord4(value) && typeof value.chunk_id === "string" && typeof value.text === "string" && (typeof value.title === "string" || value.title === null) && (typeof value.source === "string" || value.source === null) && (typeof value.metadata === "string" || value.metadata === null) && typeof value.embedding === "string";
31103
- var isNativeStoredRow = (value) => isObjectRecord4(value) && typeof value.chunk_id === "string" && typeof value.chunk_text === "string" && (typeof value.title === "string" || value.title === null) && (typeof value.source === "string" || value.source === null) && (typeof value.metadata === "string" || value.metadata === null) && typeof value.embedding === "string" && typeof value.distance === "number";
31632
+ var isObjectRecord5 = (value) => Boolean(value) && typeof value === "object";
31633
+ var isStoredRow = (value) => isObjectRecord5(value) && typeof value.chunk_id === "string" && typeof value.text === "string" && (typeof value.title === "string" || value.title === null) && (typeof value.source === "string" || value.source === null) && (typeof value.metadata === "string" || value.metadata === null) && typeof value.embedding === "string";
31634
+ var isNativeStoredRow = (value) => isObjectRecord5(value) && typeof value.chunk_id === "string" && typeof value.chunk_text === "string" && (typeof value.title === "string" || value.title === null) && (typeof value.source === "string" || value.source === null) && (typeof value.metadata === "string" || value.metadata === null) && typeof value.embedding === "string" && typeof value.distance === "number";
31104
31635
  var toStoredRows = (value) => Array.isArray(value) ? value.filter((row) => isStoredRow(row)) : [];
31105
31636
  var toNativeStoredRows = (value) => Array.isArray(value) ? value.filter((row) => isNativeStoredRow(row)) : [];
31106
31637
  var createSQLiteStatus = (dimensions, nativeDiagnostics, useNative) => ({
@@ -31128,12 +31659,6 @@ var normalizeQueryMultiplier2 = (value) => {
31128
31659
  const minMultiplier = Math.max(1, Math.floor(value));
31129
31660
  return Math.min(minMultiplier, MAX_QUERY_MULTIPLIER2);
31130
31661
  };
31131
- var normalizeCandidateLimit2 = (value) => {
31132
- if (value === undefined || !Number.isFinite(value)) {
31133
- return RAG_NATIVE_QUERY_CANDIDATE_LIMIT;
31134
- }
31135
- return Math.min(RAG_NATIVE_QUERY_CANDIDATE_LIMIT, Math.max(1, Math.floor(value)));
31136
- };
31137
31662
  var normalizeMaxBackfills2 = (value) => {
31138
31663
  if (value === undefined || !Number.isFinite(value)) {
31139
31664
  return;
@@ -31992,7 +32517,6 @@ var createSQLiteRAGStore = (options = {}) => {
31992
32517
  throw new Error("Native vector backend is not available");
31993
32518
  }
31994
32519
  const queryMultiplier = normalizeQueryMultiplier2(input.queryMultiplier ?? nativeConfig?.queryMultiplier);
31995
- const candidateLimit = normalizeCandidateLimit2(input.candidateLimit);
31996
32520
  const maxBackfills = normalizeMaxBackfills2(input.maxBackfills);
31997
32521
  const minResults = normalizeMinResults2(input.minResults, input.topK);
31998
32522
  const fillTarget = resolveFillTarget2({
@@ -32010,6 +32534,14 @@ var createSQLiteRAGStore = (options = {}) => {
32010
32534
  title: "title"
32011
32535
  });
32012
32536
  const filteredCandidateCount = getFilteredSQLiteCandidateCount(db, tableName, filterPlan);
32537
+ const candidateLimit = resolveAdaptiveNativeCandidateLimit({
32538
+ defaultCandidateLimit: RAG_NATIVE_QUERY_CANDIDATE_LIMIT,
32539
+ explicitCandidateLimit: input.candidateLimit,
32540
+ filteredCandidateCount,
32541
+ plannerProfile: input.plannerProfile,
32542
+ queryMultiplier,
32543
+ topK: input.topK
32544
+ });
32013
32545
  const searchK = planNativeCandidateSearchK({
32014
32546
  candidateLimit,
32015
32547
  filteredCandidateCount,
@@ -33347,6 +33879,9 @@ var createRAGClient = (options) => {
33347
33879
  if (typeof input.runLimit === "number") {
33348
33880
  searchParams.set("runLimit", String(input.runLimit));
33349
33881
  }
33882
+ if (typeof input.benchmarkLimit === "number") {
33883
+ searchParams.set("benchmarkLimit", String(input.benchmarkLimit));
33884
+ }
33350
33885
  if (input.targetRolloutLabel) {
33351
33886
  searchParams.set("targetRolloutLabel", input.targetRolloutLabel);
33352
33887
  }
@@ -33360,6 +33895,51 @@ var createRAGClient = (options) => {
33360
33895
  }
33361
33896
  return payload;
33362
33897
  },
33898
+ async adaptiveNativePlannerBenchmark(input) {
33899
+ const searchParams = new URLSearchParams;
33900
+ if (typeof input?.limit === "number") {
33901
+ searchParams.set("limit", String(input.limit));
33902
+ }
33903
+ if (input?.label) {
33904
+ searchParams.set("label", input.label);
33905
+ }
33906
+ if (input?.description) {
33907
+ searchParams.set("description", input.description);
33908
+ }
33909
+ const suffix = searchParams.size ? `?${searchParams}` : "";
33910
+ const response = await fetchImpl(`${basePath}/compare/retrieval/benchmarks/adaptive-native-planner${suffix}`);
33911
+ if (!response.ok) {
33912
+ throw new Error(await toErrorMessage3(response));
33913
+ }
33914
+ const payload = await parseJson(response);
33915
+ if (!payload.ok) {
33916
+ throw new Error(payload.error ?? "Adaptive native planner benchmark history failed");
33917
+ }
33918
+ return payload;
33919
+ },
33920
+ async saveAdaptiveNativePlannerBenchmarkSnapshot(input) {
33921
+ const response = await fetchImpl(`${basePath}/compare/retrieval/benchmarks/adaptive-native-planner/snapshots`, {
33922
+ body: JSON.stringify({
33923
+ createdAt: input?.createdAt,
33924
+ description: input?.description,
33925
+ label: input?.label,
33926
+ limit: input?.limit,
33927
+ metadata: input?.metadata,
33928
+ snapshotMetadata: input?.snapshotMetadata,
33929
+ version: input?.version
33930
+ }),
33931
+ headers: jsonHeaders,
33932
+ method: "POST"
33933
+ });
33934
+ if (!response.ok) {
33935
+ throw new Error(await toErrorMessage3(response));
33936
+ }
33937
+ const payload = await parseJson(response);
33938
+ if (!payload.ok) {
33939
+ throw new Error(payload.error ?? "Adaptive native planner benchmark snapshot failed");
33940
+ }
33941
+ return payload;
33942
+ },
33363
33943
  async retrievalLaneHandoffs(input) {
33364
33944
  const searchParams = new URLSearchParams;
33365
33945
  if (input?.groupKey) {
@@ -34340,6 +34920,8 @@ export {
34340
34920
  createRAGBunS3SyncClient,
34341
34921
  createRAGArchiveFileExtractor,
34342
34922
  createRAGArchiveExpander,
34923
+ createRAGAdaptiveNativePlannerBenchmarkSuite,
34924
+ createRAGAdaptiveNativePlannerBenchmarkSnapshot,
34343
34925
  createRAGAccessControl,
34344
34926
  createPostgresRAGStore,
34345
34927
  createPDFFileExtractor,
@@ -34391,5 +34973,5 @@ export {
34391
34973
  addRAGEvaluationSuiteCase
34392
34974
  };
34393
34975
 
34394
- //# debugId=E1F755AF5BA36E2664756E2164756E21
34976
+ //# debugId=025E4FAB1EEDD6C464756E2164756E21
34395
34977
  //# sourceMappingURL=index.js.map