@mastra/pg 1.21.1 → 1.22.0-alpha.3

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 (32) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/dist/docs/SKILL.md +1 -1
  3. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  4. package/dist/docs/references/docs-deployment-workers.md +2 -2
  5. package/dist/docs/references/docs-storage.md +1 -0
  6. package/dist/docs/references/integrations-databases-postgresql.md +2 -0
  7. package/dist/docs/references/reference-rag-vector-databases.md +4 -4
  8. package/dist/docs/references/reference-vectors-pg.md +2 -0
  9. package/dist/index.cjs +398 -107
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.js +398 -107
  12. package/dist/index.js.map +1 -1
  13. package/dist/storage/db/sanitize-json.d.ts +11 -0
  14. package/dist/storage/db/sanitize-json.d.ts.map +1 -0
  15. package/dist/storage/domains/observability/v-next/ddl.d.ts +17 -0
  16. package/dist/storage/domains/observability/v-next/ddl.d.ts.map +1 -1
  17. package/dist/storage/domains/observability/v-next/helpers.d.ts.map +1 -1
  18. package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
  19. package/dist/storage/domains/observability/v-next/scores.d.ts.map +1 -1
  20. package/dist/storage/domains/observability/v-next/signal-schema.d.ts +5 -1
  21. package/dist/storage/domains/observability/v-next/signal-schema.d.ts.map +1 -1
  22. package/dist/storage/domains/observability/v-next/sql.d.ts +29 -4
  23. package/dist/storage/domains/observability/v-next/sql.d.ts.map +1 -1
  24. package/dist/storage/domains/observability/v-next/traces.d.ts.map +1 -1
  25. package/dist/storage/domains/observability/v-next/tracing.d.ts +4 -3
  26. package/dist/storage/domains/observability/v-next/tracing.d.ts.map +1 -1
  27. package/dist/storage/domains/workflows/index.d.ts +2 -10
  28. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  29. package/dist/storage/factory-storage.d.ts.map +1 -1
  30. package/dist/vector/index.d.ts +60 -5
  31. package/dist/vector/index.d.ts.map +1 -1
  32. package/package.json +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,113 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 1.22.0-alpha.3
