@mastra/rag 2.7.0-alpha.2 → 2.7.1-alpha.0

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/index.cjs CHANGED
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- //#region \0rolldown/runtime.js
2
+ // \0rolldown/runtime.js
3
3
  var __create$1 = Object.create;
4
4
  var __defProp$1 = Object.defineProperty;
5
5
  var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
6
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
9
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
10
10
  var __copyProps = (to, from, except, desc) => {
11
11
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
12
12
  key = keys[i];
@@ -17,11 +17,10 @@ var __copyProps = (to, from, except, desc) => {
17
17
  }
18
18
  return to;
19
19
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp$1(target, "default", {
21
21
  value: mod,
22
22
  enumerable: true
23
23
  }) : target, mod));
24
- //#endregion
25
24
  let _mastra_core_observability = require("@mastra/core/observability");
26
25
  let _mastra_core_agent = require("@mastra/core/agent");
27
26
  let node_crypto = require("node:crypto");
@@ -35,12 +34,11 @@ zeroentropy = __toESM(zeroentropy, 1);
35
34
  let _mastra_core_tools = require("@mastra/core/tools");
36
35
  let _mastra_core_vector = require("@mastra/core/vector");
37
36
  let _aws_sdk_client_bedrock_agent_runtime = require("@aws-sdk/client-bedrock-agent-runtime");
38
- //#region src/document/prompts/format.ts
37
+ // src/document/prompts/format.ts
39
38
  function format(str, params) {
40
39
  return str.replace(/{(\w+)}/g, (_, k) => params[k] ?? "");
41
40
  }
42
- //#endregion
43
- //#region src/document/prompts/base.ts
41
+ // src/document/prompts/base.ts
44
42
  var BasePromptTemplate = class {
45
43
  templateVars = /* @__PURE__ */ new Set();
46
44
  options = {};
@@ -86,8 +84,7 @@ var PromptTemplate = class PromptTemplate extends BasePromptTemplate {
86
84
  return this.#template;
87
85
  }
88
86
  };
89
- //#endregion
90
- //#region src/document/prompts/prompt.ts
87
+ // src/document/prompts/prompt.ts
91
88
  const defaultSummaryPrompt = new PromptTemplate({
92
89
  templateVars: ["context"],
93
90
  template: `Write a summary of the following. Try to use only the information provided. Try to include as many key details as possible.
@@ -132,8 +129,7 @@ const defaultTitleCombinePromptTemplate = new PromptTemplate({
132
129
  Based on the above candidate titles and contents, what is the comprehensive title for this document?
133
130
  Title: `
134
131
  });
135
- //#endregion
136
- //#region src/document/schema/types.ts
132
+ // src/document/schema/types.ts
137
133
  var NodeRelationship = /* @__PURE__ */ ((NodeRelationship2) => {
138
134
  NodeRelationship2["SOURCE"] = "SOURCE";
139
135
  NodeRelationship2["PREVIOUS"] = "PREVIOUS";
@@ -150,8 +146,7 @@ var ObjectType = /* @__PURE__ */ ((ObjectType2) => {
150
146
  ObjectType2["IMAGE_DOCUMENT"] = "IMAGE_DOCUMENT";
151
147
  return ObjectType2;
152
148
  })(ObjectType || {});
153
- //#endregion
154
- //#region src/document/schema/node.ts
149
+ // src/document/schema/node.ts
155
150
  var __create = Object.create;
156
151
  var __defProp = Object.defineProperty;
157
152
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -362,8 +357,7 @@ function createSHA256() {
362
357
  }
363
358
  };
364
359
  }
