@mastra/rag 0.1.8-alpha.2 → 0.1.8-alpha.4
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 +15 -0
- package/dist/_tsup-dts-rollup.d.cts +12 -12
- package/dist/_tsup-dts-rollup.d.ts +12 -12
- package/dist/index.cjs +30 -38
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +29 -37
- package/package.json +2 -2
- package/src/tools/graph-rag.ts +5 -6
- package/src/tools/vector-query.ts +9 -6
- package/src/utils/default-settings.ts +18 -30
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/rag@0.1.8-alpha.
|
|
2
|
+
> @mastra/rag@0.1.8-alpha.4 build /home/runner/work/mastra/mastra/packages/rag
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake
|
|
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.3.6
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 26963ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.7.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.7.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 24816ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m83.18 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 689ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m83.86 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 686ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @mastra/rag
|
|
2
2
|
|
|
3
|
+
## 0.1.8-alpha.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [d79aedf]
|
|
8
|
+
- @mastra/core@0.5.0-alpha.4
|
|
9
|
+
|
|
10
|
+
## 0.1.8-alpha.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- f2e8e5f: Updated descriptions and input schema for vector and graph rag tools
|
|
15
|
+
- Updated dependencies [3d0e290]
|
|
16
|
+
- @mastra/core@0.5.0-alpha.3
|
|
17
|
+
|
|
3
18
|
## 0.1.8-alpha.2
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -123,22 +123,12 @@ export { createVectorQueryTool }
|
|
|
123
123
|
export { createVectorQueryTool as createVectorQueryTool_alias_1 }
|
|
124
124
|
export { createVectorQueryTool as createVectorQueryTool_alias_2 }
|
|
125
125
|
|
|
126
|
-
declare const
|
|
127
|
-
export { defaultFilter }
|
|
128
|
-
export { defaultFilter as defaultFilter_alias_1 }
|
|
129
|
-
export { defaultFilter as defaultFilter_alias_2 }
|
|
130
|
-
|
|
131
|
-
declare const defaultGraphRagDescription: (vectorStoreName: string, indexName: string) => string;
|
|
126
|
+
declare const defaultGraphRagDescription: () => string;
|
|
132
127
|
export { defaultGraphRagDescription }
|
|
133
128
|
export { defaultGraphRagDescription as defaultGraphRagDescription_alias_1 }
|
|
134
129
|
export { defaultGraphRagDescription as defaultGraphRagDescription_alias_2 }
|
|
135
130
|
|
|
136
|
-
declare const
|
|
137
|
-
export { defaultTopK }
|
|
138
|
-
export { defaultTopK as defaultTopK_alias_1 }
|
|
139
|
-
export { defaultTopK as defaultTopK_alias_2 }
|
|
140
|
-
|
|
141
|
-
declare const defaultVectorQueryDescription: (vectorStoreName: string, indexName: string) => string;
|
|
131
|
+
declare const defaultVectorQueryDescription: () => string;
|
|
142
132
|
export { defaultVectorQueryDescription }
|
|
143
133
|
export { defaultVectorQueryDescription as defaultVectorQueryDescription_alias_1 }
|
|
144
134
|
export { defaultVectorQueryDescription as defaultVectorQueryDescription_alias_2 }
|
|
@@ -152,6 +142,11 @@ declare type ExtractParams = {
|
|
|
152
142
|
export { ExtractParams }
|
|
153
143
|
export { ExtractParams as ExtractParams_alias_1 }
|
|
154
144
|
|
|
145
|
+
declare const filterDescription = "JSON-formatted criteria to refine search results.\n- Uses provided filter if specified\n- Default: {} (no filtering)\n- Example: {\"category\": \"health\"}\n- Must be valid JSON format\n- Based on query intent\n- Multiple filters can be combined";
|
|
146
|
+
export { filterDescription }
|
|
147
|
+
export { filterDescription as filterDescription_alias_1 }
|
|
148
|
+
export { filterDescription as filterDescription_alias_2 }
|
|
149
|
+
|
|
155
150
|
export declare interface GraphChunk {
|
|
156
151
|
text: string;
|
|
157
152
|
metadata: Record<string, any>;
|
|
@@ -578,6 +573,11 @@ export declare class TokenTransformer extends TextTransformer {
|
|
|
578
573
|
}): TokenTransformer;
|
|
579
574
|
}
|
|
580
575
|
|
|
576
|
+
declare const topKDescription = "Controls how many matching documents to return.\n- Uses provided value if specified\n- Default: 10 results\n- Higher values provide more context\n- Lower values focus on best matches\n- Must be a valid number\n- Based on query requirements";
|
|
577
|
+
export { topKDescription }
|
|
578
|
+
export { topKDescription as topKDescription_alias_1 }
|
|
579
|
+
export { topKDescription as topKDescription_alias_2 }
|
|
580
|
+
|
|
581
581
|
declare interface Transformer_2 {
|
|
582
582
|
transformDocuments(documents: Document_2[]): Document_2[];
|
|
583
583
|
}
|
|
@@ -123,22 +123,12 @@ export { createVectorQueryTool }
|
|
|
123
123
|
export { createVectorQueryTool as createVectorQueryTool_alias_1 }
|
|
124
124
|
export { createVectorQueryTool as createVectorQueryTool_alias_2 }
|
|
125
125
|
|
|
126
|
-
declare const
|
|
127
|
-
export { defaultFilter }
|
|
128
|
-
export { defaultFilter as defaultFilter_alias_1 }
|
|
129
|
-
export { defaultFilter as defaultFilter_alias_2 }
|
|
130
|
-
|
|
131
|
-
declare const defaultGraphRagDescription: (vectorStoreName: string, indexName: string) => string;
|
|
126
|
+
declare const defaultGraphRagDescription: () => string;
|
|
132
127
|
export { defaultGraphRagDescription }
|
|
133
128
|
export { defaultGraphRagDescription as defaultGraphRagDescription_alias_1 }
|
|
134
129
|
export { defaultGraphRagDescription as defaultGraphRagDescription_alias_2 }
|
|
135
130
|
|
|
136
|
-
declare const
|
|
137
|
-
export { defaultTopK }
|
|
138
|
-
export { defaultTopK as defaultTopK_alias_1 }
|
|
139
|
-
export { defaultTopK as defaultTopK_alias_2 }
|
|
140
|
-
|
|
141
|
-
declare const defaultVectorQueryDescription: (vectorStoreName: string, indexName: string) => string;
|
|
131
|
+
declare const defaultVectorQueryDescription: () => string;
|
|
142
132
|
export { defaultVectorQueryDescription }
|
|
143
133
|
export { defaultVectorQueryDescription as defaultVectorQueryDescription_alias_1 }
|
|
144
134
|
export { defaultVectorQueryDescription as defaultVectorQueryDescription_alias_2 }
|
|
@@ -152,6 +142,11 @@ declare type ExtractParams = {
|
|
|
152
142
|
export { ExtractParams }
|
|
153
143
|
export { ExtractParams as ExtractParams_alias_1 }
|
|
154
144
|
|
|
145
|
+
declare const filterDescription = "JSON-formatted criteria to refine search results.\n- Uses provided filter if specified\n- Default: {} (no filtering)\n- Example: {\"category\": \"health\"}\n- Must be valid JSON format\n- Based on query intent\n- Multiple filters can be combined";
|
|
146
|
+
export { filterDescription }
|
|
147
|
+
export { filterDescription as filterDescription_alias_1 }
|
|
148
|
+
export { filterDescription as filterDescription_alias_2 }
|
|
149
|
+
|
|
155
150
|
export declare interface GraphChunk {
|
|
156
151
|
text: string;
|
|
157
152
|
metadata: Record<string, any>;
|
|
@@ -578,6 +573,11 @@ export declare class TokenTransformer extends TextTransformer {
|
|
|
578
573
|
}): TokenTransformer;
|
|
579
574
|
}
|
|
580
575
|
|
|
576
|
+
declare const topKDescription = "Controls how many matching documents to return.\n- Uses provided value if specified\n- Default: 10 results\n- Higher values provide more context\n- Lower values focus on best matches\n- Must be a valid number\n- Based on query requirements";
|
|
577
|
+
export { topKDescription }
|
|
578
|
+
export { topKDescription as topKDescription_alias_1 }
|
|
579
|
+
export { topKDescription as topKDescription_alias_2 }
|
|
580
|
+
|
|
581
581
|
declare interface Transformer_2 {
|
|
582
582
|
transformDocuments(documents: Document_2[]): Document_2[];
|
|
583
583
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1613,34 +1613,22 @@ var vectorQuerySearch = async ({
|
|
|
1613
1613
|
};
|
|
1614
1614
|
|
|
1615
1615
|
// src/utils/default-settings.ts
|
|
1616
|
-
var
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
`;
|
|
1625
|
-
var
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
- If user does not specify filter or provides an invalid filter, use default filter: {}
|
|
1633
|
-
`;
|
|
1634
|
-
var defaultVectorQueryDescription = (vectorStoreName, indexName) => `Retrieves relevant information from ${vectorStoreName} using ${indexName} index.
|
|
1635
|
-
|
|
1636
|
-
${defaultTopK}
|
|
1637
|
-
${defaultFilter}
|
|
1638
|
-
`;
|
|
1639
|
-
var defaultGraphRagDescription = (vectorStoreName, indexName) => `Fetches and reranks the most relevant chunks using GraphRAG from the ${vectorStoreName} vector store using the ${indexName} index.
|
|
1640
|
-
|
|
1641
|
-
${defaultTopK}
|
|
1642
|
-
${defaultFilter}
|
|
1643
|
-
`;
|
|
1616
|
+
var defaultVectorQueryDescription = () => `Access the knowledge base to find information needed to answer user questions.`;
|
|
1617
|
+
var defaultGraphRagDescription = () => `Access and analyze relationships between information in the knowledge base to answer complex questions about connections and patterns.`;
|
|
1618
|
+
var topKDescription = `Controls how many matching documents to return.
|
|
1619
|
+
- Uses provided value if specified
|
|
1620
|
+
- Default: 10 results
|
|
1621
|
+
- Higher values provide more context
|
|
1622
|
+
- Lower values focus on best matches
|
|
1623
|
+
- Must be a valid number
|
|
1624
|
+
- Based on query requirements`;
|
|
1625
|
+
var filterDescription = `JSON-formatted criteria to refine search results.
|
|
1626
|
+
- Uses provided filter if specified
|
|
1627
|
+
- Default: {} (no filtering)
|
|
1628
|
+
- Example: {"category": "health"}
|
|
1629
|
+
- Must be valid JSON format
|
|
1630
|
+
- Based on query intent
|
|
1631
|
+
- Multiple filters can be combined`;
|
|
1644
1632
|
|
|
1645
1633
|
// src/tools/graph-rag.ts
|
|
1646
1634
|
var createGraphRAGTool = ({
|
|
@@ -1658,15 +1646,15 @@ var createGraphRAGTool = ({
|
|
|
1658
1646
|
description
|
|
1659
1647
|
}) => {
|
|
1660
1648
|
const toolId = id || `GraphRAG ${vectorStoreName} ${indexName} Tool`;
|
|
1661
|
-
const toolDescription = description || defaultGraphRagDescription(
|
|
1649
|
+
const toolDescription = description || defaultGraphRagDescription();
|
|
1662
1650
|
const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
|
|
1663
1651
|
let isInitialized = false;
|
|
1664
1652
|
return tools.createTool({
|
|
1665
1653
|
id: toolId,
|
|
1666
1654
|
inputSchema: zod.z.object({
|
|
1667
|
-
queryText: zod.z.string(),
|
|
1668
|
-
topK: zod.z.number(),
|
|
1669
|
-
filter: zod.z.string()
|
|
1655
|
+
queryText: zod.z.string().describe("The text query to search for in the vector database"),
|
|
1656
|
+
topK: zod.z.number().describe(topKDescription),
|
|
1657
|
+
filter: zod.z.string().describe(filterDescription)
|
|
1670
1658
|
}),
|
|
1671
1659
|
outputSchema: zod.z.object({
|
|
1672
1660
|
relevantContext: zod.z.any()
|
|
@@ -1735,19 +1723,23 @@ var createVectorQueryTool = ({
|
|
|
1735
1723
|
description
|
|
1736
1724
|
}) => {
|
|
1737
1725
|
const toolId = id || `VectorQuery ${vectorStoreName} ${indexName} Tool`;
|
|
1738
|
-
const toolDescription = description || defaultVectorQueryDescription(
|
|
1726
|
+
const toolDescription = description || defaultVectorQueryDescription();
|
|
1739
1727
|
return tools.createTool({
|
|
1740
1728
|
id: toolId,
|
|
1741
1729
|
inputSchema: zod.z.object({
|
|
1742
|
-
queryText: zod.z.string(),
|
|
1743
|
-
topK: zod.z.number(),
|
|
1744
|
-
filter: zod.z.string()
|
|
1730
|
+
queryText: zod.z.string().describe("The text query to search for in the vector database"),
|
|
1731
|
+
topK: zod.z.number().describe(topKDescription),
|
|
1732
|
+
filter: zod.z.string().describe(filterDescription)
|
|
1745
1733
|
}),
|
|
1746
1734
|
outputSchema: zod.z.object({
|
|
1747
1735
|
relevantContext: zod.z.any()
|
|
1748
1736
|
}),
|
|
1749
1737
|
description: toolDescription,
|
|
1750
1738
|
execute: async ({ context: { queryText, topK, filter }, mastra }) => {
|
|
1739
|
+
console.log({
|
|
1740
|
+
topK,
|
|
1741
|
+
filter
|
|
1742
|
+
});
|
|
1751
1743
|
const vectorStore = mastra?.vectors?.[vectorStoreName];
|
|
1752
1744
|
if (vectorStore) {
|
|
1753
1745
|
let queryFilter = {};
|
|
@@ -2523,8 +2515,8 @@ exports.VECTORIZE_PROMPT = VECTORIZE_PROMPT;
|
|
|
2523
2515
|
exports.createDocumentChunkerTool = createDocumentChunkerTool;
|
|
2524
2516
|
exports.createGraphRAGTool = createGraphRAGTool;
|
|
2525
2517
|
exports.createVectorQueryTool = createVectorQueryTool;
|
|
2526
|
-
exports.defaultFilter = defaultFilter;
|
|
2527
2518
|
exports.defaultGraphRagDescription = defaultGraphRagDescription;
|
|
2528
|
-
exports.defaultTopK = defaultTopK;
|
|
2529
2519
|
exports.defaultVectorQueryDescription = defaultVectorQueryDescription;
|
|
2520
|
+
exports.filterDescription = filterDescription;
|
|
2530
2521
|
exports.rerank = rerank;
|
|
2522
|
+
exports.topKDescription = topKDescription;
|
package/dist/index.d.cts
CHANGED
|
@@ -16,7 +16,7 @@ export { PINECONE_PROMPT } from './_tsup-dts-rollup.cjs';
|
|
|
16
16
|
export { QDRANT_PROMPT } from './_tsup-dts-rollup.cjs';
|
|
17
17
|
export { UPSTASH_PROMPT } from './_tsup-dts-rollup.cjs';
|
|
18
18
|
export { VECTORIZE_PROMPT } from './_tsup-dts-rollup.cjs';
|
|
19
|
-
export { defaultTopK } from './_tsup-dts-rollup.cjs';
|
|
20
|
-
export { defaultFilter } from './_tsup-dts-rollup.cjs';
|
|
21
19
|
export { defaultVectorQueryDescription } from './_tsup-dts-rollup.cjs';
|
|
22
20
|
export { defaultGraphRagDescription } from './_tsup-dts-rollup.cjs';
|
|
21
|
+
export { topKDescription } from './_tsup-dts-rollup.cjs';
|
|
22
|
+
export { filterDescription } from './_tsup-dts-rollup.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export { PINECONE_PROMPT } from './_tsup-dts-rollup.js';
|
|
|
16
16
|
export { QDRANT_PROMPT } from './_tsup-dts-rollup.js';
|
|
17
17
|
export { UPSTASH_PROMPT } from './_tsup-dts-rollup.js';
|
|
18
18
|
export { VECTORIZE_PROMPT } from './_tsup-dts-rollup.js';
|
|
19
|
-
export { defaultTopK } from './_tsup-dts-rollup.js';
|
|
20
|
-
export { defaultFilter } from './_tsup-dts-rollup.js';
|
|
21
19
|
export { defaultVectorQueryDescription } from './_tsup-dts-rollup.js';
|
|
22
20
|
export { defaultGraphRagDescription } from './_tsup-dts-rollup.js';
|
|
21
|
+
export { topKDescription } from './_tsup-dts-rollup.js';
|
|
22
|
+
export { filterDescription } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -1611,34 +1611,22 @@ var vectorQuerySearch = async ({
|
|
|
1611
1611
|
};
|
|
1612
1612
|
|
|
1613
1613
|
// src/utils/default-settings.ts
|
|
1614
|
-
var
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
`;
|
|
1623
|
-
var
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
- If user does not specify filter or provides an invalid filter, use default filter: {}
|
|
1631
|
-
`;
|
|
1632
|
-
var defaultVectorQueryDescription = (vectorStoreName, indexName) => `Retrieves relevant information from ${vectorStoreName} using ${indexName} index.
|
|
1633
|
-
|
|
1634
|
-
${defaultTopK}
|
|
1635
|
-
${defaultFilter}
|
|
1636
|
-
`;
|
|
1637
|
-
var defaultGraphRagDescription = (vectorStoreName, indexName) => `Fetches and reranks the most relevant chunks using GraphRAG from the ${vectorStoreName} vector store using the ${indexName} index.
|
|
1638
|
-
|
|
1639
|
-
${defaultTopK}
|
|
1640
|
-
${defaultFilter}
|
|
1641
|
-
`;
|
|
1614
|
+
var defaultVectorQueryDescription = () => `Access the knowledge base to find information needed to answer user questions.`;
|
|
1615
|
+
var defaultGraphRagDescription = () => `Access and analyze relationships between information in the knowledge base to answer complex questions about connections and patterns.`;
|
|
1616
|
+
var topKDescription = `Controls how many matching documents to return.
|
|
1617
|
+
- Uses provided value if specified
|
|
1618
|
+
- Default: 10 results
|
|
1619
|
+
- Higher values provide more context
|
|
1620
|
+
- Lower values focus on best matches
|
|
1621
|
+
- Must be a valid number
|
|
1622
|
+
- Based on query requirements`;
|
|
1623
|
+
var filterDescription = `JSON-formatted criteria to refine search results.
|
|
1624
|
+
- Uses provided filter if specified
|
|
1625
|
+
- Default: {} (no filtering)
|
|
1626
|
+
- Example: {"category": "health"}
|
|
1627
|
+
- Must be valid JSON format
|
|
1628
|
+
- Based on query intent
|
|
1629
|
+
- Multiple filters can be combined`;
|
|
1642
1630
|
|
|
1643
1631
|
// src/tools/graph-rag.ts
|
|
1644
1632
|
var createGraphRAGTool = ({
|
|
@@ -1656,15 +1644,15 @@ var createGraphRAGTool = ({
|
|
|
1656
1644
|
description
|
|
1657
1645
|
}) => {
|
|
1658
1646
|
const toolId = id || `GraphRAG ${vectorStoreName} ${indexName} Tool`;
|
|
1659
|
-
const toolDescription = description || defaultGraphRagDescription(
|
|
1647
|
+
const toolDescription = description || defaultGraphRagDescription();
|
|
1660
1648
|
const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
|
|
1661
1649
|
let isInitialized = false;
|
|
1662
1650
|
return createTool({
|
|
1663
1651
|
id: toolId,
|
|
1664
1652
|
inputSchema: z.object({
|
|
1665
|
-
queryText: z.string(),
|
|
1666
|
-
topK: z.number(),
|
|
1667
|
-
filter: z.string()
|
|
1653
|
+
queryText: z.string().describe("The text query to search for in the vector database"),
|
|
1654
|
+
topK: z.number().describe(topKDescription),
|
|
1655
|
+
filter: z.string().describe(filterDescription)
|
|
1668
1656
|
}),
|
|
1669
1657
|
outputSchema: z.object({
|
|
1670
1658
|
relevantContext: z.any()
|
|
@@ -1733,19 +1721,23 @@ var createVectorQueryTool = ({
|
|
|
1733
1721
|
description
|
|
1734
1722
|
}) => {
|
|
1735
1723
|
const toolId = id || `VectorQuery ${vectorStoreName} ${indexName} Tool`;
|
|
1736
|
-
const toolDescription = description || defaultVectorQueryDescription(
|
|
1724
|
+
const toolDescription = description || defaultVectorQueryDescription();
|
|
1737
1725
|
return createTool({
|
|
1738
1726
|
id: toolId,
|
|
1739
1727
|
inputSchema: z.object({
|
|
1740
|
-
queryText: z.string(),
|
|
1741
|
-
topK: z.number(),
|
|
1742
|
-
filter: z.string()
|
|
1728
|
+
queryText: z.string().describe("The text query to search for in the vector database"),
|
|
1729
|
+
topK: z.number().describe(topKDescription),
|
|
1730
|
+
filter: z.string().describe(filterDescription)
|
|
1743
1731
|
}),
|
|
1744
1732
|
outputSchema: z.object({
|
|
1745
1733
|
relevantContext: z.any()
|
|
1746
1734
|
}),
|
|
1747
1735
|
description: toolDescription,
|
|
1748
1736
|
execute: async ({ context: { queryText, topK, filter }, mastra }) => {
|
|
1737
|
+
console.log({
|
|
1738
|
+
topK,
|
|
1739
|
+
filter
|
|
1740
|
+
});
|
|
1749
1741
|
const vectorStore = mastra?.vectors?.[vectorStoreName];
|
|
1750
1742
|
if (vectorStore) {
|
|
1751
1743
|
let queryFilter = {};
|
|
@@ -2508,4 +2500,4 @@ Example Complex Query:
|
|
|
2508
2500
|
"inStock": true
|
|
2509
2501
|
}`;
|
|
2510
2502
|
|
|
2511
|
-
export { ASTRA_PROMPT, CHROMA_PROMPT, GraphRAG, LIBSQL_PROMPT, MDocument, PGVECTOR_PROMPT, PINECONE_PROMPT, QDRANT_PROMPT, UPSTASH_PROMPT, VECTORIZE_PROMPT, createDocumentChunkerTool, createGraphRAGTool, createVectorQueryTool,
|
|
2503
|
+
export { ASTRA_PROMPT, CHROMA_PROMPT, GraphRAG, LIBSQL_PROMPT, MDocument, PGVECTOR_PROMPT, PINECONE_PROMPT, QDRANT_PROMPT, UPSTASH_PROMPT, VECTORIZE_PROMPT, createDocumentChunkerTool, createGraphRAGTool, createVectorQueryTool, defaultGraphRagDescription, defaultVectorQueryDescription, filterDescription, rerank, topKDescription };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/rag",
|
|
3
|
-
"version": "0.1.8-alpha.
|
|
3
|
+
"version": "0.1.8-alpha.4",
|
|
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.2",
|
|
31
31
|
"zod": "^3.24.1",
|
|
32
|
-
"@mastra/core": "^0.5.0-alpha.
|
|
32
|
+
"@mastra/core": "^0.5.0-alpha.4"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
35
|
"ai": "^4.0.0"
|
package/src/tools/graph-rag.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { EmbeddingModel } from 'ai';
|
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
import { GraphRAG } from '../graph-rag';
|
|
6
|
-
import { vectorQuerySearch, defaultGraphRagDescription } from '../utils';
|
|
6
|
+
import { vectorQuerySearch, defaultGraphRagDescription, filterDescription, topKDescription } from '../utils';
|
|
7
7
|
|
|
8
8
|
export const createGraphRAGTool = ({
|
|
9
9
|
vectorStoreName,
|
|
@@ -33,8 +33,7 @@ export const createGraphRAGTool = ({
|
|
|
33
33
|
description?: string;
|
|
34
34
|
}): ReturnType<typeof createTool> => {
|
|
35
35
|
const toolId = id || `GraphRAG ${vectorStoreName} ${indexName} Tool`;
|
|
36
|
-
const toolDescription = description || defaultGraphRagDescription(
|
|
37
|
-
|
|
36
|
+
const toolDescription = description || defaultGraphRagDescription();
|
|
38
37
|
// Initialize GraphRAG
|
|
39
38
|
const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
|
|
40
39
|
let isInitialized = false;
|
|
@@ -42,9 +41,9 @@ export const createGraphRAGTool = ({
|
|
|
42
41
|
return createTool({
|
|
43
42
|
id: toolId,
|
|
44
43
|
inputSchema: z.object({
|
|
45
|
-
queryText: z.string(),
|
|
46
|
-
topK: z.number(),
|
|
47
|
-
filter: z.string(),
|
|
44
|
+
queryText: z.string().describe('The text query to search for in the vector database'),
|
|
45
|
+
topK: z.number().describe(topKDescription),
|
|
46
|
+
filter: z.string().describe(filterDescription),
|
|
48
47
|
}),
|
|
49
48
|
outputSchema: z.object({
|
|
50
49
|
relevantContext: z.any(),
|
|
@@ -4,7 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
|
|
5
5
|
import { rerank } from '../rerank';
|
|
6
6
|
import type { RerankConfig } from '../rerank';
|
|
7
|
-
import { vectorQuerySearch, defaultVectorQueryDescription } from '../utils';
|
|
7
|
+
import { vectorQuerySearch, defaultVectorQueryDescription, filterDescription, topKDescription } from '../utils';
|
|
8
8
|
|
|
9
9
|
export const createVectorQueryTool = ({
|
|
10
10
|
vectorStoreName,
|
|
@@ -24,20 +24,23 @@ export const createVectorQueryTool = ({
|
|
|
24
24
|
description?: string;
|
|
25
25
|
}): ReturnType<typeof createTool> => {
|
|
26
26
|
const toolId = id || `VectorQuery ${vectorStoreName} ${indexName} Tool`;
|
|
27
|
-
const toolDescription = description || defaultVectorQueryDescription(
|
|
28
|
-
|
|
27
|
+
const toolDescription = description || defaultVectorQueryDescription();
|
|
29
28
|
return createTool({
|
|
30
29
|
id: toolId,
|
|
31
30
|
inputSchema: z.object({
|
|
32
|
-
queryText: z.string(),
|
|
33
|
-
topK: z.number(),
|
|
34
|
-
filter: z.string(),
|
|
31
|
+
queryText: z.string().describe('The text query to search for in the vector database'),
|
|
32
|
+
topK: z.number().describe(topKDescription),
|
|
33
|
+
filter: z.string().describe(filterDescription),
|
|
35
34
|
}),
|
|
36
35
|
outputSchema: z.object({
|
|
37
36
|
relevantContext: z.any(),
|
|
38
37
|
}),
|
|
39
38
|
description: toolDescription,
|
|
40
39
|
execute: async ({ context: { queryText, topK, filter }, mastra }) => {
|
|
40
|
+
console.log({
|
|
41
|
+
topK,
|
|
42
|
+
filter,
|
|
43
|
+
});
|
|
41
44
|
const vectorStore = mastra?.vectors?.[vectorStoreName];
|
|
42
45
|
|
|
43
46
|
// Get relevant chunks from the vector database
|
|
@@ -1,33 +1,21 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
- Generate topK based on exactly what user specifies
|
|
4
|
-
- must be a valid number
|
|
1
|
+
export const defaultVectorQueryDescription = () =>
|
|
2
|
+
`Access the knowledge base to find information needed to answer user questions.`;
|
|
5
3
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
- If user does not specify topK or provides an invalid topK, use default topK: 10
|
|
9
|
-
`;
|
|
4
|
+
export const defaultGraphRagDescription = () =>
|
|
5
|
+
`Access and analyze relationships between information in the knowledge base to answer complex questions about connections and patterns.`;
|
|
10
6
|
|
|
11
|
-
export const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
export const topKDescription = `Controls how many matching documents to return.
|
|
8
|
+
- Uses provided value if specified
|
|
9
|
+
- Default: 10 results
|
|
10
|
+
- Higher values provide more context
|
|
11
|
+
- Lower values focus on best matches
|
|
12
|
+
- Must be a valid number
|
|
13
|
+
- Based on query requirements`;
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
${defaultTopK}
|
|
25
|
-
${defaultFilter}
|
|
26
|
-
`;
|
|
27
|
-
|
|
28
|
-
export const defaultGraphRagDescription = (vectorStoreName: string, indexName: string) =>
|
|
29
|
-
`Fetches and reranks the most relevant chunks using GraphRAG from the ${vectorStoreName} vector store using the ${indexName} index.
|
|
30
|
-
|
|
31
|
-
${defaultTopK}
|
|
32
|
-
${defaultFilter}
|
|
33
|
-
`;
|
|
15
|
+
export const filterDescription = `JSON-formatted criteria to refine search results.
|
|
16
|
+
- Uses provided filter if specified
|
|
17
|
+
- Default: {} (no filtering)
|
|
18
|
+
- Example: {"category": "health"}
|
|
19
|
+
- Must be valid JSON format
|
|
20
|
+
- Based on query intent
|
|
21
|
+
- Multiple filters can be combined`;
|