@mastra/rag 1.0.8-alpha.0 → 1.0.9-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.
@@ -1,4 +1,4 @@
1
1
 
2
- > @mastra/rag@1.0.8-alpha.0 build /home/runner/work/mastra/mastra/packages/rag
2
+ > @mastra/rag@1.0.9-alpha.0 build /home/runner/work/mastra/mastra/packages/rag
3
3
  > tsup --silent --config tsup.config.ts
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,46 @@
1
1
  # @mastra/rag
2
2
 
3
+ ## 1.0.9-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - a741dde: generateVNext plumbing
8
+ - Updated dependencies [0a7f675]
9
+ - Updated dependencies [12cae67]
10
+ - Updated dependencies [5a37d0c]
11
+ - Updated dependencies [4bde0cb]
12
+ - Updated dependencies [1a80071]
13
+ - Updated dependencies [36a3be8]
14
+ - Updated dependencies [361757b]
15
+ - Updated dependencies [2bb9955]
16
+ - Updated dependencies [2454423]
17
+ - Updated dependencies [a44d91e]
18
+ - Updated dependencies [dfb91e9]
19
+ - Updated dependencies [a741dde]
20
+ - Updated dependencies [7cb3fc0]
21
+ - Updated dependencies [195eabb]
22
+ - Updated dependencies [b78b95b]
23
+ - @mastra/core@0.14.0-alpha.4
24
+
25
+ ## 1.0.8
26
+
27
+ ### Patch Changes
28
+
29
+ - 1be6004: Added semantic markdown chunking strategy.
30
+ - Updated dependencies [d5330bf]
31
+ - Updated dependencies [2e74797]
32
+ - Updated dependencies [8388649]
33
+ - Updated dependencies [a239d41]
34
+ - Updated dependencies [dd94a26]
35
+ - Updated dependencies [3ba6772]
36
+ - Updated dependencies [b5cf2a3]
37
+ - Updated dependencies [2fff911]
38
+ - Updated dependencies [b32c50d]
39
+ - Updated dependencies [63449d0]
40
+ - Updated dependencies [121a3f8]
41
+ - Updated dependencies [ec510e7]
42
+ - @mastra/core@0.13.2
43
+
3
44
  ## 1.0.8-alpha.0
4
45
 
5
46
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/keywords.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,KAAK,cAAc,GAAG;IACpB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,GAAG,EAAE,mBAAmB,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAK;IACrB,cAAc,EAAE,oBAAoB,CAAC;IAErC;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE,kBAAkB;IAexC;;;;OAIG;IACH;;;OAGG;IACG,wBAAwB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC;IAwCvE;;;;OAIG;IACH;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;CAKjE"}
1
+ {"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/keywords.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,kBAA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AAwB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IA0CxE;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;CAKlF"}
1
+ {"version":3,"file":"questions.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/questions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEzD,KAAK,eAAe,GAAG;IACrB;;OAEG;IACH,6BAA6B,EAAE,MAAM,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,aAAa;IAC3D,GAAG,EAAE,mBAAmB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAK;IACtB,cAAc,EAAE,qBAAqB,CAAC;IACtC,aAAa,EAAE,OAAO,CAAS;IAE/B;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE,yBAAyB;IAkB/C;;;;OAIG;IACG,wBAAwB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IA4CxE;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;CAKlF"}
@@ -1 +1 @@
1
- {"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/summary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE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EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAoC9D,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,uBAAuB;YAYjB,aAAa;YAoCb,mBAAmB;CA8BlC"}
1
+ {"version":3,"file":"title.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/title.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE3E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,KAAK,YAAY,GAAG;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,qBAAa,cAAe,SAAQ,aAAa;IAC/C,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,OAAO,CAAS;IAChC,KAAK,EAAE,MAAM,CAAK;IAClB,YAAY,EAAE,oBAAoB,CAAC;IACnC,eAAe,EAAE,kBAAkB,CAAC;gBAExB,OAAO,CAAC,EAAE,mBAAmB;IAqBzC;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAoC9D,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,uBAAuB;YAYjB,aAAa;YA4Cb,mBAAmB;CAiClC"}
package/dist/index.cjs CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ var agent = require('@mastra/core/agent');
3
4
  var crypto = require('crypto');
