@mastra/rag 0.10.1-alpha.0 → 0.10.1-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.
@@ -6,8 +6,7 @@ import type { QueryResult } from '@mastra/core/vector';
6
6
  import type { QueryResult as QueryResult_2 } from '@mastra/core';
7
7
  import type { TiktokenEncoding } from 'js-tiktoken';
8
8
  import type { TiktokenModel } from 'js-tiktoken';
9
- import { Tool } from '@mastra/core/tools';
10
- import { ToolExecutionContext } from '@mastra/core';
9
+ import type { Tool } from '@mastra/core/tools';
11
10
  import type { VectorFilter } from '@mastra/core/vector/filter';
12
11
  import { z } from 'zod';
13
12
 
@@ -77,6 +76,13 @@ export declare type BasePromptTemplateOptions<TemplatesVar extends readonly stri
77
76
  options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>;
78
77
  };
79
78
 
79
+ declare const baseSchema: {
80
+ queryText: z.ZodString;
81
+ topK: z.ZodNumber;
82
+ };
83
+ export { baseSchema }
84
+ export { baseSchema as baseSchema_alias_1 }
85
+
80
86
  export declare class CharacterTransformer extends TextTransformer {
81
87
  protected separator: string;
82
88
  protected isSeparatorRegex: boolean;
@@ -182,125 +188,28 @@ declare const createGraphRAGTool: ({ vectorStoreName, indexName, model, enableFi
182
188
  };
183
189
  id?: string;
184
190
  description?: string;
185
- }) => Tool<z.ZodObject<{
186
- queryText: z.ZodString;
187
- topK: z.ZodNumber;
188
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
189
- queryText: z.ZodString;
190
- topK: z.ZodNumber;
191
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
192
- queryText: z.ZodString;
193
- topK: z.ZodNumber;
194
- }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
195
- relevantContext: z.ZodAny;
196
- sources: z.ZodArray<z.ZodObject<{
197
- id: z.ZodString;
198
- metadata: z.ZodAny;
199
- vector: z.ZodArray<z.ZodNumber, "many">;
200
- score: z.ZodNumber;
201
- document: z.ZodString;
202
- }, "strip", z.ZodTypeAny, {
203
- id: string;
204
- vector: number[];
205
- score: number;
206
- document: string;
207
- metadata?: any;
208
- }, {
209
- id: string;
210
- vector: number[];
211
- score: number;
212
- document: string;
213
- metadata?: any;
214
- }>, "many">;
191
+ }) => RagTool<z.ZodObject<{
192
+ filter: z.ZodString;
193
+ queryText: z.ZodString;
194
+ topK: z.ZodNumber;
215
195
  }, "strip", z.ZodTypeAny, {
216
- sources: {
217
- id: string;
218
- vector: number[];
219
- score: number;
220
- document: string;
221
- metadata?: any;
222
- }[];
223
- relevantContext?: any;
196
+ filter: string;
197
+ topK: number;
198
+ queryText: string;
224
199
  }, {
225
- sources: {
226
- id: string;
227
- vector: number[];
228
- score: number;
229
- document: string;
230
- metadata?: any;
231
- }[];
232
- relevantContext?: any;
233
- }>, ToolExecutionContext<z.ZodObject<{
234
- queryText: z.ZodString;
235
- topK: z.ZodNumber;
236
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
237
- queryText: z.ZodString;
238
- topK: z.ZodNumber;
239
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
240
- queryText: z.ZodString;
241
- topK: z.ZodNumber;
242
- }, z.ZodTypeAny, "passthrough">>>> & {
243
- inputSchema: z.ZodObject<{
244
- queryText: z.ZodString;
245
- topK: z.ZodNumber;
246
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
247
- queryText: z.ZodString;
248
- topK: z.ZodNumber;
249
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
250
- queryText: z.ZodString;
251
- topK: z.ZodNumber;
252
- }, z.ZodTypeAny, "passthrough">>;
253
- outputSchema: z.ZodObject<{
254
- relevantContext: z.ZodAny;
255
- sources: z.ZodArray<z.ZodObject<{
256
- id: z.ZodString;
257
- metadata: z.ZodAny;
258
- vector: z.ZodArray<z.ZodNumber, "many">;
259
- score: z.ZodNumber;
260
- document: z.ZodString;
261
- }, "strip", z.ZodTypeAny, {
262
- id: string;
263
- vector: number[];
264
- score: number;
265
- document: string;
266
- metadata?: any;
267
- }, {
268
- id: string;
269
- vector: number[];
270
- score: number;
271
- document: string;
272
- metadata?: any;
273
- }>, "many">;
274
- }, "strip", z.ZodTypeAny, {
275
- sources: {
276
- id: string;
277
- vector: number[];
278
- score: number;
279
- document: string;
280
- metadata?: any;
281
- }[];
282
- relevantContext?: any;
283
- }, {
284
- sources: {
285
- id: string;
286
- vector: number[];
287
- score: number;
288
- document: string;
289
- metadata?: any;
290
- }[];
291
- relevantContext?: any;
292
- }>;
293
- execute: (context: ToolExecutionContext<z.ZodObject<{
200
+ filter: string;
201
+ topK: number;
202
+ queryText: string;
203
+ }> | z.ZodObject<{
294
204
  queryText: z.ZodString;
295
205
  topK: z.ZodNumber;
296
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
206
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
297
207
  queryText: z.ZodString;
298
208
  topK: z.ZodNumber;
299
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
209
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
300
210
  queryText: z.ZodString;
301
211
  topK: z.ZodNumber;
302
- }, z.ZodTypeAny, "passthrough">>>) => Promise<any>;
303
- };
212
+ }, z.ZodTypeAny, "passthrough">>, any>;
304
213
  export { createGraphRAGTool }
