@mastra/rag 2.7.1 → 2.7.2

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.1"
6
+ version: "2.7.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -36,7 +36,6 @@ Read the individual reference documents for detailed explanations and code examp
36
36
  - [Reference: createDocumentChunkerTool()](references/reference-tools-document-chunker-tool.md) - The createDocumentChunkerTool() function creates a tool for splitting documents into smaller chunks for efficient processing and retrieval.
37
37
  - [Reference: createGraphRAGTool()](references/reference-tools-graph-rag-tool.md) - Use createGraphRAGTool() to build semantic relationships between document chunks and retrieve connected context for graph-based RAG queries.
38
38
  - [Reference: createVectorQueryTool()](references/reference-tools-vector-query-tool.md) - The createVectorQueryTool() function creates a tool for semantic search over vector stores.
39
- - [Reference: OracleDB vector store](references/reference-vectors-oracledb.md) - OracleVector stores embeddings in Oracle Database VECTOR columns and exposes them through Mastra's vector interface.
40
39
 
41
40
 
42
41
  Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "2.7.1",
2
+ "version": "2.7.2",
3
3
  "package": "@mastra/rag",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -145,8 +145,8 @@ export const workspace = new Workspace({
145
145
  autoIndexPaths: ['**/*.md'],
146
146
  })
147
147
 
148
- // Agents receive tools including read_file, list_files, grep,
149
- // mastra_workspace_search, and mastra_workspace_index.
148
+ // Agents receive tools including mastra_workspace_read_file, mastra_workspace_list_files,
149
+ // mastra_workspace_grep, mastra_workspace_search, and mastra_workspace_index.
150
150
  await workspace.init()
151
151
  ```
152
152
 
@@ -202,7 +202,7 @@ When using the `headers` option, the markdown strategy ignores all general optio
202
202
 
203
203
  **maxSize** (`number`): Maximum size of each chunk
204
204
 
205
- **minSize** (`number`): Minimum size of each chunk
205
+ **minSize** (`number`): Accepted for compatibility. Has no effect on JSON chunking: chunks smaller than this are kept, so no data is discarded.
206
206
 
207
207
  **ensureAscii** (`boolean`): Whether to ensure ASCII encoding
208
208
 
@@ -251,7 +251,11 @@ const results = await pgVector.query({
251
251
  })
252
252
  ```
253
253
 
254
- Postgres vector indexes (HNSW and IVFFlat) can't restrict that search to rows matching a condition. When a filter is present, pgVector instead compares the query vector against every matching row and returns the closest `topK`. Results are exact, but the work grows with the number of rows the filter matches. Indexing the metadata column speeds up row retrieval. The distance comparisons still happen per row.
254
+ With an HNSW index on pgvector 0.8.0 or newer, PostgreSQL searches the index and skips rows that don't match the filter. When the index search can't fill `topK`, pgVector reruns the query as an exact search.
255
+
256
+ With IVFFlat, or HNSW on older pgvector versions, pgVector compares the query vector against every matching row. Results are exact, but the work grows with the number of matching rows.
257
+
258
+ Indexing the metadata fields you filter on speeds up both cases and gives PostgreSQL the row counts it needs to choose between them.
255
259
 
256
260
  ### Vector Query Tool
257
261
 