4
5
  var zod = require('zod');
5
6
  var nodeHtmlBetterParser = require('node-html-better-parser');
6
7
  var jsTiktoken = require('js-tiktoken');
7
8
  var big_js = require('big.js');
8
- var agent = require('@mastra/core/agent');
9
9
  var relevance = require('@mastra/core/relevance');
10
10
  var ZeroEntropy = require('zeroentropy');
11
11
  var tools = require('@mastra/core/tools');
@@ -2291,7 +2291,7 @@ var openaiChatChunkSchema = zod.z.union([
2291
2291
  openaiErrorDataSchema
2292
2292
  ]);
2293
2293
  function isReasoningModel(modelId) {
2294
- return modelId.startsWith("o");
2294
+ return modelId.startsWith("o") || modelId.startsWith("gpt-5");
2295
2295
  }
2296
2296
  function isAudioModel(modelId) {
2297
2297
  return modelId.startsWith("gpt-4o-audio-preview");
@@ -3814,7 +3814,7 @@ function isErrorChunk(chunk) {
3814
3814
  return chunk.type === "error";
3815
3815
  }
3816
3816
  function getResponsesModelConfig(modelId) {
3817
- if (modelId.startsWith("o")) {
3817
+ if (modelId.startsWith("o") || modelId.startsWith("gpt-5")) {
3818
3818
  if (modelId.startsWith("o1-mini") || modelId.startsWith("o1-preview")) {
3819
3819
  return {
3820
3820
  isReasoningModel: true,
@@ -4140,64 +4140,65 @@ var TitleExtractor = class extends BaseExtractor {
4140
4140
  for (const [key, nodes] of Object.entries(nodesByDocument)) {
4141
4141
  const titleCandidates = await this.getTitlesCandidates(nodes);
4142
4142
  const combinedTitles = titleCandidates.join(", ");
4143
- const completion = await this.llm.doGenerate({
4144
- inputFormat: "messages",
4145
- mode: { type: "regular" },
4146
- prompt: [
4147
- {
4148
- role: "user",
4149
- content: [
4150
- {
4151
- type: "text",
4152
- text: this.combineTemplate.format({
4153
- context: combinedTitles
4154
- })
4155
- }
4156
- ]
4157
- }
4158
- ]
4159
- });
4160
4143
  let title = "";
4161
- if (typeof completion.text === "string") {
4162
- title = completion.text.trim();
4144
+ if (this.llm.specificationVersion === "v2") {
4145
+ const miniAgent = new agent.Agent({
4146
+ model: this.llm,
4147
+ name: "title-extractor",
4148
+ instructions: "You are a title extractor. You are given a list of nodes and you need to extract the title from the nodes."
4149
+ });
4150
+ const result = await miniAgent.generateVNext(
4151
+ [{ role: "user", content: this.combineTemplate.format({ context: combinedTitles }) }],
4152
+ { format: "mastra" }
4153
+ );
4154
+ title = result.text;
4163
4155
  } else {
4164
- console.warn("Title extraction LLM output was not a string:", completion.text);
4156
+ const miniAgent = new agent.Agent({
4157
+ model: this.llm,
4158
+ name: "title-extractor",
4159
+ instructions: "You are a title extractor. You are given a list of nodes and you need to extract the title from the nodes."
4160
+ });
4161
+ const result = await miniAgent.generate([
4162
+ { role: "user", content: this.combineTemplate.format({ context: combinedTitles }) }
4163
+ ]);
4164
+ title = result.text;
4165
+ }
4166
+ if (!title) {
4167
+ console.warn("Title extraction LLM output returned empty");
4165
4168
  }
4166
4169
  titlesByDocument[key] = title;
4167
4170
  }
4168
4171
  return titlesByDocument;
4169
4172
  }
4170
4173
  async getTitlesCandidates(nodes) {
4174
+ const miniAgent = new agent.Agent({
4175
+ model: this.llm,
4176
+ name: "titles-candidates-extractor",
4177
+ instructions: "You are a titles candidates extractor. You are given a list of nodes and you need to extract the titles candidates from the nodes."
4178
+ });
4171
4179
  const titleJobs = nodes.map(async (node) => {
4172
- const completion = await this.llm.doGenerate({
4173
- inputFormat: "messages",
4174
- mode: { type: "regular" },
4175
- prompt: [
4176
- {
4177
- role: "user",
4178
- content: [
4179
- {
4180
- type: "text",
4181
- text: this.nodeTemplate.format({
4182
- context: node.getContent()
4183
- })
4184
- }
4185
- ]
4186
- }
4187
- ]
4188
- });
4189
- if (typeof completion.text === "string") {
4190
- return completion.text.trim();
4180
+ let completion;
4181
+ if (this.llm.specificationVersion === "v2") {
4182
+ const result = await miniAgent.generateVNext(
4183
+ [{ role: "user", content: this.nodeTemplate.format({ context: node.getContent() }) }],
4184
+ { format: "mastra" }
4185
+ );
4186
+ completion = result.text;
4191
4187
  } else {
4192
- console.warn("Title candidate extraction LLM output was not a string:", completion.text);
4188
+ const result = await miniAgent.generate([
4189
+ { role: "user", content: this.nodeTemplate.format({ context: node.getContent() }) }
4190
+ ]);
4191
+ completion = result.text;
4192
+ }
4193
+ if (!completion) {
4194
+ console.warn("Title candidate extraction LLM output returned empty");
4193
4195
  return "";
4194
4196
  }
4197
+ return completion.trim();
4195
4198
  });
4196
4199
  return await Promise.all(titleJobs);
4197
4200
  }
4198
4201
  };
4199
-
4200
- // src/document/extractors/summary.ts
4201
4202
  var SummaryExtractor = class extends BaseExtractor {
4202
4203
  llm;
4203
4204
  summaries;
@@ -4237,21 +4238,22 @@ var SummaryExtractor = class extends BaseExtractor {
4237
4238
  const prompt = this.promptTemplate.format({
4238
4239
  context
4239
4240
  });
4240
- const result = await this.llm.doGenerate({
4241
- inputFormat: "messages",
4242
- mode: { type: "regular" },
4243
- prompt: [
4244
- {
4245
- role: "user",
4246
- content: [{ type: "text", text: prompt }]
4247
- }
4248
- ]
4241
+ const miniAgent = new agent.Agent({
4242
+ model: this.llm,
4243
+ name: "summary-extractor",
4244
+ instructions: "You are a summary extractor. You are given a node and you need to extract the summary from the node."
4249
4245
  });
4250
4246
  let summary = "";
4251
- if (typeof result.text === "string") {
4252
- summary = result.text.trim();
4247
+ if (this.llm.specificationVersion === "v2") {
4248
+ const result = await miniAgent.generateVNext([{ role: "user", content: prompt }], { format: "mastra" });
4249
+ summary = result.text;
4253
4250
  } else {
4254
- console.warn("Summary extraction LLM output was not a string:", result.text);
4251
+ const result = await miniAgent.generate([{ role: "user", content: prompt }]);
4252
+ summary = result.text;
4253
+ }
4254
+ if (!summary) {
4255
+ console.warn("Summary extraction LLM output returned empty");
4256
+ return "";
4255
4257
  }
4256
4258
  return summary.replace(STRIP_REGEX, "");
4257
4259
  }
@@ -4278,8 +4280,6 @@ var SummaryExtractor = class extends BaseExtractor {
4278
4280
  return metadataList;
4279
4281
  }
4280
4282
  };
4281
-
4282
- // src/document/extractors/questions.ts
4283
4283
  var QuestionsAnsweredExtractor = class extends BaseExtractor {
4284
4284
  llm;
4285
4285
  questions = 5;
@@ -4323,26 +4323,24 @@ var QuestionsAnsweredExtractor = class extends BaseExtractor {
4323
4323
  context: contextStr,
4324
4324
  numQuestions: this.questions.toString()
4325
4325
  });
4326
- const questions = await this.llm.doGenerate({
4327
- inputFormat: "messages",
4328
- mode: { type: "regular" },
4329
- prompt: [
4330
- {
4331
- role: "user",
4332
- content: [{ type: "text", text: prompt }]
4333
- }
4334
- ]
4326
+ const miniAgent = new agent.Agent({
4327
+ model: this.llm,
4328
+ name: "question-extractor",
4329
+ instructions: "You are a question extractor. You are given a node and you need to extract the questions from the node."
4335
4330
  });
4336
- let result = "";
4337
- try {
4338
- if (typeof questions.text === "string") {
4339
- result = questions.text.replace(STRIP_REGEX, "").trim();
4340
- } else {
4341
- console.warn("Question extraction LLM output was not a string:", questions.text);
4342
- }
4343
- } catch (err) {
4344
- console.warn("Question extraction failed:", err);
4331
+ let questionsText = "";
4332
+ if (this.llm.specificationVersion === "v2") {
4333
+ const result2 = await miniAgent.generateVNext([{ role: "user", content: prompt }], { format: "mastra" });
4334
+ questionsText = result2.text;
4335
+ } else {
4336
+ const result2 = await miniAgent.generate([{ role: "user", content: prompt }]);
4337
+ questionsText = result2.text;
4338
+ }
4339
+ if (!questionsText) {
4340
+ console.warn("Question extraction LLM output returned empty");
4341
+ return { questionsThisExcerptCanAnswer: "" };
4345
4342
  }
4343
+ const result = questionsText.replace(STRIP_REGEX, "").trim();
4346
4344
  return {
4347
4345
  questionsThisExcerptCanAnswer: result
4348
4346
  };
@@ -4357,8 +4355,6 @@ var QuestionsAnsweredExtractor = class extends BaseExtractor {
4357
4355
  return results;
4358
4356
  }
4359
4357
  };
4360
-
4361
- // src/document/extractors/keywords.ts
4362
4358
  var KeywordExtractor = class extends BaseExtractor {
4363
4359
  llm;
4364
4360
  keywords = 5;
@@ -4399,33 +4395,43 @@ var KeywordExtractor = class extends BaseExtractor {
4399
4395
  }
4400
4396
  let keywords = "";
4401
4397
  try {
4402
- const completion = await this.llm.doGenerate({
4403
- inputFormat: "messages",
4404
- mode: { type: "regular" },
4405
- prompt: [
4398
+ const miniAgent = new agent.Agent({
4399
+ model: this.llm,
4400
+ name: "keyword-extractor",
4401
+ instructions: "You are a keyword extractor. You are given a node and you need to extract the keywords from the node."
4402
+ });
4403
+ if (this.llm.specificationVersion === "v2") {
4404
+ const result = await miniAgent.generateVNext(
4405
+ [
4406
+ {
4407
+ role: "user",
4408
+ content: this.promptTemplate.format({
4409
+ context: node.getContent(),
4410
+ maxKeywords: this.keywords.toString()
4411
+ })
4412
+ }
4413
+ ],
4414
+ { format: "mastra" }
4415
+ );
4416
+ keywords = result.text;
4417
+ } else {
4418
+ const result = await miniAgent.generate([
4406
4419
  {
4407
4420
  role: "user",
4408
- content: [
4409
- {
4410
- type: "text",
4411
- text: this.promptTemplate.format({
4412
- context: node.getContent(),
4413
- maxKeywords: this.keywords.toString()
4414
- })
4415
- }
4416
- ]
4421
+ content: this.promptTemplate.format({ context: node.getContent(), maxKeywords: this.keywords.toString() })
4417
4422
  }
4418
- ]
4419
- });
4420
- if (typeof completion.text === "string") {
4421
- keywords = completion.text.trim();
4422
- } else {
4423
- console.warn("Keyword extraction LLM output was not a string:", completion.text);
4423
+ ]);
4424
+ keywords = result.text;
4425
+ }
4426
+ if (!keywords) {
4427
+ console.warn("Keyword extraction LLM output returned empty");
4428
+ return { excerptKeywords: "" };
4424
4429
  }
4430
+ return { excerptKeywords: keywords.trim() };
4425
4431
  } catch (err) {
4426
4432
  console.warn("Keyword extraction failed:", err);
4433
+ return { excerptKeywords: "" };
4427
4434
  }
4428
- return { excerptKeywords: keywords };
4429
4435
  }
4430
4436
  /**
4431
4437
  *