@mastra/mongodb 1.23.2-alpha.0 → 1.24.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.
@@ -3,7 +3,7 @@ name: mastra-mongodb
3
3
  description: Documentation for @mastra/mongodb. Use when working with @mastra/mongodb APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/mongodb"
6
- version: "1.23.2-alpha.0"
6
+ version: "1.24.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.23.2-alpha.0",
2
+ "version": "1.24.0",
3
3
  "package": "@mastra/mongodb",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -403,6 +403,28 @@ Memory uses a single embedder for both storing and recalling messages, so pick o
403
403
 
404
404
  Multilingual E5 produces 1024-dimensional vectors. Your vector index must be created with matching dimensions, and E5 vectors can't be mixed with vectors from another embedder in the same index.
405
405
 
406
+ FastEmbed models embed at most 512 tokens per input (roughly 2,000 to 2,500 characters of English text). Longer inputs are truncated, so text past the limit doesn't affect the embedding and can't be found by semantic recall. The AI SDK v3 FastEmbed models return a warning when this happens. The legacy v1 and v2 models don't. If you embed long documents with FastEmbed, chunk them to fit the window, for example with `maxSize: 1500` in `MDocument.chunk()`.
407
+
408
+ ### Setting the embedding dimension
409
+
410
+ To name the vector index, Memory needs the embedder's output dimension. By default it finds the dimension by embedding a short probe string the first time semantic recall is set up, once per `Memory` instance. If you already know the dimension, set `embeddingDimension`. Memory then skips the probe, so startup makes no embedding call and doesn't depend on the embedding provider being reachable:
411
+
412
+ ```ts
413
+ import { Memory } from '@mastra/memory'
414
+
415
+ const memory = new Memory({
416
+ embedder: 'openai/text-embedding-3-small',
417
+ embeddingDimension: 1536,
418
+ options: {
419
+ semanticRecall: true,
420
+ },
421
+ })
422
+ ```
423
+
424
+ The index name is the same whether the dimension is configured or probed, so existing indexes keep working.
425
+
426
+ The value must match the vectors the embedder returns. Memory compares it with the first real embedding, and on a mismatch it throws a `MASTRA_MEMORY_EMBEDDING_DIMENSION_MISMATCH` error naming both values before creating or querying any index. Update `embeddingDimension` whenever you change the embedding model or its output dimension.
427
+
406
428
  ## PostgreSQL index optimization
407
429
 
408
430
  When using PostgreSQL as your vector store, you can optimize semantic recall performance by configuring the vector index. This is particularly important for large-scale deployments with thousands of messages.
