@mastra/rag 0.0.0-studio-deploy-20260404184540 → 0.0.0-studio-cli-20260504022012

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 CHANGED
@@ -1,11 +1,109 @@
1
1
  # @mastra/rag
2
2
 
3
- ## 0.0.0-studio-deploy-20260404184540
3
+ ## 0.0.0-studio-cli-20260504022012
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [[`e133cc7`](https://github.com/mastra-ai/mastra/commit/e133cc73c2a73d90a39ad73f724e9cb492466b41), [`c55b527`](https://github.com/mastra-ai/mastra/commit/c55b52758a31368b2077b0dbbc3badfe4063f560), [`e133cc7`](https://github.com/mastra-ai/mastra/commit/e133cc73c2a73d90a39ad73f724e9cb492466b41), [`e133cc7`](https://github.com/mastra-ai/mastra/commit/e133cc73c2a73d90a39ad73f724e9cb492466b41), [`7eb2596`](https://github.com/mastra-ai/mastra/commit/7eb25960d607e07468c9a10c5437abd2deaf1e9a)]:
8
- - @mastra/core@0.0.0-studio-deploy-20260404184540
7
+ - Updated dependencies [[`6dcd65f`](https://github.com/mastra-ai/mastra/commit/6dcd65f2a34069e6dc43ba35f1d11119b9b40bef), [`c05c9a1`](https://github.com/mastra-ai/mastra/commit/c05c9a13230988cef6d438a62f37760f31927bc7), [`e24aacb`](https://github.com/mastra-ai/mastra/commit/e24aacba07bd66f5d95b636dc24016fca26b52cf), [`1c2dda8`](https://github.com/mastra-ai/mastra/commit/1c2dda805fbfccc0abf55d4cb20cc34402dc3f0c), [`c721164`](https://github.com/mastra-ai/mastra/commit/c7211643f7ac861f83b19a3757cc921487fc9d75), [`1b55954`](https://github.com/mastra-ai/mastra/commit/1b559541c1e08a10e49d01ffc51a634dfc37a286), [`5adc55e`](https://github.com/mastra-ai/mastra/commit/5adc55e63407be8ee977914957d68bcc2a075ceb), [`70017d7`](https://github.com/mastra-ai/mastra/commit/70017d72ab741b5d7040e2a15c251a317782e39e), [`e4942bc`](https://github.com/mastra-ai/mastra/commit/e4942bc7fdc903572f7d84f26d5e15f9d39c763d)]:
8
+ - @mastra/core@0.0.0-studio-cli-20260504022012
9
+
10
+ ## 2.2.1
11
+
12
+ ### Patch Changes
13
+
14
+ - Fixed a security issue where several parsing and tracing paths could slow down on malformed or attacker-crafted input. Normal behavior is unchanged, and these packages now handle pathological input in linear time. ([#15566](https://github.com/mastra-ai/mastra/pull/15566))
15
+
16
+ - Updated dependencies [[`20f59b8`](https://github.com/mastra-ai/mastra/commit/20f59b876cf91199efbc49a0e36b391240708f08), [`aba393e`](https://github.com/mastra-ai/mastra/commit/aba393e2da7390c69b80e516a4f153cda6f09376), [`3d83d06`](https://github.com/mastra-ai/mastra/commit/3d83d06f776f00fb5f4163dddd32a030c5c20844), [`e2687a7`](https://github.com/mastra-ai/mastra/commit/e2687a7408790c384563816a9a28ed06735684c9), [`fdd54cf`](https://github.com/mastra-ai/mastra/commit/fdd54cf612a9af876e9fdd85e534454f6e7dd518), [`6315317`](https://github.com/mastra-ai/mastra/commit/63153175fe9a7b224e5be7c209bbebc01dd9b0d5), [`a371ac5`](https://github.com/mastra-ai/mastra/commit/a371ac534aa1bb368a1acf9d8b313378dfdc787e), [`0474c2b`](https://github.com/mastra-ai/mastra/commit/0474c2b2e7c7e1ad8691dca031284841391ff1ef), [`0a5fa1d`](https://github.com/mastra-ai/mastra/commit/0a5fa1d3cb0583889d06687155f26fd7d2edc76c), [`7e0e63e`](https://github.com/mastra-ai/mastra/commit/7e0e63e2e485e84442351f4c7a79a424c83539dc), [`ea43e64`](https://github.com/mastra-ai/mastra/commit/ea43e646dd95d507694b6112b0bf1df22ad552b2), [`f607106`](https://github.com/mastra-ai/mastra/commit/f607106854c6416c4a07d4082604b9f66d047221), [`30456b6`](https://github.com/mastra-ai/mastra/commit/30456b6b08c8fd17e109dd093b73d93b65e83bc5), [`9d11a8c`](https://github.com/mastra-ai/mastra/commit/9d11a8c1c8924eb975a245a5884d40ca1b7e0491), [`9d3b24b`](https://github.com/mastra-ai/mastra/commit/9d3b24b19407ae9c09586cf7766d38dc4dff4a69), [`00d1b16`](https://github.com/mastra-ai/mastra/commit/00d1b16b401199cb294fa23f43336547db4dca9b), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`62919a6`](https://github.com/mastra-ai/mastra/commit/62919a6ee0fbf3779ad21a97b1ec6696515d5104), [`d246696`](https://github.com/mastra-ai/mastra/commit/d246696139a3144a5b21b042d41c532688e957e1), [`354f9ce`](https://github.com/mastra-ai/mastra/commit/354f9ce1ca6af2074b6a196a23f8ec30012dccca), [`16e34ca`](https://github.com/mastra-ai/mastra/commit/16e34caa98b9a114b17a6125e4e3fd87f169d0d0), [`7020c06`](https://github.com/mastra-ai/mastra/commit/7020c0690b199d9da337f0e805f16948e557922e), [`8786a61`](https://github.com/mastra-ai/mastra/commit/8786a61fa54ba265f85eeff9985ca39863d18bb6), [`9467ea8`](https://github.com/mastra-ai/mastra/commit/9467ea87695749a53dfc041576410ebf9ee7bb67), [`7338d94`](https://github.com/mastra-ai/mastra/commit/7338d949380cf68b095342e8e42610dc51d557c1), [`c80dc16`](https://github.com/mastra-ai/mastra/commit/c80dc16e113e6cc159f510ffde501ad4711b2189), [`af8a57e`](https://github.com/mastra-ai/mastra/commit/af8a57ed9ba9685ad8601d5b71ae3706da6222f9), [`d63ffdb`](https://github.com/mastra-ai/mastra/commit/d63ffdbb2c11e76fe5ea45faab44bc15460f010c), [`47cee3e`](https://github.com/mastra-ai/mastra/commit/47cee3e137fe39109cf7fffd2a8cf47b76dc702e), [`1bd5104`](https://github.com/mastra-ai/mastra/commit/1bd51048b6da93507276d6623e3fd96a9e1a8944), [`e9837b5`](https://github.com/mastra-ai/mastra/commit/e9837b53699e18711b09e0ca010a4106376f2653), [`8f1b280`](https://github.com/mastra-ai/mastra/commit/8f1b280b7fe6999ec654f160cb69c1a8719e7a57), [`92dcf02`](https://github.com/mastra-ai/mastra/commit/92dcf029294210ac91b090900c1a0555a425c57a), [`0fd90a2`](https://github.com/mastra-ai/mastra/commit/0fd90a215caf5fca8099c15a67ca03e4427747a3), [`8fb2405`](https://github.com/mastra-ai/mastra/commit/8fb2405138f2d208b7962ad03f121ca25bcc28c5), [`12df98c`](https://github.com/mastra-ai/mastra/commit/12df98c4904643d9481f5c78f3bed443725b4c96)]:
17
+ - @mastra/core@1.26.0
18
+
19
+ ## 2.2.1-alpha.0
20
+
21
+ ### Patch Changes
22
+
23
+ - Fixed a security issue where several parsing and tracing paths could slow down on malformed or attacker-crafted input. Normal behavior is unchanged, and these packages now handle pathological input in linear time. ([#15566](https://github.com/mastra-ai/mastra/pull/15566))
24
+
25
+ - Updated dependencies [[`aba393e`](https://github.com/mastra-ai/mastra/commit/aba393e2da7390c69b80e516a4f153cda6f09376), [`0a5fa1d`](https://github.com/mastra-ai/mastra/commit/0a5fa1d3cb0583889d06687155f26fd7d2edc76c), [`ea43e64`](https://github.com/mastra-ai/mastra/commit/ea43e646dd95d507694b6112b0bf1df22ad552b2), [`00d1b16`](https://github.com/mastra-ai/mastra/commit/00d1b16b401199cb294fa23f43336547db4dca9b), [`af8a57e`](https://github.com/mastra-ai/mastra/commit/af8a57ed9ba9685ad8601d5b71ae3706da6222f9)]:
26
+ - @mastra/core@1.26.0-alpha.10
27
+
28
+ ## 2.2.0
29
+
30
+ ### Minor Changes
31
+
32
+ - Add RAG observability (#10898) ([#15137](https://github.com/mastra-ai/mastra/pull/15137))
33
+
34
+ Surfaces RAG ingestion and query operations in Mastra's AI tracing.
35
+
36
+ New span types in `@mastra/core/observability`:
37
+ - `RAG_INGESTION` (root) — wraps an ingestion pipeline run
38
+ - `RAG_EMBEDDING` — embedding call (used by ingestion and query)
39
+ - `RAG_VECTOR_OPERATION` — vector store I/O (`query`/`upsert`/`delete`/`fetch`)
40
+ - `RAG_ACTION` — `chunk` / `extract_metadata` / `rerank`
41
+ - `GRAPH_ACTION` — non-RAG graph `build` / `traverse` / `update` / `prune`
42
+
43
+ New helpers exported from `@mastra/core/observability`:
44
+ - `startRagIngestion(opts)` — manual: returns `{ span, observabilityContext }`
45
+ - `withRagIngestion(opts, fn)` — scoped: runs `fn(observabilityContext)`,
46
+ attaches the return value as the span's output, routes thrown errors to
47
+ `span.error(...)`
48
+
49
+ Wired in `@mastra/rag`:
50
+ - `vectorQuerySearch` emits `RAG_EMBEDDING` (mode: `query`) and
51
+ `RAG_VECTOR_OPERATION` (operation: `query`)
52
+ - `rerank` / `rerankWithScorer` emit `RAG_ACTION` (action: `rerank`)
53
+ - `MDocument.chunk` emits `RAG_ACTION` (action: `chunk`) and
54
+ `RAG_ACTION` (action: `extract_metadata`)
55
+ - `createGraphRAGTool` emits `GRAPH_ACTION` (action: `build` / `traverse`)
56
+ - `createVectorQueryTool` and `createGraphRAGTool` thread
57
+ `observabilityContext` from the agent's `TOOL_CALL` span automatically
58
+
59
+ All new instrumentation is opt-in: functions accept an optional
60
+ `observabilityContext` and no-op when absent, so existing callers are
61
+ unaffected.
62
+
63
+ ### Patch Changes
64
+
65
+ - Updated dependencies [[`8db7663`](https://github.com/mastra-ai/mastra/commit/8db7663c9a9c735828094c359d2e327fd4f8fba3), [`153e864`](https://github.com/mastra-ai/mastra/commit/153e86476b425db7cd0dc8490050096e92964a38), [`715710d`](https://github.com/mastra-ai/mastra/commit/715710d12fa47cf88e09d41f13843eddc29327b0), [`378c6c4`](https://github.com/mastra-ai/mastra/commit/378c6c4755726e8d8cf83a14809b350b90d46c62), [`9f91fd5`](https://github.com/mastra-ai/mastra/commit/9f91fd538ab2a44f8cc740bcad8e51205f74fbea), [`ba6fa9c`](https://github.com/mastra-ai/mastra/commit/ba6fa9cc0f3e1912c49fd70d4c3bb8c44903ddaa)]:
66
+ - @mastra/core@1.24.0
67
+
68
+ ## 2.2.0-alpha.0
69
+
70
+ ### Minor Changes
71
+
72
+ - Add RAG observability (#10898) ([#15137](https://github.com/mastra-ai/mastra/pull/15137))
73
+
74
+ Surfaces RAG ingestion and query operations in Mastra's AI tracing.
75
+
76
+ New span types in `@mastra/core/observability`:
77
+ - `RAG_INGESTION` (root) — wraps an ingestion pipeline run
78
+ - `RAG_EMBEDDING` — embedding call (used by ingestion and query)
79
+ - `RAG_VECTOR_OPERATION` — vector store I/O (`query`/`upsert`/`delete`/`fetch`)
80
+ - `RAG_ACTION` — `chunk` / `extract_metadata` / `rerank`
81
+ - `GRAPH_ACTION` — non-RAG graph `build` / `traverse` / `update` / `prune`
82
+
83
+ New helpers exported from `@mastra/core/observability`:
84
+ - `startRagIngestion(opts)` — manual: returns `{ span, observabilityContext }`
85
+ - `withRagIngestion(opts, fn)` — scoped: runs `fn(observabilityContext)`,
86
+ attaches the return value as the span's output, routes thrown errors to
87
+ `span.error(...)`
88
+
89
+ Wired in `@mastra/rag`:
90
+ - `vectorQuerySearch` emits `RAG_EMBEDDING` (mode: `query`) and
91
+ `RAG_VECTOR_OPERATION` (operation: `query`)
92
+ - `rerank` / `rerankWithScorer` emit `RAG_ACTION` (action: `rerank`)
93
+ - `MDocument.chunk` emits `RAG_ACTION` (action: `chunk`) and
94
+ `RAG_ACTION` (action: `extract_metadata`)
95
+ - `createGraphRAGTool` emits `GRAPH_ACTION` (action: `build` / `traverse`)
96
+ - `createVectorQueryTool` and `createGraphRAGTool` thread
97
+ `observabilityContext` from the agent's `TOOL_CALL` span automatically
98
+
99
+ All new instrumentation is opt-in: functions accept an optional
100
+ `observabilityContext` and no-op when absent, so existing callers are
101
+ unaffected.
102
+
103
+ ### Patch Changes
104
+
105
+ - Updated dependencies [[`8db7663`](https://github.com/mastra-ai/mastra/commit/8db7663c9a9c735828094c359d2e327fd4f8fba3), [`715710d`](https://github.com/mastra-ai/mastra/commit/715710d12fa47cf88e09d41f13843eddc29327b0), [`378c6c4`](https://github.com/mastra-ai/mastra/commit/378c6c4755726e8d8cf83a14809b350b90d46c62), [`9f91fd5`](https://github.com/mastra-ai/mastra/commit/9f91fd538ab2a44f8cc740bcad8e51205f74fbea), [`ba6fa9c`](https://github.com/mastra-ai/mastra/commit/ba6fa9cc0f3e1912c49fd70d4c3bb8c44903ddaa)]:
106
+ - @mastra/core@1.24.0-alpha.1
9
107
 
10
108
  ## 2.1.3
11
109
 
@@ -3,7 +3,7 @@ name: mastra-rag
3
3
  description: Documentation for @mastra/rag. Use when working with @mastra/rag APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/rag"
6
- version: "0.0.0-studio-deploy-20260404184540"
6
+ version: "0.0.0-studio-cli-20260504022012"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.0-studio-deploy-20260404184540",
2
+ "version": "0.0.0-studio-cli-20260504022012",
3
3
  "package": "@mastra/rag",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -1,3 +1,4 @@
1
+ import type { ObservabilityContext } from '@mastra/core/observability';
1
2
  import { Document as Chunk } from './schema/index.js';
2
3
  import type { ChunkParams, ExtractParams, HTMLChunkOptions, RecursiveChunkOptions, CharacterChunkOptions, TokenChunkOptions, MarkdownChunkOptions, SemanticMarkdownChunkOptions, JsonChunkOptions, LatexChunkOptions, SentenceChunkOptions } from './types.js';
3
4
  export declare class MDocument {
@@ -28,7 +29,9 @@ export declare class MDocument {
28
29
  chunkMarkdown(options?: MarkdownChunkOptions): Promise<void>;
29
30
  chunkSentence(options?: SentenceChunkOptions): Promise<void>;
30
31
  chunkSemanticMarkdown(options?: SemanticMarkdownChunkOptions): Promise<void>;
31
- chunk(params?: ChunkParams): Promise<Chunk[]>;
32
+ chunk(params?: ChunkParams, options?: {
33
+ observabilityContext?: ObservabilityContext;
34
+ }): Promise<Chunk[]>;
32
35
  getDocs(): Chunk[];
33
36
  getText(): string[];
34
37
  getMetadata(): Record<string, any>[];
@@ -1 +1 @@
1
- {"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/document/document.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,IAA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qBAAa,2BAA4B,SAAQ,eAAe;IAC9D,OAAO,CAAC,SAAS,CAAW;IAC5B,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAmB;IACvC,OAAO,CAAC,eAAe,CAAmB;gBAE9B,EACV,aAAmB,EACnB,YAA4B,EAC5B,SAAS,EACT,SAAS,EAAE,iBAAiB,EAC5B,cAA0B,EAC1B,iBAAyB,EACzB,GAAG,WAAW,EACf,GAAE,4BAA4B,GAAG;QAAE,SAAS,CAAC,EAAE,QAAQ,CAAA;KAAO;IAkB/D,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,sBAAsB;IAgE9B,OAAO,CAAC,qBAAqB;IAqC7B,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE;IAgB/C,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,QAAQ,EAAE;IAuB/E,kBAAkB,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,QAAQ,EAAE;IAYrD,MAAM,CAAC,YAAY,CAAC,EAClB,YAA4B,EAC5B,SAAS,EACT,OAAY,GACb,EAAE;QACD,YAAY,CAAC,EAAE,gBAAgB,CAAC;QAChC,SAAS,CAAC,EAAE,aAAa,CAAC;QAC1B,OAAO,CAAC,EAAE,4BAA4B,CAAC;KACxC,GAAG,2BAA2B;CA6BhC"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ var observability = require('@mastra/core/observability');
3
4
  var agent = require('@mastra/core/agent');
4
5
  var crypto = require('crypto');
5
6
  var zod = require('zod');
@@ -6108,7 +6109,7 @@ var SemanticMarkdownTransformer = class _SemanticMarkdownTransformer extends Tex
6108
6109
  let currentTitle = "";
6109
6110
  let currentDepth = 0;
6110
6111
  let inCodeBlock = false;
6111
- const headerRegex = /^(#+)\s+(.+)$/;
6112
+ const headerRegex = /^(#{1,6})[ \t]+(\S[^\n]{0,1024})$/;
6112
6113
  for (let i = 0; i < lines.length; i++) {
6113
6114
  const line = lines[i];
6114
6115
  const headerMatch = line.match(headerRegex);
@@ -6917,15 +6918,47 @@ var MDocument = class _MDocument {
6917
6918
  const textSplit = rt.transformDocuments(this.chunks);
6918
6919
  this.chunks = textSplit;
6919
6920
  }
6920
- async chunk(params) {
6921
+ async chunk(params, options) {
6921
6922
  const { strategy: passedStrategy, extract, ...chunkOptions } = params || {};
6922
6923
  const strategy = passedStrategy || this.defaultStrategy();
6923
- validateChunkParams(strategy, chunkOptions);
6924
- await this.chunkBy(strategy, chunkOptions);
6925
- if (extract) {
6926
- await this.extractMetadata(extract);
6924
+ const parentSpan = options?.observabilityContext?.tracingContext?.currentSpan;
6925
+ const chunkSpan = parentSpan?.createChildSpan({
6926
+ type: observability.SpanType.RAG_ACTION,
6927
+ name: `rag chunk: ${strategy}`,
6928
+ input: { strategy },
6929
+ attributes: {
6930
+ action: "chunk",
6931
+ strategy,
6932
+ chunkSize: chunkOptions?.size,
6933
+ chunkOverlap: chunkOptions?.overlap
6934
+ }
6935
+ });
6936
+ try {
6937
+ validateChunkParams(strategy, chunkOptions);
6938
+ await this.chunkBy(strategy, chunkOptions);
6939
+ if (extract) {
6940
+ const extractSpan = chunkSpan?.createChildSpan({
6941
+ type: observability.SpanType.RAG_ACTION,
6942
+ name: "rag extract metadata",
6943
+ attributes: {
6944
+ action: "extract_metadata",
6945
+ extractor: Object.keys(extract).join(",")
6946
+ }
6947
+ });
6948
+ try {
6949
+ await this.extractMetadata(extract);
6950
+ } catch (err) {
6951
+ extractSpan?.error({ error: err, endSpan: true });
6952
+ throw err;
6953
+ }
6954
+ extractSpan?.end();
6955
+ }
6956
+ chunkSpan?.end({ output: { chunkCount: this.chunks.length } });
6957
+ return this.chunks;
6958
+ } catch (err) {
6959
+ chunkSpan?.error({ error: err, endSpan: true });
6960
+ throw err;
6927
6961
  }
6928
- return this.chunks;
6929
6962
  }
6930
6963
  getDocs() {
6931
6964
  return this.chunks;
@@ -7047,14 +7080,27 @@ async function executeRerank({
7047
7080
  scorer,
7048
7081
  options
7049
7082
  }) {
7050
- const { queryEmbedding, topK = 3 } = options;
7083
+ const { queryEmbedding, topK = 3, observabilityContext } = options;
7084
+ const rerankSpan = observabilityContext?.tracingContext?.currentSpan?.createChildSpan({
7085
+ type: observability.SpanType.RAG_ACTION,
7086
+ name: `rag rerank`,
7087
+ input: { query, candidateCount: results.length },
7088
+ attributes: {
7089
+ action: "rerank",
7090
+ candidateCount: results.length,
7091
+ topN: topK,
7092
+ scorer: scorer?.constructor?.name
7093
+ }
7094
+ });
7051
7095
  const weights = {
7052
7096
  ...DEFAULT_WEIGHTS,
7053
7097
  ...options.weights
7054
7098
  };
7055
7099
  const sum = Object.values(weights).reduce((acc, w) => acc.plus(w.toString()), new big_js.Big(0));
7056
7100
  if (!sum.eq(1)) {
7057
- throw new Error(`Weights must add up to 1. Got ${sum} from ${weights}`);
7101
+ const err = new Error(`Weights must add up to 1. Got ${sum} from ${weights}`);
7102
+ rerankSpan?.error({ error: err, endSpan: true });
7103
+ throw err;
7058
7104
  }
7059
7105
  const resultLength = results.length;
7060
7106
  const queryAnalysis = queryEmbedding ? analyzeQueryEmbedding(queryEmbedding) : null;
@@ -7087,7 +7133,9 @@ async function executeRerank({
7087
7133
  };
7088
7134
  })
7089
7135
  );
7090
- return scoredResults.sort((a, b) => b.score - a.score).slice(0, topK);
7136
+ const final = scoredResults.sort((a, b) => b.score - a.score).slice(0, topK);
7137
+ rerankSpan?.end({ output: { returned: final.length } });
7138
+ return final;
7091
7139
  }
7092
7140
  async function rerankWithScorer({
7093
7141
  results,
@@ -7377,33 +7425,67 @@ var vectorQuerySearch = async ({
7377
7425
  includeVectors = false,
7378
7426
  maxRetries = 2,
7379
7427
  databaseConfig = {},
7380
- providerOptions
7428
+ providerOptions,
7429
+ observabilityContext
7381
7430
  }) => {
7431
+ const parentSpan = observabilityContext?.tracingContext?.currentSpan;
7432
+ const embedSpan = parentSpan?.createChildSpan({
7433
+ type: observability.SpanType.RAG_EMBEDDING,
7434
+ name: `rag embed: query`,
7435
+ input: queryText,
7436
+ attributes: {
7437
+ mode: "query",
7438
+ model: model?.modelId,
7439
+ provider: model?.provider,
7440
+ inputCount: 1
7441
+ }
7442
+ });
7382
7443
  let embeddingResult;
7383
- if (model.specificationVersion === "v3") {
7384
- embeddingResult = await vector.embedV3({
7385
- model,
7386
- value: queryText,
7387
- maxRetries,
7388
- // Type assertion needed: providerOptions type is a union, but embedV3 expects specific version
7389
- ...providerOptions && { providerOptions }
7390
- });
7391
- } else if (model.specificationVersion === "v2") {
7392
- embeddingResult = await vector.embedV2({
7393
- model,
7394
- value: queryText,
7395
- maxRetries,
7396
- // Type assertion needed: providerOptions type is a union, but embedV2 expects specific version
7397
- ...providerOptions && { providerOptions }
7398
- });
7399
- } else {
7400
- embeddingResult = await vector.embedV1({
7401
- value: queryText,
7402
- model,
7403
- maxRetries
7404
- });
7444
+ try {
7445
+ if (model.specificationVersion === "v3") {
7446
+ embeddingResult = await vector.embedV3({
7447
+ model,
7448
+ value: queryText,
7449
+ maxRetries,
7450
+ // Type assertion needed: providerOptions type is a union, but embedV3 expects specific version
7451
+ ...providerOptions && {
7452
+ providerOptions
7453
+ }
7454
+ });
7455
+ } else if (model.specificationVersion === "v2") {
7456
+ embeddingResult = await vector.embedV2({
7457
+ model,
7458
+ value: queryText,
7459
+ maxRetries,
7460
+ // Type assertion needed: providerOptions type is a union, but embedV2 expects specific version
7461
+ ...providerOptions && {
7462
+ providerOptions
7463
+ }
7464
+ });
7465
+ } else {
7466
+ embeddingResult = await vector.embedV1({
7467
+ value: queryText,
7468
+ model,
7469
+ maxRetries
7470
+ });
7471
+ }
7472
+ } catch (err) {
7473
+ embedSpan?.error({ error: err, endSpan: true });
7474
+ throw err;
7405
7475
  }
7406
7476
  const embedding = embeddingResult.embedding;
7477
+ const embedUsage = embeddingResult?.usage;
7478
+ embedSpan?.end({
7479
+ attributes: {
7480
+ dimensions: embedding?.length,
7481
+ ...embedUsage && {
7482
+ usage: {
7483
+ inputTokens: embedUsage.tokens ?? embedUsage.promptTokens ?? embedUsage.inputTokens
7484
+ }
7485
+ }
7486
+ },
7487
+ output: { dimensions: embedding?.length }
7488
+ });
7407
7489
  const queryParams = {
7408
7490
  indexName,
7409
7491
  queryVector: embedding,
@@ -7411,7 +7493,29 @@ var vectorQuerySearch = async ({
7411
7493
  filter: queryFilter,
7412
7494
  includeVector: includeVectors
7413
7495
  };
7414
- const results = await vectorStore.query({ ...queryParams, ...databaseSpecificParams(databaseConfig) });
7496
+ const querySpan = parentSpan?.createChildSpan({
7497
+ type: observability.SpanType.RAG_VECTOR_OPERATION,
7498
+ name: `rag vector: query`,
7499
+ // Pass filter as-is; the observability layer's deepClean handles
7500
+ // size limits and sanitization centrally.
7501
+ input: { topK, filter: queryFilter },
7502
+ attributes: {
7503
+ operation: "query",
7504
+ indexName,
7505
+ topK,
7506
+ dimensions: embedding?.length
7507
+ }
7508
+ });
7509
+ let results;
7510
+ try {
7511
+ results = await vectorStore.query({ ...queryParams, ...databaseSpecificParams(databaseConfig) });
7512
+ } catch (err) {
7513
+ querySpan?.error({ error: err, endSpan: true });
7514
+ throw err;
7515
+ }
7516
+ querySpan?.end({
7517
+ output: { returned: results?.length ?? 0 }
7518
+ });
7415
7519
  return { results, queryEmbedding: embedding };
7416
7520
  };
7417
7521
  var databaseSpecificParams = (databaseConfig) => {
@@ -7675,7 +7779,9 @@ var createGraphRAGTool = (options) => {
7675
7779
  outputSchema,
7676
7780
  description: toolDescription,
7677
7781
  execute: async (inputData, context) => {
7678
- const { requestContext, mastra } = context || {};
7782
+ const { requestContext, mastra, tracingContext } = context || {};
7783
+ const observabilityContext = observability.createObservabilityContext(tracingContext);
7784
+ const parentSpan = observabilityContext.tracingContext?.currentSpan;
7679
7785
  const indexName = requestContext?.get("indexName") ?? options.indexName;
7680
7786
  const vectorStoreName = "vectorStore" in options ? storeName : requestContext?.get("vectorStoreName") ?? storeName;
7681
7787
  if (!indexName) throw new Error(`indexName is required, got: ${indexName}`);
@@ -7713,7 +7819,8 @@ var createGraphRAGTool = (options) => {
7713
7819
  queryFilter: Object.keys(queryFilter || {}).length > 0 ? queryFilter : void 0,
7714
7820
  topK: topKValue,
7715
7821
  includeVectors: true,
7716
- providerOptions
7822
+ providerOptions,
7823
+ observabilityContext
7717
7824
  });
7718
7825
  if (logger) {
7719
7826
  logger.debug("vectorQuerySearch returned results", { count: results.length });
@@ -7729,17 +7836,50 @@ var createGraphRAGTool = (options) => {
7729
7836
  if (logger) {
7730
7837
  logger.debug("Initializing graph", { chunkCount: chunks.length, embeddingCount: embeddings.length });
7731
7838
  }
7732
- graphRag.createGraph(chunks, embeddings);
7839
+ const buildSpan = parentSpan?.createChildSpan({
7840
+ type: observability.SpanType.GRAPH_ACTION,
7841
+ name: "graph build",
7842
+ input: { nodeCount: chunks.length },
7843
+ attributes: {
7844
+ action: "build",
7845
+ nodeCount: chunks.length,
7846
+ threshold: graphOptions.threshold
7847
+ }
7848
+ });
7849
+ try {
7850
+ graphRag.createGraph(chunks, embeddings);
7851
+ } catch (err) {
7852
+ buildSpan?.error({ error: err, endSpan: true });
7853
+ throw err;
7854
+ }
7855
+ buildSpan?.end();
7733
7856
  isInitialized = true;
7734
7857
  } else if (logger) {
7735
7858
  logger.debug("Graph already initialized, skipping graph construction");
7736
7859
  }
7737
- const rerankedResults = graphRag.query({
7738
- query: queryEmbedding,
7739
- topK: topKValue,
7740
- randomWalkSteps,
7741
- restartProb
7860
+ const traverseSpan = parentSpan?.createChildSpan({
7861
+ type: observability.SpanType.GRAPH_ACTION,
7862
+ name: "graph traverse",
7863
+ input: { topK: topKValue, randomWalkSteps, restartProb },
7864
+ attributes: {
7865
+ action: "traverse",
7866
+ startNodes: 1,
7867
+ maxDepth: randomWalkSteps
7868
+ }
7742
7869
  });
7870
+ let rerankedResults;
7871
+ try {
7872
+ rerankedResults = graphRag.query({
7873
+ query: queryEmbedding,
7874
+ topK: topKValue,
7875
+ randomWalkSteps,
7876
+ restartProb
7877
+ });
7878
+ } catch (err) {
7879
+ traverseSpan?.error({ error: err, endSpan: true });
7880
+ throw err;
7881
+ }
7882
+ traverseSpan?.end({ output: { returned: rerankedResults.length } });
7743
7883
  if (logger) {
7744
7884
  logger.debug("GraphRAG query returned results", { count: rerankedResults.length });
7745
7885
  }
@@ -7778,7 +7918,8 @@ var createVectorQueryTool = (options) => {
7778
7918
  inputSchema,
7779
7919
  outputSchema,
7780
7920
  execute: async (inputData, context) => {
7781
- const { requestContext, mastra } = context || {};
7921
+ const { requestContext, mastra, tracingContext } = context || {};
7922
+ const observabilityContext = observability.createObservabilityContext(tracingContext);
7782
7923
  const indexName = requestContext?.get("indexName") ?? options.indexName;
7783
7924
  const vectorStoreName = "vectorStore" in options ? storeName : requestContext?.get("vectorStoreName") ?? storeName;
7784
7925
  const includeVectors = requestContext?.get("includeVectors") ?? options.includeVectors ?? false;
@@ -7819,7 +7960,8 @@ var createVectorQueryTool = (options) => {
7819
7960
  topK: topKValue,
7820
7961
  includeVectors,
7821
7962
  databaseConfig,
7822
- providerOptions
7963
+ providerOptions,
7964
+ observabilityContext
7823
7965
  });
7824
7966
  if (logger) {
7825
7967
  logger.debug("vectorQuerySearch returned results", { count: results.length });
@@ -7836,13 +7978,15 @@ var createVectorQueryTool = (options) => {
7836
7978
  scorer: reranker.model,
7837
7979
  options: {
7838
7980
  ...reranker.options,
7839
- topK: reranker.options?.topK || topKValue
7981
+ topK: reranker.options?.topK || topKValue,
7982
+ observabilityContext
7840
7983
  }
7841
7984
  });
7842
7985
  } else {
7843
7986
  rerankedResults = await rerank(results, queryText, reranker.model, {
7844
7987
  ...reranker.options,
7845
- topK: reranker.options?.topK || topKValue
7988
+ topK: reranker.options?.topK || topKValue,
7989
+ observabilityContext
7846
7990
  });
7847
7991
  }
7848
7992
  if (logger) {