@mastra/pg 1.35.0 → 1.36.0-alpha.1

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 (30) hide show
  1. package/dist/docs/SKILL.md +2 -13
  2. package/dist/docs/assets/SOURCE_MAP.json +158 -2
  3. package/dist/docs/references/integrations-databases-neon.md +37 -1
  4. package/dist/docs/references/integrations-databases-postgresql.md +46 -0
  5. package/dist/docs/references/reference-processors-message-history-processor.md +1 -1
  6. package/dist/docs/references/reference-processors-semantic-recall-processor.md +1 -1
  7. package/dist/docs/references/reference-tools-vector-query-tool.md +3 -3
  8. package/dist/index.cjs +797 -64
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.js +798 -65
  11. package/dist/index.js.map +1 -1
  12. package/dist/storage/db/index.d.ts +3 -3
  13. package/dist/storage/db/index.d.ts.map +1 -1
  14. package/dist/storage/domains/observability/v-next/feedback.d.ts +1 -0
  15. package/dist/storage/domains/observability/v-next/feedback.d.ts.map +1 -1
  16. package/dist/storage/domains/observability/v-next/index.d.ts +1 -0
  17. package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
  18. package/dist/storage/domains/workflows/index.d.ts +87 -7
  19. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  20. package/dist/storage/retention.d.ts +3 -1
  21. package/dist/storage/retention.d.ts.map +1 -1
  22. package/package.json +3 -3
  23. package/dist/docs/references/docs-deployment-workers.md +0 -404
  24. package/dist/docs/references/docs-memory-semantic-recall.md +0 -485
  25. package/dist/docs/references/docs-memory-working-memory.md +0 -450
  26. package/dist/docs/references/docs-storage.md +0 -224
  27. package/dist/docs/references/reference-rag-retrieval.md +0 -672
  28. package/dist/docs/references/reference-rag-vector-databases.md +0 -808
  29. package/dist/docs/references/reference-storage-composite.md +0 -433
  30. package/dist/docs/references/reference-storage-retention.md +0 -310
@@ -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.35.0"
6
+ version: "1.36.0-alpha.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -14,18 +14,11 @@ Use this skill whenever you are working with @mastra/pg to obtain the domain-spe
14
14
 
15
15
  Read the individual reference documents for detailed explanations and code examples.
16
16
 
17
- ### Docs
18
-
19
- - [Workers](references/docs-deployment-workers.md) - Run Mastra workflow orchestration, schedules, and long-running background tasks in dedicated workers to keep API processes responsive under load.
20
- - [Semantic recall](references/docs-memory-semantic-recall.md) - Retrieve relevant messages from past Mastra conversations with semantic recall, vector search, embeddings, metadata filters, and configurable storage.
21
- - [Working memory](references/docs-memory-working-memory.md) - Persist user profiles, preferences, and application data with Mastra working memory using resource- or thread-scoped templates and storage adapters.
22
- - [Storage](references/docs-storage.md) - Configure Mastra storage to persist memory, workflow state, observability data, evals, schedules, and long-running agent state across restarts.
23
-
24
17
  ### Integrations
25
18
 
26
19
  - [ClickHouse Managed Postgres](references/integrations-databases-clickhouse-managed-postgres.md) - Store Mastra application data in ClickHouse Managed Postgres with PostgresStore and verified TLS.
27
20
  - [DynamoDB](references/integrations-databases-dynamodb.md) - Persist Mastra data in Amazon DynamoDB with a single-table ElectroDB design, configurable indexes, TTL support, credentials, and table initialization.
28
- - [Neon Postgres](references/integrations-databases-neon.md) - Connect Mastra to Neon Postgres with PostgresStore, pooled production connections, schema initialization, vector search, and Neon agent skills.
21
+ - [Neon Postgres](references/integrations-databases-neon.md) - Connect Mastra to Neon Postgres with PostgresStore, pooled production connections, schema initialization, vector search, and Neon agent skills, and give agents Neon tools through Mastra Connect.
29
22
  - [PostgreSQL](references/integrations-databases-postgresql.md) - Persist Mastra application data in PostgreSQL with PostgresStore, configure connections and pools, initialize schemas, and enable observability.
