@mastra/rag 2.7.0 → 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,7 +10,7 @@ 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;
@@ -32,13 +32,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__
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*:/;
@@ -1183,8 +1174,7 @@ function convertUint8ArrayToBase64(array) {
1183
1174
  function withoutTrailingSlash(url) {
1184
1175
  return url == null ? void 0 : url.replace(/\/$/, "");
1185
1176
  }
1186
- //#endregion
1187
- //#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
1188
1178
  function convertToOpenAIChatMessages({ prompt, useLegacyFunctionCalling = false, systemMessageMode = "system" }) {
1189
1179
  const messages = [];
1190
1180
  const warnings = [];
@@ -3465,12 +3455,10 @@ function createOpenAI(options = {}) {
3465
3455
  return provider;
3466
3456
  }
3467
3457
  createOpenAI({ compatibility: "strict" });
3468
- //#endregion
3469
- //#region src/document/extractors/types.ts
3458
+ // src/document/extractors/types.ts
3470
3459
  const STRIP_REGEX = /(\r\n|\n|\r)/gm;
3471
3460
  const baseLLM = createOpenAI({ apiKey: process.env.OPENAI_API_KEY })("gpt-4o");
3472
- //#endregion
3473
- //#region src/document/extractors/title.ts
3461
+ // src/document/extractors/title.ts
3474
3462
  var TitleExtractor = class extends BaseExtractor {
3475
3463
  llm;
3476
3464
  isTextNodeOnly = false;
@@ -3590,8 +3578,7 @@ var TitleExtractor = class extends BaseExtractor {
3590
3578
  return await Promise.all(titleJobs);
3591
3579
  }
3592
3580
  };
3593
- //#endregion
3594
- //#region src/document/extractors/summary.ts
3581
+ // src/document/extractors/summary.ts
3595
3582
  var SummaryExtractor = class extends BaseExtractor {
3596
3583
  llm;
3597
3584
  summaries;
@@ -3666,8 +3653,7 @@ var SummaryExtractor = class extends BaseExtractor {
3666
3653
  return metadataList;
3667
3654
  }
3668
3655
  };
3669
- //#endregion
3670
- //#region src/document/extractors/questions.ts
3656
+ // src/document/extractors/questions.ts
3671
3657
  var QuestionsAnsweredExtractor = class extends BaseExtractor {
3672
3658
  llm;
3673
3659
  questions = 5;
@@ -3735,8 +3721,7 @@ var QuestionsAnsweredExtractor = class extends BaseExtractor {
3735
3721
  return await Promise.all(nodes.map((node) => this.extractQuestionsFromNode(node)));
3736
3722
  }
3737
3723
  };
3738
- //#endregion
3739
- //#region src/document/extractors/keywords.ts
3724
+ // src/document/extractors/keywords.ts
3740
3725
  var KeywordExtractor = class extends BaseExtractor {
3741
3726
  llm;
3742
3727
  keywords = 5;
@@ -3818,8 +3803,7 @@ var KeywordExtractor = class extends BaseExtractor {
3818
3803
  return await Promise.all(nodes.map((node) => this.extractKeywordsFromNodes(node)));
3819
3804
  }
3820
3805
  };
3821
- //#endregion
3822
- //#region src/document/extractors/schema.ts
3806
+ // src/document/extractors/schema.ts
3823
3807
  var SchemaExtractor = class extends BaseExtractor {
3824
3808
  schema;
3825
3809
  llm;
@@ -3854,8 +3838,7 @@ var SchemaExtractor = class extends BaseExtractor {
3854
3838
  }));
3855
3839
  }
3856
3840
  };