305
214
  export { createGraphRAGTool as createGraphRAGTool_alias_1 }
306
215
  export { createGraphRAGTool as createGraphRAGTool_alias_2 }
@@ -315,125 +224,28 @@ declare const createVectorQueryTool: ({ vectorStoreName, indexName, model, enabl
315
224
  reranker?: RerankConfig;
316
225
  id?: string;
317
226
  description?: string;
318
- }) => Tool<z.ZodObject<{
319
- queryText: z.ZodString;
320
- topK: z.ZodNumber;
321
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
322
- queryText: z.ZodString;
323
- topK: z.ZodNumber;
324
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
325
- queryText: z.ZodString;
326
- topK: z.ZodNumber;
327
- }, z.ZodTypeAny, "passthrough">>, z.ZodObject<{
328
- relevantContext: z.ZodAny;
329
- sources: z.ZodArray<z.ZodObject<{
330
- id: z.ZodString;
331
- metadata: z.ZodAny;
332
- vector: z.ZodArray<z.ZodNumber, "many">;
333
- score: z.ZodNumber;
334
- document: z.ZodString;
335
- }, "strip", z.ZodTypeAny, {
336
- id: string;
337
- vector: number[];
338
- score: number;
339
- document: string;
340
- metadata?: any;
341
- }, {
342
- id: string;
343
- vector: number[];
344
- score: number;
345
- document: string;
346
- metadata?: any;
347
- }>, "many">;
227
+ }) => RagTool<z.ZodObject<{
228
+ filter: z.ZodString;
229
+ queryText: z.ZodString;
230
+ topK: z.ZodNumber;
348
231
  }, "strip", z.ZodTypeAny, {
349
- sources: {
350
- id: string;
351
- vector: number[];
352
- score: number;
353
- document: string;
354
- metadata?: any;
355
- }[];
356
- relevantContext?: any;
232
+ filter: string;
233
+ topK: number;
234
+ queryText: string;
357
235
  }, {
358
- sources: {
359
- id: string;
360
- vector: number[];
361
- score: number;
362
- document: string;
363
- metadata?: any;
364
- }[];
365
- relevantContext?: any;
366
- }>, ToolExecutionContext<z.ZodObject<{
367
- queryText: z.ZodString;
368
- topK: z.ZodNumber;
369
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
370
- queryText: z.ZodString;
371
- topK: z.ZodNumber;
372
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
373
- queryText: z.ZodString;
374
- topK: z.ZodNumber;
375
- }, z.ZodTypeAny, "passthrough">>>> & {
376
- inputSchema: z.ZodObject<{
377
- queryText: z.ZodString;
378
- topK: z.ZodNumber;
379
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
380
- queryText: z.ZodString;
381
- topK: z.ZodNumber;
382
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
383
- queryText: z.ZodString;
384
- topK: z.ZodNumber;
385
- }, z.ZodTypeAny, "passthrough">>;
386
- outputSchema: z.ZodObject<{
387
- relevantContext: z.ZodAny;
388
- sources: z.ZodArray<z.ZodObject<{
389
- id: z.ZodString;
390
- metadata: z.ZodAny;
391
- vector: z.ZodArray<z.ZodNumber, "many">;
392
- score: z.ZodNumber;
393
- document: z.ZodString;
394
- }, "strip", z.ZodTypeAny, {
395
- id: string;
396
- vector: number[];
397
- score: number;
398
- document: string;
399
- metadata?: any;
400
- }, {
401
- id: string;
402
- vector: number[];
403
- score: number;
404
- document: string;
405
- metadata?: any;
406
- }>, "many">;
407
- }, "strip", z.ZodTypeAny, {
408
- sources: {
409
- id: string;
410
- vector: number[];
411
- score: number;
412
- document: string;
413
- metadata?: any;
414
- }[];
415
- relevantContext?: any;
416
- }, {
417
- sources: {
418
- id: string;
419
- vector: number[];
420
- score: number;
421
- document: string;
422
- metadata?: any;
423
- }[];
424
- relevantContext?: any;
425
- }>;
426
- execute: (context: ToolExecutionContext<z.ZodObject<{
236
+ filter: string;
237
+ topK: number;
238
+ queryText: string;
239
+ }> | z.ZodObject<{
427
240
  queryText: z.ZodString;
428
241
  topK: z.ZodNumber;
429
- }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
242
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
430
243
  queryText: z.ZodString;
431
244
  topK: z.ZodNumber;
432
- }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
245
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
433
246
  queryText: z.ZodString;
434
247
  topK: z.ZodNumber;
435
- }, z.ZodTypeAny, "passthrough">>>) => Promise<any>;
436
- };
248
+ }, z.ZodTypeAny, "passthrough">>, any>;
437
249
  export { createVectorQueryTool }
