@mastra/mongodb 0.0.5 → 0.0.6-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.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/mongodb@0.0.5-alpha.4 build /home/runner/work/mastra/mastra/stores/mongodb
2
+ > @mastra/mongodb@0.0.6-alpha.0 build /home/runner/work/mastra/mastra/stores/mongodb
3
3
  > tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.4.0
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 7651ms
9
+ TSC ⚡️ Build success in 6675ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.8.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.ts
14
14
  Analysis will use the bundled TypeScript version 5.8.3
15
15
  Writing package typings: /home/runner/work/mastra/mastra/stores/mongodb/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 9483ms
16
+ DTS ⚡️ Build success in 8933ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 19.08 KB
21
- ESM ⚡️ Build success in 675ms
22
- CJS dist/index.cjs 19.13 KB
23
- CJS ⚡️ Build success in 681ms
20
+ CJS dist/index.cjs 20.42 KB
21
+ CJS ⚡️ Build success in 734ms
22
+ ESM dist/index.js 20.37 KB
23
+ ESM ⚡️ Build success in 737ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @mastra/mongodb
2
2
 
3
+ ## 0.0.6-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
8
+ - Updated dependencies [f53a6ac]
9
+ - Updated dependencies [eabdcd9]
10
+ - Updated dependencies [90be034]
11
+ - Updated dependencies [99f050a]
12
+ - Updated dependencies [d0ee3c6]
13
+ - Updated dependencies [23f258c]
14
+ - Updated dependencies [2672a05]
15
+ - @mastra/core@0.9.5-alpha.0
16
+
3
17
  ## 0.0.5
4
18
 
5
19
  ### Patch Changes
@@ -1,5 +1,8 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
2
  import type { CreateIndexParams } from '@mastra/core/vector';
3
+ import type { DeleteIndexParams } from '@mastra/core/vector';
4
+ import type { DeleteVectorParams } from '@mastra/core/vector';
5
+ import type { DescribeIndexParams } from '@mastra/core/vector';
3
6
  import type { IndexStats } from '@mastra/core/vector';
4
7
  import { MastraVector } from '@mastra/core/vector';
5
8
  import type { MongoClientOptions } from 'mongodb';
@@ -8,6 +11,7 @@ import type { ParamsToArgs } from '@mastra/core/vector';
8
11
  import type { QueryResult } from '@mastra/core/vector';
9
12
  import type { QueryVectorArgs } from '@mastra/core/vector';
10
13
  import type { QueryVectorParams } from '@mastra/core/vector';
14
+ import type { UpdateVectorParams } from '@mastra/core/vector';
11
15
  import type { UpsertVectorArgs } from '@mastra/core/vector';
12
16
  import type { UpsertVectorParams } from '@mastra/core/vector';
13
17
  import type { VectorFilter } from '@mastra/core/vector/filter';
@@ -33,6 +37,16 @@ export declare class MongoDBFilterTranslator extends BaseFilterTranslator {
33
37
  isEmpty(filter: any): boolean;
34
38
  }
35
39
 
40
+ declare type MongoDBIndexReadyArgs = [string, number?, number?];
41
+
42
+ declare interface MongoDBIndexReadyParams {
43
+ indexName: string;
44
+ timeoutMs?: number;
45
+ checkIntervalMs?: number;
46
+ }
47
+ export { MongoDBIndexReadyParams }
48
+ export { MongoDBIndexReadyParams as MongoDBIndexReadyParams_alias_1 }
49
+
36
50
  declare type MongoDBQueryArgs = [...QueryVectorArgs, string?];
37
51
  export { MongoDBQueryArgs }
38
52
  export { MongoDBQueryArgs as MongoDBQueryArgs_alias_1 }