3857
- //#endregion
3858
- //#region src/document/types.ts
3841
+ // src/document/types.ts
3859
3842
  var Language = /* @__PURE__ */ ((Language2) => {
3860
3843
  Language2["CPP"] = "cpp";
3861
3844
  Language2["GO"] = "go";
@@ -3885,8 +3868,7 @@ var Language = /* @__PURE__ */ ((Language2) => {
3885
3868
  Language2["POWERSHELL"] = "powershell";
3886
3869
  return Language2;
3887
3870
  })(Language || {});
3888
- //#endregion
3889
- //#region src/document/transformers/text.ts
3871
+ // src/document/transformers/text.ts
3890
3872
  var TextTransformer = class {
3891
3873
  maxSize;
3892
3874
  overlap;
@@ -4022,8 +4004,7 @@ var TextTransformer = class {
4022
4004
  return docs;
4023
4005
  }
4024
4006
  };
4025
- //#endregion
4026
- //#region src/document/transformers/character.ts
4007
+ // src/document/transformers/character.ts
4027
4008
  function splitTextWithRegex(text, separator, separatorPosition) {
4028
4009
  if (!separator) return text.split("");
4029
4010
  if (!separatorPosition) return text.split(new RegExp(separator)).filter((s) => s !== "");
@@ -4595,8 +4576,7 @@ var RecursiveCharacterTransformer = class RecursiveCharacterTransformer extends
4595
4576
  }
4596
4577
  }
4597
4578
  };
4598
- //#endregion
4599
- //#region src/document/transformers/html.ts
4579
+ // src/document/transformers/html.ts
4600
4580
  const BLOCK_TAGS = /* @__PURE__ */ new Set([
4601
4581
  "address",
4602
4582
  "article",
@@ -4863,8 +4843,7 @@ var HTMLSectionTransformer = class {
4863
4843
  return this.createDocuments(texts, metadatas);
4864
4844
  }
4865
4845
  };
4866
- //#endregion
4867
- //#region src/document/transformers/json.ts
4846
+ // src/document/transformers/json.ts
4868
4847
  var RecursiveJsonTransformer = class RecursiveJsonTransformer {
4869
4848
  maxSize;
4870
4849
  minSize;
@@ -5197,8 +5176,7 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
5197
5176
  });
5198
5177
  }
5199
5178
  };
5200
- //#endregion
5201
- //#region src/document/transformers/latex.ts
5179
+ // src/document/transformers/latex.ts
5202
5180
  var LatexTransformer = class extends RecursiveCharacterTransformer {
5203
5181
  constructor(options = {}) {
5204
5182
  const separators = RecursiveCharacterTransformer.getSeparatorsForLanguage(Language.LATEX);
@@ -5209,8 +5187,7 @@ var LatexTransformer = class extends RecursiveCharacterTransformer {
5209
5187
  });
5210
5188
  }
5211
5189
  };
5212
- //#endregion
5213
- //#region src/document/transformers/markdown.ts
5190
+ // src/document/transformers/markdown.ts
5214
5191
  var MarkdownTransformer = class extends RecursiveCharacterTransformer {
5215
5192
  constructor(options = {}) {
5216
5193
  const separators = RecursiveCharacterTransformer.getSeparatorsForLanguage(Language.MARKDOWN);
@@ -5376,8 +5353,7 @@ var MarkdownHeaderTransformer = class {
5376
5353
  return this.createDocuments(texts, metadatas);
5377
5354
  }
5378
5355
  };
5379
- //#endregion
5380
- //#region src/document/transformers/semantic-markdown.ts
5356
+ // src/document/transformers/semantic-markdown.ts
5381
5357
  var SemanticMarkdownTransformer = class SemanticMarkdownTransformer extends TextTransformer {
5382
5358
  tokenizer;
5383
5359
  joinThreshold;
@@ -5513,8 +5489,7 @@ ${section.content}`;
5513
5489
  });
5514
5490
  }
5515
5491
  };
5516
- //#endregion
5517
- //#region src/document/transformers/sentence.ts
5492
+ // src/document/transformers/sentence.ts
5518
5493
  var SentenceTransformer = class extends TextTransformer {
5519
5494
  minSize;
5520
5495
  maxSize;
@@ -5708,8 +5683,7 @@ var SentenceTransformer = class extends TextTransformer {
5708
5683
  return this.groupSentencesIntoChunks(sentences).filter((chunk) => chunk.trim().length > 0);
5709
5684
  }
5710
5685
  };
5711
- //#endregion
5712
- //#region src/document/transformers/token.ts
5686
+ // src/document/transformers/token.ts
5713
5687
  function splitTextOnTokens({ text, tokenizer }) {
5714
5688
  const splits = [];
5715
5689
  const inputIds = tokenizer.encode(text);
@@ -5785,8 +5759,7 @@ var TokenTransformer = class TokenTransformer extends TextTransformer {
5785
5759
  });
5786
5760
  }
5787
5761
  };
5788
- //#endregion
5789
- //#region src/document/validation.ts
5762
+ // src/document/validation.ts
5790
5763
  const baseChunkOptionsSchema = z.object({
5791
5764
  maxSize: z.number().positive().optional(),
5792
5765
  overlap: z.number().min(0).optional(),
@@ -5865,8 +5838,7 @@ function validateChunkParams(strategy, params) {
5865
5838
  throw new Error(`Invalid parameters for ${strategy} strategy: ${errorMessage}`);
5866
5839
  }
5867
5840
  }
5868
- //#endregion
5869
- //#region src/document/document.ts
5841
+ // src/document/document.ts
5870
5842
  var MDocument = class MDocument {
5871
5843
  chunks;
5872
5844
  type;
@@ -6133,8 +6105,7 @@ var MDocument = class MDocument {
6133
6105
  return this.chunks.map((doc) => doc.metadata);
6134
6106
  }
6135
6107
  };
6136
- //#endregion
6137
- //#region src/rerank/relevance/cohere/index.ts
6108
+ // src/rerank/relevance/cohere/index.ts
6138
6109
  var CohereRelevanceScorer = class {
6139
6110
  model;
6140
6111
  apiKey;
@@ -6163,8 +6134,7 @@ var CohereRelevanceScorer = class {
6163
6134
  return relevanceScore;
6164
6135
  }
6165
6136
  };
6166
- //#endregion
6167
- //#region src/rerank/relevance/mastra-agent/index.ts
6137
+ // src/rerank/relevance/mastra-agent/index.ts
6168
6138
  function parseRelevanceScore(responseText) {
6169
6139
  const trimmed = responseText.trim();
6170
6140
  const score = Number(trimmed);
@@ -6199,8 +6169,7 @@ Always return just the number, no explanation.`,
6199
6169
  return parseRelevanceScore(response.text);
6200
6170
  }
6201
6171
  };
