@mastra/memory 0.0.0-studio-deploy-20260404182525 → 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.
Files changed (113) hide show
  1. package/CHANGELOG.md +461 -3
  2. package/dist/_types/@internal_ai-sdk-v4/dist/index.d.ts +51 -5
  3. package/dist/{chunk-4FMHSWZD.cjs → chunk-6ODYOMHN.cjs} +1279 -492
  4. package/dist/chunk-6ODYOMHN.cjs.map +1 -0
  5. package/dist/{chunk-C7PARRAD.js → chunk-Z5GWA7LB.js} +1280 -493
  6. package/dist/chunk-Z5GWA7LB.js.map +1 -0
  7. package/dist/{constants-HXOCZPB7.cjs → constants-PJXB7ZIS.cjs} +2 -2
  8. package/dist/{constants-HXOCZPB7.cjs.map → constants-PJXB7ZIS.cjs.map} +1 -1
  9. package/dist/{constants-BDOITAO3.js → constants-XEHPYRDJ.js} +2 -2
  10. package/dist/{constants-BDOITAO3.js.map → constants-XEHPYRDJ.js.map} +1 -1
  11. package/dist/docs/SKILL.md +3 -1
  12. package/dist/docs/assets/SOURCE_MAP.json +47 -59
  13. package/dist/docs/references/docs-agents-background-tasks.md +242 -0
  14. package/dist/docs/references/docs-agents-supervisor-agents.md +65 -0
  15. package/dist/docs/references/docs-memory-memory-processors.md +3 -3
  16. package/dist/docs/references/docs-memory-message-history.md +8 -2
  17. package/dist/docs/references/docs-memory-observational-memory.md +65 -8
  18. package/dist/docs/references/docs-memory-storage.md +1 -2
  19. package/dist/docs/references/docs-memory-working-memory.md +2 -2
  20. package/dist/docs/references/reference-memory-clone-utilities.md +4 -2
  21. package/dist/docs/references/reference-memory-cloneThread.md +4 -2
  22. package/dist/docs/references/reference-memory-observational-memory.md +4 -0
  23. package/dist/docs/references/reference-storage-redis.md +266 -0
  24. package/dist/docs/references/reference-vectors-mongodb.md +0 -2
  25. package/dist/index.cjs +1168 -553
  26. package/dist/index.cjs.map +1 -1
  27. package/dist/index.d.ts +35 -4
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1158 -535
  30. package/dist/index.js.map +1 -1
  31. package/dist/{observational-memory-5YDQLKHE.cjs → observational-memory-OVSEK47Z.cjs} +26 -26
  32. package/dist/{observational-memory-5YDQLKHE.cjs.map → observational-memory-OVSEK47Z.cjs.map} +1 -1
  33. package/dist/{observational-memory-B7AUSTEY.js → observational-memory-UMDC4VC2.js} +3 -3
  34. package/dist/{observational-memory-B7AUSTEY.js.map → observational-memory-UMDC4VC2.js.map} +1 -1
  35. package/dist/processors/index.cjs +24 -24
  36. package/dist/processors/index.js +1 -1
  37. package/dist/processors/observational-memory/date-utils.d.ts +6 -0
  38. package/dist/processors/observational-memory/date-utils.d.ts.map +1 -1
  39. package/dist/processors/observational-memory/index.d.ts +1 -1
  40. package/dist/processors/observational-memory/index.d.ts.map +1 -1
  41. package/dist/processors/observational-memory/markers.d.ts +5 -0
  42. package/dist/processors/observational-memory/markers.d.ts.map +1 -1
  43. package/dist/processors/observational-memory/message-utils.d.ts.map +1 -1
  44. package/dist/processors/observational-memory/model-context.d.ts +10 -0
  45. package/dist/processors/observational-memory/model-context.d.ts.map +1 -0
  46. package/dist/processors/observational-memory/observation-strategies/async-buffer.d.ts.map +1 -1
  47. package/dist/processors/observational-memory/observation-strategies/base.d.ts +3 -3
  48. package/dist/processors/observational-memory/observation-strategies/base.d.ts.map +1 -1
  49. package/dist/processors/observational-memory/observation-strategies/types.d.ts +9 -0
  50. package/dist/processors/observational-memory/observation-strategies/types.d.ts.map +1 -1
  51. package/dist/processors/observational-memory/observation-turn/step.d.ts.map +1 -1
  52. package/dist/processors/observational-memory/observation-turn/turn.d.ts +6 -2
  53. package/dist/processors/observational-memory/observation-turn/turn.d.ts.map +1 -1
  54. package/dist/processors/observational-memory/observation-turn/types.d.ts +1 -0
  55. package/dist/processors/observational-memory/observation-turn/types.d.ts.map +1 -1
  56. package/dist/processors/observational-memory/observational-memory.d.ts +54 -3
  57. package/dist/processors/observational-memory/observational-memory.d.ts.map +1 -1
  58. package/dist/processors/observational-memory/observer-agent.d.ts.map +1 -1
  59. package/dist/processors/observational-memory/processor.d.ts +5 -1
  60. package/dist/processors/observational-memory/processor.d.ts.map +1 -1
  61. package/dist/processors/observational-memory/reflector-runner.d.ts +14 -2
  62. package/dist/processors/observational-memory/reflector-runner.d.ts.map +1 -1
  63. package/dist/processors/observational-memory/repro-capture.d.ts +8 -0
  64. package/dist/processors/observational-memory/repro-capture.d.ts.map +1 -1
  65. package/dist/processors/observational-memory/string-utils.d.ts +13 -0
  66. package/dist/processors/observational-memory/string-utils.d.ts.map +1 -0
  67. package/dist/processors/observational-memory/temporal-markers.d.ts +4 -0
  68. package/dist/processors/observational-memory/temporal-markers.d.ts.map +1 -0
  69. package/dist/processors/observational-memory/tool-result-helpers.d.ts.map +1 -1
  70. package/dist/processors/observational-memory/types.d.ts +56 -2
  71. package/dist/processors/observational-memory/types.d.ts.map +1 -1
  72. package/dist/tools/om-tools.d.ts +14 -2
  73. package/dist/tools/om-tools.d.ts.map +1 -1
  74. package/dist/tools/working-memory.d.ts.map +1 -1
  75. package/package.json +15 -15
  76. package/dist/chunk-3PUO6DLX.js +0 -439
  77. package/dist/chunk-3PUO6DLX.js.map +0 -1
  78. package/dist/chunk-4FMHSWZD.cjs.map +0 -1
  79. package/dist/chunk-C7PARRAD.js.map +0 -1
  80. package/dist/chunk-CK4U3AYR.cjs +0 -84
  81. package/dist/chunk-CK4U3AYR.cjs.map +0 -1
  82. package/dist/chunk-DAJJSFVA.cjs +0 -441
  83. package/dist/chunk-DAJJSFVA.cjs.map +0 -1
  84. package/dist/chunk-DGUM43GV.js +0 -10
  85. package/dist/chunk-DGUM43GV.js.map +0 -1
  86. package/dist/chunk-EQ4M72KU.js +0 -439
  87. package/dist/chunk-EQ4M72KU.js.map +0 -1
  88. package/dist/chunk-IDRQZVB4.cjs +0 -84
  89. package/dist/chunk-IDRQZVB4.cjs.map +0 -1
  90. package/dist/chunk-JEQ2X3Z6.cjs +0 -12
  91. package/dist/chunk-JEQ2X3Z6.cjs.map +0 -1
  92. package/dist/chunk-RC6RZVYE.js +0 -79
  93. package/dist/chunk-RC6RZVYE.js.map +0 -1
  94. package/dist/chunk-SVPZMV27.js +0 -79
  95. package/dist/chunk-SVPZMV27.js.map +0 -1
  96. package/dist/chunk-ZD3BKU5O.cjs +0 -441
  97. package/dist/chunk-ZD3BKU5O.cjs.map +0 -1
  98. package/dist/token-APYSY3BW-2DN6RAUY.js +0 -61
  99. package/dist/token-APYSY3BW-2DN6RAUY.js.map +0 -1
  100. package/dist/token-APYSY3BW-POD4OUWN.cjs +0 -63
  101. package/dist/token-APYSY3BW-POD4OUWN.cjs.map +0 -1
  102. package/dist/token-APYSY3BW-YTVQELJT.js +0 -61
  103. package/dist/token-APYSY3BW-YTVQELJT.js.map +0 -1
  104. package/dist/token-APYSY3BW-ZQ7TMBY7.cjs +0 -63
  105. package/dist/token-APYSY3BW-ZQ7TMBY7.cjs.map +0 -1
  106. package/dist/token-util-RMHT2CPJ-6TGPE335.cjs +0 -10
  107. package/dist/token-util-RMHT2CPJ-6TGPE335.cjs.map +0 -1
  108. package/dist/token-util-RMHT2CPJ-77HHGIQN.cjs +0 -10
  109. package/dist/token-util-RMHT2CPJ-77HHGIQN.cjs.map +0 -1
  110. package/dist/token-util-RMHT2CPJ-RJEA3FAN.js +0 -8
  111. package/dist/token-util-RMHT2CPJ-RJEA3FAN.js.map +0 -1
  112. package/dist/token-util-RMHT2CPJ-WJZ2SYAR.js +0 -8
  113. package/dist/token-util-RMHT2CPJ-WJZ2SYAR.js.map +0 -1
