@mastra/opensearch 0.0.0-generate-message-id-20250512171942 → 0.0.0-vector-sources-20250516175436

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.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,28 @@
1
1
  # @mastra/opensearch
2
2
 
3
- ## 0.0.0-generate-message-id-20250512171942
3
+ ## 0.0.0-vector-sources-20250516175436
4
4
 
5
5
  ### Patch Changes
6
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 [d0ee3c6]
11
+ - Updated dependencies [23f258c]
12
+ - Updated dependencies [2672a05]
13
+ - @mastra/core@0.0.0-vector-sources-20250516175436
14
+
15
+ ## 0.1.1
16
+
17
+ ### Patch Changes
18
+
19
+ - c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
20
+ - Updated dependencies [396be50]
7
21
  - Updated dependencies [ab80e7e]
8
- - Updated dependencies [66a786d]
22
+ - Updated dependencies [c3bd795]
23
+ - Updated dependencies [da082f8]
24
+ - Updated dependencies [a5810ce]
25
+ - Updated dependencies [3e9c131]
9
26
  - Updated dependencies [3171b5b]
10
27
  - Updated dependencies [973e5ac]
11
28
  - Updated dependencies [daf942f]
@@ -14,7 +31,25 @@
14
31
  - Updated dependencies [6fa1ad1]
15
32
  - Updated dependencies [c28d7a0]
16
33
  - Updated dependencies [edf1e88]
17
- - @mastra/core@0.0.0-generate-message-id-20250512171942
34
+ - @mastra/core@0.9.4
35
+
36
+ ## 0.1.1-alpha.4
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [3e9c131]
41
+ - @mastra/core@0.9.4-alpha.4
42
+
43
+ ## 0.1.1-alpha.3
44
+
45
+ ### Patch Changes
46
+
47
+ - c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
48
+ - Updated dependencies [396be50]
49
+ - Updated dependencies [c3bd795]
50
+ - Updated dependencies [da082f8]
51
+ - Updated dependencies [a5810ce]
52
+ - @mastra/core@0.9.4-alpha.3
18
53
 
19
54
  ## 0.1.1-alpha.2
20
55
 
@@ -1,10 +1,15 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
2
  import type { CreateIndexParams } from '@mastra/core';
3
+ import type { DeleteIndexParams } from '@mastra/core';
4
+ import type { DeleteVectorParams } from '@mastra/core';
5
+ import type { DescribeIndexParams } from '@mastra/core';
3
6
  import type { IndexStats } from '@mastra/core';
4
7
  import { MastraVector } from '@mastra/core/vector';
5
8
  import type { OperatorSupport } from '@mastra/core/vector/filter';
9
+ import type { ParamsToArgs } from '@mastra/core';
6
10
  import type { QueryResult } from '@mastra/core';
7
11
  import type { QueryVectorParams } from '@mastra/core';
12
+ import type { UpdateVectorParams } from '@mastra/core';
8
13
  import type { UpsertVectorParams } from '@mastra/core';
9
14
  import type { VectorFilter } from '@mastra/core/vector/filter';
10
15
 
@@ -50,7 +55,19 @@ export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
50
55
 
51
56
  declare class OpenSearchVector extends MastraVector {
52
57
  private client;
58
+ /**
59
+ * @deprecated Passing a string URL is deprecated. Use an object parameter: { url }.
60
+ * @param url - The OpenSearch node URL (deprecated)
61
+ */
53
62
  constructor(url: string);
63
+ /**
64
+ * Creates a new OpenSearchVector client.
65
+ *
66
+ * @param params - An object with a url property specifying the OpenSearch node.
67
+ */
68
+ constructor(params: {
69
+ url: string;
70
+ });
54
71
  /**
55
72
  * Creates a new collection with the specified configuration.
56
73
  *
@@ -66,14 +83,21 @@ declare class OpenSearchVector extends MastraVector {
66
83
  * @returns {Promise<string[]>} A promise that resolves to an array of indexes.
67
84
  */
68
85
  listIndexes(): Promise<string[]>;
69
- describeIndex(indexName: string): Promise<IndexStats>;
86
+ /**
87
+ * Retrieves statistics about a vector index.
88
+ *
89
+ * @param params - The parameters for describing an index
90
+ * @param params.indexName - The name of the index to describe
91
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
92
+ */
93
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
70
94
  /**
71
95
  * Deletes the specified index.
72
96
  *
73
97
  * @param {string} indexName - The name of the index to delete.
74
98
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
75
99
  */
76
- deleteIndex(indexName: string): Promise<void>;
100
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
77
101
  /**
78
102
  * Inserts or updates vectors in the specified collection.
79
103
  *
@@ -111,27 +135,50 @@ declare class OpenSearchVector extends MastraVector {
111
135
  */
112
136
  private transformFilter;
113
137
  /**
114
- * Updates a specific document in the index by ID.
138
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
115
139
  *
116
- * @param {string} indexName - The name of the index containing the document.
117
- * @param {string} id - The ID of the document to update.
118
- * @param {Object} update - The update to apply to the document.
119
- * @param {number[]} [update.vector] - Optional new vector to update.
120
- * @param {Record<string, any>} [update.metadata] - Optional new metadata to update.
121
- * @returns {Promise<void>} A promise that resolves when the document is updated.
140
+ * Updates a vector by its ID with the provided vector and/or metadata.
141
+ * @param indexName - The name of the index containing the vector.
142
+ * @param id - The ID of the vector to update.
143
+ * @param update - An object containing the vector and/or metadata to update.
144
+ * @param update.vector - An optional array of numbers representing the new vector.
145
+ * @param update.metadata - An optional record containing the new metadata.
146
+ * @returns A promise that resolves when the update is complete.
147
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
122
148
  */
123
149
  updateIndexById(indexName: string, id: string, update: {
124
150
  vector?: number[];
125
151
  metadata?: Record<string, any>;
126
152
  }): Promise<void>;
127
153
  /**
128
- * Deletes a specific document from the index by ID.
154
+ * Updates a vector by its ID with the provided vector and/or metadata.
155
+ * @param indexName - The name of the index containing the vector.
156
+ * @param id - The ID of the vector to update.
157
+ * @param update - An object containing the vector and/or metadata to update.
158
+ * @param update.vector - An optional array of numbers representing the new vector.
159
+ * @param update.metadata - An optional record containing the new metadata.
160
+ * @returns A promise that resolves when the update is complete.
161
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
162
+ */
163
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
164
+ /**
165
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
129
166
  *
130
- * @param {string} indexName - The name of the index containing the document.
131
- * @param {string} id - The ID of the document to delete.
132
- * @returns {Promise<void>} A promise that resolves when the document is deleted.
167
+ * Deletes a vector by its ID.
168
+ * @param indexName - The name of the index containing the vector.
169
+ * @param id - The ID of the vector to delete.
170
+ * @returns A promise that resolves when the deletion is complete.
171
+ * @throws Will throw an error if the deletion operation fails.
133
172
  */
134
173
  deleteIndexById(indexName: string, id: string): Promise<void>;
174
+ /**
175
+ * Deletes a vector by its ID.
176
+ * @param indexName - The name of the index containing the vector.
177
+ * @param id - The ID of the vector to delete.
178
+ * @returns A promise that resolves when the deletion is complete.
179
+ * @throws Will throw an error if the deletion operation fails.
180
+ */
181
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
135
182
  }
