@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.js CHANGED
@@ -10,14 +10,14 @@ import ZeroEntropy from "zeroentropy";
10
10
  import { createTool } from "@mastra/core/tools";
11
11
  import { embedV1, embedV2, embedV3, embedV4 } from "@mastra/core/vector";
12
12
  import { AgenticRetrieveStreamCommand, BedrockAgentRuntimeClient, RetrieveCommand } from "@aws-sdk/client-bedrock-agent-runtime";
13
- //#region \0rolldown/runtime.js
13
+ // \0rolldown/runtime.js
14
14
  var __create$1 = Object.create;
15
15
  var __defProp$1 = Object.defineProperty;
16
16
  var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
17
17
  var __getOwnPropNames = Object.getOwnPropertyNames;
18
18
  var __getProtoOf = Object.getPrototypeOf;
19
19
  var __hasOwnProp = Object.prototype.hasOwnProperty;
20
- var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
20
+ var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
21
21
  var __copyProps = (to, from, except, desc) => {
22
22
  if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
23
23
  key = keys[i];
@@ -28,17 +28,15 @@ var __copyProps = (to, from, except, desc) => {
28
28
  }
29
29
  return to;
30
30
  };
31
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
31
+ 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", {
32
32
  value: mod,
33
33
  enumerable: true
34
34
  }) : target, mod));
35
- //#endregion
36
- //#region src/document/prompts/format.ts
35
+ // src/document/prompts/format.ts
37
36
  function format(str, params) {
38
37
  return str.replace(/{(\w+)}/g, (_, k) => params[k] ?? "");
39
38
  }
40
- //#endregion
41
- //#region src/document/prompts/base.ts
39
+ // src/document/prompts/base.ts
42
40
  var BasePromptTemplate = class {
43
41
  templateVars = /* @__PURE__ */ new Set();
44
42
  options = {};
@@ -84,8 +82,7 @@ var PromptTemplate = class PromptTemplate extends BasePromptTemplate {
84
82
  return this.#template;
85
83
  }
86
84
  };
87
- //#endregion
88
- //#region src/document/prompts/prompt.ts
85
+ // src/document/prompts/prompt.ts
89
86
  const defaultSummaryPrompt = new PromptTemplate({
90
87
  templateVars: ["context"],
91
88
  template: `Write a summary of the following. Try to use only the information provided. Try to include as many key details as possible.
@@ -130,8 +127,7 @@ const defaultTitleCombinePromptTemplate = new PromptTemplate({
130
127
  Based on the above candidate titles and contents, what is the comprehensive title for this document?
131
128
  Title: `
132
129
  });
133
- //#endregion
134
- //#region src/document/schema/types.ts
130
+ // src/document/schema/types.ts
135
131
  var NodeRelationship = /* @__PURE__ */ ((NodeRelationship2) => {
136
132
  NodeRelationship2["SOURCE"] = "SOURCE";
137
133
  NodeRelationship2["PREVIOUS"] = "PREVIOUS";
@@ -148,8 +144,7 @@ var ObjectType = /* @__PURE__ */ ((ObjectType2) => {
148
144
  ObjectType2["IMAGE_DOCUMENT"] = "IMAGE_DOCUMENT";
149
145
  return ObjectType2;
150
146
  })(ObjectType || {});
151
- //#endregion
152
- //#region src/document/schema/node.ts
147
+ // src/document/schema/node.ts
153
148
  var __create = Object.create;
154
149
  var __defProp = Object.defineProperty;
155
150
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -360,8 +355,7 @@ function createSHA256() {
360
355
  }
361
356
  };
362
357
  }
