@mastra/rag 2.7.3-alpha.2 → 2.8.0-alpha.3
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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +18 -18
- package/dist/docs/references/reference-rag-chunk.md +1 -1
- package/dist/docs/references/reference-rag-graph-rag-guide.md +3 -1
- package/dist/document/transformers/json.d.ts.map +1 -1
- package/dist/document/validation.d.ts.map +1 -1
- package/dist/index.cjs +38 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -34
- package/dist/index.js.map +1 -1
- package/dist/tools/graph-rag.d.ts.map +1 -1
- package/dist/tools/types.d.ts +3 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/tool-helpers.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import { createSimilarityPrompt } from "@mastra/core/relevance";
|
|
|
9
9
|
import ZeroEntropy from "zeroentropy";
|
|
10
10
|
import { createTool } from "@mastra/core/tools";
|
|
11
11
|
import { embedV1, embedV2, embedV3, embedV4 } from "@mastra/core/vector";
|
|
12
|
+
import { getRequestUser } from "@mastra/core/utils";
|
|
12
13
|
import { AgenticRetrieveStreamCommand, BedrockAgentRuntimeClient, RetrieveCommand } from "@aws-sdk/client-bedrock-agent-runtime";
|
|
13
14
|
// \0rolldown/runtime.js
|
|
14
15
|
var __create$1 = Object.create;
|
|
@@ -4847,6 +4848,7 @@ var RecursiveJsonTransformer = class RecursiveJsonTransformer {
|
|
|
4847
4848
|
ensureAscii;
|
|
4848
4849
|
convertLists;
|
|
4849
4850
|
constructor({ maxSize = 2e3, ensureAscii = false, convertLists = true }) {
|
|
4851
|
+
if (!Number.isFinite(maxSize) || maxSize < 21) throw new RangeError("JSON maxSize must be at least 21");
|
|
4850
4852
|
this.maxSize = maxSize;
|
|
4851
4853
|
this.ensureAscii = ensureAscii;
|
|
4852
4854
|
this.convertLists = convertLists;
|
|
@@ -5779,6 +5781,7 @@ const validationSchemas = {
|
|
|
5779
5781
|
disallowedSpecial: setOrAllSchema
|
|
5780
5782
|
}).strict(),
|
|
5781
5783
|
json: baseChunkOptionsSchema.extend({
|
|
5784
|
+
maxSize: z.number().min(21).optional(),
|
|
5782
5785
|
minSize: z.number().positive().optional(),
|
|
5783
5786
|
ensureAscii: z.boolean().optional(),
|
|
5784
5787
|
convertLists: z.boolean().optional()
|
|
@@ -6746,7 +6749,8 @@ async function resolveVectorStore(options, context, logger) {
|
|
|
6746
6749
|
if (typeof vectorStoreOption === "function") {
|
|
6747
6750
|
const resolved = await vectorStoreOption({
|
|
6748
6751
|
requestContext,
|
|
6749
|
-
mastra
|
|
6752
|
+
mastra,
|
|
6753
|
+
user: getRequestUser(requestContext)
|
|
6750
6754
|
});
|
|
6751
6755
|
if (!isValidMastraVector(resolved)) {
|
|
6752
6756
|
const contextStr = buildContextString(context);
|
|
@@ -6850,8 +6854,6 @@ const createGraphRAGTool = (options) => {
|
|
|
6850
6854
|
...defaultGraphOptions,
|
|
6851
6855
|
...options.graphOptions || {}
|
|
6852
6856
|
};
|
|
6853
|
-
const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
|
|
6854
|
-
let isInitialized = false;
|
|
6855
6857
|
const inputSchema = options.enableFilter ? filterSchema : z.object(baseSchema).passthrough();
|
|
6856
6858
|
return createTool({
|
|
6857
6859
|
id: toolId,
|
|
@@ -6911,38 +6913,40 @@ const createGraphRAGTool = (options) => {
|
|
|
6911
6913
|
observabilityContext
|
|
6912
6914
|
});
|
|
6913
6915
|
if (logger) logger.debug("vectorQuerySearch returned results", { count: results.length });
|
|
6914
|
-
if (
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
} catch (err) {
|
|
6937
|
-
buildSpan?.error({
|
|
6938
|
-
error: err,
|
|
6939
|
-
endSpan: true
|
|
6940
|
-
});
|
|
6941
|
-
throw err;
|
|
6916
|
+
if (results.length === 0) return {
|
|
6917
|
+
relevantContext: [],
|
|
6918
|
+
sources: []
|
|
6919
|
+
};
|
|
6920
|
+
const graphRag = new GraphRAG(graphOptions.dimension, graphOptions.threshold);
|
|
6921
|
+
const chunks = results.map((result) => ({
|
|
6922
|
+
text: result?.metadata?.text,
|
|
6923
|
+
metadata: result.metadata ?? {}
|
|
6924
|
+
}));
|
|
6925
|
+
const embeddings = results.map((result) => ({ vector: result.vector || [] }));
|
|
6926
|
+
if (logger) logger.debug("Initializing graph", {
|
|
6927
|
+
chunkCount: chunks.length,
|
|
6928
|
+
embeddingCount: embeddings.length
|
|
6929
|
+
});
|
|
6930
|
+
const buildSpan = parentSpan?.createChildSpan({
|
|
6931
|
+
type: SpanType.GRAPH_ACTION,
|
|
6932
|
+
name: "graph build",
|
|
6933
|
+
input: { nodeCount: chunks.length },
|
|
6934
|
+
attributes: {
|
|
6935
|
+
action: "build",
|
|
6936
|
+
nodeCount: chunks.length,
|
|
6937
|
+
threshold: graphOptions.threshold
|
|
6942
6938
|
}
|
|
6943
|
-
|
|
6944
|
-
|
|
6945
|
-
|
|
6939
|
+
});
|
|
6940
|
+
try {
|
|
6941
|
+
graphRag.createGraph(chunks, embeddings);
|
|
6942
|
+
} catch (err) {
|
|
6943
|
+
buildSpan?.error({
|
|
6944
|
+
error: err,
|
|
6945
|
+
endSpan: true
|
|
6946
|
+
});
|
|
6947
|
+
throw err;
|
|
6948
|
+
}
|
|
6949
|
+
buildSpan?.end();
|
|
6946
6950
|
const traverseSpan = parentSpan?.createChildSpan({
|
|
6947
6951
|
type: SpanType.GRAPH_ACTION,
|
|
6948
6952
|
name: "graph traverse",
|