6202
- //#endregion
6203
- //#region src/rerank/relevance/zeroentropy/index.ts
6172
+ // src/rerank/relevance/zeroentropy/index.ts
6204
6173
  var ZeroEntropyRelevanceScorer = class {
6205
6174
  client;
6206
6175
  model;
@@ -6217,8 +6186,7 @@ var ZeroEntropyRelevanceScorer = class {
6217
6186
  })).results[0]?.relevance_score ?? 0;
6218
6187
  }
6219
6188
  };
6220
- //#endregion
6221
- //#region src/rerank/index.ts
6189
+ // src/rerank/index.ts
6222
6190
  const DEFAULT_WEIGHTS = {
6223
6191
  semantic: .4,
6224
6192
  vector: .4,
@@ -6325,8 +6293,7 @@ async function rerank(results, query, model, options) {
6325
6293
  options
6326
6294
  });
6327
6295
  }
6328
- //#endregion
6329
- //#region src/graph-rag/index.ts
6296
+ // src/graph-rag/index.ts
6330
6297
  const GRAPH_RAG_SNAPSHOT_VERSION = 1;
6331
6298
  var GraphRAG = class GraphRAG {
6332
6299
  nodes;
@@ -6542,8 +6509,7 @@ var GraphRAG = class GraphRAG {
6542
6509
  }));
6543
6510
  }
6544
6511
  };
6545
- //#endregion
6546
- //#region src/tools/document-chunker.ts
6512
+ // src/tools/document-chunker.ts
6547
6513
  const DEFAULT_CHUNK_PARAMS = {
6548
6514
  strategy: "recursive",
6549
6515
  maxSize: 512,
@@ -6560,8 +6526,7 @@ const createDocumentChunkerTool = ({ doc, params = DEFAULT_CHUNK_PARAMS }) => {
6560
6526
  }
6561
6527
  });
6562
6528
  };
