@mastra/memory 0.0.0-error-handler-fix-20251020202607 → 0.0.0-esbuild-bundle-worker-20260807182016

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 (169) hide show
  1. package/CHANGELOG.md +4656 -3
  2. package/LICENSE.md +15 -0
  3. package/README.md +26 -1
  4. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +7450 -0
  5. package/dist/docs/SKILL.md +62 -0
  6. package/dist/docs/assets/SOURCE_MAP.json +11 -0
  7. package/dist/docs/references/docs-agents-agent-approval.md +664 -0
  8. package/dist/docs/references/docs-agents-networks.md +184 -0
  9. package/dist/docs/references/docs-capabilities-subagents.md +454 -0
  10. package/dist/docs/references/docs-evals-evals-with-memory.md +146 -0
  11. package/dist/docs/references/docs-long-running-agents-background-tasks.md +382 -0
  12. package/dist/docs/references/docs-long-running-agents-goals.md +118 -0
  13. package/dist/docs/references/docs-memory-memory-processors.md +385 -0
  14. package/dist/docs/references/docs-memory-message-history.md +348 -0
  15. package/dist/docs/references/docs-memory-multi-user-threads.md +208 -0
  16. package/dist/docs/references/docs-memory-observational-memory.md +835 -0
  17. package/dist/docs/references/docs-memory-overview.md +266 -0
  18. package/dist/docs/references/docs-memory-semantic-recall.md +401 -0
  19. package/dist/docs/references/docs-memory-working-memory.md +431 -0
  20. package/dist/docs/references/docs-storage-overview.md +214 -0
  21. package/dist/docs/references/reference-core-getMemory.md +51 -0
  22. package/dist/docs/references/reference-core-listMemory.md +57 -0
  23. package/dist/docs/references/reference-file-based-agents-memory.md +58 -0
  24. package/dist/docs/references/reference-memory-clone-utilities.md +203 -0
  25. package/dist/docs/references/reference-memory-cloneThread.md +173 -0
  26. package/dist/docs/references/reference-memory-createThread.md +70 -0
  27. package/dist/docs/references/reference-memory-getThreadById.md +26 -0
  28. package/dist/docs/references/reference-memory-listThreads.md +147 -0
  29. package/dist/docs/references/reference-memory-memory-class.md +148 -0
  30. package/dist/docs/references/reference-memory-observational-memory.md +877 -0
  31. package/dist/docs/references/reference-memory-summarizeConversation.md +99 -0
  32. package/dist/docs/references/reference-memory-summarizeThread.md +93 -0
  33. package/dist/docs/references/reference-processors-token-limiter-processor.md +158 -0
  34. package/dist/docs/references/reference-storage-dsql.md +430 -0
  35. package/dist/docs/references/reference-storage-dynamodb.md +284 -0
  36. package/dist/docs/references/reference-storage-libsql.md +143 -0
  37. package/dist/docs/references/reference-storage-mongodb.md +267 -0
  38. package/dist/docs/references/reference-storage-postgresql.md +531 -0
  39. package/dist/docs/references/reference-storage-redis.md +268 -0
  40. package/dist/docs/references/reference-storage-upstash.md +162 -0
  41. package/dist/docs/references/reference-vectors-libsql.md +307 -0
  42. package/dist/docs/references/reference-vectors-mongodb.md +567 -0
  43. package/dist/docs/references/reference-vectors-pg.md +430 -0
  44. package/dist/docs/references/reference-vectors-upstash.md +296 -0
  45. package/dist/index.cjs +35 -893
  46. package/dist/index.d.ts +465 -62
  47. package/dist/index.d.ts.map +1 -1
  48. package/dist/index.js +2 -887
  49. package/dist/processors/index.cjs +32 -165
  50. package/dist/processors/index.d.ts +1 -2
  51. package/dist/processors/index.d.ts.map +1 -1
  52. package/dist/processors/index.js +2 -158
  53. package/dist/processors/observational-memory/activation-ttl.d.ts +4 -0
  54. package/dist/processors/observational-memory/activation-ttl.d.ts.map +1 -0
  55. package/dist/processors/observational-memory/anchor-ids.d.ts +4 -0
  56. package/dist/processors/observational-memory/anchor-ids.d.ts.map +1 -0
  57. package/dist/processors/observational-memory/buffering-coordinator.d.ts +61 -0
  58. package/dist/processors/observational-memory/buffering-coordinator.d.ts.map +1 -0
  59. package/dist/processors/observational-memory/built-in-extractors.d.ts +15 -0
  60. package/dist/processors/observational-memory/built-in-extractors.d.ts.map +1 -0
  61. package/dist/processors/observational-memory/constants.d.ts +74 -0
  62. package/dist/processors/observational-memory/constants.d.ts.map +1 -0
  63. package/dist/processors/observational-memory/date-utils.d.ts +41 -0
  64. package/dist/processors/observational-memory/date-utils.d.ts.map +1 -0
  65. package/dist/processors/observational-memory/debug.d.ts +3 -0
  66. package/dist/processors/observational-memory/debug.d.ts.map +1 -0
  67. package/dist/processors/observational-memory/extracted-values.d.ts +44 -0
  68. package/dist/processors/observational-memory/extracted-values.d.ts.map +1 -0
  69. package/dist/processors/observational-memory/extraction-runner.d.ts +22 -0
  70. package/dist/processors/observational-memory/extraction-runner.d.ts.map +1 -0
  71. package/dist/processors/observational-memory/extractor.d.ts +76 -0
  72. package/dist/processors/observational-memory/extractor.d.ts.map +1 -0
  73. package/dist/processors/observational-memory/index.d.ts +30 -0
  74. package/dist/processors/observational-memory/index.d.ts.map +1 -0
  75. package/dist/processors/observational-memory/internal-request-context.d.ts +17 -0
  76. package/dist/processors/observational-memory/internal-request-context.d.ts.map +1 -0
  77. package/dist/processors/observational-memory/markers.d.ts +118 -0
  78. package/dist/processors/observational-memory/markers.d.ts.map +1 -0
  79. package/dist/processors/observational-memory/message-utils.d.ts +83 -0
  80. package/dist/processors/observational-memory/message-utils.d.ts.map +1 -0
  81. package/dist/processors/observational-memory/model-by-input-tokens.d.ts +14 -0
  82. package/dist/processors/observational-memory/model-by-input-tokens.d.ts.map +1 -0
  83. package/dist/processors/observational-memory/model-context.d.ts +2 -0
  84. package/dist/processors/observational-memory/model-context.d.ts.map +1 -0
  85. package/dist/processors/observational-memory/observation-groups.d.ts +15 -0
  86. package/dist/processors/observational-memory/observation-groups.d.ts.map +1 -0
  87. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts +39 -0
  88. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -0
  89. package/dist/processors/observational-memory/observation-strategies/base.d.ts +122 -0
  90. package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -0
  91. package/dist/processors/observational-memory/observation-strategies/index.d.ts +7 -0
  92. package/dist/processors/observational-memory/observation-strategies/index.d.ts.map +1 -0
  93. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts +43 -0
  94. package/dist/processors/observational-memory/observation-strategies/resource-scoped.d.ts.map +1 -0
  95. package/dist/processors/observational-memory/observation-strategies/sync.d.ts +41 -0
  96. package/dist/processors/observational-memory/observation-strategies/sync.d.ts.map +1 -0
  97. package/dist/processors/observational-memory/observation-strategies/types.d.ts +103 -0
  98. package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -0
  99. package/dist/processors/observational-memory/observation-turn/index.d.ts +4 -0
  100. package/dist/processors/observational-memory/observation-turn/index.d.ts.map +1 -0
  101. package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts +9 -0
  102. package/dist/processors/observational-memory/observation-turn/load-memory-context.d.ts.map +1 -0
  103. package/dist/processors/observational-memory/observation-turn/step.d.ts +53 -0
  104. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -0
  105. package/dist/processors/observational-memory/observation-turn/turn.d.ts +139 -0
  106. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -0
  107. package/dist/processors/observational-memory/observation-turn/types.d.ts +46 -0
  108. package/dist/processors/observational-memory/observation-turn/types.d.ts.map +1 -0
  109. package/dist/processors/observational-memory/observation-utils.d.ts +16 -0
  110. package/dist/processors/observational-memory/observation-utils.d.ts.map +1 -0
  111. package/dist/processors/observational-memory/observational-memory.d.ts +930 -0
  112. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -0
  113. package/dist/processors/observational-memory/observer-agent.d.ts +190 -0
  114. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -0
  115. package/dist/processors/observational-memory/observer-runner.d.ts +141 -0
  116. package/dist/processors/observational-memory/observer-runner.d.ts.map +1 -0
  117. package/dist/processors/observational-memory/operation-registry.d.ts +14 -0
  118. package/dist/processors/observational-memory/operation-registry.d.ts.map +1 -0
  119. package/dist/processors/observational-memory/processor.d.ts +70 -0
  120. package/dist/processors/observational-memory/processor.d.ts.map +1 -0
  121. package/dist/processors/observational-memory/reflector-agent.d.ts +62 -0
  122. package/dist/processors/observational-memory/reflector-agent.d.ts.map +1 -0
  123. package/dist/processors/observational-memory/reflector-runner.d.ts +133 -0
  124. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -0
  125. package/dist/processors/observational-memory/repro-capture.d.ts +33 -0
  126. package/dist/processors/observational-memory/repro-capture.d.ts.map +1 -0
  127. package/dist/processors/observational-memory/retry.d.ts +63 -0
  128. package/dist/processors/observational-memory/retry.d.ts.map +1 -0
  129. package/dist/processors/observational-memory/string-utils.d.ts +13 -0
  130. package/dist/processors/observational-memory/string-utils.d.ts.map +1 -0
  131. package/dist/processors/observational-memory/summarize.d.ts +92 -0
  132. package/dist/processors/observational-memory/summarize.d.ts.map +1 -0
  133. package/dist/processors/observational-memory/temporal-markers.d.ts +4 -0
  134. package/dist/processors/observational-memory/temporal-markers.d.ts.map +1 -0
  135. package/dist/processors/observational-memory/temporary-memory.d.ts +8 -0
  136. package/dist/processors/observational-memory/temporary-memory.d.ts.map +1 -0
  137. package/dist/processors/observational-memory/thresholds.d.ts +52 -0
  138. package/dist/processors/observational-memory/thresholds.d.ts.map +1 -0
  139. package/dist/processors/observational-memory/token-counter.d.ts +57 -0
  140. package/dist/processors/observational-memory/token-counter.d.ts.map +1 -0
  141. package/dist/processors/observational-memory/tool-result-helpers.d.ts +12 -0
  142. package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -0
  143. package/dist/processors/observational-memory/tracing.d.ts +17 -0
  144. package/dist/processors/observational-memory/tracing.d.ts.map +1 -0
  145. package/dist/processors/observational-memory/types.d.ts +997 -0
  146. package/dist/processors/observational-memory/types.d.ts.map +1 -0
  147. package/dist/processors/observational-memory/working-memory-extractor.d.ts +5 -0
  148. package/dist/processors/observational-memory/working-memory-extractor.d.ts.map +1 -0
  149. package/dist/processors/working-memory-state/index.d.ts +2 -0
  150. package/dist/processors/working-memory-state/index.d.ts.map +1 -0
  151. package/dist/processors/working-memory-state/processor.d.ts +53 -0
  152. package/dist/processors/working-memory-state/processor.d.ts.map +1 -0
  153. package/dist/src-C1tlhGeW.js +28559 -0
  154. package/dist/src-C1tlhGeW.js.map +1 -0
  155. package/dist/src-DqoifKIy.cjs +28813 -0
  156. package/dist/src-DqoifKIy.cjs.map +1 -0
  157. package/dist/tools/om-tools.d.ts +172 -0
  158. package/dist/tools/om-tools.d.ts.map +1 -0
  159. package/dist/tools/working-memory.d.ts +33 -28
  160. package/dist/tools/working-memory.d.ts.map +1 -1
  161. package/package.json +36 -28
  162. package/dist/index.cjs.map +0 -1
  163. package/dist/index.js.map +0 -1
  164. package/dist/processors/index.cjs.map +0 -1
  165. package/dist/processors/index.js.map +0 -1
  166. package/dist/processors/token-limiter.d.ts +0 -32
  167. package/dist/processors/token-limiter.d.ts.map +0 -1
  168. package/dist/processors/tool-call-filter.d.ts +0 -20
  169. package/dist/processors/tool-call-filter.d.ts.map +0 -1
