@mastra/pg 1.2.0 → 1.3.0-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.
Files changed (40) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/dist/docs/SKILL.md +28 -25
  3. package/dist/docs/{SOURCE_MAP.json → assets/SOURCE_MAP.json} +1 -1
  4. package/dist/docs/{memory/03-semantic-recall.md → references/docs-memory-semantic-recall.md} +33 -17
  5. package/dist/docs/{memory/01-storage.md → references/docs-memory-storage.md} +29 -39
  6. package/dist/docs/{memory/02-working-memory.md → references/docs-memory-working-memory.md} +16 -27
  7. package/dist/docs/{rag/01-overview.md → references/docs-rag-overview.md} +2 -4
  8. package/dist/docs/{rag/03-retrieval.md → references/docs-rag-retrieval.md} +26 -53
  9. package/dist/docs/{rag/02-vector-databases.md → references/docs-rag-vector-databases.md} +198 -202
  10. package/dist/docs/{memory/04-reference.md → references/reference-memory-memory-class.md} +28 -14
  11. package/dist/docs/references/reference-processors-message-history-processor.md +85 -0
  12. package/dist/docs/references/reference-processors-semantic-recall-processor.md +123 -0
  13. package/dist/docs/references/reference-processors-working-memory-processor.md +154 -0
  14. package/dist/docs/{rag/04-reference.md → references/reference-rag-metadata-filters.md} +26 -179
  15. package/dist/docs/references/reference-storage-composite.md +235 -0
  16. package/dist/docs/references/reference-storage-dynamodb.md +282 -0
  17. package/dist/docs/references/reference-storage-postgresql.md +529 -0
  18. package/dist/docs/{tools/01-reference.md → references/reference-tools-vector-query-tool.md} +137 -118
  19. package/dist/docs/{vectors/01-reference.md → references/reference-vectors-pg.md} +115 -14
  20. package/dist/index.cjs +1998 -217
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.js +1998 -219
  23. package/dist/index.js.map +1 -1
  24. package/dist/storage/db/constraint-utils.d.ts +16 -0
  25. package/dist/storage/db/constraint-utils.d.ts.map +1 -0
  26. package/dist/storage/db/index.d.ts.map +1 -1
  27. package/dist/storage/domains/agents/index.d.ts +9 -12
  28. package/dist/storage/domains/agents/index.d.ts.map +1 -1
  29. package/dist/storage/domains/memory/index.d.ts +7 -1
  30. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  31. package/dist/storage/domains/prompt-blocks/index.d.ts +33 -0
  32. package/dist/storage/domains/prompt-blocks/index.d.ts.map +1 -0
  33. package/dist/storage/domains/scorer-definitions/index.d.ts +33 -0
  34. package/dist/storage/domains/scorer-definitions/index.d.ts.map +1 -0
  35. package/dist/storage/index.d.ts +3 -1
  36. package/dist/storage/index.d.ts.map +1 -1
  37. package/package.json +2 -3
  38. package/dist/docs/README.md +0 -36
  39. package/dist/docs/processors/01-reference.md +0 -296
  40. package/dist/docs/storage/01-reference.md +0 -905
@@ -1,14 +1,12 @@
1
- > Guide on vector storage options in Mastra, including embedded and dedicated vector databases for similarity search.
2
-
3
1
  # Storing Embeddings in A Vector Database
4
2
 
5
3
  After generating embeddings, you need to store them in a database that supports vector similarity search. Mastra provides a consistent interface for storing and querying embeddings across various vector databases.
6
4
 
7
5
  ## Supported Databases
8
6
 
9
- **mongodb:**
7
+ **MongoDB**:
10
8
 
11
- ```ts title="vector-store.ts"
9
+ ```ts
12
10
  import { MongoDBVector } from "@mastra/mongodb";
13
11
 