@@ -74,12 +88,28 @@ declare class MongoDBVector extends MastraVector {
74
88
  connect(): Promise<void>;
75
89
  disconnect(): Promise<void>;
76
90
  createIndex(params: CreateIndexParams): Promise<void>;
77
- waitForIndexReady(indexName: string, timeoutMs?: number, checkIntervalMs?: number): Promise<void>;
91
+ /**
92
+ * Waits for the index to be ready.
93
+ *
94
+ * @param params - The parameters for waiting for the index to be ready
95
+ * @param params.indexName - The name of the index to wait for
96
+ * @param params.timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
97
+ * @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
98
+ * @returns A promise that resolves when the index is ready
99
+ */
100
+ waitForIndexReady(...args: ParamsToArgs<MongoDBIndexReadyParams> | MongoDBIndexReadyArgs): Promise<void>;
78
101
  upsert(params: MongoDBUpsertVectorParams): Promise<string[]>;
79
102
  query(params: MongoDBQueryVectorParams): Promise<QueryResult[]>;
80
103
  listIndexes(): Promise<string[]>;
81
- describeIndex(indexName: string): Promise<IndexStats>;
82
- deleteIndex(indexName: string): Promise<void>;
104
+ /**
105
+ * Retrieves statistics about a vector index.
106
+ *
107
+ * @param params - The parameters for describing an index
108
+ * @param params.indexName - The name of the index to describe
109
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
110
+ */
111
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
112
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
83
113
  /**
84
114
  * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
85
115
  *
@@ -106,10 +136,7 @@ declare class MongoDBVector extends MastraVector {
106
136
  * @returns A promise that resolves when the update is complete.
107
137
  * @throws Will throw an error if no updates are provided or if the update operation fails.
108
138
  */
109
- updateVector(indexName: string, id: string, update: {
110
- vector?: number[];
111
- metadata?: Record<string, any>;
112
- }): Promise<void>;
139
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
113
140
  /**
114
141
  * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
115
142
  *
@@ -127,7 +154,7 @@ declare class MongoDBVector extends MastraVector {
127
154
  * @returns A promise that resolves when the deletion is complete.
128
155
  * @throws Will throw an error if the deletion operation fails.
129
156
  */
130
- deleteVector(indexName: string, id: string): Promise<void>;
157
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
131
158
  private getCollection;
132
159
  private validateVectorDimensions;
133
160
  private setIndexDimension;
@@ -1,5 +1,8 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
2
  import type { CreateIndexParams } from '@mastra/core/vector';
3
+ import type { DeleteIndexParams } from '@mastra/core/vector';
4
+ import type { DeleteVectorParams } from '@mastra/core/vector';
5
+ import type { DescribeIndexParams } from '@mastra/core/vector';
3
6
  import type { IndexStats } from '@mastra/core/vector';
4
7
  import { MastraVector } from '@mastra/core/vector';
5
8
  import type { MongoClientOptions } from 'mongodb';
@@ -8,6 +11,7 @@ import type { ParamsToArgs } from '@mastra/core/vector';
8
11
  import type { QueryResult } from '@mastra/core/vector';
9
12
  import type { QueryVectorArgs } from '@mastra/core/vector';
10
13
  import type { QueryVectorParams } from '@mastra/core/vector';
14
+ import type { UpdateVectorParams } from '@mastra/core/vector';
11
15
  import type { UpsertVectorArgs } from '@mastra/core/vector';
12
16
  import type { UpsertVectorParams } from '@mastra/core/vector';
13
17
  import type { VectorFilter } from '@mastra/core/vector/filter';
@@ -33,6 +37,16 @@ export declare class MongoDBFilterTranslator extends BaseFilterTranslator {
33
37
  isEmpty(filter: any): boolean;
34
38
  }
35
39
 
40
+ declare type MongoDBIndexReadyArgs = [string, number?, number?];
41
+
42
+ declare interface MongoDBIndexReadyParams {
43
+ indexName: string;
44
+ timeoutMs?: number;
45
+ checkIntervalMs?: number;
46
+ }
47
+ export { MongoDBIndexReadyParams }
48
+ export { MongoDBIndexReadyParams as MongoDBIndexReadyParams_alias_1 }
49
+
36
50
  declare type MongoDBQueryArgs = [...QueryVectorArgs, string?];
37
51
  export { MongoDBQueryArgs }
38
52
  export { MongoDBQueryArgs as MongoDBQueryArgs_alias_1 }
@@ -74,12 +88,28 @@ declare class MongoDBVector extends MastraVector {
74
88
  connect(): Promise<void>;
75
89
  disconnect(): Promise<void>;
76
90
  createIndex(params: CreateIndexParams): Promise<void>;
77
- waitForIndexReady(indexName: string, timeoutMs?: number, checkIntervalMs?: number): Promise<void>;
91
+ /**
92
+ * Waits for the index to be ready.
93
+ *
94
+ * @param params - The parameters for waiting for the index to be ready
95
+ * @param params.indexName - The name of the index to wait for
96
+ * @param params.timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
97
+ * @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
98
+ * @returns A promise that resolves when the index is ready
99
+ */
100
+ waitForIndexReady(...args: ParamsToArgs<MongoDBIndexReadyParams> | MongoDBIndexReadyArgs): Promise<void>;
78
101
  upsert(params: MongoDBUpsertVectorParams): Promise<string[]>;
79
102
  query(params: MongoDBQueryVectorParams): Promise<QueryResult[]>;
80
103
  listIndexes(): Promise<string[]>;
81
- describeIndex(indexName: string): Promise<IndexStats>;
82
- deleteIndex(indexName: string): Promise<void>;
104
+ /**
105
+ * Retrieves statistics about a vector index.
106
+ *
107
+ * @param params - The parameters for describing an index
108
+ * @param params.indexName - The name of the index to describe
109
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
110
+ */
111
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
112
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
83
113
  /**
84
114
  * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
85
115
  *
@@ -106,10 +136,7 @@ declare class MongoDBVector extends MastraVector {
106
136
  * @returns A promise that resolves when the update is complete.
107
137
  * @throws Will throw an error if no updates are provided or if the update operation fails.
108
138
  */
109
- updateVector(indexName: string, id: string, update: {
110
- vector?: number[];
111
- metadata?: Record<string, any>;
112
- }): Promise<void>;
139
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
113
140
  /**
114
141
  * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
115
142
  *
@@ -127,7 +154,7 @@ declare class MongoDBVector extends MastraVector {
127
154
  * @returns A promise that resolves when the deletion is complete.
128
155
  * @throws Will throw an error if the deletion operation fails.
129
156
  */
130
- deleteVector(indexName: string, id: string): Promise<void>;
157
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
131
158
  private getCollection;
132
159
  private validateVectorDimensions;
133
160
  private setIndexDimension;
package/dist/index.cjs CHANGED
@@ -160,7 +160,21 @@ var MongoDBVector = class extends vector.MastraVector {
160
160
  }
161
161
  await collection.updateOne({ _id: "__index_metadata__" }, { $set: { dimension, metric } }, { upsert: true });
162
162
  }
163
- async waitForIndexReady(indexName, timeoutMs = 6e4, checkIntervalMs = 2e3) {
163
+ /**
164
+ * Waits for the index to be ready.
165
+ *
166
+ * @param params - The parameters for waiting for the index to be ready
167
+ * @param params.indexName - The name of the index to wait for
168
+ * @param params.timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
169
+ * @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
170
+ * @returns A promise that resolves when the index is ready
171
+ */
172
+ async waitForIndexReady(...args) {
173
+ const params = this.normalizeArgs("waitForIndexReady", args, [
174
+ "timeoutMs",
175
+ "checkIntervalMs"
176
+ ]);
177
+ const { indexName, timeoutMs = 6e4, checkIntervalMs = 2e3 } = params;
164
178
  const collection = await this.getCollection(indexName, true);
165
179
  const indexNameInternal = `${indexName}_vector_index`;
166
180
  const startTime = Date.now();
@@ -179,7 +193,7 @@ var MongoDBVector = class extends vector.MastraVector {
179
193
  const { indexName, vectors, metadata, ids, documents } = params;
180
194
  const collection = await this.getCollection(indexName);
181
195
  this.collectionForValidation = collection;
182
- const stats = await this.describeIndex(indexName);
196
+ const stats = await this.describeIndex({ indexName });
183
197
  await this.validateVectorDimensions(vectors, stats.dimension);
184
198
  const generatedIds = ids || vectors.map(() => uuid.v4());
185
199
  const operations = vectors.map((vector, idx) => {
@@ -269,7 +283,16 @@ var MongoDBVector = class extends vector.MastraVector {
269
283
  const collections = await this.db.listCollections().toArray();
270
284
  return collections.map((col) => col.name);
271
285
  }
272
- async describeIndex(indexName) {
286
+ /**
287
+ * Retrieves statistics about a vector index.
288
+ *
289
+ * @param params - The parameters for describing an index
290
+ * @param params.indexName - The name of the index to describe
291
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
292
+ */
293
+ async describeIndex(...args) {
294
+ const params = this.normalizeArgs("describeIndex", args);
295
+ const { indexName } = params;
273
296
  const collection = await this.getCollection(indexName, true);
274
297
  const count = await collection.countDocuments({ _id: { $ne: "__index_metadata__" } });
275
298
  const metadataDoc = await collection.findOne({ _id: "__index_metadata__" });
@@ -281,7 +304,9 @@ var MongoDBVector = class extends vector.MastraVector {
281
304
  metric
282
305
  };
283
306
  }
284
- async deleteIndex(indexName) {
307
+ async deleteIndex(...args) {
308
+ const params = this.normalizeArgs("deleteIndex", args);
309
+ const { indexName } = params;
285
310
  const collection = await this.getCollection(indexName, false);
286
311
  if (collection) {
287
312
  await collection.drop();
@@ -308,7 +333,7 @@ var MongoDBVector = class extends vector.MastraVector {
308
333
  Please use updateVector() instead.
309
334
  updateIndexById() will be removed on May 20th, 2025.`
310
335
  );
311
- await this.updateVector(indexName, id, update);
336
+ await this.updateVector({ indexName, id, update });
312
337
  }
313
338
  /**
314
339
  * Updates a vector by its ID with the provided vector and/or metadata.
@@ -320,7 +345,9 @@ var MongoDBVector = class extends vector.MastraVector {
320
345
  * @returns A promise that resolves when the update is complete.
321
346
  * @throws Will throw an error if no updates are provided or if the update operation fails.
322
347
  */
323
- async updateVector(indexName, id, update) {
348
+ async updateVector(...args) {
349
+ const params = this.normalizeArgs("updateVector", args);
350
+ const { indexName, id, update } = params;
324
351
  try {
325
352
  if (!update.vector && !update.metadata) {
326
353
  throw new Error("No updates provided");
@@ -328,7 +355,7 @@ var MongoDBVector = class extends vector.MastraVector {
328
355
  const collection = await this.getCollection(indexName, true);
329
356
  const updateDoc = {};
330
357
  if (update.vector) {
331
- const stats = await this.describeIndex(indexName);
358
+ const stats = await this.describeIndex({ indexName });
332
359
  await this.validateVectorDimensions([update.vector], stats.dimension);
333
360
  updateDoc[this.embeddingFieldName] = update.vector;
334
361
  }
@@ -362,7 +389,7 @@ var MongoDBVector = class extends vector.MastraVector {
362
389
  Please use deleteVector() instead.
363
390
  deleteIndexById() will be removed on May 20th, 2025.`
364
391
  );
365
- await this.deleteVector(indexName, id);
392
+ await this.deleteVector({ indexName, id });
366
393
  }
367
394
  /**
368
395
  * Deletes a vector by its ID.
@@ -371,7 +398,9 @@ var MongoDBVector = class extends vector.MastraVector {
371
398
  * @returns A promise that resolves when the deletion is complete.
372
399
  * @throws Will throw an error if the deletion operation fails.
373
400
  */
374
- async deleteVector(indexName, id) {
401
+ async deleteVector(...args) {
402
+ const params = this.normalizeArgs("deleteVector", args);
403
+ const { indexName, id } = params;
375
404
  try {
376
405
  const collection = await this.getCollection(indexName, true);
377
406
  await collection.deleteOne({ _id: id });
package/dist/index.d.cts CHANGED
@@ -4,4 +4,5 @@ export { MongoDBQueryArgs } from './_tsup-dts-rollup.cjs';
4
4
  export { MongoDBUpsertParams } from './_tsup-dts-rollup.cjs';
5
5
  export { MongoDBUpsertVectorParams } from './_tsup-dts-rollup.cjs';
6
6
  export { MongoDBQueryVectorParams } from './_tsup-dts-rollup.cjs';
7
+ export { MongoDBIndexReadyParams } from './_tsup-dts-rollup.cjs';
7
8
  export { MongoDBVector } from './_tsup-dts-rollup.cjs';
package/dist/index.d.ts CHANGED
@@ -4,4 +4,5 @@ export { MongoDBQueryArgs } from './_tsup-dts-rollup.js';
4
4
  export { MongoDBUpsertParams } from './_tsup-dts-rollup.js';
5
5
  export { MongoDBUpsertVectorParams } from './_tsup-dts-rollup.js';
6
6
  export { MongoDBQueryVectorParams } from './_tsup-dts-rollup.js';
7
+ export { MongoDBIndexReadyParams } from './_tsup-dts-rollup.js';
7
8
  export { MongoDBVector } from './_tsup-dts-rollup.js';
package/dist/index.js CHANGED
@@ -158,7 +158,21 @@ var MongoDBVector = class extends MastraVector {
158
158
  }
159
159
  await collection.updateOne({ _id: "__index_metadata__" }, { $set: { dimension, metric } }, { upsert: true });
160
160
  }
161
- async waitForIndexReady(indexName, timeoutMs = 6e4, checkIntervalMs = 2e3) {
161
+ /**
162
+ * Waits for the index to be ready.
163
+ *
164
+ * @param params - The parameters for waiting for the index to be ready
165
+ * @param params.indexName - The name of the index to wait for
166
+ * @param params.timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
167
+ * @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
168
+ * @returns A promise that resolves when the index is ready
169
+ */
170
+ async waitForIndexReady(...args) {
171
+ const params = this.normalizeArgs("waitForIndexReady", args, [
172
+ "timeoutMs",
173
+ "checkIntervalMs"
174
+ ]);
175
+ const { indexName, timeoutMs = 6e4, checkIntervalMs = 2e3 } = params;
162
176
  const collection = await this.getCollection(indexName, true);
163
177
  const indexNameInternal = `${indexName}_vector_index`;
164
178
  const startTime = Date.now();
@@ -177,7 +191,7 @@ var MongoDBVector = class extends MastraVector {
177
191
  const { indexName, vectors, metadata, ids, documents } = params;
178
192
  const collection = await this.getCollection(indexName);
179
193
  this.collectionForValidation = collection;
180
- const stats = await this.describeIndex(indexName);
194
+ const stats = await this.describeIndex({ indexName });
181
195
  await this.validateVectorDimensions(vectors, stats.dimension);
182
196
  const generatedIds = ids || vectors.map(() => v4());
183
197
  const operations = vectors.map((vector, idx) => {
@@ -267,7 +281,16 @@ var MongoDBVector = class extends MastraVector {
267
281
  const collections = await this.db.listCollections().toArray();
268
282
  return collections.map((col) => col.name);
269
283
  }
270
- async describeIndex(indexName) {
284
+ /**
285
+ * Retrieves statistics about a vector index.
286
+ *
287
+ * @param params - The parameters for describing an index
288
+ * @param params.indexName - The name of the index to describe
289
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
290
+ */
291
+ async describeIndex(...args) {
292
+ const params = this.normalizeArgs("describeIndex", args);
293
+ const { indexName } = params;
271
294
  const collection = await this.getCollection(indexName, true);
272
295
  const count = await collection.countDocuments({ _id: { $ne: "__index_metadata__" } });
273
296
  const metadataDoc = await collection.findOne({ _id: "__index_metadata__" });
@@ -279,7 +302,9 @@ var MongoDBVector = class extends MastraVector {
279
302
  metric
280
303
  };
281
304
  }
282
- async deleteIndex(indexName) {
305
+ async deleteIndex(...args) {
306
+ const params = this.normalizeArgs("deleteIndex", args);
307
+ const { indexName } = params;
283
308
  const collection = await this.getCollection(indexName, false);
284
309
  if (collection) {
285
310
  await collection.drop();
@@ -306,7 +331,7 @@ var MongoDBVector = class extends MastraVector {
306
331
  Please use updateVector() instead.
307
332
  updateIndexById() will be removed on May 20th, 2025.`
308
333
  );
309
- await this.updateVector(indexName, id, update);
334
+ await this.updateVector({ indexName, id, update });
310
335
  }
311
336
  /**
312
337
  * Updates a vector by its ID with the provided vector and/or metadata.
@@ -318,7 +343,9 @@ var MongoDBVector = class extends MastraVector {
318
343
  * @returns A promise that resolves when the update is complete.
319
344
  * @throws Will throw an error if no updates are provided or if the update operation fails.
320
345
  */
321
- async updateVector(indexName, id, update) {
346
+ async updateVector(...args) {
347
+ const params = this.normalizeArgs("updateVector", args);
348
+ const { indexName, id, update } = params;
322
349
  try {
323
350
  if (!update.vector && !update.metadata) {
324
351
  throw new Error("No updates provided");
@@ -326,7 +353,7 @@ var MongoDBVector = class extends MastraVector {
326
353
  const collection = await this.getCollection(indexName, true);
327
354
  const updateDoc = {};
328
355
  if (update.vector) {
329
- const stats = await this.describeIndex(indexName);
356
+ const stats = await this.describeIndex({ indexName });
330
357
  await this.validateVectorDimensions([update.vector], stats.dimension);
331
358
  updateDoc[this.embeddingFieldName] = update.vector;
332
359
  }
@@ -360,7 +387,7 @@ var MongoDBVector = class extends MastraVector {
360
387
  Please use deleteVector() instead.
361
388
  deleteIndexById() will be removed on May 20th, 2025.`
362
389
  );
363
- await this.deleteVector(indexName, id);
390
+ await this.deleteVector({ indexName, id });
364
391
  }
365
392
  /**
366
393
  * Deletes a vector by its ID.
@@ -369,7 +396,9 @@ var MongoDBVector = class extends MastraVector {
369
396
  * @returns A promise that resolves when the deletion is complete.
370
397
  * @throws Will throw an error if the deletion operation fails.
371
398
  */
372
- async deleteVector(indexName, id) {
399
+ async deleteVector(...args) {
400
+ const params = this.normalizeArgs("deleteVector", args);
401
+ const { indexName, id } = params;
373
402
  try {
374
403
  const collection = await this.getCollection(indexName, true);
375
404
  await collection.deleteOne({ _id: id });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mongodb",
3
- "version": "0.0.5",
3
+ "version": "0.0.6-alpha.0",
4
4
  "description": "MongoDB provider for Mastra - includes vector store capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -23,7 +23,7 @@
23
23
  "cloudflare": "^4.1.0",
24
24
  "mongodb": "^6.15.0",
25
25
  "uuid": "^11.1.0",
26
- "@mastra/core": "^0.9.4"
26
+ "@mastra/core": "^0.9.5-alpha.0"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@microsoft/api-extractor": "^7.52.5",
@@ -60,7 +60,7 @@ async function createIndexAndWait(
60
60
  metric: 'cosine' | 'euclidean' | 'dotproduct',
61
61
  ) {
62
62
  await vectorDB.createIndex({ indexName, dimension, metric });
63
- await vectorDB.waitForIndexReady(indexName);
63
+ await vectorDB.waitForIndexReady({ indexName });
64
64
  const created = await waitForCondition(
65
65
  async () => {
66
66
  const cols = await vectorDB.listIndexes();
@@ -75,7 +75,7 @@ async function createIndexAndWait(
75
75
  // Delete index (collection) and wait until it is removed
76
76
  async function deleteIndexAndWait(vectorDB: MongoDBVector, indexName: string) {
77
77
  try {
78
- await vectorDB.deleteIndex(indexName);
78
+ await vectorDB.deleteIndex({ indexName });
79
79
  const deleted = await waitForCondition(
80
80
  async () => {
81
81
  const cols = await vectorDB.listIndexes();
@@ -105,7 +105,7 @@ describe('MongoDBVector Integration Tests', () => {
105
105
  // Cleanup any existing collections
106
106
  try {
107
107
  const cols = await vectorDB.listIndexes();
108
- await Promise.all(cols.map(c => vectorDB.deleteIndex(c)));
108
+ await Promise.all(cols.map(c => vectorDB.deleteIndex({ indexName: c })));
109
109
  const deleted = await waitForCondition(async () => (await vectorDB.listIndexes()).length === 0, 30000, 2000);
110
110
  if (!deleted) throw new Error('Timed out waiting for collections to be deleted');
111
111
  } catch (error) {
@@ -119,12 +119,12 @@ describe('MongoDBVector Integration Tests', () => {
119
119
 
120
120
  afterAll(async () => {
121
121
  try {
122
- await vectorDB.deleteIndex(testIndexName);
122
+ await vectorDB.deleteIndex({ indexName: testIndexName });
123
123
  } catch (error) {
124
124
  console.error('Failed to delete test collection:', error);
125
125
  }
126
126
  try {
127
- await vectorDB.deleteIndex(testIndexName2);
127
+ await vectorDB.deleteIndex({ indexName: testIndexName2 });
128
128
  } catch (error) {
129
129
  console.error('Failed to delete test collection:', error);
130
130
  }
@@ -137,7 +137,7 @@ describe('MongoDBVector Integration Tests', () => {
137
137
  expect(cols).toContain(testIndexName);
138
138
 
139
139
  // Check stats (should be zero docs initially)
140
- const initialStats = await vectorDB.describeIndex(testIndexName);
140
+ const initialStats = await vectorDB.describeIndex({ indexName: testIndexName });
141
141
  expect(initialStats).toEqual({ dimension: 4, metric: 'cosine', count: 0 });
142
142
 
143
143
  // Upsert 4 vectors with metadata
@@ -153,7 +153,7 @@ describe('MongoDBVector Integration Tests', () => {
153
153
 
154
154
  // Wait for the document count to update (increased delay to 5000ms)
155
155
  await new Promise(resolve => setTimeout(resolve, 5000));
156
- const updatedStats = await vectorDB.describeIndex(testIndexName);
156
+ const updatedStats = await vectorDB.describeIndex({ indexName: testIndexName });
157
157
  expect(updatedStats.count).toEqual(4);
158
158
 
159
159
  // Query for similar vectors (delay again to allow for index update)
@@ -175,7 +175,7 @@ describe('MongoDBVector Integration Tests', () => {
175
175
  expect(filteredResults[0]?.metadata).toEqual({ label: 'vector2' });
176
176
 
177
177
  // Final stats should show > 0 documents
178
- const finalStats = await vectorDB.describeIndex(testIndexName);
178
+ const finalStats = await vectorDB.describeIndex({ indexName: testIndexName });
179
179
  expect(finalStats.count).toBeGreaterThan(0);
180
180
  });
181
181
 
@@ -379,7 +379,11 @@ describe('MongoDBVector Integration Tests', () => {
379
379
  const idToBeUpdated = ids[0];
380
380
  const newVector = [1, 2, 3, 4];
381
381
  const newMetaData = { test: 'updates' };
382
- await vectorDB.updateVector(indexName, idToBeUpdated, { vector: newVector, metadata: newMetaData });
382
+ await vectorDB.updateVector({
383
+ indexName,
384
+ id: idToBeUpdated,
385
+ update: { vector: newVector, metadata: newMetaData },
386
+ });
383
387
  await new Promise(resolve => setTimeout(resolve, 5000));
384
388
  const results = await vectorDB.query({
385
389
  indexName,
@@ -399,7 +403,7 @@ describe('MongoDBVector Integration Tests', () => {
399
403
  expect(ids).toHaveLength(4);
400
404
  const idToBeUpdated = ids[0];
401
405
  const newMetaData = { test: 'metadata only update' };
402
- await vectorDB.updateVector(indexName, idToBeUpdated, { metadata: newMetaData });
406
+ await vectorDB.updateVector({ indexName, id: idToBeUpdated, update: { metadata: newMetaData } });
403
407
  await new Promise(resolve => setTimeout(resolve, 5000));
404
408
  const results = await vectorDB.query({
405
409
  indexName,
@@ -419,7 +423,7 @@ describe('MongoDBVector Integration Tests', () => {
419
423
  expect(ids).toHaveLength(4);
420
424
  const idToBeUpdated = ids[0];
421
425
  const newVector = [1, 2, 3, 4];
422
- await vectorDB.updateVector(indexName, idToBeUpdated, { vector: newVector });
426
+ await vectorDB.updateVector({ indexName, id: idToBeUpdated, update: { vector: newVector } });
423
427
  await new Promise(resolve => setTimeout(resolve, 5000));
424
428
  const results = await vectorDB.query({
425
429
  indexName,
@@ -434,21 +438,23 @@ describe('MongoDBVector Integration Tests', () => {
434
438
  expect(updatedResult?.vector).toEqual(newVector);
435
439
  });
436
440
  it('should throw exception when no updates are given', async () => {
437
- await expect(vectorDB.updateVector(indexName, 'nonexistent-id', {})).rejects.toThrow('No updates provided');
441
+ await expect(vectorDB.updateVector({ indexName, id: 'nonexistent-id', update: {} })).rejects.toThrow(
442
+ 'No updates provided',
443
+ );
438
444
  });
439
445
  it('should delete the vector by id', async () => {
440
446
  const ids = await vectorDB.upsert({ indexName, vectors: testVectors });
441
447
  expect(ids).toHaveLength(4);
442
448
  const idToBeDeleted = ids[0];
443
449
 
444
- const initialStats = await vectorDB.describeIndex(indexName);
450
+ const initialStats = await vectorDB.describeIndex({ indexName });
445
451
 
446
- await vectorDB.deleteVector(indexName, idToBeDeleted);
452
+ await vectorDB.deleteVector({ indexName, id: idToBeDeleted });
447
453
  const results = await vectorDB.query({ indexName, queryVector: [1, 0, 0, 0], topK: 2 });
448
454
  expect(results.map(res => res.id)).not.toContain(idToBeDeleted);
449
455
 
450
456
  await new Promise(resolve => setTimeout(resolve, 5000)); // Wait for count to update
451
- const finalStats = await vectorDB.describeIndex(indexName);
457
+ const finalStats = await vectorDB.describeIndex({ indexName });
452
458
  expect(finalStats.count).toBe(initialStats.count - 1);
453
459
  });
454
460
  });
@@ -8,6 +8,10 @@ import type {
8
8
  ParamsToArgs,
9
9
  QueryVectorArgs,
10
10
  UpsertVectorArgs,
11
+ DescribeIndexParams,
12
+ DeleteIndexParams,
13
+ DeleteVectorParams,
14
+ UpdateVectorParams,
11
15
  } from '@mastra/core/vector';
12
16
  import type { VectorFilter } from '@mastra/core/vector/filter';
13
17
  import { MongoClient } from 'mongodb';
@@ -29,6 +33,14 @@ export interface MongoDBQueryVectorParams extends QueryVectorParams {
29
33
  documentFilter?: VectorFilter;
30
34
  }
31
35
 
36
+ export interface MongoDBIndexReadyParams {
37
+ indexName: string;
38
+ timeoutMs?: number;
39
+ checkIntervalMs?: number;
40
+ }
41
+
42
+ type MongoDBIndexReadyArgs = [string, number?, number?];
43
+
32
44
  // Define the document interface
33
45
  interface MongoDBDocument extends Document {
34
46
  _id: string; // Explicitly declare '_id' as string
@@ -118,7 +130,21 @@ export class MongoDBVector extends MastraVector {
118
130
  await collection.updateOne({ _id: '__index_metadata__' }, { $set: { dimension, metric } }, { upsert: true });
119
131
  }
120
132
 
121
- async waitForIndexReady(indexName: string, timeoutMs: number = 60000, checkIntervalMs: number = 2000): Promise<void> {
133
+ /**
134
+ * Waits for the index to be ready.
135
+ *
136
+ * @param params - The parameters for waiting for the index to be ready
137
+ * @param params.indexName - The name of the index to wait for
138
+ * @param params.timeoutMs - The maximum time in milliseconds to wait for the index to be ready (default: 60000)
139
+ * @param params.checkIntervalMs - The interval in milliseconds at which to check if the index is ready (default: 2000)
140
+ * @returns A promise that resolves when the index is ready
141
+ */
142
+ async waitForIndexReady(...args: ParamsToArgs<MongoDBIndexReadyParams> | MongoDBIndexReadyArgs): Promise<void> {
143
+ const params = this.normalizeArgs<MongoDBIndexReadyParams, MongoDBIndexReadyArgs>('waitForIndexReady', args, [
144
+ 'timeoutMs',
145
+ 'checkIntervalMs',
146
+ ]);
147
+ const { indexName, timeoutMs = 60000, checkIntervalMs = 2000 } = params;
122
148
  const collection = await this.getCollection(indexName, true);
123
149
  const indexNameInternal = `${indexName}_vector_index`;
124
150
 
@@ -143,7 +169,7 @@ export class MongoDBVector extends MastraVector {
143
169
  this.collectionForValidation = collection;
144
170
 
145
171
  // Get index stats to check dimension
146
- const stats = await this.describeIndex(indexName);
172
+ const stats = await this.describeIndex({ indexName });
147
173
 
148
174
  // Validate vector dimensions
149
175
  await this.validateVectorDimensions(vectors, stats.dimension);
@@ -255,7 +281,17 @@ export class MongoDBVector extends MastraVector {
255
281
  return collections.map(col => col.name);
256
282
  }
257
283
 
258
- async describeIndex(indexName: string): Promise<IndexStats> {
284
+ /**
285
+ * Retrieves statistics about a vector index.
286
+ *
287
+ * @param params - The parameters for describing an index
288
+ * @param params.indexName - The name of the index to describe
289
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
290
+ */
291
+ async describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats> {
292
+ const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
293
+
294
+ const { indexName } = params;
259
295
  const collection = await this.getCollection(indexName, true);
260
296
 
261
297
  // Get the count of documents, excluding the metadata document
@@ -273,7 +309,10 @@ export class MongoDBVector extends MastraVector {
273
309
  };
274
310
  }
275
311
 
276
- async deleteIndex(indexName: string): Promise<void> {
312
+ async deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void> {
313
+ const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
314
+
315
+ const { indexName } = params;
277
316
  const collection = await this.getCollection(indexName, false); // Do not throw error if collection doesn't exist
278
317
  if (collection) {
279
318
  await collection.drop();
@@ -306,7 +345,7 @@ export class MongoDBVector extends MastraVector {
306
345
  Please use updateVector() instead.
307
346
  updateIndexById() will be removed on May 20th, 2025.`,
308
347
  );
309
- await this.updateVector(indexName, id, update);
348
+ await this.updateVector({ indexName, id, update });
310
349
  }
311
350
 
312
351
  /**
@@ -319,11 +358,9 @@ export class MongoDBVector extends MastraVector {
319
358
  * @returns A promise that resolves when the update is complete.
320
359
  * @throws Will throw an error if no updates are provided or if the update operation fails.
321
360
  */
322
- async updateVector(
323
- indexName: string,
324
- id: string,
325
- update: { vector?: number[]; metadata?: Record<string, any> },
326
- ): Promise<void> {
361
+ async updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void> {
362
+ const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
363
+ const { indexName, id, update } = params;
327
364
  try {
328
365
  if (!update.vector && !update.metadata) {
329
366
  throw new Error('No updates provided');
@@ -333,7 +370,7 @@ export class MongoDBVector extends MastraVector {
333
370
  const updateDoc: Record<string, any> = {};
334
371
 
335
372
  if (update.vector) {
336
- const stats = await this.describeIndex(indexName);
373
+ const stats = await this.describeIndex({ indexName });
337
374
  await this.validateVectorDimensions([update.vector], stats.dimension);
338
375
  updateDoc[this.embeddingFieldName] = update.vector;
339
376
  }
@@ -373,7 +410,7 @@ export class MongoDBVector extends MastraVector {
373
410
  Please use deleteVector() instead.
374
411
  deleteIndexById() will be removed on May 20th, 2025.`,
375
412
  );
376
- await this.deleteVector(indexName, id);
413
+ await this.deleteVector({ indexName, id });
377
414
  }
378
415
 
379
416
  /**
@@ -383,7 +420,9 @@ export class MongoDBVector extends MastraVector {
383
420
  * @returns A promise that resolves when the deletion is complete.
384
421
  * @throws Will throw an error if the deletion operation fails.
385
422
  */
386
- async deleteVector(indexName: string, id: string): Promise<void> {
423
+ async deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void> {
424
+ const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
425
+ const { indexName, id } = params;
387
426
  try {
388
427
  const collection = await this.getCollection(indexName, true);
389
428
  await collection.deleteOne({ _id: id });