438
250
  export { createVectorQueryTool as createVectorQueryTool_alias_1 }
439
251
  export { createVectorQueryTool as createVectorQueryTool_alias_2 }
@@ -516,6 +328,22 @@ export { filterDescription }
516
328
  export { filterDescription as filterDescription_alias_1 }
517
329
  export { filterDescription as filterDescription_alias_2 }
518
330
 
331
+ declare const filterSchema: z.ZodObject<{
332
+ filter: z.ZodString;
333
+ queryText: z.ZodString;
334
+ topK: z.ZodNumber;
335
+ }, "strip", z.ZodTypeAny, {
336
+ filter: string;
337
+ topK: number;
338
+ queryText: string;
339
+ }, {
340
+ filter: string;
341
+ topK: number;
342
+ queryText: string;
343
+ }>;
344
+ export { filterSchema }
345
+ export { filterSchema as filterSchema_alias_1 }
346
+
519
347
  /**
520
348
  * Formats a string by replacing placeholders with values from the provided parameters.
521
349
  * @param str The string to format.
@@ -798,6 +626,49 @@ declare enum ObjectType {
798
626
  export { ObjectType }
799
627
  export { ObjectType as ObjectType_alias_1 }
800
628
 
629
+ declare const outputSchema: z.ZodObject<{
630
+ relevantContext: z.ZodAny;
631
+ sources: z.ZodArray<z.ZodObject<{
632
+ id: z.ZodString;
633
+ metadata: z.ZodAny;
634
+ vector: z.ZodArray<z.ZodNumber, "many">;
635
+ score: z.ZodNumber;
636
+ document: z.ZodString;
637
+ }, "strip", z.ZodTypeAny, {
638
+ id: string;
639
+ vector: number[];
640
+ score: number;
641
+ document: string;
642
+ metadata?: any;
643
+ }, {
644
+ id: string;
645
+ vector: number[];
646
+ score: number;
647
+ document: string;
648
+ metadata?: any;
649
+ }>, "many">;
650
+ }, "strip", z.ZodTypeAny, {
651
+ sources: {
652
+ id: string;
653
+ vector: number[];
654
+ score: number;
655
+ document: string;
656
+ metadata?: any;
657
+ }[];
658
+ relevantContext?: any;
659
+ }, {
660
+ sources: {
661
+ id: string;
662
+ vector: number[];
663
+ score: number;
664
+ document: string;
665
+ metadata?: any;
666
+ }[];
667
+ relevantContext?: any;
668
+ }>;
669
+ export { outputSchema }
670
+ export { outputSchema as outputSchema_alias_1 }
671
+
801
672
  /** @deprecated Import from @mastra/pg instead */
