@mastra/libsql 0.0.0-workflow-timeout-issue-20260220185702 → 0.0.0-workflow-graph-crash-20260527191009
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1085 -3
- package/LICENSE.md +15 -0
- package/dist/docs/SKILL.md +18 -19
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-agent-builder-deploying.md +121 -0
- package/dist/docs/references/docs-agent-builder-overview.md +97 -0
- package/dist/docs/references/docs-agents-agent-approval.md +336 -202
- package/dist/docs/references/docs-agents-networks.md +107 -215
- package/dist/docs/references/docs-memory-memory-processors.md +86 -88
- package/dist/docs/references/docs-memory-message-history.md +71 -63
- package/dist/docs/references/docs-memory-multi-user-threads.md +206 -0
- package/dist/docs/references/docs-memory-overview.md +221 -24
- package/dist/docs/references/docs-memory-semantic-recall.md +162 -75
- package/dist/docs/references/docs-memory-storage.md +72 -73
- package/dist/docs/references/docs-memory-working-memory.md +62 -62
- package/dist/docs/references/docs-rag-retrieval.md +132 -135
- package/dist/docs/references/docs-workflows-snapshots.md +31 -31
- package/dist/docs/references/guides-agent-frameworks-ai-sdk.md +36 -36
- package/dist/docs/references/reference-core-getMemory.md +15 -16
- package/dist/docs/references/reference-core-listMemory.md +17 -18
- package/dist/docs/references/reference-core-mastra-class.md +37 -27
- package/dist/docs/references/reference-memory-memory-class.md +41 -43
- package/dist/docs/references/reference-storage-composite.md +65 -55
- package/dist/docs/references/reference-storage-dynamodb.md +36 -36
- package/dist/docs/references/reference-storage-libsql.md +27 -27
- package/dist/docs/references/reference-vectors-libsql.md +72 -72
- package/dist/index.cjs +7896 -3257
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7888 -3259
- package/dist/index.js.map +1 -1
- package/dist/storage/db/index.d.ts +14 -1
- package/dist/storage/db/index.d.ts.map +1 -1
- package/dist/storage/db/utils.d.ts +16 -0
- package/dist/storage/db/utils.d.ts.map +1 -1
- package/dist/storage/domains/agents/index.d.ts.map +1 -1
- package/dist/storage/domains/background-tasks/index.d.ts +18 -0
- package/dist/storage/domains/background-tasks/index.d.ts.map +1 -0
- package/dist/storage/domains/blobs/index.d.ts +17 -0
- package/dist/storage/domains/blobs/index.d.ts.map +1 -0
- package/dist/storage/domains/channels/index.d.ts +20 -0
- package/dist/storage/domains/channels/index.d.ts.map +1 -0
- package/dist/storage/domains/datasets/index.d.ts +43 -0
- package/dist/storage/domains/datasets/index.d.ts.map +1 -0
- package/dist/storage/domains/experiments/index.d.ts +31 -0
- package/dist/storage/domains/experiments/index.d.ts.map +1 -0
- package/dist/storage/domains/favorites/index.d.ts +17 -0
- package/dist/storage/domains/favorites/index.d.ts.map +1 -0
- package/dist/storage/domains/mcp-clients/index.d.ts.map +1 -1
- package/dist/storage/domains/mcp-servers/index.d.ts +26 -0
- package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
- package/dist/storage/domains/memory/index.d.ts +7 -3
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/domains/observability/index.d.ts +2 -1
- package/dist/storage/domains/observability/index.d.ts.map +1 -1
- package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -1
- package/dist/storage/domains/schedules/index.d.ts +19 -0
- package/dist/storage/domains/schedules/index.d.ts.map +1 -0
- package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -1
- package/dist/storage/domains/skills/index.d.ts +26 -0
- package/dist/storage/domains/skills/index.d.ts.map +1 -0
- package/dist/storage/domains/workflows/index.d.ts +1 -0
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/dist/storage/domains/workspaces/index.d.ts +26 -0
- package/dist/storage/domains/workspaces/index.d.ts.map +1 -0
- package/dist/storage/index.d.ts +38 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/vector/index.d.ts +14 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +12 -12
- package/dist/docs/references/docs-agents-agent-memory.md +0 -212
- package/dist/docs/references/docs-agents-network-approval.md +0 -275
- package/dist/docs/references/docs-observability-overview.md +0 -70
- package/dist/docs/references/docs-observability-tracing-exporters-default.md +0 -211
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
# Semantic
|
|
1
|
+
# Semantic recall
|
|
2
2
|
|
|
3
3
|
If you ask your friend what they did last weekend, they will search in their memory for events associated with "last weekend" and then tell you what they did. That's sort of like how semantic recall works in Mastra.
|
|
4
4
|
|
|
5
5
|
> **Watch 📹:** What semantic recall is, how it works, and how to configure it in Mastra → [YouTube (5 minutes)](https://youtu.be/UVZtK8cK8xQ)
|
|
6
6
|
|
|
7
|
-
## How
|
|
7
|
+
## How semantic recall works
|
|
8
8
|
|
|
9
9
|
Semantic recall is RAG-based search that helps agents maintain context across longer interactions when messages are no longer within [recent message history](https://mastra.ai/docs/memory/message-history).
|
|
10
10
|
|
|
@@ -16,44 +16,59 @@ When it's enabled, new messages are used to query a vector DB for semantically s
|
|
|
16
16
|
|
|
17
17
|
After getting a response from the LLM, all new messages (user, assistant, and tool calls/results) are inserted into the vector DB to be recalled in later interactions.
|
|
18
18
|
|
|
19
|
-
##
|
|
19
|
+
## Quickstart
|
|
20
20
|
|
|
21
|
-
Semantic recall is
|
|
21
|
+
Semantic recall is disabled by default. To enable it, set `semanticRecall: true` in `options` and provide a `vector` store and `embedder`:
|
|
22
22
|
|
|
23
23
|
```typescript
|
|
24
|
-
import { Agent } from
|
|
25
|
-
import { Memory } from
|
|
24
|
+
import { Agent } from '@mastra/core/agent'
|
|
25
|
+
import { Memory } from '@mastra/memory'
|
|
26
|
+
import { LibSQLStore, LibSQLVector } from '@mastra/libsql'
|
|
27
|
+
import { ModelRouterEmbeddingModel } from '@mastra/core/llm'
|
|
26
28
|
|
|
27
29
|
const agent = new Agent({
|
|
28
|
-
id:
|
|
29
|
-
name:
|
|
30
|
-
instructions:
|
|
31
|
-
model:
|
|
32
|
-
memory: new Memory(
|
|
33
|
-
|
|
30
|
+
id: 'support-agent',
|
|
31
|
+
name: 'SupportAgent',
|
|
32
|
+
instructions: 'You are a helpful support agent.',
|
|
33
|
+
model: 'openai/gpt-5.4',
|
|
34
|
+
memory: new Memory({
|
|
35
|
+
storage: new LibSQLStore({
|
|
36
|
+
id: 'agent-storage',
|
|
37
|
+
url: 'file:./local.db',
|
|
38
|
+
}),
|
|
39
|
+
vector: new LibSQLVector({
|
|
40
|
+
id: 'agent-vector',
|
|
41
|
+
url: 'file:./local.db',
|
|
42
|
+
}),
|
|
43
|
+
embedder: new ModelRouterEmbeddingModel('openai/text-embedding-3-small'),
|
|
44
|
+
options: {
|
|
45
|
+
semanticRecall: true,
|
|
46
|
+
},
|
|
47
|
+
}),
|
|
48
|
+
})
|
|
34
49
|
```
|
|
35
50
|
|
|
36
|
-
## Using the recall()
|
|
51
|
+
## Using the `recall()` method
|
|
37
52
|
|
|
38
|
-
While `listMessages` retrieves messages by thread ID with basic pagination, [`recall()`](https://mastra.ai/reference/memory/recall) adds support for **semantic search**. When you need to find messages by meaning rather than
|
|
53
|
+
While `listMessages` retrieves messages by thread ID with basic pagination, [`recall()`](https://mastra.ai/reference/memory/recall) adds support for **semantic search**. When you need to find messages by meaning rather than recency, use `recall()` with a `vectorSearchString`:
|
|
39
54
|
|
|
40
55
|
```typescript
|
|
41
|
-
const memory = await agent.getMemory()
|
|
56
|
+
const memory = await agent.getMemory()
|
|
42
57
|
|
|
43
58
|
// Basic recall - similar to listMessages
|
|
44
59
|
const { messages } = await memory!.recall({
|
|
45
|
-
threadId:
|
|
60
|
+
threadId: 'thread-123',
|
|
46
61
|
perPage: 50,
|
|
47
|
-
})
|
|
62
|
+
})
|
|
48
63
|
|
|
49
64
|
// Semantic recall - find messages by meaning
|
|
50
65
|
const { messages: relevantMessages } = await memory!.recall({
|
|
51
|
-
threadId:
|
|
52
|
-
vectorSearchString:
|
|
66
|
+
threadId: 'thread-123',
|
|
67
|
+
vectorSearchString: 'What did we discuss about the project deadline?',
|
|
53
68
|
threadConfig: {
|
|
54
69
|
semanticRecall: true,
|
|
55
70
|
},
|
|
56
|
-
})
|
|
71
|
+
})
|
|
57
72
|
```
|
|
58
73
|
|
|
59
74
|
## Storage configuration
|
|
@@ -61,24 +76,27 @@ const { messages: relevantMessages } = await memory!.recall({
|
|
|
61
76
|
Semantic recall relies on a [storage and vector db](https://mastra.ai/reference/memory/memory-class) to store messages and their embeddings.
|
|
62
77
|
|
|
63
78
|
```ts
|
|
64
|
-
import { Memory } from
|
|
65
|
-
import { Agent } from
|
|
66
|
-
import { LibSQLStore, LibSQLVector } from
|
|
79
|
+
import { Memory } from '@mastra/memory'
|
|
80
|
+
import { Agent } from '@mastra/core/agent'
|
|
81
|
+
import { LibSQLStore, LibSQLVector } from '@mastra/libsql'
|
|
67
82
|
|
|
68
83
|
const agent = new Agent({
|
|
69
84
|
memory: new Memory({
|
|
70
85
|
// this is the default storage db if omitted
|
|
71
86
|
storage: new LibSQLStore({
|
|
72
87
|
id: 'agent-storage',
|
|
73
|
-
url:
|
|
88
|
+
url: 'file:./local.db',
|
|
74
89
|
}),
|
|
75
90
|
// this is the default vector db if omitted
|
|
76
91
|
vector: new LibSQLVector({
|
|
77
92
|
id: 'agent-vector',
|
|
78
|
-
url:
|
|
93
|
+
url: 'file:./local.db',
|
|
79
94
|
}),
|
|
95
|
+
options: {
|
|
96
|
+
semanticRecall: true,
|
|
97
|
+
},
|
|
80
98
|
}),
|
|
81
|
-
})
|
|
99
|
+
})
|
|
82
100
|
```
|
|
83
101
|
|
|
84
102
|
Each vector store page below includes installation instructions, configuration parameters, and usage examples:
|
|
@@ -103,70 +121,151 @@ Each vector store page below includes installation instructions, configuration p
|
|
|
103
121
|
|
|
104
122
|
## Recall configuration
|
|
105
123
|
|
|
106
|
-
The
|
|
124
|
+
The following options control semantic recall behavior:
|
|
107
125
|
|
|
108
|
-
1. **topK**:
|
|
109
|
-
2. **messageRange**:
|
|
110
|
-
3. **scope**: Whether to search
|
|
126
|
+
1. **topK**: The number of similar messages to retrieve
|
|
127
|
+
2. **messageRange**: The surrounding messages to include with each match
|
|
128
|
+
3. **scope**: Whether to search the current thread or all threads for a resource
|
|
129
|
+
4. **filter**: Metadata criteria that restrict search results
|
|
111
130
|
|
|
112
131
|
```typescript
|
|
113
132
|
const agent = new Agent({
|
|
114
133
|
memory: new Memory({
|
|
115
134
|
options: {
|
|
116
135
|
semanticRecall: {
|
|
117
|
-
topK: 3, // Retrieve 3
|
|
136
|
+
topK: 3, // Retrieve 3 similar messages
|
|
118
137
|
messageRange: 2, // Include 2 messages before and after each match
|
|
119
|
-
scope:
|
|
138
|
+
scope: 'resource', // Search all threads for this resource
|
|
139
|
+
filter: { projectId: { $eq: 'project-a' } },
|
|
120
140
|
},
|
|
121
141
|
},
|
|
122
142
|
}),
|
|
123
|
-
})
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
> **Note:** `scope: 'resource'` is supported by the LibSQL, PostgreSQL, and Upstash storage adapters.
|
|
147
|
+
|
|
148
|
+
### Metadata filtering
|
|
149
|
+
|
|
150
|
+
The `filter` option restricts semantic recall results to messages with matching thread metadata.
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
const agent = new Agent({
|
|
154
|
+
memory: new Memory({
|
|
155
|
+
options: {
|
|
156
|
+
semanticRecall: {
|
|
157
|
+
scope: 'resource',
|
|
158
|
+
filter: {
|
|
159
|
+
projectId: { $eq: 'project-a' },
|
|
160
|
+
category: { $in: ['work', 'personal'] },
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
}),
|
|
165
|
+
})
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Filters match metadata stored on message embeddings when messages are saved. If thread metadata changes later, existing embeddings keep their previous metadata until those messages are saved or indexed again.
|
|
169
|
+
|
|
170
|
+
Supported filter operators:
|
|
171
|
+
|
|
172
|
+
- `$and`: Logical AND
|
|
173
|
+
- `$eq`: Equal to
|
|
174
|
+
- `$gt`: Greater than
|
|
175
|
+
- `$gte`: Greater than or equal
|
|
176
|
+
- `$in`: In array
|
|
177
|
+
- `$lt`: Less than
|
|
178
|
+
- `$lte`: Less than or equal
|
|
179
|
+
- `$ne`: Not equal to
|
|
180
|
+
- `$nin`: Not in array
|
|
181
|
+
- `$or`: Logical OR
|
|
182
|
+
|
|
183
|
+
The following example demonstrates metadata filters for common use cases:
|
|
184
|
+
|
|
185
|
+
```typescript
|
|
186
|
+
// Filter by project
|
|
187
|
+
const options = {
|
|
188
|
+
semanticRecall: { filter: { projectId: { $eq: 'my-project' } } },
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// Filter by multiple categories
|
|
192
|
+
const options = {
|
|
193
|
+
semanticRecall: { filter: { category: { $in: ['work', 'research'] } } },
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Filter by project and priority
|
|
197
|
+
const options = {
|
|
198
|
+
semanticRecall: {
|
|
199
|
+
filter: {
|
|
200
|
+
$and: [{ projectId: { $eq: 'project-a' } }, { priority: { $gte: 3 } }],
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
}
|
|
124
204
|
```
|
|
125
205
|
|
|
126
206
|
## Embedder configuration
|
|
127
207
|
|
|
128
208
|
Semantic recall relies on an [embedding model](https://mastra.ai/reference/memory/memory-class) to convert messages into embeddings. Mastra supports embedding models through the model router using `provider/model` strings, or you can use any [embedding model](https://sdk.vercel.ai/docs/ai-sdk-core/embeddings) compatible with the AI SDK.
|
|
129
209
|
|
|
130
|
-
|
|
210
|
+
### Using the Model Router (Recommended)
|
|
131
211
|
|
|
132
212
|
The simplest way is to use a `provider/model` string with autocomplete support:
|
|
133
213
|
|
|
134
214
|
```ts
|
|
135
|
-
import { Memory } from
|
|
136
|
-
import { Agent } from
|
|
137
|
-
import { ModelRouterEmbeddingModel } from
|
|
215
|
+
import { Memory } from '@mastra/memory'
|
|
216
|
+
import { Agent } from '@mastra/core/agent'
|
|
217
|
+
import { ModelRouterEmbeddingModel } from '@mastra/core/llm'
|
|
138
218
|
|
|
139
219
|
const agent = new Agent({
|
|
140
220
|
memory: new Memory({
|
|
141
|
-
embedder: new ModelRouterEmbeddingModel(
|
|
221
|
+
embedder: new ModelRouterEmbeddingModel('openai/text-embedding-3-small'),
|
|
222
|
+
options: {
|
|
223
|
+
semanticRecall: true,
|
|
224
|
+
},
|
|
142
225
|
}),
|
|
143
|
-
})
|
|
226
|
+
})
|
|
144
227
|
```
|
|
145
228
|
|
|
146
229
|
Supported embedding models:
|
|
147
230
|
|
|
148
231
|
- **OpenAI**: `text-embedding-3-small`, `text-embedding-3-large`, `text-embedding-ada-002`
|
|
149
232
|
- **Google**: `gemini-embedding-001`
|
|
233
|
+
- **OpenRouter**: Access embedding models from various providers
|
|
150
234
|
|
|
151
|
-
|
|
235
|
+
```ts
|
|
236
|
+
import { Agent } from '@mastra/core/agent'
|
|
237
|
+
import { Memory } from '@mastra/memory'
|
|
238
|
+
import { ModelRouterEmbeddingModel } from '@mastra/core/llm'
|
|
152
239
|
|
|
153
|
-
|
|
240
|
+
const agent = new Agent({
|
|
241
|
+
memory: new Memory({
|
|
242
|
+
embedder: new ModelRouterEmbeddingModel({
|
|
243
|
+
providerId: 'openrouter',
|
|
244
|
+
modelId: 'openai/text-embedding-3-small',
|
|
245
|
+
}),
|
|
246
|
+
}),
|
|
247
|
+
})
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
The model router automatically handles API key detection from environment variables (`OPENAI_API_KEY`, `GOOGLE_GENERATIVE_AI_API_KEY`, `OPENROUTER_API_KEY`).
|
|
251
|
+
|
|
252
|
+
### Using AI SDK Packages
|
|
154
253
|
|
|
155
254
|
You can also use AI SDK embedding models directly:
|
|
156
255
|
|
|
157
256
|
```ts
|
|
158
|
-
import { Memory } from
|
|
159
|
-
import { Agent } from
|
|
160
|
-
import { ModelRouterEmbeddingModel } from
|
|
257
|
+
import { Memory } from '@mastra/memory'
|
|
258
|
+
import { Agent } from '@mastra/core/agent'
|
|
259
|
+
import { ModelRouterEmbeddingModel } from '@mastra/core/llm'
|
|
161
260
|
|
|
162
261
|
const agent = new Agent({
|
|
163
262
|
memory: new Memory({
|
|
164
|
-
embedder: new ModelRouterEmbeddingModel(
|
|
263
|
+
embedder: new ModelRouterEmbeddingModel('openai/text-embedding-3-small'),
|
|
165
264
|
}),
|
|
166
|
-
})
|
|
265
|
+
})
|
|
167
266
|
```
|
|
168
267
|
|
|
169
|
-
|
|
268
|
+
### Using FastEmbed (local)
|
|
170
269
|
|
|
171
270
|
To use FastEmbed (a local embedding model), install `@mastra/fastembed`:
|
|
172
271
|
|
|
@@ -197,26 +296,26 @@ bun add @mastra/fastembed@latest
|
|
|
197
296
|
Then configure it in your memory:
|
|
198
297
|
|
|
199
298
|
```ts
|
|
200
|
-
import { Memory } from
|
|
201
|
-
import { Agent } from
|
|
202
|
-
import { fastembed } from
|
|
299
|
+
import { Memory } from '@mastra/memory'
|
|
300
|
+
import { Agent } from '@mastra/core/agent'
|
|
301
|
+
import { fastembed } from '@mastra/fastembed'
|
|
203
302
|
|
|
204
303
|
const agent = new Agent({
|
|
205
304
|
memory: new Memory({
|
|
206
305
|
embedder: fastembed,
|
|
207
306
|
}),
|
|
208
|
-
})
|
|
307
|
+
})
|
|
209
308
|
```
|
|
210
309
|
|
|
211
|
-
## PostgreSQL
|
|
310
|
+
## PostgreSQL index optimization
|
|
212
311
|
|
|
213
312
|
When using PostgreSQL as your vector store, you can optimize semantic recall performance by configuring the vector index. This is particularly important for large-scale deployments with thousands of messages.
|
|
214
313
|
|
|
215
314
|
PostgreSQL supports both IVFFlat and HNSW indexes. By default, Mastra creates an IVFFlat index, but HNSW indexes typically provide better performance, especially with OpenAI embeddings which use inner product distance.
|
|
216
315
|
|
|
217
316
|
```typescript
|
|
218
|
-
import { Memory } from
|
|
219
|
-
import { PgStore, PgVector } from
|
|
317
|
+
import { Memory } from '@mastra/memory'
|
|
318
|
+
import { PgStore, PgVector } from '@mastra/pg'
|
|
220
319
|
|
|
221
320
|
const agent = new Agent({
|
|
222
321
|
memory: new Memory({
|
|
@@ -233,40 +332,28 @@ const agent = new Agent({
|
|
|
233
332
|
topK: 5,
|
|
234
333
|
messageRange: 2,
|
|
235
334
|
indexConfig: {
|
|
236
|
-
type:
|
|
237
|
-
metric:
|
|
335
|
+
type: 'hnsw', // Use HNSW for better performance
|
|
336
|
+
metric: 'dotproduct', // Best for OpenAI embeddings
|
|
238
337
|
m: 16, // Number of bi-directional links (default: 16)
|
|
239
338
|
efConstruction: 64, // Size of candidate list during construction (default: 64)
|
|
240
339
|
},
|
|
241
340
|
},
|
|
242
341
|
},
|
|
243
342
|
}),
|
|
244
|
-
})
|
|
343
|
+
})
|
|
245
344
|
```
|
|
246
345
|
|
|
247
346
|
For detailed information about index configuration options and performance tuning, see the [PgVector configuration guide](https://mastra.ai/reference/vectors/pg).
|
|
248
347
|
|
|
249
|
-
##
|
|
348
|
+
## Disable semantic recall
|
|
250
349
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
Semantic recall is enabled by default but can be disabled when not needed:
|
|
254
|
-
|
|
255
|
-
```typescript
|
|
256
|
-
const agent = new Agent({
|
|
257
|
-
memory: new Memory({
|
|
258
|
-
options: {
|
|
259
|
-
semanticRecall: false,
|
|
260
|
-
},
|
|
261
|
-
}),
|
|
262
|
-
});
|
|
263
|
-
```
|
|
350
|
+
Semantic recall is disabled by default (`semanticRecall: false`). Each call adds latency because new messages are converted into embeddings and used to query a vector database before the LLM receives them.
|
|
264
351
|
|
|
265
|
-
|
|
352
|
+
Keep semantic recall disabled when:
|
|
266
353
|
|
|
267
|
-
-
|
|
268
|
-
-
|
|
354
|
+
- Message history provides sufficient context for the current conversation.
|
|
355
|
+
- You're building performance-sensitive applications, like realtime two-way audio, where embedding and vector query latency is noticeable.
|
|
269
356
|
|
|
270
|
-
## Viewing
|
|
357
|
+
## Viewing recalled messages
|
|
271
358
|
|
|
272
359
|
When tracing is enabled, any messages retrieved via semantic recall will appear in the agent's trace output, alongside recent message history (if configured).
|