14
12
  const store = new MongoDBVector({
@@ -27,15 +25,13 @@ await store.upsert({
27
25
  });
28
26
  ```
29
27
 
30
- <h3>Using MongoDB Atlas Vector search</h3>
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).
28
+ ### Using MongoDB Atlas Vector search
33
29
 
34
-
30
+ 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).
35
31
 
36
- **pg-vector:**
32
+ **PgVector**:
37
33
 
38
- ```ts title="vector-store.ts"
34
+ ```ts
39
35
  import { PgVector } from "@mastra/pg";
40
36
 
41
37
  const store = new PgVector({
@@ -55,16 +51,13 @@ await store.upsert({
55
51
  });
56
52
  ```
57
53
 
58
- <h3>Using PostgreSQL with pgvector</h3>
59
-
60
- PostgreSQL with the pgvector extension is a good solution for teams already using PostgreSQL who want to minimize infrastructure complexity.
61
- For detailed setup instructions and best practices, see the [official pgvector repository](https://github.com/pgvector/pgvector).
54
+ ### Using PostgreSQL with pgvector
62
55
 
63
-
56
+ PostgreSQL with the pgvector extension is a good solution for teams already using PostgreSQL who want to minimize infrastructure complexity. For detailed setup instructions and best practices, see the [official pgvector repository](https://github.com/pgvector/pgvector).
64
57
 
65
- **pinecone:**
58
+ **Pinecone**:
66
59
 
67
- ```ts title="vector-store.ts"
60
+ ```ts
68
61
  import { PineconeVector } from "@mastra/pinecone";
69
62
 
70
63
  const store = new PineconeVector({
@@ -82,11 +75,9 @@ await store.upsert({
82
75
  });
83
76
  ```
84
77
 
85
-
78
+ **Qdrant**:
86
79
 
87
- **qdrant:**
88
-
89
- ```ts title="vector-store.ts"
80
+ ```ts
90
81
  import { QdrantVector } from "@mastra/qdrant";
91
82
 
92
83
  const store = new QdrantVector({
@@ -107,11 +98,9 @@ await store.upsert({
107
98
  });
108
99
  ```
109
100
 
110
-
111
-
112
- **chroma:**
101
+ **Chroma**:
113
102
 
114
- ```ts title="vector-store.ts"
103
+ ```ts
115
104
  import { ChromaVector } from "@mastra/chroma";
116
105
 
117
106
  // Running Chroma locally
@@ -137,11 +126,9 @@ await store.upsert({
137
126
  });
138
127
  ```
139
128
 
140
-
141
-
142
- **astra:**
129
+ **Astra**:
143
130
 
144
- ```ts title="vector-store.ts"
131
+ ```ts
145
132
  import { AstraVector } from "@mastra/astra";
146
133
 
147
134
  const store = new AstraVector({
@@ -163,11 +150,9 @@ await store.upsert({
163
150
  });
164
151
  ```
165
152
 
166
-
167
-
168
- **libsql:**
153
+ **libSQL**:
169
154
 
170
- ```ts title="vector-store.ts"
155
+ ```ts
171
156
  import { LibSQLVector } from "@mastra/core/vector/libsql";
172
157
 
173
158
  const store = new LibSQLVector({
@@ -188,11 +173,9 @@ await store.upsert({
188
173
  });
189
174
  ```
190
175
 
191
-
176
+ **Upstash**:
192
177
 
193
- **upstash:**
194
-
195
- ```ts title="vector-store.ts"
178
+ ```ts
196
179
  import { UpstashVector } from "@mastra/upstash";
197
180
 
198
181
  // In upstash they refer to the store as an index
@@ -211,11 +194,9 @@ await store.upsert({
211
194
  });
212
195
  ```
213
196
 
214
-
197
+ **Cloudflare**:
215
198
 
216
- **cloudflare:**
217
-
218
- ```ts title="vector-store.ts"
199
+ ```ts
219
200
  import { CloudflareVector } from "@mastra/vectorize";
220
201
 
221
202
  const store = new CloudflareVector({
@@ -234,11 +215,9 @@ await store.upsert({
234
215
  });
235
216
  ```
236
217
 
237
-
238
-
239
- **opensearch:**
218
+ **OpenSearch**:
240
219
 
241
- ```ts title="vector-store.ts"
220
+ ```ts
242
221
  import { OpenSearchVector } from "@mastra/opensearch";
243
222
 
244
223
  const store = new OpenSearchVector({ id: "opensearch", node: process.env.OPENSEARCH_URL });
@@ -255,11 +234,9 @@ await store.upsert({
255
234
  });
256
235
  ```
257
236
 
258
-
259
-
260
- **elasticsearch:**
237
+ **ElasticSearch**:
261
238
 
262
- ```ts title="vector-store.ts"
239
+ ```ts
263
240
  import { ElasticSearchVector } from "@mastra/elasticsearch";
264
241
 
265
242
  const store = new ElasticSearchVector({
@@ -281,14 +258,14 @@ await store.upsert({
281
258
  metadata: chunks.map((chunk) => ({ text: chunk.text })),
282
259
  });
283
260
  ```
284
- <h3>Using Elasticsearch</h3>
261
+
262
+ ### Using Elasticsearch
285
263
 
286
264
  For detailed setup instructions and best practices, see the [official Elasticsearch documentation](https://www.elastic.co/docs/solutions/search/get-started).
287
265
 
288
-
289
- **couchbase:**
266
+ **Couchbase**:
290
267
 
291
- ```ts title="vector-store.ts"
268
+ ```ts
292
269
  import { CouchbaseVector } from "@mastra/couchbase";
293
270
 
294
271
  const store = new CouchbaseVector({
@@ -311,10 +288,9 @@ await store.upsert({
311
288
  });
312
289
  ```
313
290
 
314
-
315
- **lancedb:**
291
+ **Lance**:
316
292
 
317
- ```ts title="vector-store.ts"
293
+ ```ts
318
294
  import { LanceVectorStore } from "@mastra/lance";
319
295
 
320
296
  const store = await LanceVectorStore.create("/path/to/db");
@@ -332,15 +308,13 @@ await store.upsert({
332
308
  });
333
309
  ```
334
310
 
335
- <h3>Using LanceDB</h3>
311
+ ### Using LanceDB
336
312
 
337
- LanceDB is an embedded vector database built on the Lance columnar format, suitable for local development or cloud deployment.
338
- For detailed setup instructions and best practices, see the [official LanceDB documentation](https://lancedb.github.io/lancedb/).
313
+ LanceDB is an embedded vector database built on the Lance columnar format, suitable for local development or cloud deployment. For detailed setup instructions and best practices, see the [official LanceDB documentation](https://lancedb.github.io/lancedb/).
339
314
 
340
-
341
- **s3vectors:**
315
+ **S3 Vectors**:
342
316
 
343
- ```ts title="vector-store.ts"
317
+ ```ts
344
318
  import { S3Vectors } from "@mastra/s3vectors";
345
319
 
346
320
  const store = new S3Vectors({
@@ -363,8 +337,6 @@ await store.upsert({
363
337
  });
364
338
  ```
365
339
 
366
-
367
-
368
340
  ## Using Vector Storage
369
341
 
370
342
  Once initialized, all vector stores share the same interface for creating indexes, upserting embeddings, and querying.
@@ -373,7 +345,7 @@ Once initialized, all vector stores share the same interface for creating indexe
373
345
 
374
346
  Before storing embeddings, you need to create an index with the appropriate dimension size for your embedding model:
375
347
 
376
- ```ts title="store-embeddings.ts"
348
+ ```ts
377
349
  // Create an index with dimension 1536 (for text-embedding-3-small)
378
350
  await store.createIndex({
379
351
  indexName: "myCollection",
@@ -387,148 +359,172 @@ The dimension size must match the output dimension of your chosen embedding mode
387
359
  - Cohere embed-multilingual-v3: 1024 dimensions
388
360
  - Google gemini-embedding-001: 768 dimensions (or custom)
389
361
 
390
- > **Note:**
391
- Index dimensions cannot be changed after creation. To use a different model, delete and recreate the index with the new dimension size.
362
+ > **Warning:** Index dimensions cannot be changed after creation. To use a different model, delete and recreate the index with the new dimension size.
392
363
 
393
364
  ### Naming Rules for Databases
394
365
 
395
366
  Each vector database enforces specific naming conventions for indexes and collections to ensure compatibility and prevent conflicts.
396
367
 
397
- **mongodb:**
398
-
399
- Collection (index) names must:
400
- - Start with a letter or underscore
401
- - Be up to 120 bytes long
402
- - Contain only letters, numbers, underscores, or dots
403
- - Cannot contain `$` or the null character
404
- - Example: `my_collection.123` is valid
405
- - Example: `my-index` is not valid (contains hyphen)
406
- - Example: `My$Collection` is not valid (contains `$`)
407
-
408
- **pgVector:**
409
-
410
- Index names must:
411
- - Start with a letter or underscore
412
- - Contain only letters, numbers, and underscores
413
- - Example: `my_index_123` is valid
414
- - Example: `my-index` is not valid (contains hyphen)
415
-
416
- **pinecone:**
417
-
418
- Index names must:
419
- - Use only lowercase letters, numbers, and dashes
420
- - Not contain dots (used for DNS routing)
421
- - Not use non-Latin characters or emojis
422
- - Have a combined length (with project ID) under 52 characters
423
- - Example: `my-index-123` is valid
424
- - Example: `my.index` is not valid (contains dot)
425
-
426
- **qdrant:**
427
-
428
- Collection names must:
429
- - Be 1-255 characters long
430
- - Not contain any of these special characters:
431
- - `< > : " / \ | ? *`
432
- - Null character (`\0`)
433
- - Unit separator (`\u{1F}`)
434
- - Example: `my_collection_123` is valid
435
- - Example: `my/collection` is not valid (contains slash)
436
-
437
- **chroma:**
438
-
439
- Collection names must:
440
- - Be 3-63 characters long
441
- - Start and end with a letter or number
442
- - Contain only letters, numbers, underscores, or hyphens
443
- - Not contain consecutive periods (..)
444
- - Not be a valid IPv4 address
445
- - Example: `my-collection-123` is valid
446
- - Example: `my..collection` is not valid (consecutive periods)
447
-
448
- **astra:**
449
-
450
- Collection names must:
451
- - Not be empty
452
- - Be 48 characters or less
453
- - Contain only letters, numbers, and underscores
454
- - Example: `my_collection_123` is valid
455
- - Example: `my-collection` is not valid (contains hyphen)
456
-
457
- **libsql:**
458
-
459
- Index names must:
460
- - Start with a letter or underscore
461
- - Contain only letters, numbers, and underscores
462
- - Example: `my_index_123` is valid
463
- - Example: `my-index` is not valid (contains hyphen)
464
-
465
- **upstash:**
466
-
467
- Namespace names must:
468
- - Be 2-100 characters long
469
- - Contain only:
470
- - Alphanumeric characters (a-z, A-Z, 0-9)
471
- - Underscores, hyphens, dots
472
- - Not start or end with special characters (_, -, .)
473
- - Can be case-sensitive
474
- - Example: `MyNamespace123` is valid
475
- - Example: `_namespace` is not valid (starts with underscore)
476
-
477
- **cloudflare:**
478
-
479
- Index names must:
480
- - Start with a letter
481
- - Be shorter than 32 characters
482
- - Contain only lowercase ASCII letters, numbers, and dashes
483
- - Use dashes instead of spaces
484
- - Example: `my-index-123` is valid
485
- - Example: `My_Index` is not valid (uppercase and underscore)
486
-
487
- **opensearch:**
488
-
489
- Index names must:
490
- - Use only lowercase letters
491
- - Not begin with underscores or hyphens
492
- - Not contain spaces, commas
493
- - Not contain special characters (e.g. `:`, `"`, `*`, `+`, `/`, `\`, `|`, `?`, `#`, `>`, `<`)
494
- - Example: `my-index-123` is valid
495
- - Example: `My_Index` is not valid (contains uppercase letters)
496
- - Example: `_myindex` is not valid (begins with underscore)
497
-
498
- **elasticsearch:**
499
-
500
- Index names must:
501
- - Use only lowercase letters
502
- - Not exceed 255 bytes (counting multi-byte characters)
503
- - Not begin with underscores, hyphens, or plus signs
504
- - Not contain spaces, commas
505
- - Not contain special characters (e.g. `:`, `"`, `*`, `+`, `/`, `\`, `|`, `?`, `#`, `>`, `<`)
506
- - Not be "." or ".."
507
- - Not start with "." (deprecated except for system/hidden indices)
508
- - Example: `my-index-123` is valid
509
- - Example: `My_Index` is not valid (contains uppercase letters)
510
- - Example: `_myindex` is not valid (begins with underscore)
511
- - Example: `.myindex` is not valid (begins with dot, deprecated)
512
-
513
- **s3vectors:**
514
-
515
- Index names must:
516
- - Be unique within the same vector bucket
517
- - Be 3–63 characters long
518
- - Use only lowercase letters (`a–z`), numbers (`0–9`), hyphens (`-`), and dots (`.`)
519
- - Begin and end with a letter or number
520
- - Example: `my-index.123` is valid
521
- - Example: `my_index` is not valid (contains underscore)
522
- - Example: `-myindex` is not valid (begins with hyphen)
523
- - Example: `myindex-` is not valid (ends with hyphen)
524
- - Example: `MyIndex` is not valid (contains uppercase letters)
525
-
368
+ **MongoDB**:
369
+
370
+ Collection (index) names must:
371
+
372
+ - Start with a letter or underscore
373
+ - Be up to 120 bytes long
374
+ - Contain only letters, numbers, underscores, or dots
375
+ - Cannot contain `$` or the null character
376
+ - Example: `my_collection.123` is valid
377
+ - Example: `my-index` is not valid (contains hyphen)
378
+ - Example: `My$Collection` is not valid (contains `$`)
379
+
380
+ **PgVector**:
381
+
382
+ Index names must:
383
+
384
+ - Start with a letter or underscore
385
+ - Contain only letters, numbers, and underscores
386
+ - Example: `my_index_123` is valid
387
+ - Example: `my-index` is not valid (contains hyphen)
388
+
389
+ **Pinecone**:
390
+
391
+ Index names must:
392
+
393
+ - Use only lowercase letters, numbers, and dashes
394
+
395
+ - Not contain dots (used for DNS routing)
396
+
397
+ - Not use non-Latin characters or emojis
398
+
399
+ - Have a combined length (with project ID) under 52 characters
400
+
401
+ - Example: `my-index-123` is valid
402
+ - Example: `my.index` is not valid (contains dot)
403
+
404
+ **Qdrant**:
405
+
406
+ Collection names must:
407
+
408
+ - Be 1-255 characters long
409
+
410
+ - Not contain any of these special characters:
411
+
412
+ - `< > : " / \ | ? *`
413
+ - Null character (`\0`)
414
+ - Unit separator (`\u{1F}`)
415
+
416
+ - Example: `my_collection_123` is valid
417
+
418
+ - Example: `my/collection` is not valid (contains slash)
419
+
420
+ **Chroma**:
421
+
422
+ Collection names must:
423
+
424
+ - Be 3-63 characters long
425
+ - Start and end with a letter or number
426
+ - Contain only letters, numbers, underscores, or hyphens
427
+ - Not contain consecutive periods (..)
428
+ - Not be a valid IPv4 address
429
+ - Example: `my-collection-123` is valid
430
+ - Example: `my..collection` is not valid (consecutive periods)
431
+
432
+ **Astra**:
433
+
434
+ Collection names must:
435
+
436
+ - Not be empty
437
+ - Be 48 characters or less
438
+ - Contain only letters, numbers, and underscores
439
+ - Example: `my_collection_123` is valid
440
+ - Example: `my-collection` is not valid (contains hyphen)
441
+
442
+ **libSQL**:
443
+
444
+ Index names must:
445
+
446
+ - Start with a letter or underscore
447
+ - Contain only letters, numbers, and underscores
448
+ - Example: `my_index_123` is valid
449
+ - Example: `my-index` is not valid (contains hyphen)
450
+
451
+ **Upstash**:
452
+
453
+ Namespace names must:
454
+
455
+ - Be 2-100 characters long
456
+
457
+ - Contain only:
458
+
459
+ - Alphanumeric characters (a-z, A-Z, 0-9)
460
+ - Underscores, hyphens, dots
461
+
462
+ - Not start or end with special characters (\_, -, .)
463
+
464
+ - Can be case-sensitive
465
+
466
+ - Example: `MyNamespace123` is valid
467
+
468
+ - Example: `_namespace` is not valid (starts with underscore)
469
+
470
+ **Cloudflare**:
471
+
472
+ Index names must:
473
+
474
+ - Start with a letter
475
+ - Be shorter than 32 characters
476
+ - Contain only lowercase ASCII letters, numbers, and dashes
477
+ - Use dashes instead of spaces
478
+ - Example: `my-index-123` is valid
479
+ - Example: `My_Index` is not valid (uppercase and underscore)
480
+
481
+ **OpenSearch**:
482
+
483
+ Index names must:
484
+
485
+ - Use only lowercase letters
486
+ - Not begin with underscores or hyphens
487
+ - Not contain spaces, commas
488
+ - Not contain special characters (e.g. `:`, `"`, `*`, `+`, `/`, `\`, `|`, `?`, `#`, `>`, `<`)
489
+ - Example: `my-index-123` is valid
490
+ - Example: `My_Index` is not valid (contains uppercase letters)
491
+ - Example: `_myindex` is not valid (begins with underscore)
492
+
493
+ **ElasticSearch**:
494
+
495
+ Index names must:
496
+
497
+ - Use only lowercase letters
498
+ - Not exceed 255 bytes (counting multi-byte characters)
499
+ - Not begin with underscores, hyphens, or plus signs
500
+ - Not contain spaces, commas
501
+ - Not contain special characters (e.g. `:`, `"`, `*`, `+`, `/`, `\`, `|`, `?`, `#`, `>`, `<`)
502
+ - Not be "." or ".."
503
+ - Not start with "." (deprecated except for system/hidden indices)
504
+ - Example: `my-index-123` is valid
505
+ - Example: `My_Index` is not valid (contains uppercase letters)
506
+ - Example: `_myindex` is not valid (begins with underscore)
507
+ - Example: `.myindex` is not valid (begins with dot, deprecated)
508
+
509
+ **S3 Vectors**:
510
+
511
+ Index names must:
512
+
513
+ - Be unique within the same vector bucket
514
+ - Be 3–63 characters long
515
+ - Use only lowercase letters (`a–z`), numbers (`0–9`), hyphens (`-`), and dots (`.`)
516
+ - Begin and end with a letter or number
517
+ - Example: `my-index.123` is valid
518
+ - Example: `my_index` is not valid (contains underscore)
519
+ - Example: `-myindex` is not valid (begins with hyphen)
520
+ - Example: `myindex-` is not valid (ends with hyphen)
521
+ - Example: `MyIndex` is not valid (contains uppercase letters)
526
522
 
527
523
  ### Upserting Embeddings
528
524
 
529
525
  After creating an index, you can store embeddings along with their basic metadata:
530
526
 
531
- ```ts title="store-embeddings.ts"
527
+ ```ts
532
528
  // Store embeddings with their corresponding metadata
533
529
  await store.upsert({
534
530
  indexName: "myCollection", // index name
@@ -551,8 +547,7 @@ The upsert operation:
551
547
 
552
548
  Vector stores support rich metadata (any JSON-serializable fields) for filtering and organization. Since metadata is stored with no fixed schema, use consistent field naming to avoid unexpected query results.
553
549
 
554
- > **Note:**
555
- Metadata is crucial for vector storage - without it, you'd only have numerical embeddings with no way to return the original text or filter results. Always store at least the source text as metadata.
550
+ > **Warning:** Metadata is crucial for vector storage - without it, you'd only have numerical embeddings with no way to return the original text or filter results. Always store at least the source text as metadata.
556
551
 
557
552
  ```ts
558
553
  // Store embeddings with rich metadata for better organization and filtering
@@ -594,7 +589,7 @@ When building RAG applications, you often need to clean up stale vectors when do
594
589
 
595
590
  The most common use case is deleting all vectors for a specific document when a user deletes it:
596
591
 
597
- ```ts title="delete-vectors.ts"
592
+ ```ts
598
593
  // Delete all vectors for a specific document
599
594
  await store.deleteVectors({
600
595
  indexName: "myCollection",
@@ -603,6 +598,7 @@ await store.deleteVectors({
603
598
  ```
604
599
 
605
600
  This is particularly useful when:
601
+
606
602
  - A user deletes a document and you need to remove all its chunks
607
603
  - You're re-indexing a document and want to remove old vectors first
608
604
  - You need to clean up vectors for a specific user or tenant
@@ -611,7 +607,7 @@ This is particularly useful when:
611
607
 
612
608
  You can also use complex filters to delete vectors matching multiple conditions:
613
609
 
614
- ```ts title="delete-vectors-advanced.ts"
610
+ ```ts
615
611
  // Delete all vectors for multiple documents
616
612
  await store.deleteVectors({
617
613
  indexName: "myCollection",
@@ -636,7 +632,7 @@ await store.deleteVectors({
636
632
 
637
633
  If you have specific vector IDs to delete, you can pass them directly:
638
634
 
639
- ```ts title="delete-by-ids.ts"
635
+ ```ts
640
636
  // Delete specific vectors by their IDs
641
637
  await store.deleteVectors({
642
638
  indexName: "myCollection",
@@ -1,19 +1,10 @@
1
- # Memory API Reference
2
-
3
- > API reference for memory - 1 entries
4
-
5
-
6
- ---
7
-
8
- ## Reference: Memory Class
9
-
10
- > Documentation for the `Memory` class in Mastra, which provides a robust system for managing conversation history and thread-based message storage.
1
+ # Memory Class
11
2
 
12
3
  The `Memory` class provides a robust system for managing conversation history and thread-based message storage in Mastra. It enables persistent storage of conversations, semantic search capabilities, and efficient message retrieval. You must configure a storage provider for conversation history, and if you enable semantic recall you will also need to provide a vector store and embedder.
13
4
 
14
5
  ## Usage example
15
6
 
16
- ```typescript title="src/mastra/agents/test-agent.ts"
7
+ ```typescript
17
8
  import { Memory } from "@mastra/memory";
18
9
  import { Agent } from "@mastra/core/agent";
19
10
 
@@ -31,17 +22,39 @@ export const agent = new Agent({
31
22
  });
32
23
  ```
33
24
 
34
- > To enable `workingMemory` on an agent, you’ll need a storage provider configured on your main Mastra instance. See [Mastra class](../core/mastra-class) for more information.
25
+ > To enable `workingMemory` on an agent, you’ll need a storage provider configured on your main Mastra instance. See [Mastra class](https://mastra.ai/reference/core/mastra-class) for more information.
35
26
 
36
27
  ## Constructor parameters
37
28
 
29
+ **storage?:** (`MastraCompositeStore`): Storage implementation for persisting memory data. Defaults to \`new DefaultStorage({ config: { url: "file:memory.db" } })\` if not provided.
30
+
31
+ **vector?:** (`MastraVector | false`): Vector store for semantic search capabilities. Set to \`false\` to disable vector operations.
32
+
33
+ **embedder?:** (`EmbeddingModel<string> | EmbeddingModelV2<string>`): Embedder instance for vector embeddings. Required when semantic recall is enabled.
34
+
35
+ **options?:** (`MemoryConfig`): Memory configuration options.
36
+
38
37
  ### Options parameters
39
38
 
39
+ **lastMessages?:** (`number | false`): Number of most recent messages to retrieve. Set to false to disable. (Default: `10`)
40
+
41
+ **readOnly?:** (`boolean`): When true, prevents memory from saving new messages and provides working memory as read-only context (without the updateWorkingMemory tool). Useful for read-only operations like previews, internal routing agents, or sub agents that should reference but not modify memory. (Default: `false`)
42
+
43
+ **semanticRecall?:** (`boolean | { topK: number; messageRange: number | { before: number; after: number }; scope?: 'thread' | 'resource' }`): Enable semantic search in message history. Can be a boolean or an object with configuration options. When enabled, requires both vector store and embedder to be configured. Default topK is 4, default messageRange is {before: 1, after: 1}. (Default: `false`)
44
+
45
+ **workingMemory?:** (`WorkingMemory`): Configuration for working memory feature. Can be \`{ enabled: boolean; template?: string; schema?: ZodObject\<any> | JSONSchema7; scope?: 'thread' | 'resource' }\` or \`{ enabled: boolean }\` to disable. (Default: `{ enabled: false, template: '# User Information\n- **First Name**:\n- **Last Name**:\n...' }`)
46
+
47
+ **observationalMemory?:** (`boolean | ObservationalMemoryOptions`): Enable Observational Memory for long-context agentic memory. Set to \`true\` for defaults, or pass a config object to customize token budgets, models, and scope. See \[Observational Memory reference]\(/reference/memory/observational-memory) for configuration details. (Default: `false`)
48
+
49
+ **generateTitle?:** (`boolean | { model: DynamicArgument<MastraLanguageModel>; instructions?: DynamicArgument<string> }`): Controls automatic thread title generation from the user's first message. Can be a boolean or an object with custom model and instructions. (Default: `false`)
50
+
40
51
  ## Returns
41
52
 
53
+ **memory:** (`Memory`): A new Memory instance with the specified configuration.
54
+
42
55
  ## Extended usage example
43
56
 
44
- ```typescript title="src/mastra/agents/test-agent.ts"
57
+ ```typescript
45
58
  import { Memory } from "@mastra/memory";
46
59
  import { Agent } from "@mastra/core/agent";
47
60
  import { LibSQLStore, LibSQLVector } from "@mastra/libsql";
@@ -77,7 +90,7 @@ export const agent = new Agent({
77
90
 
78
91
  ## PostgreSQL with index configuration
79
92
 
80
- ```typescript title="src/mastra/agents/pg-agent.ts"
93
+ ```typescript
81
94
  import { Memory } from "@mastra/memory";
82
95
  import { Agent } from "@mastra/core/agent";
83
96
  import { ModelRouterEmbeddingModel } from "@mastra/core/llm";
@@ -123,6 +136,7 @@ export const agent = new Agent({
123
136
  - [Getting Started with Memory](https://mastra.ai/docs/memory/overview)
124
137
  - [Semantic Recall](https://mastra.ai/docs/memory/semantic-recall)
125
138
  - [Working Memory](https://mastra.ai/docs/memory/working-memory)
139
+ - [Observational Memory](https://mastra.ai/docs/memory/observational-memory)
126
140
  - [Memory Processors](https://mastra.ai/docs/memory/memory-processors)
127
141
  - [createThread](https://mastra.ai/reference/memory/createThread)
128
142
  - [recall](https://mastra.ai/reference/memory/recall)