@mastra/rag 0.1.13-alpha.0 → 0.1.13-alpha.2
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 +13 -0
- package/dist/index.cjs +16 -14
- package/dist/index.js +16 -14
- package/package.json +2 -2
- package/src/tools/graph-rag.ts +8 -7
- package/src/tools/vector-query.test.ts +11 -14
- package/src/tools/vector-query.ts +8 -7
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/rag@0.1.13-alpha.
|
|
2
|
+
> @mastra/rag@0.1.13-alpha.2 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.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 27290ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.2
|
|
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.2
|
|
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 36864ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[32m92.
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m92.31 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 1806ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m93.03 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 1806ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mastra/rag
|
|
2
2
|
|
|
3
|
+
## 0.1.13-alpha.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- ac30427: Updated inputschema for vectorquery tool
|
|
8
|
+
|
|
9
|
+
## 0.1.13-alpha.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [6794797]
|
|
14
|
+
- @mastra/core@0.6.4-alpha.1
|
|
15
|
+
|
|
3
16
|
## 0.1.13-alpha.0
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -1878,11 +1878,11 @@ var createGraphRAGTool = ({
|
|
|
1878
1878
|
let isInitialized = false;
|
|
1879
1879
|
const baseSchema = {
|
|
1880
1880
|
queryText: zod.z.string().describe(queryTextDescription),
|
|
1881
|
-
topK: zod.z.
|
|
1881
|
+
topK: zod.z.coerce.number().describe(topKDescription)
|
|
1882
1882
|
};
|
|
1883
1883
|
const inputSchema = enableFilter ? zod.z.object({
|
|
1884
1884
|
...baseSchema,
|
|
1885
|
-
filter: zod.z.string().describe(filterDescription)
|
|
1885
|
+
filter: zod.z.coerce.string().describe(filterDescription)
|
|
1886
1886
|
}).passthrough() : zod.z.object(baseSchema).passthrough();
|
|
1887
1887
|
return tools.createTool({
|
|
1888
1888
|
id: toolId,
|
|
@@ -1893,7 +1893,8 @@ var createGraphRAGTool = ({
|
|
|
1893
1893
|
description: toolDescription,
|
|
1894
1894
|
execute: async ({ context: { queryText, topK, filter }, mastra }) => {
|
|
1895
1895
|
const topKValue = typeof topK === "number" && !isNaN(topK) ? topK : typeof topK === "string" && !isNaN(Number(topK)) ? Number(topK) : 10;
|
|
1896
|
-
const vectorStore = mastra?.
|
|
1896
|
+
const vectorStore = mastra?.getVector(vectorStoreName);
|
|
1897
|
+
const logger = mastra?.getLogger();
|
|
1897
1898
|
if (vectorStore) {
|
|
1898
1899
|
let queryFilter = {};
|
|
1899
1900
|
if (enableFilter) {
|
|
@@ -1901,15 +1902,15 @@ var createGraphRAGTool = ({
|
|
|
1901
1902
|
try {
|
|
1902
1903
|
return typeof filter === "string" ? JSON.parse(filter) : filter;
|
|
1903
1904
|
} catch (error) {
|
|
1904
|
-
if (
|
|
1905
|
-
|
|
1905
|
+
if (logger) {
|
|
1906
|
+
logger.warn("Failed to parse filter as JSON, using empty filter", { filter, error });
|
|
1906
1907
|
}
|
|
1907
1908
|
return {};
|
|
1908
1909
|
}
|
|
1909
1910
|
})();
|
|
1910
1911
|
}
|
|
1911
|
-
if (
|
|
1912
|
-
|
|
1912
|
+
if (logger) {
|
|
1913
|
+
logger.debug("Using this filter and topK:", { queryFilter, topK: topKValue });
|
|
1913
1914
|
}
|
|
1914
1915
|
const { results, queryEmbedding } = await vectorQuerySearch({
|
|
1915
1916
|
indexName,
|
|
@@ -1961,11 +1962,11 @@ var createVectorQueryTool = ({
|
|
|
1961
1962
|
const toolDescription = description || defaultVectorQueryDescription();
|
|
1962
1963
|
const baseSchema = {
|
|
1963
1964
|
queryText: zod.z.string().describe(queryTextDescription),
|
|
1964
|
-
topK: zod.z.
|
|
1965
|
+
topK: zod.z.coerce.number().describe(topKDescription)
|
|
1965
1966
|
};
|
|
1966
1967
|
const inputSchema = enableFilter ? zod.z.object({
|
|
1967
1968
|
...baseSchema,
|
|
1968
|
-
filter: zod.z.string().describe(filterDescription)
|
|
1969
|
+
filter: zod.z.coerce.string().describe(filterDescription)
|
|
1969
1970
|
}).passthrough() : zod.z.object(baseSchema).passthrough();
|
|
1970
1971
|
return tools.createTool({
|
|
1971
1972
|
id: toolId,
|
|
@@ -1976,7 +1977,8 @@ var createVectorQueryTool = ({
|
|
|
1976
1977
|
description: toolDescription,
|
|
1977
1978
|
execute: async ({ context: { queryText, topK, filter }, mastra }) => {
|
|
1978
1979
|
const topKValue = typeof topK === "number" && !isNaN(topK) ? topK : typeof topK === "string" && !isNaN(Number(topK)) ? Number(topK) : 10;
|
|
1979
|
-
const vectorStore = mastra?.
|
|
1980
|
+
const vectorStore = mastra?.getVector(vectorStoreName);
|
|
1981
|
+
const logger = mastra?.getLogger();
|
|
1980
1982
|
if (vectorStore) {
|
|
1981
1983
|
let queryFilter = {};
|
|
1982
1984
|
if (enableFilter && filter) {
|
|
@@ -1984,15 +1986,15 @@ var createVectorQueryTool = ({
|
|
|
1984
1986
|
try {
|
|
1985
1987
|
return typeof filter === "string" ? JSON.parse(filter) : filter;
|
|
1986
1988
|
} catch (error) {
|
|
1987
|
-
if (
|
|
1988
|
-
|
|
1989
|
+
if (logger) {
|
|
1990
|
+
logger.warn("Failed to parse filter as JSON, using empty filter", { filter, error });
|
|
1989
1991
|
}
|
|
1990
1992
|
return {};
|
|
1991
1993
|
}
|
|
1992
1994
|
})();
|
|
1993
1995
|
}
|
|
1994
|
-
if (
|
|
1995
|
-
|
|
1996
|
+
if (logger) {
|
|
1997
|
+
logger.debug("Using this filter and topK:", { queryFilter, topK: topKValue });
|
|
1996
1998
|
}
|
|
1997
1999
|
const { results } = await vectorQuerySearch({
|
|
1998
2000
|
indexName,
|
package/dist/index.js
CHANGED
|
@@ -1876,11 +1876,11 @@ var createGraphRAGTool = ({
|
|
|
1876
1876
|
let isInitialized = false;
|
|
1877
1877
|
const baseSchema = {
|
|
1878
1878
|
queryText: z.string().describe(queryTextDescription),
|
|
1879
|
-
topK: z.
|
|
1879
|
+
topK: z.coerce.number().describe(topKDescription)
|
|
1880
1880
|
};
|
|
1881
1881
|
const inputSchema = enableFilter ? z.object({
|
|
1882
1882
|
...baseSchema,
|
|
1883
|
-
filter: z.string().describe(filterDescription)
|
|
1883
|
+
filter: z.coerce.string().describe(filterDescription)
|
|
1884
1884
|
}).passthrough() : z.object(baseSchema).passthrough();
|
|
1885
1885
|
return createTool({
|
|
1886
1886
|
id: toolId,
|
|
@@ -1891,7 +1891,8 @@ var createGraphRAGTool = ({
|
|
|
1891
1891
|
description: toolDescription,
|
|
1892
1892
|
execute: async ({ context: { queryText, topK, filter }, mastra }) => {
|
|
1893
1893
|
const topKValue = typeof topK === "number" && !isNaN(topK) ? topK : typeof topK === "string" && !isNaN(Number(topK)) ? Number(topK) : 10;
|
|
1894
|
-
const vectorStore = mastra?.
|
|
1894
|
+
const vectorStore = mastra?.getVector(vectorStoreName);
|
|
1895
|
+
const logger = mastra?.getLogger();
|
|
1895
1896
|
if (vectorStore) {
|
|
1896
1897
|
let queryFilter = {};
|
|
1897
1898
|
if (enableFilter) {
|
|
@@ -1899,15 +1900,15 @@ var createGraphRAGTool = ({
|
|
|
1899
1900
|
try {
|
|
1900
1901
|
return typeof filter === "string" ? JSON.parse(filter) : filter;
|
|
1901
1902
|
} catch (error) {
|
|
1902
|
-
if (
|
|
1903
|
-
|
|
1903
|
+
if (logger) {
|
|
1904
|
+
logger.warn("Failed to parse filter as JSON, using empty filter", { filter, error });
|
|
1904
1905
|
}
|
|
1905
1906
|
return {};
|
|
1906
1907
|
}
|
|
1907
1908
|
})();
|
|
1908
1909
|
}
|
|
1909
|
-
if (
|
|
1910
|
-
|
|
1910
|
+
if (logger) {
|
|
1911
|
+
logger.debug("Using this filter and topK:", { queryFilter, topK: topKValue });
|
|
1911
1912
|
}
|
|
1912
1913
|
const { results, queryEmbedding } = await vectorQuerySearch({
|
|
1913
1914
|
indexName,
|
|
@@ -1959,11 +1960,11 @@ var createVectorQueryTool = ({
|
|
|
1959
1960
|
const toolDescription = description || defaultVectorQueryDescription();
|
|
1960
1961
|
const baseSchema = {
|
|
1961
1962
|
queryText: z.string().describe(queryTextDescription),
|
|
1962
|
-
topK: z.
|
|
1963
|
+
topK: z.coerce.number().describe(topKDescription)
|
|
1963
1964
|
};
|
|
1964
1965
|
const inputSchema = enableFilter ? z.object({
|
|
1965
1966
|
...baseSchema,
|
|
1966
|
-
filter: z.string().describe(filterDescription)
|
|
1967
|
+
filter: z.coerce.string().describe(filterDescription)
|
|
1967
1968
|
}).passthrough() : z.object(baseSchema).passthrough();
|
|
1968
1969
|
return createTool({
|
|
1969
1970
|
id: toolId,
|
|
@@ -1974,7 +1975,8 @@ var createVectorQueryTool = ({
|
|
|
1974
1975
|
description: toolDescription,
|
|
1975
1976
|
execute: async ({ context: { queryText, topK, filter }, mastra }) => {
|
|
1976
1977
|
const topKValue = typeof topK === "number" && !isNaN(topK) ? topK : typeof topK === "string" && !isNaN(Number(topK)) ? Number(topK) : 10;
|
|
1977
|
-
const vectorStore = mastra?.
|
|
1978
|
+
const vectorStore = mastra?.getVector(vectorStoreName);
|
|
1979
|
+
const logger = mastra?.getLogger();
|
|
1978
1980
|
if (vectorStore) {
|
|
1979
1981
|
let queryFilter = {};
|
|
1980
1982
|
if (enableFilter && filter) {
|
|
@@ -1982,15 +1984,15 @@ var createVectorQueryTool = ({
|
|
|
1982
1984
|
try {
|
|
1983
1985
|
return typeof filter === "string" ? JSON.parse(filter) : filter;
|
|
1984
1986
|
} catch (error) {
|
|
1985
|
-
if (
|
|
1986
|
-
|
|
1987
|
+
if (logger) {
|
|
1988
|
+
logger.warn("Failed to parse filter as JSON, using empty filter", { filter, error });
|
|
1987
1989
|
}
|
|
1988
1990
|
return {};
|
|
1989
1991
|
}
|
|
1990
1992
|
})();
|
|
1991
1993
|
}
|
|
1992
|
-
if (
|
|
1993
|
-
|
|
1994
|
+
if (logger) {
|
|
1995
|
+
logger.debug("Using this filter and topK:", { queryFilter, topK: topKValue });
|
|
1994
1996
|
}
|
|
1995
1997
|
const { results } = await vectorQuerySearch({
|
|
1996
1998
|
indexName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/rag",
|
|
3
|
-
"version": "0.1.13-alpha.
|
|
3
|
+
"version": "0.1.13-alpha.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"node-html-better-parser": "^1.4.7",
|
|
30
30
|
"pathe": "^2.0.3",
|
|
31
31
|
"zod": "^3.24.2",
|
|
32
|
-
"@mastra/core": "^0.6.4-alpha.
|
|
32
|
+
"@mastra/core": "^0.6.4-alpha.1"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"ai": "^4.0.0"
|
package/src/tools/graph-rag.ts
CHANGED
|
@@ -46,13 +46,13 @@ export const createGraphRAGTool = ({
|
|
|
46
46
|
|
|
47
47
|
const baseSchema = {
|
|
48
48
|
queryText: z.string().describe(queryTextDescription),
|
|
49
|
-
topK: z.
|
|
49
|
+
topK: z.coerce.number().describe(topKDescription),
|
|
50
50
|
};
|
|
51
51
|
const inputSchema = enableFilter
|
|
52
52
|
? z
|
|
53
53
|
.object({
|
|
54
54
|
...baseSchema,
|
|
55
|
-
filter: z.string().describe(filterDescription),
|
|
55
|
+
filter: z.coerce.string().describe(filterDescription),
|
|
56
56
|
})
|
|
57
57
|
.passthrough()
|
|
58
58
|
: z.object(baseSchema).passthrough();
|
|
@@ -70,7 +70,8 @@ export const createGraphRAGTool = ({
|
|
|
70
70
|
: typeof topK === 'string' && !isNaN(Number(topK))
|
|
71
71
|
? Number(topK)
|
|
72
72
|
: 10;
|
|
73
|
-
const vectorStore = mastra?.
|
|
73
|
+
const vectorStore = mastra?.getVector(vectorStoreName);
|
|
74
|
+
const logger = mastra?.getLogger();
|
|
74
75
|
|
|
75
76
|
if (vectorStore) {
|
|
76
77
|
let queryFilter = {};
|
|
@@ -80,15 +81,15 @@ export const createGraphRAGTool = ({
|
|
|
80
81
|
return typeof filter === 'string' ? JSON.parse(filter) : filter;
|
|
81
82
|
} catch (error) {
|
|
82
83
|
// Log the error and use empty object
|
|
83
|
-
if (
|
|
84
|
-
|
|
84
|
+
if (logger) {
|
|
85
|
+
logger.warn('Failed to parse filter as JSON, using empty filter', { filter, error });
|
|
85
86
|
}
|
|
86
87
|
return {};
|
|
87
88
|
}
|
|
88
89
|
})();
|
|
89
90
|
}
|
|
90
|
-
if (
|
|
91
|
-
|
|
91
|
+
if (logger) {
|
|
92
|
+
logger.debug('Using this filter and topK:', { queryFilter, topK: topKValue });
|
|
92
93
|
}
|
|
93
94
|
const { results, queryEmbedding } = await vectorQuerySearch({
|
|
94
95
|
indexName,
|
|
@@ -28,11 +28,21 @@ describe('createVectorQueryTool', () => {
|
|
|
28
28
|
// Mock vector store methods
|
|
29
29
|
},
|
|
30
30
|
},
|
|
31
|
+
getVector: vi.fn(() => ({
|
|
32
|
+
testStore: {
|
|
33
|
+
// Mock vector store methods
|
|
34
|
+
},
|
|
35
|
+
})),
|
|
31
36
|
logger: {
|
|
32
37
|
debug: vi.fn(),
|
|
33
38
|
warn: vi.fn(),
|
|
34
39
|
info: vi.fn(),
|
|
35
40
|
},
|
|
41
|
+
getLogger: vi.fn(() => ({
|
|
42
|
+
debug: vi.fn(),
|
|
43
|
+
warn: vi.fn(),
|
|
44
|
+
info: vi.fn(),
|
|
45
|
+
})),
|
|
36
46
|
};
|
|
37
47
|
|
|
38
48
|
beforeEach(() => {
|
|
@@ -78,7 +88,7 @@ describe('createVectorQueryTool', () => {
|
|
|
78
88
|
// Get the Zod schema
|
|
79
89
|
const schema = tool.__inputSchema;
|
|
80
90
|
|
|
81
|
-
// Test various filter inputs that should
|
|
91
|
+
// Test various filter inputs that should coerce to string
|
|
82
92
|
const testCases = [
|
|
83
93
|
// String inputs
|
|
84
94
|
{ filter: '{"field": "value"}' },
|
|
@@ -86,9 +96,6 @@ describe('createVectorQueryTool', () => {
|
|
|
86
96
|
{ filter: 'simple-string' },
|
|
87
97
|
// Empty
|
|
88
98
|
{ filter: '' },
|
|
89
|
-
];
|
|
90
|
-
|
|
91
|
-
const invalidTestCases = [
|
|
92
99
|
{ filter: { field: 'value' } },
|
|
93
100
|
{ filter: {} },
|
|
94
101
|
{ filter: 123 },
|
|
@@ -106,16 +113,6 @@ describe('createVectorQueryTool', () => {
|
|
|
106
113
|
).not.toThrow();
|
|
107
114
|
});
|
|
108
115
|
|
|
109
|
-
invalidTestCases.forEach(({ filter }) => {
|
|
110
|
-
expect(() =>
|
|
111
|
-
schema.parse({
|
|
112
|
-
queryText: 'test query',
|
|
113
|
-
topK: 5,
|
|
114
|
-
filter,
|
|
115
|
-
}),
|
|
116
|
-
).toThrow();
|
|
117
|
-
});
|
|
118
|
-
|
|
119
116
|
// Verify that all parsed values are strings
|
|
120
117
|
testCases.forEach(({ filter }) => {
|
|
121
118
|
const result = schema.parse({
|
|
@@ -34,13 +34,13 @@ export const createVectorQueryTool = ({
|
|
|
34
34
|
// Create base schema with required fields
|
|
35
35
|
const baseSchema = {
|
|
36
36
|
queryText: z.string().describe(queryTextDescription),
|
|
37
|
-
topK: z.
|
|
37
|
+
topK: z.coerce.number().describe(topKDescription),
|
|
38
38
|
};
|
|
39
39
|
const inputSchema = enableFilter
|
|
40
40
|
? z
|
|
41
41
|
.object({
|
|
42
42
|
...baseSchema,
|
|
43
|
-
filter: z.string().describe(filterDescription),
|
|
43
|
+
filter: z.coerce.string().describe(filterDescription),
|
|
44
44
|
})
|
|
45
45
|
.passthrough()
|
|
46
46
|
: z.object(baseSchema).passthrough();
|
|
@@ -59,7 +59,8 @@ export const createVectorQueryTool = ({
|
|
|
59
59
|
? Number(topK)
|
|
60
60
|
: 10;
|
|
61
61
|
|
|
62
|
-
const vectorStore = mastra?.
|
|
62
|
+
const vectorStore = mastra?.getVector(vectorStoreName);
|
|
63
|
+
const logger = mastra?.getLogger();
|
|
63
64
|
|
|
64
65
|
// Get relevant chunks from the vector database
|
|
65
66
|
if (vectorStore) {
|
|
@@ -70,15 +71,15 @@ export const createVectorQueryTool = ({
|
|
|
70
71
|
return typeof filter === 'string' ? JSON.parse(filter) : filter;
|
|
71
72
|
} catch (error) {
|
|
72
73
|
// Log the error and use empty object
|
|
73
|
-
if (
|
|
74
|
-
|
|
74
|
+
if (logger) {
|
|
75
|
+
logger.warn('Failed to parse filter as JSON, using empty filter', { filter, error });
|
|
75
76
|
}
|
|
76
77
|
return {};
|
|
77
78
|
}
|
|
78
79
|
})();
|
|
79
80
|
}
|
|
80
|
-
if (
|
|
81
|
-
|
|
81
|
+
if (logger) {
|
|
82
|
+
logger.debug('Using this filter and topK:', { queryFilter, topK: topKValue });
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
const { results } = await vectorQuerySearch({
|