30
23
  - [PG](references/integrations-vectors-pg.md) - Run pgvector similarity search inside PostgreSQL from Mastra with HNSW or IVFFlat indexing, metadata filtering, and direct connection pool access.
31
24
 
@@ -38,10 +31,6 @@ Read the individual reference documents for detailed explanations and code examp
38
31
  - [Chunking and embedding documents](references/reference-rag-chunking-and-embedding.md) - Chunk documents with MDocument, generate embeddings through the AI SDK, and prepare text and metadata for vector storage and RAG retrieval.
39
32
  - [Reference: Metadata filters](references/reference-rag-metadata-filters.md) - Mastra provides a unified metadata filtering syntax across all vector stores, based on MongoDB/Sift query syntax.
40
33
  - [RAG (Retrieval-Augmented Generation) in Mastra](references/reference-rag-overview.md) - RAG in Mastra helps you enhance LLM outputs by incorporating relevant context from your own data sources, improving accuracy and grounding responses in real information.
41
- - [Retrieval, semantic search, reranking](references/reference-rag-retrieval.md) - After storing embeddings, you need to retrieve relevant chunks to answer user queries.
42
- - [Storing embeddings in a vector database](references/reference-rag-vector-databases.md) - After generating embeddings, you need to store them in a database that supports vector similarity search.
43
- - [Reference: Composite storage](references/reference-storage-composite.md) - MastraCompositeStore can compose storage domains from different providers. Use it when you need different databases for different purposes.
44
- - [Reference: Storage retention (prune)](references/reference-storage-retention.md) - prune() deletes rows. It caps growth and is safe to run against large tables (batched, bounded, resumable, cancellable).
45
34
  - [Reference: createVectorQueryTool()](references/reference-tools-vector-query-tool.md) - The createVectorQueryTool() function creates a tool for semantic search over vector stores.
46
35
 
47
36
 