802
673
  declare const PGVECTOR_PROMPT = "When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n- $elemMatch: Match array elements that meet all specified conditions\n Example: { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 100 } } } }\n- $contains: Check if array contains value\n Example: { \"tags\": { \"$contains\": \"premium\" } }\n\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n- $nor: Logical NOR\n Example: { \"$nor\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n- $regex: Pattern matching (PostgreSQL regex syntax)\n Example: { \"name\": { \"$regex\": \"^iphone\" } }\n- $options: Regex options (used with $regex)\n Example: { \"name\": { \"$regex\": \"iphone\", \"$options\": \"i\" } }\n\nRestrictions:\n- Direct RegExp patterns are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Array operations work on array fields only\n- Regex patterns must follow PostgreSQL syntax\n- Empty arrays in conditions are handled gracefully\n- Only logical operators ($and, $or, $not, $nor) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$regex\": \"pattern\" }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other logical operators ($and, $or, $nor):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n- $elemMatch requires an object with conditions\n Valid: { \"array\": { \"$elemMatch\": { \"field\": \"value\" } } }\n Invalid: { \"array\": { \"$elemMatch\": \"value\" } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\", \"sale\"] } },\n { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 50 }, \"inStock\": true } } },\n { \"$or\": [\n { \"name\": { \"$regex\": \"^iphone\", \"$options\": \"i\" } },\n { \"description\": { \"$regex\": \".*apple.*\" } }\n ]}\n ]\n}";
803
674
  export { PGVECTOR_PROMPT }
