@mastra/memory 1.10.1-alpha.3 → 1.11.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/{chunk-SKRONGCV.js → chunk-D4D6ZFBQ.js} +355 -105
  3. package/dist/chunk-D4D6ZFBQ.js.map +1 -0
  4. package/dist/{chunk-DTAZSLVU.cjs → chunk-VINRPDYQ.cjs} +355 -105
  5. package/dist/chunk-VINRPDYQ.cjs.map +1 -0
  6. package/dist/docs/SKILL.md +1 -1
  7. package/dist/docs/assets/SOURCE_MAP.json +47 -47
  8. package/dist/docs/references/docs-memory-observational-memory.md +49 -4
  9. package/dist/docs/references/reference-memory-observational-memory.md +32 -6
  10. package/dist/index.cjs +577 -36
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.ts +46 -0
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +570 -29
  15. package/dist/index.js.map +1 -1
  16. package/dist/{observational-memory-XIZTJN3S.cjs → observational-memory-FATH657E.cjs} +26 -26
  17. package/dist/{observational-memory-XIZTJN3S.cjs.map → observational-memory-FATH657E.cjs.map} +1 -1
  18. package/dist/{observational-memory-UGDENJPE.js → observational-memory-SN7GKMHZ.js} +3 -3
  19. package/dist/{observational-memory-UGDENJPE.js.map → observational-memory-SN7GKMHZ.js.map} +1 -1
  20. package/dist/processors/index.cjs +24 -24
  21. package/dist/processors/index.js +1 -1
  22. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  23. package/dist/processors/observational-memory/observation-strategies/base.d.ts +9 -0
  24. package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -1
  25. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -1
  26. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -1
  27. package/dist/processors/observational-memory/observation-strategies/types.d.ts +2 -0
  28. package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
  29. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
  30. package/dist/processors/observational-memory/observation-turn/turn.d.ts +4 -0
  31. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
  32. package/dist/processors/observational-memory/observational-memory.d.ts +27 -2
  33. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  34. package/dist/processors/observational-memory/observer-runner.d.ts +14 -3
  35. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -1
  36. package/dist/processors/observational-memory/processor.d.ts +8 -12
  37. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  38. package/dist/processors/observational-memory/reflector-runner.d.ts +11 -1
  39. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  40. package/dist/processors/observational-memory/tracing.d.ts +17 -0
  41. package/dist/processors/observational-memory/tracing.d.ts.map +1 -0
  42. package/dist/processors/observational-memory/types.d.ts +19 -1
  43. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  44. package/dist/tools/om-tools.d.ts +96 -4
  45. package/dist/tools/om-tools.d.ts.map +1 -1
  46. package/package.json +7 -7
  47. package/dist/chunk-DTAZSLVU.cjs.map +0 -1
  48. package/dist/chunk-SKRONGCV.js.map +0 -1
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.10.1-alpha.3"
6
+ version: "1.11.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,120 +1,120 @@
1
1
  {
2
- "version": "1.10.1-alpha.3",
2
+ "version": "1.11.0",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {
5
5
  "ModelByInputTokens": {
6
6
  "types": "dist/processors/index.d.ts",
7
- "implementation": "dist/chunk-SKRONGCV.js",
8
- "line": 665
7
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
8
+ "line": 666
9
9
  },
10
10
  "OBSERVER_SYSTEM_PROMPT": {
11
11
  "types": "dist/processors/index.d.ts",
12
- "implementation": "dist/chunk-SKRONGCV.js"
12
+ "implementation": "dist/chunk-D4D6ZFBQ.js"
13
13
  },
14
14
  "ObservationalMemory": {
15
15
  "types": "dist/processors/index.d.ts",
16
- "implementation": "dist/chunk-SKRONGCV.js",
17
- "line": 5518
16
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
17
+ "line": 5698
18
18
  },
19
19
  "ObservationalMemoryProcessor": {
20
20
  "types": "dist/processors/index.d.ts",
21
- "implementation": "dist/chunk-SKRONGCV.js",
22
- "line": 7976
21
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
22
+ "line": 8220
23
23
  },
24
24
  "TokenCounter": {
25
25
  "types": "dist/processors/index.d.ts",
26
- "implementation": "dist/chunk-SKRONGCV.js",
27
- "line": 5070
26
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
27
+ "line": 5250
28
28
  },
29
29
  "buildObserverPrompt": {
30
30
  "types": "dist/processors/index.d.ts",
31
- "implementation": "dist/chunk-SKRONGCV.js",
32
- "line": 3229
31
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
32
+ "line": 3277
33
33
  },
34
34
  "buildObserverSystemPrompt": {
35
35
  "types": "dist/processors/index.d.ts",
36
- "implementation": "dist/chunk-SKRONGCV.js",
37
- "line": 2703
36
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
37
+ "line": 2751
38
38
  },
39
39
  "combineObservationGroupRanges": {
40
40
  "types": "dist/processors/index.d.ts",
41
- "implementation": "dist/chunk-SKRONGCV.js",
42
- "line": 754
41
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
42
+ "line": 755
43
43
  },
44
44
  "deriveObservationGroupProvenance": {
45
45
  "types": "dist/processors/index.d.ts",
46
- "implementation": "dist/chunk-SKRONGCV.js",
47
- "line": 781
46
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
47
+ "line": 782
48
48
  },
49
49
  "extractCurrentTask": {
50
50
  "types": "dist/processors/index.d.ts",
51
- "implementation": "dist/chunk-SKRONGCV.js",
52
- "line": 3343
51
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
52
+ "line": 3391
53
53
  },
54
54
  "formatMessagesForObserver": {
55
55
  "types": "dist/processors/index.d.ts",
56
- "implementation": "dist/chunk-SKRONGCV.js",
57
- "line": 2969
56
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
57
+ "line": 3017
58
58
  },
59
59
  "getObservationsAsOf": {
60
60
  "types": "dist/processors/index.d.ts",
61
- "implementation": "dist/chunk-SKRONGCV.js",
62
- "line": 8148
61
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
62
+ "line": 8398
63
63
  },
64
64
  "hasCurrentTaskSection": {
65
65
  "types": "dist/processors/index.d.ts",
66
- "implementation": "dist/chunk-SKRONGCV.js",
67
- "line": 3331
66
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
67
+ "line": 3379
68
68
  },
69
69
  "injectAnchorIds": {
70
70
  "types": "dist/processors/index.d.ts",
71
- "implementation": "dist/chunk-SKRONGCV.js",
72
- "line": 2260
71
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
72
+ "line": 2308
73
73
  },
74
74
  "optimizeObservationsForContext": {
75
75
  "types": "dist/processors/index.d.ts",
76
- "implementation": "dist/chunk-SKRONGCV.js",
77
- "line": 3354
76
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
77
+ "line": 3402
78
78
  },
79
79
  "parseAnchorId": {
80
80
  "types": "dist/processors/index.d.ts",
81
- "implementation": "dist/chunk-SKRONGCV.js",
82
- "line": 2233
81
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
82
+ "line": 2281
83
83
  },
84
84
  "parseObservationGroups": {
85
85
  "types": "dist/processors/index.d.ts",
86
- "implementation": "dist/chunk-SKRONGCV.js",
87
- "line": 726
86
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
87
+ "line": 727
88
88
  },
89
89
  "parseObserverOutput": {
90
90
  "types": "dist/processors/index.d.ts",
91
- "implementation": "dist/chunk-SKRONGCV.js",
92
- "line": 3239
91
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
92
+ "line": 3287
93
93
  },
94
94
  "reconcileObservationGroupsFromReflection": {
95
95
  "types": "dist/processors/index.d.ts",
96
- "implementation": "dist/chunk-SKRONGCV.js",
97
- "line": 808
96
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
97
+ "line": 809
98
98
  },
99
99
  "renderObservationGroupsForReflection": {
100
100
  "types": "dist/processors/index.d.ts",
101
- "implementation": "dist/chunk-SKRONGCV.js",
102
- "line": 761
101
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
102
+ "line": 762
103
103
  },
104
104
  "stripEphemeralAnchorIds": {
105
105
  "types": "dist/processors/index.d.ts",
106
- "implementation": "dist/chunk-SKRONGCV.js",
107
- "line": 2290
106
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
107
+ "line": 2338
108
108
  },
109
109
  "stripObservationGroups": {
110
110
  "types": "dist/processors/index.d.ts",
111
- "implementation": "dist/chunk-SKRONGCV.js",
112
- "line": 748
111
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
112
+ "line": 749
113
113
  },
114
114
  "wrapInObservationGroup": {
115
115
  "types": "dist/processors/index.d.ts",
116
- "implementation": "dist/chunk-SKRONGCV.js",
117
- "line": 719
116
+ "implementation": "dist/chunk-D4D6ZFBQ.js",
117
+ "line": 720
118
118
  },
119
119
  "OBSERVATIONAL_MEMORY_DEFAULTS": {
120
120
  "types": "dist/processors/index.d.ts",
@@ -161,7 +161,7 @@
161
161
  "processors": {
162
162
  "index": "dist/processors/index.js",
163
163
  "chunks": [
164
- "chunk-SKRONGCV.js",
164
+ "chunk-D4D6ZFBQ.js",
165
165
  "chunk-LSJJAJAF.js"
166
166
  ]
167
167
  }
@@ -95,27 +95,72 @@ The result is a three-tier system:
95
95
 
96
96
  Normal OM compresses messages into observations, which is great for staying on task — but the original wording is gone. Retrieval mode fixes this by keeping each observation group linked to the raw messages that produced it. When the agent needs exact wording, tool output, or chronology that the summary compressed away, it can call a `recall` tool to page through the source messages.
97
97
 
98
+ #### Browsing only
99
+
100
+ Set `retrieval: true` to enable the recall tool for browsing raw messages. No vector store needed. By default, the recall tool can browse across all threads for the current resource.
101
+
98
102
  ```typescript
99
103
  const memory = new Memory({
100
104
  options: {
101
105
  observationalMemory: {
102
106
  model: 'google/gemini-2.5-flash',
103
- scope: 'thread',
104
107
  retrieval: true,
105
108
  },
106
109
  },
107
110
  })
108
111
  ```
109
112
 
113
+ #### With semantic search
114
+
115
+ Set `retrieval: { vector: true }` to also enable semantic search. This reuses the vector store and embedder already configured on your Memory instance:
116
+
117
+ ```typescript
118
+ const memory = new Memory({
119
+ storage,
120
+ vector: myVectorStore,
121
+ embedder: myEmbedder,
122
+ options: {
123
+ observationalMemory: {
124
+ model: 'google/gemini-2.5-flash',
125
+ retrieval: { vector: true },
126
+ },
127
+ },
128
+ })
129
+ ```
130
+
131
+ When vector search is configured, new observation groups are automatically indexed at buffer time and during synchronous observation (fire-and-forget, non-blocking). Semantic search returns observation-group matches with their raw source message ID ranges, so the recall tool can show the summarized memory alongside where it came from.
132
+
133
+ #### Restricting to the current thread
134
+
135
+ By default, the recall tool scope is `'resource'` — the agent can list threads, browse other threads, and search across all conversations. Set `scope: 'thread'` to restrict the agent to only the current thread:
136
+
137
+ ```typescript
138
+ const memory = new Memory({
139
+ options: {
140
+ observationalMemory: {
141
+ model: 'google/gemini-2.5-flash',
142
+ retrieval: { vector: true, scope: 'thread' },
143
+ },
144
+ },
145
+ })
146
+ ```
147
+
148
+ #### What retrieval enables
149
+
110
150
  With retrieval mode enabled, OM:
111
151
 
112
152
  - Stores a `range` (e.g. `startId:endId`) on each observation group pointing to the messages it was derived from
153
+
113
154
  - Keeps range metadata visible in the agent's context so the agent knows which observations map to which messages
114
- - Registers a `recall` tool the agent can call to page through the raw messages behind any range
115
155
 
116
- Retrieval mode is only active for thread-scoped OM. Setting `retrieval: true` with `scope: 'resource'` has no effect — OM keeps resource-scoped behavior but skips retrieval-mode context and does not register the `recall` tool.
156
+ - Registers a `recall` tool the agent can call to:
157
+
158
+ - Page through the raw messages behind any observation group range
159
+ - Search by semantic similarity (`mode: "search"` with a `query` string) — requires `vector: true`
160
+ - List all threads (`mode: "threads"`), browse other threads (`threadId`), and search across all threads (default `scope: 'resource'`)
161
+ - When `scope: 'thread'`: restrict browsing and search to the current thread only
117
162
 
118
- See the [recall tool reference](https://mastra.ai/reference/memory/observational-memory) for the full API (detail levels, part indexing, pagination, and token limiting).
163
+ See the [recall tool reference](https://mastra.ai/reference/memory/observational-memory) for the full API (detail levels, part indexing, pagination, cross-thread browsing, and token limiting).
119
164
 
120
165
  ## Models
121
166
 
@@ -38,7 +38,7 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
38
38
 
39
39
  **shareTokenBudget** (`boolean`): Share the token budget between messages and observations. When enabled, the total budget is \`observation.messageTokens + reflection.observationTokens\`. Messages can use more space when observations are small, and vice versa. This maximizes context usage through flexible allocation. \`shareTokenBudget\` is not yet compatible with async buffering. You must set \`observation: { bufferTokens: false }\` when using this option (this is a temporary limitation). (Default: `false`)
40
40
 
41
- **retrieval** (`boolean`): \*\*Experimental.\*\* Enable retrieval-mode observation groups as durable pointers to raw message history. Retrieval mode is only active when \`scope\` is \`'thread'\`. If you set \`retrieval: true\` with \`scope: 'resource'\`, OM keeps resource-scoped memory behavior but skips retrieval-mode context and does not register the \`recall\` tool. (Default: `false`)
41
+ **retrieval** (`boolean | { vector?: boolean; scope?: 'thread' | 'resource' }`): \*\*Experimental.\*\* Enable retrieval-mode observation groups as durable pointers to raw message history. \`true\` enables cross-thread browsing by default. \`{ vector: true }\` also enables semantic search using Memory's vector store and embedder. \`{ scope: 'thread' }\` restricts the recall tool to the current thread only. Default scope is \`'resource'\`. (Default: `false`)
42
42
 
43
43
  **observation** (`ObservationalMemoryObservationConfig`): Configuration for the observation step. Controls when the Observer agent runs and how it behaves.
44
44
 
@@ -578,21 +578,31 @@ The standalone `ObservationalMemory` class accepts all the same options as the `
578
578
 
579
579
  ## Recall tool
580
580
 
581
- When `retrieval: true` is set with `scope: 'thread'`, OM registers a `recall` tool that the agent can call to page through the raw messages behind an observation group's `_range`. The tool is automatically added to the agent's tool list — no manual registration is needed.
581
+ When `retrieval` is set (any truthy value), a `recall` tool is registered so the agent can page through raw messages behind observation group ranges. By default (scope `'resource'`), the tool supports listing threads (`mode: "threads"`), browsing other threads (`threadId`), and cross-thread search. With `retrieval: { vector: true }`, semantic search is available (`mode: "search"`). Set `scope: 'thread'` to restrict the tool to the current thread only. The tool is automatically added to the agent's tool list — no manual registration is needed.
582
582
 
583
583
  ### Parameters
584
584
 
585
- **cursor** (`string`): A message ID to anchor the recall query. Extract the start or end ID from an observation group range (e.g. from \`\_range: \\\`startId:endId\\\`\_\`, use either \`startId\` or \`endId\`). If a range string is passed directly, the tool returns a hint explaining how to extract the correct ID.
585
+ **mode** (`'messages' | 'threads' | 'search'`): What to retrieve. \`"messages"\` (default) pages through message history. \`"threads"\` lists all threads for the current user. \`"search"\` finds messages by semantic similarity across all threads (requires vector store and embedder). (Default: `'messages'`)
586
586
 
587
- **page** (`number`): Pagination offset from the cursor. Positive values page forward (messages after the cursor), negative values page backward (messages before the cursor). \`0\` is treated as \`1\`. (Default: `1`)
587
+ **query** (`string`): Search query for \`mode: "search"\`. Finds messages semantically similar to this text across all threads for the current user.
588
588
 
589
- **limit** (`number`): Maximum number of messages per page. (Default: `20`)
589
+ **cursor** (`string`): A message ID to anchor the recall query. Required for \`mode: "messages"\` when browsing the current thread. Extract the start or end ID from an observation group range (e.g. from \`\_range: \\\`startId:endId\\\`\_\`, use either \`startId\` or \`endId\`). If a range string is passed directly, the tool returns a hint explaining how to extract the correct ID. Can be omitted when \`threadId\` is provided to start reading from the beginning of that thread.
590
+
591
+ **threadId** (`string`): Browse a different thread by its ID. Use \`mode: "threads"\` first to discover thread IDs. When provided without a \`cursor\`, reading starts from the beginning of the thread.
592
+
593
+ **page** (`number`): Pagination offset. For messages: positive values page forward from cursor, negative values page backward. For threads: page number (0-indexed). \`0\` is treated as \`1\` for messages. (Default: `1`)
594
+
595
+ **limit** (`number`): Maximum number of items to return per page. (Default: `20`)
590
596
 
591
597
  **detail** (`'low' | 'high'`): Controls how much content is shown per message part. \`'low'\` shows truncated text and tool names with positional indices (\`\[p0]\`, \`\[p1]\`). \`'high'\` shows full content including tool arguments and results, clamped to one part per call with continuation hints. (Default: `'low'`)
592
598
 
593
599
  **partIndex** (`number`): Fetch a single message part at full detail by its positional index. Use this when a low-detail recall shows an interesting part at \`\[p1]\` — call again with \`partIndex: 1\` to see the full content without loading every part.
594
600
 
595
- ### Returns
601
+ **before** (`string`): For \`mode: "threads"\` only. Filter to threads created before this date. Accepts ISO 8601 format (e.g. \`"2026-03-15"\`, \`"2026-03-10T00:00:00Z"\`).
602
+
603
+ **after** (`string`): For \`mode: "threads"\` only. Filter to threads created after this date. Accepts ISO 8601 format (e.g. \`"2026-03-01"\`, \`"2026-03-10T00:00:00Z"\`).
604
+
605
+ ### Returns (messages mode)
596
606
 
597
607
  **messages** (`string`): Formatted message content. Format depends on the \`detail\` level.
598
608
 
@@ -612,6 +622,22 @@ When `retrieval: true` is set with `scope: 'thread'`, OM registers a `recall` to
612
622
 
613
623
  **tokenOffset** (`number`): Approximate number of tokens that were trimmed when \`truncated\` is true.
614
624
 
625
+ ### Returns (threads mode)
626
+
627
+ **threads** (`string`): Formatted thread listing. Each thread shows its title, ID, and dates. The current thread is marked with \`← current\`.
628
+
629
+ **count** (`number`): Number of threads returned.
630
+
631
+ **page** (`number`): The page number returned.
632
+
633
+ **hasMore** (`boolean`): Whether more threads exist on the next page.
634
+
635
+ ### Returns (search mode)
636
+
637
+ **results** (`string`): Formatted search results grouped by thread. Each result shows the thread title, thread ID, relevance score, message preview, and a cursor ID for browsing into that thread.
638
+
639
+ **count** (`number`): Number of matching messages found.
640
+
615
641
  ### ModelByInputTokens
616
642
 
617
643
  `ModelByInputTokens` selects a model based on the input token count. It chooses the model for the smallest threshold that covers the actual input size.