365
- //#endregion
366
- //#region src/document/extractors/base.ts
360
+ // src/document/extractors/base.ts
367
361
  var BaseExtractor = class {
368
362
  isTextNodeOnly = true;
369
363
  /**
@@ -381,8 +375,7 @@ var BaseExtractor = class {
381
375
  return newNodes;
382
376
  }
383
377
  };
384
- //#endregion
385
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/provider/1.1.3/7d8eaddb7973e5820d04ac18a887c85cc63f173732e3c66432ceefbff819b4ac/node_modules/@ai-sdk/provider/dist/index.mjs
378
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/provider/1.1.3/7d8eaddb7973e5820d04ac18a887c85cc63f173732e3c66432ceefbff819b4ac/node_modules/@ai-sdk/provider/dist/index.mjs
386
379
  var marker = "vercel.ai.error";
387
380
  var symbol = Symbol.for(marker);
388
381
  var _a;
@@ -633,8 +626,7 @@ var UnsupportedFunctionalityError = class extends AISDKError {
633
626
  }
634
627
  };
635
628
  _a14 = symbol14;
636
- //#endregion
637
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/nanoid/5.1.16/f16424b532a5e69aacddcb2977ac17378b6f79695bbd27ead3d90c703848f22f/node_modules/nanoid/non-secure/index.js
629
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/nanoid/5.1.16/f16424b532a5e69aacddcb2977ac17378b6f79695bbd27ead3d90c703848f22f/node_modules/nanoid/non-secure/index.js
638
630
  let customAlphabet = (alphabet, defaultSize = 21) => {
639
631
  return (size = defaultSize) => {
640
632
  let id = "";
@@ -643,8 +635,7 @@ let customAlphabet = (alphabet, defaultSize = 21) => {
643
635
  return id;
644
636
  };
645
637
  };
646
- //#endregion
647
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/provider-utils/2.2.8/b5ebb650c869d075671e49b164b6e4defe8f9652b8a95fc120ecfeb885936b4f/node_modules/@ai-sdk/provider-utils/dist/index.mjs
638
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/provider-utils/2.2.8/b5ebb650c869d075671e49b164b6e4defe8f9652b8a95fc120ecfeb885936b4f/node_modules/@ai-sdk/provider-utils/dist/index.mjs
648
639
  var import_secure_json_parse = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
649
640
  const hasBuffer = typeof Buffer !== "undefined";
650
641
  const suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
@@ -778,7 +769,6 @@ function createEventSourceParserStream() {
778
769
  case "retry":
779
770
  const parsedRetry = parseInt(value, 10);
780
771
  if (!isNaN(parsedRetry)) retry = parsedRetry;
781
- break;
782
772
  }
783
773
  }
784
774
  return new TransformStream({
@@ -1186,8 +1176,7 @@ function convertUint8ArrayToBase64(array) {
1186
1176
  function withoutTrailingSlash(url) {
1187
1177
  return url == null ? void 0 : url.replace(/\/$/, "");
1188
1178
  }
1189
- //#endregion
1190
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/openai/1.3.24/9ea9437756f1191484449f4e611ce2befb4ff9a7be92f5dfa8b1970d80a87966/node_modules/@ai-sdk/openai/dist/index.mjs
1179
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/openai/1.3.24/9ea9437756f1191484449f4e611ce2befb4ff9a7be92f5dfa8b1970d80a87966/node_modules/@ai-sdk/openai/dist/index.mjs
1191
1180
  function convertToOpenAIChatMessages({ prompt, useLegacyFunctionCalling = false, systemMessageMode = "system" }) {
1192
1181
  const messages = [];
1193
1182
  const warnings = [];
@@ -1277,16 +1266,14 @@ function convertToOpenAIChatMessages({ prompt, useLegacyFunctionCalling = false,
1277
1266
  case "text":
1278
1267
  text += part.text;
1279
1268
  break;
1280
- case "tool-call":
1281
- toolCalls.push({
1282
- id: part.toolCallId,
1283
- type: "function",
1284
- function: {
1285
- name: part.toolName,
1286
- arguments: JSON.stringify(part.args)
1287
- }
1288
- });
1289
- break;
1269
+ case "tool-call": toolCalls.push({
1270
+ id: part.toolCallId,
1271
+ type: "function",
1272
+ function: {
1273
+ name: part.toolName,
1274
+ arguments: JSON.stringify(part.args)
1275
+ }
1276
+ });
1290
1277
  }
1291
1278
  if (useLegacyFunctionCalling) {
1292
1279
  if (toolCalls.length > 1) throw new UnsupportedFunctionalityError({ functionality: "useLegacyFunctionCalling with multiple tool calls in one message" });
@@ -2643,14 +2630,12 @@ function convertToOpenAIResponsesMessages({ prompt, systemMessageMode }) {
2643
2630
  }]
2644
2631
  });
2645
2632
  break;
2646
- case "tool-call":
2647
- messages.push({
2648
- type: "function_call",
2649
- call_id: part.toolCallId,
2650
- name: part.toolName,
2651
- arguments: JSON.stringify(part.args)
2652
- });
2653
- break;
2633
+ case "tool-call": messages.push({
2634
+ type: "function_call",
2635
+ call_id: part.toolCallId,
2636
+ name: part.toolName,
2637
+ arguments: JSON.stringify(part.args)
2638
+ });
2654
2639
  }
2655
2640
  break;
2656
2641
  case "tool":
@@ -2706,20 +2691,16 @@ function prepareResponsesTools({ mode, strict }) {
2706
2691
  user_location: tool.args.userLocation
2707
2692
  });
2708
2693
  break;
2709
- default:
2710
- toolWarnings.push({
2711
- type: "unsupported-tool",
2712
- tool
2713
- });
2714
- break;
2694
+ default: toolWarnings.push({
2695
+ type: "unsupported-tool",
2696
+ tool
2697
+ });
2715
2698
  }
2716
2699
  break;
2717
- default:
2718
- toolWarnings.push({
2719
- type: "unsupported-tool",
2720
- tool
2721
- });
2722
- break;
2700
+ default: toolWarnings.push({
2701
+ type: "unsupported-tool",
2702
+ tool
2703
+ });
2723
2704
  }
2724
2705
  if (toolChoice == null) return {
2725
2706
  tools: openaiTools2,
@@ -3334,19 +3315,21 @@ var OpenAISpeechModel = class {
3334
3315
  speed,
3335
3316
  instructions
3336
3317
  };
3337
- if (outputFormat) if ([
3338
- "mp3",
3339
- "opus",
3340
- "aac",
3341
- "flac",
3342
- "wav",
3343
- "pcm"
3344
- ].includes(outputFormat)) requestBody.response_format = outputFormat;
3345
- else warnings.push({
3346
- type: "unsupported-setting",
3347
- setting: "outputFormat",
3348
- details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
3349
- });
3318
+ if (outputFormat) {
3319
+ if ([
3320
+ "mp3",
3321
+ "opus",
3322
+ "aac",
3323
+ "flac",
3324
+ "wav",
3325
+ "pcm"
3326
+ ].includes(outputFormat)) requestBody.response_format = outputFormat;
3327
+ else warnings.push({
3328
+ type: "unsupported-setting",
3329
+ setting: "outputFormat",
3330
+ details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
3331
+ });
3332
+ }
3350
3333
  if (openAIOptions) {
3351
3334
  const speechModelOptions = {};
3352
3335
  for (const key in speechModelOptions) {
@@ -3474,12 +3457,10 @@ function createOpenAI(options = {}) {
3474
3457
  return provider;
3475
3458
  }
3476
3459
  createOpenAI({ compatibility: "strict" });
3477
- //#endregion
3478
- //#region src/document/extractors/types.ts
3460
+ // src/document/extractors/types.ts
3479
3461
  const STRIP_REGEX = /(\r\n|\n|\r)/gm;
3480
3462
  const baseLLM = createOpenAI({ apiKey: process.env.OPENAI_API_KEY })("gpt-4o");
3481
- //#endregion
3482
- //#region src/document/extractors/title.ts
3463
+ // src/document/extractors/title.ts
3483
3464
  var TitleExtractor = class extends BaseExtractor {
3484
3465
  llm;
3485
3466
  isTextNodeOnly = false;
@@ -3599,8 +3580,7 @@ var TitleExtractor = class extends BaseExtractor {
3599
3580
  return await Promise.all(titleJobs);
3600
3581
  }
3601
3582
  };
3602
- //#endregion
3603
- //#region src/document/extractors/summary.ts
3583
+ // src/document/extractors/summary.ts
3604
3584
  var SummaryExtractor = class extends BaseExtractor {
3605
3585
  llm;
3606
3586
  summaries;
@@ -3675,8 +3655,7 @@ var SummaryExtractor = class extends BaseExtractor {
3675
3655
  return metadataList;
3676
3656
  }
3677
3657
  };
3678
- //#endregion
3679
- //#region src/document/extractors/questions.ts
3658
+ // src/document/extractors/questions.ts
3680
3659
  var QuestionsAnsweredExtractor = class extends BaseExtractor {
3681
3660
  llm;
3682
3661
  questions = 5;
@@ -3744,8 +3723,7 @@ var QuestionsAnsweredExtractor = class extends BaseExtractor {
3744
3723
  return await Promise.all(nodes.map((node) => this.extractQuestionsFromNode(node)));
3745
3724
  }
3746
3725
  };
3747
- //#endregion
3748
- //#region src/document/extractors/keywords.ts
3726
+ // src/document/extractors/keywords.ts
3749
3727
  var KeywordExtractor = class extends BaseExtractor {
3750
3728
  llm;
3751
3729
  keywords = 5;
@@ -3827,8 +3805,7 @@ var KeywordExtractor = class extends BaseExtractor {
3827
3805
  return await Promise.all(nodes.map((node) => this.extractKeywordsFromNodes(node)));
3828
3806
  }
3829
3807
  };
3830
- //#endregion
3831
- //#region src/document/extractors/schema.ts
3808
+ // src/document/extractors/schema.ts
3832
3809
  var SchemaExtractor = class extends BaseExtractor {
3833
3810
  schema;
3834
3811
  llm;
@@ -3863,8 +3840,7 @@ var SchemaExtractor = class extends BaseExtractor {
3863
3840
  }));
3864
3841
  }
3865
3842
  };
3866
- //#endregion
3867
- //#region src/document/types.ts
3843
+ // src/document/types.ts
3868
3844
  var Language = /* @__PURE__ */ ((Language2) => {
3869
3845
  Language2["CPP"] = "cpp";
3870
3846
  Language2["GO"] = "go";
@@ -3894,8 +3870,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
3894
3870
  Language2["POWERSHELL"] = "powershell";
3895
3871
  return Language2;
3896
3872
  })(Language || {});
3897
- //#endregion
3898
- //#region src/document/transformers/text.ts
3873
+ // src/document/transformers/text.ts
3899
3874
  var TextTransformer = class {
3900
3875
  maxSize;
3901
3876
  overlap;
@@ -4031,8 +4006,7 @@ var TextTransformer = class {
4031
4006
  return docs;
4032
4007
  }
4033
4008
  };
4034
- //#endregion
4035
- //#region src/document/transformers/character.ts
4009
+ // src/document/transformers/character.ts
4036
4010
  function splitTextWithRegex(text, separator, separatorPosition) {
4037
4011
  if (!separator) return text.split("");
4038
4012
  if (!separatorPosition) return text.split(new RegExp(separator)).filter((s) => s !== "");
@@ -4604,8 +4578,7 @@ var RecursiveCharacterTransformer = class RecursiveCharacterTransformer extends
4604
4578
  }
4605
4579
  }
