@mastra/rag 2.7.2 → 2.7.3-alpha.1

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.2"
6
+ version: "2.7.3-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -20,7 +20,6 @@ Read the individual reference documents for detailed explanations and code examp
20
20
 
21
21
  ### Reference
22
22
 
23
- - [RAG](references/reference-migrations-upgrade-to-v1-rag.md) - Migrate RAG code to Mastra v1 with renamed chunking parameters and narrowed option types, including updates to related document-processing APIs.
24
23
  - [Reference: .chunk()](references/reference-rag-chunk.md) - The .chunk() function splits documents into smaller segments using strategies and options.
25
24
  - [Chunking and embedding documents](references/reference-rag-chunking-and-embedding.md) - Chunk documents with MDocument, generate embeddings through the AI SDK, and prepare text and metadata for vector storage and RAG retrieval.
26
25
  - [Reference: DatabaseConfig](references/reference-rag-database-config.md) - The DatabaseConfig type allows you to specify database-specific configurations when using vector query tools.
@@ -1,6 +1,92 @@
1
1
  {
2
- "version": "2.7.2",
2
+ "version": "2.7.3-alpha.1",
3
3
  "package": "@mastra/rag",
4
- "exports": {},
4
+ "exports": {
5
+ "CohereRelevanceScorer": {
6
+ "types": "dist/rerank/relevance/cohere/index.d.ts",
7
+ "implementation": "dist/index.js",
8
+ "line": 6088
9
+ },
10
+ "GraphRAG": {
11
+ "types": "dist/graph-rag/index.d.ts",
12
+ "implementation": "dist/index.js",
13
+ "line": 6285
14
+ },
15
+ "Language": {
16
+ "types": "dist/document/types.d.ts",
17
+ "implementation": "dist/index.js",
18
+ "line": 3842
19
+ },
20
+ "MDocument": {
21
+ "types": "dist/document/document.d.ts",
22
+ "implementation": "dist/index.js",
23
+ "line": 5821
24
+ },
25
+ "MastraAgentRelevanceScorer": {
26
+ "types": "dist/rerank/relevance/mastra-agent/index.d.ts",
27
+ "implementation": "dist/index.js",
28
+ "line": 6123
29
+ },
30
+ "ZeroEntropyRelevanceScorer": {
31
+ "types": "dist/rerank/relevance/zeroentropy/index.d.ts",
32
+ "implementation": "dist/index.js",
33
+ "line": 6152
34
+ },
35
+ "createBedrockKBTool": {
36
+ "types": "dist/tools/bedrock-knowledge-base.d.ts",
37
+ "implementation": "dist/index.js",
38
+ "line": 7115
39
+ },
40
+ "createDocumentChunkerTool": {
41
+ "types": "dist/tools/document-chunker.d.ts",
42
+ "implementation": "dist/index.js",
43
+ "line": 6506
44
+ },
45
+ "createGraphRAGTool": {
46
+ "types": "dist/tools/graph-rag.d.ts",
47
+ "implementation": "dist/index.js",
48
+ "line": 6821
49
+ },
50
+ "createVectorQueryTool": {
51
+ "types": "dist/tools/vector-query.d.ts",
52
+ "implementation": "dist/index.js",
53
+ "line": 6975
54
+ },
55
+ "defaultGraphRagDescription": {
56
+ "types": "dist/utils/default-settings.d.ts",
57
+ "implementation": "dist/index.js",
58
+ "line": 6653
59
+ },
60
+ "defaultVectorQueryDescription": {
61
+ "types": "dist/utils/default-settings.d.ts",
62
+ "implementation": "dist/index.js",
63
+ "line": 6652
64
+ },
65
+ "filterDescription": {
66
+ "types": "dist/utils/default-settings.d.ts",
67
+ "implementation": "dist/index.js",
68
+ "line": 6672
69
+ },
70
+ "queryTextDescription": {
71
+ "types": "dist/utils/default-settings.d.ts",
72
+ "implementation": "dist/index.js",
73
+ "line": 6654
74
+ },
75
+ "rerank": {
76
+ "types": "dist/rerank/index.d.ts",
77
+ "implementation": "dist/index.js",
78
+ "line": 6272
79
+ },
80
+ "rerankWithScorer": {
81
+ "types": "dist/rerank/index.d.ts",
82
+ "implementation": "dist/index.js",
83
+ "line": 6264
84
+ },
85
+ "topKDescription": {
86
+ "types": "dist/utils/default-settings.d.ts",
87
+ "implementation": "dist/index.js",
88
+ "line": 6662
89
+ }
90
+ },
5
91
  "modules": {}
6
92
  }
