@mastra/memory 1.32.0 → 1.32.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.
@@ -3,7 +3,7 @@ name: mastra-memory
3
3
  description: Documentation for @mastra/memory. Use when working with @mastra/memory APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/memory"
6
- version: "1.32.0"
6
+ version: "1.32.1"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.32.0",
2
+ "version": "1.32.1",
3
3
  "package": "@mastra/memory",
4
4
  "exports": {},
5
5
  "modules": {
@@ -186,6 +186,7 @@ const memory = new Memory({
186
186
  - Schema-less extractors are inline string extractors emitted directly in the Observer or Reflector output.
187
187
  - Dynamic extractor functions receive runtime context, including `source`, `threadId`, `resourceId`, `mainAgent`, `memory`, and `requestContext` when available.
188
188
  - `WorkingMemoryExtractor` uses the normal extractor pipeline to update working memory through the active `Memory` instance. It uses structured extraction when working memory has a JSON schema and skips OM metadata persistence, so the working memory payload isn't duplicated under OM extracted metadata.
189
+ - When `workingMemory.schema` is set, `WorkingMemoryExtractor` validates each update against that schema before saving it. If an update doesn't match, it's skipped and reported as an extraction failure while the previous working memory stays in place. Because the schema isn't sent to the model as a structured output constraint, one invalid working memory update can't fail other extractors. A `null` in an optional field is treated as not provided.
189
190
  - `observationalMemory.observation.manageWorkingMemory` adds `WorkingMemoryExtractor` and defaults `workingMemory.agentManaged` to `false`. It defaults `workingMemory.useStateSignals` to `true` when working memory is enabled.
190
191
  - Extraction failures are reported in OM marker data and don't discard other successful extracted values.
191
192
 
@@ -87,7 +87,9 @@ Creates a new vector index (collection) in MongoDB.
87
87
 
88
88
  **indexName** (`string`): Name of the collection to create
89
89
 
90
- **dimension** (`number`): Vector dimension (must match your embedding model)
90
+ **dimension** (`number`): Vector dimension (must match your embedding model). Required unless autoEmbed is set, where the embedding model determines the dimension. Passing both is an error.
91
+
92
+ **autoEmbed** (`MongoDBAutoEmbedConfig`): Generate the embeddings in MongoDB instead of supplying vectors. See Automated Embedding for the supported fields.
91
93
 
92
94
  **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
93
95
 
@@ -115,13 +117,13 @@ Adds or updates vectors and their metadata in the collection. On a bring-your-ow
115
117
 
116
118
  **indexName** (`string`): Name of the collection to insert into
117
119
 
118
- **vectors** (`number[][]`): Array of embedding vectors
120
+ **vectors** (`number[][]`): Array of embedding vectors. Required unless the index was created with autoEmbed, where MongoDB generates them from documents and supplying vectors is an error.
119
121
 
120
122
  **metadata** (`Record<string, any>[]`): Metadata for each vector
121
123
 
122
124
  **ids** (`string[]`): Optional vector IDs (auto-generated if not provided)
123
125
 
124
- **documents** (`string[]`): Optional document text content to store alongside vectors
126
+ **documents** (`string[]`): Document text content to store alongside vectors. On an autoEmbed index this is the text MongoDB embeds, and it is required.
125
127
 
126
128
  ### `query()`
127
129
 
@@ -129,7 +131,11 @@ Searches for similar vectors with optional metadata filtering.
129
131
 
130
132
  **indexName** (`string`): Name of the collection to search in
131
133
 
132
- **queryVector** (`number[]`): Query vector to find similar vectors for
134
+ **queryVector** (`number[]`): Query vector to find similar vectors for. Supply this or queryText, not both.
135
+
136
+ **queryText** (`string`): Text for MongoDB to embed at query time. autoEmbed indexes only, and mutually exclusive with queryVector. For full-text matching use textQuery() instead.
137
+
138
+ **model** (`string`): Embedding model for this query, overriding the index's. Requires queryText, and must be compatible with the index's model.
133
139
 
134
140
  **topK** (`number`): Number of results to return (Default: `10`)
135
141
 
@@ -226,7 +232,11 @@ Runs a hybrid search that fuses vector similarity with full-text results through
226
232
 
227
233
  **indexName** (`string`): Name of the Mastra index to search
228
234
 
229
- **queryVector** (`number[]`): Query vector for similarity search
235
+ **queryVector** (`number[]`): Query vector for the vector branch. Supply this or queryText, not both.
236
+
237
+ **queryText** (`string`): Text for MongoDB to embed for the vector branch. autoEmbed indexes only. Independent of query, so each branch can search for something different.
238
+
239
+ **model** (`string`): Embedding model for the vector branch, overriding the index's. Requires queryText.
230
240
 
231
241
  **query** (`string`): Full-text search query string
232
242
 
@@ -273,6 +283,8 @@ interface IndexStats {
273
283
  }
274
284
  ```
275
285
 
286
+ On an `autoEmbed` index, `dimension` is read from the index definition and reports MongoDB's default of `1024` when the index doesn't pin one. `count` counts documents that carry the embedded text field, since the generated vectors aren't stored on your documents.
287
+
276
288
  ### `deleteIndex()`
277
289
 
278
290
  Deletes a vector index. Behavior depends on how the index was created:
@@ -367,6 +379,79 @@ try {
367
379
  }
368
380
  ```
369
381
 
382
+ ## Automated Embedding
383
+
384
+ MongoDB can generate the embeddings for you. Create the index with `autoEmbed` and a Voyage AI model, write plain text through `documents`, and search with `queryText`. No embedding provider runs in your application, and no vectors travel through it.
385
+
386
+ ```typescript
387
+ import { MongoDBVector } from '@mastra/mongodb'
388
+
389
+ const store = new MongoDBVector({
390
+ id: 'mongodb-vector',
391
+ uri: process.env.MONGODB_URI,
392
+ dbName: process.env.MONGODB_DB_NAME,
393
+ })
394
+
395
+ // No `dimension`: the embedding model determines it.
396
+ await store.createIndex({
397
+ indexName: 'movies',
398
+ autoEmbed: { model: 'voyage-4' },
399
+ filterFields: ['year'],
400
+ })
401
+
402
+ // Automated Embedding indexes build slower than client-embedded ones.
403
+ await store.waitForIndexReady({ indexName: 'movies', timeoutMs: 300000 })
404
+
405
+ // No `vectors`: MongoDB embeds the text as documents are written.
406
+ await store.upsert({
407
+ indexName: 'movies',
408
+ documents: [
409
+ 'A lonely astronaut adrift near a strange ocean planet.',
410
+ 'A heist crew robs a bank vault in Paris.',
411
+ ],
412
+ metadata: [{ year: 1972 }, { year: 2001 }],
413
+ })
414
+
415
+ // No `queryVector`: MongoDB embeds the query string with the same model.
416
+ const results = await store.query({
417
+ indexName: 'movies',
418
+ queryText: 'space opera about isolation',
419
+ topK: 5,
420
+ filter: { year: { $gt: 1970 } },
421
+ })
422
+ ```
423
+
424
+ ### `autoEmbed` options
425
+
426
+ **model** (`string`): Voyage AI model to embed with, for example voyage-4. MongoDB rejects a name it does not support and lists the ones it does.
427
+
428
+ **path** (`string`): Text field to embed. Defaults to the managed document field that upsert({ documents }) writes. Point it at a field of your own to index an existing collection in place. (Default: `document`)
429
+
430
+ **similarity** (`'cosine' | 'dotProduct' | 'euclidean'`): Vector similarity function. Defaults to MongoDB's own default when omitted.
431
+
432
+ **numDimensions** (`256 | 512 | 1024 | 2048`): Length of the generated embeddings. (Default: `1024`)
433
+
434
+ **quantization** (`'float' | 'scalar' | 'binary' | 'binaryNoRescore'`): Storage format for the generated vectors. (Default: `scalar`)
435
+
436
+ **indexingMethod** (`'hnsw' | 'flat'`): Index structure for the vector field. (Default: `hnsw`)
437
+
438
+ **hnswOptions** (`{ maxEdges?: number; numEdgeCandidates?: number }`): Tuning for the HNSW graph. MongoDB's defaults suit most workloads.
439
+
440
+ Any other field the `autoEmbed` index definition accepts is forwarded to MongoDB as given, so options added after this release work without a package update. Anything omitted keeps MongoDB's default.
441
+
442
+ **Important notes:**
443
+
444
+ - Automated Embedding is a **MongoDB Preview feature**. It requires an Atlas cluster with Automated Embedding available, or the `mongodb/mongodb-atlas-local:preview` image for local development. Self-managed deployments need `mongot` configured with a Voyage AI API key.
445
+ - The Voyage AI API key must be provisioned through the Atlas UI. A key issued directly by Voyage AI is rejected by the default embedding endpoint.
446
+ - **MongoDB stores the generated vectors outside your collection**, so documents carry text only. `includeVector: true` isn't supported on an `autoEmbed` index and throws.
447
+ - Embeddings are generated asynchronously. A query can legitimately return no results for a short time after a write, even once the index reports ready.
448
+ - An index declares either a vector field or an `autoEmbed` field, never both. Omit `autoEmbed` to keep supplying your own vectors. The client-side path is unchanged.
449
+ - Passing `vectors` to an `autoEmbed` index is an error, since they would be written to a field no index reads.
450
+ - When `document` is the embedded field it's no longer a declared filter field, so `documentFilter` uses the `$match` pre-filter automatically. Metadata filters declared through `filterFields` still push into `$vectorSearch`.
451
+ - `updateVector()` rejects a vector update on an `autoEmbed` index. Upsert the document with new text instead, and MongoDB re-embeds it.
452
+ - `queryVector` still works against an `autoEmbed` index, but the vector must come from a compatible model and match the index `quantization`. MongoDB rejects a mismatch.
453
+ - Embedding generation is billed per token, for both documents and queries.
454
+
370
455
  ## Indexing an existing collection
371
456
 
372
457
  You can create a vector index on an existing operational collection instead of using a managed collection. This is useful when you want to add vector search capabilities to documents that already exist in your MongoDB database.
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("./src-C7u5SaET.cjs");
2
+ const require_src = require("./src-DS-duN3y.cjs");
3
3
  let _mastra_core_processors = require("@mastra/core/processors");
4
4
  exports.Extractor = require_src.Extractor;
5
5
  exports.KnowledgeSemanticIndexCoordinator = require_src.KnowledgeSemanticIndexCoordinator;
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import { C as SUMMARIZE_THREAD_DEFAULTS, G as StaleKnowledgeSemanticIndexError, Q as Extractor, S as WorkingMemoryExtractor, U as Subconscious, W as KnowledgeSemanticIndexCoordinator, a as extractWorkingMemoryContent, b as WorkingMemoryStateProcessor, c as getObservationsAsOf, i as WorkingMemory, n as MessageHistory, o as extractWorkingMemoryTags, q as ModelByInputTokens, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, v as WORKING_MEMORY_STATE_ID, w as summarizeConversation, x as deepMergeWorkingMemory, y as WORKING_MEMORY_STATE_PROCESSOR_ID } from "./src-B0ISVOJX.js";
1
+ import { C as SUMMARIZE_THREAD_DEFAULTS, G as StaleKnowledgeSemanticIndexError, Q as Extractor, S as deepMergeWorkingMemory, U as Subconscious, W as KnowledgeSemanticIndexCoordinator, a as extractWorkingMemoryContent, b as WorkingMemoryStateProcessor, c as getObservationsAsOf, i as WorkingMemory, n as MessageHistory, o as extractWorkingMemoryTags, q as ModelByInputTokens, r as SemanticRecall, s as removeWorkingMemoryTags, t as Memory, v as WORKING_MEMORY_STATE_ID, w as summarizeConversation, x as WorkingMemoryExtractor, y as WORKING_MEMORY_STATE_PROCESSOR_ID } from "./src-DsewkOlu.js";
2
2
  export { Extractor, KnowledgeSemanticIndexCoordinator, Memory, MessageHistory, ModelByInputTokens, SUMMARIZE_THREAD_DEFAULTS, SemanticRecall, StaleKnowledgeSemanticIndexError, Subconscious, WORKING_MEMORY_STATE_ID, WORKING_MEMORY_STATE_PROCESSOR_ID, WorkingMemory, WorkingMemoryExtractor, WorkingMemoryStateProcessor, deepMergeWorkingMemory, extractWorkingMemoryContent, extractWorkingMemoryTags, getObservationsAsOf, removeWorkingMemoryTags, summarizeConversation };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_src = require("../src-C7u5SaET.cjs");
2
+ const require_src = require("../src-DS-duN3y.cjs");
3
3
  exports.Extractor = require_src.Extractor;
4
4
  exports.KnowledgeSemanticIndexCoordinator = require_src.KnowledgeSemanticIndexCoordinator;
5
5
  exports.ModelByInputTokens = require_src.ModelByInputTokens;
@@ -1,2 +1,2 @@
1
- import { A as formatMessagesForObserver, B as OBSERVATION_CONTEXT_PROMPT_THREAD, D as buildObserverPrompt, E as OBSERVER_SYSTEM_PROMPT, F as parseAnchorId, G as StaleKnowledgeSemanticIndexError, H as getObservationContextPrompt, I as stripEphemeralAnchorIds, J as SUBCONSCIOUS_ACTIVITY_STATE_ID, K as SubconsciousRemindExtractor, L as OBSERVATIONAL_MEMORY_DEFAULTS, M as optimizeObservationsForContext, N as parseObserverOutput, O as buildObserverSystemPrompt, P as injectAnchorIds, Q as Extractor, R as OBSERVATION_CONTEXT_INSTRUCTIONS, S as WorkingMemoryExtractor, T as TokenCounter, U as Subconscious, V as OBSERVATION_CONTINUATION_HINT, W as KnowledgeSemanticIndexCoordinator, X as publishSubconsciousActivity, Y as buildSubconsciousActivitySnapshot, Z as renderSubconsciousActivity, _ as wrapInObservationGroup, c as getObservationsAsOf, d as combineObservationGroupRanges, f as deriveObservationGroupProvenance, g as stripObservationGroups, h as renderObservationGroupsForReflection, j as hasCurrentTaskSection, k as extractCurrentTask, l as ObservationalMemoryProcessor, m as reconcileObservationGroupsFromReflection, p as parseObservationGroups, q as ModelByInputTokens, u as ObservationalMemory, w as summarizeConversation, z as OBSERVATION_CONTEXT_PROMPT } from "../src-B0ISVOJX.js";
1
+ import { A as formatMessagesForObserver, B as OBSERVATION_CONTEXT_PROMPT_THREAD, D as buildObserverPrompt, E as OBSERVER_SYSTEM_PROMPT, F as parseAnchorId, G as StaleKnowledgeSemanticIndexError, H as getObservationContextPrompt, I as stripEphemeralAnchorIds, J as SUBCONSCIOUS_ACTIVITY_STATE_ID, K as SubconsciousRemindExtractor, L as OBSERVATIONAL_MEMORY_DEFAULTS, M as optimizeObservationsForContext, N as parseObserverOutput, O as buildObserverSystemPrompt, P as injectAnchorIds, Q as Extractor, R as OBSERVATION_CONTEXT_INSTRUCTIONS, T as TokenCounter, U as Subconscious, V as OBSERVATION_CONTINUATION_HINT, W as KnowledgeSemanticIndexCoordinator, X as publishSubconsciousActivity, Y as buildSubconsciousActivitySnapshot, Z as renderSubconsciousActivity, _ as wrapInObservationGroup, c as getObservationsAsOf, d as combineObservationGroupRanges, f as deriveObservationGroupProvenance, g as stripObservationGroups, h as renderObservationGroupsForReflection, j as hasCurrentTaskSection, k as extractCurrentTask, l as ObservationalMemoryProcessor, m as reconcileObservationGroupsFromReflection, p as parseObservationGroups, q as ModelByInputTokens, u as ObservationalMemory, w as summarizeConversation, x as WorkingMemoryExtractor, z as OBSERVATION_CONTEXT_PROMPT } from "../src-DsewkOlu.js";
2
2
  export { Extractor, KnowledgeSemanticIndexCoordinator, ModelByInputTokens, OBSERVATIONAL_MEMORY_DEFAULTS, OBSERVATION_CONTEXT_INSTRUCTIONS, OBSERVATION_CONTEXT_PROMPT, OBSERVATION_CONTEXT_PROMPT_THREAD, OBSERVATION_CONTINUATION_HINT, OBSERVER_SYSTEM_PROMPT, ObservationalMemory, ObservationalMemoryProcessor, SUBCONSCIOUS_ACTIVITY_STATE_ID, StaleKnowledgeSemanticIndexError, Subconscious, SubconsciousRemindExtractor, TokenCounter, WorkingMemoryExtractor, buildObserverPrompt, buildObserverSystemPrompt, buildSubconsciousActivitySnapshot, combineObservationGroupRanges, deriveObservationGroupProvenance, extractCurrentTask, formatMessagesForObserver, getObservationContextPrompt, getObservationsAsOf, hasCurrentTaskSection, injectAnchorIds, optimizeObservationsForContext, parseAnchorId, parseObservationGroups, parseObserverOutput, publishSubconsciousActivity, reconcileObservationGroupsFromReflection, renderObservationGroupsForReflection, renderSubconsciousActivity, stripEphemeralAnchorIds, stripObservationGroups, summarizeConversation, wrapInObservationGroup };
@@ -1 +1 @@
1
- {"version":3,"file":"working-memory-extractor.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/working-memory-extractor.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAyDxC,qBAAa,sBAAuB,SAAQ,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;;CAqC7F"}
1
+ {"version":3,"file":"working-memory-extractor.d.ts","sourceRoot":"","sources":["../../../src/processors/observational-memory/working-memory-extractor.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAgFxC,qBAAa,sBAAuB,SAAQ,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;;CAyC7F"}