136
183
  export { OpenSearchVector }
137
184
  export { OpenSearchVector as OpenSearchVector_alias_1 }
@@ -1,10 +1,15 @@
1
1
  import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
2
  import type { CreateIndexParams } from '@mastra/core';
3
+ import type { DeleteIndexParams } from '@mastra/core';
4
+ import type { DeleteVectorParams } from '@mastra/core';
5
+ import type { DescribeIndexParams } from '@mastra/core';
3
6
  import type { IndexStats } from '@mastra/core';
4
7
  import { MastraVector } from '@mastra/core/vector';
5
8
  import type { OperatorSupport } from '@mastra/core/vector/filter';
9
+ import type { ParamsToArgs } from '@mastra/core';
6
10
  import type { QueryResult } from '@mastra/core';
7
11
  import type { QueryVectorParams } from '@mastra/core';
12
+ import type { UpdateVectorParams } from '@mastra/core';
8
13
  import type { UpsertVectorParams } from '@mastra/core';
9
14
  import type { VectorFilter } from '@mastra/core/vector/filter';
10
15
 
@@ -50,7 +55,19 @@ export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
50
55
 
51
56
  declare class OpenSearchVector extends MastraVector {
52
57
  private client;
58
+ /**
59
+ * @deprecated Passing a string URL is deprecated. Use an object parameter: { url }.
60
+ * @param url - The OpenSearch node URL (deprecated)
61
+ */
53
62
  constructor(url: string);
63
+ /**
64
+ * Creates a new OpenSearchVector client.
65
+ *
66
+ * @param params - An object with a url property specifying the OpenSearch node.
67
+ */
68
+ constructor(params: {
69
+ url: string;
70
+ });
54
71
  /**
55
72
  * Creates a new collection with the specified configuration.
56
73
  *
@@ -66,14 +83,21 @@ declare class OpenSearchVector extends MastraVector {
66
83
  * @returns {Promise<string[]>} A promise that resolves to an array of indexes.
67
84
  */
68
85
  listIndexes(): Promise<string[]>;
69
- describeIndex(indexName: string): Promise<IndexStats>;
86
+ /**
87
+ * Retrieves statistics about a vector index.
88
+ *
89
+ * @param params - The parameters for describing an index
90
+ * @param params.indexName - The name of the index to describe
91
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
92
+ */
93
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
70
94
  /**
71
95
  * Deletes the specified index.
72
96
  *
73
97
  * @param {string} indexName - The name of the index to delete.
74
98
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
75
99
  */
76
- deleteIndex(indexName: string): Promise<void>;
100
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
77
101
  /**
78
102
  * Inserts or updates vectors in the specified collection.
79
103
  *
@@ -111,27 +135,50 @@ declare class OpenSearchVector extends MastraVector {
111
135
  */
112
136
  private transformFilter;
113
137
  /**
114
- * Updates a specific document in the index by ID.
138
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
115
139
  *
116
- * @param {string} indexName - The name of the index containing the document.
117
- * @param {string} id - The ID of the document to update.
118
- * @param {Object} update - The update to apply to the document.
119
- * @param {number[]} [update.vector] - Optional new vector to update.
120
- * @param {Record<string, any>} [update.metadata] - Optional new metadata to update.
121
- * @returns {Promise<void>} A promise that resolves when the document is updated.
140
+ * Updates a vector by its ID with the provided vector and/or metadata.
141
+ * @param indexName - The name of the index containing the vector.
142
+ * @param id - The ID of the vector to update.
143
+ * @param update - An object containing the vector and/or metadata to update.
144
+ * @param update.vector - An optional array of numbers representing the new vector.
145
+ * @param update.metadata - An optional record containing the new metadata.
146
+ * @returns A promise that resolves when the update is complete.
147
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
122
148
  */
123
149
  updateIndexById(indexName: string, id: string, update: {
124
150
  vector?: number[];
125
151
  metadata?: Record<string, any>;
126
152
  }): Promise<void>;
127
153
  /**
128
- * Deletes a specific document from the index by ID.
154
+ * Updates a vector by its ID with the provided vector and/or metadata.
155
+ * @param indexName - The name of the index containing the vector.
156
+ * @param id - The ID of the vector to update.
157
+ * @param update - An object containing the vector and/or metadata to update.
158
+ * @param update.vector - An optional array of numbers representing the new vector.
159
+ * @param update.metadata - An optional record containing the new metadata.
160
+ * @returns A promise that resolves when the update is complete.
161
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
162
+ */
163
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
164
+ /**
165
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
129
166
  *
130
- * @param {string} indexName - The name of the index containing the document.
131
- * @param {string} id - The ID of the document to delete.
132
- * @returns {Promise<void>} A promise that resolves when the document is deleted.
167
+ * Deletes a vector by its ID.
168
+ * @param indexName - The name of the index containing the vector.
169
+ * @param id - The ID of the vector to delete.
170
+ * @returns A promise that resolves when the deletion is complete.
171
+ * @throws Will throw an error if the deletion operation fails.
133
172
  */
134
173
  deleteIndexById(indexName: string, id: string): Promise<void>;
174
+ /**
175
+ * Deletes a vector by its ID.
176
+ * @param indexName - The name of the index containing the vector.
177
+ * @param id - The ID of the vector to delete.
178
+ * @returns A promise that resolves when the deletion is complete.
179
+ * @throws Will throw an error if the deletion operation fails.
180
+ */
181
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
135
182
  }
