@mastra/rag 2.5.0 → 2.6.0-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.
- package/CHANGELOG.md +26 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-rag-chunking-and-embedding.md +1 -1
- package/dist/docs/references/reference-rag-graph-rag.md +71 -8
- package/dist/docs/references/reference-tools-bedrock-kb-tool.md +1 -1
- package/dist/docs/references/reference-tools-vector-query-tool.md +1 -1
- package/dist/graph-rag/index.d.ts +28 -0
- package/dist/graph-rag/index.d.ts.map +1 -1
- package/dist/index.cjs +45 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +45 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './document/types.js';
|
|
|
3
3
|
export * from './rerank/index.js';
|
|
4
4
|
export * from './rerank/relevance/index.js';
|
|
5
5
|
export { GraphRAG } from './graph-rag/index.js';
|
|
6
|
+
export type { GraphRAGSnapshot } from './graph-rag/index.js';
|
|
6
7
|
export * from './tools/index.js';
|
|
7
8
|
export * from './utils/default-settings.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,cAAc,SAAS,CAAC;AACxB,cAAc,0BAA0B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,YAAY,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACpD,cAAc,SAAS,CAAC;AACxB,cAAc,0BAA0B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -6222,7 +6222,8 @@ async function rerank(results, query, model, options) {
|
|
|
6222
6222
|
}
|
|
6223
6223
|
//#endregion
|
|
6224
6224
|
//#region src/graph-rag/index.ts
|
|
6225
|
-
|
|
6225
|
+
const GRAPH_RAG_SNAPSHOT_VERSION = 1;
|
|
6226
|
+
var GraphRAG = class GraphRAG {
|
|
6226
6227
|
nodes;
|
|
6227
6228
|
edges;
|
|
6228
6229
|
dimension;
|
|
@@ -6257,6 +6258,49 @@ var GraphRAG = class {
|
|
|
6257
6258
|
getEdgesByType(type) {
|
|
6258
6259
|
return this.edges.filter((edge) => edge.type === type);
|
|
6259
6260
|
}
|
|
6261
|
+
/**
|
|
6262
|
+
* Produce a JSON-safe snapshot of the graph so it can be persisted and
|
|
6263
|
+
* restored later instead of rebuilt with `createGraph`.
|
|
6264
|
+
*
|
|
6265
|
+
* The snapshot is a deep copy, including nested node metadata, so mutating it
|
|
6266
|
+
* does not affect this instance.
|
|
6267
|
+
* Note that every node carries its full embedding, so snapshots of large
|
|
6268
|
+
* graphs can be several megabytes of JSON.
|
|
6269
|
+
*/
|
|
6270
|
+
serialize() {
|
|
6271
|
+
return {
|
|
6272
|
+
version: GRAPH_RAG_SNAPSHOT_VERSION,
|
|
6273
|
+
dimension: this.dimension,
|
|
6274
|
+
threshold: this.threshold,
|
|
6275
|
+
nodes: Array.from(this.nodes.values()).map((node) => ({
|
|
6276
|
+
...node,
|
|
6277
|
+
...node.embedding ? { embedding: [...node.embedding] } : {},
|
|
6278
|
+
...node.metadata ? { metadata: structuredClone(node.metadata) } : {}
|
|
6279
|
+
})),
|
|
6280
|
+
edges: this.edges.map((edge) => ({ ...edge }))
|
|
6281
|
+
};
|
|
6282
|
+
}
|
|
6283
|
+
/**
|
|
6284
|
+
* Rebuild a GraphRAG instance from a snapshot produced by `serialize()`.
|
|
6285
|
+
*
|
|
6286
|
+
* @throws if the snapshot version is unsupported, a node embedding does not
|
|
6287
|
+
* match the snapshot dimension, or an edge references an unknown node.
|
|
6288
|
+
*/
|
|
6289
|
+
static deserialize(snapshot) {
|
|
6290
|
+
if (snapshot?.version !== GRAPH_RAG_SNAPSHOT_VERSION) throw new Error(`Unsupported GraphRAG snapshot version: ${snapshot?.version}`);
|
|
6291
|
+
const graph = new GraphRAG(snapshot.dimension, snapshot.threshold);
|
|
6292
|
+
for (const node of snapshot.nodes ?? []) graph.addNode({
|
|
6293
|
+
...node,
|
|
6294
|
+
...node.embedding ? { embedding: [...node.embedding] } : {},
|
|
6295
|
+
...node.metadata ? { metadata: structuredClone(node.metadata) } : {}
|
|
6296
|
+
});
|
|
6297
|
+
for (const edge of snapshot.edges ?? []) {
|
|
6298
|
+
if (!graph.nodes.has(edge.source)) throw new Error(`Edge references unknown node: ${edge.source}`);
|
|
6299
|
+
if (!graph.nodes.has(edge.target)) throw new Error(`Edge references unknown node: ${edge.target}`);
|
|
6300
|
+
}
|
|
6301
|
+
graph.edges = (snapshot.edges ?? []).map((edge) => ({ ...edge }));
|
|
6302
|
+
return graph;
|
|
6303
|
+
}
|
|
6260
6304
|
clear() {
|
|
6261
6305
|
this.nodes.clear();
|
|
6262
6306
|
this.edges = [];
|