6563
- //#endregion
6564
- //#region src/utils/vector-search.ts
6529
+ // src/utils/vector-search.ts
6565
6530
  var DatabaseType = /* @__PURE__ */ ((DatabaseType2) => {
6566
6531
  DatabaseType2["Pinecone"] = "pinecone";
6567
6532
  DatabaseType2["PgVector"] = "pgvector";
@@ -6696,8 +6661,7 @@ const databaseSpecificParams = (databaseConfig) => {
6696
6661
  }
6697
6662
  return databaseSpecificParams2;
6698
6663
  };
6699
- //#endregion
6700
- //#region src/utils/default-settings.ts
6664
+ // src/utils/default-settings.ts
6701
6665
  const defaultVectorQueryDescription = () => `Access the knowledge base to find information needed to answer user questions.`;
6702
6666
  const defaultGraphRagDescription = () => `Access and analyze relationships between information in the knowledge base to answer complex questions about connections and patterns.`;
6703
6667
  const queryTextDescription = `The text query to search for in the vector database.
@@ -6730,8 +6694,7 @@ const filterDescription = `JSON-formatted criteria to refine search results.
6730
6694
  - Do NOT use single quotes or unquoted properties
6731
6695
  - IMPORTANT: Always ensure JSON is properly closed with matching brackets
6732
6696
  - Multiple filters can be combined`;
6733
- //#endregion
6734
- //#region src/utils/tool-schemas.ts
6697
+ // src/utils/tool-schemas.ts
6735
6698
  const baseSchema = {
6736
6699
  queryText: z.string().describe(queryTextDescription),
6737
6700
  topK: z.coerce.number().describe(topKDescription)
@@ -6750,8 +6713,7 @@ const filterSchema = z.object({
6750
6713
  ...baseSchema,
6751
6714
  filter: z.coerce.string().describe(filterDescription)
6752
6715
  });
6753
- //#endregion
6754
- //#region src/utils/tool-helpers.ts
6716
+ // src/utils/tool-helpers.ts
6755
6717
  function isValidMastraVector(value) {
6756
6718
  return value !== null && value !== void 0 && typeof value === "object";
6757
6719
  }
@@ -6842,8 +6804,7 @@ function parseFilterValue(filter, logger) {
6842
6804
  }
6843
6805
  return parsedFilter;
6844
6806
  }
6845
- //#endregion
6846
- //#region src/utils/convert-sources.ts
6807
+ // src/utils/convert-sources.ts
6847
6808
  const convertToSources = (results) => {
6848
6809
  return results.map((result) => {
6849
6810
  if ("content" in result) return {
@@ -6869,16 +6830,14 @@ const convertToSources = (results) => {
6869
6830
  };
6870
6831
  });
6871
6832
  };
6872
- //#endregion
6873
- //#region src/tools/types.ts
6833
+ // src/tools/types.ts
6874
6834
  const defaultGraphOptions = {
6875
6835
  dimension: 1536,
6876
6836
  randomWalkSteps: 100,
6877
6837
  restartProb: .15,
6878
6838
  threshold: .7
6879
6839
  };
6880
- //#endregion
6881
- //#region src/tools/graph-rag.ts
6840
+ // src/tools/graph-rag.ts
6882
6841
  const createGraphRAGTool = (options) => {
6883
6842
  const { model, id, description } = options;
6884
6843
  const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
@@ -7032,8 +6991,7 @@ const createGraphRAGTool = (options) => {
7032
6991
  }
7033
6992
  });
7034
6993
  };
7035
- //#endregion
7036
- //#region src/tools/vector-query.ts
6994
+ // src/tools/vector-query.ts
7037
6995
  const createVectorQueryTool = (options) => {
7038
6996
  const { id, description } = options;
7039
6997
  const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
@@ -7152,8 +7110,7 @@ const createVectorQueryTool = (options) => {
7152
7110
  }
7153
7111
  });
7154
7112
  };
7155
- //#endregion
7156
- //#region src/tools/bedrock-knowledge-base.ts
7113
+ // src/tools/bedrock-knowledge-base.ts
7157
7114
  function getSourceUri(location) {
7158
7115
  if (location?.s3Location) return location.s3Location.uri;
7159
7116
  if (location?.webLocation) return location.webLocation.url;
@@ -7242,7 +7199,6 @@ function createBedrockKBTool(options) {
7242
7199
  }
7243
7200
  });
7244
7201
  }
7245
- //#endregion
7246
7202
  export { CohereRelevanceScorer, GraphRAG, Language, MDocument, MastraAgentRelevanceScorer, ZeroEntropyRelevanceScorer, createBedrockKBTool, createDocumentChunkerTool, createGraphRAGTool, createVectorQueryTool, defaultGraphRagDescription, defaultVectorQueryDescription, filterDescription, queryTextDescription, rerank, rerankWithScorer, topKDescription };
7247
7203
 
7248
7204
  //# sourceMappingURL=index.js.map