@mastra/rag 1.2.2 → 1.2.3-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.
@@ -1 +1 @@
1
- {"version":3,"file":"graph-rag.d.ts","sourceRoot":"","sources":["../../src/tools/graph-rag.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnD,eAAO,MAAM,kBAAkB,GAAI,SAAS,mBAAmB,KA8IvD,OAAO;;;;;;;;;;;;;;;;;;;;;kCAAqB,GAAG,CACtC,CAAC"}
1
+ {"version":3,"file":"graph-rag.d.ts","sourceRoot":"","sources":["../../src/tools/graph-rag.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAGnD,eAAO,MAAM,kBAAkB,GAAI,SAAS,mBAAmB,KAiJvD,OAAO;;;;;;;;;;;;;;;;;;;;;kCAAqB,GAAG,CACtC,CAAC"}
@@ -1,5 +1,4 @@
1
- import type { MastraVector } from '@mastra/core/vector';
2
- import type { EmbeddingModel } from 'ai';
1
+ import type { MastraVector, MastraEmbeddingModel } from '@mastra/core/vector';
3
2
  import type { RerankConfig } from '../rerank/index.js';
4
3
  export interface PineconeConfig {
5
4
  namespace?: string;
@@ -47,14 +46,14 @@ export type VectorQueryToolOptions = {
47
46
  id?: string;
48
47
  description?: string;
49
48
  indexName: string;
50
- model: EmbeddingModel<string>;
49
+ model: MastraEmbeddingModel<string>;
51
50
  enableFilter?: boolean;
52
51
  includeVectors?: boolean;
53
52
  includeSources?: boolean;
54
53
  reranker?: RerankConfig;
55
54
  /** Database-specific configuration options */
56
55
  databaseConfig?: DatabaseConfig;
57
- } & ({
56
+ } & ProviderOptions & ({
58
57
  vectorStoreName: string;
59
58
  } | {
60
59
  vectorStoreName?: string;
@@ -65,7 +64,7 @@ export type GraphRagToolOptions = {
65
64
  description?: string;
66
65
  indexName: string;
67
66
  vectorStoreName: string;
68
- model: EmbeddingModel<string>;
67
+ model: MastraEmbeddingModel<string>;
69
68
  enableFilter?: boolean;
70
69
  includeSources?: boolean;
71
70
  graphOptions?: {
@@ -74,6 +73,20 @@ export type GraphRagToolOptions = {
74
73
  restartProb?: number;
75
74
  threshold?: number;
76
75
  };
76
+ } & ProviderOptions;
77
+ export type ProviderOptions = {
78
+ /**
79
+ * Provider-specific options for the embedding model (e.g., outputDimensionality).
80
+ *
81
+ * ⚠️ **IMPORTANT**: `providerOptions` only work with AI SDK v2 models.
82
+ *
83
+ * **For v1 models**: Configure options when creating the model:
84
+ * ✅ const model = openai.embedding('text-embedding-3-small', { dimensions: 512 });
85
+ *
86
+ * **For v2 models**: Use providerOptions:
87
+ * ✅ providerOptions: { openai: { dimensions: 512 } }
88
+ */
89
+ providerOptions?: Record<string, Record<string, any>>;
77
90
  };
78
91
  /**
79
92
  * Default options for GraphRAG
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACzC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE;QACb,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB,CAAC;CACH;AAED,MAAM,WAAW,cAAc;IAC7B,QAA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AAE,MAAM,CAAC;QACnB,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;CACH,GAAG,eAAe,CAAC;AAEpB,MAAM,MAAM,eAAe,GAAG;IAC5B;;;;;;;;;;OAUG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACvD,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB;;;;;CAK/B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"vector-query.d.ts","sourceRoot":"","sources":["../../src/tools/vector-query.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,qBAAqB,GAAI,SAAS,sBAAsB,KA2J7D,OAAO;;;;;;;;;;;;;;;;;;;;;kCAAqB,GAAG,CACtC,CAAC"}
1
+ {"version":3,"file":"vector-query.d.ts","sourceRoot":"","sources":["../../src/tools/vector-query.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAKxB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAExC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEtD,eAAO,MAAM,qBAAqB,GAAI,SAAS,sBAAsB,KA8J7D,OAAO;;;;;;;;;;;;;;;;;;;;;kCAAqB,GAAG,CACtC,CAAC"}
@@ -1,23 +1,22 @@
1
- import type { MastraVector, QueryResult } from '@mastra/core/vector';
1
+ import type { MastraVector, MastraEmbeddingModel, QueryResult } from '@mastra/core/vector';
2
2
  import type { VectorFilter } from '@mastra/core/vector/filter';
3
- import type { EmbeddingModel } from 'ai';
4
- import type { DatabaseConfig } from '../tools/types.js';
5
- interface VectorQuerySearchParams {
3
+ import type { DatabaseConfig, ProviderOptions } from '../tools/types.js';
4
+ type VectorQuerySearchParams = {
6
5
  indexName: string;
7
6
  vectorStore: MastraVector;
8
7
  queryText: string;
9
- model: EmbeddingModel<string>;
8
+ model: MastraEmbeddingModel<string>;
10
9
  queryFilter?: VectorFilter;
11
10
  topK: number;
12
11
  includeVectors?: boolean;
13
12
  maxRetries?: number;
14
13
  /** Database-specific configuration options */
15
14
  databaseConfig?: DatabaseConfig;
16
- }
15
+ } & ProviderOptions;
17
16
  interface VectorQuerySearchResult {
18
17
  results: QueryResult[];
19
18
  queryEmbedding: number[];
20
19
  }
21
- export declare const vectorQuerySearch: ({ indexName, vectorStore, queryText, model, queryFilter, topK, includeVectors, maxRetries, databaseConfig, }: VectorQuerySearchParams) => Promise<VectorQuerySearchResult>;
20
+ export declare const vectorQuerySearch: ({ indexName, vectorStore, queryText, model, queryFilter, topK, includeVectors, maxRetries, databaseConfig, providerOptions, }: VectorQuerySearchParams) => Promise<VectorQuerySearchResult>;
22
21
  export {};
23
22
  //# sourceMappingURL=vector-search.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vector-search.d.ts","sourceRoot":"","sources":["../../src/utils/vector-search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAqB,MAAM,qBAAqB,CAAC;AACxF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,IAAI,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAErD,UAAU,uBAAuB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,YAAY,CAAC;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAA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HAWrC,uBAAuB,KAAG,OAAO,CAAC,uBAAuB,CAiC3D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/rag",
3
- "version": "1.2.2",
3
+ "version": "1.2.3-alpha.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -46,9 +46,9 @@
46
46
  "typescript": "^5.8.3",
47
47
  "vitest": "^3.2.4",
48
48
  "zod": "^3.25.67",
49
+ "@internal/types-builder": "0.0.9",
49
50
  "@internal/lint": "0.0.34",
50
- "@mastra/core": "0.15.2",
51
- "@internal/types-builder": "0.0.9"
51
+ "@mastra/core": "0.15.3-alpha.1"
52
52
  },
53
53
  "keywords": [
54
54
  "rag",
@@ -39,6 +39,8 @@ export const createGraphRAGTool = (options: GraphRagToolOptions) => {
39
39
  const topK: number = runtimeContext.get('topK') ?? context.topK ?? 10;
40
40
  const filter: Record<string, any> = runtimeContext.get('filter') ?? context.filter;
41
41
  const queryText = context.queryText;
42
+ const providerOptions: Record<string, Record<string, any>> | undefined =
43
+ runtimeContext.get('providerOptions') ?? options.providerOptions;
42
44
 
43
45
  const enableFilter = !!runtimeContext.get('filter') || (options.enableFilter ?? false);
44
46
 
@@ -92,6 +94,7 @@ export const createGraphRAGTool = (options: GraphRagToolOptions) => {
92
94
  queryFilter: Object.keys(queryFilter || {}).length > 0 ? queryFilter : undefined,
93
95
  topK: topKValue,
94
96
  includeVectors: true,
97
+ providerOptions,
95
98
  });
96
99
  if (logger) {
97
100
  logger.debug('vectorQuerySearch returned results', { count: results.length });
@@ -1,5 +1,5 @@
1
- import type { MastraVector } from '@mastra/core/vector';
2
- import type { EmbeddingModel } from 'ai';
1
+ import type { MastraVector, MastraEmbeddingModel } from '@mastra/core/vector';
2
+
3
3
  import type { RerankConfig } from '../rerank';
4
4
 
5
5
  export interface PineconeConfig {
@@ -57,29 +57,30 @@ export type VectorQueryToolOptions = {
57
57
  id?: string;
58
58
  description?: string;
59
59
  indexName: string;
60
- model: EmbeddingModel<string>;
60
+ model: MastraEmbeddingModel<string>;
61
61
  enableFilter?: boolean;
62
62
  includeVectors?: boolean;
63
63
  includeSources?: boolean;
64
64
  reranker?: RerankConfig;
65
65
  /** Database-specific configuration options */
66
66
  databaseConfig?: DatabaseConfig;
67
- } & (
68
- | {
69
- vectorStoreName: string;
70
- }
71
- | {
72
- vectorStoreName?: string;
73
- vectorStore: MastraVector;
74
- }
75
- );
67
+ } & ProviderOptions &
68
+ (
69
+ | {
70
+ vectorStoreName: string;
71
+ }
72
+ | {
73
+ vectorStoreName?: string;
74
+ vectorStore: MastraVector;
75
+ }
76
+ );
76
77
 
77
78
  export type GraphRagToolOptions = {
78
79
  id?: string;
79
80
  description?: string;
80
81
  indexName: string;
81
82
  vectorStoreName: string;
82
- model: EmbeddingModel<string>;
83
+ model: MastraEmbeddingModel<string>;
83
84
  enableFilter?: boolean;
84
85
  includeSources?: boolean;
85
86
  graphOptions?: {
@@ -88,6 +89,21 @@ export type GraphRagToolOptions = {
88
89
  restartProb?: number;
89
90
  threshold?: number;
90
91
  };
92
+ } & ProviderOptions;
93
+
94
+ export type ProviderOptions = {
95
+ /**
96
+ * Provider-specific options for the embedding model (e.g., outputDimensionality).
97
+ *
98
+ * ⚠️ **IMPORTANT**: `providerOptions` only work with AI SDK v2 models.
99
+ *
100
+ * **For v1 models**: Configure options when creating the model:
101
+ * ✅ const model = openai.embedding('text-embedding-3-small', { dimensions: 512 });
102
+ *
103
+ * **For v2 models**: Use providerOptions:
104
+ * ✅ providerOptions: { openai: { dimensions: 512 } }
105
+ */
106
+ providerOptions?: Record<string, Record<string, any>>;
91
107
  };
92
108
 
93
109
  /**
@@ -415,4 +415,63 @@ describe('createVectorQueryTool', () => {
415
415
  expect(result.relevantContext[0]).toEqual({ text: 'bar' });
416
416
  });
417
417
  });
418
+
419
+ describe('providerOptions', () => {
420
+ it('should pass providerOptions to vectorQuerySearch', async () => {
421
+ const tool = createVectorQueryTool({
422
+ indexName: 'testIndex',
423
+ model: mockModel,
424
+ vectorStoreName: 'testStore',
425
+ providerOptions: { google: { outputDimensionality: 1536 } },
426
+ });
427
+
428
+ await tool.execute({
429
+ context: { queryText: 'foo', topK: 10 },
430
+ mastra: mockMastra as any,
431
+ runtimeContext: new RuntimeContext(),
432
+ });
433
+
434
+ expect(vectorQuerySearch).toHaveBeenCalledWith({
435
+ indexName: 'testIndex',
436
+ vectorStore: { testStore: {} },
437
+ queryText: 'foo',
438
+ model: mockModel,
439
+ queryFilter: undefined,
440
+ topK: 10,
441
+ includeVectors: false,
442
+ databaseConfig: undefined,
443
+ providerOptions: { google: { outputDimensionality: 1536 } },
444
+ });
445
+ });
446
+
447
+ it('should allow providerOptions override via runtimeContext', async () => {
448
+ const tool = createVectorQueryTool({
449
+ indexName: 'testIndex',
450
+ model: mockModel,
451
+ vectorStoreName: 'testStore',
452
+ providerOptions: { google: { outputDimensionality: 1536 } },
453
+ });
454
+
455
+ const runtimeContext = new RuntimeContext();
456
+ runtimeContext.set('providerOptions', { google: { outputDimensionality: 768 } });
457
+
458
+ await tool.execute({
459
+ context: { queryText: 'foo', topK: 10 },
460
+ mastra: mockMastra as any,
461
+ runtimeContext,
462
+ });
463
+
464
+ expect(vectorQuerySearch).toHaveBeenCalledWith({
465
+ indexName: 'testIndex',
466
+ vectorStore: { testStore: {} },
467
+ queryText: 'foo',
468
+ model: mockModel,
469
+ queryFilter: undefined,
470
+ topK: 10,
471
+ includeVectors: false,
472
+ databaseConfig: undefined,
473
+ providerOptions: { google: { outputDimensionality: 768 } },
474
+ });
475
+ });
476
+ });
418
477
  });
@@ -1,6 +1,5 @@
1
1
  import { createTool } from '@mastra/core/tools';
2
- import type { MastraVector } from '@mastra/core/vector';
3
- import type { EmbeddingModel } from 'ai';
2
+ import type { MastraVector, MastraEmbeddingModel } from '@mastra/core/vector';
4
3
  import { z } from 'zod';
5
4
 
6
5
  import { rerank, rerankWithScorer } from '../rerank';
@@ -31,7 +30,9 @@ export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
31
30
  const includeSources: boolean = runtimeContext.get('includeSources') ?? options.includeSources ?? true;
32
31
  const reranker: RerankConfig = runtimeContext.get('reranker') ?? options.reranker;
33
32
  const databaseConfig = runtimeContext.get('databaseConfig') ?? options.databaseConfig;
34
- const model: EmbeddingModel<string> = runtimeContext.get('model') ?? options.model;
33
+ const model: MastraEmbeddingModel<string> = runtimeContext.get('model') ?? options.model;
34
+ const providerOptions: Record<string, Record<string, any>> | undefined =
35
+ runtimeContext.get('providerOptions') ?? options.providerOptions;
35
36
 
36
37
  if (!indexName) throw new Error(`indexName is required, got: ${indexName}`);
37
38
  if (!vectorStoreName) throw new Error(`vectorStoreName is required, got: ${vectorStoreName}`); // won't fire
@@ -98,6 +99,7 @@ export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
98
99
  topK: topKValue,
99
100
  includeVectors,
100
101
  databaseConfig,
102
+ providerOptions,
101
103
  });
102
104
  if (logger) {
103
105
  logger.debug('vectorQuerySearch returned results', { count: results.length });
@@ -1,21 +1,20 @@
1
- import type { MastraVector, QueryResult, QueryVectorParams } from '@mastra/core/vector';
1
+ import type { MastraVector, MastraEmbeddingModel, QueryResult, QueryVectorParams } from '@mastra/core/vector';
2
+ import { embedV1, embedV2 } from '@mastra/core/vector';
2
3
  import type { VectorFilter } from '@mastra/core/vector/filter';
3
- import { embed } from 'ai';
4
- import type { EmbeddingModel } from 'ai';
5
- import type { DatabaseConfig } from '../tools/types';
4
+ import type { DatabaseConfig, ProviderOptions } from '../tools/types';
6
5
 
7
- interface VectorQuerySearchParams {
6
+ type VectorQuerySearchParams = {
8
7
  indexName: string;
9
8
  vectorStore: MastraVector;
10
9
  queryText: string;
11
- model: EmbeddingModel<string>;
10
+ model: MastraEmbeddingModel<string>;
12
11
  queryFilter?: VectorFilter;
13
12
  topK: number;
14
13
  includeVectors?: boolean;
15
14
  maxRetries?: number;
16
15
  /** Database-specific configuration options */
17
16
  databaseConfig?: DatabaseConfig;
18
- }
17
+ } & ProviderOptions;
19
18
 
20
19
  interface VectorQuerySearchResult {
21
20
  results: QueryResult[];
@@ -41,12 +40,26 @@ export const vectorQuerySearch = async ({
41
40
  includeVectors = false,
42
41
  maxRetries = 2,
43
42
  databaseConfig = {},
43
+ providerOptions,
44
44
  }: VectorQuerySearchParams): Promise<VectorQuerySearchResult> => {
45
- const { embedding } = await embed({
46
- value: queryText,
47
- model,
48
- maxRetries,
49
- });
45
+ let embeddingResult;
46
+
47
+ if (model.specificationVersion === 'v2') {
48
+ embeddingResult = await embedV2({
49
+ model: model,
50
+ value: queryText,
51
+ maxRetries,
52
+ ...(providerOptions && { providerOptions }),
53
+ });
54
+ } else {
55
+ embeddingResult = await embedV1({
56
+ value: queryText,
57
+ model: model,
58
+ maxRetries,
59
+ });
60
+ }
61
+
62
+ const embedding = embeddingResult.embedding;
50
63
 
51
64
  // Build query parameters with database-specific configurations
52
65
  const queryParams: QueryVectorParams = {