@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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/rag@0.10.1-alpha.0 build /home/runner/work/mastra/mastra/packages/rag
2
+ > @mastra/rag@0.10.1-alpha.1 build /home/runner/work/mastra/mastra/packages/rag
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 17241ms
9
+ TSC ⚡️ Build success in 15915ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/packages/rag/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/packages/rag/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 16153ms
16
+ DTS ⚡️ Build success in 14168ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- CJS dist/index.cjs 240.87 KB
21
- CJS ⚡️ Build success in 4013ms
22
- ESM dist/index.js 239.11 KB
23
- ESM ⚡️ Build success in 4026ms
20
+ CJS dist/index.cjs 239.65 KB
21
+ CJS ⚡️ Build success in 4626ms
22
+ ESM dist/index.js 237.94 KB
23
+ ESM ⚡️ Build success in 4627ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mastra/rag
2
2
 
3
+ ## 0.10.1-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f56fd29: added return type for vector-query and graph-rag
8
+
3
9
  ## 0.10.1-alpha.0
4
10
 
5
11
  ### Patch Changes
@@ -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
  }