4606
4580
  };
4607
- //#endregion
4608
- //#region src/document/transformers/html.ts
4581
+ // src/document/transformers/html.ts
4609
4582
  const BLOCK_TAGS = /* @__PURE__ */ new Set([
4610
4583
  "address",
4611
4584
  "article",
@@ -4872,8 +4845,7 @@ var HTMLSectionTransformer = class {
4872
4845
  return this.createDocuments(texts, metadatas);
4873
4846
  }
4874
4847
  };
4875
- //#endregion
4876
- //#region src/document/transformers/json.ts
4848
+ // src/document/transformers/json.ts
4877
4849
  var RecursiveJsonTransformer = class RecursiveJsonTransformer {
4878
4850
  maxSize;
4879
4851
  minSize;
@@ -4950,21 +4922,22 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
4950
4922
  */
4951
4923
  handlePrimitiveValue(value, key, currentChunk, chunks, fullPath) {
4952
4924
  const testValue = { [key]: value };
4953
- if (RecursiveJsonTransformer.jsonSize(testValue) <= this.maxSize) if (RecursiveJsonTransformer.jsonSize({
4954
- ...currentChunk,
4955
- ...testValue
4956
- }) <= this.maxSize) return {
4957
- currentChunk: {
4925
+ if (RecursiveJsonTransformer.jsonSize(testValue) <= this.maxSize) {
4926
+ if (RecursiveJsonTransformer.jsonSize({
4958
4927
  ...currentChunk,
4959
4928
  ...testValue
4960
- },
4961
- chunks
4962
- };
4963
- else return {
4964
- currentChunk: testValue,
4965
- chunks: [...chunks, currentChunk]
4966
- };
4967
- else if (typeof value === "string") {
4929
+ }) <= this.maxSize) return {
4930
+ currentChunk: {
4931
+ ...currentChunk,
4932
+ ...testValue
4933
+ },
4934
+ chunks
4935
+ };
4936
+ else return {
4937
+ currentChunk: testValue,
4938
+ chunks: [...chunks, currentChunk]
4939
+ };
4940
+ } else if (typeof value === "string") {
4968
4941
  const newChunks = this.splitLongString(value).map((chunk) => {
4969
4942
  return this.createChunk(chunk, fullPath);
4970
4943
  }).filter((chunk) => RecursiveJsonTransformer.jsonSize(chunk) <= this.maxSize);
@@ -5205,8 +5178,7 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
5205
5178
  });
5206
5179
  }
5207
5180
  };
5208
- //#endregion
5209
- //#region src/document/transformers/latex.ts
5181
+ // src/document/transformers/latex.ts
5210
5182
  var LatexTransformer = class extends RecursiveCharacterTransformer {
5211
5183
  constructor(options = {}) {
5212
5184
  const separators = RecursiveCharacterTransformer.getSeparatorsForLanguage(Language.LATEX);
@@ -5217,8 +5189,7 @@ var LatexTransformer = class extends RecursiveCharacterTransformer {
5217
5189
  });
5218
5190
  }
5219
5191
  };
