@absolutejs/absolute 0.19.0-beta.613 → 0.19.0-beta.615

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
@@ -3772,10 +3772,35 @@ var buildRAGRetrievalTracePresentation = (trace) => {
3772
3772
  ];
3773
3773
  const details = [
3774
3774
  { label: "Transformed query", value: trace.transformedQuery },
3775
+ ...trace.queryTransformLabel || trace.queryTransformProvider ? [
3776
+ {
3777
+ label: "Query transform",
3778
+ value: trace.queryTransformLabel ?? trace.queryTransformProvider ?? "configured"
3779
+ },
3780
+ ...trace.queryTransformReason ? [
3781
+ {
3782
+ label: "Query transform reason",
3783
+ value: trace.queryTransformReason
3784
+ }
3785
+ ] : []
3786
+ ] : [],
3775
3787
  {
3776
3788
  label: "Variant queries",
3777
3789
  value: trace.variantQueries.length > 0 ? trace.variantQueries.join(" \xB7 ") : "none"
3778
3790
  },
3791
+ ...trace.requestedMode && trace.requestedMode !== trace.mode ? [{ label: "Requested mode", value: trace.requestedMode }] : [],
3792
+ ...trace.routingLabel || trace.routingProvider ? [
3793
+ {
3794
+ label: "Routing decision",
3795
+ value: trace.routingLabel ?? trace.routingProvider ?? "configured"
3796
+ },
3797
+ ...trace.routingReason ? [
3798
+ {
3799
+ label: "Routing reason",
3800
+ value: trace.routingReason
3801
+ }
3802
+ ] : []
3803
+ ] : [],
3779
3804
  { label: "Candidate topK", value: String(trace.candidateTopK) },
3780
3805
  { label: "Lexical topK", value: String(trace.lexicalTopK) }
3781
3806
  ];
@@ -4668,10 +4693,10 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4668
4693
  const vectorHits = channels.includes("vector") ? 1 : 0;
4669
4694
  const lexicalHits = channels.includes("lexical") ? 1 : 0;
4670
4695
  const hybridHits = isHybrid ? 1 : 0;