363
- //#endregion
364
- //#region src/document/extractors/base.ts
358
+ // src/document/extractors/base.ts
365
359
  var BaseExtractor = class {
366
360
  isTextNodeOnly = true;
367
361
  /**
@@ -379,8 +373,7 @@ var BaseExtractor = class {
379
373
  return newNodes;
380
374
  }
381
375
  };
382
- //#endregion
383
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/provider/1.1.3/7d8eaddb7973e5820d04ac18a887c85cc63f173732e3c66432ceefbff819b4ac/node_modules/@ai-sdk/provider/dist/index.mjs
376
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/provider/1.1.3/7d8eaddb7973e5820d04ac18a887c85cc63f173732e3c66432ceefbff819b4ac/node_modules/@ai-sdk/provider/dist/index.mjs
384
377
  var marker = "vercel.ai.error";
385
378
  var symbol = Symbol.for(marker);
386
379
  var _a;
@@ -631,8 +624,7 @@ var UnsupportedFunctionalityError = class extends AISDKError {
631
624
  }
632
625
  };
633
626
  _a14 = symbol14;
634
- //#endregion
635
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/nanoid/5.1.16/f16424b532a5e69aacddcb2977ac17378b6f79695bbd27ead3d90c703848f22f/node_modules/nanoid/non-secure/index.js
627
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@/nanoid/5.1.16/f16424b532a5e69aacddcb2977ac17378b6f79695bbd27ead3d90c703848f22f/node_modules/nanoid/non-secure/index.js
636
628
  let customAlphabet = (alphabet, defaultSize = 21) => {
637
629
  return (size = defaultSize) => {
638
630
  let id = "";
@@ -641,8 +633,7 @@ let customAlphabet = (alphabet, defaultSize = 21) => {
641
633
  return id;
642
634
  };
643
635
  };
644
- //#endregion
645
- //#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
636
+ // ../../../../../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
646
637
  var import_secure_json_parse = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
647
638
  const hasBuffer = typeof Buffer !== "undefined";
648
639
  const suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
@@ -776,7 +767,6 @@ function createEventSourceParserStream() {
776
767
  case "retry":
777
768
  const parsedRetry = parseInt(value, 10);
778
769
  if (!isNaN(parsedRetry)) retry = parsedRetry;
779
- break;
780
770
  }
781
771
  }
782
772
  return new TransformStream({
@@ -1184,8 +1174,7 @@ function convertUint8ArrayToBase64(array) {
1184
1174
  function withoutTrailingSlash(url) {
1185
1175
  return url == null ? void 0 : url.replace(/\/$/, "");
1186
1176
  }
1187
- //#endregion
1188
- //#region ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/openai/1.3.24/9ea9437756f1191484449f4e611ce2befb4ff9a7be92f5dfa8b1970d80a87966/node_modules/@ai-sdk/openai/dist/index.mjs
1177
+ // ../../../../../setup-pnpm/node_modules/.bin/store/v11/links/@ai-sdk/openai/1.3.24/9ea9437756f1191484449f4e611ce2befb4ff9a7be92f5dfa8b1970d80a87966/node_modules/@ai-sdk/openai/dist/index.mjs
1189
1178
  function convertToOpenAIChatMessages({ prompt, useLegacyFunctionCalling = false, systemMessageMode = "system" }) {
1190
1179
  const messages = [];
1191
1180
  const warnings = [];
@@ -1275,16 +1264,14 @@ function convertToOpenAIChatMessages({ prompt, useLegacyFunctionCalling = false,
1275
1264
  case "text":
1276
1265
  text += part.text;
1277
1266
  break;
1278
- case "tool-call":
1279
- toolCalls.push({
1280
- id: part.toolCallId,
1281
- type: "function",
1282
- function: {
1283
- name: part.toolName,
1284
- arguments: JSON.stringify(part.args)
1285
- }
1286
- });
1287
- break;
1267
+ case "tool-call": toolCalls.push({
1268
+ id: part.toolCallId,
1269
+ type: "function",
1270
+ function: {
1271
+ name: part.toolName,
1272
+ arguments: JSON.stringify(part.args)
1273
+ }
1274
+ });
1288
1275
  }
1289
1276
  if (useLegacyFunctionCalling) {
1290
1277
  if (toolCalls.length > 1) throw new UnsupportedFunctionalityError({ functionality: "useLegacyFunctionCalling with multiple tool calls in one message" });
@@ -2641,14 +2628,12 @@ function convertToOpenAIResponsesMessages({ prompt, systemMessageMode }) {
2641
2628
  }]
2642
2629
  });
2643
2630
  break;
2644
- case "tool-call":
2645
- messages.push({
2646
- type: "function_call",
2647
- call_id: part.toolCallId,
2648
- name: part.toolName,
2649
- arguments: JSON.stringify(part.args)
2650
- });
2651
- break;
2631
+ case "tool-call": messages.push({
2632
+ type: "function_call",
2633
+ call_id: part.toolCallId,
2634
+ name: part.toolName,
2635
+ arguments: JSON.stringify(part.args)
2636
+ });
2652
2637
  }
2653
2638
  break;
2654
2639
  case "tool":
@@ -2704,20 +2689,16 @@ function prepareResponsesTools({ mode, strict }) {
2704
2689
  user_location: tool.args.userLocation
2705
2690
  });
2706
2691
  break;
2707
- default:
2708
- toolWarnings.push({
2709
- type: "unsupported-tool",
2710
- tool
2711
- });
2712
- break;
2692
+ default: toolWarnings.push({
2693
+ type: "unsupported-tool",
2694
+ tool
2695
+ });
2713
2696
  }
2714
2697
  break;
2715
- default:
2716
- toolWarnings.push({
2717
- type: "unsupported-tool",
2718
- tool
2719
- });
2720
- break;
2698
+ default: toolWarnings.push({
2699
+ type: "unsupported-tool",
2700
+ tool
2701
+ });
2721
2702
  }
2722
2703
  if (toolChoice == null) return {
2723
2704
  tools: openaiTools2,
@@ -3332,19 +3313,21 @@ var OpenAISpeechModel = class {
3332
3313
  speed,
3333
3314
  instructions
3334
3315
  };
3335
- if (outputFormat) if ([
3336
- "mp3",
3337
- "opus",
3338
- "aac",
3339
- "flac",
3340
- "wav",
3341
- "pcm"
3342
- ].includes(outputFormat)) requestBody.response_format = outputFormat;
3343
- else warnings.push({
3344
- type: "unsupported-setting",
3345
- setting: "outputFormat",
3346
- details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
3347
- });
3316
+ if (outputFormat) {
3317
+ if ([
3318
+ "mp3",
3319
+ "opus",
3320
+ "aac",
3321
+ "flac",
3322
+ "wav",
3323
+ "pcm"
3324
+ ].includes(outputFormat)) requestBody.response_format = outputFormat;
3325
+ else warnings.push({
3326
+ type: "unsupported-setting",
3327
+ setting: "outputFormat",
3328
+ details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
3329
+ });
3330
+ }
3348
3331
  if (openAIOptions) {
3349
3332
  const speechModelOptions = {};
3350
3333
  for (const key in speechModelOptions) {
@@ -3472,12 +3455,10 @@ function createOpenAI(options = {}) {
3472
3455
  return provider;
3473
3456
  }
3474
3457
  createOpenAI({ compatibility: "strict" });
3475
- //#endregion
3476
- //#region src/document/extractors/types.ts
3458
+ // src/document/extractors/types.ts
3477
3459
  const STRIP_REGEX = /(\r\n|\n|\r)/gm;
3478
3460
  const baseLLM = createOpenAI({ apiKey: process.env.OPENAI_API_KEY })("gpt-4o");
3479
- //#endregion
3480
- //#region src/document/extractors/title.ts
3461
+ // src/document/extractors/title.ts
3481
3462
  var TitleExtractor = class extends BaseExtractor {
3482
3463
  llm;
3483
3464
  isTextNodeOnly = false;
@@ -3597,8 +3578,7 @@ var TitleExtractor = class extends BaseExtractor {
3597
3578
  return await Promise.all(titleJobs);
3598
3579
  }
3599
3580
  };
3600
- //#endregion
3601
- //#region src/document/extractors/summary.ts
3581
+ // src/document/extractors/summary.ts
3602
3582
  var SummaryExtractor = class extends BaseExtractor {
3603
3583
  llm;
3604
3584
  summaries;
@@ -3673,8 +3653,7 @@ var SummaryExtractor = class extends BaseExtractor {
3673
3653
  return metadataList;
3674
3654
  }
3675
3655
  };
3676
- //#endregion
3677
- //#region src/document/extractors/questions.ts
3656
+ // src/document/extractors/questions.ts
3678
3657
  var QuestionsAnsweredExtractor = class extends BaseExtractor {
3679
3658
  llm;
3680
3659
  questions = 5;
@@ -3742,8 +3721,7 @@ var QuestionsAnsweredExtractor = class extends BaseExtractor {
3742
3721
  return await Promise.all(nodes.map((node) => this.extractQuestionsFromNode(node)));
3743
3722
  }
3744
3723
  };
3745
- //#endregion
3746
- //#region src/document/extractors/keywords.ts
3724
+ // src/document/extractors/keywords.ts
3747
3725
  var KeywordExtractor = class extends BaseExtractor {
3748
3726
  llm;
3749
3727
  keywords = 5;
@@ -3825,8 +3803,7 @@ var KeywordExtractor = class extends BaseExtractor {
3825
3803
  return await Promise.all(nodes.map((node) => this.extractKeywordsFromNodes(node)));
3826
3804
  }
3827
3805
  };
3828
- //#endregion
3829
- //#region src/document/extractors/schema.ts
3806
+ // src/document/extractors/schema.ts
3830
3807
  var SchemaExtractor = class extends BaseExtractor {
3831
3808
  schema;
3832
3809
  llm;
@@ -3861,8 +3838,7 @@ var SchemaExtractor = class extends BaseExtractor {
3861
3838
  }));
3862
3839
  }
3863
3840
  };
3864
- //#endregion
3865
- //#region src/document/types.ts
3841
+ // src/document/types.ts
3866
3842
  var Language = /* @__PURE__ */ ((Language2) => {
3867
3843
  Language2["CPP"] = "cpp";
3868
3844
  Language2["GO"] = "go";
@@ -3892,8 +3868,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
3892
3868
  Language2["POWERSHELL"] = "powershell";
3893
3869
  return Language2;
3894
3870
  })(Language || {});
3895
- //#endregion
3896
- //#region src/document/transformers/text.ts
3871
+ // src/document/transformers/text.ts
3897
3872
  var TextTransformer = class {
3898
3873
  maxSize;
3899
3874
  overlap;
@@ -4029,8 +4004,7 @@ var TextTransformer = class {
4029
4004
  return docs;
4030
4005
  }
4031
4006
  };
4032
- //#endregion
4033
- //#region src/document/transformers/character.ts
4007
+ // src/document/transformers/character.ts
4034
4008
  function splitTextWithRegex(text, separator, separatorPosition) {
4035
4009
  if (!separator) return text.split("");
4036
4010
  if (!separatorPosition) return text.split(new RegExp(separator)).filter((s) => s !== "");
@@ -4602,8 +4576,7 @@ var RecursiveCharacterTransformer = class RecursiveCharacterTransformer extends
4602
4576
  }
4603
4577
  }