@@ -1 +1 @@
1
- {"version":3,"file":"character.d.ts","sourceRoot":"","sources":["../../../src/document/transformers/character.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAE/F,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AA6EzC,qBAAa,oBAAqB,SAAQ,eAAe;IACvD,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAC;IAEpC,YAAY,EAAE,SAAkB,EAAE,gBAAwB,EAAE,GAAG,WAAW,EAAE,GAAE,qBAA0B,EAIvG;IAED,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA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Q,eAAe;IAChE,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAC/B,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAC;IAEpC,YAAY,EAAE,UAAU,EAAE,gBAAwB,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAE,GAAE,qBAA0B,EAIzG;IAED,OAAO,CAAC,UAAU;IA8DlB,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE,CAE9C;IAED,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,GAAE,gBAAqB,GAAG,6BAA6B,CAQrG;IAED,MAAM,CAAC,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,EAAE,CAua5D;CACF"}
@@ -2,10 +2,9 @@ import { Document } from '../schema/index.js';
2
2
  import type { JsonChunkOptions } from '../types.js';
3
3
  export declare class RecursiveJsonTransformer {
4
4
  private maxSize;
5
- private minSize;
6
5
  private ensureAscii;
7
6
  private convertLists;
8
- constructor({ maxSize, minSize, ensureAscii, convertLists }: JsonChunkOptions);
7
+ constructor({ maxSize, ensureAscii, convertLists }: JsonChunkOptions);
9
8
  private static jsonSize;
10
9
  /**
11
10
  * Transform JSON data while handling circular references
@@ -60,11 +59,6 @@ export declare class RecursiveJsonTransformer {
60
59
  jsonData: Record<string, any>;
61
60
  convertLists?: boolean;
62
61
  }): Record<string, any>[];
63
- /**
64
- * Converts Unicode characters to their escaped ASCII representation
65
- * e.g., 'café' becomes 'caf\u00e9'
66
- */
67
- private escapeNonAscii;
68
62
  /**
69
63
  * Splits JSON into a list of JSON formatted strings
70
64
  */
@@ -1 +1 @@
1
- {"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../src/document/transformers/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AACrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,M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
@@ -1 +1 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/document/transformers/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAa5D,qBAAa,mBAAoB,SAAQ,6BAA6B;IACpE,YAAY,OAAO,GAAE,gBAAqB,EAGzC;CACF;AAED,qBAAa,yBAAyB;IACpC,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,YAAY,CAAU;IAE9B,YAAY,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,cAAc,GAAE,OAAe,EAAE,YAAY,GAAE,OAAc,EAI9G;IAED,OAAO,CAAC,sBAAsB;IAuD9B,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ,EAAE,CAkIhD;IAED,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,QAAQ,EAAE,CAiB9E;IAED,kBAAkB,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAUpD;CACF"}
1
+ {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../src/document/transformers/markdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGrC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAa5D,qBAAa,mBAAoB,SAAQ,6BAA6B;IACpE,YAAY,OAAO,GAAE,gBAAqB,EAGzC;CACF;AAED,qBAAa,yBAAyB;IACpC,OAAO,CAAC,gBAAgB,CAAqB;IAC7C,OAAO,CAAC,cAAc,CAAU;IAChC,OAAO,CAAC,YAAY,CAAU;IAE9B,YAAY,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,EAAE,cAAc,GAAE,OAAe,EAAE,YAAY,GAAE,OAAc,EAI9G;IAED,OAAO,CAAC,sBAAsB;IAuD9B,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,QAAQ,EAAE,CAsIhD;IAED,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,QAAQ,EAAE,CAiB9E;IAED,kBAAkB,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE,CAUpD;CACF"}
package/dist/index.cjs CHANGED
@@ -4009,24 +4009,22 @@ var TextTransformer = class {
4009
4009
  // src/document/transformers/character.ts
4010
4010
  function splitTextWithRegex(text, separator, separatorPosition) {
4011
4011
  if (!separator) return text.split("");
4012
- if (!separatorPosition) return text.split(new RegExp(separator)).filter((s) => s !== "");
4013
4012
  if (!text) return [];
4014
- const splits = text.split(new RegExp(`(${separator})`));
4015
4013
  const result = [];
4016
- if (separatorPosition === "end") {
4017
- for (let i = 0; i < splits.length - 1; i += 2) if (i + 1 < splits.length) {
4018
- const chunk = splits[i] + (splits[i + 1] || "");
4019
- if (chunk) result.push(chunk);
4020
- }
4021
- if (splits.length % 2 === 1 && splits[splits.length - 1]) result.push(splits?.[splits.length - 1]);
4022
- } else {
4023
- if (splits[0]) result.push(splits[0]);
4024
- for (let i = 1; i < splits.length - 1; i += 2) {
4025
- const separator2 = splits[i];
4026
- const text2 = splits[i + 1] ?? "";
4027
- if (separator2) result.push(separator2 + text2);
4028
- }
4029
- }
4014
+ let lastIndex = 0;
4015
+ let pendingSeparator = "";
4016
+ for (const match of text.matchAll(new RegExp(separator, "g"))) {
4017
+ const matched = match[0];
4018
+ const piece = text.slice(lastIndex, match.index);
4019
+ if (separatorPosition === "end") result.push(piece + matched);
4020
+ else if (separatorPosition === "start") {
4021
+ result.push(pendingSeparator + piece);
4022
+ pendingSeparator = matched;
4023
+ } else result.push(piece);
4024
+ lastIndex = match.index + matched.length;
4025
+ }
4026
+ const tail = text.slice(lastIndex);
4027
+ result.push(separatorPosition === "start" ? pendingSeparator + tail : tail);
4030
4028
  return result.filter((s) => s !== "");
4031
4029
  }
4032
4030
  function splitTextWithMatchedSeparators(text, separator) {
@@ -4848,12 +4846,10 @@ var HTMLSectionTransformer = class {
4848
4846
  // src/document/transformers/json.ts
4849
4847
  var RecursiveJsonTransformer = class RecursiveJsonTransformer {
4850
4848
  maxSize;
4851
- minSize;
4852
4849
  ensureAscii;
4853
4850
  convertLists;
4854
- constructor({ maxSize = 2e3, minSize, ensureAscii = false, convertLists = true }) {
4851
+ constructor({ maxSize = 2e3, ensureAscii = false, convertLists = true }) {
4855
4852
  this.maxSize = maxSize;
4856
- this.minSize = minSize ?? Math.max(maxSize - 200, 50);
4857
4853
  this.ensureAscii = ensureAscii;
4858
4854
  this.convertLists = convertLists;
4859
4855
  }
@@ -4980,14 +4976,11 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
4980
4976
  let currentGroup = [];
4981
4977
  const saveCurrentGroup = () => {
4982
4978
  if (currentGroup.length > 0) {
4983
- const groupChunk = this.createChunk(currentGroup, path);
4984
- if (RecursiveJsonTransformer.jsonSize(groupChunk) >= this.minSize) {
4985
- chunks.push(groupChunk);
4986
- currentGroup = [];
4987
- }
4979
+ chunks.push(this.createChunk(currentGroup, path));
4980
+ currentGroup = [];
4988
4981
  }
4989
4982
  };
4990
- for (const item of value) {
4983
+ for (const [itemIndex, item] of value.entries()) {
4991
4984
  const testGroup = [...currentGroup, item];
4992
4985
  const testChunk = this.createChunk(testGroup, path);
4993
4986
  if (this.isWithinSizeLimit(testChunk)) {
@@ -5000,7 +4993,7 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
5000
4993
  const singleItemChunk = this.createChunk(singleItemArray, path);
5001
4994
  if (this.isWithinSizeLimit(singleItemChunk)) currentGroup = singleItemArray;
5002
4995
  else {
5003
- const itemPath = [...path, String(chunks.length)];
4996
+ const itemPath = [...path, String(itemIndex)];
5004
4997
  const nestedChunks = this.handleNestedObject(item, itemPath, depth + 1, maxDepth);
5005
4998
  chunks.push(...nestedChunks);
5006
4999
  }
@@ -5025,11 +5018,8 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
5025
5018
  let currentChunk = {};
5026
5019
  const saveCurrentChunk = () => {
5027
5020
  if (Object.keys(currentChunk).length > 0) {
5028
- const objChunk = this.createChunk(currentChunk, path);
5029
- if (RecursiveJsonTransformer.jsonSize(objChunk) >= this.minSize) {
5030
- chunks.push(objChunk);
5031
- currentChunk = {};
5032
- }
5021
+ chunks.push(this.createChunk(currentChunk, path));
5022
+ currentChunk = {};
5033
5023
  }
5034
5024
  };
5035
5025
  for (const [key, val] of Object.entries(value)) {
@@ -5117,30 +5107,15 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
5117
5107
  return chunks;
5118
5108
  }
5119
5109
  /**
5120
- * Converts Unicode characters to their escaped ASCII representation
5121
- * e.g., 'café' becomes 'caf\u00e9'
5122
- */
5123
- escapeNonAscii(obj) {
5124
- if (typeof obj === "string") return obj.replace(/[\u0080-\uffff]/g, (char) => {
5125
- return `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`;
5126
- });
5127
- if (Array.isArray(obj)) return obj.map((item) => this.escapeNonAscii(item));
5128
- if (typeof obj === "object" && obj !== null) return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, this.escapeNonAscii(value)]));
5129
- return obj;
5130
- }
5131
- /**
5132
5110
  * Splits JSON into a list of JSON formatted strings
5133
5111
  */
5134
5112
  splitText({ jsonData, convertLists = false, ensureAscii = true }) {
5135
- const chunks = this.splitJson({
5113
+ const serialized = this.splitJson({
5136
5114
  jsonData,
5137
5115
  convertLists
5138
- });
5139
- if (ensureAscii) return chunks.map((chunk) => this.escapeNonAscii(chunk)).map((chunk) => JSON.stringify(chunk));
5140
- return chunks.map((chunk) => JSON.stringify(chunk, (key, value) => {
5141
- if (typeof value === "string") return value.replace(/\\u[\da-f]{4}/gi, (match) => String.fromCharCode(parseInt(match.slice(2), 16)));
5142
- return value;
5143
- }));
5116
+ }).map((chunk) => JSON.stringify(chunk));
5117
+ if (!ensureAscii) return serialized;
5118
+ return serialized.map((text) => text.replace(/[\u0080-\uffff]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`));
5144
5119
  }
5145
5120
  /**
5146
5121
  * Create documents from a list of json objects
@@ -5252,11 +5227,12 @@ var MarkdownHeaderTransformer = class {
5252
5227
  const line = lines[i];
5253
5228
  const strippedLine = line.trim();
5254
5229
  if (!inCodeBlock) {
5255
- if (strippedLine.startsWith("```") && strippedLine.split("```").length === 2 || strippedLine.startsWith("~~~")) {
5230
+ const fence = strippedLine.match(/^(`{3,}|~{3,})/);
5231
+ if (fence && (fence[1][0] !== "`" || !strippedLine.slice(fence[1].length).includes("`"))) {
5256
5232
  inCodeBlock = true;
5257
- openingFence = strippedLine.startsWith("```") ? "```" : "~~~";
5233
+ openingFence = fence[1];
5258
5234
  }
5259
- } else if (strippedLine.startsWith(openingFence)) {
5235
+ } else if (strippedLine.startsWith(openingFence) && new RegExp(`^${openingFence[0]}{${openingFence.length},}\\s*$`).test(strippedLine)) {
5260
5236
  inCodeBlock = false;
5261
5237
  openingFence = "";
5262
5238
  }
@@ -5264,13 +5240,9 @@ var MarkdownHeaderTransformer = class {
5264
5240
  currentContent.push(line);
5265
5241
  continue;
5266
5242
  }
5267
- if (strippedLine.includes("|") && strippedLine.length > 0) {
5268
- if (!inTable) inTable = true;
5269
- currentContent.push(line);
5270
- continue;
5271
- } else if (inTable) inTable = false;
5243
+ const isIndentedCode = strippedLine.includes("|") && /^(?: {4}|\t)/.test(line);
5272
5244
  let headerMatched = false;
5273
- for (const [sep, name] of this.headersToSplitOn) if (strippedLine.startsWith(sep) && (strippedLine.length === sep.length || strippedLine[sep.length] === " ")) {
5245
+ for (const [sep, name] of this.headersToSplitOn) if (!isIndentedCode && strippedLine.startsWith(sep) && (strippedLine.length === sep.length || strippedLine[sep.length] === " ")) {
5274
5246
  headerMatched = true;
5275
5247
  if (currentContent.length > 0) {
5276
5248
  linesWithMetadata.push({
@@ -5302,7 +5274,14 @@ var MarkdownHeaderTransformer = class {
5302
5274
  });
5303
5275
  break;
5304
5276
  }
5305
- if (!headerMatched) {
5277
+ if (headerMatched) inTable = false;
5278
+ else {
5279
+ if (strippedLine.includes("|")) {
5280
+ inTable = true;
5281
+ currentContent.push(line);
5282
+ continue;
5283
+ }
5284
+ if (inTable) inTable = false;
5306
5285
  if (strippedLine || this.returnEachLine) {
5307
5286
  currentContent.push(line);
5308
5287
  if (this.returnEachLine) {