@mastra/pg 1.31.1-alpha.0 → 1.31.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.
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-deployment-workers.md +1 -1
- package/dist/docs/references/reference-storage-composite.md +34 -0
- package/dist/docs/references/reference-tools-vector-query-tool.md +4 -4
- package/dist/docs/references/reference-vectors-pg.md +16 -11
- package/dist/index.cjs +3 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -19
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/workflows/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/docs/SKILL.md
CHANGED
|
@@ -146,7 +146,7 @@ Workers are internal infrastructure. They're not exposed to end users and don't
|
|
|
146
146
|
In a split deployment:
|
|
147
147
|
|
|
148
148
|
- **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.
|
|
149
|
-
- **Workers
|
|
149
|
+
- **Workers don't serve client traffic**: They pull events from the distributed PubSub backend and read/write to the shared storage database. Each worker process also listens on `PORT` (default `4111`) for internal health checks. `/health` reports readiness and `/config` returns the worker configuration to authorized callers. Keep this port on the private network.
|
|
150
150
|
- **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.
|
|
151
151
|
|
|
152
152
|
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 creating a token for a voice integration.
|
|
@@ -210,6 +210,40 @@ export const mastra = new Mastra({
|
|
|
210
210
|
|
|
211
211
|
**domains.experiments** (`ExperimentsStorage`): Storage for experiment runs and per-item experiment results.
|
|
212
212
|
|
|
213
|
+
**domains.workflowDefinitions** (`WorkflowDefinitionsStorage`): Storage for persisted workflow definitions.
|
|
214
|
+
|
|
215
|
+
**domains.promptBlocks** (`PromptBlocksStorage`): Storage for stored prompt blocks and their versions.
|
|
216
|
+
|
|
217
|
+
**domains.scorerDefinitions** (`ScorerDefinitionsStorage`): Storage for stored scorer definitions and their versions.
|
|
218
|
+
|
|
219
|
+
**domains.mcpClients** (`MCPClientsStorage`): Storage for stored MCP client configurations and their versions.
|
|
220
|
+
|
|
221
|
+
**domains.mcpServers** (`MCPServersStorage`): Storage for stored MCP server configurations and their versions.
|
|
222
|
+
|
|
223
|
+
**domains.workspaces** (`WorkspacesStorage`): Storage for stored workspace configurations and their versions.
|
|
224
|
+
|
|
225
|
+
**domains.skills** (`SkillsStorage`): Storage for stored skill definitions and their versions.
|
|
226
|
+
|
|
227
|
+
**domains.favorites** (`FavoritesStorage`): Storage for user favorites on stored entities.
|
|
228
|
+
|
|
229
|
+
**domains.blobs** (`BlobStore`): Content-addressable storage for file contents used by skill versioning.
|
|
230
|
+
|
|
231
|
+
**domains.backgroundTasks** (`BackgroundTasksStorage`): Storage for background task state.
|
|
232
|
+
|
|
233
|
+
**domains.schedules** (`SchedulesStorage`): Storage for schedules that the scheduler fires.
|
|
234
|
+
|
|
235
|
+
**domains.channels** (`ChannelsStorage`): Storage for channel installations and configuration.
|
|
236
|
+
|
|
237
|
+
**domains.harness** (`HarnessStorage`): Storage for harness sessions.
|
|
238
|
+
|
|
239
|
+
**domains.toolProviderConnections** (`ToolProviderConnectionsStorage`): Storage for authorized tool provider connections.
|
|
240
|
+
|
|
241
|
+
**domains.notifications** (`NotificationsStorage`): Storage for notifications and their delivery state.
|
|
242
|
+
|
|
243
|
+
**domains.threadState** (`ThreadStateStorage`): Storage for per-thread agent state, such as task lists and goals.
|
|
244
|
+
|
|
245
|
+
**domains.knowledge** (`KnowledgeStorage`): Storage for knowledge nodes and records. Experimental.
|
|
246
|
+
|
|
213
247
|
## Initialization
|
|
214
248
|
|
|
215
249
|
`MastraCompositeStore` initializes each configured domain independently. When passed to the Mastra class, `init()` is called automatically:
|
|
@@ -21,13 +21,13 @@ const queryTool = createVectorQueryTool({
|
|
|
21
21
|
|
|
22
22
|
## Parameters
|
|
23
23
|
|
|
24
|
-
> **Note:** **Parameter Requirements:** Most fields can be set at creation as defaults. Some fields can be overridden at runtime via the request context or input. If a required field is missing from both creation and runtime, an error will be thrown. Note that `
|
|
24
|
+
> **Note:** **Parameter Requirements:** Most fields can be set at creation as defaults. Some fields can be overridden at runtime via the request context or input. If a required field is missing from both creation and runtime, an error will be thrown. Note that `id` and `description` can only be set at creation time.
|
|
25
25
|
|
|
26
|
-
**id** (`string`): Custom ID for the tool. By default: 'VectorQuery {vectorStoreName} {indexName} Tool'. (Set at creation only.)
|
|
26
|
+
**id** (`string`): Custom ID for the tool. By default: 'VectorQuery {vectorStoreName} {indexName} Tool', where {vectorStoreName} is 'DirectVectorStore' when a vectorStore instance is passed without a vectorStoreName. (Set at creation only.)
|
|
27
27
|
|
|
28
28
|
**description** (`string`): Custom description for the tool. By default: 'Access the knowledge base to find information needed to answer user questions' (Set at creation only.)
|
|
29
29
|
|
|
30
|
-
**model** (`EmbeddingModel`): Embedding model to use for vector search. (
|
|
30
|
+
**model** (`EmbeddingModel`): Embedding model to use for vector search. (Can be set at creation or overridden at runtime via the request context.)
|
|
31
31
|
|
|
32
32
|
**vectorStoreName** (`string`): Name of the vector store to query. (Can be set at creation or overridden at runtime.)
|
|
33
33
|
|
|
@@ -47,7 +47,7 @@ const queryTool = createVectorQueryTool({
|
|
|
47
47
|
|
|
48
48
|
**reranker.options.weights** (`WeightConfig`): Weights for scoring components (semantic: 0.4, vector: 0.4, position: 0.2)
|
|
49
49
|
|
|
50
|
-
**reranker.options.topK** (`number`): Number of top results to return
|
|
50
|
+
**reranker.options.topK** (`number`): Number of top results to return after reranking. Falls back to the query's topK (from the request context, the tool input, or 10) when unset or 0.
|
|
51
51
|
|
|
52
52
|
**databaseConfig** (`DatabaseConfig`): Database-specific configuration options for optimizing queries. (Can be set at creation or overridden at runtime.)
|
|
53
53
|
|
|
@@ -82,7 +82,9 @@ const vectorStore = new PgVector({
|
|
|
82
82
|
|
|
83
83
|
**dimension** (`number`): Vector dimension (must match your embedding model)
|
|
84
84
|
|
|
85
|
-
**metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
|
|
85
|
+
**metric** (`'cosine' | 'euclidean' | 'dotproduct' | 'hamming' | 'jaccard'`): Distance metric for similarity search. 'hamming' and 'jaccard' are only valid with vectorType 'bit', and 'jaccard' requires an HNSW index. (Default: `'cosine' ('hamming' when vectorType is 'bit')`)
|
|
86
|
+
|
|
87
|
+
**vectorType** (`'vector' | 'halfvec' | 'bit' | 'sparsevec'`): pgvector storage type for the embeddings (Default: `vector`)
|
|
86
88
|
|
|
87
89
|
**indexConfig** (`IndexConfig`): Index configuration (Default: `{ type: 'ivfflat' }`)
|
|
88
90
|
|
|
@@ -142,13 +144,11 @@ Higher M values or efConstruction values will increase memory requirements subst
|
|
|
142
144
|
|
|
143
145
|
**includeVector** (`boolean`): Whether to include the vector in the result (Default: `false`)
|
|
144
146
|
|
|
145
|
-
**minScore** (`number`): Minimum similarity score threshold (Default: `
|
|
146
|
-
|
|
147
|
-
**options** (`{ ef?: number; probes?: number }`): Additional options for HNSW and IVF indexes
|
|
147
|
+
**minScore** (`number`): Minimum similarity score threshold (Default: `-1`)
|
|
148
148
|
|
|
149
|
-
**
|
|
149
|
+
**ef** (`number`): HNSW search parameter. Higher values improve accuracy at the cost of speed.
|
|
150
150
|
|
|
151
|
-
**
|
|
151
|
+
**probes** (`number`): IVFFlat search parameter. Number of lists to visit during search.
|
|
152
152
|
|
|
153
153
|
### `listIndexes()`
|
|
154
154
|
|
|
@@ -164,8 +164,9 @@ Returns:
|
|
|
164
164
|
interface PGIndexStats {
|
|
165
165
|
dimension: number
|
|
166
166
|
count: number
|
|
167
|
-
metric: 'cosine' | 'euclidean' | 'dotproduct'
|
|
167
|
+
metric: 'cosine' | 'euclidean' | 'dotproduct' | 'hamming' | 'jaccard'
|
|
168
168
|
type: 'flat' | 'hnsw' | 'ivfflat'
|
|
169
|
+
vectorType: 'vector' | 'halfvec' | 'bit' | 'sparsevec'
|
|
169
170
|
config: {
|
|
170
171
|
m?: number
|
|
171
172
|
efConstruction?: number
|
|
@@ -246,7 +247,7 @@ Closes the database connection pool. Should be called when done using the store.
|
|
|
246
247
|
|
|
247
248
|
**indexName** (`string`): Name of the index to define
|
|
248
249
|
|
|
249
|
-
**metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
|
|
250
|
+
**metric** (`'cosine' | 'euclidean' | 'dotproduct' | 'hamming' | 'jaccard'`): Distance metric for similarity search (Default: `cosine`)
|
|
250
251
|
|
|
251
252
|
**indexConfig** (`IndexConfig`): Configuration for the index type and parameters
|
|
252
253
|
|
|
@@ -291,17 +292,21 @@ interface QueryResult {
|
|
|
291
292
|
|
|
292
293
|
## Error handling
|
|
293
294
|
|
|
294
|
-
The store throws
|
|
295
|
+
The store throws `MastraError` instances from `@mastra/core/error`:
|
|
295
296
|
|
|
296
297
|
```typescript
|
|
298
|
+
import { MastraError } from '@mastra/core/error'
|
|
299
|
+
|
|
297
300
|
try {
|
|
298
301
|
await store.query({
|
|
299
302
|
indexName: 'index_name',
|
|
300
303
|
queryVector: queryVector,
|
|
301
304
|
})
|
|
302
305
|
} catch (error) {
|
|
303
|
-
if (error instanceof
|
|
304
|
-
console.log(error.
|
|
306
|
+
if (error instanceof MastraError) {
|
|
307
|
+
console.log(error.id) // 'MASTRA_VECTOR_PG_QUERY_FAILED'
|
|
308
|
+
console.log(error.domain) // 'MASTRA_VECTOR'
|
|
309
|
+
console.log(error.category) // 'USER' | 'THIRD_PARTY'
|
|
305
310
|
console.log(error.details) // Additional error context
|
|
306
311
|
}
|
|
307
312
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -25151,25 +25151,9 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
|
|
|
25151
25151
|
schemaName: getSchemaName(this.#schema)
|
|
25152
25152
|
});
|
|
25153
25153
|
const existingSnapshotResult = await t.oneOrNone(`SELECT snapshot FROM ${tableName} WHERE workflow_name = $1 AND run_id = $2 FOR UPDATE`, [workflowName, runId]);
|
|
25154
|
-
|
|
25155
|
-
|
|
25156
|
-
|
|
25157
|
-
activePaths: [],
|
|
25158
|
-
timestamp: Date.now(),
|
|
25159
|
-
suspendedPaths: {},
|
|
25160
|
-
activeStepsPath: {},
|
|
25161
|
-
resumeLabels: {},
|
|
25162
|
-
serializedStepGraph: [],
|
|
25163
|
-
status: "pending",
|
|
25164
|
-
value: {},
|
|
25165
|
-
waitingPaths: {},
|
|
25166
|
-
runId,
|
|
25167
|
-
requestContext: {}
|
|
25168
|
-
};
|
|
25169
|
-
else {
|
|
25170
|
-
const existingSnapshot = existingSnapshotResult.snapshot;
|
|
25171
|
-
snapshot = typeof existingSnapshot === "string" ? JSON.parse(existingSnapshot) : existingSnapshot;
|
|
25172
|
-
}
|
|
25154
|
+
if (!existingSnapshotResult) return {};
|
|
25155
|
+
const existingSnapshot = existingSnapshotResult.snapshot;
|
|
25156
|
+
const snapshot = typeof existingSnapshot === "string" ? JSON.parse(existingSnapshot) : existingSnapshot;
|
|
25173
25157
|
(0, _mastra_core_storage.mergeWorkflowStepResult)({
|
|
25174
25158
|
snapshot,
|
|
25175
25159
|
stepId,
|