4604
4578
  };
4605
- //#endregion
4606
- //#region src/document/transformers/html.ts
4579
+ // src/document/transformers/html.ts
4607
4580
  const BLOCK_TAGS = /* @__PURE__ */ new Set([
4608
4581
  "address",
4609
4582
  "article",
@@ -4870,8 +4843,7 @@ var HTMLSectionTransformer = class {
4870
4843
  return this.createDocuments(texts, metadatas);
4871
4844
  }
4872
4845
  };
4873
- //#endregion
4874
- //#region src/document/transformers/json.ts
4846
+ // src/document/transformers/json.ts
4875
4847
  var RecursiveJsonTransformer = class RecursiveJsonTransformer {
4876
4848
  maxSize;
4877
4849
  minSize;
@@ -4948,21 +4920,22 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
4948
4920
  */
4949
4921
  handlePrimitiveValue(value, key, currentChunk, chunks, fullPath) {
4950
4922
  const testValue = { [key]: value };
4951
- if (RecursiveJsonTransformer.jsonSize(testValue) <= this.maxSize) if (RecursiveJsonTransformer.jsonSize({
4952
- ...currentChunk,
4953
- ...testValue
4954
- }) <= this.maxSize) return {
4955
- currentChunk: {
4923
+ if (RecursiveJsonTransformer.jsonSize(testValue) <= this.maxSize) {
4924
+ if (RecursiveJsonTransformer.jsonSize({
4956
4925
  ...currentChunk,
4957
4926
  ...testValue
4958
- },
4959
- chunks
4960
- };
4961
- else return {
4962
- currentChunk: testValue,
4963
- chunks: [...chunks, currentChunk]
4964
- };
4965
- else if (typeof value === "string") {
4927
+ }) <= this.maxSize) return {
4928
+ currentChunk: {
4929
+ ...currentChunk,
4930
+ ...testValue
4931
+ },
4932
+ chunks
4933
+ };
4934
+ else return {
4935
+ currentChunk: testValue,
4936
+ chunks: [...chunks, currentChunk]
4937
+ };
4938
+ } else if (typeof value === "string") {
4966
4939
  const newChunks = this.splitLongString(value).map((chunk) => {
4967
4940
  return this.createChunk(chunk, fullPath);
4968
4941
  }).filter((chunk) => RecursiveJsonTransformer.jsonSize(chunk) <= this.maxSize);
@@ -5203,8 +5176,7 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
5203
5176
  });
5204
5177
  }
5205
5178
  };
5206
- //#endregion
5207
- //#region src/document/transformers/latex.ts
5179
+ // src/document/transformers/latex.ts
5208
5180
  var LatexTransformer = class extends RecursiveCharacterTransformer {
5209
5181
  constructor(options = {}) {
5210
5182
  const separators = RecursiveCharacterTransformer.getSeparatorsForLanguage(Language.LATEX);
@@ -5215,8 +5187,7 @@ var LatexTransformer = class extends RecursiveCharacterTransformer {
5215
5187
  });
5216
5188
  }
5217
5189
  };