@@ -103,7 +103,7 @@ serialize(): GraphRAGSnapshot
103
103
 
104
104
  Returns a `GraphRAGSnapshot` object containing:
105
105
 
106
- **version** (`number`): Snapshot format version, used to reject snapshots this version of the class can't load
106
+ **version** (`1`): Snapshot format version. Always 1 in the current format, so deserialize rejects snapshots with any other version
107
107
 
108
108
  **dimension** (`number`): Dimension of the embedding vectors the graph was built with
109
109
 
@@ -88,14 +88,14 @@ The tool returns an object with:
88
88
  ```typescript
89
89
  {
90
90
  id: string; // Unique chunk/document identifier
91
- metadata: any; // All metadata fields (document ID, etc.)
92
- vector: number[]; // Embedding vector (if available)
91
+ metadata?: any; // All metadata fields (document ID, etc.)
92
+ vector: number[]; // Embedding vector, or [] when unavailable
93
93
  score: number; // Similarity score for this retrieval
94
94
  document: string; // Full chunk/document text (if available)
95
95
  }
96
96
  ```
97
97
 
98
- `document` is only populated by vector stores whose `query()` returns document content, such as Chroma, Elasticsearch, LanceDB, and MongoDB. For other stores, such as PgVector, it's an empty string. Read the chunk text from `sources[i].metadata.text` (or whichever metadata key you stored it under).
98
+ `document` is only populated by vector stores whose `query()` returns document content, such as Chroma, Elasticsearch, LanceDB, and MongoDB. For other stores, such as PgVector, it's an empty string. Read the chunk text from `sources[i].metadata?.text` (or whichever metadata key you stored it under). `metadata` is `undefined` when the store returns no metadata for a result.
99
99
 
100
100
  ## Default tool description
101
101
 
@@ -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;AAqEzC,qBAAa,oBAAqB,SAAQ,eAAe;IACvD,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,gBAAgB,EA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AA0B,EAIvG;IAED,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE,CAmB9C;IAED,OAAO,CAAC,YAAY;CAyDrB;AAED,qBAAa,6BAA8B,SAAQ,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"}
package/dist/index.cjs CHANGED
@@ -4008,7 +4008,7 @@ var TextTransformer = class {
4008
4008
  };
4009
4009
  // src/document/transformers/character.ts
4010
4010
  function splitTextWithRegex(text, separator, separatorPosition) {
4011
- if (!separator) return text.split("");
4011
+ if (!separator) return Array.from(text);
4012
4012
  if (!text) return [];
4013
4013
  const result = [];
4014
4014
  let lastIndex = 0;
@@ -6219,6 +6219,14 @@ async function executeRerank({ results, query, scorer, options }) {
6219
6219
  });
6220
6220
  throw err;
6221
6221
  }
6222
+ if (!Number.isInteger(topK) || topK < 0) {
6223
+ const err = /* @__PURE__ */ new Error(`topK must be a nonnegative integer. Got ${topK}`);
6224
+ rerankSpan?.error({
6225
+ error: err,
6226
+ endSpan: true
6227
+ });
6228
+ throw err;
6229
+ }
6222
6230
  const resultLength = results.length;
6223
6231
  const queryAnalysis = queryEmbedding ? analyzeQueryEmbedding(queryEmbedding) : null;
6224
6232
  let scoredResults;
@@ -6752,15 +6760,8 @@ async function resolveVectorStore(options, context, logger) {
6752
6760
  if (mastra) return mastra.getVector(vectorStoreName);
6753
6761
  }
6754
6762
  function coerceTopK(topK, defaultValue = 10) {
6755
- if (typeof topK === "number") {
6756
- if (Number.isFinite(topK) && topK > 0) return topK;
6757
- return defaultValue;
6758
- }
6759
- if (typeof topK === "string") {
6760
- const parsed = Number(topK);
6761
- if (Number.isFinite(parsed) && parsed > 0) return parsed;
6762
- return defaultValue;
6763
- }
6763
+ const parsed = typeof topK === "string" ? Number(topK) : topK;
6764
+ if (typeof parsed === "number" && Number.isFinite(parsed) && Math.floor(parsed) >= 1) return Math.floor(parsed);
6764
6765
  return defaultValue;
6765
6766
  }
6766
6767
  function parseFilterValue(filter, logger) {