@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,430 @@
1
+ > Discover all available pages from the documentation index: https://mastra.ai/llms.txt
2
+
3
+ # Aurora DSQL Storage
4
+
5
+ The Aurora DSQL storage implementation provides storage using Amazon Aurora DSQL with IAM authentication.
6
+
7
+ Aurora DSQL doesn't support PostgreSQL extensions (`CREATE EXTENSION`), including `pgvector`. For vector storage, use a separate vector store such as `@mastra/s3vectors`.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @mastra/dsql@beta
13
+ ```
14
+
15
+ ## Prerequisites
16
+
17
+ - Amazon Aurora DSQL cluster
18
+ - AWS credentials with access to the DSQL cluster (IAM authentication)
19
+
20
+ ## Usage
21
+
22
+ ```typescript
23
+ import { DSQLStore } from '@mastra/dsql'
24
+
25
+ const storage = new DSQLStore({
26
+ id: 'my-dsql-store',
27
+ host: 'abc123.dsql.us-east-1.on.aws',
28
+ // region is auto-detected from host, or specify explicitly:
29
+ // region: 'us-east-1',
30
+ // user: 'admin', // default
31
+ // database: 'postgres', // default
32
+ })
33
+
34
+ // Initialize the store (creates tables if needed)
35
+ await storage.init()
36
+ ```
37
+
38
+ ## Parameters
39
+
40
+ **id** (`string`): Unique identifier for this store instance
41
+
42
+ **host** (`string`): DSQL cluster endpoint (e.g., abc123.dsql.us-east-1.on.aws)
43
+
44
+ **pool** (`pg.Pool`): Pre-configured pg.Pool instance. Use this for direct control over the connection pool. Cannot be used with host configuration.
45
+
46
+ **user** (`string`): Database user. Aurora DSQL's admin role is 'admin'.
47
+
48
+ **database** (`string`): Database name. Aurora DSQL exposes a single database named 'postgres' per cluster.
49
+
50
+ **region** (`string`): AWS region. Extracted from host if not provided.
51
+
52
+ **schemaName** (`string`): PostgreSQL schema name where Mastra tables and indexes are created.
53
+
54
+ **customCredentialsProvider** (`AwsCredentialIdentityProvider`): Custom AWS credentials provider for IAM authentication.
55
+
56
+ **max** (`number`): Maximum connections in the pool.
57
+
58
+ **min** (`number`): Minimum connections in the pool.
59
+
60
+ **idleTimeoutMillis** (`number`): Close idle connections after this many milliseconds.
61
+
62
+ **maxLifetimeSeconds** (`number`): Maximum connection lifetime in seconds. Must be less than 3600 due to Aurora DSQL's 60-minute connection limit.
63
+
64
+ **connectionTimeoutMillis** (`number`): Connection acquisition timeout in milliseconds.
65
+
66
+ **allowExitOnIdle** (`boolean`): Allow the process to exit when all connections are idle.
67
+
68
+ ## Constructor Examples
69
+
70
+ You can instantiate `DSQLStore` in the following ways:
71
+
72
+ ```typescript
73
+ import { DSQLStore } from '@mastra/dsql'
74
+
75
+ // Basic configuration (region auto-detected from host)
76
+ const store1 = new DSQLStore({
77
+ id: 'my-dsql-store',
78
+ host: 'abc123.dsql.us-east-1.on.aws',
79
+ })
80
+
81
+ // With explicit region and schema
82
+ const store2 = new DSQLStore({
83
+ id: 'my-dsql-store',
84
+ host: 'abc123.dsql.us-east-1.on.aws',
85
+ region: 'us-east-1',
86
+ schemaName: 'my_app',
87
+ })
88
+
89
+ // With custom credentials provider
90
+ import { fromNodeProviderChain } from '@aws-sdk/credential-providers'
91
+
92
+ const store3 = new DSQLStore({
93
+ id: 'my-dsql-store',
94
+ host: 'abc123.dsql.us-east-1.on.aws',
95
+ customCredentialsProvider: fromNodeProviderChain(),
96
+ })
97
+
98
+ // With connection pool settings
99
+ const store4 = new DSQLStore({
100
+ id: 'my-dsql-store',
101
+ host: 'abc123.dsql.us-east-1.on.aws',
102
+ max: 20,
103
+ min: 2,
104
+ idleTimeoutMillis: 300000,
105
+ maxLifetimeSeconds: 3000,
106
+ connectionTimeoutMillis: 10000,
107
+ })
108
+
109
+ // Using a pre-configured pg.Pool
110
+ import { Pool } from 'pg'
111
+ import { AuroraDSQLClient } from '@aws/aurora-dsql-node-postgres-connector'
112
+
113
+ const pool = new Pool({
114
+ host: 'abc123.dsql.us-east-1.on.aws',
115
+ Client: AuroraDSQLClient,
116
+ region: 'us-east-1',
117
+ })
118
+
119
+ const store5 = new DSQLStore({
120
+ id: 'my-dsql-store',
121
+ pool,
122
+ })
123
+ ```
124
+
125
+ ## Additional Notes
126
+
127
+ ### Schema Management
128
+
129
+ The storage implementation handles schema creation and updates automatically. It creates the following tables:
130
+
131
+ - `mastra_workflow_snapshot`: Stores workflow state and execution data
132
+ - `mastra_threads`: Stores conversation threads
133
+ - `mastra_messages`: Stores individual messages
134
+ - `mastra_ai_spans`: Stores span data for observability
135
+ - `mastra_scorers`: Stores scoring and evaluation data
136
+ - `mastra_resources`: Stores resource working memory data
137
+ - `mastra_agents`: Stores agent data
138
+
139
+ ### Initialization
140
+
141
+ When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
142
+
143
+ ```typescript
144
+ import { Mastra } from '@mastra/core'
145
+ import { DSQLStore } from '@mastra/dsql'
146
+
147
+ const storage = new DSQLStore({
148
+ id: 'my-dsql-store',
149
+ host: 'abc123.dsql.us-east-1.on.aws',
150
+ })
151
+
152
+ const mastra = new Mastra({
153
+ storage, // init() is called automatically
154
+ })
155
+ ```
156
+
157
+ If you're using storage directly without Mastra, you must call `init()` explicitly to create the tables:
158
+
159
+ ```typescript
160
+ import { DSQLStore } from '@mastra/dsql'
161
+
162
+ const storage = new DSQLStore({
163
+ id: 'my-dsql-store',
164
+ host: 'abc123.dsql.us-east-1.on.aws',
165
+ })
166
+
167
+ // Required when using storage directly
168
+ await storage.init()
169
+
170
+ // Access domain-specific stores via getStore()
171
+ const memoryStore = await storage.getStore('memory')
172
+ const thread = await memoryStore?.getThreadById({ threadId: '...' })
173
+ ```
174
+
175
+ > **Warning:** If `init()` isn't called, tables won't be created and storage operations will fail silently or throw errors.
176
+
177
+ ### Direct Database and Pool Access
178
+
179
+ `DSQLStore` exposes both the underlying database client and the pg.Pool instance as public fields:
180
+
181
+ ```typescript
182
+ storage.db // Database client for executing queries
183
+ storage.pool // Underlying pg.Pool instance
184
+ ```
185
+
186
+ It supports direct queries and custom transaction management. When using these fields:
187
+
188
+ - You are responsible for proper connection and transaction handling.
189
+ - Closing the store (`storage.close()`) will destroy the connection pool if it was created by the store.
190
+ - Direct access bypasses any additional logic or validation provided by DSQLStore methods.
191
+
192
+ This approach is intended for advanced scenarios where low-level access is required.
193
+
194
+ ### Aurora DSQL Specifics
195
+
196
+ #### IAM-only authentication
197
+
198
+ Connections are authenticated with IAM. No database passwords are required. `@mastra/dsql` uses `@aws/aurora-dsql-node-postgres-connector` to generate short-lived auth tokens. You can provide a custom credentials provider via `customCredentialsProvider`.
199
+
200
+ #### Single database, schema-based isolation
201
+
202
+ Each cluster exposes a single database `postgres`. Logical separation is done via schemas. The `schemaName` option controls where Mastra tables are created.
203
+
204
+ #### No PostgreSQL extensions
205
+
206
+ `CREATE EXTENSION` isn't supported. This includes `pgvector`, `PostGIS`, and others. For vector storage, use a separate store such as `@mastra/s3vectors` alongside `DSQLStore`.
207
+
208
+ #### JSON stored as text
209
+
210
+ JSON/JSONB are available as query types but not as column types. `@mastra/dsql` stores structured fields (metadata, content, etc.) in `TEXT` columns and casts to JSON at query time.
211
+
212
+ #### Schema and DDL constraints
213
+
214
+ Some PostgreSQL features aren't available:
215
+
216
+ - Foreign key constraints
217
+ - `TRUNCATE`
218
+ - Synchronous `CREATE INDEX`
219
+
220
+ Indexes are created asynchronously using `CREATE INDEX ASYNC`. The store's `init()` and index helper APIs respect these constraints.
221
+
222
+ #### Transactions and optimistic concurrency
223
+
224
+ Aurora DSQL uses optimistic concurrency control (OCC) and may return retriable OCC errors under contention. Limits exist on transaction duration and size. Large bulk operations should be split into smaller batches at the application level.
225
+
226
+ #### Connection lifetime
227
+
228
+ Individual connections are limited to about 60 minutes. The default `maxLifetimeSeconds: 3300` ensures connections are recycled before hitting this limit.
229
+
230
+ ## Usage Example
231
+
232
+ ### Adding memory to an agent
233
+
234
+ To add Aurora DSQL memory to an agent use the `Memory` class and create a new `storage` key using `DSQLStore`. The `host` should point to your Aurora DSQL cluster endpoint.
235
+
236
+ ```typescript
237
+ import { Memory } from '@mastra/memory'
238
+ import { Agent } from '@mastra/core/agent'
239
+ import { DSQLStore } from '@mastra/dsql'
240
+
241
+ export const dsqlAgent = new Agent({
242
+ id: 'dsql-agent',
243
+ name: 'DSQL Agent',
244
+ instructions:
245
+ 'You are an AI agent with the ability to automatically recall memories from previous interactions.',
246
+ model: 'openai/gpt-5.6-sol',
247
+ memory: new Memory({
248
+ storage: new DSQLStore({
249
+ id: 'dsql-agent-storage',
250
+ host: process.env.DSQL_HOST!,
251
+ }),
252
+ options: {
253
+ generateTitle: true, // Explicitly enable automatic title generation
254
+ },
255
+ }),
256
+ })
257
+ ```
258
+
259
+ ### Using the agent
260
+
261
+ 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.
262
+
263
+ ```typescript
264
+ import 'dotenv/config'
265
+
266
+ import { mastra } from './mastra'
267
+
268
+ const threadId = '123'
269
+ const resourceId = 'user-456'
270
+
271
+ const agent = mastra.getAgent('dsql-agent')
272
+
273
+ const message = await agent.stream('My name is Mastra', {
274
+ memory: {
275
+ thread: threadId,
276
+ resource: resourceId,
277
+ },
278
+ })
279
+
280
+ await message.textStream.pipeTo(new WritableStream())
281
+
282
+ const stream = await agent.stream("What's my name?", {
283
+ memory: {
284
+ thread: threadId,
285
+ resource: resourceId,
286
+ },
287
+ memoryOptions: {
288
+ lastMessages: 5,
289
+ semanticRecall: {
290
+ topK: 3,
291
+ messageRange: 2,
292
+ },
293
+ },
294
+ })
295
+
296
+ for await (const chunk of stream.textStream) {
297
+ process.stdout.write(chunk)
298
+ }
299
+ ```
300
+
301
+ ## Index Management
302
+
303
+ Aurora DSQL storage provides index management capabilities to optimize query performance.
304
+
305
+ ### Automatic Performance Indexes
306
+
307
+ Aurora DSQL storage automatically creates composite indexes during initialization for common query patterns:
308
+
309
+ - `mastra_threads_resourceid_createdat_idx`: (resourceId, createdAt)
310
+ - `mastra_messages_thread_id_createdat_idx`: (thread\_id, createdAt)
311
+ - `mastra_ai_spans_traceid_startedat_idx`: (traceId, startedAt)
312
+ - `mastra_ai_spans_parentspanid_startedat_idx`: (parentSpanId, startedAt)
313
+ - `mastra_ai_spans_name_idx`: (name)
314
+ - `mastra_ai_spans_spantype_startedat_idx`: (spanType, startedAt)
315
+ - `mastra_scores_trace_id_span_id_created_at_idx`: (traceId, spanId, createdAt)
316
+
317
+ Aurora DSQL creates these indexes asynchronously using `CREATE INDEX ASYNC`. Because index creation is asynchronous, new indexes may not be immediately available after `init()`. The store will continue to function without them, but queries may be slower until index creation completes.
318
+
319
+ ### Creating Custom Indexes
320
+
321
+ Create additional indexes to optimize specific query patterns:
322
+
323
+ ```typescript
324
+ await storage.createIndex({
325
+ name: 'idx_threads_resource',
326
+ table: 'mastra_threads',
327
+ columns: ['resourceId'],
328
+ })
329
+
330
+ await storage.createIndex({
331
+ name: 'idx_messages_composite',
332
+ table: 'mastra_messages',
333
+ columns: ['thread_id', 'createdAt'],
334
+ })
335
+ ```
336
+
337
+ Aurora DSQL doesn't allow `ASC`/`DESC` in `CREATE INDEX ASYNC`. If you include them, they will be automatically stripped.
338
+
339
+ ### Index Options
340
+
341
+ **name** (`string`): Unique name for the index
342
+
343
+ **table** (`string`): Table name (e.g., 'mastra\_threads')
344
+
345
+ **columns** (`string[]`): Array of column names. ASC/DESC modifiers are automatically stripped for Aurora DSQL compatibility.
346
+
347
+ **unique** (`boolean`): Create a unique index.
348
+
349
+ **concurrent** (`boolean`): Ignored in Aurora DSQL. Indexes are always created asynchronously.
350
+
351
+ **where** (`string`): Partial index condition.
352
+
353
+ **method** (`string`): Ignored in Aurora DSQL. Only btree indexes are supported.
354
+
355
+ **opclass** (`string`): Ignored in Aurora DSQL.
356
+
357
+ **storage** (`Record<string, any>`): Ignored in Aurora DSQL.
358
+
359
+ **tablespace** (`string`): Ignored in Aurora DSQL. Tablespaces are not supported.
360
+
361
+ ### Managing Indexes
362
+
363
+ List and monitor existing indexes:
364
+
365
+ ```typescript
366
+ // List all indexes
367
+ const allIndexes = await storage.listIndexes()
368
+ console.log(allIndexes)
369
+ // [
370
+ // {
371
+ // name: 'mastra_threads_pkey',
372
+ // table: 'mastra_threads',
373
+ // columns: ['id'],
374
+ // unique: true,
375
+ // size: '16 KB',
376
+ // definition: 'CREATE UNIQUE INDEX...'
377
+ // },
378
+ // ...
379
+ // ]
380
+
381
+ // List indexes for a specific table
382
+ const threadIndexes = await storage.listIndexes('mastra_threads')
383
+
384
+ // Get detailed statistics for an index
385
+ const stats = await storage.describeIndex('idx_threads_resource')
386
+ console.log(stats)
387
+ // {
388
+ // name: 'idx_threads_resource',
389
+ // table: 'mastra_threads',
390
+ // columns: ['resourceId'],
391
+ // unique: false,
392
+ // size: '128 KB',
393
+ // definition: 'CREATE INDEX idx_threads_resource...',
394
+ // method: 'btree',
395
+ // scans: 1542,
396
+ // tuples_read: 45230,
397
+ // tuples_fetched: 12050
398
+ // }
399
+
400
+ // Drop an index
401
+ await storage.dropIndex('idx_threads_status')
402
+ ```
403
+
404
+ ### Schema-Specific Indexes
405
+
406
+ When using custom schemas, indexes are created with schema prefixes:
407
+
408
+ ```typescript
409
+ const storage = new DSQLStore({
410
+ id: 'my-dsql-store',
411
+ host: 'abc123.dsql.us-east-1.on.aws',
412
+ schemaName: 'custom_schema',
413
+ })
414
+
415
+ // Creates index as: custom_schema_idx_threads_status
416
+ await storage.createIndex({
417
+ name: 'idx_threads_status',
418
+ table: 'mastra_threads',
419
+ columns: ['status'],
420
+ })
421
+ ```
422
+
423
+ ## Related Resources
424
+
425
+ - [Aurora DSQL Documentation](https://docs.aws.amazon.com/aurora-dsql/)
426
+ - [SQL Reference](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-aurora-dsql-sql.html)
427
+ - [Supported SQL Features](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility-supported-sql-features.html)
428
+ - [Unsupported PostgreSQL Features](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility-unsupported-features.html)
429
+ - [Supported Data Types](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-postgresql-compatibility-supported-data-types.html)
430
+ - [Asynchronous Indexes](https://docs.aws.amazon.com/aurora-dsql/latest/userguide/working-with-create-index-async.html)