4
+
5
+ ### Minor Changes
6
+
7
+ - Added namespace isolation to PgVector operations so applications can safely reuse vector indexes across tenants. Existing vectors remain available in the default namespace. ([#22149](https://github.com/mastra-ai/mastra/pull/22149))
8
+
9
+ ```ts
10
+ await pgVector.upsert({
11
+ indexName: 'documents',
12
+ vectors,
13
+ ids,
14
+ namespace: 'tenant-123',
15
+ });
16
+
17
+ const results = await pgVector.query({
18
+ indexName: 'documents',
19
+ queryVector,
20
+ namespace: 'tenant-123',
21
+ });
22
+ ```
23
+
24
+ ### Patch Changes
25
+
26
+ - Fixed `PgVector` scanning every vector table on startup. Constructing a `PgVector` warms an index cache in the background, and that warmup asked for full index statistics, which include `SELECT COUNT(*)` per table. On a large index that is a full table scan per index, per process start, and the warmup never used the count it paid for. `query()`, `upsert()`, `updateVector()` and the "has this index changed?" check in `createIndex()` paid for the same count. ([#22180](https://github.com/mastra-ai/mastra/pull/22180))
27
+
28
+ These paths now read only the index metadata they use (dimension, metric, index type, vector type, index configuration), all of which comes from the Postgres catalog at a cost that does not grow with the size of the table.
29
+
30
+ `describeIndex()` is unchanged and still returns an exact `count`:
31
+
32
+ ```ts
33
+ const stats = await pgVector.describeIndex({ indexName: 'embeddings' });
34
+ console.log(stats.count); // exact row count, as before
35
+ ```
36
+
37
+ Concurrent callers on a cold cache also no longer duplicate the lookup: the first call is shared with everyone waiting on it, and a failed lookup is not cached.
38
+
39
+ Fixes [#21952](https://github.com/mastra-ai/mastra/issues/21952).
40
+
41
+ - Updated dependencies [[`c8e4cea`](https://github.com/mastra-ai/mastra/commit/c8e4ceac9a390d78c8327dff3cdb2861dd71957f), [`ed01e9a`](https://github.com/mastra-ai/mastra/commit/ed01e9a807514a904374bf687a7b8f18750f6f78), [`4e9a228`](https://github.com/mastra-ai/mastra/commit/4e9a2283d5fd6ed1b70a2751eb3dc2cbf82ada20), [`63041eb`](https://github.com/mastra-ai/mastra/commit/63041eb4c50b520a0a80e03d4cd6ea99f67715a0)]:
42
+ - @mastra/core@1.62.0-alpha.6
43
+
44
+ ## 1.22.0-alpha.2
45
+
46
+ ### Minor Changes
47
+
48
+ - **In-progress traces now appear in Studio with `PostgresStoreVNext`** ([#22137](https://github.com/mastra-ai/mastra/pull/22137))
49
+
50
+ `PostgresStoreVNext` previously persisted a span only after it finished, so a long agent run stayed invisible until it completed. It now uses the `event-sourced` tracing strategy: one row is written when a span starts and another when it ends, and reads collapse those rows back into a single span. Traces show up in Studio while the run is executing, and filtering by `running` status works.
51
+
52
+ This also fixes duplicate traces from durable runs. A run that suspends and resumes opens a second root span on the same trace, which used to render as two separate entries; the trace list now shows the current root only.
53
+
54
+ Writes stay append-only, so throughput is unchanged. The span table gains an `isPending` column, added automatically on `init()` — no manual migration needed. Closes #22054.
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies [[`79f04a7`](https://github.com/mastra-ai/mastra/commit/79f04a7f6c6829da541139f638f2f1d267916e08), [`fd4d5fe`](https://github.com/mastra-ai/mastra/commit/fd4d5fe4f943699b85db5e74404f190d5a6b8c2a), [`f591643`](https://github.com/mastra-ai/mastra/commit/f591643becdf0be9bddce6ba1748e64bc30d77f1), [`b1ad324`](https://github.com/mastra-ai/mastra/commit/b1ad324d657f3544b0701332aef7eb10e9a36258), [`61c566d`](https://github.com/mastra-ai/mastra/commit/61c566dd2f2cde2b23ed8f139924e530d4202214)]:
59
+ - @mastra/core@1.62.0-alpha.4
60
+
61
+ ## 1.22.0-alpha.1
62
+
63
+ ### Minor Changes
64
+
65
+ - Added native application collection counts so totals no longer load matching rows. ([#22021](https://github.com/mastra-ai/mastra/pull/22021))
66
+
67
+ **Before**
68
+
69
+ ```ts
70
+ const total = (await storage.ops.findMany('jobs', { status: 'failed' })).length;
71
+ ```
72
+
73
+ **After**
74
+
75
+ ```ts
76
+ const total = await storage.ops.count?.('jobs', { status: 'failed' });
77
+ ```
78
+
79
+ ### Patch Changes
80
+
81
+ - Workflow snapshot upserts no longer overwrite a previously stored `resourceId` with NULL when a run is re-persisted without one (for example during resume). ([#22105](https://github.com/mastra-ai/mastra/pull/22105))
82
+
83
+ - Fix PostgreSQL observability writes failing on NUL characters and unpaired Unicode surrogates ([#21728](https://github.com/mastra-ai/mastra/pull/21728))
84
+
85
+ Span serialization truncated strings by UTF-16 code unit, so a cut inside an emoji left a lone surrogate that PostgreSQL rejected on the jsonb cast (`22P02`). NUL characters were rejected as well (`22P05`). Because observability events are inserted as a single multi-row statement, one malformed field discarded the entire batch.
86
+
87
+ Truncation now preserves complete surrogate pairs, and the v-next PostgreSQL observability encoder sanitizes NUL and unpaired surrogates before the jsonb cast, using the same sanitizer that workflow snapshots already rely on. Valid Unicode, including complete emoji, is preserved.
88
+
89
+ - Updated dependencies [[`2c85f42`](https://github.com/mastra-ai/mastra/commit/2c85f428e04ccd63ea31a7ec80b5b327afdad555), [`11bbeb9`](https://github.com/mastra-ai/mastra/commit/11bbeb9b108ef2264e05acefc6dafb9cbb342921), [`1a485f3`](https://github.com/mastra-ai/mastra/commit/1a485f3538f5ec64d58bd8b5e1e99de0c695c87b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`8661d7d`](https://github.com/mastra-ai/mastra/commit/8661d7d7179f0a024456aabdd8679bcecd09ac28), [`575e343`](https://github.com/mastra-ai/mastra/commit/575e343900451021d96110916497d334af7bc252), [`cacb839`](https://github.com/mastra-ai/mastra/commit/cacb8392d9e74189b56d857290b0615f98a2683d), [`b47b26e`](https://github.com/mastra-ai/mastra/commit/b47b26e6fe95cb8a3482be2c5e52de157fe59d0b), [`0d37487`](https://github.com/mastra-ai/mastra/commit/0d37487d9f349388a3f1cef6a536cf9dcc4b6273), [`c46eb09`](https://github.com/mastra-ai/mastra/commit/c46eb09ce4987509af57a0ac582c61241a6dd2f1), [`30ed33e`](https://github.com/mastra-ai/mastra/commit/30ed33ee14084a26019aba15fceadda6d6ddefaf), [`91ad69d`](https://github.com/mastra-ai/mastra/commit/91ad69d64994c89199b0c55399e64ed91c61df2f), [`8dc408d`](https://github.com/mastra-ai/mastra/commit/8dc408d34438f9e13297f792c11a5cfd6cf952e1), [`c92def1`](https://github.com/mastra-ai/mastra/commit/c92def10a13c822972c96f0a4ca6ffc1f4258aed), [`c5eaec5`](https://github.com/mastra-ai/mastra/commit/c5eaec5a860d80d0e3805e67db0414b87ac8cbed), [`e66b2ba`](https://github.com/mastra-ai/mastra/commit/e66b2ba100db63eaeab6e21e1ea34b113f2ec781)]:
90
+ - @mastra/core@1.62.0-alpha.3
91
+
92
+ ## 1.22.0-alpha.0
93
+
94
+ ### Minor Changes
95
+
96
+ - Added support for filtering scores by metadata key-value pairs in listScores. ([#22047](https://github.com/mastra-ai/mastra/pull/22047))
97
+
98
+ ```typescript
99
+ const result = await storage.listScores({
100
+ filters: { metadata: { env: 'prod' } },
101
+ });
102
+ ```
103
+
104
+ Each top-level metadata key is matched with exact equality against the stored value. Nested objects and arrays compare structurally (key order doesn't matter) with no partial/subset matching, and an empty metadata filter is a no-op.
105
+
106
+ ### Patch Changes
107
+
108
+ - Updated dependencies [[`e737014`](https://github.com/mastra-ai/mastra/commit/e737014e0fc7035759762bb5b48baef1d6c0f6a7), [`d6ce34a`](https://github.com/mastra-ai/mastra/commit/d6ce34aeceb06ddf3d595a1eed5cc74f481a46a1), [`e6f8450`](https://github.com/mastra-ai/mastra/commit/e6f845074d478527026b18d85031b23353e1d0a4)]:
109
+ - @mastra/core@1.62.0-alpha.2
110
+
3
111
  ## 1.21.1
4
112
 
5
113
  ### Patch Changes
@@ -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.21.1"
6
+ version: "1.22.0-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.21.1",
2
+ "version": "1.22.0-alpha.3",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -29,7 +29,7 @@ Subscribes to workflow events on the [PubSub](https://mastra.ai/docs/server/pubs
29
29
 
30
30
  In a split deployment, the orchestration worker pulls events from a distributed PubSub backend and delegates step execution back to the API over HTTP. In-process, it runs steps directly.
31
31
 
32
- The orchestration worker requires a PubSub backend that supports pull mode (e.g., [`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams) or [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub)).
32
+ The orchestration worker requires a PubSub backend that supports pull mode (e.g., [`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams), [`ValkeyStreamsPubSub`](https://mastra.ai/reference/pubsub/valkey-streams), or [`GoogleCloudPubSub`](https://mastra.ai/reference/pubsub/google-cloud-pubsub)).
33
33
 
34
34
  ### Scheduler worker
35
35
 
@@ -104,7 +104,7 @@ Any [supported storage backend](https://mastra.ai/reference/workers/overview) wo
104
104
 
105
105
  Run the same build artifact in multiple containers, each with a different [`MASTRA_WORKERS`](https://mastra.ai/reference/workers/overview) value to control which worker starts in each process.
106
106
 
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.
107
+ Split deployments require a distributed PubSub backend ([`RedisStreamsPubSub`](https://mastra.ai/reference/pubsub/redis-streams), [`ValkeyStreamsPubSub`](https://mastra.ai/reference/pubsub/valkey-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
110
 
@@ -207,6 +207,7 @@ Each provider page includes installation instructions, configuration parameters,
207
207
  - [OracleDB](https://mastra.ai/integrations/databases/oracledb)
208
208
  - [PostgreSQL](https://mastra.ai/integrations/databases/postgresql)
209
209
  - [Redis](https://mastra.ai/integrations/databases/redis)
210
+ - [Valkey](https://mastra.ai/integrations/databases/valkey)
210
211
  - [Upstash](https://mastra.ai/integrations/databases/upstash)
211
212
 
212
213
  ## Next steps
@@ -146,6 +146,8 @@ PostgreSQL supports observability and can handle low trace volumes. Throughput c
146
146
  - Setting up table partitioning for efficient data retention
147
147
  - Migrating observability to [ClickHouse via composite storage](https://mastra.ai/reference/storage/composite) if you need to scale further
148
148
 
149
+ `PostgresStoreVNext` uses the `event-sourced` [tracing strategy](https://mastra.ai/docs/observability/integrations/exporters/mastra-storage) instead. It writes one row when a span starts and another when it ends, never updating a row in place, and collapses those rows when a trace is read. Writes stay append-only, and traces appear in Studio while the run is still executing.
150
+
149
151
  ### Initialization
150
152
 
151
153
  When you pass storage to the Mastra class, `init()` is called automatically before any storage operation:
@@ -27,9 +27,9 @@ await store.upsert({
27
27
  })
28
28
  ```
29
29
 
30
- ### Using MongoDB Atlas Vector Search
30
+ ### Using MongoDB Vector Search
31
31
 
32
- For detailed setup instructions and best practices, see the [official MongoDB Atlas Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/?utm_campaign=devrel\&utm_source=third-party-content\&utm_medium=cta\&utm_content=mastra-docs).
32
+ MongoDB Vector Search is a good solution for teams who want to consolidate vector search, full-text search, and operational data in a single database to minimize infrastructure complexity and maintain production-grade performance. For detailed setup instructions and best practices, see the [official MongoDB Vector Search documentation](https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-overview/?utm_campaign=devrel\&utm_source=third-party-content\&utm_medium=cta\&utm_content=mastra-docs).
33
33
 
34
34
  ### Using VoyageAI with MongoDB
35
35
 
@@ -37,7 +37,7 @@ MongoDB works seamlessly with VoyageAI's embedding models, which are optimized f
37
37
 
38
38
  ### Hybrid Search (Vector + Full-Text)
39
39
 
40
- MongoDB supports hybrid search that fuses vector similarity with BM25 full-text search using server-side `$rankFusion` (requires MongoDB >= 8.0; generally available from 8.1, and enabled on Atlas 8.0.x). This is useful when you want to combine semantic and keyword-based retrieval:
40
+ MongoDB supports hybrid search that fuses vector similarity with BM25 full-text search using server-side `$rankFusion` (requires MongoDB >= 8.0; generally available from 8.1, and enabled on MongoDB Atlas 8.0.x). This is useful when you want to combine semantic and keyword-based retrieval:
41
41
 
42
42
  ```ts
43
43
  await store.createSearchIndex({ indexName: 'myCollection', fields: ['text'] })
@@ -420,7 +420,7 @@ Each vector database enforces specific naming conventions for indexes and collec
420
420
 
421
421
  **MongoDB**:
422
422
 
423
- Collection (index) names must:
423
+ Collection and index names must:
424
424
 
425
425
  - Start with a letter or underscore
426
426
  - Be up to 120 bytes long
@@ -173,6 +173,8 @@ interface PGIndexStats {
173
173
  }
174
174
  ```
175
175
 
176
+ `count` is an exact `SELECT COUNT(*)`, which scans the whole table, so avoid calling `describeIndex()` on a hot path for a large index. Reads and writes never pay for it: they only use the index metadata, which comes from the Postgres catalog.
177
+
176
178
  ### `deleteIndex()`
177
179
 
178
180
  **indexName** (`string`): Name of the index to delete