@@ -38,8 +38,45 @@ const memory = new Memory({
38
38
 
39
39
  See [configuration options](https://mastra.ai/reference/memory/observational-memory) for full API details.
40
40
 
41
+ > **Warning:** When you use OM with a client application, send **only the new message** from the client instead of the full conversation history.
42
+ >
43
+ > Observational memory still relies on stored conversation history. Sending the full history is redundant and can cause message ordering bugs when client-side timestamps conflict with stored timestamps.
44
+ >
45
+ > For an AI SDK example, see [Using Mastra Memory](https://mastra.ai/guides/build-your-ui/ai-sdk-ui).
46
+
41
47
  > **Note:** OM currently only supports `@mastra/pg`, `@mastra/libsql`, and `@mastra/mongodb` storage adapters. It uses background agents for managing memory. When using `observationalMemory: true`, the default model is `google/gemini-2.5-flash`. When passing a config object, a `model` must be explicitly set.
42
48
 
49
+ ## Temporal gap markers
50
+
51
+ Temporal gap markers insert a short reminder before a new user message when enough time has passed since the previous message in the thread. They help the agent and the UI see that the conversation resumed after a meaningful pause.
52
+
53
+ Temporal gap markers are off by default. Enable them with `temporalMarkers: true` in the `observationalMemory` config:
54
+
55
+ ```typescript
56
+ import { Memory } from '@mastra/memory'
57
+ import { Agent } from '@mastra/core/agent'
58
+
59
+ export const agent = new Agent({
60
+ name: 'my-agent',
61
+ instructions: 'You are a helpful assistant.',
62
+ model: 'openai/gpt-5-mini',
63
+ memory: new Memory({
64
+ options: {
65
+ observationalMemory: {
66
+ model: 'google/gemini-2.5-flash',
67
+ temporalMarkers: true,
68
+ },
69
+ },
70
+ }),
71
+ })
72
+ ```
73
+
74
+ Mastra inserts a temporal gap marker when the gap is at least 10 minutes. The marker is stored in memory and also emitted as a transient reminder event, so clients can render it as a lightweight timeline hint.
75
+
76
+ The observer also sees these markers when it processes the thread, so the observations it writes can anchor memories to when they happened (for example, "User asked about deployment after a 2-day gap").
77
+
78
+ See [the API reference](https://mastra.ai/reference/memory/observational-memory) for the full configuration shape.
79
+
43
80
  ## Benefits
44
81
 
45
82
  - **Prompt caching**: OM's context is stable and observations append over time rather than being dynamically retrieved each turn. This keeps the prompt prefix cacheable, which reduces costs.
@@ -157,7 +194,7 @@ With retrieval mode enabled, OM:
157
194
  - Registers a `recall` tool the agent can call to:
158
195
 
159
196
  - Page through the raw messages behind any observation group range
160
- - Search by semantic similarity (`mode: "search"` with a `query` string) — requires `vector: true`
197
+ - Search by semantic similarity (`mode: "search"` with a `query` string); requires `vector: true`
161
198
  - List all threads (`mode: "threads"`), browse other threads (`threadId`), and search across all threads (default `scope: 'resource'`)
162
199
  - When `scope: 'thread'`: restrict browsing and search to the current thread only
163
200
 
@@ -327,13 +364,33 @@ Reflection works similarly — the Reflector runs in the background when observa
327
364
 
328
365
  ### Settings
329
366
 
330
- | Setting | Default | What it controls |
331
- | ------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
332
- | `observation.bufferTokens` | `0.2` | How often to buffer. `0.2` means every 20% of `messageTokens` — with the default 30k threshold, that's roughly every 6k tokens. Can also be an absolute token count (e.g. `5000`). |
333
- | `observation.bufferActivation` | `0.8` | How aggressively to clear the message window on activation. `0.8` means remove enough messages to keep only 20% of `messageTokens` remaining. Lower values keep more message history. |
334
- | `observation.blockAfter` | `1.2` | Safety threshold as a multiplier of `messageTokens`. At `1.2`, synchronous observation is forced at 36k tokens (1.2 × 30k). Only matters if buffering can't keep up. |
335
- | `reflection.bufferActivation` | `0.5` | When to start background reflection. `0.5` means reflection begins when observations reach 50% of the `observationTokens` threshold. |
336
- | `reflection.blockAfter` | `1.2` | Safety threshold for reflection, same logic as observation. |
367
+ | Setting | Default | What it controls |
368
+ | ------------------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
369
+ | `observation.bufferTokens` | `0.2` | How often to buffer. `0.2` means every 20% of `messageTokens` — with the default 30k threshold, that's roughly every 6k tokens. Can also be an absolute token count (e.g. `5000`). |
370
+ | `observation.bufferActivation` | `0.8` | How aggressively to clear the message window on activation. `0.8` means remove enough messages to keep only 20% of `messageTokens` remaining. Lower values keep more message history. |
371
+ | `observation.blockAfter` | `1.2` | Safety threshold as a multiplier of `messageTokens`. At `1.2`, synchronous observation is forced at 36k tokens (1.2 × 30k). Only matters if buffering can't keep up. |
372
+ | `activateAfterIdle` | none | Forces buffered observations and buffered reflections to activate after a period of inactivity, even if their token thresholds have not been reached yet. Accepts milliseconds or duration strings like `300_000`, `"5m"`, or `"1hr"`. Set this to your prompt cache TTL if you want activation to happen before the next cold prompt. |
373
+ | `activateOnProviderChange` | `false` | Forces buffered observations and reflections to activate when the next step uses a different `provider/model` than the one that produced the latest assistant step. Use this when switching providers or models would invalidate prompt cache reuse. |
374
+ | `reflection.bufferActivation` | `0.5` | When to start background reflection. `0.5` means reflection begins when observations reach 50% of the `observationTokens` threshold. |
375
+ | `reflection.blockAfter` | `1.2` | Safety threshold for reflection, same logic as observation. |
376
+
377
+ If you're relying on prompt caching, set `activateAfterIdle` to match your cache TTL. That way, once a thread has been idle long enough for the cache to expire, the next request can activate buffered observations or reflections first and send a smaller compressed context window.
378
+
379
+ ```typescript
380
+ const memory = new Memory({
381
+ options: {
382
+ observationalMemory: {
383
+ model: 'google/gemini-2.5-flash',
384
+ activateAfterIdle: '5m',
385
+ activateOnProviderChange: true,
386
+ },
387
+ },
388
+ })
389
+ ```
390
+
391
+ With a 5-minute prompt cache TTL, this activates buffered context after 5 minutes of inactivity so the next uncached prompt uses observations and reflections instead of a larger raw message window. If you prefer, `300_000` works the same way.
392
+
393
+ Changing model or providers mid-thread will invalidate the prompt cache. If your agent can switch between providers or models mid-thread, `activateOnProviderChange: true` forces buffered context to activate before the new provider runs. That avoids sending a large raw window to a provider that cannot reuse the previous prompt cache.
337
394
 
338
395
  ### Disabling
339
396
 
@@ -34,6 +34,7 @@ Each provider page includes installation instructions, configuration parameters,
34
34
  - [PostgreSQL](https://mastra.ai/reference/storage/postgresql)
35
35
  - [MongoDB](https://mastra.ai/reference/storage/mongodb)
36
36
  - [Upstash](https://mastra.ai/reference/storage/upstash)
37
+ - [Redis](https://mastra.ai/reference/storage/redis)
37
38
  - [Cloudflare D1](https://mastra.ai/reference/storage/cloudflare-d1)
38
39
  - [Cloudflare KV & Durable Objects](https://mastra.ai/reference/storage/cloudflare)
39
40
  - [Convex](https://mastra.ai/reference/storage/convex)
@@ -118,8 +119,6 @@ export const agent = new Agent({
118
119
  })
119
120
  ```
120
121
 
121
- > **Warning:** Agent-level storage isn't supported when using [Mastra Cloud Store](https://mastra.ai/docs/mastra-cloud/deployment). If you use Mastra Cloud Store, configure storage on the Mastra instance instead. This limitation doesn't apply if you bring your own database.
122
-
123
122
  ## Threads and resources
124
123
 
125
124
  Mastra organizes conversations using two identifiers:
@@ -208,7 +208,7 @@ const paragraphMemory = new Memory({
208
208
 
209
209
  ## Structured working memory
210
210
 
211
- Working memory can also be defined using a structured schema instead of a Markdown template. This allows you to specify the exact fields and types that should be tracked, using a [Zod](https://zod.dev/) schema. When using a schema, the agent will see and update working memory as a JSON object matching your schema.
211
+ Working memory can also be defined using a structured schema instead of a Markdown template. This allows you to specify the exact fields and types that should be tracked, using a [Standard JSON Schema](https://standardschema.dev/json-schema) ([Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), etc.). When using a schema, the agent will see and update working memory as a JSON object matching your schema.
212
212
 
213
213
  **Important:** You must specify either `template` or `schema`, but not both.
214
214
 
@@ -397,4 +397,4 @@ const response = await agent.generate('What do you know about me?', {
397
397
 
398
398
  - [Working memory with template](https://github.com/mastra-ai/mastra/tree/main/examples/memory-with-template)
399
399
  - [Working memory with schema](https://github.com/mastra-ai/mastra/tree/main/examples/memory-with-schema)
400
- - [Per-resource working memory](https://github.com/mastra-ai/mastra/tree/main/examples/memory-per-resource-example) - Complete example showing resource-scoped memory persistence
400
+ - [Per-resource working memory](https://github.com/mastra-ai/mastra/tree/main/examples/memory-per-resource-example): Complete example showing resource-scoped memory persistence
@@ -153,8 +153,10 @@ async function manageClones() {
153
153
 
154
154
  // Have a conversation...
155
155
  await agent.generate("Hello! Let's discuss project options.", {
156
- threadId: originalThread.id,
157
- resourceId: 'user-123',
156
+ memory: {
157
+ thread: originalThread.id,
158
+ resource: 'user-123',
159
+ },
158
160
  })
159
161
 
160
162
  // Create multiple branches (clones) to explore different paths
@@ -93,8 +93,10 @@ const { thread: dateFilteredClone } = await memory.cloneThread({
93
93
 
94
94
  // Continue conversation on the cloned thread
95
95
  const response = await agent.generate("Let's try a different approach", {
96
- threadId: fullClone.id,
97
- resourceId: fullClone.resourceId,
96
+ memory: {
97
+ thread: fullClone.id,
98
+ resource: fullClone.resourceId,
99
+ },
98
100
  })
99
101
  ```
100
102
 
@@ -36,8 +36,12 @@ OM performs thresholding with fast local token estimation. Text uses `tokenx`, a
36
36
 
37
37
  **scope** (`'resource' | 'thread'`): Memory scope for observations. \`'thread'\` keeps observations per-thread. \`'resource'\` (experimental) shares observations across all threads for a resource, enabling cross-conversation memory. (Default: `'thread'`)
38
38
 
39
+ **activateAfterIdle** (`number | string`): Time before buffered observations or buffered reflections are forced to activate after inactivity, even if their token thresholds have not been reached yet. Accepts milliseconds or duration strings like \`300\_000\`, \`"5m"\`, or \`"1hr"\`. When the gap between the current time and the last assistant message part timestamp exceeds this value, buffered observational memory activates before the next prompt. Useful for aligning with prompt cache TTLs.
40
+
39
41
  **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
42
 
43
+ **temporalMarkers** (`boolean`): Insert temporal-gap reminder markers before new user messages when the previous message in the thread is at least 10 minutes older. The marker is persisted in memory, emitted as an inline reminder event so clients can render it specially, and shown to the observer so it can anchor observations to when events occurred. (Default: `false`)
44
+
41
45
  **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
46
 
43
47
  **observation** (`ObservationalMemoryObservationConfig`): Configuration for the observation step. Controls when the Observer agent runs and how it behaves.
@@ -0,0 +1,266 @@
1
+ # Redis Storage
2
+
3
+ The Redis storage implementation provides a high-performance storage solution using direct Redis connections via [node-redis](https://github.com/redis/node-redis) (the official Redis client for Node.js). It supports standalone Redis, and through custom client configuration, Redis Sentinel and Cluster deployments.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @mastra/redis
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Using Connection String
14
+
15
+ ```typescript
16
+ import { RedisStore } from '@mastra/redis'
17
+
18
+ const storage = new RedisStore({
19
+ id: 'redis-storage',
20
+ connectionString: 'redis://localhost:6379',
21
+ })
22
+
23
+ await storage.init()
24
+ ```
25
+
26
+ ### Using Host/Port Configuration
27
+
28
+ ```typescript
29
+ import { RedisStore } from '@mastra/redis'
30
+
31
+ const storage = new RedisStore({
32
+ id: 'redis-storage',
33
+ host: 'localhost',
34
+ port: 6379,
35
+ password: 'your-password',
36
+ db: 0,
37
+ })
38
+
39
+ await storage.init()
40
+ ```
41
+
42
+ ### Using Pre-configured Client
43
+
44
+ For advanced configurations like Sentinel or Cluster, you can pass a pre-configured redis client:
45
+
46
+ ```typescript
47
+ import { RedisStore } from '@mastra/redis'
48
+ import { createClient } from 'redis'
49
+
50
+ const client = createClient({
51
+ url: 'redis://localhost:6379',
52
+ socket: {
53
+ reconnectStrategy: retries => Math.min(retries * 50, 2000),
54
+ },
55
+ })
56
+
57
+ // Connect the client before passing to RedisStore
58
+ await client.connect()
59
+
60
+ const storage = new RedisStore({
61
+ id: 'redis-storage',
62
+ client,
63
+ })
64
+ ```
65
+
66
+ ## Parameters
67
+
68
+ **id** (`string`): Unique identifier for the storage instance
69
+
70
+ **connectionString** (`string`): Redis connection URL (e.g., \`redis\://localhost:6379\` or \`redis\://:password\@localhost:6379\`)
71
+
72
+ **host** (`string`): Redis host address
73
+
74
+ **port** (`number`): Redis port number (Default: `6379`)
75
+
76
+ **password** (`string`): Redis password for authentication
77
+
78
+ **db** (`number`): Redis database number (Default: `0`)
79
+
80
+ **client** (`RedisClient`): Pre-configured redis client (from the \`redis\` package) for advanced setups
81
+
82
+ > **Note:** You must provide either `connectionString`, `host`, or `client`. These options are mutually exclusive.
83
+
84
+ ## Additional Notes
85
+
86
+ ### Key Structure
87
+
88
+ The Redis storage implementation uses the following key patterns:
89
+
90
+ - Threads: `mastra_threads:id:{threadId}`
91
+ - Messages: `mastra_messages:threadId:{threadId}:id:{messageId}`
92
+ - Message index: `msg-idx:{messageId}` (for fast lookups)
93
+ - Thread messages sorted set: `thread:{threadId}:messages`
94
+ - Workflow snapshots: `mastra_workflow_snapshot:namespace:{ns}:workflow_name:{name}:run_id:{id}`
95
+ - Scores: `mastra_scorers:id:{scoreId}`
96
+ - Resources: `mastra_resources:{resourceId}`
97
+
98
+ ### Redis Sentinel
99
+
100
+ For high-availability deployments using Redis Sentinel, create a custom client:
101
+
102
+ ```typescript
103
+ import { RedisStore } from '@mastra/redis'
104
+ import { createClient } from 'redis'
105
+
106
+ const client = createClient({
107
+ url: 'redis://sentinel-host:26379',
108
+ // Configure sentinel options as needed for your setup
109
+ })
110
+
111
+ await client.connect()
112
+
113
+ const storage = new RedisStore({
114
+ id: 'redis-sentinel-storage',
115
+ client,
116
+ })
117
+ ```
118
+
119
+ ### Redis Cluster
120
+
121
+ For Redis Cluster deployments, use the cluster client:
122
+
123
+ ```typescript
124
+ import { RedisStore } from '@mastra/redis'
125
+ import { createCluster } from 'redis'
126
+
127
+ const cluster = createCluster({
128
+ rootNodes: [
129
+ { url: 'redis://node-1:6379' },
130
+ { url: 'redis://node-2:6379' },
131
+ { url: 'redis://node-3:6379' },
132
+ ],
133
+ })
134
+
135
+ await cluster.connect()
136
+
137
+ const storage = new RedisStore({
138
+ id: 'redis-cluster-storage',
139
+ client: cluster,
140
+ })
141
+ ```
142
+
143
+ ### Accessing the Underlying Client
144
+
145
+ You can access the underlying redis client for custom operations:
146
+
147
+ ```typescript
148
+ const storage = new RedisStore({
149
+ id: 'redis-storage',
150
+ connectionString: 'redis://localhost:6379',
151
+ })
152
+
153
+ await storage.init()
154
+
155
+ const client = storage.getClient()
156
+
157
+ // Custom Redis operations
158
+ await client.set('custom-key', 'value')
159
+ const value = await client.get('custom-key')
160
+ ```
161
+
162
+ ### Closing Connections
163
+
164
+ When shutting down your application, close the Redis connection:
165
+
166
+ ```typescript
167
+ await storage.close()
168
+ ```
169
+
170
+ ## Usage Example
171
+
172
+ ### Adding memory to an agent
173
+
174
+ ```typescript
175
+ import { Memory } from '@mastra/memory'
176
+ import { Agent } from '@mastra/core/agent'
177
+ import { RedisStore } from '@mastra/redis'
178
+
179
+ export const redisAgent = new Agent({
180
+ id: 'redis-agent',
181
+ name: 'Redis Agent',
182
+ instructions:
183
+ 'You are an AI agent with the ability to automatically recall memories from previous interactions.',
184
+ model: 'openai/gpt-4o',
185
+ memory: new Memory({
186
+ storage: new RedisStore({
187
+ id: 'redis-agent-storage',
188
+ connectionString: process.env.REDIS_URL!,
189
+ }),
190
+ options: {
191
+ lastMessages: 10,
192
+ },
193
+ }),
194
+ })
195
+ ```
196
+
197
+ ### Using the agent
198
+
199
+ ```typescript
200
+ import 'dotenv/config'
201
+
202
+ import { mastra } from './mastra'
203
+
204
+ const threadId = '123'
205
+ const resourceId = 'user-456'
206
+
207
+ const agent = mastra.getAgent('redisAgent')
208
+
209
+ const message = await agent.stream('My name is Mastra', {
210
+ memory: {
211
+ thread: threadId,
212
+ resource: resourceId,
213
+ },
214
+ })
215
+
216
+ await message.textStream.pipeTo(new WritableStream())
217
+
218
+ const stream = await agent.stream("What's my name?", {
219
+ memory: {
220
+ thread: threadId,
221
+ resource: resourceId,
222
+ },
223
+ memoryOptions: {
224
+ lastMessages: 5,
225
+ },
226
+ })
227
+
228
+ for await (const chunk of stream.textStream) {
229
+ process.stdout.write(chunk)
230
+ }
231
+ ```
232
+
233
+ ### Using with Mastra instance
234
+
235
+ ```typescript
236
+ import { Mastra } from '@mastra/core'
237
+ import { RedisStore } from '@mastra/redis'
238
+
239
+ const storage = new RedisStore({
240
+ id: 'mastra-storage',
241
+ host: 'localhost',
242
+ port: 6379,
243
+ })
244
+
245
+ const mastra = new Mastra({
246
+ storage, // init() called automatically
247
+ })
248
+ ```
249
+
250
+ If using storage directly without Mastra, call `init()` explicitly:
251
+
252
+ ```typescript
253
+ import { RedisStore } from '@mastra/redis'
254
+
255
+ const storage = new RedisStore({
256
+ id: 'redis-storage',
257
+ host: 'localhost',
258
+ port: 6379,
259
+ })
260
+
261
+ await storage.init()
262
+
263
+ // Access domain-specific stores via getStore()
264
+ const memoryStore = await storage.getStore('memory')
265
+ const thread = await memoryStore?.getThreadById({ threadId: '...' })
266
+ ```
@@ -107,8 +107,6 @@ Searches for similar vectors with optional metadata filtering.
107
107
 
108
108
  **includeVector** (`boolean`): Whether to include vector data in results (Default: `false`)
109
109
 
110
- **minScore** (`number`): Minimum similarity score threshold (Default: `0`)
111
-
112
110
  ### `describeIndex()`
113
111
 
114
112
  Returns information about the index (collection).