@@ -217,7 +217,7 @@ const paragraphMemory = new Memory({
217
217
 
218
218
  Working memory can also be defined using a structured schema instead of a Markdown template. A [Standard JSON Schema](https://standardschema.dev/json-schema) ([Zod](https://zod.dev/), [Valibot](https://valibot.dev/), [ArkType](https://arktype.io/), etc.). When using a schema, the agent will see and update working memory as a JSON object matching your schema.
219
219
 
220
- **Requirement:** You must specify either `template` or `schema`, but not both.
220
+ You can specify either `template` or `schema`, but not both. If you omit both, Mastra uses the default working memory template.
221
221
 
222
222
  ### Example: Schema-Based Working Memory
223
223
 
package/dist/index.cjs CHANGED
@@ -10,7 +10,7 @@ let _mastra_core_agent = require("@mastra/core/agent");
10
10
  let _mastra_core_evals = require("@mastra/core/evals");
11
11
  let _mastra_core_storage_domains_skills = require("@mastra/core/storage/domains/skills");
12
12
  //#region package.json
13
- var version = "1.23.2-alpha.0";
13
+ var version = "1.24.0";
14
14
  //#endregion
15
15
  //#region src/vector/filter.ts
16
16
  /**
@@ -42,13 +42,15 @@ var MongoDBFilterTranslator = class extends _mastra_core_vector_filter.BaseFilte
42
42
  return Object.fromEntries(translatedEntries);
43
43
  }
44
44
  translateOperatorValue(operator, value) {
45
- if (this.isLogicalOperator(operator)) if (operator === "$not") {
46
- if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("$not operator requires an object");
47
- if (this.isEmpty(value)) throw new Error("$not operator cannot be empty");
48
- return this.translateNode(value);
49
- } else {
50
- if (!Array.isArray(value)) throw new Error(`Value for logical operator ${operator} must be an array`);
51
- return value.map((item) => this.translateNode(item));
45
+ if (this.isLogicalOperator(operator)) {
46
+ if (operator === "$not") {
47
+ if (typeof value !== "object" || value === null || Array.isArray(value)) throw new Error("$not operator requires an object");
48
+ if (this.isEmpty(value)) throw new Error("$not operator cannot be empty");
49
+ return this.translateNode(value);
50
+ } else {
51
+ if (!Array.isArray(value)) throw new Error(`Value for logical operator ${operator} must be an array`);
52
+ return value.map((item) => this.translateNode(item));
53
+ }
52
54
  }
53
55
  if (this.isBasicOperator(operator) || this.isNumericOperator(operator)) {
54
56
  if (value instanceof Date) return value.toISOString();
@@ -1532,17 +1534,19 @@ var MongoDBVector = class MongoDBVector extends _mastra_core_vector.MastraVector
1532
1534
  if (Array.isArray(filter)) return filter.map((item) => this.transformMetadataFilter(item, metadataMode));
1533
1535
  if (metadataMode === "document") {
1534
1536
  const transformed = {};
1535
- for (const [key, value] of Object.entries(filter)) if (key.startsWith("$")) if (Array.isArray(value)) transformed[key] = value.map((item) => this.transformMetadataFilter(item, metadataMode));
1536
- else if (typeof value === "object" && value !== null) transformed[key] = this.transformMetadataFilter(value, metadataMode);
1537
- else transformed[key] = value;
1538
- else transformed[key] = value;
1537
+ for (const [key, value] of Object.entries(filter)) if (key.startsWith("$")) {
1538
+ if (Array.isArray(value)) transformed[key] = value.map((item) => this.transformMetadataFilter(item, metadataMode));
1539
+ else if (typeof value === "object" && value !== null) transformed[key] = this.transformMetadataFilter(value, metadataMode);
1540
+ else transformed[key] = value;
1541
+ } else transformed[key] = value;
1539
1542
  return transformed;
1540
1543
  }
1541
1544
  const transformed = {};
1542
- for (const [key, value] of Object.entries(filter)) if (key.startsWith("$")) if (Array.isArray(value)) transformed[key] = value.map((item) => this.transformMetadataFilter(item, metadataMode));
1543
- else if (typeof value === "object" && value !== null) transformed[key] = this.transformMetadataFilter(value, metadataMode);
1544
- else transformed[key] = value;
1545
- else if (key.startsWith("metadata.")) transformed[key] = value;
1545
+ for (const [key, value] of Object.entries(filter)) if (key.startsWith("$")) {
1546
+ if (Array.isArray(value)) transformed[key] = value.map((item) => this.transformMetadataFilter(item, metadataMode));
1547
+ else if (typeof value === "object" && value !== null) transformed[key] = this.transformMetadataFilter(value, metadataMode);
1548
+ else transformed[key] = value;
1549
+ } else if (key.startsWith("metadata.")) transformed[key] = value;
1546
1550
  else if (this.isMetadataField(key)) transformed[`metadata.${key}`] = value;
1547
1551
  else transformed[key] = value;
1548
1552
  return transformed;
@@ -3211,6 +3215,7 @@ var MongoDBDatasetsStorage = class extends _mastra_core_storage.DatasetsStorage
3211
3215
  const { page, perPage: perPageInput } = args.pagination;
3212
3216
  const collection = await this.getCollection(_mastra_core_storage.TABLE_DATASETS);
3213
3217
  const filter = {};
3218
+ if (args.filters?.datasetIds !== void 0) filter.id = { $in: args.filters.datasetIds };
3214
3219
  if (args.filters?.organizationId !== void 0) filter.organizationId = args.filters.organizationId;
3215
3220
  if (args.filters?.projectId !== void 0) filter.projectId = args.filters.projectId;
3216
3221
  if (args.filters?.candidateKey !== void 0) filter.candidateKey = args.filters.candidateKey;
@@ -9576,15 +9581,13 @@ MIGRATION REQUIRED: Duplicate spans detected in ${_mastra_core_storage.TABLE_SPA
9576
9581
  error: null
9577
9582
  });
9578
9583
  break;
9579
- case _mastra_core_storage.TraceStatus.SUCCESS:
9580
- andConditions.push({
9581
- endedAt: {
9582
- $exists: true,
9583
- $ne: null
9584
- },
9585
- error: null
9586
- });
9587
- break;
9584
+ case _mastra_core_storage.TraceStatus.SUCCESS: andConditions.push({
9585
+ endedAt: {
9586
+ $exists: true,
9587
+ $ne: null
9588
+ },
9589
+ error: null
9590
+ });
9588
9591
  }
9589
9592
  }
9590
9593
  if (andConditions.length) mongoFilter.$and = andConditions;
@@ -12366,8 +12369,10 @@ var WorkflowsStorageMongoDB = class WorkflowsStorageMongoDB extends _mastra_core
12366
12369
  if (options.workflowName) query["workflow_name"] = options.workflowName;
12367
12370
  if (options.status) query["snapshot.status"] = options.status;
12368
12371
  if (options.fromDate) query["createdAt"] = { $gte: options.fromDate };
12369
- if (options.toDate) if (query["createdAt"]) query["createdAt"].$lte = options.toDate;
12370
- else query["createdAt"] = { $lte: options.toDate };
12372
+ if (options.toDate) {
12373
+ if (query["createdAt"]) query["createdAt"].$lte = options.toDate;
12374
+ else query["createdAt"] = { $lte: options.toDate };
12375
+ }
12371
12376
  if (options.resourceId) query["resourceId"] = options.resourceId;
12372
12377
  const collection = await this.getCollection(_mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT);
12373
12378
  let total = 0;