5218
- //#endregion
5219
- //#region src/document/transformers/markdown.ts
5190
+ // src/document/transformers/markdown.ts
5220
5191
  var MarkdownTransformer = class extends RecursiveCharacterTransformer {
5221
5192
  constructor(options = {}) {
5222
5193
  const separators = RecursiveCharacterTransformer.getSeparatorsForLanguage(Language.MARKDOWN);
@@ -5382,8 +5353,7 @@ var MarkdownHeaderTransformer = class {
5382
5353
  return this.createDocuments(texts, metadatas);
5383
5354
  }
5384
5355
  };
5385
- //#endregion
5386
- //#region src/document/transformers/semantic-markdown.ts
5356
+ // src/document/transformers/semantic-markdown.ts
5387
5357
  var SemanticMarkdownTransformer = class SemanticMarkdownTransformer extends TextTransformer {
5388
5358
  tokenizer;
5389
5359
  joinThreshold;
@@ -5519,8 +5489,7 @@ ${section.content}`;
5519
5489
  });
5520
5490
  }
5521
5491
  };
5522
- //#endregion
5523
- //#region src/document/transformers/sentence.ts
5492
+ // src/document/transformers/sentence.ts
5524
5493
  var SentenceTransformer = class extends TextTransformer {
5525
5494
  minSize;
5526
5495
  maxSize;
@@ -5714,8 +5683,7 @@ var SentenceTransformer = class extends TextTransformer {
5714
5683
  return this.groupSentencesIntoChunks(sentences).filter((chunk) => chunk.trim().length > 0);
5715
5684
  }
5716
5685
  };
5717
- //#endregion
5718
- //#region src/document/transformers/token.ts
5686
+ // src/document/transformers/token.ts
5719
5687
  function splitTextOnTokens({ text, tokenizer }) {
5720
5688
  const splits = [];
5721
5689
  const inputIds = tokenizer.encode(text);
@@ -5791,8 +5759,7 @@ var TokenTransformer = class TokenTransformer extends TextTransformer {
5791
5759
  });
5792
5760
  }
5793
5761
  };
5794
- //#endregion
5795
- //#region src/document/validation.ts
5762
+ // src/document/validation.ts
5796
5763
  const baseChunkOptionsSchema = z.object({
5797
5764
  maxSize: z.number().positive().optional(),
5798
5765
  overlap: z.number().min(0).optional(),
@@ -5871,8 +5838,7 @@ function validateChunkParams(strategy, params) {
5871
5838
  throw new Error(`Invalid parameters for ${strategy} strategy: ${errorMessage}`);
5872
5839
  }
5873
5840
  }
5874
- //#endregion
5875
- //#region src/document/document.ts
5841
+ // src/document/document.ts
5876
5842
  var MDocument = class MDocument {
5877
5843
  chunks;
5878
5844
  type;
@@ -6139,8 +6105,7 @@ var MDocument = class MDocument {
6139
6105
  return this.chunks.map((doc) => doc.metadata);
6140
6106
  }
6141
6107
  };
6142
- //#endregion
6143
- //#region src/rerank/relevance/cohere/index.ts
6108
+ // src/rerank/relevance/cohere/index.ts
6144
6109
  var CohereRelevanceScorer = class {
6145
6110
  model;
6146
6111
  apiKey;
@@ -6169,8 +6134,7 @@ var CohereRelevanceScorer = class {
6169
6134
  return relevanceScore;
6170
6135
  }
6171
6136
  };
6172
- //#endregion
6173
- //#region src/rerank/relevance/mastra-agent/index.ts
6137
+ // src/rerank/relevance/mastra-agent/index.ts
6174
6138
  function parseRelevanceScore(responseText) {
6175
6139
  const trimmed = responseText.trim();
6176
6140
  const score = Number(trimmed);
@@ -6205,8 +6169,7 @@ Always return just the number, no explanation.`,
6205
6169
  return parseRelevanceScore(response.text);
6206
6170
  }
6207
6171
  };