@@ -1,6 +1,162 @@
1
1
  {
2
- "version": "1.35.0",
2
+ "version": "1.36.0-alpha.1",
3
3
  "package": "@mastra/pg",
4
- "exports": {},
4
+ "exports": {
5
+ "AgentsPG": {
6
+ "types": "dist/storage/domains/agents/index.d.ts",
7
+ "implementation": "dist/index.js",
8
+ "line": 4366
9
+ },
10
+ "BackgroundTasksPG": {
11
+ "types": "dist/storage/domains/background-tasks/index.d.ts",
12
+ "implementation": "dist/index.js",
13
+ "line": 5297
14
+ },
15
+ "BlobsPG": {
16
+ "types": "dist/storage/domains/blobs/index.d.ts",
17
+ "implementation": "dist/index.js",
18
+ "line": 5688
19
+ },
20
+ "ChannelsPG": {
21
+ "types": "dist/storage/domains/channels/index.d.ts",
22
+ "implementation": "dist/index.js",
23
+ "line": 5790
24
+ },
25
+ "DatasetsPG": {
26
+ "types": "dist/storage/domains/datasets/index.d.ts",
27
+ "implementation": "dist/index.js",
28
+ "line": 6032
29
+ },
30
+ "ExperimentsPG": {
31
+ "types": "dist/storage/domains/experiments/index.d.ts",
32
+ "implementation": "dist/index.js",
33
+ "line": 7289
34
+ },
35
+ "FavoritesPG": {
36
+ "types": "dist/storage/domains/favorites/index.d.ts",
37
+ "implementation": "dist/index.js",
38
+ "line": 8261
39
+ },
40
+ "KnowledgePG": {
41
+ "types": "dist/storage/domains/knowledge/index.d.ts",
42
+ "implementation": "dist/index.js",
43
+ "line": 10139
44
+ },
45
+ "MCPClientsPG": {
46
+ "types": "dist/storage/domains/mcp-clients/index.d.ts",
47
+ "implementation": "dist/index.js",
48
+ "line": 10296
49
+ },
50
+ "MCPServersPG": {
51
+ "types": "dist/storage/domains/mcp-servers/index.d.ts",
52
+ "implementation": "dist/index.js",
53
+ "line": 10865
54
+ },
55
+ "MemoryPG": {
56
+ "types": "dist/storage/domains/memory/index.d.ts",
57
+ "implementation": "dist/index.js",
58
+ "line": 11653
59
+ },
60
+ "NotificationsPG": {
61
+ "types": "dist/storage/domains/notifications/index.d.ts",
62
+ "implementation": "dist/index.js",
63
+ "line": 14464
64
+ },
65
+ "ObservabilityPG": {
66
+ "types": "dist/storage/domains/observability/index.d.ts",
67
+ "implementation": "dist/index.js",
68
+ "line": 14886
69
+ },
70
+ "ObservabilityStoragePostgresVNext": {
71
+ "types": "dist/storage/domains/observability/v-next/index.d.ts",
72
+ "implementation": "dist/index.js",
73
+ "line": 21805
74
+ },
75
+ "PGVECTOR_PROMPT": {
76
+ "types": "dist/vector/prompt.d.ts",
77
+ "implementation": "dist/index.js",
78
+ "line": 28475
79
+ },
80
+ "PgFactoryStorage": {
81
+ "types": "dist/storage/factory-storage.d.ts",
82
+ "implementation": "dist/index.js",
83
+ "line": 27961
84
+ },
85
+ "PgVector": {
86
+ "types": "dist/vector/index.d.ts",
87
+ "implementation": "dist/index.js",
88
+ "line": 593
89
+ },
90
+ "PoolAdapter": {
91
+ "types": "dist/storage/client.d.ts",
92
+ "implementation": "dist/index.js",
93
+ "line": 2069
94
+ },
95
+ "PostgresStore": {
96
+ "types": "dist/storage/index.d.ts",
97
+ "implementation": "dist/index.js",
98
+ "line": 28176
99
+ },
100
+ "PostgresStoreVNext": {
101
+ "types": "dist/storage/index.d.ts",
102
+ "implementation": "dist/index.js",
103
+ "line": 28394
104
+ },
105
+ "PromptBlocksPG": {
106
+ "types": "dist/storage/domains/prompt-blocks/index.d.ts",
107
+ "implementation": "dist/index.js",
108
+ "line": 22250
109
+ },
110
+ "SchedulesPG": {
111
+ "types": "dist/storage/domains/schedules/index.d.ts",
112
+ "implementation": "dist/index.js",
113
+ "line": 22877
114
+ },
115
+ "ScorerDefinitionsPG": {
116
+ "types": "dist/storage/domains/scorer-definitions/index.d.ts",
117
+ "implementation": "dist/index.js",
118
+ "line": 23198
119
+ },
120
+ "ScoresPG": {
121
+ "types": "dist/storage/domains/scores/index.d.ts",
122
+ "implementation": "dist/index.js",
123
+ "line": 23821
124
+ },
125
+ "SkillsPG": {
126
+ "types": "dist/storage/domains/skills/index.d.ts",
127
+ "implementation": "dist/index.js",
128
+ "line": 24264
129
+ },
130
+ "ThreadStatePG": {
131
+ "types": "dist/storage/domains/thread-state/index.d.ts",
132
+ "implementation": "dist/index.js",
133
+ "line": 24955
134
+ },
135
+ "ToolProviderConnectionsPG": {
136
+ "types": "dist/storage/domains/tool-provider-connections/index.d.ts",
137
+ "implementation": "dist/index.js",
138
+ "line": 25129
139
+ },
140
+ "WorkflowDefinitionsPG": {
141
+ "types": "dist/storage/domains/workflow-definitions/index.d.ts",
142
+ "implementation": "dist/index.js",
143
+ "line": 25393
144
+ },
145
+ "WorkflowsPG": {
146
+ "types": "dist/storage/domains/workflows/index.d.ts",
147
+ "implementation": "dist/index.js",
148
+ "line": 25776
149
+ },
150
+ "WorkspacesPG": {
151
+ "types": "dist/storage/domains/workspaces/index.d.ts",
152
+ "implementation": "dist/index.js",
153
+ "line": 27061
154
+ },
155
+ "exportSchemas": {
156
+ "types": "dist/storage/index.d.ts",
157
+ "implementation": "dist/index.js",
158
+ "line": 28143
159
+ }
160
+ },
5
161
  "modules": {}
6
162
  }