136
183
  export { OpenSearchVector }
137
184
  export { OpenSearchVector as OpenSearchVector_alias_1 }
package/dist/index.cjs CHANGED
@@ -364,8 +364,21 @@ var REVERSE_METRIC_MAPPING = {
364
364
  };
365
365
  var OpenSearchVector = class extends vector.MastraVector {
366
366
  client;
367
- constructor(url) {
367
+ constructor(paramsOrUrl) {
368
368
  super();
369
+ let url;
370
+ if (typeof paramsOrUrl === "string") {
371
+ if (typeof console !== "undefined" && console.warn) {
372
+ console.warn(
373
+ "Deprecation Warning: OpenSearchVector constructor positional arguments are deprecated. Please use a single object parameter instead. This signature will be removed on May 20th, 2025."
374
+ );
375
+ }
376
+ url = paramsOrUrl;
377
+ } else if (typeof paramsOrUrl === "object" && paramsOrUrl !== null && "url" in paramsOrUrl) {
378
+ url = paramsOrUrl.url;
379
+ } else {
380
+ throw new Error("Invalid parameters for OpenSearchVector constructor. Expected { url: string }.");
381
+ }
369
382
  this.client = new opensearch.Client({ node: url });
370
383
  }
371
384
  /**
@@ -429,7 +442,16 @@ var OpenSearchVector = class extends vector.MastraVector {
429
442
  throw new Error(`Failed to list indexes: ${error.message}`);
430
443
  }
431
444
  }
432
- async describeIndex(indexName) {
445
+ /**
446
+ * Retrieves statistics about a vector index.
447
+ *
448
+ * @param params - The parameters for describing an index
449
+ * @param params.indexName - The name of the index to describe
450
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
451
+ */
452
+ async describeIndex(...args) {
453
+ const params = this.normalizeArgs("describeIndex", args);
454
+ const { indexName } = params;
433
455
  const { body: indexInfo } = await this.client.indices.get({ index: indexName });
434
456
  const mappings = indexInfo[indexName]?.mappings;
435
457
  const embedding = mappings?.properties?.embedding;
@@ -447,7 +469,9 @@ var OpenSearchVector = class extends vector.MastraVector {
447
469
  * @param {string} indexName - The name of the index to delete.
448
470
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
449
471
  */
450
- async deleteIndex(indexName) {
472
+ async deleteIndex(...args) {
473
+ const params = this.normalizeArgs("deleteIndex", args);
474
+ const { indexName } = params;
451
475
  try {
452
476
  await this.client.indices.delete({ index: indexName });
453
477
  } catch (error) {
@@ -467,7 +491,7 @@ var OpenSearchVector = class extends vector.MastraVector {
467
491
  const { indexName, vectors, metadata = [], ids } = params;
468
492
  const vectorIds = ids || vectors.map(() => crypto.randomUUID());
469
493
  const operations = [];
470
- const indexInfo = await this.describeIndex(indexName);
494
+ const indexInfo = await this.describeIndex({ indexName });
471
495
  this.validateVectorDimensions(vectors, indexInfo.dimension);
472
496
  for (let i = 0; i < vectors.length; i++) {
473
497
  const operation = {
@@ -558,16 +582,38 @@ var OpenSearchVector = class extends vector.MastraVector {
558
582
  return translator.translate(filter);
559
583
  }
560
584
  /**
561
- * Updates a specific document in the index by ID.
585
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
562
586
  *
563
- * @param {string} indexName - The name of the index containing the document.
564
- * @param {string} id - The ID of the document to update.
565
- * @param {Object} update - The update to apply to the document.
566
- * @param {number[]} [update.vector] - Optional new vector to update.
567
- * @param {Record<string, any>} [update.metadata] - Optional new metadata to update.
568
- * @returns {Promise<void>} A promise that resolves when the document is updated.
587
+ * Updates a vector by its ID with the provided vector and/or metadata.
588
+ * @param indexName - The name of the index containing the vector.
589
+ * @param id - The ID of the vector to update.
590
+ * @param update - An object containing the vector and/or metadata to update.
591
+ * @param update.vector - An optional array of numbers representing the new vector.
592
+ * @param update.metadata - An optional record containing the new metadata.
593
+ * @returns A promise that resolves when the update is complete.
594
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
569
595
  */
570
596
  async updateIndexById(indexName, id, update) {
597
+ this.logger.warn(
598
+ `Deprecation Warning: updateIndexById() is deprecated.
599
+ Please use updateVector() instead.
600
+ updateIndexById() will be removed on May 20th, 2025.`
601
+ );
602
+ await this.updateVector({ indexName, id, update });
603
+ }
604
+ /**
605
+ * Updates a vector by its ID with the provided vector and/or metadata.
606
+ * @param indexName - The name of the index containing the vector.
607
+ * @param id - The ID of the vector to update.
608
+ * @param update - An object containing the vector and/or metadata to update.
609
+ * @param update.vector - An optional array of numbers representing the new vector.
610
+ * @param update.metadata - An optional record containing the new metadata.
611
+ * @returns A promise that resolves when the update is complete.
612
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
613
+ */
614
+ async updateVector(...args) {
615
+ const params = this.normalizeArgs("updateVector", args);
616
+ const { indexName, id, update } = params;
571
617
  if (!update.vector && !update.metadata) {
572
618
  throw new Error("No updates provided");
573
619
  }
@@ -586,7 +632,7 @@ var OpenSearchVector = class extends vector.MastraVector {
586
632
  id: source.id || id
587
633
  };
588
634
  if (update.vector) {
589
- const indexInfo = await this.describeIndex(indexName);
635
+ const indexInfo = await this.describeIndex({ indexName });
590
636
  this.validateVectorDimensions([update.vector], indexInfo.dimension);
591
637
  updatedDoc.embedding = update.vector;
592
638
  } else if (source.embedding) {
@@ -609,13 +655,32 @@ var OpenSearchVector = class extends vector.MastraVector {
609
655
  }
610
656
  }
611
657
  /**
612
- * Deletes a specific document from the index by ID.
658
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
613
659
  *
614
- * @param {string} indexName - The name of the index containing the document.
615
- * @param {string} id - The ID of the document to delete.
616
- * @returns {Promise<void>} A promise that resolves when the document is deleted.
660
+ * Deletes a vector by its ID.
661
+ * @param indexName - The name of the index containing the vector.
662
+ * @param id - The ID of the vector to delete.
663
+ * @returns A promise that resolves when the deletion is complete.
664
+ * @throws Will throw an error if the deletion operation fails.
617
665
  */
618
666
  async deleteIndexById(indexName, id) {
667
+ this.logger.warn(
668
+ `Deprecation Warning: deleteIndexById() is deprecated.
669
+ Please use deleteVector() instead.
670
+ deleteIndexById() will be removed on May 20th, 2025.`
671
+ );
672
+ await this.deleteVector({ indexName, id });
673
+ }
674
+ /**
675
+ * Deletes a vector by its ID.
676
+ * @param indexName - The name of the index containing the vector.
677
+ * @param id - The ID of the vector to delete.
678
+ * @returns A promise that resolves when the deletion is complete.
679
+ * @throws Will throw an error if the deletion operation fails.
680
+ */
681
+ async deleteVector(...args) {
682
+ const params = this.normalizeArgs("deleteVector", args);
683
+ const { indexName, id } = params;
619
684
  try {
620
685
  await this.client.delete({
621
686
  index: indexName,
package/dist/index.js CHANGED
@@ -362,8 +362,21 @@ var REVERSE_METRIC_MAPPING = {
362
362
  };
363
363
  var OpenSearchVector = class extends MastraVector {
364
364
  client;
365
- constructor(url) {
365
+ constructor(paramsOrUrl) {
366
366
  super();
367
+ let url;
368
+ if (typeof paramsOrUrl === "string") {
369
+ if (typeof console !== "undefined" && console.warn) {
370
+ console.warn(
371
+ "Deprecation Warning: OpenSearchVector constructor positional arguments are deprecated. Please use a single object parameter instead. This signature will be removed on May 20th, 2025."
372
+ );
373
+ }
374
+ url = paramsOrUrl;
375
+ } else if (typeof paramsOrUrl === "object" && paramsOrUrl !== null && "url" in paramsOrUrl) {
376
+ url = paramsOrUrl.url;
377
+ } else {
378
+ throw new Error("Invalid parameters for OpenSearchVector constructor. Expected { url: string }.");
379
+ }
367
380
  this.client = new Client({ node: url });
368
381
  }
369
382
  /**
@@ -427,7 +440,16 @@ var OpenSearchVector = class extends MastraVector {
427
440
  throw new Error(`Failed to list indexes: ${error.message}`);
428
441
  }
429
442
  }
430
- async describeIndex(indexName) {
443
+ /**
444
+ * Retrieves statistics about a vector index.
445
+ *
446
+ * @param params - The parameters for describing an index
447
+ * @param params.indexName - The name of the index to describe
448
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
449
+ */
450
+ async describeIndex(...args) {
451
+ const params = this.normalizeArgs("describeIndex", args);
452
+ const { indexName } = params;
431
453
  const { body: indexInfo } = await this.client.indices.get({ index: indexName });
432
454
  const mappings = indexInfo[indexName]?.mappings;
433
455
  const embedding = mappings?.properties?.embedding;
@@ -445,7 +467,9 @@ var OpenSearchVector = class extends MastraVector {
445
467
  * @param {string} indexName - The name of the index to delete.
446
468
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
447
469
  */
448
- async deleteIndex(indexName) {
470
+ async deleteIndex(...args) {
471
+ const params = this.normalizeArgs("deleteIndex", args);
472
+ const { indexName } = params;
449
473
  try {
450
474
  await this.client.indices.delete({ index: indexName });
451
475
  } catch (error) {
@@ -465,7 +489,7 @@ var OpenSearchVector = class extends MastraVector {
465
489
  const { indexName, vectors, metadata = [], ids } = params;
466
490
  const vectorIds = ids || vectors.map(() => crypto.randomUUID());
467
491
  const operations = [];
468
- const indexInfo = await this.describeIndex(indexName);
492
+ const indexInfo = await this.describeIndex({ indexName });
469
493
  this.validateVectorDimensions(vectors, indexInfo.dimension);
470
494
  for (let i = 0; i < vectors.length; i++) {
471
495
  const operation = {
@@ -556,16 +580,38 @@ var OpenSearchVector = class extends MastraVector {
556
580
  return translator.translate(filter);
557
581
  }
558
582
  /**
559
- * Updates a specific document in the index by ID.
583
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
560
584
  *
561
- * @param {string} indexName - The name of the index containing the document.
562
- * @param {string} id - The ID of the document to update.
563
- * @param {Object} update - The update to apply to the document.
564
- * @param {number[]} [update.vector] - Optional new vector to update.
565
- * @param {Record<string, any>} [update.metadata] - Optional new metadata to update.
566
- * @returns {Promise<void>} A promise that resolves when the document is updated.
585
+ * Updates a vector by its ID with the provided vector and/or metadata.
586
+ * @param indexName - The name of the index containing the vector.
587
+ * @param id - The ID of the vector to update.
588
+ * @param update - An object containing the vector and/or metadata to update.
589
+ * @param update.vector - An optional array of numbers representing the new vector.
590
+ * @param update.metadata - An optional record containing the new metadata.
591
+ * @returns A promise that resolves when the update is complete.
592
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
567
593
  */
568
594
  async updateIndexById(indexName, id, update) {
595
+ this.logger.warn(
596
+ `Deprecation Warning: updateIndexById() is deprecated.
597
+ Please use updateVector() instead.
598
+ updateIndexById() will be removed on May 20th, 2025.`
599
+ );
600
+ await this.updateVector({ indexName, id, update });
601
+ }
602
+ /**
603
+ * Updates a vector by its ID with the provided vector and/or metadata.
604
+ * @param indexName - The name of the index containing the vector.
605
+ * @param id - The ID of the vector to update.
606
+ * @param update - An object containing the vector and/or metadata to update.
607
+ * @param update.vector - An optional array of numbers representing the new vector.
608
+ * @param update.metadata - An optional record containing the new metadata.
609
+ * @returns A promise that resolves when the update is complete.
610
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
611
+ */
612
+ async updateVector(...args) {
613
+ const params = this.normalizeArgs("updateVector", args);
614
+ const { indexName, id, update } = params;
569
615
  if (!update.vector && !update.metadata) {
570
616
  throw new Error("No updates provided");
571
617
  }
@@ -584,7 +630,7 @@ var OpenSearchVector = class extends MastraVector {
584
630
  id: source.id || id
585
631
  };
586
632
  if (update.vector) {
587
- const indexInfo = await this.describeIndex(indexName);
633
+ const indexInfo = await this.describeIndex({ indexName });
588
634
  this.validateVectorDimensions([update.vector], indexInfo.dimension);
589
635
  updatedDoc.embedding = update.vector;
590
636
  } else if (source.embedding) {
@@ -607,13 +653,32 @@ var OpenSearchVector = class extends MastraVector {
607
653
  }
608
654
  }
609
655
  /**
610
- * Deletes a specific document from the index by ID.
656
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
611
657
  *
612
- * @param {string} indexName - The name of the index containing the document.
613
- * @param {string} id - The ID of the document to delete.
614
- * @returns {Promise<void>} A promise that resolves when the document is deleted.
658
+ * Deletes a vector by its ID.
659
+ * @param indexName - The name of the index containing the vector.
660
+ * @param id - The ID of the vector to delete.
661
+ * @returns A promise that resolves when the deletion is complete.
662
+ * @throws Will throw an error if the deletion operation fails.
615
663
  */
616
664
  async deleteIndexById(indexName, id) {
665
+ this.logger.warn(
666
+ `Deprecation Warning: deleteIndexById() is deprecated.
667
+ Please use deleteVector() instead.
668
+ deleteIndexById() will be removed on May 20th, 2025.`
669
+ );
670
+ await this.deleteVector({ indexName, id });
671
+ }
672
+ /**
673
+ * Deletes a vector by its ID.
674
+ * @param indexName - The name of the index containing the vector.
675
+ * @param id - The ID of the vector to delete.
676
+ * @returns A promise that resolves when the deletion is complete.
677
+ * @throws Will throw an error if the deletion operation fails.
678
+ */
679
+ async deleteVector(...args) {
680
+ const params = this.normalizeArgs("deleteVector", args);
681
+ const { indexName, id } = params;
617
682
  try {
618
683
  await this.client.delete({
619
684
  index: indexName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/opensearch",
3
- "version": "0.0.0-generate-message-id-20250512171942",
3
+ "version": "0.0.0-vector-sources-20250516175436",
4
4
  "description": "OpenSearch vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "dependencies": {
22
22
  "@opensearch-project/opensearch": "^3.4.0",
23
- "@mastra/core": "0.0.0-generate-message-id-20250512171942"
23
+ "@mastra/core": "0.0.0-vector-sources-20250516175436"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@microsoft/api-extractor": "^7.52.1",
@@ -29,7 +29,7 @@
29
29
  "tsup": "^8.4.0",
30
30
  "typescript": "^5.8.2",
31
31
  "vitest": "^3.0.8",
32
- "@internal/lint": "0.0.0-generate-message-id-20250512171942"
32
+ "@internal/lint": "0.0.0-vector-sources-20250516175436"
33
33
  },
34
34
  "scripts": {
35
35
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
@@ -39,31 +39,31 @@ describe('OpenSearchVector', () => {
39
39
 
40
40
  beforeAll(async () => {
41
41
  // Initialize PgVector
42
- vectorDB = new OpenSearchVector(url);
42
+ vectorDB = new OpenSearchVector({ url });
43
43
  });
44
44
 
45
45
  afterAll(async () => {
46
46
  // Clean up test tables
47
- await vectorDB.deleteIndex(testIndexName);
47
+ await vectorDB.deleteIndex({ indexName: testIndexName });
48
48
  });
49
49
 
50
50
  // Index Management Tests
51
51
  describe('Index Management', () => {
52
52
  describe('createIndex', () => {
53
53
  afterAll(async () => {
54
- await vectorDB.deleteIndex(testIndexName2);
54
+ await vectorDB.deleteIndex({ indexName: testIndexName2 });
55
55
  });
56
56
 
57
57
  it('should create a new vector table with specified dimensions', async () => {
58
58
  await vectorDB.createIndex({ indexName: testIndexName, dimension: 3 });
59
- const stats = await vectorDB.describeIndex(testIndexName);
59
+ const stats = await vectorDB.describeIndex({ indexName: testIndexName });
60
60
  expect(stats?.dimension).toBe(3);
61
61
  expect(stats?.count).toBe(0);
62
62
  });
63
63
 
64
64
  it('should create index with specified metric', async () => {
65
65
  await vectorDB.createIndex({ indexName: testIndexName2, dimension: 3, metric: 'euclidean' });
66
- const stats = await vectorDB.describeIndex(testIndexName2);
66
+ const stats = await vectorDB.describeIndex({ indexName: testIndexName2 });
67
67
  expect(stats.metric).toBe('euclidean');
68
68
  });
69
69
 
@@ -75,7 +75,7 @@ describe('OpenSearchVector', () => {
75
75
  describe('metrics', () => {
76
76
  const testIndex = 'test_metric';
77
77
  afterEach(async () => {
78
- await vectorDB.deleteIndex(testIndex);
78
+ await vectorDB.deleteIndex({ indexName: testIndex });
79
79
  });
80
80
  it('should create index with cosine metric', async () => {
81
81
  await vectorDB.createIndex({
@@ -83,7 +83,7 @@ describe('OpenSearchVector', () => {
83
83
  dimension: 3,
84
84
  metric: 'cosine',
85
85
  });
86
- const stats = await vectorDB.describeIndex(testIndex);
86
+ const stats = await vectorDB.describeIndex({ indexName: testIndex });
87
87
  expect(stats.metric).toBe('cosine');
88
88
  });
89
89
 
@@ -93,7 +93,7 @@ describe('OpenSearchVector', () => {
93
93
  dimension: 3,
94
94
  metric: 'euclidean',
95
95
  });
96
- const stats = await vectorDB.describeIndex(testIndex);
96
+ const stats = await vectorDB.describeIndex({ indexName: testIndex });
97
97
  expect(stats.metric).toBe('euclidean');
98
98
  });
99
99
 
@@ -103,7 +103,7 @@ describe('OpenSearchVector', () => {
103
103
  dimension: 3,
104
104
  metric: 'dotproduct',
105
105
  });
106
- const stats = await vectorDB.describeIndex(testIndex);
106
+ const stats = await vectorDB.describeIndex({ indexName: testIndex });
107
107
  expect(stats.metric).toBe('dotproduct');
108
108
  });
109
109
  });
@@ -115,7 +115,7 @@ describe('OpenSearchVector', () => {
115
115
  });
116
116
 
117
117
  afterAll(async () => {
118
- await vectorDB.deleteIndex(indexName);
118
+ await vectorDB.deleteIndex({ indexName });
119
119
  });
120
120
 
121
121
  it('should list all vector tables', async () => {
@@ -124,7 +124,7 @@ describe('OpenSearchVector', () => {
124
124
  });
125
125
 
126
126
  it('should not return created index in list if it is deleted', async () => {
127
- await vectorDB.deleteIndex(indexName);
127
+ await vectorDB.deleteIndex({ indexName });
128
128
  const indexes = await vectorDB.listIndexes();
129
129
  expect(indexes).not.toContain(indexName);
130
130
  });
@@ -137,7 +137,7 @@ describe('OpenSearchVector', () => {
137
137
  });
138
138
 
139
139
  afterAll(async () => {
140
- await vectorDB.deleteIndex(indexName);
140
+ await vectorDB.deleteIndex({ indexName });
141
141
  });
142
142
 
143
143
  it('should return correct index stats', async () => {
@@ -147,7 +147,7 @@ describe('OpenSearchVector', () => {
147
147
  ];
148
148
  await vectorDB.upsert({ indexName, vectors });
149
149
 
150
- const stats = await vectorDB.describeIndex(indexName);
150
+ const stats = await vectorDB.describeIndex({ indexName });
151
151
  expect(stats).toEqual({
152
152
  dimension: 3,
153
153
  count: 2,
@@ -156,7 +156,7 @@ describe('OpenSearchVector', () => {
156
156
  });
157
157
 
158
158
  it('should throw error for non-existent index', async () => {
159
- await expect(vectorDB.describeIndex('non_existent')).rejects.toThrow();
159
+ await expect(vectorDB.describeIndex({ indexName: 'non_existent' })).rejects.toThrow();
160
160
  });
161
161
  });
162
162
 
@@ -170,7 +170,7 @@ describe('OpenSearchVector', () => {
170
170
  expect(indexes).toContain(testIndexName);
171
171
 
172
172
  // Delete the index after the test
173
- await vectorDB.deleteIndex(testIndexName);
173
+ await vectorDB.deleteIndex({ indexName: testIndexName });
174
174
  });
175
175
 
176
176
  it('should throw an error if dimension is not a positive integer', async () => {
@@ -186,7 +186,7 @@ describe('OpenSearchVector', () => {
186
186
  let indexes = await vectorDB.listIndexes();
187
187
  expect(indexes).toContain(deleteTestIndex);
188
188
 
189
- await vectorDB.deleteIndex(deleteTestIndex);
189
+ await vectorDB.deleteIndex({ indexName: deleteTestIndex });
190
190
 
191
191
  indexes = await vectorDB.listIndexes();
192
192
  expect(indexes).not.toContain(deleteTestIndex);
@@ -201,7 +201,7 @@ describe('OpenSearchVector', () => {
201
201
  });
202
202
 
203
203
  afterEach(async () => {
204
- await vectorDB.deleteIndex(testIndexName);
204
+ await vectorDB.deleteIndex({ indexName: testIndexName });
205
205
  });
206
206
 
207
207
  describe('query', () => {
@@ -421,7 +421,7 @@ describe('OpenSearchVector', () => {
421
421
  });
422
422
 
423
423
  afterEach(async () => {
424
- await vectorDB.deleteIndex(testIndexName);
424
+ await vectorDB.deleteIndex({ indexName: testIndexName });
425
425
  });
426
426
 
427
427
  it('should insert new vectors', async () => {
@@ -432,7 +432,7 @@ describe('OpenSearchVector', () => {
432
432
  const ids = await vectorDB.upsert({ indexName: testIndexName, vectors });
433
433
 
434
434
  expect(ids).toHaveLength(2);
435
- const stats = await vectorDB.describeIndex(testIndexName);
435
+ const stats = await vectorDB.describeIndex({ indexName: testIndexName });
436
436
  expect(stats.count).toBe(2);
437
437
  });
438
438
 
@@ -485,7 +485,7 @@ describe('OpenSearchVector', () => {
485
485
  });
486
486
 
487
487
  afterEach(async () => {
488
- await vectorDB.deleteIndex(testIndexName);
488
+ await vectorDB.deleteIndex({ indexName: testIndexName });
489
489
  });
490
490
 
491
491
  it('should update the vector by id', async () => {
@@ -503,7 +503,7 @@ describe('OpenSearchVector', () => {
503
503
  metadata: newMetaData,
504
504
  };
505
505
 
506
- await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
506
+ await vectorDB.updateVector({ indexName: testIndexName, id: idToBeUpdated, update });
507
507
 
508
508
  const results: QueryResult[] = await vectorDB.query({
509
509
  indexName: testIndexName,
@@ -530,7 +530,7 @@ describe('OpenSearchVector', () => {
530
530
  metadata: newMetaData,
531
531
  };
532
532
 
533
- await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
533
+ await vectorDB.updateVector({ indexName: testIndexName, id: idToBeUpdated, update });
534
534
 
535
535
  const results: QueryResult[] = await vectorDB.query({
536
536
  indexName: testIndexName,
@@ -555,7 +555,7 @@ describe('OpenSearchVector', () => {
555
555
  vector: newVector,
556
556
  };
557
557
 
558
- await vectorDB.updateIndexById(testIndexName, idToBeUpdated, update);
558
+ await vectorDB.updateVector({ indexName: testIndexName, id: idToBeUpdated, update });
559
559
 
560
560
  const results: QueryResult[] = await vectorDB.query({
561
561
  indexName: testIndexName,
@@ -569,7 +569,9 @@ describe('OpenSearchVector', () => {
569
569
  });
570
570
 
571
571
  it('should throw exception when no updates are given', async () => {
572
- await expect(vectorDB.updateIndexById(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
572
+ await expect(vectorDB.updateVector({ indexName: testIndexName, id: 'id', update: {} })).rejects.toThrow(
573
+ 'No updates provided',
574
+ );
573
575
  });
574
576
  });
575
577
 
@@ -586,7 +588,7 @@ describe('OpenSearchVector', () => {
586
588
  });
587
589
 
588
590
  afterEach(async () => {
589
- await vectorDB.deleteIndex(testIndexName);
591
+ await vectorDB.deleteIndex({ indexName: testIndexName });
590
592
  });
591
593
 
592
594
  it('should delete the vector by id', async () => {
@@ -594,7 +596,7 @@ describe('OpenSearchVector', () => {
594
596
  expect(ids).toHaveLength(3);
595
597
  const idToBeDeleted = ids[0];
596
598
 
597
- await vectorDB.deleteIndexById(testIndexName, idToBeDeleted);
599
+ await vectorDB.deleteVector({ indexName: testIndexName, id: idToBeDeleted });
598
600
 
599
601
  const results: QueryResult[] = await vectorDB.query({
600
602
  indexName: testIndexName,
@@ -663,7 +665,7 @@ describe('OpenSearchVector', () => {
663
665
  });
664
666
 
665
667
  afterEach(async () => {
666
- await vectorDB.deleteIndex(indexName);
668
+ await vectorDB.deleteIndex({ indexName });
667
669
  });
668
670
 
669
671
  // Numeric Comparison Tests
@@ -1487,7 +1489,7 @@ describe('OpenSearchVector', () => {
1487
1489
  });
1488
1490
 
1489
1491
  afterAll(async () => {
1490
- await vectorDB.deleteIndex(testIndexName);
1492
+ await vectorDB.deleteIndex({ indexName: testIndexName });
1491
1493
  });
1492
1494
 
1493
1495
  it('should handle non-existent index queries', async () => {
@@ -1550,7 +1552,7 @@ describe('OpenSearchVector', () => {
1550
1552
  infoSpy.mockRestore();
1551
1553
  warnSpy.mockRestore();
1552
1554
  // Cleanup
1553
- await vectorDB.deleteIndex(duplicateIndexName);
1555
+ await vectorDB.deleteIndex({ indexName: duplicateIndexName });
1554
1556
  }
1555
1557
  });
1556
1558
  });
@@ -1,4 +1,15 @@
1
- import type { CreateIndexParams, IndexStats, QueryResult, QueryVectorParams, UpsertVectorParams } from '@mastra/core';
1
+ import type {
2
+ CreateIndexParams,
3
+ DeleteIndexParams,
4
+ DeleteVectorParams,
5
+ DescribeIndexParams,
6
+ IndexStats,
7
+ ParamsToArgs,
8
+ QueryResult,
9
+ QueryVectorParams,
10
+ UpdateVectorParams,
11
+ UpsertVectorParams,
12
+ } from '@mastra/core';
2
13
  import { MastraVector } from '@mastra/core/vector';
3
14
  import type { VectorFilter } from '@mastra/core/vector/filter';
4
15
  import { Client as OpenSearchClient } from '@opensearch-project/opensearch';
@@ -19,8 +30,33 @@ const REVERSE_METRIC_MAPPING = {
19
30
  export class OpenSearchVector extends MastraVector {
20
31
  private client: OpenSearchClient;
21
32
 
22
- constructor(url: string) {
33
+ /**
34
+ * @deprecated Passing a string URL is deprecated. Use an object parameter: { url }.
35
+ * @param url - The OpenSearch node URL (deprecated)
36
+ */
37
+ constructor(url: string);
38
+ /**
39
+ * Creates a new OpenSearchVector client.
40
+ *
41
+ * @param params - An object with a url property specifying the OpenSearch node.
42
+ */
43
+ constructor(params: { url: string });
44
+ constructor(paramsOrUrl: { url: string } | string) {
23
45
  super();
46
+ let url: string;
47
+ if (typeof paramsOrUrl === 'string') {
48
+ // Deprecation warning for positional argument
49
+ if (typeof console !== 'undefined' && console.warn) {
50
+ console.warn(
51
+ 'Deprecation Warning: OpenSearchVector constructor positional arguments are deprecated. Please use a single object parameter instead. This signature will be removed on May 20th, 2025.',
52
+ );
53
+ }
54
+ url = paramsOrUrl;
55
+ } else if (typeof paramsOrUrl === 'object' && paramsOrUrl !== null && 'url' in paramsOrUrl) {
56
+ url = paramsOrUrl.url;
57
+ } else {
58
+ throw new Error('Invalid parameters for OpenSearchVector constructor. Expected { url: string }.');
59
+ }
24
60
  this.client = new OpenSearchClient({ node: url });
25
61
  }
26
62
 
@@ -93,7 +129,17 @@ export class OpenSearchVector extends MastraVector {
93
129
  }
94
130
  }
95
131
 
96
- async describeIndex(indexName: string): Promise<IndexStats> {
132
+ /**
133
+ * Retrieves statistics about a vector index.
134
+ *
135
+ * @param params - The parameters for describing an index
136
+ * @param params.indexName - The name of the index to describe
137
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
138
+ */
139
+ async describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats> {
140
+ const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
141
+
142
+ const { indexName } = params;
97
143
  const { body: indexInfo } = await this.client.indices.get({ index: indexName });
98
144
  const mappings = indexInfo[indexName]?.mappings;
99
145
  const embedding: any = mappings?.properties?.embedding;
@@ -114,7 +160,10 @@ export class OpenSearchVector extends MastraVector {
114
160
  * @param {string} indexName - The name of the index to delete.
115
161
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
116
162
  */
117
- async deleteIndex(indexName: string): Promise<void> {
163
+ async deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void> {
164
+ const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
165
+
166
+ const { indexName } = params;
118
167
  try {
119
168
  await this.client.indices.delete({ index: indexName });
120
169
  } catch (error) {
@@ -138,7 +187,7 @@ export class OpenSearchVector extends MastraVector {
138
187
  const operations = [];
139
188
 
140
189
  // Get index stats to check dimension
141
- const indexInfo = await this.describeIndex(indexName);
190
+ const indexInfo = await this.describeIndex({ indexName });
142
191
 
143
192
  // Validate vector dimensions
144
193
  this.validateVectorDimensions(vectors, indexInfo.dimension);
@@ -244,23 +293,43 @@ export class OpenSearchVector extends MastraVector {
244
293
  }
245
294
 
246
295
  /**
247
- * Updates a specific document in the index by ID.
296
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
248
297
  *
249
- * @param {string} indexName - The name of the index containing the document.
250
- * @param {string} id - The ID of the document to update.
251
- * @param {Object} update - The update to apply to the document.
252
- * @param {number[]} [update.vector] - Optional new vector to update.
253
- * @param {Record<string, any>} [update.metadata] - Optional new metadata to update.
254
- * @returns {Promise<void>} A promise that resolves when the document is updated.
298
+ * Updates a vector by its ID with the provided vector and/or metadata.
299
+ * @param indexName - The name of the index containing the vector.
300
+ * @param id - The ID of the vector to update.
301
+ * @param update - An object containing the vector and/or metadata to update.
302
+ * @param update.vector - An optional array of numbers representing the new vector.
303
+ * @param update.metadata - An optional record containing the new metadata.
304
+ * @returns A promise that resolves when the update is complete.
305
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
255
306
  */
256
307
  async updateIndexById(
257
308
  indexName: string,
258
309
  id: string,
259
- update: {
260
- vector?: number[];
261
- metadata?: Record<string, any>;
262
- },
310
+ update: { vector?: number[]; metadata?: Record<string, any> },
263
311
  ): Promise<void> {
312
+ this.logger.warn(
313
+ `Deprecation Warning: updateIndexById() is deprecated.
314
+ Please use updateVector() instead.
315
+ updateIndexById() will be removed on May 20th, 2025.`,
316
+ );
317
+ await this.updateVector({ indexName, id, update });
318
+ }
319
+
320
+ /**
321
+ * Updates a vector by its ID with the provided vector and/or metadata.
322
+ * @param indexName - The name of the index containing the vector.
323
+ * @param id - The ID of the vector to update.
324
+ * @param update - An object containing the vector and/or metadata to update.
325
+ * @param update.vector - An optional array of numbers representing the new vector.
326
+ * @param update.metadata - An optional record containing the new metadata.
327
+ * @returns A promise that resolves when the update is complete.
328
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
329
+ */
330
+ async updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void> {
331
+ const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
332
+ const { indexName, id, update } = params;
264
333
  if (!update.vector && !update.metadata) {
265
334
  throw new Error('No updates provided');
266
335
  }
@@ -288,7 +357,7 @@ export class OpenSearchVector extends MastraVector {
288
357
  // Update vector if provided
289
358
  if (update.vector) {
290
359
  // Get index stats to check dimension
291
- const indexInfo = await this.describeIndex(indexName);
360
+ const indexInfo = await this.describeIndex({ indexName });
292
361
 
293
362
  // Validate vector dimensions
294
363
  this.validateVectorDimensions([update.vector], indexInfo.dimension);
@@ -319,13 +388,33 @@ export class OpenSearchVector extends MastraVector {
319
388
  }
320
389
 
321
390
  /**
322
- * Deletes a specific document from the index by ID.
391
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
323
392
  *
324
- * @param {string} indexName - The name of the index containing the document.
325
- * @param {string} id - The ID of the document to delete.
326
- * @returns {Promise<void>} A promise that resolves when the document is deleted.
393
+ * Deletes a vector by its ID.
394
+ * @param indexName - The name of the index containing the vector.
395
+ * @param id - The ID of the vector to delete.
396
+ * @returns A promise that resolves when the deletion is complete.
397
+ * @throws Will throw an error if the deletion operation fails.
327
398
  */
328
399
  async deleteIndexById(indexName: string, id: string): Promise<void> {
400
+ this.logger.warn(
401
+ `Deprecation Warning: deleteIndexById() is deprecated.
402
+ Please use deleteVector() instead.
403
+ deleteIndexById() will be removed on May 20th, 2025.`,
404
+ );
405
+ await this.deleteVector({ indexName, id });
406
+ }
407
+
408
+ /**
409
+ * Deletes a vector by its ID.
410
+ * @param indexName - The name of the index containing the vector.
411
+ * @param id - The ID of the vector to delete.
412
+ * @returns A promise that resolves when the deletion is complete.
413
+ * @throws Will throw an error if the deletion operation fails.
414
+ */
415
+ async deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void> {
416
+ const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
417
+ const { indexName, id } = params;
329
418
  try {
330
419
  await this.client.delete({
331
420
  index: indexName,