6208
- //#endregion
6209
- //#region src/rerank/relevance/zeroentropy/index.ts
6172
+ // src/rerank/relevance/zeroentropy/index.ts
6210
6173
  var ZeroEntropyRelevanceScorer = class {
6211
6174
  client;
6212
6175
  model;
@@ -6223,8 +6186,7 @@ var ZeroEntropyRelevanceScorer = class {
6223
6186
  })).results[0]?.relevance_score ?? 0;
6224
6187
  }
6225
6188
  };
6226
- //#endregion
6227
- //#region src/rerank/index.ts
6189
+ // src/rerank/index.ts
6228
6190
  const DEFAULT_WEIGHTS = {
6229
6191
  semantic: .4,
6230
6192
  vector: .4,
@@ -6331,8 +6293,7 @@ async function rerank(results, query, model, options) {
6331
6293
  options
6332
6294
  });
6333
6295
  }
6334
- //#endregion
6335
- //#region src/graph-rag/index.ts
6296
+ // src/graph-rag/index.ts
6336
6297
  const GRAPH_RAG_SNAPSHOT_VERSION = 1;
6337
6298
  var GraphRAG = class GraphRAG {
6338
6299
  nodes;
@@ -6548,8 +6509,7 @@ var GraphRAG = class GraphRAG {
6548
6509
  }));