@@ -878,6 +749,12 @@ declare class QuestionsAnsweredExtractor extends BaseExtractor {
878
749
  export { QuestionsAnsweredExtractor }
879
750
  export { QuestionsAnsweredExtractor as QuestionsAnsweredExtractor_alias_1 }
880
751
 
752
+ declare type RagTool<TInput extends z.ZodType<any, z.ZodTypeDef, any> | undefined, TOutput extends z.ZodType<any, z.ZodTypeDef, any> | undefined> = Tool<TInput, TOutput> & {
753
+ execute: NonNullable<Tool<TInput, TOutput>['execute']>;
754
+ };
755
+ export { RagTool }
756
+ export { RagTool as RagTool_alias_1 }
757
+
881
758
  export declare interface RankedNode extends GraphNode {
882
759
  score: number;
883
760
  }
package/dist/index.cjs CHANGED
@@ -6275,6 +6275,33 @@ var filterDescription = `JSON-formatted criteria to refine search results.
6275
6275
  - Do NOT use single quotes or unquoted properties
6276
6276
  - IMPORTANT: Always ensure JSON is properly closed with matching brackets
6277
6277
  - Multiple filters can be combined`;
6278
+ var baseSchema = {
6279
+ queryText: zod.z.string().describe(queryTextDescription),
6280
+ topK: zod.z.coerce.number().describe(topKDescription)
6281
+ };
6282
+ var outputSchema = zod.z.object({
6283
+ // Array of metadata or content for compatibility with prior usage
6284
+ relevantContext: zod.z.any(),
6285
+ // Array of full retrieval result objects
6286
+ sources: zod.z.array(
6287
+ zod.z.object({
6288
+ id: zod.z.string(),
6289
+ // Unique chunk/document identifier
6290
+ metadata: zod.z.any(),
6291
+ // All metadata fields (document ID, etc.)
6292
+ vector: zod.z.array(zod.z.number()),
6293
+ // Embedding vector (if available)
6294
+ score: zod.z.number(),
6295
+ // Similarity score for this retrieval
6296
+ document: zod.z.string()
6297
+ // Full chunk/document text (if available)
6298
+ })
6299
+ )
6300
+ });
6301
+ var filterSchema = zod.z.object({
6302
+ ...baseSchema,
6303
+ filter: zod.z.coerce.string().describe(filterDescription)
6304
+ });
6278
6305
 
6279
6306
  // src/utils/convert-sources.ts
6280
6307
  var convertToSources = (results) => {
@@ -6327,39 +6354,11 @@ var createGraphRAGTool = ({
6327
6354
  const toolDescription = description || defaultGraphRagDescription();
6328
6355
  const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
6329
6356
  let isInitialized = false;
6330
- const baseSchema = {
6331
- queryText: zod.z.string().describe(queryTextDescription),
6332
- topK: zod.z.coerce.number().describe(topKDescription)
6333
- };
6334
- const inputSchema = enableFilter ? zod.z.object({
6335
- ...baseSchema,
6336
- filter: zod.z.coerce.string().describe(filterDescription)
6337
- }).passthrough() : zod.z.object(baseSchema).passthrough();
6357
+ const inputSchema = enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough();
6338
6358
  return tools.createTool({
6339
6359
  id: toolId,
6340
6360
  inputSchema,
6341
- // Output schema includes `sources`, which exposes the full set of retrieved chunks (QueryResult objects)
6342
- // Each source contains all information needed to reference
6343
- // the original document, chunk, and similarity score.
6344
- outputSchema: zod.z.object({
6345
- // Array of metadata or content for compatibility with prior usage
6346
- relevantContext: zod.z.any(),
6347
- // Array of full retrieval result objects
6348
- sources: zod.z.array(
6349
- zod.z.object({
6350
- id: zod.z.string(),
6351
- // Unique chunk/document identifier
6352
- metadata: zod.z.any(),
6353
- // All metadata fields (document ID, etc.)
6354
- vector: zod.z.array(zod.z.number()),
6355
- // Embedding vector (if available)
6356
- score: zod.z.number(),
6357
- // Similarity score for this retrieval
6358
- document: zod.z.string()
6359
- // Full chunk/document text (if available)
6360
- })
6361
- )
6362
- }),
6361
+ outputSchema,
6363
6362
  description: toolDescription,
6364
6363
  execute: async ({ context: { queryText, topK, filter }, mastra }) => {
6365
6364
  const logger = mastra?.getLogger();
@@ -6453,6 +6452,7 @@ var createGraphRAGTool = ({
6453
6452
  return { relevantContext: [], sources: [] };
6454
6453
  }
6455
6454
  }
6455
+ // Use any for output schema as the structure of the output causes type inference issues
6456
6456
  });
6457
6457
  };
6458
6458
  var createVectorQueryTool = ({
@@ -6468,39 +6468,11 @@ var createVectorQueryTool = ({
6468
6468
  }) => {
6469
6469
  const toolId = id || `VectorQuery ${vectorStoreName} ${indexName} Tool`;
6470
6470
  const toolDescription = description || defaultVectorQueryDescription();
6471
- const baseSchema = {
6472
- queryText: zod.z.string().describe(queryTextDescription),
6473
- topK: zod.z.coerce.number().describe(topKDescription)
6474
- };
6475
- const inputSchema = enableFilter ? zod.z.object({
6476
- ...baseSchema,
6477
- filter: zod.z.coerce.string().describe(filterDescription)
6478
- }).passthrough() : zod.z.object(baseSchema).passthrough();
6471
+ const inputSchema = enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough();
6479
6472
  return tools.createTool({
6480
6473
  id: toolId,
6481
6474
  inputSchema,
6482
- // Output schema includes `sources`, which exposes the full set of retrieved chunks (QueryResult objects)
6483
- // Each source contains all information needed to reference
6484
- // the original document, chunk, and similarity score.
6485
- outputSchema: zod.z.object({
6486
- // Array of metadata or content for compatibility with prior usage
6487
- relevantContext: zod.z.any(),
6488
- // Array of full retrieval result objects
6489
- sources: zod.z.array(
6490
- zod.z.object({
6491
- id: zod.z.string(),
6492
- // Unique chunk/document identifier
6493
- metadata: zod.z.any(),
6494
- // All metadata fields (document ID, etc.)
6495
- vector: zod.z.array(zod.z.number()),
6496
- // Embedding vector (if available)
6497
- score: zod.z.number(),
6498
- // Similarity score for this retrieval
6499
- document: zod.z.string()
6500
- // Full chunk/document text (if available)
6501
- })
6502
- )
6503
- }),
6475
+ outputSchema,
6504
6476
  description: toolDescription,
6505
6477
  execute: async ({ context: { queryText, topK, filter }, mastra }) => {
6506
6478
  const logger = mastra?.getLogger();
@@ -6587,6 +6559,7 @@ var createVectorQueryTool = ({
6587
6559
  return { relevantContext: [], sources: [] };
6588
6560
  }
6589
6561
  }
6562
+ // Use any for output schema as the structure of the output causes type inference issues
6590
6563
  });
6591
6564
  };
6592
6565
 
package/dist/index.js CHANGED
@@ -6273,6 +6273,33 @@ var filterDescription = `JSON-formatted criteria to refine search results.
6273
6273
  - Do NOT use single quotes or unquoted properties
6274
6274
  - IMPORTANT: Always ensure JSON is properly closed with matching brackets
6275
6275
  - Multiple filters can be combined`;
6276
+ var baseSchema = {
6277
+ queryText: z.string().describe(queryTextDescription),
6278
+ topK: z.coerce.number().describe(topKDescription)
6279
+ };
6280
+ var outputSchema = z.object({
6281
+ // Array of metadata or content for compatibility with prior usage
6282
+ relevantContext: z.any(),
6283
+ // Array of full retrieval result objects
6284
+ sources: z.array(
6285
+ z.object({
6286
+ id: z.string(),
6287
+ // Unique chunk/document identifier
6288
+ metadata: z.any(),
6289
+ // All metadata fields (document ID, etc.)
6290
+ vector: z.array(z.number()),
6291
+ // Embedding vector (if available)
6292
+ score: z.number(),
6293
+ // Similarity score for this retrieval
6294
+ document: z.string()
6295
+ // Full chunk/document text (if available)
6296
+ })
6297
+ )
6298
+ });
6299
+ var filterSchema = z.object({
6300
+ ...baseSchema,
6301
+ filter: z.coerce.string().describe(filterDescription)
6302
+ });
6276
6303
 
6277
6304
  // src/utils/convert-sources.ts
6278
6305
  var convertToSources = (results) => {
@@ -6325,39 +6352,11 @@ var createGraphRAGTool = ({
6325
6352
  const toolDescription = description || defaultGraphRagDescription();
6326
6353
  const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
6327
6354
  let isInitialized = false;
6328
- const baseSchema = {
6329
- queryText: z.string().describe(queryTextDescription),
6330
- topK: z.coerce.number().describe(topKDescription)
6331
- };
6332
- const inputSchema = enableFilter ? z.object({
6333
- ...baseSchema,
6334
- filter: z.coerce.string().describe(filterDescription)
6335
- }).passthrough() : z.object(baseSchema).passthrough();
6355
+ const inputSchema = enableFilter ? filterSchema : z.object(baseSchema).passthrough();
6336
6356
  return createTool({
6337
6357
  id: toolId,
6338
6358
  inputSchema,
6339
- // Output schema includes `sources`, which exposes the full set of retrieved chunks (QueryResult objects)
6340
- // Each source contains all information needed to reference
6341
- // the original document, chunk, and similarity score.
6342
- outputSchema: z.object({
6343
- // Array of metadata or content for compatibility with prior usage
6344
- relevantContext: z.any(),
6345
- // Array of full retrieval result objects
6346
- sources: z.array(
6347
- z.object({
6348
- id: z.string(),
6349
- // Unique chunk/document identifier
6350
- metadata: z.any(),
6351
- // All metadata fields (document ID, etc.)
6352
- vector: z.array(z.number()),
6353
- // Embedding vector (if available)
6354
- score: z.number(),
6355
- // Similarity score for this retrieval
6356
- document: z.string()
6357
- // Full chunk/document text (if available)
6358
- })
6359
- )
6360
- }),
6359
+ outputSchema,
6361
6360
  description: toolDescription,
6362
6361
  execute: async ({ context: { queryText, topK, filter }, mastra }) => {
6363
6362
  const logger = mastra?.getLogger();
@@ -6451,6 +6450,7 @@ var createGraphRAGTool = ({
6451
6450
  return { relevantContext: [], sources: [] };
6452
6451
  }
6453
6452
  }
6453
+ // Use any for output schema as the structure of the output causes type inference issues
6454
6454
  });
6455
6455
  };
6456
6456
  var createVectorQueryTool = ({
@@ -6466,39 +6466,11 @@ var createVectorQueryTool = ({
6466
6466
  }) => {
6467
6467
  const toolId = id || `VectorQuery ${vectorStoreName} ${indexName} Tool`;
6468
6468
  const toolDescription = description || defaultVectorQueryDescription();
6469
- const baseSchema = {
6470
- queryText: z.string().describe(queryTextDescription),
6471
- topK: z.coerce.number().describe(topKDescription)
6472
- };
6473
- const inputSchema = enableFilter ? z.object({
6474
- ...baseSchema,
6475
- filter: z.coerce.string().describe(filterDescription)
6476
- }).passthrough() : z.object(baseSchema).passthrough();
6469
+ const inputSchema = enableFilter ? filterSchema : z.object(baseSchema).passthrough();
6477
6470
  return createTool({
6478
6471
  id: toolId,
6479
6472
  inputSchema,
6480
- // Output schema includes `sources`, which exposes the full set of retrieved chunks (QueryResult objects)
6481
- // Each source contains all information needed to reference
6482
- // the original document, chunk, and similarity score.
6483
- outputSchema: z.object({
6484
- // Array of metadata or content for compatibility with prior usage
6485
- relevantContext: z.any(),
6486
- // Array of full retrieval result objects
6487
- sources: z.array(
6488
- z.object({
6489
- id: z.string(),
6490
- // Unique chunk/document identifier
6491
- metadata: z.any(),
6492
- // All metadata fields (document ID, etc.)
6493
- vector: z.array(z.number()),
6494
- // Embedding vector (if available)
6495
- score: z.number(),
6496
- // Similarity score for this retrieval
6497
- document: z.string()
6498
- // Full chunk/document text (if available)
6499
- })
6500
- )
6501
- }),
6473
+ outputSchema,
6502
6474
  description: toolDescription,
6503
6475
  execute: async ({ context: { queryText, topK, filter }, mastra }) => {
6504
6476
  const logger = mastra?.getLogger();
@@ -6585,6 +6557,7 @@ var createVectorQueryTool = ({
6585
6557
  return { relevantContext: [], sources: [] };
6586
6558
  }
6587
6559
  }
6560
+ // Use any for output schema as the structure of the output causes type inference issues
6588
6561
  });
6589
6562
  };
6590
6563
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/rag",
3
- "version": "0.10.1-alpha.0",
3
+ "version": "0.10.1-alpha.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",