@@ -6,6 +6,8 @@
6
6
 
7
7
  [Neon](https://neon.com) is a managed PostgreSQL service. Mastra connects to Neon through [`PostgresStore`](https://mastra.ai/integrations/databases/postgresql), which uses the Node.js `pg` driver. Neon doesn't require a separate Mastra storage package.
8
8
 
9
+ You can also give an agent tools to manage Neon projects and branches, run SQL, and apply schema migrations through [Mastra Connect](#connect).
10
+
9
11
  ## Quickstart
10
12
 
11
13
  Create a Neon project, then copy its [pooled connection string](https://neon.com/docs/connect/connect-from-any-app) into `DATABASE_URL`.
@@ -219,4 +221,38 @@ const vector = new PgVector({
219
221
  })
220
222
  ```
221
223
 
222
- Setting `disableInit: true` prevents the runtime process from creating or changing the extension, tables and indexes.
224
+ Setting `disableInit: true` prevents the runtime process from creating or changing the extension, tables and indexes.
225
+
226
+ ## Connect
227
+
228
+ Before you start, complete the [Connect setup](https://mastra.ai/docs/mastra-platform/connect) to install `@mastra/connect` and configure your platform project.
229
+
230
+ ### Agent tools
231
+
232
+ Give agents tools from Neon's hosted Model Context Protocol (MCP) server to manage projects and branches, run SQL, and plan and apply schema migrations in Neon.
233
+
234
+ Connect an account with the `neon-mcp` provider ID. Run this command from the directory that contains your `.env` file:
235
+
236
+ ```bash
237
+ mastra connect add neon-mcp
238
+ ```
239
+
240
+ Then pass [`tools()`](https://mastra.ai/reference/connect/tools) to the agent and select the provider:
241
+
242
+ ```typescript
243
+ import { Agent } from '@mastra/core/agent'
244
+ import { tools } from '@mastra/connect'
245
+
246
+ export const neonMcpAgent = new Agent({
247
+ id: 'neon-mcp-agent',
248
+ name: 'Neon agent',
249
+ instructions:
250
+ 'You help people manage projects and branches, run SQL, and plan and apply schema migrations in Neon.',
251
+ model: '__GATEWAY_OPENAI_MODEL_LUNA__',
252
+ tools: tools({ providers: ['neon-mcp'] }),
253
+ })
254
+ ```
255
+
256
+ Mastra discovers Neon's tools from its MCP server when the agent runs. The available tools depend on the server and the connected account, not on your `@mastra/connect` version. Tool keys start with `neon-mcp_`.
257
+
258
+ To see which tools Neon provides, read the [Neon MCP server](https://neon.com/docs/ai/neon-mcp-server) documentation. To require approval before a call runs, see [MCP providers](https://mastra.ai/reference/connect/tools) in the `tools()` reference.
@@ -243,6 +243,52 @@ const thread = await memoryStore?.getThreadById({ threadId: '...' })
243
243
 
244
244
  > **Warning:** If `init()` isn't called, tables won't be created and storage operations will fail silently or throw errors.
245
245
 
246
+ ### Managed PostgreSQL and connection poolers
247
+
248
+ `PostgresStore` connects to managed PostgreSQL providers with the connection string they give you. No provider-specific package is required.
249
+
250
+ `init()` runs all schema changes on a single connection, so it works through transaction-mode connection poolers such as PgBouncer. You can use the provider's pooled connection string and let Mastra create the schema on startup.
251
+
252
+ #### Separate schema initialization
253
+
254
+ If the runtime database role can't create tables or indexes, run `init()` once during deployment with a role that can:
255
+
256
+ ```typescript
257
+ import { PostgresStore } from '@mastra/pg'
258
+
259
+ const storage = new PostgresStore({
260
+ id: 'pg-storage-init',
261
+ connectionString: process.env.DATABASE_ADMIN_URL,
262
+ })
263
+
264
+ try {
265
+ await storage.init()
266
+ // Only needed if the application uses Knowledge
267
+ await storage.initKnowledge()
268
+ } finally {
269
+ await storage.close()
270
+ }
271
+ ```
272
+
273
+ The runtime role needs read and write access to the tables this script creates. See [PostgreSQL privileges](https://www.postgresql.org/docs/current/ddl-priv.html).
274
+
275
+ Then set `disableInit: true` on the runtime store so it skips schema creation:
276
+
277
+ ```typescript
278
+ import { Mastra } from '@mastra/core'
279
+ import { PostgresStore } from '@mastra/pg'
280
+
281
+ export const mastra = new Mastra({
282
+ storage: new PostgresStore({
283
+ id: 'pg-storage',
284
+ connectionString: process.env.DATABASE_URL,
285
+ disableInit: true,
286
+ }),
287
+ })
288
+ ```
289
+
290
+ `disableInit: true` also makes explicit `init()` calls a no-op, so leave it off the store in the deployment script.
291
+
246
292
  ### Using an Existing Pool
247
293
 
248
294
  If you already have a `pg.Pool` in your application (e.g., shared with an ORM or for Row Level Security), you can pass it directly to `PostgresStore`:
@@ -33,7 +33,7 @@ const processor = new MessageHistory({
33
33
 
34
34
  **processInput** (`(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; tracingContext?: TracingContext; requestContext?: RequestContext }) => Promise<MessageList | MastraDBMessage[]>`): Fetches historical messages from storage and adds them to the message list
35
35
 
36
- **processOutputResult** (`(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; tracingContext?: TracingContext; requestContext?: RequestContext }) => Promise<MessageList>`): Persists new messages (user input and assistant response) to storage, excluding system messages
36
+ **processOutputResult** (`(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; tracingContext?: TracingContext; requestContext?: RequestContext; result?: OutputResult }) => Promise<MessageList>`): Persists new messages (user input and assistant response) to storage, excluding system messages
37
37
 
38
38
  ## Extended usage example
39
39
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  # SemanticRecall
6
6
 
7
- The `SemanticRecall` is a **hybrid processor** that enables semantic search over conversation history using vector embeddings. On input, it performs semantic search to find relevant historical messages. On output, it creates embeddings for new messages to enable future semantic retrieval.
7
+ The `SemanticRecall` is a **hybrid processor** that enables semantic search over conversation history using vector embeddings. On input, it performs semantic search to find relevant historical messages. On output, it creates embeddings for new messages to enable future semantic retrieval. With a self-embedding vector store and no `embedder`, it sends the message text to the store, which creates the embeddings.
8
8
 
9
9
  ## Usage example
10
10
 
@@ -88,14 +88,14 @@ The tool returns an object with:
88
88
  ```typescript
89
89
  {
90
90
  id: string; // Unique chunk/document identifier
91
- metadata: any; // All metadata fields (document ID, etc.)
92
- vector: number[]; // Embedding vector (if available)
91
+ metadata?: any; // All metadata fields (document ID, etc.)
92
+ vector: number[]; // Embedding vector, or [] when unavailable
93
93
  score: number; // Similarity score for this retrieval
94
94
  document: string; // Full chunk/document text (if available)
95
95
  }
96
96
  ```
97
97
 
98
- `document` is only populated by vector stores whose `query()` returns document content, such as Chroma, Elasticsearch, LanceDB, and MongoDB. For other stores, such as PgVector, it's an empty string. Read the chunk text from `sources[i].metadata.text` (or whichever metadata key you stored it under).
98
+ `document` is only populated by vector stores whose `query()` returns document content, such as Chroma, Elasticsearch, LanceDB, and MongoDB. For other stores, such as PgVector, it's an empty string. Read the chunk text from `sources[i].metadata?.text` (or whichever metadata key you stored it under). `metadata` is `undefined` when the store returns no metadata for a result.
99
99
 
100
100
  ## Default tool description
101
101