@@ -0,0 +1,284 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # DynamoDB storage
4
+
5
+ The DynamoDB storage implementation provides a high-capacity and performant NoSQL database solution for Mastra, using a single-table design pattern with [ElectroDB](https://electrodb.dev/).
6
+
7
+ > **Observability Not Supported:** DynamoDB storage **doesn't support the observability domain**. Traces from the `MastraStorageExporter` can't be persisted to DynamoDB, and [Studio's](https://mastra.ai/docs/studio/overview) observability features won't work with DynamoDB as your only storage provider. To enable observability, use [composite storage](https://mastra.ai/reference/storage/composite) to route observability data to a supported provider like ClickHouse.
8
+
9
+ > **Item Size Limit:** DynamoDB enforces a **400 KB maximum item size**. This limit can be exceeded when storing messages with base64-encoded attachments such as images. See [Handling large attachments](https://mastra.ai/docs/memory/memory-processors) for workarounds including uploading attachments to external storage.
10
+
11
+ ## Features
12
+
13
+ - Efficient single-table design for all Mastra storage needs
14
+ - Based on ElectroDB for type-safe DynamoDB access
15
+ - Support for AWS credentials, regions, and endpoints
16
+ - Compatible with AWS DynamoDB Local for development
17
+ - Stores Thread, Message, Eval, and Workflow data
18
+ - Optimized for serverless environments
19
+ - Configurable TTL (Time To Live) for automatic data expiration per entity type
20
+
21
+ ## Installation
22
+
23
+ **npm**:
24
+
25
+ ```bash
26
+ npm install @mastra/dynamodb@latest
27
+ ```
28
+
29
+ **pnpm**:
30
+
31
+ ```bash
32
+ pnpm add @mastra/dynamodb@latest
33
+ ```
34
+
35
+ **Yarn**:
36
+
37
+ ```bash
38
+ yarn add @mastra/dynamodb@latest
39
+ ```
40
+
41
+ **Bun**:
42
+
43
+ ```bash
44
+ bun add @mastra/dynamodb@latest
45
+ ```
46
+
47
+ ## Prerequisites
48
+
49
+ Before using this package, you **must** create a DynamoDB table with a specific structure, including primary keys and Global Secondary Indexes (GSIs). This adapter expects the DynamoDB table and its GSIs to be provisioned externally.
50
+
51
+ Detailed instructions for setting up the table using AWS CloudFormation or AWS CDK are available in [TABLE\_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md). Please ensure your table is configured according to those instructions before proceeding.
52
+
53
+ ## Usage
54
+
55
+ ### Basic Usage
56
+
57
+ ```typescript
58
+ import { Memory } from '@mastra/memory'
59
+ import { DynamoDBStore } from '@mastra/dynamodb'
60
+
61
+ // Initialize the DynamoDB storage
62
+ const storage = new DynamoDBStore({
63
+ id: 'dynamodb', // Unique identifier for this storage instance
64
+ config: {
65
+ tableName: 'mastra-single-table', // Name of your DynamoDB table
66
+ region: 'us-east-1', // Optional: AWS region, defaults to 'us-east-1'
67
+ // endpoint: "http://localhost:8000", // Optional: For local DynamoDB
68
+ // credentials: { accessKeyId: "YOUR_ACCESS_KEY", secretAccessKey: "YOUR_SECRET_KEY" } // Optional
69
+ },
70
+ })
71
+
72
+ // Example: Initialize Memory with DynamoDB storage
73
+ const memory = new Memory({
74
+ storage,
75
+ options: {
76
+ lastMessages: 10,
77
+ },
78
+ })
79
+ ```
80
+
81
+ ### Local Development with DynamoDB Local
82
+
83
+ For local development, you can use [DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html).
84
+
85
+ 1. **Run DynamoDB Local (e.g., using Docker):**
86
+
87
+ ```bash
88
+ docker run -p 8000:8000 amazon/dynamodb-local
89
+ ```
90
+
91
+ 2. **Configure `DynamoDBStore` to use the local endpoint:**
92
+
93
+ ```typescript
94
+ import { DynamoDBStore } from '@mastra/dynamodb'
95
+
96
+ const storage = new DynamoDBStore({
97
+ id: 'dynamodb-local',
98
+ config: {
99
+ tableName: 'mastra-single-table', // Ensure this table is created in your local DynamoDB
100
+ region: 'localhost', // Can be any string for local, 'localhost' is common
101
+ endpoint: 'http://localhost:8000',
102
+ // For DynamoDB Local, credentials are not typically required unless configured.
103
+ // If you've configured local credentials:
104
+ // credentials: { accessKeyId: "fakeMyKeyId", secretAccessKey: "fakeSecretAccessKey" }
105
+ },
106
+ })
107
+ ```
108
+
109
+ You will still need to create the table and GSIs in your local DynamoDB instance, for example, using the AWS CLI pointed to your local endpoint.
110
+
111
+ ## Parameters
112
+
113
+ **id** (`string`): Unique identifier for this storage instance.
114
+
115
+ **config.tableName** (`string`): The name of your DynamoDB table.
116
+
117
+ **config.region** (`string`): AWS region. Defaults to 'us-east-1'. For local development, can be set to 'localhost' or similar.
118
+
119
+ **config.endpoint** (`string`): Custom endpoint for DynamoDB (e.g., 'http\://localhost:8000' for local development).
120
+
121
+ **config.credentials** (`object`): AWS credentials object with accessKeyId and secretAccessKey. If not provided, the AWS SDK will attempt to source credentials from environment variables, IAM roles (e.g., for EC2/Lambda), or the shared AWS credentials file.
122
+
123
+ **config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval, workflow\_snapshot, resource, score. Each entity config includes: enabled (boolean), attributeName (string, default: 'ttl'), defaultTtlSeconds (number).
124
+
125
+ ## TTL (time to live) configuration
126
+
127
+ DynamoDB TTL allows you to automatically delete items after a specified duration for these use cases:
128
+
129
+ - **Cost optimization**: Automatically remove old data to reduce storage costs
130
+ - **Data lifecycle management**: Implement retention policies for compliance
131
+ - **Performance**: Prevent tables from growing indefinitely
132
+ - **Privacy compliance**: Automatically purge personal data after specified periods
133
+
134
+ ### Enabling TTL
135
+
136
+ To use TTL, you must:
137
+
138
+ 1. **Configure TTL in DynamoDBStore** (shown below)
139
+ 2. **Enable TTL on your DynamoDB table** via AWS Console or CLI, specifying the attribute name (default: `ttl`)
140
+
141
+ ```typescript
142
+ import { DynamoDBStore } from '@mastra/dynamodb'
143
+
144
+ const storage = new DynamoDBStore({
145
+ name: 'dynamodb',
146
+ config: {
147
+ tableName: 'mastra-single-table',
148
+ region: 'us-east-1',
149
+ ttl: {
150
+ // Messages expire after 30 days
151
+ message: {
152
+ enabled: true,
153
+ defaultTtlSeconds: 30 * 24 * 60 * 60, // 30 days
154
+ },
155
+ // Threads expire after 90 days
156
+ thread: {
157
+ enabled: true,
158
+ defaultTtlSeconds: 90 * 24 * 60 * 60, // 90 days
159
+ },
160
+ // Traces expire after 7 days with custom attribute name
161
+ trace: {
162
+ enabled: true,
163
+ attributeName: 'expiresAt', // Custom TTL attribute
164
+ defaultTtlSeconds: 7 * 24 * 60 * 60, // 7 days
165
+ },
166
+ // Workflow snapshots don't expire
167
+ workflow_snapshot: {
168
+ enabled: false,
169
+ },
170
+ },
171
+ },
172
+ })
173
+ ```
174
+
175
+ ### Supported Entity Types
176
+
177
+ TTL can be configured for these entity types:
178
+
179
+ | Entity | Description |
180
+ | ------------------- | ------------------------ |
181
+ | `thread` | Conversation threads |
182
+ | `message` | Messages within threads |
183
+ | `trace` | Observability traces |
184
+ | `eval` | Evaluation results |
185
+ | `workflow_snapshot` | Workflow state snapshots |
186
+ | `resource` | User/resource data |
187
+ | `score` | Scoring results |
188
+
189
+ ### TTL Entity Configuration
190
+
191
+ Each entity type accepts the following configuration:
192
+
193
+ **enabled** (`boolean`): Whether TTL is enabled for this entity type.
194
+
195
+ **attributeName** (`string`): The DynamoDB attribute name to use for TTL. Must match the TTL attribute configured on your DynamoDB table. Defaults to 'ttl'.
196
+
197
+ **defaultTtlSeconds** (`number`): Default TTL in seconds from item creation time. Items will be automatically deleted by DynamoDB after this duration.
198
+
199
+ ### Enabling TTL on Your DynamoDB Table
200
+
201
+ After configuring TTL in your code, you must enable TTL on the DynamoDB table itself:
202
+
203
+ **Using AWS CLI:**
204
+
205
+ ```bash
206
+ aws dynamodb update-time-to-live \
207
+ --table-name mastra-single-table \
208
+ --time-to-live-specification "Enabled=true, AttributeName=ttl"
209
+ ```
210
+
211
+ **Using AWS Console:**
212
+
213
+ 1. Go to the DynamoDB console
214
+ 2. Select your table
215
+ 3. Go to "Additional settings" tab
216
+ 4. Under "Time to Live (TTL)", select "Manage TTL"
217
+ 5. Enable TTL and specify the attribute name (default: `ttl`)
218
+
219
+ > **Note:** DynamoDB deletes expired items within 48 hours after expiration. Items remain queryable until actually deleted.
220
+
221
+ ## AWS IAM permissions
222
+
223
+ The IAM role or user executing the code needs appropriate permissions to interact with the specified DynamoDB table and its indexes. Below is a sample policy. Replace `${YOUR_TABLE_NAME}` with your actual table name and `${YOUR_AWS_REGION}` and `${YOUR_AWS_ACCOUNT_ID}` with appropriate values.
224
+
225
+ ```json
226
+ {
227
+ "Version": "2012-10-17",
228
+ "Statement": [
229
+ {
230
+ "Effect": "Allow",
231
+ "Action": [
232
+ "dynamodb:DescribeTable",
233
+ "dynamodb:GetItem",
234
+ "dynamodb:PutItem",
235
+ "dynamodb:UpdateItem",
236
+ "dynamodb:DeleteItem",
237
+ "dynamodb:Query",
238
+ "dynamodb:Scan",
239
+ "dynamodb:BatchGetItem",
240
+ "dynamodb:BatchWriteItem"
241
+ ],
242
+ "Resource": [
243
+ "arn:aws:dynamodb:${YOUR_AWS_REGION}:${YOUR_AWS_ACCOUNT_ID}:table/${YOUR_TABLE_NAME}",
244
+ "arn:aws:dynamodb:${YOUR_AWS_REGION}:${YOUR_AWS_ACCOUNT_ID}:table/${YOUR_TABLE_NAME}/index/*"
245
+ ]
246
+ }
247
+ ]
248
+ }
249
+ ```
250
+
251
+ ## Key considerations
252
+
253
+ Before diving into the architectural details, keep these key points in mind when working with the DynamoDB storage adapter:
254
+
255
+ - **External Table Provisioning:** This adapter _requires_ you to create and configure the DynamoDB table and its Global Secondary Indexes (GSIs) yourself, prior to using the adapter. Follow the guide in [TABLE\_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md).
256
+ - **Single-Table Design:** All Mastra data (threads, messages, etc.) is stored in one DynamoDB table. This is a deliberate design choice optimized for DynamoDB, differing from relational database approaches.
257
+ - **Understanding GSIs:** Familiarity with how the GSIs are structured (as per `TABLE_SETUP.md`) is important for understanding data retrieval and potential query patterns.
258
+ - **ElectroDB:** The adapter uses ElectroDB to manage interactions with DynamoDB, providing a layer of abstraction and type safety over raw DynamoDB operations.
259
+
260
+ ## Architectural approach
261
+
262
+ This storage adapter utilizes a **single-table design pattern** with [ElectroDB](https://electrodb.dev/), a common and recommended approach for DynamoDB. This differs architecturally from relational database adapters (like `@mastra/pg` or `@mastra/libsql`) that typically use multiple tables, each dedicated to a specific entity (threads, messages, etc.).
263
+
264
+ Key aspects of this approach:
265
+
266
+ - **DynamoDB Native:** The single-table design is optimized for DynamoDB's key-value and query capabilities, often leading to better performance and capacity compared to mimicking relational models.
267
+ - **External Table Management:** Unlike some adapters that might offer helper functions to create tables via code, this adapter **expects the DynamoDB table and its associated Global Secondary Indexes (GSIs) to be provisioned externally** before use. Please refer to [TABLE\_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md) for detailed instructions using tools like AWS CloudFormation or CDK. The adapter focuses solely on interacting with the pre-existing table structure.
268
+ - **Consistency via Interface:** While the underlying storage model differs, this adapter adheres to the same `MastraStorage` interface as other adapters, ensuring it can be used interchangeably within the Mastra `Memory` component.
269
+
270
+ ### Mastra Data in the Single Table
271
+
272
+ Within the single DynamoDB table, different Mastra data entities (such as Threads, Messages, Traces, Evals, and Workflows) are managed and distinguished using ElectroDB. ElectroDB defines specific models for each entity type, which include unique key structures and attributes. It allows the adapter to store and retrieve diverse data types efficiently within the same table.
273
+
274
+ For example, a `Thread` item might have a primary key like `THREAD#<threadId>`, while a `Message` item belonging to that thread might use `THREAD#<threadId>` as a partition key and `MESSAGE#<messageId>` as a sort key. The Global Secondary Indexes (GSIs), detailed in `TABLE_SETUP.md`, are strategically designed to support common access patterns across these different entities, such as fetching all messages for a thread or querying traces associated with a workflow.
275
+
276
+ ### Advantages of Single-Table Design
277
+
278
+ This implementation uses a single-table design pattern with ElectroDB, which offers several advantages within the context of DynamoDB:
279
+
280
+ 1. **Lower cost (potentially):** Fewer tables can simplify Read/Write Capacity Unit (RCU/WCU) provisioning and management, especially with on-demand capacity.
281
+ 2. **Better performance:** Related data can be co-located or accessed efficiently through GSIs, enabling fast lookups for common access patterns.
282
+ 3. **Simplified administration:** Fewer distinct tables to monitor and back up, with less to manage.
283
+ 4. **Reduced complexity in access patterns:** ElectroDB helps manage the complexity of item types and access patterns on a single table.
284
+ 5. **Transaction support:** DynamoDB transactions can be used across different "entity" types stored within the same table if needed.
@@ -0,0 +1,143 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # libSQL storage
4
+
5
+ [libSQL](https://docs.turso.tech/libsql) is an open-source, SQLite-compatible database that supports both local and remote deployments. It can be used to store message history, workflow snapshots, traces, and eval scores.
6
+
7
+ For vectors like semantic recall or traditional RAG, use [libSQL Vector](https://mastra.ai/reference/vectors/libsql) which covers embeddings and vector search.
8
+
9
+ ## Installation
10
+
11
+ Storage providers must be installed as separate packages:
12
+
13
+ **npm**:
14
+
15
+ ```bash
16
+ npm install @mastra/libsql@latest
17
+ ```
18
+
19
+ **pnpm**:
20
+
21
+ ```bash
22
+ pnpm add @mastra/libsql@latest
23
+ ```
24
+
25
+ **Yarn**:
26
+
27
+ ```bash
28
+ yarn add @mastra/libsql@latest
29
+ ```
30
+
31
+ **Bun**:
32
+
33
+ ```bash
34
+ bun add @mastra/libsql@latest
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ```typescript
40
+ import { LibSQLStore } from '@mastra/libsql'
41
+ import { Mastra } from '@mastra/core'
42
+
43
+ const mastra = new Mastra({
44
+ storage: new LibSQLStore({
45
+ id: 'libsql-storage',
46
+ url: 'file:./storage.db',
47
+ }),
48
+ })
49
+ ```
50
+
51
+ Agent-level file storage:
52
+
53
+ ```typescript
54
+ import { Memory } from '@mastra/memory'
55
+ import { Agent } from '@mastra/core/agent'
56
+ import { LibSQLStore } from '@mastra/libsql'
57
+
58
+ export const agent = new Agent({
59
+ id: 'example-agent',
60
+ memory: new Memory({
61
+ storage: new LibSQLStore({
62
+ id: 'libsql-storage',
63
+ url: 'file:./agent.db',
64
+ }),
65
+ }),
66
+ })
67
+ ```
68
+
69
+ > **Warning:** File storage doesn't work with serverless platforms that have ephemeral file systems. For serverless deployments, use [Turso](https://turso.tech) or a different database engine.
70
+
71
+ Production with remote database:
72
+
73
+ ```typescript
74
+ storage: new LibSQLStore({
75
+ id: 'libsql-storage',
76
+ url: 'libsql://your-db-name.aws-ap-northeast-1.turso.io',
77
+ authToken: process.env.TURSO_AUTH_TOKEN,
78
+ })
79
+ ```
80
+
81
+ For local development and testing, you can store data in memory:
82
+
83
+ ```typescript
84
+ storage: new LibSQLStore({
85
+ id: 'libsql-storage',
86
+ url: ':memory:',
87
+ })
88
+ ```
89
+
90
+ > **Warning:** In-memory storage resets when the process changes. Only suitable for development.
91
+
92
+ ## Options
93
+
94
+ **url** (`string`): Database URL. Use :memory: for in-memory database, file:filename.db for a file database, or a libSQL connection string (e.g., libsql://your-database.turso.io) for remote storage.
95
+
96
+ **authToken** (`string`): Authentication token for remote libSQL databases.
97
+
98
+ ## Managed tables
99
+
100
+ The storage implementation creates the core storage tables automatically, including `mastra_notifications` for notification inbox records and delivery metadata.
101
+
102
+ `LibSQLStore` exposes notification storage through `getStore('notifications')`.
103
+
104
+ ## Initialization
105
+
106
+ When you pass storage to the Mastra class, `init()` is called automatically to create the [core schema](https://mastra.ai/reference/storage/overview):
107
+
108
+ ```typescript
109
+ import { Mastra } from '@mastra/core'
110
+ import { LibSQLStore } from '@mastra/libsql'
111
+
112
+ const storage = new LibSQLStore({
113
+ id: 'libsql-storage',
114
+ url: 'file:./storage.db',
115
+ })
116
+
117
+ const mastra = new Mastra({
118
+ storage, // init() called automatically
119
+ })
120
+ ```
121
+
122
+ If using storage directly without Mastra, call `init()` explicitly:
123
+
124
+ ```typescript
125
+ import { LibSQLStore } from '@mastra/libsql'
126
+
127
+ const storage = new LibSQLStore({
128
+ id: 'libsql-storage',
129
+ url: 'file:./storage.db',
130
+ })
131
+
132
+ await storage.init()
133
+
134
+ // Access domain-specific stores via getStore()
135
+ const memoryStore = await storage.getStore('memory')
136
+ const thread = await memoryStore?.getThreadById({ threadId: '...' })
137
+ ```
138
+
139
+ ## Observability
140
+
141
+ libSQL supports observability and is ideal for local development. Use the `realtime` [tracing strategy](https://mastra.ai/docs/observability/integrations/exporters/mastra-storage) for immediate visibility while debugging.
142
+
143
+ For production environments with higher trace volumes, consider using [PostgreSQL](https://mastra.ai/reference/storage/postgresql) or [ClickHouse via composite storage](https://mastra.ai/reference/storage/composite).
@@ -0,0 +1,267 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # MongoDB storage
4
+
5
+ The MongoDB storage implementation provides a high-capacity storage solution using MongoDB databases with support for both document storage and vector operations.
6
+
7
+ ## Installation
8
+
9
+ **npm**:
10
+
11
+ ```bash
12
+ npm install @mastra/mongodb@latest
13
+ ```
14
+
15
+ **pnpm**:
16
+
17
+ ```bash
18
+ pnpm add @mastra/mongodb@latest
19
+ ```
20
+
21
+ **Yarn**:
22
+
23
+ ```bash
24
+ yarn add @mastra/mongodb@latest
25
+ ```
26
+
27
+ **Bun**:
28
+
29
+ ```bash
30
+ bun add @mastra/mongodb@latest
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ Ensure you have a [MongoDB Atlas Local (via Docker)](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-deploy-docker/) or [MongoDB Atlas Cloud](https://www.mongodb.com/docs/atlas/cli/current/atlas-cli-getting-started/) instance with Atlas Search enabled. MongoDB 7.0+ is recommended.
36
+
37
+ ```typescript
38
+ import { MongoDBStore } from '@mastra/mongodb'
39
+
40
+ const storage = new MongoDBStore({
41
+ id: 'mongodb-storage',
42
+ uri: process.env.MONGODB_URI,
43
+ dbName: process.env.MONGODB_DB_NAME,
44
+ })
45
+ ```
46
+
47
+ ## Parameters
48
+
49
+ **id** (`string`): Unique identifier for this storage instance.
50
+
51
+ **uri** (`string`): MongoDB connection string (e.g., mongodb+srv://user:password\@cluster.mongodb.net)
52
+
53
+ **url** (`string`): Deprecated. Use uri instead. MongoDB connection string (supported for backward compatibility).
54
+
55
+ **dbName** (`string`): The name of the database you want the storage to use.
56
+
57
+ **options** (`MongoClientOptions`): MongoDB client options for advanced configuration (SSL, connection pooling, etc.). See Connection Options
58
+
59
+ **disableInit** (`boolean`): When true, automatic initialization (collection creation) is disabled. Useful for CI/CD pipelines where you want to run migrations explicitly. You must call storage.init() manually when this is true.
60
+
61
+ **skipDefaultIndexes** (`boolean`): When true, default indexes will not be created during initialization. Useful when managing indexes separately or using only custom indexes.
62
+
63
+ **indexes** (`MongoDBIndexConfig[]`): Custom indexes to create during initialization. Each index must specify a collection, keys, and optional index options. See Indexes
64
+
65
+ **connectorHandler** (`ConnectorHandler`): Custom connection handler for advanced connection management. Alternative to providing uri/dbName directly.
66
+
67
+ > **Deprecation Notice:** The `url` parameter is deprecated but still supported for backward compatibility. Please use `uri` instead in all new code.
68
+
69
+ ## Constructor examples
70
+
71
+ You can instantiate `MongoDBStore` in the following ways:
72
+
73
+ ```ts
74
+ import { MongoDBStore } from '@mastra/mongodb'
75
+
76
+ // Basic connection without custom options
77
+ const store1 = new MongoDBStore({
78
+ id: 'mongodb-storage-01',
79
+ uri: 'mongodb+srv://user:password@cluster.mongodb.net',
80
+ dbName: 'mastra_storage',
81
+ })
82
+
83
+ // Using connection string with options
84
+ const store2 = new MongoDBStore({
85
+ id: 'mongodb-storage-02',
86
+ uri: 'mongodb+srv://user:password@cluster.mongodb.net',
87
+ dbName: 'mastra_storage',
88
+ options: {
89
+ retryWrites: true,
90
+ maxPoolSize: 10,
91
+ serverSelectionTimeoutMS: 5000,
92
+ socketTimeoutMS: 45000,
93
+ },
94
+ })
95
+
96
+ // With custom indexes
97
+ const store3 = new MongoDBStore({
98
+ id: 'mongodb-storage-03',
99
+ uri: 'mongodb+srv://user:password@cluster.mongodb.net',
100
+ dbName: 'mastra_storage',
101
+ indexes: [
102
+ { collection: 'mastra_threads', keys: { 'metadata.type': 1 } },
103
+ { collection: 'mastra_messages', keys: { 'metadata.status': 1 }, options: { sparse: true } },
104
+ ],
105
+ })
106
+
107
+ // For CI/CD with explicit initialization
108
+ const store4 = new MongoDBStore({
109
+ id: 'mongodb-storage-04',
110
+ uri: 'mongodb+srv://user:password@cluster.mongodb.net',
111
+ dbName: 'mastra_storage',
112
+ disableInit: true, // Disable auto-init
113
+ })
114
+ await store4.init() // Call init explicitly
115
+ ```
116
+
117
+ ## Additional notes
118
+
119
+ ### Collection Management
120
+
121
+ The storage implementation handles collection creation and management automatically. It creates the following collections:
122
+
123
+ - `mastra_workflow_snapshot`: Stores workflow state and execution data
124
+ - `mastra_evals`: Stores evaluation results and metadata
125
+ - `mastra_threads`: Stores conversation threads
126
+ - `mastra_messages`: Stores individual messages
127
+ - `mastra_traces`: Stores telemetry and tracing data
128
+ - `mastra_scorers`: Stores scoring and evaluation data
129
+ - `mastra_resources`: Stores resource working memory data
130
+ - `mastra_notifications`: Stores notification inbox records and delivery metadata
131
+
132
+ `MongoDBStore` exposes notification storage through `getStore('notifications')`.
133
+
134
+ ### Initialization
135
+
136
+ When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
137
+
138
+ ```typescript
139
+ import { Mastra } from '@mastra/core'
140
+ import { MongoDBStore } from '@mastra/mongodb'
141
+
142
+ const storage = new MongoDBStore({
143
+ id: 'mongodb-storage',
144
+ uri: process.env.MONGODB_URI,
145
+ dbName: process.env.MONGODB_DB_NAME,
146
+ })
147
+
148
+ const mastra = new Mastra({
149
+ storage, // init() is called automatically
150
+ })
151
+ ```
152
+
153
+ If you're using storage directly without Mastra, you must call `init()` explicitly to create the collections:
154
+
155
+ ```typescript
156
+ import { MongoDBStore } from '@mastra/mongodb'
157
+
158
+ const storage = new MongoDBStore({
159
+ id: 'mongodb-storage',
160
+ uri: process.env.MONGODB_URI,
161
+ dbName: process.env.MONGODB_DB_NAME,
162
+ })
163
+
164
+ // Required when using storage directly
165
+ await storage.init()
166
+
167
+ // Access domain-specific stores via getStore()
168
+ const memoryStore = await storage.getStore('memory')
169
+ const thread = await memoryStore?.getThreadById({ threadId: '...' })
170
+ ```
171
+
172
+ > **Warning:** If `init()` isn't called, collections won't be created and storage operations will fail silently or throw errors.
173
+
174
+ ### Connection Management
175
+
176
+ The `close()` method closes the MongoDB client connection. Call this when shutting down your application:
177
+
178
+ ```typescript
179
+ import { MongoDBStore } from '@mastra/mongodb'
180
+
181
+ const storage = new MongoDBStore({
182
+ id: 'mongodb-storage',
183
+ uri: process.env.MONGODB_URI,
184
+ dbName: process.env.MONGODB_DB_NAME,
185
+ })
186
+
187
+ // Use storage...
188
+
189
+ // Clean up on shutdown
190
+ await storage.close()
191
+ ```
192
+
193
+ ## Vector search capabilities
194
+
195
+ MongoDB storage includes built-in vector search capabilities for AI applications. For detailed vector operations including index creation, upserting embeddings, similarity search, and metadata filtering, see the [MongoDB vector reference](https://mastra.ai/reference/vectors/mongodb).
196
+
197
+ ## Usage example
198
+
199
+ ### Adding memory to an agent
200
+
201
+ To add MongoDB memory to an agent use the `Memory` class and create a new `storage` key using `MongoDBStore`. The configuration supports both local and remote MongoDB instances.
202
+
203
+ ```typescript
204
+ import { Memory } from '@mastra/memory'
205
+ import { Agent } from '@mastra/core/agent'
206
+ import { MongoDBStore } from '@mastra/mongodb'
207
+
208
+ export const mongodbAgent = new Agent({
209
+ id: 'mongodb-agent',
210
+ name: 'mongodb-agent',
211
+ instructions:
212
+ 'You are an AI agent with the ability to automatically recall memories from previous interactions.',
213
+ model: 'openai/gpt-5.6-sol',
214
+ memory: new Memory({
215
+ storage: new MongoDBStore({
216
+ id: 'mongodb-storage',
217
+ uri: process.env.MONGODB_URI!,
218
+ dbName: process.env.MONGODB_DB_NAME!,
219
+ }),
220
+ options: {
221
+ generateTitle: true,
222
+ },
223
+ }),
224
+ })
225
+ ```
226
+
227
+ ### Using the agent
228
+
229
+ Use `memoryOptions` to scope recall for this request. Set `lastMessages: 5` to limit recency-based recall, and use `semanticRecall` to fetch the `topK: 3` most relevant messages, including `messageRange: 2` neighboring messages for context around each match.
230
+
231
+ ```typescript
232
+ import 'dotenv/config'
233
+
234
+ import { mastra } from './mastra'
235
+
236
+ const threadId = '123'
237
+ const resourceId = 'user-456'
238
+
239
+ const agent = mastra.getAgent('mongodbAgent')
240
+
241
+ const message = await agent.stream('My name is Mastra', {
242
+ memory: {
243
+ thread: threadId,
244
+ resource: resourceId,
245
+ },
246
+ })
247
+
248
+ await message.textStream.pipeTo(new WritableStream())
249
+
250
+ const stream = await agent.stream("What's my name?", {
251
+ memory: {
252
+ thread: threadId,
253
+ resource: resourceId,
254
+ },
255
+ memoryOptions: {
256
+ lastMessages: 5,
257
+ semanticRecall: {
258
+ topK: 3,
259
+ messageRange: 2,
260
+ },
261
+ },
262
+ })
263
+
264
+ for await (const chunk of stream.textStream) {
265
+ process.stdout.write(chunk)
266
+ }
267
+ ```