@absolutejs/absolute 0.19.0-beta.527 → 0.19.0-beta.529

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
@@ -4332,7 +4332,7 @@ var createRAGCollection = (options) => {
4332
4332
  validateRAGEmbeddingDimensions(vector, getExpectedDimensions(), context);
4333
4333
  return vector;
4334
4334
  };
4335
- const search = async (input) => {
4335
+ const searchWithTrace = async (input) => {
4336
4336
  const model = input.model ?? options.defaultModel;
4337
4337
  const topK = input.topK ?? defaultTopK;
4338
4338
  const hasReranker = Boolean(input.rerank ?? options.rerank);
@@ -4355,11 +4355,47 @@ var createRAGCollection = (options) => {
4355
4355
  const runVector = shouldRunVectorRetrieval(retrieval.mode);
4356
4356
  const runLexical = shouldRunLexicalRetrieval(retrieval.mode, options.store);
4357
4357
  const lexicalTopK = Math.max(topK, Math.floor(retrieval.lexicalTopK ?? candidateTopK));
4358
+ const steps = [
4359
+ {
4360
+ count: topK,
4361
+ label: "Search input received",
4362
+ metadata: {
4363
+ candidateTopK,
4364
+ hasQueryTransform,
4365
+ hasReranker,
4366
+ mode: retrieval.mode,
4367
+ runLexical,
4368
+ runVector,
4369
+ topK
4370
+ },
4371
+ stage: "input"
4372
+ }
4373
+ ];
4358
4374
  const queryVector = runVector ? await embed({
4359
4375
  model,
4360
4376
  signal: input.signal,
4361
4377
  text: input.query
4362
4378
  }, "query") : [];
4379
+ if (runVector) {
4380
+ steps.push({
4381
+ label: "Embedded primary query",
4382
+ metadata: {
4383
+ dimensions: queryVector.length,
4384
+ query: input.query
4385
+ },
4386
+ stage: "embed"
4387
+ });
4388
+ }
4389
+ if (transformed.query !== input.query || searchQueries.length > 1) {
4390
+ steps.push({
4391
+ label: "Expanded query variants",
4392
+ metadata: {
4393
+ transformedQuery: transformed.query,
4394
+ variantCount: Math.max(0, searchQueries.length - 1)
4395
+ },
4396
+ stage: "query_transform"
4397
+ });
4398
+ }
4363
4399
  const resultGroups = await Promise.all(searchQueries.map(async (query, queryIndex) => {
4364
4400
  const [vectorResults2, lexicalResults2] = await Promise.all([
4365
4401
  runVector ? embed({
@@ -4383,7 +4419,29 @@ var createRAGCollection = (options) => {
4383
4419
  };
4384
4420
  }));
4385
4421
  const vectorResults = mergeQueryResults(resultGroups.flatMap((group) => group.vectorResults));
4422
+ if (runVector) {
4423
+ steps.push({
4424
+ count: vectorResults.length,
4425
+ label: "Collected vector candidates",
4426
+ metadata: {
4427
+ queryCount: searchQueries.length,
4428
+ topK: candidateTopK
4429
+ },
4430
+ stage: "vector_search"
4431
+ });
4432
+ }
4386
4433
  const lexicalResults = mergeQueryResults(resultGroups.flatMap((group) => group.lexicalResults));
4434
+ if (runLexical) {
4435
+ steps.push({
4436
+ count: lexicalResults.length,
4437
+ label: "Collected lexical candidates",
4438
+ metadata: {
4439
+ queryCount: searchQueries.length,
4440
+ topK: lexicalTopK
4441
+ },
4442
+ stage: "lexical_search"
4443
+ });
4444
+ }
4387
4445
  const results = retrieval.mode === "lexical" ? lexicalResults : retrieval.mode === "vector" ? vectorResults : fuseRAGQueryResults({
4388
4446
  fusion: retrieval.fusion,
4389
4447
  fusionConstant: retrieval.fusionConstant,
@@ -4392,6 +4450,14 @@ var createRAGCollection = (options) => {
4392
4450
  vector: vectorResults,
4393
4451
  vectorWeight: retrieval.vectorWeight
4394
4452
  });
4453
+ steps.push({
4454
+ count: results.length,
4455
+ label: retrieval.mode === "hybrid" ? "Fused retrieval candidates" : "Selected retrieval candidates",
4456
+ metadata: {
4457
+ mode: retrieval.mode
4458
+ },
4459
+ stage: "fusion"
4460
+ });
4395
4461
  const rerankInput = {
4396
4462
  candidateTopK,
4397
4463
  filter: input.filter,
@@ -4406,12 +4472,92 @@ var createRAGCollection = (options) => {
4406
4472
  input: rerankInput,
4407
4473
  reranker: input.rerank ?? options.rerank
4408
4474
  });
4475
+ steps.push({
4476
+ count: reranked.length,
4477
+ label: hasReranker ? "Reranked retrieval candidates" : "Skipped reranking and kept retrieval order",
4478
+ metadata: {
4479
+ applied: hasReranker
4480
+ },
4481
+ stage: "rerank"
4482
+ });
4409
4483
  const limited = reranked.slice(0, topK);
4410
4484
  if (typeof input.scoreThreshold !== "number") {
4411
- return limited;
4485
+ steps.push({
4486
+ count: limited.length,
4487
+ label: "Finalized retrieval results",
4488
+ metadata: {
4489
+ appliedScoreThreshold: false
4490
+ },
4491
+ stage: "finalize"
4492
+ });
4493
+ return {
4494
+ results: limited,
4495
+ trace: {
4496
+ candidateTopK,
4497
+ lexicalTopK,
4498
+ mode: retrieval.mode,
4499
+ query: input.query,
4500
+ resultCounts: {
4501
+ final: limited.length,
4502
+ fused: results.length,
4503
+ lexical: lexicalResults.length,
4504
+ reranked: reranked.length,
4505
+ vector: vectorResults.length
4506
+ },
4507
+ runLexical,
4508
+ runVector,
4509
+ steps,
4510
+ topK,
4511
+ transformedQuery: transformed.query,
4512
+ variantQueries: searchQueries.slice(1)
4513
+ }
4514
+ };
4412
4515
  }
4413
4516
  const { scoreThreshold } = input;
4414
- return limited.filter((entry) => entry.score >= scoreThreshold);
4517
+ const filtered = limited.filter((entry) => entry.score >= scoreThreshold);
4518
+ steps.push({
4519
+ count: filtered.length,
4520
+ label: "Applied score threshold",
4521
+ metadata: {
4522
+ scoreThreshold
4523
+ },
4524
+ stage: "score_filter"
4525
+ });
4526
+ steps.push({
4527
+ count: filtered.length,
4528
+ label: "Finalized retrieval results",
4529
+ metadata: {
4530
+ appliedScoreThreshold: true
4531
+ },
4532
+ stage: "finalize"
4533
+ });
4534
+ return {
4535
+ results: filtered,
4536
+ trace: {
4537
+ candidateTopK,
4538
+ lexicalTopK,
4539
+ mode: retrieval.mode,
4540
+ query: input.query,
4541
+ resultCounts: {
4542
+ final: filtered.length,
4543
+ fused: results.length,
4544
+ lexical: lexicalResults.length,
4545
+ reranked: reranked.length,
4546
+ vector: vectorResults.length
4547
+ },
4548
+ runLexical,
4549
+ runVector,
4550
+ scoreThreshold,
4551
+ steps,
4552
+ topK,
4553
+ transformedQuery: transformed.query,
4554
+ variantQueries: searchQueries.slice(1)
4555
+ }
4556
+ };
4557
+ };
4558
+ const search = async (input) => {
4559
+ const result = await searchWithTrace(input);
4560
+ return result.results;
4415
4561
  };
4416
4562
  const ingest = async (input) => {
4417
4563
  const chunks = await Promise.all(input.chunks.map(async (chunk) => {
@@ -4433,6 +4579,7 @@ var createRAGCollection = (options) => {
4433
4579
  clear: typeof options.store.clear === "function" ? () => options.store.clear?.() : undefined,
4434
4580
  getCapabilities: typeof getCapabilities === "function" ? () => getCapabilities() : undefined,
4435
4581
  getStatus: typeof getStatus === "function" ? () => getStatus() : undefined,
4582
+ searchWithTrace,
4436
4583
  search,
4437
4584
  store: options.store,
4438
4585
  ingest
@@ -4547,6 +4694,13 @@ var buildSourceGroupKey = (source) => source.source ?? source.title ?? source.ch
4547
4694
  var buildSourceLabel = (source) => source.source ?? source.title ?? source.chunkId;
4548
4695
  var getContextNumber = (value) => typeof value === "number" && Number.isFinite(value) ? value : undefined;
4549
4696
  var getContextString = (value) => typeof value === "string" && value.trim().length > 0 ? value.trim() : undefined;
4697
+ var isRAGRetrievalTrace = (value) => {
4698
+ if (!value || typeof value !== "object") {
4699
+ return false;
4700
+ }
4701
+ const candidate = value;
4702
+ return typeof candidate.query === "string" && typeof candidate.transformedQuery === "string" && Array.isArray(candidate.variantQueries) && Array.isArray(candidate.steps);
4703
+ };
4550
4704
  var formatTimestampLabel = (value) => {
4551
4705
  const timestamp = typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" ? Date.parse(value) : Number.NaN;
4552
4706
  if (!Number.isFinite(timestamp)) {
@@ -4814,6 +4968,7 @@ var buildRAGRetrievedState = (messages) => {
4814
4968
  retrievalDurationMs: message.retrievalDurationMs,
4815
4969
  retrievalStartedAt: message.retrievalStartedAt,
4816
4970
  retrievedAt: message.retrievedAt,
4971
+ trace: isRAGRetrievalTrace(message.retrievalTrace) ? message.retrievalTrace : undefined,
4817
4972
  sourceGroups: buildRAGSourceGroups(sources),
4818
4973
  sourceSummaries: buildRAGSourceSummaries(sources),
4819
4974
  sources
@@ -6303,16 +6458,17 @@ var buildRAGContextFromQuery = async (config, topK, scoreThreshold, queryText, r
6303
6458
  sources: []
6304
6459
  };
6305
6460
  }
6306
- const queried = await collection.search({
6461
+ const queried = await collection.searchWithTrace({
6307
6462
  model: embeddingModel ?? ragModel,
6308
6463
  query: queryText,
6309
6464
  scoreThreshold,
6310
6465
  topK
6311
6466
  });
6312
- const sources = buildSources2(queried);
6467
+ const sources = buildSources2(queried.results);
6313
6468
  return {
6314
- ragContext: buildRAGContext(queried),
6315
- sources
6469
+ ragContext: buildRAGContext(queried.results),
6470
+ sources,
6471
+ trace: queried.trace
6316
6472
  };
6317
6473
  };
6318
6474
  var ragChat = (config) => {
@@ -6439,7 +6595,7 @@ var ragChat = (config) => {
6439
6595
  conversation.title = message.content.slice(0, TITLE_MAX_LENGTH2);
6440
6596
  }
6441
6597
  };
6442
- const appendAssistantMessage = async (conversationId, messageId, content, sources, usage, model, retrievalStartedAt, retrievedAt, retrievalDurationMs) => {
6598
+ const appendAssistantMessage = async (conversationId, messageId, content, sources, usage, model, retrievalStartedAt, retrievedAt, retrievalDurationMs, retrievalTrace) => {
6443
6599
  const conv = await store.get(conversationId);
6444
6600
  if (!conv) {
6445
6601
  return;
@@ -6452,6 +6608,7 @@ var ragChat = (config) => {
6452
6608
  role: "assistant",
6453
6609
  retrievalDurationMs,
6454
6610
  retrievalStartedAt,
6611
+ retrievalTrace,
6455
6612
  retrievedAt,
6456
6613
  sources,
6457
6614
  timestamp: Date.now(),
@@ -6481,7 +6638,7 @@ var ragChat = (config) => {
6481
6638
  type: "branched"
6482
6639
  }));
6483
6640
  };
6484
- const handleRAGRetrieved = (ws, conversationId, messageId, sources, retrievalStartedAt, retrievedAt, retrievalDurationMs) => {
6641
+ const handleRAGRetrieved = (ws, conversationId, messageId, sources, retrievalStartedAt, retrievedAt, retrievalDurationMs, trace) => {
6485
6642
  ws.send(JSON.stringify({
6486
6643
  conversationId,
6487
6644
  messageId,
@@ -6489,6 +6646,7 @@ var ragChat = (config) => {
6489
6646
  retrievalStartedAt,
6490
6647
  retrievedAt,
6491
6648
  sources,
6649
+ trace,
6492
6650
  type: "rag_retrieved"
6493
6651
  }));
6494
6652
  };
@@ -6525,10 +6683,10 @@ var ragChat = (config) => {
6525
6683
  const rag = await buildRAGContextFromQuery(config, topK, scoreThreshold, content, ragModel, config.embedding, config.embeddingModel);
6526
6684
  const controller = new AbortController;
6527
6685
  abortControllers.set(conversationId, controller);
6528
- const { ragContext, sources } = rag;
6686
+ const { ragContext, sources, trace } = rag;
6529
6687
  const retrievedAt = Date.now();
6530
6688
  const retrievalDurationMs = retrievedAt - retrievalStartedAt;
6531
- handleRAGRetrieved(ws, conversationId, assistantMessageId, sources, retrievalStartedAt, retrievedAt, retrievalDurationMs);
6689
+ handleRAGRetrieved(ws, conversationId, assistantMessageId, sources, retrievalStartedAt, retrievedAt, retrievalDurationMs, trace);
6532
6690
  await streamAI(ws, conversationId, assistantMessageId, {
6533
6691
  completeMeta: includeCompleteSources ? { sources } : undefined,
6534
6692
  maxTurns: config.maxTurns,
@@ -6543,7 +6701,7 @@ var ragChat = (config) => {
6543
6701
  thinking: resolveThinking2(config, providerName, model),
6544
6702
  tools: resolveTools2(config, providerName, model),
6545
6703
  onComplete: async (fullResponse, usage) => {
6546
- await appendAssistantMessage(conversationId, assistantMessageId, fullResponse, sources, usage, model, retrievalStartedAt, retrievedAt, retrievalDurationMs);
6704
+ await appendAssistantMessage(conversationId, assistantMessageId, fullResponse, sources, usage, model, retrievalStartedAt, retrievedAt, retrievalDurationMs, trace);
6547
6705
  abortControllers.delete(conversationId);
6548
6706
  config.onComplete?.(conversationId, fullResponse, usage, sources);
6549
6707
  }
@@ -6747,13 +6905,22 @@ var ragChat = (config) => {
6747
6905
  if (!collection) {
6748
6906
  return { error: "RAG collection is not configured", ok: false };
6749
6907
  }
6750
- const results = await collection.search({
6908
+ const input = {
6751
6909
  filter: getObjectProperty(body, "filter"),
6752
6910
  model: getStringProperty(body, "model"),
6753
6911
  query,
6754
6912
  scoreThreshold: typeof body.scoreThreshold === "number" ? body.scoreThreshold : undefined,
6755
6913
  topK: typeof body.topK === "number" ? body.topK : undefined
6756
- });
6914
+ };
6915
+ if (getBooleanProperty(body, "includeTrace") === true) {
6916
+ const result = await collection.searchWithTrace(input);
6917
+ return {
6918
+ ok: true,
6919
+ results: buildSources2(result.results),
6920
+ trace: result.trace
6921
+ };
6922
+ }
6923
+ const results = await collection.search(input);
6757
6924
  return { ok: true, results: buildSources2(results) };
6758
6925
  };
6759
6926
  const summarizeDocuments = (documents) => ({
@@ -6897,14 +7064,14 @@ var ragChat = (config) => {
6897
7064
  };
6898
7065
  };
6899
7066
  const buildReadiness = () => ({
6900
- embeddingConfigured: Boolean(config.embedding),
6901
- embeddingModel: config.embeddingModel,
7067
+ embeddingConfigured: Boolean(config.embedding ?? config.collection),
7068
+ embeddingModel: config.embeddingModel ?? (config.collection ? "collection-managed embeddings" : undefined),
6902
7069
  extractorNames: (extractors ?? []).map((extractor) => extractor.name),
6903
7070
  extractorsConfigured: (extractors?.length ?? 0) > 0,
6904
7071
  indexManagerConfigured: Boolean(indexManager),
6905
7072
  model: typeof config.model === "string" ? config.model : undefined,
6906
7073
  providerConfigured: typeof config.provider === "function",
6907
- providerName: typeof config.provider === "function" && config.provider.name ? config.provider.name : undefined,
7074
+ providerName: typeof config.provider === "function" ? config.readinessProviderName : undefined,
6908
7075
  rerankerConfigured: Boolean(config.rerank ?? config.collection)
6909
7076
  });
6910
7077
  const buildAdminCapabilities = () => ({
@@ -10933,8 +11100,12 @@ var createRAGClient = (options) => {
10933
11100
  return parseJson(response);
10934
11101
  },
10935
11102
  async search(input) {
11103
+ const result = await this.searchDetailed(input);
11104
+ return result.results;
11105
+ },
11106
+ async searchDetailed(input) {
10936
11107
  const response = await fetchImpl(`${basePath}/search`, {
10937
- body: JSON.stringify(input),
11108
+ body: JSON.stringify({ ...input, includeTrace: true }),
10938
11109
  headers: jsonHeaders,
10939
11110
  method: "POST"
10940
11111
  });
@@ -10945,7 +11116,10 @@ var createRAGClient = (options) => {
10945
11116
  if (!payload.ok) {
10946
11117
  throw new Error(payload.error ?? "RAG search failed");
10947
11118
  }
10948
- return payload.results ?? [];
11119
+ return {
11120
+ results: payload.results ?? [],
11121
+ trace: payload.trace
11122
+ };
10949
11123
  },
10950
11124
  async status() {
10951
11125
  const response = await fetchImpl(`${basePath}/status`);
@@ -11107,5 +11281,5 @@ export {
11107
11281
  aiChat
11108
11282
  };
11109
11283
 
11110
- //# debugId=1F634E647D260F1364756E2164756E21
11284
+ //# debugId=3C016671455736C564756E2164756E21
11111
11285
  //# sourceMappingURL=index.js.map