@absolutejs/absolute 0.19.0-beta.509 → 0.19.0-beta.510

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
@@ -2717,15 +2717,8 @@ var detectDomains = (tokens) => {
2717
2717
  var uniqueQueryStrings = (values) => Array.from(new Set(values.map((value) => value.trim()).filter((value) => value.length > 0)));
2718
2718
  var hasExplicitTimestamp = (query) => /\b\d{1,2}:\d{2}\b/.test(query) || /\b\d{1,2}:\d{2}\s*(?:to|-)\s*\d{1,2}:\d{2}\b/i.test(query);
2719
2719
  var hasNamedSourcePhrase = (query) => /\bnamed\s+[a-z0-9]/i.test(query) || /\btitled\s+[a-z0-9]/i.test(query);
2720
- var shouldPreservePrimaryQuery = (query, domains) => {
2721
- if (hasExplicitTimestamp(query) && (domains.includes("audio") || domains.includes("video"))) {
2722
- return true;
2723
- }
2724
- if (hasNamedSourcePhrase(query) && domains.includes("spreadsheet")) {
2725
- return true;
2726
- }
2727
- return false;
2728
- };
2720
+ var isExactMediaTimestampQuery = (query, domains) => hasExplicitTimestamp(query) && (domains.includes("audio") || domains.includes("video"));
2721
+ var isExactNamedSpreadsheetQuery = (query, domains) => hasNamedSourcePhrase(query) && domains.includes("spreadsheet");
2729
2722
  var createHeuristicRAGQueryTransform = (options = {}) => createRAGQueryTransform({
2730
2723
  defaultModel: options.defaultModel ?? "absolute-heuristic-query-transform",
2731
2724
  providerName: options.providerName ?? "absolute_heuristic",
@@ -2769,10 +2762,11 @@ var createHeuristicRAGQueryTransform = (options = {}) => createRAGQueryTransform
2769
2762
  if (mediaTimestampVariant.length > 0) {
2770
2763
  variants.push(mediaTimestampVariant);
2771
2764
  }
2772
- const preservePrimaryQuery = shouldPreservePrimaryQuery(query, domains);
2765
+ const exactMediaTimestampQuery = isExactMediaTimestampQuery(query, domains);
2766
+ const preservePrimaryQuery = exactMediaTimestampQuery || isExactNamedSpreadsheetQuery(query, domains);
2773
2767
  return {
2774
2768
  query: preservePrimaryQuery ? query : rewrittenQuery,
2775
- variants: uniqueQueryStrings(preservePrimaryQuery ? [rewrittenQuery, ...variants] : variants)
2769
+ variants: uniqueQueryStrings(exactMediaTimestampQuery ? [] : preservePrimaryQuery ? [rewrittenQuery, ...variants] : variants)
2776
2770
  };
2777
2771
  }
2778
2772
  });
@@ -4298,6 +4292,7 @@ var prepareRAGDirectoryDocuments = async (input) => prepareRAGDocuments(await lo
4298
4292
 
4299
4293
  // src/ai/rag/collection.ts
4300
4294
  var DEFAULT_TOP_K = 6;
4295
+ var VARIANT_RESULT_WEIGHT = 0.92;
4301
4296
  var mergeQueryResults = (results) => {
4302
4297
  const merged = new Map;
4303
4298
  for (const result of results) {
@@ -4313,6 +4308,16 @@ var mergeQueryResults = (results) => {
4313
4308
  return left.chunkId.localeCompare(right.chunkId);
4314
4309
  });
4315
4310
  };
4311
+ var weightQueryResults = (results, queryIndex) => {
4312
+ if (queryIndex === 0) {
4313
+ return results;
4314
+ }
4315
+ const weight = Math.pow(VARIANT_RESULT_WEIGHT, queryIndex);
4316
+ return results.map((result) => ({
4317
+ ...result,
4318
+ score: result.score * weight
4319
+ }));
4320
+ };
4316
4321
  var shouldRunVectorRetrieval = (mode) => mode === "vector" || mode === "hybrid";
4317
4322
  var shouldRunLexicalRetrieval = (mode, store) => mode === "lexical" || mode === "hybrid" && Boolean(store.queryLexical);
4318
4323
  var createRAGCollection = (options) => {
@@ -4355,7 +4360,7 @@ var createRAGCollection = (options) => {
4355
4360
  signal: input.signal,
4356
4361
  text: input.query
4357
4362
  }, "query") : [];
4358
- const resultGroups = await Promise.all(searchQueries.map(async (query) => {
4363
+ const resultGroups = await Promise.all(searchQueries.map(async (query, queryIndex) => {
4359
4364
  const [vectorResults2, lexicalResults2] = await Promise.all([
4360
4365
  runVector ? embed({
4361
4366
  model,
@@ -4372,7 +4377,10 @@ var createRAGCollection = (options) => {
4372
4377
  topK: lexicalTopK
4373
4378
  }) ?? Promise.resolve([]) : Promise.resolve([])
4374
4379
  ]);
4375
- return { lexicalResults: lexicalResults2, vectorResults: vectorResults2 };
4380
+ return {
4381
+ lexicalResults: weightQueryResults(lexicalResults2, queryIndex),
4382
+ vectorResults: weightQueryResults(vectorResults2, queryIndex)
4383
+ };
4376
4384
  }));
4377
4385
  const vectorResults = mergeQueryResults(resultGroups.flatMap((group) => group.vectorResults));
4378
4386
  const lexicalResults = mergeQueryResults(resultGroups.flatMap((group) => group.lexicalResults));
@@ -10277,5 +10285,5 @@ export {
10277
10285
  aiChat
10278
10286
  };
10279
10287
 
10280
- //# debugId=E4C202F91B1AEC6364756E2164756E21
10288
+ //# debugId=9FFECCD86029913764756E2164756E21
10281
10289
  //# sourceMappingURL=index.js.map