@mastra/rag 1.0.4 → 1.0.5-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.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +26 -0
- package/dist/_tsup-dts-rollup.d.cts +6 -2
- package/dist/_tsup-dts-rollup.d.ts +6 -2
- package/dist/index.cjs +10 -4
- package/dist/index.js +10 -4
- package/package.json +5 -5
- package/src/tools/types.ts +10 -2
- package/src/tools/vector-query.test.ts +87 -0
- package/src/tools/vector-query.ts +13 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/rag@1.0.
|
|
2
|
+
> @mastra/rag@1.0.5-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
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 15061ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/rag/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/rag/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 14790ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m248.
|
|
21
|
-
[32mCJS[39m ⚡️ Build success in
|
|
22
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
23
|
-
[32mESM[39m ⚡️ Build success in
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m248.32 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 5123ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m246.24 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 5124ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @mastra/rag
|
|
2
2
|
|
|
3
|
+
## 1.0.5-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- f42c4c2: update peer deps for packages to latest core range
|
|
8
|
+
- @mastra/core@0.12.0-alpha.5
|
|
9
|
+
|
|
10
|
+
## 1.0.5-alpha.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- fc437d9: dependencies updates:
|
|
15
|
+
- Updated dependency [`node-html-better-parser@^1.5.1` ↗︎](https://www.npmjs.com/package/node-html-better-parser/v/1.5.1) (from `^1.4.11`, in `dependencies`)
|
|
16
|
+
- b5a6da2: Allow vector query tool to be used without a Mastra server
|
|
17
|
+
- Updated dependencies [510e2c8]
|
|
18
|
+
- Updated dependencies [2f72fb2]
|
|
19
|
+
- Updated dependencies [3f89307]
|
|
20
|
+
- Updated dependencies [9eda7d4]
|
|
21
|
+
- Updated dependencies [9d49408]
|
|
22
|
+
- Updated dependencies [2ecf658]
|
|
23
|
+
- Updated dependencies [7a7754f]
|
|
24
|
+
- Updated dependencies [fc92d80]
|
|
25
|
+
- Updated dependencies [23a6a7c]
|
|
26
|
+
- Updated dependencies [09bca64]
|
|
27
|
+
- @mastra/core@0.12.0-alpha.0
|
|
28
|
+
|
|
3
29
|
## 1.0.4
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
|
@@ -1264,7 +1264,6 @@ export declare type VectorQueryToolOptions = {
|
|
|
1264
1264
|
id?: string;
|
|
1265
1265
|
description?: string;
|
|
1266
1266
|
indexName: string;
|
|
1267
|
-
vectorStoreName: string;
|
|
1268
1267
|
model: EmbeddingModel<string>;
|
|
1269
1268
|
enableFilter?: boolean;
|
|
1270
1269
|
includeVectors?: boolean;
|
|
@@ -1272,7 +1271,12 @@ export declare type VectorQueryToolOptions = {
|
|
|
1272
1271
|
reranker?: RerankConfig;
|
|
1273
1272
|
/** Database-specific configuration options */
|
|
1274
1273
|
databaseConfig?: DatabaseConfig;
|
|
1275
|
-
}
|
|
1274
|
+
} & ({
|
|
1275
|
+
vectorStoreName: string;
|
|
1276
|
+
} | {
|
|
1277
|
+
vectorStoreName?: string;
|
|
1278
|
+
vectorStore: MastraVector;
|
|
1279
|
+
});
|
|
1276
1280
|
|
|
1277
1281
|
declare type WeightConfig = {
|
|
1278
1282
|
semantic?: number;
|
|
@@ -1264,7 +1264,6 @@ export declare type VectorQueryToolOptions = {
|
|
|
1264
1264
|
id?: string;
|
|
1265
1265
|
description?: string;
|
|
1266
1266
|
indexName: string;
|
|
1267
|
-
vectorStoreName: string;
|
|
1268
1267
|
model: EmbeddingModel<string>;
|
|
1269
1268
|
enableFilter?: boolean;
|
|
1270
1269
|
includeVectors?: boolean;
|
|
@@ -1272,7 +1271,12 @@ export declare type VectorQueryToolOptions = {
|
|
|
1272
1271
|
reranker?: RerankConfig;
|
|
1273
1272
|
/** Database-specific configuration options */
|
|
1274
1273
|
databaseConfig?: DatabaseConfig;
|
|
1275
|
-
}
|
|
1274
|
+
} & ({
|
|
1275
|
+
vectorStoreName: string;
|
|
1276
|
+
} | {
|
|
1277
|
+
vectorStoreName?: string;
|
|
1278
|
+
vectorStore: MastraVector;
|
|
1279
|
+
});
|
|
1276
1280
|
|
|
1277
1281
|
declare type WeightConfig = {
|
|
1278
1282
|
semantic?: number;
|
package/dist/index.cjs
CHANGED
|
@@ -735,7 +735,7 @@ var customAlphabet = (alphabet, defaultSize = 21) => {
|
|
|
735
735
|
};
|
|
736
736
|
};
|
|
737
737
|
|
|
738
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@2.2.8_zod@3.25.
|
|
738
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@2.2.8_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
739
739
|
var import_secure_json_parse = __toESM(require_secure_json_parse());
|
|
740
740
|
function combineHeaders(...headers) {
|
|
741
741
|
return headers.reduce(
|
|
@@ -6672,7 +6672,8 @@ var createGraphRAGTool = (options) => {
|
|
|
6672
6672
|
};
|
|
6673
6673
|
var createVectorQueryTool = (options) => {
|
|
6674
6674
|
const { id, description } = options;
|
|
6675
|
-
const
|
|
6675
|
+
const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
|
|
6676
|
+
const toolId = id || `VectorQuery ${storeName} ${options.indexName} Tool`;
|
|
6676
6677
|
const toolDescription = description || defaultVectorQueryDescription();
|
|
6677
6678
|
const inputSchema = options.enableFilter ? filterSchema : zod.z.object(baseSchema).passthrough();
|
|
6678
6679
|
return tools.createTool({
|
|
@@ -6682,7 +6683,7 @@ var createVectorQueryTool = (options) => {
|
|
|
6682
6683
|
outputSchema,
|
|
6683
6684
|
execute: async ({ context, mastra, runtimeContext }) => {
|
|
6684
6685
|
const indexName = runtimeContext.get("indexName") ?? options.indexName;
|
|
6685
|
-
const vectorStoreName = runtimeContext.get("vectorStoreName") ??
|
|
6686
|
+
const vectorStoreName = "vectorStore" in options ? storeName : runtimeContext.get("vectorStoreName") ?? storeName;
|
|
6686
6687
|
const includeVectors = runtimeContext.get("includeVectors") ?? options.includeVectors ?? false;
|
|
6687
6688
|
const includeSources = runtimeContext.get("includeSources") ?? options.includeSources ?? true;
|
|
6688
6689
|
const reranker = runtimeContext.get("reranker") ?? options.reranker;
|
|
@@ -6705,7 +6706,12 @@ var createVectorQueryTool = (options) => {
|
|
|
6705
6706
|
}
|
|
6706
6707
|
try {
|
|
6707
6708
|
const topKValue = typeof topK === "number" && !isNaN(topK) ? topK : typeof topK === "string" && !isNaN(Number(topK)) ? Number(topK) : 10;
|
|
6708
|
-
|
|
6709
|
+
let vectorStore = void 0;
|
|
6710
|
+
if ("vectorStore" in options) {
|
|
6711
|
+
vectorStore = options.vectorStore;
|
|
6712
|
+
} else if (mastra) {
|
|
6713
|
+
vectorStore = mastra.getVector(vectorStoreName);
|
|
6714
|
+
}
|
|
6709
6715
|
if (!vectorStore) {
|
|
6710
6716
|
if (logger) {
|
|
6711
6717
|
logger.error("Vector store not found", { vectorStoreName });
|
package/dist/index.js
CHANGED
|
@@ -729,7 +729,7 @@ var customAlphabet = (alphabet, defaultSize = 21) => {
|
|
|
729
729
|
};
|
|
730
730
|
};
|
|
731
731
|
|
|
732
|
-
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@2.2.8_zod@3.25.
|
|
732
|
+
// ../../node_modules/.pnpm/@ai-sdk+provider-utils@2.2.8_zod@3.25.76/node_modules/@ai-sdk/provider-utils/dist/index.mjs
|
|
733
733
|
var import_secure_json_parse = __toESM(require_secure_json_parse());
|
|
734
734
|
function combineHeaders(...headers) {
|
|
735
735
|
return headers.reduce(
|
|
@@ -6666,7 +6666,8 @@ var createGraphRAGTool = (options) => {
|
|
|
6666
6666
|
};
|
|
6667
6667
|
var createVectorQueryTool = (options) => {
|
|
6668
6668
|
const { id, description } = options;
|
|
6669
|
-
const
|
|
6669
|
+
const storeName = options["vectorStoreName"] ? options.vectorStoreName : "DirectVectorStore";
|
|
6670
|
+
const toolId = id || `VectorQuery ${storeName} ${options.indexName} Tool`;
|
|
6670
6671
|
const toolDescription = description || defaultVectorQueryDescription();
|
|
6671
6672
|
const inputSchema = options.enableFilter ? filterSchema : z.object(baseSchema).passthrough();
|
|
6672
6673
|
return createTool({
|
|
@@ -6676,7 +6677,7 @@ var createVectorQueryTool = (options) => {
|
|
|
6676
6677
|
outputSchema,
|
|
6677
6678
|
execute: async ({ context, mastra, runtimeContext }) => {
|
|
6678
6679
|
const indexName = runtimeContext.get("indexName") ?? options.indexName;
|
|
6679
|
-
const vectorStoreName = runtimeContext.get("vectorStoreName") ??
|
|
6680
|
+
const vectorStoreName = "vectorStore" in options ? storeName : runtimeContext.get("vectorStoreName") ?? storeName;
|
|
6680
6681
|
const includeVectors = runtimeContext.get("includeVectors") ?? options.includeVectors ?? false;
|
|
6681
6682
|
const includeSources = runtimeContext.get("includeSources") ?? options.includeSources ?? true;
|
|
6682
6683
|
const reranker = runtimeContext.get("reranker") ?? options.reranker;
|
|
@@ -6699,7 +6700,12 @@ var createVectorQueryTool = (options) => {
|
|
|
6699
6700
|
}
|
|
6700
6701
|
try {
|
|
6701
6702
|
const topKValue = typeof topK === "number" && !isNaN(topK) ? topK : typeof topK === "string" && !isNaN(Number(topK)) ? Number(topK) : 10;
|
|
6702
|
-
|
|
6703
|
+
let vectorStore = void 0;
|
|
6704
|
+
if ("vectorStore" in options) {
|
|
6705
|
+
vectorStore = options.vectorStore;
|
|
6706
|
+
} else if (mastra) {
|
|
6707
|
+
vectorStore = mastra.getVector(vectorStoreName);
|
|
6708
|
+
}
|
|
6703
6709
|
if (!vectorStore) {
|
|
6704
6710
|
if (logger) {
|
|
6705
6711
|
logger.error("Vector store not found", { vectorStoreName });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/rag",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5-alpha.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"@paralleldrive/cuid2": "^2.2.2",
|
|
25
25
|
"big.js": "^7.0.1",
|
|
26
26
|
"js-tiktoken": "^1.0.20",
|
|
27
|
-
"node-html-better-parser": "^1.
|
|
27
|
+
"node-html-better-parser": "^1.5.1",
|
|
28
28
|
"pathe": "^2.0.3",
|
|
29
29
|
"zeroentropy": "0.1.0-alpha.6",
|
|
30
30
|
"zod": "^3.25.67"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@mastra/core": ">=0.10.0-0 <0.
|
|
33
|
+
"@mastra/core": ">=0.10.0-0 <0.13.0-0",
|
|
34
34
|
"ai": "^4.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"tsup": "^8.5.0",
|
|
46
46
|
"typescript": "^5.8.3",
|
|
47
47
|
"vitest": "^3.2.4",
|
|
48
|
-
"@internal/lint": "0.0.
|
|
49
|
-
"@mastra/core": "0.
|
|
48
|
+
"@internal/lint": "0.0.23",
|
|
49
|
+
"@mastra/core": "0.12.0-alpha.5"
|
|
50
50
|
},
|
|
51
51
|
"keywords": [
|
|
52
52
|
"rag",
|
package/src/tools/types.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MastraVector } from '@mastra/core/vector';
|
|
1
2
|
import type { EmbeddingModel } from 'ai';
|
|
2
3
|
import type { RerankConfig } from '../rerank';
|
|
3
4
|
|
|
@@ -56,7 +57,6 @@ export type VectorQueryToolOptions = {
|
|
|
56
57
|
id?: string;
|
|
57
58
|
description?: string;
|
|
58
59
|
indexName: string;
|
|
59
|
-
vectorStoreName: string;
|
|
60
60
|
model: EmbeddingModel<string>;
|
|
61
61
|
enableFilter?: boolean;
|
|
62
62
|
includeVectors?: boolean;
|
|
@@ -64,7 +64,15 @@ export type VectorQueryToolOptions = {
|
|
|
64
64
|
reranker?: RerankConfig;
|
|
65
65
|
/** Database-specific configuration options */
|
|
66
66
|
databaseConfig?: DatabaseConfig;
|
|
67
|
-
}
|
|
67
|
+
} & (
|
|
68
|
+
| {
|
|
69
|
+
vectorStoreName: string;
|
|
70
|
+
}
|
|
71
|
+
| {
|
|
72
|
+
vectorStoreName?: string;
|
|
73
|
+
vectorStore: MastraVector;
|
|
74
|
+
}
|
|
75
|
+
);
|
|
68
76
|
|
|
69
77
|
export type GraphRagToolOptions = {
|
|
70
78
|
id?: string;
|
|
@@ -262,6 +262,93 @@ describe('createVectorQueryTool', () => {
|
|
|
262
262
|
}),
|
|
263
263
|
);
|
|
264
264
|
});
|
|
265
|
+
|
|
266
|
+
it('Returns early when no Mastra server or vector store is provided', async () => {
|
|
267
|
+
const tool = createVectorQueryTool({
|
|
268
|
+
id: 'test',
|
|
269
|
+
model: mockModel,
|
|
270
|
+
indexName: 'testIndex',
|
|
271
|
+
vectorStoreName: 'testStore',
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
const runtimeContext = new RuntimeContext();
|
|
275
|
+
const result = await tool.execute({
|
|
276
|
+
context: { queryText: 'foo', topK: 1 },
|
|
277
|
+
runtimeContext,
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
expect(result).toEqual({ relevantContext: [], sources: [] });
|
|
281
|
+
expect(vectorQuerySearch).not.toHaveBeenCalled();
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('works without a mastra server if a vector store is passed as an argument', async () => {
|
|
285
|
+
const testStore = {
|
|
286
|
+
testStore: {},
|
|
287
|
+
};
|
|
288
|
+
const tool = createVectorQueryTool({
|
|
289
|
+
id: 'test',
|
|
290
|
+
model: mockModel,
|
|
291
|
+
indexName: 'testIndex',
|
|
292
|
+
vectorStoreName: 'testStore',
|
|
293
|
+
vectorStore: testStore as any,
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
const runtimeContext = new RuntimeContext();
|
|
297
|
+
const result = await tool.execute({
|
|
298
|
+
context: { queryText: 'foo', topK: 1 },
|
|
299
|
+
runtimeContext,
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
expect(result.relevantContext[0]).toEqual({ text: 'foo' });
|
|
303
|
+
expect(vectorQuerySearch).toHaveBeenCalledWith(
|
|
304
|
+
expect.objectContaining({
|
|
305
|
+
databaseConfig: undefined,
|
|
306
|
+
indexName: 'testIndex',
|
|
307
|
+
vectorStore: {
|
|
308
|
+
testStore: {},
|
|
309
|
+
},
|
|
310
|
+
queryText: 'foo',
|
|
311
|
+
model: mockModel,
|
|
312
|
+
queryFilter: undefined,
|
|
313
|
+
topK: 1,
|
|
314
|
+
}),
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('prefers the passed vector store over one from a passed Mastra server', async () => {
|
|
319
|
+
const thirdStore = {
|
|
320
|
+
thirdStore: {},
|
|
321
|
+
};
|
|
322
|
+
const tool = createVectorQueryTool({
|
|
323
|
+
id: 'test',
|
|
324
|
+
model: mockModel,
|
|
325
|
+
indexName: 'testIndex',
|
|
326
|
+
vectorStoreName: 'thirdStore',
|
|
327
|
+
vectorStore: thirdStore as any,
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
const runtimeContext = new RuntimeContext();
|
|
331
|
+
const result = await tool.execute({
|
|
332
|
+
context: { queryText: 'foo', topK: 1 },
|
|
333
|
+
mastra: mockMastra as any,
|
|
334
|
+
runtimeContext,
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
expect(result.relevantContext[0]).toEqual({ text: 'foo' });
|
|
338
|
+
expect(vectorQuerySearch).toHaveBeenCalledWith(
|
|
339
|
+
expect.objectContaining({
|
|
340
|
+
databaseConfig: undefined,
|
|
341
|
+
indexName: 'testIndex',
|
|
342
|
+
vectorStore: {
|
|
343
|
+
thirdStore: {},
|
|
344
|
+
},
|
|
345
|
+
queryText: 'foo',
|
|
346
|
+
model: mockModel,
|
|
347
|
+
queryFilter: undefined,
|
|
348
|
+
topK: 1,
|
|
349
|
+
}),
|
|
350
|
+
);
|
|
351
|
+
});
|
|
265
352
|
});
|
|
266
353
|
|
|
267
354
|
describe('runtimeContext', () => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createTool } from '@mastra/core/tools';
|
|
2
|
+
import type { MastraVector } from '@mastra/core/vector';
|
|
2
3
|
import type { EmbeddingModel } from 'ai';
|
|
3
4
|
import { z } from 'zod';
|
|
4
5
|
|
|
@@ -11,7 +12,9 @@ import type { VectorQueryToolOptions } from './types';
|
|
|
11
12
|
|
|
12
13
|
export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
|
|
13
14
|
const { id, description } = options;
|
|
14
|
-
const
|
|
15
|
+
const storeName = options['vectorStoreName'] ? options.vectorStoreName : 'DirectVectorStore';
|
|
16
|
+
|
|
17
|
+
const toolId = id || `VectorQuery ${storeName} ${options.indexName} Tool`;
|
|
15
18
|
const toolDescription = description || defaultVectorQueryDescription();
|
|
16
19
|
const inputSchema = options.enableFilter ? filterSchema : z.object(baseSchema).passthrough();
|
|
17
20
|
|
|
@@ -22,7 +25,8 @@ export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
|
|
|
22
25
|
outputSchema,
|
|
23
26
|
execute: async ({ context, mastra, runtimeContext }) => {
|
|
24
27
|
const indexName: string = runtimeContext.get('indexName') ?? options.indexName;
|
|
25
|
-
const vectorStoreName: string =
|
|
28
|
+
const vectorStoreName: string =
|
|
29
|
+
'vectorStore' in options ? storeName : (runtimeContext.get('vectorStoreName') ?? storeName);
|
|
26
30
|
const includeVectors: boolean = runtimeContext.get('includeVectors') ?? options.includeVectors ?? false;
|
|
27
31
|
const includeSources: boolean = runtimeContext.get('includeSources') ?? options.includeSources ?? true;
|
|
28
32
|
const reranker: RerankConfig = runtimeContext.get('reranker') ?? options.reranker;
|
|
@@ -30,7 +34,7 @@ export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
|
|
|
30
34
|
const model: EmbeddingModel<string> = runtimeContext.get('model') ?? options.model;
|
|
31
35
|
|
|
32
36
|
if (!indexName) throw new Error(`indexName is required, got: ${indexName}`);
|
|
33
|
-
if (!vectorStoreName) throw new Error(`vectorStoreName is required, got: ${vectorStoreName}`);
|
|
37
|
+
if (!vectorStoreName) throw new Error(`vectorStoreName is required, got: ${vectorStoreName}`); // won't fire
|
|
34
38
|
|
|
35
39
|
const topK: number = runtimeContext.get('topK') ?? context.topK ?? 10;
|
|
36
40
|
const filter: Record<string, any> = runtimeContext.get('filter') ?? context.filter;
|
|
@@ -54,8 +58,12 @@ export const createVectorQueryTool = (options: VectorQueryToolOptions) => {
|
|
|
54
58
|
? Number(topK)
|
|
55
59
|
: 10;
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
|
|
61
|
+
let vectorStore: MastraVector | undefined = undefined;
|
|
62
|
+
if ('vectorStore' in options) {
|
|
63
|
+
vectorStore = options.vectorStore;
|
|
64
|
+
} else if (mastra) {
|
|
65
|
+
vectorStore = mastra.getVector(vectorStoreName);
|
|
66
|
+
}
|
|
59
67
|
if (!vectorStore) {
|
|
60
68
|
if (logger) {
|
|
61
69
|
logger.error('Vector store not found', { vectorStoreName });
|