@mastra/pg 1.33.0-alpha.0 → 1.33.0-alpha.2

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 (34) hide show
  1. package/dist/_types/@internal_core/dist/knowledge-compat/index.d.ts +0 -2
  2. package/dist/_types/@internal_core/dist/memory/index.d.ts +0 -2
  3. package/dist/docs/SKILL.md +1 -1
  4. package/dist/docs/assets/SOURCE_MAP.json +1 -1
  5. package/dist/docs/references/docs-memory-semantic-recall.md +5 -1
  6. package/dist/docs/references/integrations-databases-dynamodb.md +4 -4
  7. package/dist/docs/references/integrations-databases-postgresql.md +4 -4
  8. package/dist/docs/references/reference-memory-memory-class.md +2 -2
  9. package/dist/docs/references/reference-rag-chunking-and-embedding.md +1 -1
  10. package/dist/docs/references/reference-rag-retrieval.md +11 -0
  11. package/dist/docs/references/reference-storage-retention.md +1 -1
  12. package/dist/docs/references/reference-tools-vector-query-tool.md +1 -0
  13. package/dist/docs/references/reference-vectors-pg.md +1 -1
  14. package/dist/index.cjs +149 -174
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.js +149 -173
  17. package/dist/index.js.map +1 -1
  18. package/dist/shared/pool-error-guard.d.ts +23 -0
  19. package/dist/shared/pool-error-guard.d.ts.map +1 -0
  20. package/dist/shared/test-fixtures/terminate-backend.d.ts +2 -0
  21. package/dist/shared/test-fixtures/terminate-backend.d.ts.map +1 -0
  22. package/dist/storage/db/index.d.ts.map +1 -1
  23. package/dist/storage/domains/agents/index.d.ts.map +1 -1
  24. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  25. package/dist/storage/domains/observability/v-next/ddl.d.ts +2 -0
  26. package/dist/storage/domains/observability/v-next/ddl.d.ts.map +1 -1
  27. package/dist/storage/domains/observability/v-next/index.d.ts.map +1 -1
  28. package/dist/storage/domains/workflows/index.d.ts +5 -2
  29. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  30. package/dist/storage/factory-storage.d.ts +1 -22
  31. package/dist/storage/factory-storage.d.ts.map +1 -1
  32. package/dist/storage/index.d.ts.map +1 -1
  33. package/dist/vector/index.d.ts.map +1 -1
  34. package/package.json +13 -13
@@ -1,4 +1,3 @@
1
- //#region src/knowledge-compat/index.d.ts
2
1
  export declare const KNOWLEDGE_V2_CORE_FEATURE = "knowledge-v2";
3
2
  export declare const KNOWLEDGE_STORAGE_CONTRACT_VERSION: 2;
4
3
  export declare const KNOWLEDGE_STORAGE_SCHEMA_VERSION: 2;
@@ -589,6 +588,5 @@ interface KnowledgeV2Core {
589
588
  }
590
589
  export declare function assertKnowledgeV2CoreSupport(features: ReadonlySet<string>): void;
591
590
  export declare function createKnowledgeV2CoreLoader(features: ReadonlySet<string>, loadStorageModule: () => Promise<unknown>): () => Promise<KnowledgeV2Core>;
592
- //#endregion
593
591
  export {};
594
592
  //# sourceMappingURL=index.d.ts.map
@@ -1,4 +1,3 @@
1
- //#region src/memory/index.d.ts
2
1
  /**
3
2
  * Shared rules for observational memory lifecycle writes. Every storage adapter applies
4
3
  * these inside its own atomic section (lock, transaction, or conditional update), so the
@@ -97,5 +96,4 @@ export declare function assertActiveObservationsApplied(result: UpdateActiveObse
97
96
  * (equal, or only appended to since).
98
97
  */
99
98
  export declare function isAppendOnlySince(storedObservations: string, snapshotObservations: string): boolean;
100
- //#endregion
101
99
  //# sourceMappingURL=index.d.ts.map
@@ -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.33.0-alpha.0"
6
+ version: "1.33.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.33.0-alpha.0",
2
+ "version": "1.33.0-alpha.2",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -4,7 +4,11 @@
4
4
 