6549
6510
  }
6550
6511
  };
6551
- //#endregion
6552
- //#region src/tools/document-chunker.ts
6512
+ // src/tools/document-chunker.ts
6553
6513
  const DEFAULT_CHUNK_PARAMS = {
6554
6514
  strategy: "recursive",
6555
6515
  maxSize: 512,
@@ -6566,8 +6526,7 @@ const createDocumentChunkerTool = ({ doc, params = DEFAULT_CHUNK_PARAMS }) => {
6566
6526
  }
6567
6527
  });
6568
6528
  };
6569
- //#endregion
6570
- //#region src/utils/vector-search.ts
6529
+ // src/utils/vector-search.ts
6571
6530
  var DatabaseType = /* @__PURE__ */ ((DatabaseType2) => {
6572
6531
  DatabaseType2["Pinecone"] = "pinecone";
6573
6532
  DatabaseType2["PgVector"] = "pgvector";
@@ -6702,8 +6661,7 @@ const databaseSpecificParams = (databaseConfig) => {
6702
6661
  }
6703
6662
  return databaseSpecificParams2;
6704
6663
  };
6705
- //#endregion
6706
- //#region src/utils/default-settings.ts
6664
+ // src/utils/default-settings.ts
6707
6665
  const defaultVectorQueryDescription = () => `Access the knowledge base to find information needed to answer user questions.`;
6708
6666
  const defaultGraphRagDescription = () => `Access and analyze relationships between information in the knowledge base to answer complex questions about connections and patterns.`;
6709
6667
  const queryTextDescription = `The text query to search for in the vector database.
@@ -6736,8 +6694,7 @@ const filterDescription = `JSON-formatted criteria to refine search results.
6736
6694
  - Do NOT use single quotes or unquoted properties
6737
6695
  - IMPORTANT: Always ensure JSON is properly closed with matching brackets
6738
6696
  - Multiple filters can be combined`;
6739
- //#endregion
6740
- //#region src/utils/tool-schemas.ts
6697
+ // src/utils/tool-schemas.ts
6741
6698
  const baseSchema = {
6742
6699
  queryText: z.string().describe(queryTextDescription),
6743
6700
  topK: z.coerce.number().describe(topKDescription)
@@ -6756,8 +6713,7 @@ const filterSchema = z.object({
6756
6713
  ...baseSchema,
6757
6714
  filter: z.coerce.string().describe(filterDescription)
6758
6715
  });
6759
- //#endregion
6760
- //#region src/utils/tool-helpers.ts
6716
+ // src/utils/tool-helpers.ts
6761
6717
  function isValidMastraVector(value) {
6762
6718
  return value !== null && value !== void 0 && typeof value === "object";
6763
6719
  }
@@ -6848,8 +6804,7 @@ function parseFilterValue(filter, logger) {
6848
6804
  }
6849
6805
  return parsedFilter;
6850
6806
  }
6851
- //#endregion
6852
- //#region src/utils/convert-sources.ts
6807
+ // src/utils/convert-sources.ts
6853
6808
  const convertToSources = (results) => {
6854
6809
  return results.map((result) => {
6855
6810
  if ("content" in result) return {
@@ -6875,16 +6830,14 @@ const convertToSources = (results) => {
6875
6830
  };
6876
6831
  });
6877
6832
  };
6878
- //#endregion
6879
- //#region src/tools/types.ts
6833
+ // src/tools/types.ts
6880
6834
  const defaultGraphOptions = {
6881
6835
  dimension: 1536,
6882
6836
  randomWalkSteps: 100,
6883
6837
  restartProb: .15,
6884
6838
  threshold: .7
6885
6839
  };
6886
- //#endregion
6887
- //#region src/tools/graph-rag.ts
6840
+ // src/tools/graph-rag.ts
6888
6841
  const createGraphRAGTool = (options) => {
6889
6842
  const { model, id, description } = options;
6890
6843
  const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
@@ -6896,9 +6849,10 @@ const createGraphRAGTool = (options) => {
6896
6849
  };
6897
6850
  const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
6898
6851
  let isInitialized = false;
6852
+ const inputSchema = options.enableFilter ? filterSchema : z.object(baseSchema).passthrough();
6899
6853
  return createTool({
6900
6854
  id: toolId,
6901
- inputSchema: options.enableFilter ? filterSchema : z.object(baseSchema).passthrough(),
6855
+ inputSchema,
6902
6856
  outputSchema: outputSchema$1,
6903
6857
  description: toolDescription,
6904
6858
  execute: async (inputData, context) => {
@@ -7037,15 +6991,17 @@ const createGraphRAGTool = (options) => {
7037
6991
  }
7038
6992
  });
7039
6993
  };
7040
- //#endregion
7041
- //#region src/tools/vector-query.ts
6994
+ // src/tools/vector-query.ts
7042
6995
  const createVectorQueryTool = (options) => {
7043
6996
  const { id, description } = options;
7044
6997
  const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
6998
+ const toolId = id || `VectorQuery ${storeName} ${options.indexName} Tool`;
6999
+ const toolDescription = description || defaultVectorQueryDescription();
7000
+ const inputSchema = options.enableFilter ? filterSchema : z.object(baseSchema).passthrough();
7045
7001
  return createTool({
7046
- id: id || `VectorQuery ${storeName} ${options.indexName} Tool`,
7047
- description: description || defaultVectorQueryDescription(),
7048
- inputSchema: options.enableFilter ? filterSchema : z.object(baseSchema).passthrough(),
7002
+ id: toolId,
7003
+ description: toolDescription,
7004
+ inputSchema,
7049
7005
  outputSchema: outputSchema$1,
7050
7006
  execute: async (inputData, context) => {
7051
7007
  const { requestContext, mastra, tracingContext } = context || {};
@@ -7154,8 +7110,7 @@ const createVectorQueryTool = (options) => {
7154
7110
  }
7155
7111
  });
7156
7112
  };
7157
- //#endregion
7158
- //#region src/tools/bedrock-knowledge-base.ts
7113
+ // src/tools/bedrock-knowledge-base.ts
7159
7114
  function getSourceUri(location) {
7160
7115
  if (location?.s3Location) return location.s3Location.uri;
7161
7116
  if (location?.webLocation) return location.webLocation.url;
@@ -7244,7 +7199,6 @@ function createBedrockKBTool(options) {
7244
7199
  }
7245
7200
  });
7246
7201
  }
7247
- //#endregion
7248
7202
  export { CohereRelevanceScorer, GraphRAG, Language, MDocument, MastraAgentRelevanceScorer, ZeroEntropyRelevanceScorer, createBedrockKBTool, createDocumentChunkerTool, createGraphRAGTool, createVectorQueryTool, defaultGraphRagDescription, defaultVectorQueryDescription, filterDescription, queryTextDescription, rerank, rerankWithScorer, topKDescription };
7249
7203
 
7250
7204
  //# sourceMappingURL=index.js.map