5220
- //#endregion
5221
- //#region src/document/transformers/markdown.ts
5192
+ // src/document/transformers/markdown.ts
5222
5193
  var MarkdownTransformer = class extends RecursiveCharacterTransformer {
5223
5194
  constructor(options = {}) {
5224
5195
  const separators = RecursiveCharacterTransformer.getSeparatorsForLanguage(Language.MARKDOWN);
@@ -5384,8 +5355,7 @@ var MarkdownHeaderTransformer = class {
5384
5355
  return this.createDocuments(texts, metadatas);
5385
5356
  }
5386
5357
  };
5387
- //#endregion
5388
- //#region src/document/transformers/semantic-markdown.ts
5358
+ // src/document/transformers/semantic-markdown.ts
5389
5359
  var SemanticMarkdownTransformer = class SemanticMarkdownTransformer extends TextTransformer {
5390
5360
  tokenizer;
5391
5361
  joinThreshold;
@@ -5521,8 +5491,7 @@ ${section.content}`;
5521
5491
  });
5522
5492
  }
5523
5493
  };
5524
- //#endregion
5525
- //#region src/document/transformers/sentence.ts
5494
+ // src/document/transformers/sentence.ts
5526
5495
  var SentenceTransformer = class extends TextTransformer {
5527
5496
  minSize;
5528
5497
  maxSize;
@@ -5716,8 +5685,7 @@ var SentenceTransformer = class extends TextTransformer {
5716
5685
  return this.groupSentencesIntoChunks(sentences).filter((chunk) => chunk.trim().length > 0);
5717
5686
  }
5718
5687
  };
5719
- //#endregion
5720
- //#region src/document/transformers/token.ts
5688
+ // src/document/transformers/token.ts
5721
5689
  function splitTextOnTokens({ text, tokenizer }) {
5722
5690
  const splits = [];
5723
5691
  const inputIds = tokenizer.encode(text);
@@ -5793,8 +5761,7 @@ var TokenTransformer = class TokenTransformer extends TextTransformer {
5793
5761
  });
5794
5762
  }
5795
5763
  };
5796
- //#endregion
5797
- //#region src/document/validation.ts
5764
+ // src/document/validation.ts
5798
5765
  const baseChunkOptionsSchema = zod.z.object({
5799
5766
  maxSize: zod.z.number().positive().optional(),
5800
5767
  overlap: zod.z.number().min(0).optional(),
@@ -5873,8 +5840,7 @@ function validateChunkParams(strategy, params) {
5873
5840
  throw new Error(`Invalid parameters for ${strategy} strategy: ${errorMessage}`);
5874
5841
  }
5875
5842
  }
5876
- //#endregion
5877
- //#region src/document/document.ts
5843
+ // src/document/document.ts
5878
5844
  var MDocument = class MDocument {
5879
5845
  chunks;
5880
5846
  type;
@@ -6141,8 +6107,7 @@ var MDocument = class MDocument {
6141
6107
  return this.chunks.map((doc) => doc.metadata);
6142
6108
  }
6143
6109
  };
6144
- //#endregion
6145
- //#region src/rerank/relevance/cohere/index.ts
6110
+ // src/rerank/relevance/cohere/index.ts
6146
6111
  var CohereRelevanceScorer = class {
6147
6112
  model;
6148
6113
  apiKey;
@@ -6171,8 +6136,7 @@ var CohereRelevanceScorer = class {
6171
6136
  return relevanceScore;
6172
6137
  }
6173
6138
  };
6174
- //#endregion
6175
- //#region src/rerank/relevance/mastra-agent/index.ts
6139
+ // src/rerank/relevance/mastra-agent/index.ts
6176
6140
  function parseRelevanceScore(responseText) {
6177
6141
  const trimmed = responseText.trim();
6178
6142
  const score = Number(trimmed);
@@ -6207,8 +6171,7 @@ Always return just the number, no explanation.`,
6207
6171
  return parseRelevanceScore(response.text);
6208
6172
  }
6209
6173
  };