4671
- const queryOrigin = source.metadata?.retrievalQueryOrigin;
4672
- const primaryHits = queryOrigin === "primary" ? 1 : 0;
4673
- const transformedHits = queryOrigin === "transformed" ? 1 : 0;
4674
- const variantHits = queryOrigin === "variant" ? 1 : 0;
4696
+ const queryOrigins = Array.isArray(source.metadata?.retrievalQueryOrigins) ? source.metadata.retrievalQueryOrigins.filter((value) => value === "primary" || value === "transformed" || value === "variant") : source.metadata?.retrievalQueryOrigin === "primary" || source.metadata?.retrievalQueryOrigin === "transformed" || source.metadata?.retrievalQueryOrigin === "variant" ? [source.metadata.retrievalQueryOrigin] : [];
4697
+ const primaryHits = queryOrigins.includes("primary") ? 1 : 0;
4698
+ const transformedHits = queryOrigins.includes("transformed") ? 1 : 0;
4699
+ const variantHits = queryOrigins.includes("variant") ? 1 : 0;
4675
4700
  if (!existing) {
4676
4701
  sections.set(key, {
4677
4702
  bestScore: source.score,
@@ -4878,7 +4903,14 @@ var buildRAGSectionRetrievalDiagnostics = (sources, trace) => {
4878
4903
  transformedHits: section.transformedHits,
4879
4904
  variantHits: section.variantHits
4880
4905
  },
4906
+ requestedMode: trace?.requestedMode,
4881
4907
  retrievalMode: trace?.mode,
4908
+ routingLabel: trace?.routingLabel,
4909
+ routingProvider: trace?.routingProvider,
4910
+ routingReason: trace?.routingReason,
4911
+ queryTransformLabel: trace?.queryTransformLabel,
4912
+ queryTransformProvider: trace?.queryTransformProvider,
4913
+ queryTransformReason: trace?.queryTransformReason,
4882
4914
  reasons,
4883
4915
  rerankApplied: trace?.steps.some((step) => step.stage === "rerank" && step.metadata?.applied === true),
4884
4916
  scoreShare,
@@ -8356,7 +8388,17 @@ var STOP_WORDS3 = new Set([
8356
8388
  "which",
8357
8389
  "why"
8358
8390
  ]);
8359
- var collectMetadataStrings2 = (value) => {
8391
+ var INTERNAL_RETRIEVAL_METADATA_KEYS = new Set([
8392
+ "retrievalChannels",
8393
+ "retrievalQuery",
8394
+ "retrievalQueryIndex",
8395
+ "retrievalQueryOrigin",
8396
+ "retrievalQueryOrigins"
8397
+ ]);
8398
+ var collectMetadataStrings2 = (value, key) => {
8399
+ if (typeof key === "string" && INTERNAL_RETRIEVAL_METADATA_KEYS.has(key)) {
8400
+ return [];
8401
+ }
8360
8402
  if (typeof value === "string" || typeof value === "number") {
8361
8403
  return [String(value)];
8362
8404
  }
@@ -8364,7 +8406,7 @@ var collectMetadataStrings2 = (value) => {
8364
8406
  return value.flatMap((entry) => collectMetadataStrings2(entry));
8365
8407
  }
8366
8408
  if (value && typeof value === "object") {
8367
- return Object.values(value).flatMap((entry) => collectMetadataStrings2(entry));
8409
+ return Object.entries(value).flatMap(([entryKey, entry]) => collectMetadataStrings2(entry, entryKey));
8368
8410
  }
8369
8411
  return [];
8370
8412
  };
@@ -10538,9 +10580,17 @@ var mergeQueryResults = (results) => {
10538
10580
  const merged = new Map;
10539
10581
  for (const result of results) {
10540
10582
  const existing = merged.get(result.chunkId);
10541
- if (!existing || result.score > existing.score) {
10542
- merged.set(result.chunkId, result);
10543
- }
10583
+ const existingOrigins = Array.isArray(existing?.metadata?.retrievalQueryOrigins) ? existing.metadata.retrievalQueryOrigins.filter((value) => typeof value === "string") : typeof existing?.metadata?.retrievalQueryOrigin === "string" ? [existing.metadata.retrievalQueryOrigin] : [];
10584
+ const resultOrigins = Array.isArray(result.metadata?.retrievalQueryOrigins) ? result.metadata.retrievalQueryOrigins.filter((value) => typeof value === "string") : typeof result.metadata?.retrievalQueryOrigin === "string" ? [result.metadata.retrievalQueryOrigin] : [];
10585
+ const mergedOrigins = Array.from(new Set([...existingOrigins, ...resultOrigins]));
10586
+ const preferred = !existing || result.score > existing.score ? result : existing;
10587
+ merged.set(result.chunkId, {
10588
+ ...preferred,
10589
+ metadata: {
10590
+ ...preferred.metadata ?? {},
10591
+ retrievalQueryOrigins: mergedOrigins
10592
+ }
10593
+ });
10544
10594
  }
10545
10595
  return [...merged.values()].sort((left, right) => {
10546
10596
  if (right.score !== left.score) {
@@ -10744,6 +10794,19 @@ var annotateRetrievalQueryOrigin = (input) => {
10744
10794
  };
10745
10795
  var shouldRunVectorRetrieval = (mode) => mode === "vector" || mode === "hybrid";
10746
10796
  var shouldRunLexicalRetrieval = (mode, store) => mode === "lexical" || mode === "hybrid" && Boolean(store.queryLexical);
10797
+ var resolveRAGRetrievalStrategy = (retrievalStrategy) => {
10798
+ if (!retrievalStrategy) {
10799
+ return null;
10800
+ }
10801
+ if (typeof retrievalStrategy === "function") {
10802
+ return {
10803
+ defaultLabel: undefined,
10804
+ providerName: undefined,
10805
+ select: retrievalStrategy
10806
+ };
10807
+ }
10808
+ return retrievalStrategy;
10809
+ };
10747
10810
  var createRAGCollection = (options) => {
10748
10811
  const defaultTopK = options.defaultTopK ?? DEFAULT_TOP_K2;
10749
10812
  const defaultCandidateMultiplier = Math.max(1, Math.floor(options.defaultCandidateMultiplier ?? 4));
@@ -10760,10 +10823,11 @@ var createRAGCollection = (options) => {
10760
10823
  const model = input.model ?? options.defaultModel;
10761
10824
  const topK = input.topK ?? defaultTopK;
10762
10825
  const hasReranker = Boolean(input.rerank ?? options.rerank);
10763
- const retrieval = resolveRAGHybridSearchOptions(input.retrieval);
10826
+ const requestedRetrieval = resolveRAGHybridSearchOptions(input.retrieval);
10764
10827
  const hasQueryTransform = Boolean(input.queryTransform ?? options.queryTransform);
10765
- const shouldExpandCandidates = hasReranker || hasQueryTransform || retrieval.mode !== "vector";
10828
+ const shouldExpandCandidates = hasReranker || hasQueryTransform || requestedRetrieval.mode !== "vector";
10766
10829
  const candidateTopK = Math.max(topK, Math.floor(input.candidateTopK ?? (shouldExpandCandidates ? topK * defaultCandidateMultiplier : topK)));
10830
+ const resolvedQueryTransform = resolveRAGQueryTransform(input.queryTransform ?? options.queryTransform);
10767
10831
  const transformed = await applyRAGQueryTransform({
10768
10832
  input: {
10769
10833
  candidateTopK,
@@ -10773,9 +10837,25 @@ var createRAGCollection = (options) => {
10773
10837
  scoreThreshold: input.scoreThreshold,
10774
10838
  topK
10775
10839
  },
10776
- queryTransform: input.queryTransform ?? options.queryTransform
10840
+ queryTransform: resolvedQueryTransform ?? undefined
10777
10841
  });
10778
10842
  const searchQueries = Array.from(new Set([transformed.query, ...transformed.variants ?? []])).filter(Boolean);
10843
+ const resolvedRetrievalStrategy = resolveRAGRetrievalStrategy(input.retrievalStrategy ?? options.retrievalStrategy);
10844
+ const retrievalDecision = resolvedRetrievalStrategy ? await Promise.resolve(resolvedRetrievalStrategy.select({
10845
+ candidateTopK,
10846
+ filter: input.filter,
10847
+ model,
10848
+ query: input.query,
10849
+ retrieval: requestedRetrieval,
10850
+ scoreThreshold: input.scoreThreshold,
10851
+ topK,
10852
+ transformedQuery: transformed.query,
10853
+ variantQueries: searchQueries.slice(1)
10854
+ })) : undefined;
10855
+ const retrieval = retrievalDecision ? {
10856
+ ...requestedRetrieval,
10857
+ ...retrievalDecision
10858
+ } : requestedRetrieval;
10779
10859
  const runVector = shouldRunVectorRetrieval(retrieval.mode);
10780
10860
  const runLexical = shouldRunLexicalRetrieval(retrieval.mode, options.store);
10781
10861
  const lexicalTopK = Math.max(topK, Math.floor(retrieval.lexicalTopK ?? candidateTopK));
@@ -10818,12 +10898,31 @@ var createRAGCollection = (options) => {
10818
10898
  steps.push({
10819
10899
  label: "Expanded query variants",
10820
10900
  metadata: {
10901
+ label: transformed.label ?? resolvedQueryTransform?.providerName ?? null,
10902
+ providerName: resolvedQueryTransform?.providerName ?? null,
10903
+ reason: transformed.reason ?? null,
10821
10904
  transformedQuery: transformed.query,
10822
- variantCount: Math.max(0, searchQueries.length - 1)
10905
+ variantCount: Math.max(0, searchQueries.length - 1),
10906
+ ...transformed.metadata ?? {}
10823
10907
  },
10824
10908
  stage: "query_transform"
10825
10909
  });
10826
10910
  }
10911
+ if (retrievalDecision || requestedRetrieval.mode !== retrieval.mode || requestedRetrieval.lexicalTopK !== retrieval.lexicalTopK) {
10912
+ steps.push({
10913
+ label: retrievalDecision?.label ?? "Selected retrieval strategy",
10914
+ metadata: {
10915
+ applied: Boolean(retrievalDecision),
10916
+ label: retrievalDecision?.label ?? resolvedRetrievalStrategy?.defaultLabel ?? null,
10917
+ providerName: resolvedRetrievalStrategy?.providerName ?? null,
10918
+ reason: retrievalDecision?.reason ?? null,
10919
+ requestedMode: requestedRetrieval.mode,
10920
+ selectedMode: retrieval.mode,
10921
+ ...retrievalDecision?.metadata ?? {}
10922
+ },
10923
+ stage: "routing"
10924
+ });
10925
+ }
10827
10926
  const resultGroups = await Promise.all(searchQueries.map(async (query, queryIndex) => {
10828
10927
  const [vectorResults2, lexicalResults2] = await Promise.all([
10829
10928
  runVector ? embed({
@@ -10982,6 +11081,9 @@ var createRAGCollection = (options) => {
10982
11081
  mode: retrieval.mode,
10983
11082
  diversityStrategy: retrieval.diversityStrategy,
10984
11083
  query: input.query,
11084
+ queryTransformLabel: transformed.label,
11085
+ queryTransformProvider: resolvedQueryTransform?.providerName,
11086
+ queryTransformReason: transformed.reason,
10985
11087
  resultCounts: {
10986
11088
  final: limited.length,
10987
11089
  fused: results.length,
@@ -10989,8 +11091,12 @@ var createRAGCollection = (options) => {
10989
11091
  reranked: diversified.length,
10990
11092
  vector: vectorResults.length
10991
11093
  },
11094
+ requestedMode: requestedRetrieval.mode,
10992
11095
  runLexical,
10993
11096
  runVector,
11097
+ routingLabel: retrievalDecision?.label ?? resolvedRetrievalStrategy?.defaultLabel,
11098
+ routingProvider: resolvedRetrievalStrategy?.providerName,
11099
+ routingReason: retrievalDecision?.reason,
10994
11100
  sourceBalanceStrategy: retrieval.sourceBalanceStrategy,
10995
11101
  steps,
10996
11102
  topK,
@@ -11031,6 +11137,9 @@ var createRAGCollection = (options) => {
11031
11137
  mode: retrieval.mode,
11032
11138
  diversityStrategy: retrieval.diversityStrategy,
11033
11139
  query: input.query,
11140
+ queryTransformLabel: transformed.label,
11141
+ queryTransformProvider: resolvedQueryTransform?.providerName,
11142
+ queryTransformReason: transformed.reason,
11034
11143
  resultCounts: {
11035
11144
  final: filtered.length,
11036
11145
  fused: results.length,
@@ -11038,8 +11147,12 @@ var createRAGCollection = (options) => {
11038
11147
  reranked: diversified.length,
11039
11148
  vector: vectorResults.length
11040
11149
  },
11150
+ requestedMode: requestedRetrieval.mode,
11041
11151
  runLexical,
11042
11152
  runVector,
11153
+ routingLabel: retrievalDecision?.label ?? resolvedRetrievalStrategy?.defaultLabel,
11154
+ routingProvider: resolvedRetrievalStrategy?.providerName,
11155
+ routingReason: retrievalDecision?.reason,
11043
11156
  scoreThreshold,
11044
11157
  sourceBalanceStrategy: retrieval.sourceBalanceStrategy,
11045
11158
  steps,
@@ -18100,6 +18213,64 @@ var ragChat = (config) => {
18100
18213
  // src/ai/rag/htmxConfig.ts
18101
18214
  var createRAGHTMXConfig = (config) => config;
18102
18215
  var createRAGHTMXWorkflowRenderConfig = (config) => config;
18216
+ // src/ai/rag/retrievalStrategies.ts
18217
+ var tokenize4 = (value) => value.toLowerCase().split(/[^a-z0-9]+/i).map((token) => token.trim()).filter((token) => token.length > 0);
18218
+ var hasAnyToken2 = (tokens, values) => values.some((value) => tokens.includes(value));
18219
+ var createHeuristicRAGRetrievalStrategy = (options = {}) => ({
18220
+ defaultLabel: options.defaultLabel ?? "Heuristic retrieval routing",
18221
+ providerName: options.providerName ?? "heuristic_retrieval_strategy",
18222
+ select: (input) => {
18223
+ const scopedSource = typeof input.filter?.source === "string" && input.filter.source.trim().length > 0;
18224
+ const scopedDocumentId = typeof input.filter?.documentId === "string" && input.filter.documentId.trim().length > 0;
18225
+ if ((scopedSource || scopedDocumentId) && input.retrieval.mode !== "vector") {
18226
+ return {
18227
+ label: "Scoped direct route",
18228
+ mode: "vector",
18229
+ reason: scopedDocumentId ? "documentId filter narrows retrieval to one target document" : "source filter narrows retrieval to one source family",
18230
+ metadata: {
18231
+ selector: "scoped_direct_route"
18232
+ }
18233
+ };
18234
+ }
18235
+ const tokens = tokenize4(input.query);
18236
+ const transformedTokens = tokenize4(input.transformedQuery);
18237
+ const combined = Array.from(new Set([...tokens, ...transformedTokens]));
18238
+ const hasVariants = input.variantQueries.length > 0;
18239
+ const supportLexical = hasAnyToken2(combined, ["faq", "policy", "password", "billing"]) && !hasVariants;
18240
+ if (supportLexical) {
18241
+ return {
18242
+ label: "Support lexical route",
18243
+ mode: "lexical",
18244
+ reason: "faq/support phrase matched",
18245
+ metadata: {
18246
+ selector: "support_lexical"
18247
+ }
18248
+ };
18249
+ }
18250
+ const sourceNativeHybrid = hasVariants || hasAnyToken2(combined, [
18251
+ "sheet",
18252
+ "worksheet",
18253
+ "workbook",
18254
+ "spreadsheet",
18255
+ "timestamp",
18256
+ "transcript",
18257
+ "attachment",
18258
+ "archive"
18259
+ ]);
18260
+ if (sourceNativeHybrid && input.retrieval.mode === "vector") {
18261
+ return {
18262
+ label: "Source-native hybrid route",
18263
+ mode: "hybrid",
18264
+ lexicalTopK: Math.max(input.topK, Math.floor(input.retrieval.lexicalTopK ?? input.candidateTopK)),
18265
+ reason: hasVariants ? "query expansion introduced source-native variants" : "source-native terminology benefits from hybrid retrieval",
18266
+ metadata: {
18267
+ selector: "source_native_hybrid"
18268
+ }
18269
+ };
18270
+ }
18271
+ return;
18272
+ }
18273
+ });
18103
18274
  // src/ai/rag/embeddingProviders.ts
18104
18275
  var DEFAULT_OPENAI_BASE_URL = "https://api.openai.com";
18105
18276
  var DEFAULT_GEMINI_BASE_URL = "https://generativelanguage.googleapis.com";
@@ -22361,6 +22532,7 @@ export {
22361
22532
  createMemoryStore,
22362
22533
  createLegacyDocumentExtractor,
22363
22534
  createInMemoryRAGStore,
22535
+ createHeuristicRAGRetrievalStrategy,
22364
22536
  createHeuristicRAGReranker,
22365
22537
  createHeuristicRAGQueryTransform,
22366
22538
  createEmailExtractor,
@@ -22374,56 +22546,21 @@ export {
22374
22546
  buildRAGUpsertInputFromURLs,
22375
22547
  buildRAGUpsertInputFromDocuments,
22376
22548
  buildRAGUpsertInputFromDirectory,
22377
- buildRAGSyncSourcePresentations,
22378
- buildRAGSyncSourcePresentation,
22379
- buildRAGSyncOverviewPresentation,
22380
- buildRAGSourceSummaries,
22381
- buildRAGSourceGroups,
22382
22549
  buildRAGSearchTraceRecord,
22383
22550
  buildRAGSearchTraceDiff,
22384
- buildRAGRetrievalTracePresentation,
22385
22551
  buildRAGRetrievalTraceHistoryTrend,
22386
22552
  buildRAGRetrievalReleaseVerdict,
22387
- buildRAGRetrievalOverviewPresentation,
22388
- buildRAGRetrievalComparisonPresentations,
22389
- buildRAGRetrievalComparisonOverviewPresentation,
22390
22553
  buildRAGRetrievalComparisonDecisionSummary,
22391
- buildRAGRerankerOverviewPresentation,
22392
- buildRAGRerankerComparisonPresentations,
22393
- buildRAGRerankerComparisonOverviewPresentation,
22394
- buildRAGReadinessPresentation,
22395
- buildRAGQualityOverviewPresentation,
22396
22554
  buildRAGLexicalHaystack,
22397
- buildRAGGroundingReferences,
22398
- buildRAGGroundingProviderPresentations,
22399
- buildRAGGroundingProviderOverviewPresentation,
22400
- buildRAGGroundingProviderCaseComparisonPresentations,
22401
- buildRAGGroundingOverviewPresentation,
22402
- buildRAGGroundedAnswer,
22403
22555
  buildRAGEvaluationRunDiff,
22404
22556
  buildRAGEvaluationResponse,
22405
22557
  buildRAGEvaluationLeaderboard,
22406
- buildRAGEvaluationHistoryRows,
22407
- buildRAGEvaluationHistoryPresentation,
22408
- buildRAGEvaluationCaseTracePresentations,
22409
- buildRAGCorpusHealthPresentation,
22410
22558
  buildRAGContext,
22411
- buildRAGComparisonTraceSummaryRows,
22412
- buildRAGComparisonTraceDiffRows,
22413
- buildRAGCitations,
22414
- buildRAGCitationReferenceMap,
22415
- buildRAGAnswerGroundingHistoryRows,
22416
- buildRAGAnswerGroundingHistoryPresentation,
22417
22559
  buildRAGAnswerGroundingEvaluationRunDiff,
22418
22560
  buildRAGAnswerGroundingEvaluationResponse,
22419
22561
  buildRAGAnswerGroundingEvaluationLeaderboard,
22420
- buildRAGAnswerGroundingCaseSnapshotPresentations,
22421
22562
  buildRAGAnswerGroundingCaseDifficultyRunDiff,
22422
22563
  buildRAGAnswerGroundingCaseDifficultyLeaderboard,
22423
- buildRAGAdminJobPresentations,
22424
- buildRAGAdminJobPresentation,
22425
- buildRAGAdminActionPresentations,
22426
- buildRAGAdminActionPresentation,
22427
22564
  applyRAGReranking,
22428
22565
  applyRAGQueryTransform,
22429
22566
  anthropicOCR,
@@ -22432,5 +22569,5 @@ export {
22432
22569
  aiChat
22433
22570
  };
22434
22571
 
22435
- //# debugId=13C12436C949ED5964756E2164756E21
22572
+ //# debugId=2EBD38302AA26EE564756E2164756E21
22436
22573
  //# sourceMappingURL=index.js.map