@mastra/rag 2.7.0-alpha.2 → 2.7.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.
@@ -3,7 +3,7 @@ name: mastra-rag
3
3
  description: Documentation for @mastra/rag. Use when working with @mastra/rag APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/rag"
6
- version: "2.7.0-alpha.2"
6
+ version: "2.7.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.7.0-alpha.2",
2
+ "version": "2.7.0",
3
3
  "package": "@mastra/rag",
4
4
  "exports": {},
5
5
  "modules": {}
package/dist/index.cjs CHANGED
@@ -6,7 +6,7 @@ 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,7 +17,7 @@ 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));
@@ -778,7 +778,6 @@ function createEventSourceParserStream() {
778
778
  case "retry":
779
779
  const parsedRetry = parseInt(value, 10);
780
780
  if (!isNaN(parsedRetry)) retry = parsedRetry;
781
- break;
782
781
  }
783
782
  }
784
783
  return new TransformStream({
@@ -1277,16 +1276,14 @@ function convertToOpenAIChatMessages({ prompt, useLegacyFunctionCalling = false,
1277
1276
  case "text":
1278
1277
  text += part.text;
1279
1278
  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;
1279
+ case "tool-call": toolCalls.push({
1280
+ id: part.toolCallId,
1281
+ type: "function",
1282
+ function: {
1283
+ name: part.toolName,
1284
+ arguments: JSON.stringify(part.args)
1285
+ }
1286
+ });
1290
1287
  }
1291
1288
  if (useLegacyFunctionCalling) {
1292
1289
  if (toolCalls.length > 1) throw new UnsupportedFunctionalityError({ functionality: "useLegacyFunctionCalling with multiple tool calls in one message" });
@@ -2643,14 +2640,12 @@ function convertToOpenAIResponsesMessages({ prompt, systemMessageMode }) {
2643
2640
  }]
2644
2641
  });
2645
2642
  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;
2643
+ case "tool-call": messages.push({
2644
+ type: "function_call",
2645
+ call_id: part.toolCallId,
2646
+ name: part.toolName,
2647
+ arguments: JSON.stringify(part.args)
2648
+ });
2654
2649
  }
2655
2650
  break;
2656
2651
  case "tool":
@@ -2706,20 +2701,16 @@ function prepareResponsesTools({ mode, strict }) {
2706
2701
  user_location: tool.args.userLocation
2707
2702
  });
2708
2703
  break;
2709
- default:
2710
- toolWarnings.push({
2711
- type: "unsupported-tool",
2712
- tool
2713
- });
2714
- break;
2704
+ default: toolWarnings.push({
2705
+ type: "unsupported-tool",
2706
+ tool
2707
+ });
2715
2708
  }
2716
2709
  break;
2717
- default:
2718
- toolWarnings.push({
2719
- type: "unsupported-tool",
2720
- tool
2721
- });
2722
- break;
2710
+ default: toolWarnings.push({
2711
+ type: "unsupported-tool",
2712
+ tool
2713
+ });
2723
2714
  }
2724
2715
  if (toolChoice == null) return {
2725
2716
  tools: openaiTools2,
@@ -3334,19 +3325,21 @@ var OpenAISpeechModel = class {
3334
3325
  speed,
3335
3326
  instructions
3336
3327
  };
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
- });
3328
+ if (outputFormat) {
3329
+ if ([
3330
+ "mp3",
3331
+ "opus",
3332
+ "aac",
3333
+ "flac",
3334
+ "wav",
3335
+ "pcm"
3336
+ ].includes(outputFormat)) requestBody.response_format = outputFormat;
3337
+ else warnings.push({
3338
+ type: "unsupported-setting",
3339
+ setting: "outputFormat",
3340
+ details: `Unsupported output format: ${outputFormat}. Using mp3 instead.`
3341
+ });
3342
+ }
3350
3343
  if (openAIOptions) {
3351
3344
  const speechModelOptions = {};
3352
3345
  for (const key in speechModelOptions) {
@@ -4950,21 +4943,22 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
4950
4943
  */
4951
4944
  handlePrimitiveValue(value, key, currentChunk, chunks, fullPath) {
4952
4945
  const testValue = { [key]: value };
4953
- if (RecursiveJsonTransformer.jsonSize(testValue) <= this.maxSize) if (RecursiveJsonTransformer.jsonSize({
4954
- ...currentChunk,
4955
- ...testValue
4956
- }) <= this.maxSize) return {
4957
- currentChunk: {
4946
+ if (RecursiveJsonTransformer.jsonSize(testValue) <= this.maxSize) {
4947
+ if (RecursiveJsonTransformer.jsonSize({
4958
4948
  ...currentChunk,
4959
4949
  ...testValue
4960
- },
4961
- chunks
4962
- };
4963
- else return {
4964
- currentChunk: testValue,
4965
- chunks: [...chunks, currentChunk]
4966
- };
4967
- else if (typeof value === "string") {
4950
+ }) <= this.maxSize) return {
4951
+ currentChunk: {
4952
+ ...currentChunk,
4953
+ ...testValue
4954
+ },
4955
+ chunks
4956
+ };
4957
+ else return {
4958
+ currentChunk: testValue,
4959
+ chunks: [...chunks, currentChunk]
4960
+ };
4961
+ } else if (typeof value === "string") {
4968
4962
  const newChunks = this.splitLongString(value).map((chunk) => {
4969
4963
  return this.createChunk(chunk, fullPath);
4970
4964
  }).filter((chunk) => RecursiveJsonTransformer.jsonSize(chunk) <= this.maxSize);
@@ -6898,9 +6892,10 @@ const createGraphRAGTool = (options) => {
6898
6892
  };
6899
6893
  const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
6900
6894
  let isInitialized = false;
6895
+ const inputSchema = options.enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough();
6901
6896
  return (0, _mastra_core_tools.createTool)({
6902
6897
  id: toolId,
6903
- inputSchema: options.enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough(),
6898
+ inputSchema,
6904
6899
  outputSchema: outputSchema$1,
6905
6900
  description: toolDescription,
6906
6901
  execute: async (inputData, context) => {
@@ -7044,10 +7039,13 @@ const createGraphRAGTool = (options) => {
7044
7039
  const createVectorQueryTool = (options) => {
7045
7040
  const { id, description } = options;
7046
7041
  const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
7042
+ const toolId = id || `VectorQuery ${storeName} ${options.indexName} Tool`;
7043
+ const toolDescription = description || defaultVectorQueryDescription();
7044
+ const inputSchema = options.enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough();
7047
7045
  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(),
7046
+ id: toolId,
7047
+ description: toolDescription,
7048
+ inputSchema,
7051
7049
  outputSchema: outputSchema$1,
7052
7050
  execute: async (inputData, context) => {
7053
7051
  const { requestContext, mastra, tracingContext } = context || {};