5
5
  # Semantic recall
6
6
 
7
- 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.
7
+ Semantic recall is a built-in form of Retrieval-Augmented Generation (RAG) for agent memory. When a user sends a message, Mastra searches earlier messages for ones with a similar meaning and adds the most relevant ones to the agent's context.
8
+
9
+ Matching on meaning matters because people often remember the idea behind something, not the exact words they used. A user might ask "What did we decide about the refund?" after originally writing "Let's give them their money back." A keyword search misses that connection, but semantic recall finds it.
10
+
11
+ Use semantic recall when your agent needs details from earlier in a long conversation, or from a user's other conversations, that are no longer in [recent message history](https://mastra.ai/docs/memory/message-history).
8
12
 
9
13
  > **📹 Watch:** Watch [Mastra semantic recall](https://www.youtube.com/watch?v=UVZtK8cK8xQ\&pp=ygUVbWFzdHJhIHdvcmtpbmcgbWVtb3J5) to see how agents retrieve relevant messages from past conversations.
10
14
 
@@ -50,7 +50,7 @@ bun add @mastra/dynamodb@latest
50
50
 
51
51
  Before using this package, you **must** create a DynamoDB table with a specific structure, including primary keys and Global Secondary Indexes (GSIs). This adapter expects the DynamoDB table and its GSIs to be provisioned externally.
52
52
 
53
- Detailed instructions for setting up the table using AWS CloudFormation or AWS CDK are available in [TABLE\_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md). Please ensure your table is configured according to those instructions before proceeding.
53
+ Detailed instructions for setting up the table using AWS CloudFormation or AWS CDK are available in [TABLE_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md). Please ensure your table is configured according to those instructions before proceeding.
54
54
 
55
55
  ## Usage
56
56
 
@@ -122,7 +122,7 @@ For local development, you can use [DynamoDB Local](https://docs.aws.amazon.com/
122
122
 
123
123
  **config.credentials** (`object`): AWS credentials object with accessKeyId and secretAccessKey. If not provided, the AWS SDK will attempt to source credentials from environment variables, IAM roles (e.g., for EC2/Lambda), or the shared AWS credentials file.
124
124
 
125
- **config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval, workflow\_snapshot, resource, score. Each entity config includes: enabled (boolean), attributeName (string, default: 'ttl'), defaultTtlSeconds (number).
125
+ **config.ttl** (`object`): TTL (Time To Live) configuration for automatic data expiration. Configure per entity type: thread, message, trace, eval, workflow_snapshot, resource, score. Each entity config includes: enabled (boolean), attributeName (string, default: 'ttl'), defaultTtlSeconds (number).
126
126
 
127
127
  ## TTL (time to live) configuration
128
128
 
@@ -254,7 +254,7 @@ The IAM role or user executing the code needs appropriate permissions to interac
254
254
 
255
255
  Before diving into the architectural details, keep these key points in mind when working with the DynamoDB storage adapter:
256
256
 
257
- - **External Table Provisioning:** This adapter _requires_ you to create and configure the DynamoDB table and its Global Secondary Indexes (GSIs) yourself, prior to using the adapter. Follow the guide in [TABLE\_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md).
257
+ - **External Table Provisioning:** This adapter _requires_ you to create and configure the DynamoDB table and its Global Secondary Indexes (GSIs) yourself, prior to using the adapter. Follow the guide in [TABLE_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md).
258
258
  - **Single-Table Design:** All Mastra data (threads, messages, etc.) is stored in one DynamoDB table. This is a deliberate design choice optimized for DynamoDB, differing from relational database approaches.
259
259
  - **Understanding GSIs:** Familiarity with how the GSIs are structured (as per `TABLE_SETUP.md`) is important for understanding data retrieval and potential query patterns.
260
260
  - **ElectroDB:** The adapter uses ElectroDB to manage interactions with DynamoDB, providing a layer of abstraction and type safety over raw DynamoDB operations.
@@ -266,7 +266,7 @@ This storage adapter utilizes a **single-table design pattern** with [ElectroDB]
266
266
  Key aspects of this approach:
267
267
 
268
268
  - **DynamoDB Native:** The single-table design is optimized for DynamoDB's key-value and query capabilities, often leading to better performance and capacity compared to mimicking relational models.
269
- - **External Table Management:** Unlike some adapters that might offer helper functions to create tables via code, this adapter **expects the DynamoDB table and its associated Global Secondary Indexes (GSIs) to be provisioned externally** before use. Please refer to [TABLE\_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md) for detailed instructions using tools like AWS CloudFormation or CDK. The adapter focuses solely on interacting with the pre-existing table structure.
269
+ - **External Table Management:** Unlike some adapters that might offer helper functions to create tables via code, this adapter **expects the DynamoDB table and its associated Global Secondary Indexes (GSIs) to be provisioned externally** before use. Please refer to [TABLE_SETUP.md](https://github.com/mastra-ai/mastra/blob/main/stores/dynamodb/TABLE_SETUP.md) for detailed instructions using tools like AWS CloudFormation or CDK. The adapter focuses solely on interacting with the pre-existing table structure.
270
270
  - **Consistency via Interface:** While the underlying storage model differs, this adapter adheres to the same `MastraStorage` interface as other adapters, ensuring it can be used interchangeably within the Mastra `Memory` component.
271
271
 
272
272
  ### Mastra Data in the Single Table
@@ -429,14 +429,14 @@ PostgreSQL storage provides index management to optimize query performance.
429
429
  PostgreSQL storage creates composite indexes during initialization for common query patterns:
430
430
 
431
431
  - `mastra_threads_resourceid_createdat_idx`: (resourceId, createdAt DESC)
432
- - `mastra_messages_thread_id_createdat_idx`: (thread\_id, createdAt DESC)
432
+ - `mastra_messages_thread_id_createdat_idx`: (thread_id, createdAt DESC)
433
433
  - `mastra_ai_spans_traceid_startedat_idx`: (traceId, startedAt DESC)
434
434
  - `mastra_ai_spans_parentspanid_startedat_idx`: (parentSpanId, startedAt DESC)
435
435
  - `mastra_ai_spans_name_startedat_idx`: (name, startedAt DESC)
436
436
  - `mastra_ai_spans_scope_startedat_idx`: (scope, startedAt DESC)
437
437
  - `mastra_scores_trace_id_span_id_created_at_idx`: (traceId, spanId, createdAt DESC)
438
- - `mastra_workflow_snapshot_name_createdat_idx`: (workflow\_name, createdAt DESC)
439
- - `mastra_workflow_snapshot_name_status_createdat_idx`: (workflow\_name, snapshot->>'status', createdAt DESC), created only when the `snapshot` column is `jsonb`
438
+ - `mastra_workflow_snapshot_name_createdat_idx`: (workflow_name, createdAt DESC)
439
+ - `mastra_workflow_snapshot_name_status_createdat_idx`: (workflow_name, snapshot->>'status', createdAt DESC), created only when the `snapshot` column is `jsonb`
440
440
 
441
441
  These indexes improve performance for filtered queries with sorting, including `dateRange` filters on message queries and Studio's workflow runs-list.
442
442
 
@@ -485,7 +485,7 @@ For advanced index types, you can specify additional options:
485
485
 
486
486
  **name** (`string`): Unique name for the index
487
487
 
488
- **table** (`string`): Table name (e.g., 'mastra\_threads')
488
+ **table** (`string`): Table name (e.g., 'mastra_threads')
489
489
 
490
490
  **columns** (`string[]`): Array of column names with optional sort order (e.g., \['id', 'createdAt DESC'])
491
491
 
@@ -37,11 +37,11 @@ export const agent = new Agent({
37
37
 
38
38
  **embedder** (`EmbeddingModel<string> | EmbeddingModelV2<string>`): Embedder instance for vector embeddings. Required when semantic recall is enabled.
39
39
 
40
- **embeddingDimension** (`number`): Output dimension of the embedder, as a positive integer. When set, Memory uses it to name the semantic recall index instead of embedding a probe string on first use. It must match the vectors the embedder returns: a mismatch throws a MASTRA\_MEMORY\_EMBEDDING\_DIMENSION\_MISMATCH error before any index is created. See Setting the embedding dimension.
40
+ **embeddingDimension** (`number`): Output dimension of the embedder, as a positive integer. When set, Memory uses it to name the semantic recall index instead of embedding a probe string on first use. It must match the vectors the embedder returns: a mismatch throws a MASTRA_MEMORY_EMBEDDING_DIMENSION_MISMATCH error before any index is created. See Setting the embedding dimension.
41
41
 
42
42
  **options** (`MemoryConfig`): Memory configuration options.
43
43
 
44
- **options.lastMessages** (`number | false`): Number of most recent messages to include in context. Set to false to disable the message history feature entirely (messages are not loaded into context or saved). Use Number.MAX\_SAFE\_INTEGER to retrieve all messages with no limit. To load messages without saving new ones, use the readOnly option. The window slides forward on every request, so once a thread exceeds the limit, each turn invalidates the provider prompt cache. For long-running conversations, use Observational Memory instead.
44
+ **options.lastMessages** (`number | false`): Number of most recent messages to include in context. Set to false to disable the message history feature entirely (messages are not loaded into context or saved). Use Number.MAX_SAFE_INTEGER to retrieve all messages with no limit. To load messages without saving new ones, use the readOnly option. The window slides forward on every request, so once a thread exceeds the limit, each turn invalidates the provider prompt cache. For long-running conversations, use Observational Memory instead.
45
45
 
46
46
  **options.messageHistory** (`{ maxTokens: number; atMaxRemoveTokens?: number }`): Token budget for the complete prompt, including remembered history, system instructions, context, and the current turn. When the prompt exceeds maxTokens, the oldest remembered messages are dropped until the prompt is at most maxTokens - atMaxRemoveTokens (defaults to 25% of maxTokens). Protected content is never removed. Linked tool calls and results are removed together. During agent runs, trimmed history is excluded from later turns via a persisted per-thread boundary, but the messages themselves stay in storage. When set without an explicit lastMessages, the default 10-message cap is not applied. Set maxTokens to 0 to disable message history. Prefer this over lastMessages, since message count is a poor proxy for context size.
47
47
 
@@ -118,7 +118,7 @@ const { embeddings } = await embedMany({
118
118
  })
119
119
  ```
120
120
 
121
- Google (text-embedding-001):
121
+ Google (gemini-embedding-001):
122
122
 
123
123
  ```ts
124
124
  const { embeddings } = await embedMany({
@@ -382,6 +382,7 @@ Vector store prompts define query patterns and filtering capabilities for each v
382
382
 
383
383
  ```ts
384
384
  import { MONGODB_PROMPT } from '@mastra/mongodb'
385
+ import { Agent } from '@mastra/core/agent'
385
386
 
386
387
  export const ragAgent = new Agent({
387
388
  id: 'rag-agent',
@@ -416,6 +417,7 @@ export const ragAgent = new Agent({
416
417
 
417
418
  ```ts
418
419
  import { PINECONE_PROMPT } from '@mastra/pinecone'
420
+ import { Agent } from '@mastra/core/agent'
419
421
 
420
422
  export const ragAgent = new Agent({
421
423
  id: 'rag-agent',
@@ -433,6 +435,7 @@ export const ragAgent = new Agent({
433
435
 
434
436
  ```ts
435
437
  import { QDRANT_PROMPT } from '@mastra/qdrant'
438
+ import { Agent } from '@mastra/core/agent'
436
439
 
437
440
  export const ragAgent = new Agent({
438
441
  id: 'rag-agent',
@@ -450,6 +453,7 @@ export const ragAgent = new Agent({
450
453
 
451
454
  ```ts
452
455
  import { CHROMA_PROMPT } from '@mastra/chroma'
456
+ import { Agent } from '@mastra/core/agent'
453
457
 
454
458
  export const ragAgent = new Agent({
455
459
  id: 'rag-agent',
@@ -467,6 +471,7 @@ export const ragAgent = new Agent({
467
471
 
468
472
  ```ts
469
473
  import { ASTRA_PROMPT } from '@mastra/astra'
474
+ import { Agent } from '@mastra/core/agent'
470
475
 
471
476
  export const ragAgent = new Agent({
472
477
  id: 'rag-agent',
@@ -484,6 +489,7 @@ export const ragAgent = new Agent({
484
489
 
485
490
  ```ts
486
491
  import { LIBSQL_PROMPT } from '@mastra/libsql'
492
+ import { Agent } from '@mastra/core/agent'
487
493
 
488
494
  export const ragAgent = new Agent({
489
495
  id: 'rag-agent',
@@ -501,6 +507,7 @@ export const ragAgent = new Agent({
501
507
 
502
508
  ```ts
503
509
  import { UPSTASH_PROMPT } from '@mastra/upstash'
510
+ import { Agent } from '@mastra/core/agent'
504
511
 
505
512
  export const ragAgent = new Agent({
506
513
  id: 'rag-agent',
@@ -518,6 +525,7 @@ export const ragAgent = new Agent({
518
525
 
519
526
  ```ts
520
527
  import { VECTORIZE_PROMPT } from '@mastra/vectorize'
528
+ import { Agent } from '@mastra/core/agent'
521
529
 
522
530
  export const ragAgent = new Agent({
523
531
  id: 'rag-agent',
@@ -535,6 +543,7 @@ export const ragAgent = new Agent({
535
543
 
536
544
  ```ts
537
545
  import { OPENSEARCH_PROMPT } from '@mastra/opensearch'
546
+ import { Agent } from '@mastra/core/agent'
538
547
 
539
548
  export const ragAgent = new Agent({
540
549
  id: 'rag-agent',
@@ -552,6 +561,7 @@ export const ragAgent = new Agent({
552
561
 
553
562
  ```ts
554
563
  import { ORACLEDB_PROMPT } from '@mastra/oracledb'
564
+ import { Agent } from '@mastra/core/agent'
555
565
 
556
566
  export const ragAgent = new Agent({
557
567
  id: 'rag-agent',
@@ -569,6 +579,7 @@ export const ragAgent = new Agent({
569
579
 
570
580
  ```ts
571
581
  import { S3VECTORS_PROMPT } from '@mastra/s3vectors'
582
+ import { Agent } from '@mastra/core/agent'
572
583
 
573
584
  export const ragAgent = new Agent({
574
585
  id: 'rag-agent',
@@ -294,7 +294,7 @@ const storage = new MongoDBStore({
294
294
 
295
295
  ## Reclaiming disk
296
296
 
297
- `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.
297
+ `prune()` deletes rows but doesn't shrink the database file. On SQLite/libSQL the freed pages go on a freelist for reuse by future writes. Reusing these pages prevents unbounded file growth for most users.
298
298
 
299
299
  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.
300
300
 
@@ -436,6 +436,7 @@ For multi-tenant applications where each tenant has isolated data (e.g., separat
436
436
  ```typescript
437
437
  import { createVectorQueryTool, VectorStoreResolver } from '@mastra/rag'
438
438
  import { PgVector } from '@mastra/pg'
439
+ import { RequestContext } from '@mastra/core/request-context'
439
440
 
440
441
  // Cache for tenant-specific vector stores
441
442
  const vectorStoreCache = new Map<string, PgVector>()
@@ -30,7 +30,7 @@ The PgVector class provides vector search using [PostgreSQL](https://www.postgre
30
30
 
31
31
  **pgPoolOptions** (`PoolConfig`): Additional pg pool configuration options
32
32
 
33
- **disableInit** (`boolean`): When true, automatic DDL (schema, extension, table, and index creation) inside createIndex is skipped. Useful for CI/CD pipelines where schema and indexes are managed separately and the runtime database role lacks DDL privileges. Can also be enabled with the MASTRA\_DISABLE\_STORAGE\_INIT environment variable. (Default: `false`)
33
+ **disableInit** (`boolean`): When true, automatic DDL (schema, extension, table, and index creation) inside createIndex is skipped. Useful for CI/CD pipelines where schema and indexes are managed separately and the runtime database role lacks DDL privileges. Can also be enabled with the MASTRA_DISABLE_STORAGE_INIT environment variable. (Default: `false`)
34
34
 
35
35
  ## Constructor examples
36
36