@mastra/pg 1.20.0 → 1.20.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/docs/SKILL.md +2 -2
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-deployment-workers.md +251 -5
- package/dist/docs/references/docs-memory-semantic-recall.md +1 -1
- package/dist/docs/references/docs-memory-working-memory.md +2 -2
- package/dist/docs/references/docs-storage-overview.md +7 -6
- package/dist/docs/references/integrations-databases-postgresql.md +10 -9
- package/dist/docs/references/reference-rag-chunking-and-embedding.md +1 -1
- package/dist/docs/references/reference-rag-metadata-filters.md +1 -1
- package/dist/docs/references/reference-storage-retention.md +1 -1
- package/dist/docs/references/reference-tools-vector-query-tool.md +1 -1
- package/dist/docs/references/reference-vectors-pg.md +1 -1
- package/dist/index.cjs +17 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -3
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts +1 -2
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 1.20.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Improved workflow run list performance in `@mastra/pg` when filtering by workflow name. The default index avoids sorting the ordered result query for workflows with large run histories. Paginated requests still use a separate count query. ([#21308](https://github.com/mastra-ai/mastra/pull/21308))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`7e096f0`](https://github.com/mastra-ai/mastra/commit/7e096f02f0dddbf09b85d306458351245ed2f886), [`8f0a332`](https://github.com/mastra-ai/mastra/commit/8f0a3321bf180368d76fe7b36aa1a8f60f00b6de), [`b098de9`](https://github.com/mastra-ai/mastra/commit/b098de9d7cb9f672e0883a5c716465a3a689693d), [`ef6e295`](https://github.com/mastra-ai/mastra/commit/ef6e295b59bc25a5b61b633a89c97bcfce9fb465), [`208e1b3`](https://github.com/mastra-ai/mastra/commit/208e1b39f30f4b386e494394e9d71d96f0f90241), [`c938d34`](https://github.com/mastra-ai/mastra/commit/c938d34739936c8ecbabd67ad6a4a4396f41c4c6), [`1d9a0ea`](https://github.com/mastra-ai/mastra/commit/1d9a0ea4a9901baee6cd56737243bd6d1f631ac0), [`3667679`](https://github.com/mastra-ai/mastra/commit/3667679db057edfb086846d13369fdda4902ad65), [`49696e8`](https://github.com/mastra-ai/mastra/commit/49696e8e42f870674a0a58f5abcd22cc54dd2864), [`512100a`](https://github.com/mastra-ai/mastra/commit/512100a7d8b7e9c920f2590c6b3612f5de0d3cff), [`9ef432b`](https://github.com/mastra-ai/mastra/commit/9ef432b6faa534b57b0d182a610e13dd9a7123ff), [`b9cf308`](https://github.com/mastra-ai/mastra/commit/b9cf30846f97f99ac1906ee8a68f4f2d117b0378)]:
|
|
10
|
+
- @mastra/core@1.60.0-alpha.2
|
|
11
|
+
|
|
3
12
|
## 1.20.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -3,7 +3,7 @@ name: mastra-pg
|
|
|
3
3
|
description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
|
|
4
4
|
metadata:
|
|
5
5
|
package: "@mastra/pg"
|
|
6
|
-
version: "1.20.0"
|
|
6
|
+
version: "1.20.1-alpha.0"
|
|
7
7
|
---
|
|
8
8
|
|
|
9
9
|
## When to use
|
|
@@ -19,7 +19,7 @@ Read the individual reference documents for detailed explanations and code examp
|
|
|
19
19
|
- [Workers](references/docs-deployment-workers.md) - Separate background processing from the API layer by running workflow execution, cron schedules, and background tasks in dedicated worker processes.
|
|
20
20
|
- [Semantic recall](references/docs-memory-semantic-recall.md) - Learn how to use semantic recall in Mastra to retrieve relevant messages from past conversations using vector search and embeddings.
|
|
21
21
|
- [Working memory](references/docs-memory-working-memory.md) - Learn how to configure working memory in Mastra to store persistent user data, preferences.
|
|
22
|
-
- [Storage
|
|
22
|
+
- [Storage](references/docs-storage-overview.md) - Configure storage for Mastra to persist runtime state across agents, workflows, observability, evals, schedules, and memory.
|
|
23
23
|
|
|
24
24
|
### Integrations
|
|
25
25
|
|
|
@@ -106,19 +106,266 @@ Run the same build artifact in multiple containers, each with a different [`MAST
|
|
|
106
106
|
|
|
107
107
|
Split deployments require a distributed PubSub backend ([`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams) or [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub)), a shared [storage backend](https://mastra.ai/reference/workers/overview), and network connectivity between the orchestration worker and the API.
|
|
108
108
|
|
|
109
|
-
|
|
109
|
+
### Select workers
|
|
110
|
+
|
|
111
|
+
Set [`MASTRA_WORKERS`](https://mastra.ai/reference/workers/overview) to control which workers run in each process:
|
|
112
|
+
|
|
113
|
+
| Value | Behavior |
|
|
114
|
+
| ------------------------------- | ------------------------------------------------------------------------------ |
|
|
115
|
+
| `false` | Disable all workers. Use this for the API process in a fully split deployment. |
|
|
116
|
+
| `orchestration` | Start the orchestration worker. |
|
|
117
|
+
| `scheduler` | Start the scheduler worker. |
|
|
118
|
+
| `backgroundTasks` | Start the background task worker. |
|
|
119
|
+
| `orchestration,backgroundTasks` | Start multiple workers from a comma-separated allowlist. |
|
|
120
|
+
|
|
121
|
+
You can also pass a worker name to the CLI. The command sets `MASTRA_WORKERS` in the spawned process:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
mastra worker start orchestration
|
|
125
|
+
```
|
|
110
126
|
|
|
111
127
|
## Network architecture
|
|
112
128
|
|
|
113
|
-
Workers are internal infrastructure. They're not exposed to end users and don't need their own subdomain
|
|
129
|
+
Workers are internal infrastructure. They're not exposed to end users and don't need their own subdomain or public URL, including an inbound HTTP route.
|
|
114
130
|
|
|
115
131
|
In a split deployment:
|
|
116
132
|
|
|
117
|
-
- **The API server is the only public-facing process**: It serves all client HTTP requests
|
|
133
|
+
- **The API server is the only public-facing process**: It serves all client HTTP requests. These requests include REST endpoints and agent interactions, plus workflow triggers and custom routes.
|
|
118
134
|
- **Workers connect outbound only**: They pull events from the distributed PubSub backend and read/write to the shared storage database. They don't accept inbound traffic from clients.
|
|
119
135
|
- **The orchestration worker calls the API internally**: It sends step execution requests to the API over the container network using `MASTRA_STEP_EXECUTION_URL`. This is internal service-to-service communication, not a public endpoint.
|
|
120
136
|
|
|
121
|
-
All three worker types (orchestration, scheduler, background task) sit behind the API on a private network. They share access to the PubSub backend and storage database but never receive traffic directly from clients.
|
|
137
|
+
All three worker types (orchestration, scheduler, background task) sit behind the API on a private network. They share access to the PubSub backend and storage database but never receive traffic directly from clients. HTTP routes for worker-related features run on the API server rather than the worker process. One example is token minting for a voice integration.
|
|
138
|
+
|
|
139
|
+
## Deploy split workers
|
|
140
|
+
|
|
141
|
+
Build the API and worker artifacts:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
mastra build
|
|
145
|
+
mastra worker build --output-dir .mastra/worker
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
`mastra build` creates the API artifact in `.mastra/output/`. [`mastra worker build`](https://mastra.ai/reference/cli/mastra) creates a worker artifact in `.mastra/worker/`. The following Dockerfile accepts either directory:
|
|
149
|
+
|
|
150
|
+
```dockerfile
|
|
151
|
+
FROM node:22-alpine
|
|
152
|
+
|
|
153
|
+
ARG MASTRA_OUTPUT=.mastra/output
|
|
154
|
+
|
|
155
|
+
WORKDIR /app
|
|
156
|
+
|
|
157
|
+
COPY ${MASTRA_OUTPUT}/package.json ${MASTRA_OUTPUT}/.npmrc* ./
|
|
158
|
+
RUN npm install --omit=dev
|
|
159
|
+
|
|
160
|
+
COPY ${MASTRA_OUTPUT}/ .
|
|
161
|
+
|
|
162
|
+
EXPOSE 4111
|
|
163
|
+
CMD ["node", "index.mjs"]
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
See [Deploy a Mastra server](https://mastra.ai/docs/deployment/mastra-server) for more information about the build output.
|
|
167
|
+
|
|
168
|
+
### Docker Compose
|
|
169
|
+
|
|
170
|
+
The following configuration runs PostgreSQL, Redis, the API, and one process for each worker type. Every process uses shared infrastructure, and the worker processes use the worker artifact.
|
|
171
|
+
|
|
172
|
+
```yaml
|
|
173
|
+
x-worker: &worker
|
|
174
|
+
build:
|
|
175
|
+
context: .
|
|
176
|
+
args:
|
|
177
|
+
MASTRA_OUTPUT: .mastra/worker
|
|
178
|
+
|
|
179
|
+
x-mastra-environment: &shared-environment
|
|
180
|
+
DATABASE_URL: postgres://mastra:${POSTGRES_PASSWORD}@postgres:5432/mastra
|
|
181
|
+
REDIS_URL: redis://redis:6379
|
|
182
|
+
|
|
183
|
+
services:
|
|
184
|
+
postgres:
|
|
185
|
+
image: postgres:16-alpine
|
|
186
|
+
environment:
|
|
187
|
+
POSTGRES_USER: mastra
|
|
188
|
+
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
|
|
189
|
+
POSTGRES_DB: mastra
|
|
190
|
+
volumes:
|
|
191
|
+
- pgdata:/var/lib/postgresql/data
|
|
192
|
+
healthcheck:
|
|
193
|
+
test: ['CMD-SHELL', 'pg_isready -U mastra']
|
|
194
|
+
interval: 5s
|
|
195
|
+
timeout: 3s
|
|
196
|
+
retries: 5
|
|
197
|
+
|
|
198
|
+
redis:
|
|
199
|
+
image: redis:7-alpine
|
|
200
|
+
healthcheck:
|
|
201
|
+
test: ['CMD', 'redis-cli', 'ping']
|
|
202
|
+
interval: 5s
|
|
203
|
+
timeout: 3s
|
|
204
|
+
retries: 5
|
|
205
|
+
|
|
206
|
+
api:
|
|
207
|
+
build:
|
|
208
|
+
context: .
|
|
209
|
+
args:
|
|
210
|
+
MASTRA_OUTPUT: .mastra/output
|
|
211
|
+
ports:
|
|
212
|
+
- '4111:4111'
|
|
213
|
+
environment:
|
|
214
|
+
<<: *shared-environment
|
|
215
|
+
WORKER_TOKEN: ${WORKER_TOKEN}
|
|
216
|
+
MASTRA_WORKERS: 'false'
|
|
217
|
+
depends_on:
|
|
218
|
+
postgres:
|
|
219
|
+
condition: service_healthy
|
|
220
|
+
redis:
|
|
221
|
+
condition: service_healthy
|
|
222
|
+
healthcheck:
|
|
223
|
+
test: ['CMD', 'wget', '-qO-', 'http://localhost:4111/api/agents']
|
|
224
|
+
interval: 5s
|
|
225
|
+
timeout: 3s
|
|
226
|
+
retries: 5
|
|
227
|
+
|
|
228
|
+
orchestration-worker:
|
|
229
|
+
<<: *worker
|
|
230
|
+
environment:
|
|
231
|
+
<<: *shared-environment
|
|
232
|
+
MASTRA_WORKERS: orchestration
|
|
233
|
+
MASTRA_STEP_EXECUTION_URL: http://api:4111/api
|
|
234
|
+
MASTRA_WORKER_AUTH_TOKEN: ${WORKER_TOKEN}
|
|
235
|
+
depends_on:
|
|
236
|
+
api:
|
|
237
|
+
condition: service_healthy
|
|
238
|
+
|
|
239
|
+
scheduler-worker:
|
|
240
|
+
<<: *worker
|
|
241
|
+
environment:
|
|
242
|
+
<<: *shared-environment
|
|
243
|
+
MASTRA_WORKERS: scheduler
|
|
244
|
+
depends_on:
|
|
245
|
+
api:
|
|
246
|
+
condition: service_healthy
|
|
247
|
+
|
|
248
|
+
background-task-worker:
|
|
249
|
+
<<: *worker
|
|
250
|
+
environment:
|
|
251
|
+
<<: *shared-environment
|
|
252
|
+
MASTRA_WORKERS: backgroundTasks
|
|
253
|
+
depends_on:
|
|
254
|
+
api:
|
|
255
|
+
condition: service_healthy
|
|
256
|
+
|
|
257
|
+
volumes:
|
|
258
|
+
pgdata:
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Set the secrets next to `docker-compose.yml`, along with any model provider credentials your application needs:
|
|
262
|
+
|
|
263
|
+
```bash
|
|
264
|
+
POSTGRES_PASSWORD=your-secure-password
|
|
265
|
+
WORKER_TOKEN=your-shared-secret-token
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Configure the API auth provider to accept `WORKER_TOKEN` before exposing the deployment. The orchestration worker sends the same value through `MASTRA_WORKER_AUTH_TOKEN`. The scheduler and background task workers don't call the step execution endpoint in this pull-based topology, so they don't need that variable.
|
|
269
|
+
|
|
270
|
+
Start the stack and verify that the containers and API are available:
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
docker compose up -d
|
|
274
|
+
docker compose ps
|
|
275
|
+
curl http://localhost:4111/api/agents
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
### Kubernetes
|
|
279
|
+
|
|
280
|
+
Create separate Deployments for the API, orchestration worker, scheduler worker, and background task worker. Use the same image and Secret for each Deployment. Set only the role-specific environment variables directly on each container.
|
|
281
|
+
|
|
282
|
+
The orchestration worker Deployment has the following shape:
|
|
283
|
+
|
|
284
|
+
```yaml
|
|
285
|
+
apiVersion: apps/v1
|
|
286
|
+
kind: Deployment
|
|
287
|
+
metadata:
|
|
288
|
+
name: orchestration-worker
|
|
289
|
+
spec:
|
|
290
|
+
replicas: 1
|
|
291
|
+
selector:
|
|
292
|
+
matchLabels:
|
|
293
|
+
app: orchestration-worker
|
|
294
|
+
template:
|
|
295
|
+
metadata:
|
|
296
|
+
labels:
|
|
297
|
+
app: orchestration-worker
|
|
298
|
+
spec:
|
|
299
|
+
containers:
|
|
300
|
+
- name: worker
|
|
301
|
+
image: your-registry/mastra-workers:latest
|
|
302
|
+
env:
|
|
303
|
+
- name: MASTRA_WORKERS
|
|
304
|
+
value: orchestration
|
|
305
|
+
- name: MASTRA_STEP_EXECUTION_URL
|
|
306
|
+
value: http://api:4111/api
|
|
307
|
+
envFrom:
|
|
308
|
+
- secretRef:
|
|
309
|
+
name: mastra-secrets
|
|
310
|
+
resources:
|
|
311
|
+
requests:
|
|
312
|
+
cpu: 250m
|
|
313
|
+
memory: 256Mi
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Use `MASTRA_WORKERS: scheduler` and `MASTRA_WORKERS: backgroundTasks` for the other worker Deployments. Set `MASTRA_WORKERS: 'false'` on the API Deployment and expose the API with a Service. Give every process access to the same database and PubSub backend. Configure the API auth provider with a worker token, then expose that token to the orchestration worker as `MASTRA_WORKER_AUTH_TOKEN`. See [Deploy Mastra to Kubernetes](https://mastra.ai/integrations/deploy/kubernetes) for the base Kubernetes resources.
|
|
317
|
+
|
|
318
|
+
Apply the manifests, then verify the pods and API:
|
|
319
|
+
|
|
320
|
+
```bash
|
|
321
|
+
kubectl apply -f k8s/
|
|
322
|
+
kubectl get pods
|
|
323
|
+
kubectl port-forward svc/api 4111:4111
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
In a separate terminal, request an API route:
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
curl http://localhost:4111/api/agents
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Step execution URL
|
|
333
|
+
|
|
334
|
+
In a fully split deployment, the orchestration worker delegates workflow step execution to the API over HTTP. Set `MASTRA_STEP_EXECUTION_URL` to the API's internal URL, including the `/api` prefix:
|
|
335
|
+
|
|
336
|
+
```bash
|
|
337
|
+
MASTRA_STEP_EXECUTION_URL=http://api:4111/api
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
Without this variable, the orchestration worker attempts to execute steps in its own process, which doesn't have access to the full Mastra runtime in a split deployment.
|
|
341
|
+
|
|
342
|
+
The endpoint uses the server's normal auth pipeline. If the API has an auth provider, set `MASTRA_WORKER_AUTH_TOKEN` to a bearer token that provider accepts. Mastra forwards the value as an `Authorization: Bearer` credential. The configured auth provider validates the token. See [Worker authentication](https://mastra.ai/docs/server/auth/workers) for server configuration and other credential formats.
|
|
343
|
+
|
|
344
|
+
### Scale workers
|
|
345
|
+
|
|
346
|
+
The orchestration and background task workers can scale horizontally. PubSub consumer groups distribute events across their instances:
|
|
347
|
+
|
|
348
|
+
```bash
|
|
349
|
+
docker compose up -d --scale orchestration-worker=3
|
|
350
|
+
docker compose up -d --scale background-task-worker=2
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
For Kubernetes, change the Deployment replica count manually or use a HorizontalPodAutoscaler:
|
|
354
|
+
|
|
355
|
+
```bash
|
|
356
|
+
kubectl scale deployment/orchestration-worker --replicas=3
|
|
357
|
+
kubectl scale deployment/background-task-worker --replicas=2
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
Run exactly one scheduler worker. Multiple schedulers polling the same storage can publish duplicate events for a schedule.
|
|
361
|
+
|
|
362
|
+
### Crash recovery
|
|
363
|
+
|
|
364
|
+
A distributed PubSub backend persists unacknowledged events, which lets orchestration and background task workers resume after a restart. When the API is unavailable, a failed step-execution request causes the event to be delivered again. Because an event can be processed more than once, handlers should be idempotent when possible.
|
|
365
|
+
|
|
366
|
+
The scheduler calculates the next fire time from the current time after it restarts. It doesn't replay schedules that elapsed while it was unavailable.
|
|
367
|
+
|
|
368
|
+
If the API crashes while a step is executing, that work can be lost and the workflow run can remain in a `running` state. See [known limitations](#known-limitations) and [durable agent crash recovery](https://mastra.ai/docs/long-running-agents/durable-agents).
|
|
122
369
|
|
|
123
370
|
## Known limitations
|
|
124
371
|
|
|
@@ -129,7 +376,6 @@ All three worker types (orchestration, scheduler, background task) sit behind th
|
|
|
129
376
|
|
|
130
377
|
## Related
|
|
131
378
|
|
|
132
|
-
- [Worker deployment guide](https://mastra.ai/guides/deployment/mastra-workers): Docker Compose and Kubernetes examples
|
|
133
379
|
- [Worker authentication](https://mastra.ai/docs/server/auth/workers): Secure worker-to-API communication
|
|
134
380
|
- [Workers reference](https://mastra.ai/reference/workers/overview): Details about worker environment variables and types, with a list of supported storage backends
|
|
135
381
|
- [CLI reference](https://mastra.ai/reference/cli/mastra): `mastra worker build` and `mastra worker start`
|
|
@@ -270,7 +270,7 @@ Supported embedding models:
|
|
|
270
270
|
|
|
271
271
|
- **OpenAI**: `text-embedding-3-small`, `text-embedding-3-large`, `text-embedding-ada-002`
|
|
272
272
|
- **Google**: `gemini-embedding-001`
|
|
273
|
-
- **OpenRouter**: Access embedding models from
|
|
273
|
+
- **OpenRouter**: Access embedding models from multiple providers
|
|
274
274
|
|
|
275
275
|
```ts
|
|
276
276
|
import { Agent } from '@mastra/core/agent'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
2
|
|
|
3
|
-
# Working
|
|
3
|
+
# Working memory
|
|
4
4
|
|
|
5
5
|
While [message history](https://mastra.ai/docs/memory/message-history) and [semantic recall](https://mastra.ai/docs/memory/semantic-recall) help agents remember conversations, working memory allows them to maintain persistent information about users across interactions.
|
|
6
6
|
|
|
@@ -213,7 +213,7 @@ const paragraphMemory = new Memory({
|
|
|
213
213
|
|
|
214
214
|
## Structured working memory
|
|
215
215
|
|
|
216
|
-
Working memory can also be defined using a structured schema instead of a Markdown template.
|
|
216
|
+
Working memory can also be defined using a structured schema instead of a Markdown template. 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.
|
|
217
217
|
|
|
218
218
|
**Requirement:** You must specify either `template` or `schema`, but not both.
|
|
219
219
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
> Discover all available pages from the documentation index: https://mastra.ai/llms.txt
|
|
2
2
|
|
|
3
|
-
# Storage
|
|
3
|
+
# Storage
|
|
4
4
|
|
|
5
5
|
Storage is the persistence layer for the Mastra runtime. It keeps memory, workflow state, observability data, eval results, schedules, and long-running agent state available after a process restarts.
|
|
6
6
|
|
|
@@ -188,25 +188,26 @@ You can also route `observability` to a dedicated analytics backend. See the [ob
|
|
|
188
188
|
|
|
189
189
|
## Supported providers
|
|
190
190
|
|
|
191
|
-
Each provider page includes installation instructions, configuration parameters, and usage examples
|
|
191
|
+
Each provider page includes installation instructions, configuration parameters, and usage examples. libSQL is the fastest path for local development because it doesn't require running a separate database server.
|
|
192
192
|
|
|
193
|
+
- [Aurora DSQL](https://mastra.ai/integrations/databases/aurora-dsql)
|
|
194
|
+
- [ClickHouse](https://mastra.ai/integrations/databases/clickhouse)
|
|
193
195
|
- [Cloudflare D1](https://mastra.ai/integrations/databases/cloudflare-d1)
|
|
194
|
-
- [Cloudflare KV
|
|
196
|
+
- [Cloudflare KV](https://mastra.ai/integrations/databases/cloudflare-kv)
|
|
195
197
|
- [Convex](https://mastra.ai/integrations/databases/convex)
|
|
198
|
+
- [DuckDB](https://mastra.ai/integrations/databases/duckdb)
|
|
196
199
|
- [DynamoDB](https://mastra.ai/integrations/databases/dynamodb)
|
|
197
200
|
- [Google Cloud Spanner](https://mastra.ai/integrations/databases/spanner)
|
|
198
201
|
- [LanceDB](https://mastra.ai/integrations/databases/lancedb)
|
|
199
202
|
- [libSQL](https://mastra.ai/integrations/databases/libsql)
|
|
200
|
-
- [Microsoft SQL Server](https://mastra.ai/integrations/databases/mssql)
|
|
201
203
|
- [MongoDB](https://mastra.ai/integrations/databases/mongodb)
|
|
204
|
+
- [MSSQL](https://mastra.ai/integrations/databases/mssql)
|
|
202
205
|
- [Neon Postgres](https://mastra.ai/integrations/databases/neon)
|
|
203
206
|
- [OracleDB](https://mastra.ai/integrations/databases/oracledb)
|
|
204
207
|
- [PostgreSQL](https://mastra.ai/integrations/databases/postgresql)
|
|
205
208
|
- [Redis](https://mastra.ai/integrations/databases/redis)
|
|
206
209
|
- [Upstash](https://mastra.ai/integrations/databases/upstash)
|
|
207
210
|
|
|
208
|
-
> **Tip:** libSQL is the fastest path for local development because it doesn't require running a separate database server.
|
|
209
|
-
|
|
210
211
|
## Next steps
|
|
211
212
|
|
|
212
213
|
- [Composite storage](https://mastra.ai/reference/storage/composite)
|
|
@@ -407,8 +407,9 @@ PostgreSQL storage creates composite indexes during initialization for common qu
|
|
|
407
407
|
- `mastra_ai_spans_name_startedat_idx`: (name, startedAt DESC)
|
|
408
408
|
- `mastra_ai_spans_scope_startedat_idx`: (scope, startedAt DESC)
|
|
409
409
|
- `mastra_scores_trace_id_span_id_created_at_idx`: (traceId, spanId, createdAt DESC)
|
|
410
|
+
- `mastra_workflow_snapshot_name_createdat_idx`: (workflow\_name, createdAt DESC)
|
|
410
411
|
|
|
411
|
-
These indexes improve performance for filtered queries with sorting, including `dateRange` filters on message queries.
|
|
412
|
+
These indexes improve performance for filtered queries with sorting, including `dateRange` filters on message queries and Studio's workflow runs-list.
|
|
412
413
|
|
|
413
414
|
### Configuring Indexes
|
|
414
415
|
|
|
@@ -521,11 +522,11 @@ const stats = await storage.db.one(`
|
|
|
521
522
|
|
|
522
523
|
PostgreSQL offers different index types optimized for specific scenarios:
|
|
523
524
|
|
|
524
|
-
| Index Type | Best For | Storage
|
|
525
|
-
| ------------------- | --------------------------------------- |
|
|
526
|
-
| **btree** (default) | Range queries, sorting, general purpose | Moderate
|
|
527
|
-
| **hash** | Equality comparisons only | Small
|
|
528
|
-
| **gin** | JSONB, arrays, full-text search | Large
|
|
529
|
-
| **gist** | Geometric data, full-text search | Moderate
|
|
530
|
-
| **spgist** | Non-balanced data, text patterns | Small
|
|
531
|
-
| **brin** | Large tables with natural ordering | Very small
|
|
525
|
+
| Index Type | Best For | Storage size | Speed |
|
|
526
|
+
| ------------------- | --------------------------------------- | ------------ | -------------------------- |
|
|
527
|
+
| **btree** (default) | Range queries, sorting, general purpose | Moderate | Fast |
|
|
528
|
+
| **hash** | Equality comparisons only | Small | Very fast for `=` |
|
|
529
|
+
| **gin** | JSONB, arrays, full-text search | Large | Fast for contains |
|
|
530
|
+
| **gist** | Geometric data, full-text search | Moderate | Fast for nearest-neighbor |
|
|
531
|
+
| **spgist** | Non-balanced data, text patterns | Small | Fast for specific patterns |
|
|
532
|
+
| **brin** | Large tables with natural ordering | Very small | Fast for ranges |
|
|
@@ -127,7 +127,7 @@ const { embeddings } = await embedMany({
|
|
|
127
127
|
})
|
|
128
128
|
```
|
|
129
129
|
|
|
130
|
-
> **Vector Database Compatibility:** When storing embeddings, the vector database index
|
|
130
|
+
> **Vector Database Compatibility:** When storing embeddings, configure the vector database index to match the output size of your embedding model to avoid errors or data corruption from mismatched dimensions.
|
|
131
131
|
|
|
132
132
|
## Example: Complete pipeline
|
|
133
133
|
|
|
@@ -201,7 +201,7 @@ const results = await store.query({
|
|
|
201
201
|
### Amazon S3 Vectors
|
|
202
202
|
|
|
203
203
|
- Equality values must be primitives (string/number/boolean). `null`/`undefined`, arrays, objects, and Date aren't allowed for equality. Range operators accept numbers or Date (Dates are normalized to epoch ms).
|
|
204
|
-
- `$in`/`$nin` require **non-empty arrays of primitives
|
|
204
|
+
- `$in`/`$nin` require **non-empty arrays of primitives**. Date elements are allowed and normalized to epoch ms. **Array equality** isn't supported.
|
|
205
205
|
- Implicit AND is canonicalized (`{a:1,b:2}` → `{$and:[{a:1},{b:2}]`). Logical operators must contain field conditions and use non-empty arrays. They may appear only at the root or within other logical operators (not inside field values).
|
|
206
206
|
- Keys listed in `nonFilterableMetadataKeys` at index creation are stored but not filterable. This setting is immutable.
|
|
207
207
|
- $exists requires a boolean value.
|
|
@@ -234,7 +234,7 @@ const storage = new MongoDBStore({
|
|
|
234
234
|
|
|
235
235
|
`prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist and are reused by future writes, so the file stops growing: for most users this alone solves the unbounded-growth problem.
|
|
236
236
|
|
|
237
|
-
Handing that free space back to the OS is a separate concern that Mastra doesn't manage. If you specifically need to shrink the file, run the underlying database's compaction (for example `VACUUM` on self-hosted libSQL) yourself in a maintenance window. A full `VACUUM` locks the file and needs roughly twice the file size in free disk. On PostgreSQL, autovacuum reclaims dead tuples for reuse automatically
|
|
237
|
+
Handing that free space back to the OS is a separate concern that Mastra doesn't manage. If you specifically need to shrink the file, run the underlying database's compaction (for example `VACUUM` on self-hosted libSQL) yourself in a maintenance window. A full `VACUUM` locks the file and needs roughly twice the file size in free disk. On PostgreSQL, autovacuum reclaims dead tuples for reuse automatically. A manual `VACUUM FULL` is only needed if you must return disk to the OS.
|
|
238
238
|
|
|
239
239
|
For MongoDB, deleted documents are reused by future insertions. To reclaim disk space, run [`db.runCommand({ compact: "collection_name" })`](https://www.mongodb.com/docs/manual/reference/command/compact/) during a maintenance window.
|
|
240
240
|
|
|
@@ -353,7 +353,7 @@ const response = await agent.generate('Find information about deployment', {
|
|
|
353
353
|
})
|
|
354
354
|
```
|
|
355
355
|
|
|
356
|
-
|
|
356
|
+
Runtime configuration supports these use cases:
|
|
357
357
|
|
|
358
358
|
- Switch between environments (dev/staging/prod)
|
|
359
359
|
- Adjust performance parameters based on load
|
|
@@ -350,7 +350,7 @@ The `PgVector` class exposes its underlying PostgreSQL connection pool as a publ
|
|
|
350
350
|
pgVector.pool // instance of pg.Pool
|
|
351
351
|
```
|
|
352
352
|
|
|
353
|
-
|
|
353
|
+
Direct pool access supports advanced operations such as direct SQL queries, transactions, or pool-state monitoring. When using the pool directly:
|
|
354
354
|
|
|
355
355
|
- You are responsible for releasing clients (`client.release()`) after use.
|
|
356
356
|
- The pool remains accessible after calling `disconnect()`, but new queries will fail.
|
package/dist/index.cjs
CHANGED
|
@@ -19382,33 +19382,47 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
19382
19382
|
updatedAt: new Date(row.updatedAtZ || row.updatedAt)
|
|
19383
19383
|
};
|
|
19384
19384
|
}
|
|
19385
|
+
static getDefaultIndexDefs(schemaPrefix) {
|
|
19386
|
+
return [{
|
|
19387
|
+
name: `${schemaPrefix}mastra_workflow_snapshot_name_createdat_idx`,
|
|
19388
|
+
table: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
19389
|
+
columns: ["workflow_name", "createdAt DESC"]
|
|
19390
|
+
}];
|
|
19391
|
+
}
|
|
19385
19392
|
/**
|
|
19386
19393
|
* Returns all DDL statements for this domain: table with unique constraint.
|
|
19387
19394
|
* Used by exportSchemas to produce a complete, reproducible schema export.
|
|
19388
19395
|
*/
|
|
19389
19396
|
static getExportDDL(schemaName) {
|
|
19390
19397
|
const statements = [];
|
|
19398
|
+
const parsedSchema = schemaName ? (0, _mastra_core_utils.parseSqlIdentifier)(schemaName, "schema name") : "";
|
|
19399
|
+
const schemaPrefix = parsedSchema && parsedSchema !== "public" ? `${parsedSchema}_` : "";
|
|
19391
19400
|
statements.push(generateTableSQL({
|
|
19392
19401
|
tableName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT,
|
|
19393
19402
|
schema: _mastra_core_storage.TABLE_SCHEMAS[_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT],
|
|
19394
19403
|
schemaName,
|
|
19395
19404
|
includeAllConstraints: true
|
|
19396
19405
|
}));
|
|
19406
|
+
for (const idx of WorkflowsPG.getDefaultIndexDefs(schemaPrefix)) statements.push(generateIndexSQL(idx, schemaName));
|
|
19397
19407
|
return statements;
|
|
19398
19408
|
}
|
|
19399
19409
|
/**
|
|
19400
19410
|
* Returns default index definitions for the workflows domain tables.
|
|
19401
|
-
* Currently no default indexes are defined for workflows.
|
|
19402
19411
|
*/
|
|
19403
19412
|
getDefaultIndexDefinitions() {
|
|
19404
|
-
|
|
19413
|
+
const schemaPrefix = this.#schema !== "public" ? `${this.#schema}_` : "";
|
|
19414
|
+
return WorkflowsPG.getDefaultIndexDefs(schemaPrefix);
|
|
19405
19415
|
}
|
|
19406
19416
|
/**
|
|
19407
19417
|
* Creates default indexes for optimal query performance.
|
|
19408
|
-
* Currently no default indexes are defined for workflows.
|
|
19409
19418
|
*/
|
|
19410
19419
|
async createDefaultIndexes() {
|
|
19411
19420
|
if (this.#skipDefaultIndexes) return;
|
|
19421
|
+
for (const indexDef of this.getDefaultIndexDefinitions()) try {
|
|
19422
|
+
await this.#db.createIndex(indexDef);
|
|
19423
|
+
} catch (error) {
|
|
19424
|
+
this.logger?.warn?.(`Failed to create index ${indexDef.name}:`, error);
|
|
19425
|
+
}
|
|
19412
19426
|
}
|
|
19413
19427
|
async init() {
|
|
19414
19428
|
await this.#db.createTable({
|