6210
- //#endregion
6211
- //#region src/rerank/relevance/zeroentropy/index.ts
6174
+ // src/rerank/relevance/zeroentropy/index.ts
6212
6175
  var ZeroEntropyRelevanceScorer = class {
6213
6176
  client;
6214
6177
  model;
@@ -6225,8 +6188,7 @@ var ZeroEntropyRelevanceScorer = class {
6225
6188
  })).results[0]?.relevance_score ?? 0;
6226
6189
  }
6227
6190
  };
6228
- //#endregion
6229
- //#region src/rerank/index.ts
6191
+ // src/rerank/index.ts
6230
6192
  const DEFAULT_WEIGHTS = {
6231
6193
  semantic: .4,
6232
6194
  vector: .4,
@@ -6333,8 +6295,7 @@ async function rerank(results, query, model, options) {
6333
6295
  options
6334
6296
  });
6335
6297
  }
6336
- //#endregion
6337
- //#region src/graph-rag/index.ts
6298
+ // src/graph-rag/index.ts
6338
6299
  const GRAPH_RAG_SNAPSHOT_VERSION = 1;
6339
6300
  var GraphRAG = class GraphRAG {
6340
6301
  nodes;
@@ -6550,8 +6511,7 @@ var GraphRAG = class GraphRAG {
6550
6511
  }));
