@absolutejs/absolute 0.19.0-beta.550 → 0.19.0-beta.552

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
@@ -2569,6 +2569,7 @@ var resolveRAGHybridSearchOptions = (retrieval) => {
2569
2569
  fusion: retrieval.fusion ?? "rrf",
2570
2570
  fusionConstant: Math.max(1, Math.floor(retrieval.fusionConstant ?? DEFAULT_FUSION_CONSTANT)),
2571
2571
  lexicalTopK: retrieval.lexicalTopK,
2572
+ maxResultsPerSource: typeof retrieval.maxResultsPerSource === "number" ? Math.max(1, Math.floor(retrieval.maxResultsPerSource)) : undefined,
2572
2573
  lexicalWeight: Math.max(0, retrieval.lexicalWeight ?? 2),
2573
2574
  mode: retrieval.mode ?? "vector",
2574
2575
  vectorWeight: Math.max(0, retrieval.vectorWeight ?? 1)
@@ -4314,6 +4315,27 @@ var mergeQueryResults = (results) => {
4314
4315
  return left.chunkId.localeCompare(right.chunkId);
4315
4316
  });
4316
4317
  };
4318
+ var getRAGSourceDiversityKey = (result) => {
4319
+ const documentId = typeof result.metadata?.documentId === "string" ? result.metadata.documentId : undefined;
4320
+ return result.source ?? documentId ?? result.title ?? result.chunkId;
4321
+ };
4322
+ var applyRAGSourceDiversity = (results, maxResultsPerSource) => {
4323
+ if (typeof maxResultsPerSource !== "number") {
4324
+ return results;
4325
+ }
4326
+ const limited = [];
4327
+ const counts = new Map;
4328
+ for (const result of results) {
4329
+ const key = getRAGSourceDiversityKey(result);
4330
+ const count = counts.get(key) ?? 0;
4331
+ if (count >= maxResultsPerSource) {
4332
+ continue;
4333
+ }
4334
+ counts.set(key, count + 1);
4335
+ limited.push(result);
4336
+ }
4337
+ return limited;
4338
+ };
4317
4339
  var weightQueryResults = (results, queryIndex) => {
4318
4340
  if (queryIndex === 0) {
4319
4341
  return results;
@@ -4369,6 +4391,7 @@ var createRAGCollection = (options) => {
4369
4391
  candidateTopK,
4370
4392
  hasQueryTransform,
4371
4393
  hasReranker,
4394
+ maxResultsPerSource: retrieval.maxResultsPerSource ?? null,
4372
4395
  mode: retrieval.mode,
4373
4396
  runLexical,
4374
4397
  runVector,
@@ -4486,7 +4509,18 @@ var createRAGCollection = (options) => {
4486
4509
  },
4487
4510
  stage: "rerank"
4488
4511
  });
4489
- const limited = reranked.slice(0, topK);
4512
+ const diversified = applyRAGSourceDiversity(reranked, retrieval.maxResultsPerSource);
4513
+ if (typeof retrieval.maxResultsPerSource === "number") {
4514
+ steps.push({
4515
+ count: diversified.length,
4516
+ label: "Balanced candidates across sources",
4517
+ metadata: {
4518
+ maxResultsPerSource: retrieval.maxResultsPerSource
4519
+ },
4520
+ stage: "source_balance"
4521
+ });
4522
+ }
4523
+ const limited = diversified.slice(0, topK);
4490
4524
  if (typeof input.scoreThreshold !== "number") {
4491
4525
  steps.push({
4492
4526
  count: limited.length,
@@ -4501,13 +4535,14 @@ var createRAGCollection = (options) => {
4501
4535
  trace: {
4502
4536
  candidateTopK,
4503
4537
  lexicalTopK,
4538
+ maxResultsPerSource: retrieval.maxResultsPerSource,
4504
4539
  mode: retrieval.mode,
4505
4540
  query: input.query,
4506
4541
  resultCounts: {
4507
4542
  final: limited.length,
4508
4543
  fused: results.length,
4509
4544
  lexical: lexicalResults.length,
4510
- reranked: reranked.length,
4545
+ reranked: diversified.length,
4511
4546
  vector: vectorResults.length
4512
4547
  },
4513
4548
  runLexical,
@@ -4542,13 +4577,14 @@ var createRAGCollection = (options) => {
4542
4577
  trace: {
4543
4578
  candidateTopK,
4544
4579
  lexicalTopK,
4580
+ maxResultsPerSource: retrieval.maxResultsPerSource,
4545
4581
  mode: retrieval.mode,
4546
4582
  query: input.query,
4547
4583
  resultCounts: {
4548
4584
  final: filtered.length,
4549
4585
  fused: results.length,
4550
4586
  lexical: lexicalResults.length,
4551
- reranked: reranked.length,
4587
+ reranked: diversified.length,
4552
4588
  vector: vectorResults.length
4553
4589
  },
4554
4590
  runLexical,
@@ -6370,10 +6406,14 @@ var buildRAGGroundingProviderOverviewPresentation = (input) => {
6370
6406
  summary: winnerEntry ? `passing ${formatEvaluationPassingRate(winnerEntry.response.passingRate)} \xB7 citation f1 ${winnerEntry.response.summary.averageCitationF1.toFixed(3)} \xB7 resolved ${formatEvaluationPassingRate(winnerEntry.response.summary.averageResolvedCitationRate)}` : "Stored workflow evaluation"
6371
6407
  };
6372
6408
  };
6373
- var buildRAGQualityOverviewPresentation = (input) => ({
6409
+ var buildRAGRetrievalOverviewPresentation = (comparison) => ({
6410
+ rows: buildRAGRetrievalComparisonOverviewPresentation(comparison).rows
6411
+ });
6412
+ var buildRAGRerankerOverviewPresentation = (comparison) => ({
6413
+ rows: buildRAGRerankerComparisonOverviewPresentation(comparison).rows
6414
+ });
6415
+ var buildRAGGroundingOverviewPresentation = (input) => ({
6374
6416
  rows: [
6375
- ...buildRAGRetrievalComparisonOverviewPresentation(input.retrievalComparison).rows,
6376
- ...buildRAGRerankerComparisonOverviewPresentation(input.rerankerComparison).rows,
6377
6417
  {
6378
6418
  label: "Grounding",
6379
6419
  value: formatGroundingHistorySummaryValue(input.groundingEvaluation)
@@ -6386,6 +6426,16 @@ var buildRAGQualityOverviewPresentation = (input) => ({
6386
6426
  ]
6387
6427
  ]
6388
6428
  });
6429
+ var buildRAGQualityOverviewPresentation = (input) => ({
6430
+ rows: [
6431
+ ...buildRAGRetrievalOverviewPresentation(input.retrievalComparison).rows,
6432
+ ...buildRAGRerankerOverviewPresentation(input.rerankerComparison).rows,
6433
+ ...buildRAGGroundingOverviewPresentation({
6434
+ groundingEvaluation: input.groundingEvaluation,
6435
+ groundingProviderOverview: input.groundingProviderOverview
6436
+ }).rows
6437
+ ]
6438
+ });
6389
6439
  var buildRAGGroundingProviderCaseComparisonPresentations = (comparisons) => comparisons.map((comparison) => {
6390
6440
  const resolveLabel = (key) => comparison.entries.find((entry) => entry.providerKey === key)?.label ?? key ?? "n/a";
6391
6441
  return {
@@ -12444,8 +12494,10 @@ export {
12444
12494
  buildRAGSourceSummaries,
12445
12495
  buildRAGSourceGroups,
12446
12496
  buildRAGRetrievalTracePresentation,
12497
+ buildRAGRetrievalOverviewPresentation,
12447
12498
  buildRAGRetrievalComparisonPresentations,
12448
12499
  buildRAGRetrievalComparisonOverviewPresentation,
12500
+ buildRAGRerankerOverviewPresentation,
12449
12501
  buildRAGRerankerComparisonPresentations,
12450
12502
  buildRAGRerankerComparisonOverviewPresentation,
12451
12503
  buildRAGReadinessPresentation,
@@ -12455,6 +12507,7 @@ export {
12455
12507
  buildRAGGroundingProviderPresentations,
12456
12508
  buildRAGGroundingProviderOverviewPresentation,
12457
12509
  buildRAGGroundingProviderCaseComparisonPresentations,
12510
+ buildRAGGroundingOverviewPresentation,
12458
12511
  buildRAGGroundedAnswer,
12459
12512
  buildRAGEvaluationRunDiff,
12460
12513
  buildRAGEvaluationResponse,
@@ -12488,5 +12541,5 @@ export {
12488
12541
  aiChat
12489
12542
  };
12490
12543
 
12491
- //# debugId=87BF178FDB66370264756E2164756E21
12544
+ //# debugId=FD250EE2F99EB57964756E2164756E21
12492
12545
  //# sourceMappingURL=index.js.map