6551
6512
  }
6552
6513
  };
6553
- //#endregion
6554
- //#region src/tools/document-chunker.ts
6514
+ // src/tools/document-chunker.ts
6555
6515
  const DEFAULT_CHUNK_PARAMS = {
6556
6516
  strategy: "recursive",
6557
6517
  maxSize: 512,
@@ -6568,8 +6528,7 @@ const createDocumentChunkerTool = ({ doc, params = DEFAULT_CHUNK_PARAMS }) => {
6568
6528
  }
6569
6529
  });
6570
6530
  };
6571
- //#endregion
6572
- //#region src/utils/vector-search.ts
6531
+ // src/utils/vector-search.ts
6573
6532
  var DatabaseType = /* @__PURE__ */ ((DatabaseType2) => {
6574
6533
  DatabaseType2["Pinecone"] = "pinecone";
6575
6534
  DatabaseType2["PgVector"] = "pgvector";
@@ -6704,8 +6663,7 @@ const databaseSpecificParams = (databaseConfig) => {
6704
6663
  }
6705
6664
  return databaseSpecificParams2;
6706
6665
  };
6707
- //#endregion
6708
- //#region src/utils/default-settings.ts
6666
+ // src/utils/default-settings.ts
6709
6667
  const defaultVectorQueryDescription = () => `Access the knowledge base to find information needed to answer user questions.`;
6710
6668
  const defaultGraphRagDescription = () => `Access and analyze relationships between information in the knowledge base to answer complex questions about connections and patterns.`;
6711
6669
  const queryTextDescription = `The text query to search for in the vector database.
@@ -6738,8 +6696,7 @@ const filterDescription = `JSON-formatted criteria to refine search results.
6738
6696
  - Do NOT use single quotes or unquoted properties
6739
6697
  - IMPORTANT: Always ensure JSON is properly closed with matching brackets
6740
6698
  - Multiple filters can be combined`;
6741
- //#endregion
6742
- //#region src/utils/tool-schemas.ts
6699
+ // src/utils/tool-schemas.ts
6743
6700
  const baseSchema = {
6744
6701
  queryText: zod.z.string().describe(queryTextDescription),
6745
6702
  topK: zod.z.coerce.number().describe(topKDescription)
@@ -6758,8 +6715,7 @@ const filterSchema = zod.z.object({
6758
6715
  ...baseSchema,
6759
6716
  filter: zod.z.coerce.string().describe(filterDescription)
6760
6717
  });
6761
- //#endregion
6762
- //#region src/utils/tool-helpers.ts
6718
+ // src/utils/tool-helpers.ts
6763
6719
  function isValidMastraVector(value) {
6764
6720
  return value !== null && value !== void 0 && typeof value === "object";
6765
6721
  }
@@ -6850,8 +6806,7 @@ function parseFilterValue(filter, logger) {
6850
6806
  }
6851
6807
  return parsedFilter;
6852
6808
  }
6853
- //#endregion
6854
- //#region src/utils/convert-sources.ts
6809
+ // src/utils/convert-sources.ts
6855
6810
  const convertToSources = (results) => {
6856
6811
  return results.map((result) => {
6857
6812
  if ("content" in result) return {
@@ -6877,16 +6832,14 @@ const convertToSources = (results) => {
6877
6832
  };
6878
6833
  });
6879
6834
  };
6880
- //#endregion
6881
- //#region src/tools/types.ts
6835
+ // src/tools/types.ts
6882
6836
  const defaultGraphOptions = {
6883
6837
  dimension: 1536,
6884
6838
  randomWalkSteps: 100,
6885
6839
  restartProb: .15,
6886
6840
  threshold: .7
6887
6841
  };
6888
- //#endregion
6889
- //#region src/tools/graph-rag.ts
6842
+ // src/tools/graph-rag.ts
6890
6843
  const createGraphRAGTool = (options) => {
6891
6844
  const { model, id, description } = options;
6892
6845
  const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
@@ -6898,9 +6851,10 @@ const createGraphRAGTool = (options) => {
6898
6851
  };
6899
6852
  const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
6900
6853
  let isInitialized = false;
6854
+ const inputSchema = options.enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough();
6901
6855
  return (0, _mastra_core_tools.createTool)({
6902
6856
  id: toolId,
6903
- inputSchema: options.enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough(),
6857
+ inputSchema,
6904
6858
  outputSchema: outputSchema$1,
6905
6859
  description: toolDescription,
6906
6860
  execute: async (inputData, context) => {
@@ -7039,15 +6993,17 @@ const createGraphRAGTool = (options) => {
7039
6993
  }
7040
6994
  });
7041
6995
  };
7042
- //#endregion
7043
- //#region src/tools/vector-query.ts
6996
+ // src/tools/vector-query.ts
7044
6997
  const createVectorQueryTool = (options) => {
7045
6998
  const { id, description } = options;
7046
6999
  const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
7000
+ const toolId = id || `VectorQuery ${storeName} ${options.indexName} Tool`;
7001
+ const toolDescription = description || defaultVectorQueryDescription();
7002
+ const inputSchema = options.enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough();
7047
7003
  return (0, _mastra_core_tools.createTool)({
7048
- id: id || `VectorQuery ${storeName} ${options.indexName} Tool`,
7049
- description: description || defaultVectorQueryDescription(),
7050
- inputSchema: options.enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough(),
7004
+ id: toolId,
7005
+ description: toolDescription,
7006
+ inputSchema,
7051
7007
  outputSchema: outputSchema$1,
7052
7008
  execute: async (inputData, context) => {
7053
7009
  const { requestContext, mastra, tracingContext } = context || {};
@@ -7156,8 +7112,7 @@ const createVectorQueryTool = (options) => {
7156
7112
  }
7157
7113
  });
7158
7114
  };
7159
- //#endregion
7160
- //#region src/tools/bedrock-knowledge-base.ts
7115
+ // src/tools/bedrock-knowledge-base.ts
7161
7116
  function getSourceUri(location) {
7162
7117
  if (location?.s3Location) return location.s3Location.uri;
7163
7118
  if (location?.webLocation) return location.webLocation.url;
@@ -7246,7 +7201,6 @@ function createBedrockKBTool(options) {
7246
7201
  }
7247
7202
  });
7248
7203
  }
7249
- //#endregion
7250
7204
  exports.CohereRelevanceScorer = CohereRelevanceScorer;
7251
7205
  exports.GraphRAG = GraphRAG;
7252
7206
  exports.Language = Language;