@mastra/opensearch 0.1.2-alpha.0 → 0.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/opensearch@0.1.2-alpha.0 build /home/runner/work/mastra/mastra/stores/opensearch
2
+ > @mastra/opensearch@0.2.0-alpha.1 build /home/runner/work/mastra/mastra/stores/opensearch
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 10177ms
9
+ TSC ⚡️ Build success in 10415ms
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/opensearch/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/opensearch/dist/_tsup-dts-rollup.d.cts
16
- DTS ⚡️ Build success in 10541ms
16
+ DTS ⚡️ Build success in 11166ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 24.34 KB
21
- ESM ⚡️ Build success in 870ms
22
- CJS dist/index.cjs 24.39 KB
23
- CJS ⚡️ Build success in 870ms
20
+ ESM dist/index.js 21.72 KB
21
+ ESM ⚡️ Build success in 764ms
22
+ CJS dist/index.cjs 21.76 KB
23
+ CJS ⚡️ Build success in 763ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @mastra/opensearch
2
2
 
3
+ ## 0.2.0-alpha.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 83da932: Move @mastra/core to peerdeps
8
+
9
+ ### Patch Changes
10
+
11
+ - a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
12
+ - Updated dependencies [b3a3d63]
13
+ - Updated dependencies [344f453]
14
+ - Updated dependencies [0a3ae6d]
15
+ - Updated dependencies [95911be]
16
+ - Updated dependencies [5eb5a99]
17
+ - Updated dependencies [7e632c5]
18
+ - Updated dependencies [1e9fbfa]
19
+ - Updated dependencies [b2ae5aa]
20
+ - Updated dependencies [a7292b0]
21
+ - Updated dependencies [0dcb9f0]
22
+ - @mastra/core@0.10.0-alpha.1
23
+
3
24
  ## 0.1.2-alpha.0
4
25
 
5
26
  ### Patch Changes
@@ -6,7 +6,6 @@ import type { DescribeIndexParams } from '@mastra/core';
6
6
  import type { IndexStats } from '@mastra/core';
7
7
  import { MastraVector } from '@mastra/core/vector';
8
8
  import type { OperatorSupport } from '@mastra/core/vector/filter';
9
- import type { ParamsToArgs } from '@mastra/core';
10
9
  import type { QueryResult } from '@mastra/core';
11
10
  import type { QueryVectorParams } from '@mastra/core';
12
11
  import type { UpdateVectorParams } from '@mastra/core';
@@ -55,17 +54,12 @@ export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
55
54
 
56
55
  declare class OpenSearchVector extends MastraVector {
57
56
  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
- */
62
- constructor(url: string);
63
57
  /**
64
58
  * Creates a new OpenSearchVector client.
65
59
  *
66
- * @param params - An object with a url property specifying the OpenSearch node.
60
+ * @param {string} url - The url of the OpenSearch node.
67
61
  */
68
- constructor(params: {
62
+ constructor({ url }: {
69
63
  url: string;
70
64
  });
71
65
  /**
@@ -76,7 +70,7 @@ declare class OpenSearchVector extends MastraVector {
76
70
  * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
77
71
  * @returns {Promise<void>} A promise that resolves when the collection is created.
78
72
  */
79
- createIndex(params: CreateIndexParams): Promise<void>;
73
+ createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
80
74
  /**
81
75
  * Lists all indexes.
82
76
  *
@@ -86,18 +80,17 @@ declare class OpenSearchVector extends MastraVector {
86
80
  /**
87
81
  * Retrieves statistics about a vector index.
88
82
  *
89
- * @param params - The parameters for describing an index
90
- * @param params.indexName - The name of the index to describe
83
+ * @param {string} indexName - The name of the index to describe
91
84
  * @returns A promise that resolves to the index statistics including dimension, count and metric
92
85
  */
93
- describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
86
+ describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
94
87
  /**
95
88
  * Deletes the specified index.
96
89
  *
97
90
  * @param {string} indexName - The name of the index to delete.
98
91
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
99
92
  */
100
- deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
93
+ deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
101
94
  /**
102
95
  * Inserts or updates vectors in the specified collection.
103
96
  *
@@ -107,7 +100,7 @@ declare class OpenSearchVector extends MastraVector {
107
100
  * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
108
101
  * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
109
102
  */
110
- upsert(params: UpsertVectorParams): Promise<string[]>;
103
+ upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
111
104
  /**
112
105
  * Queries the specified collection using a vector and optional filter.
113
106
  *
@@ -118,7 +111,7 @@ declare class OpenSearchVector extends MastraVector {
118
111
  * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
119
112
  * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
120
113
  */
121
- query(params: QueryVectorParams): Promise<QueryResult[]>;
114
+ query({ indexName, queryVector, filter, topK, includeVector, }: QueryVectorParams): Promise<QueryResult[]>;
122
115
  /**
123
116
  * Validates the dimensions of the vectors.
124
117
  *
@@ -135,8 +128,6 @@ declare class OpenSearchVector extends MastraVector {
135
128
  */
136
129
  private transformFilter;
137
130
  /**
138
- * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
139
- *
140
131
  * Updates a vector by its ID with the provided vector and/or metadata.
141
132
  * @param indexName - The name of the index containing the vector.
142
133
  * @param id - The ID of the vector to update.
@@ -146,31 +137,7 @@ declare class OpenSearchVector extends MastraVector {
146
137
  * @returns A promise that resolves when the update is complete.
147
138
  * @throws Will throw an error if no updates are provided or if the update operation fails.
148
139
  */
149
- updateIndexById(indexName: string, id: string, update: {
150
- vector?: number[];
151
- metadata?: Record<string, any>;
152
- }): Promise<void>;
153
- /**
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.
166
- *
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.
172
- */
173
- deleteIndexById(indexName: string, id: string): Promise<void>;
140
+ updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
174
141
  /**
175
142
  * Deletes a vector by its ID.
176
143
  * @param indexName - The name of the index containing the vector.
@@ -178,7 +145,7 @@ declare class OpenSearchVector extends MastraVector {
178
145
  * @returns A promise that resolves when the deletion is complete.
179
146
  * @throws Will throw an error if the deletion operation fails.
180
147
  */
181
- deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
148
+ deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
182
149
  }
183
150
  export { OpenSearchVector }
184
151
  export { OpenSearchVector as OpenSearchVector_alias_1 }
@@ -6,7 +6,6 @@ import type { DescribeIndexParams } from '@mastra/core';
6
6
  import type { IndexStats } from '@mastra/core';
7
7
  import { MastraVector } from '@mastra/core/vector';
8
8
  import type { OperatorSupport } from '@mastra/core/vector/filter';
9
- import type { ParamsToArgs } from '@mastra/core';
10
9
  import type { QueryResult } from '@mastra/core';
11
10
  import type { QueryVectorParams } from '@mastra/core';
12
11
  import type { UpdateVectorParams } from '@mastra/core';
@@ -55,17 +54,12 @@ export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
55
54
 
56
55
  declare class OpenSearchVector extends MastraVector {
57
56
  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
- */
62
- constructor(url: string);
63
57
  /**
64
58
  * Creates a new OpenSearchVector client.
65
59
  *
66
- * @param params - An object with a url property specifying the OpenSearch node.
60
+ * @param {string} url - The url of the OpenSearch node.
67
61
  */
68
- constructor(params: {
62
+ constructor({ url }: {
69
63
  url: string;
70
64
  });
71
65
  /**
@@ -76,7 +70,7 @@ declare class OpenSearchVector extends MastraVector {
76
70
  * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
77
71
  * @returns {Promise<void>} A promise that resolves when the collection is created.
78
72
  */
79
- createIndex(params: CreateIndexParams): Promise<void>;
73
+ createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
80
74
  /**
81
75
  * Lists all indexes.
82
76
  *
@@ -86,18 +80,17 @@ declare class OpenSearchVector extends MastraVector {
86
80
  /**
87
81
  * Retrieves statistics about a vector index.
88
82
  *
89
- * @param params - The parameters for describing an index
90
- * @param params.indexName - The name of the index to describe
83
+ * @param {string} indexName - The name of the index to describe
91
84
  * @returns A promise that resolves to the index statistics including dimension, count and metric
92
85
  */
93
- describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
86
+ describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
94
87
  /**
95
88
  * Deletes the specified index.
96
89
  *
97
90
  * @param {string} indexName - The name of the index to delete.
98
91
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
99
92
  */
100
- deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
93
+ deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
101
94
  /**
102
95
  * Inserts or updates vectors in the specified collection.
103
96
  *
@@ -107,7 +100,7 @@ declare class OpenSearchVector extends MastraVector {
107
100
  * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
108
101
  * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
109
102
  */
110
- upsert(params: UpsertVectorParams): Promise<string[]>;
103
+ upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
111
104
  /**
112
105
  * Queries the specified collection using a vector and optional filter.
113
106
  *
@@ -118,7 +111,7 @@ declare class OpenSearchVector extends MastraVector {
118
111
  * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
119
112
  * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
120
113
  */
121
- query(params: QueryVectorParams): Promise<QueryResult[]>;
114
+ query({ indexName, queryVector, filter, topK, includeVector, }: QueryVectorParams): Promise<QueryResult[]>;
122
115
  /**
123
116
  * Validates the dimensions of the vectors.
124
117
  *
@@ -135,8 +128,6 @@ declare class OpenSearchVector extends MastraVector {
135
128
  */
136
129
  private transformFilter;
137
130
  /**
138
- * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
139
- *
140
131
  * Updates a vector by its ID with the provided vector and/or metadata.
141
132
  * @param indexName - The name of the index containing the vector.
142
133
  * @param id - The ID of the vector to update.
@@ -146,31 +137,7 @@ declare class OpenSearchVector extends MastraVector {
146
137
  * @returns A promise that resolves when the update is complete.
147
138
  * @throws Will throw an error if no updates are provided or if the update operation fails.
148
139
  */
149
- updateIndexById(indexName: string, id: string, update: {
150
- vector?: number[];
151
- metadata?: Record<string, any>;
152
- }): Promise<void>;
153
- /**
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.
166
- *
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.
172
- */
173
- deleteIndexById(indexName: string, id: string): Promise<void>;
140
+ updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
174
141
  /**
175
142
  * Deletes a vector by its ID.
176
143
  * @param indexName - The name of the index containing the vector.
@@ -178,7 +145,7 @@ declare class OpenSearchVector extends MastraVector {
178
145
  * @returns A promise that resolves when the deletion is complete.
179
146
  * @throws Will throw an error if the deletion operation fails.
180
147
  */
181
- deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
148
+ deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
182
149
  }
183
150
  export { OpenSearchVector }
184
151
  export { OpenSearchVector as OpenSearchVector_alias_1 }
package/dist/index.cjs CHANGED
@@ -364,21 +364,13 @@ var REVERSE_METRIC_MAPPING = {
364
364
  };
365
365
  var OpenSearchVector = class extends vector.MastraVector {
366
366
  client;
367
- constructor(paramsOrUrl) {
367
+ /**
368
+ * Creates a new OpenSearchVector client.
369
+ *
370
+ * @param {string} url - The url of the OpenSearch node.
371
+ */
372
+ constructor({ url }) {
368
373
  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
- }
382
374
  this.client = new opensearch.Client({ node: url });
383
375
  }
384
376
  /**
@@ -389,8 +381,7 @@ var OpenSearchVector = class extends vector.MastraVector {
389
381
  * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
390
382
  * @returns {Promise<void>} A promise that resolves when the collection is created.
391
383
  */
392
- async createIndex(params) {
393
- const { indexName, dimension, metric = "cosine" } = params;
384
+ async createIndex({ indexName, dimension, metric = "cosine" }) {
394
385
  if (!Number.isInteger(dimension) || dimension <= 0) {
395
386
  throw new Error("Dimension must be a positive integer");
396
387
  }
@@ -445,13 +436,10 @@ var OpenSearchVector = class extends vector.MastraVector {
445
436
  /**
446
437
  * Retrieves statistics about a vector index.
447
438
  *
448
- * @param params - The parameters for describing an index
449
- * @param params.indexName - The name of the index to describe
439
+ * @param {string} indexName - The name of the index to describe
450
440
  * @returns A promise that resolves to the index statistics including dimension, count and metric
451
441
  */
452
- async describeIndex(...args) {
453
- const params = this.normalizeArgs("describeIndex", args);
454
- const { indexName } = params;
442
+ async describeIndex({ indexName }) {
455
443
  const { body: indexInfo } = await this.client.indices.get({ index: indexName });
456
444
  const mappings = indexInfo[indexName]?.mappings;
457
445
  const embedding = mappings?.properties?.embedding;
@@ -469,9 +457,7 @@ var OpenSearchVector = class extends vector.MastraVector {
469
457
  * @param {string} indexName - The name of the index to delete.
470
458
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
471
459
  */
472
- async deleteIndex(...args) {
473
- const params = this.normalizeArgs("deleteIndex", args);
474
- const { indexName } = params;
460
+ async deleteIndex({ indexName }) {
475
461
  try {
476
462
  await this.client.indices.delete({ index: indexName });
477
463
  } catch (error) {
@@ -487,8 +473,7 @@ var OpenSearchVector = class extends vector.MastraVector {
487
473
  * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
488
474
  * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
489
475
  */
490
- async upsert(params) {
491
- const { indexName, vectors, metadata = [], ids } = params;
476
+ async upsert({ indexName, vectors, metadata = [], ids }) {
492
477
  const vectorIds = ids || vectors.map(() => crypto.randomUUID());
493
478
  const operations = [];
494
479
  const indexInfo = await this.describeIndex({ indexName });
@@ -528,8 +513,13 @@ var OpenSearchVector = class extends vector.MastraVector {
528
513
  * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
529
514
  * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
530
515
  */
531
- async query(params) {
532
- const { indexName, queryVector, filter, topK = 10, includeVector = false } = params;
516
+ async query({
517
+ indexName,
518
+ queryVector,
519
+ filter,
520
+ topK = 10,
521
+ includeVector = false
522
+ }) {
533
523
  try {
534
524
  const translatedFilter = this.transformFilter(filter);
535
525
  const response = await this.client.search({
@@ -581,26 +571,6 @@ var OpenSearchVector = class extends vector.MastraVector {
581
571
  const translator = new OpenSearchFilterTranslator();
582
572
  return translator.translate(filter);
583
573
  }
584
- /**
585
- * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
586
- *
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.
595
- */
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
574
  /**
605
575
  * Updates a vector by its ID with the provided vector and/or metadata.
606
576
  * @param indexName - The name of the index containing the vector.
@@ -611,9 +581,7 @@ var OpenSearchVector = class extends vector.MastraVector {
611
581
  * @returns A promise that resolves when the update is complete.
612
582
  * @throws Will throw an error if no updates are provided or if the update operation fails.
613
583
  */
614
- async updateVector(...args) {
615
- const params = this.normalizeArgs("updateVector", args);
616
- const { indexName, id, update } = params;
584
+ async updateVector({ indexName, id, update }) {
617
585
  if (!update.vector && !update.metadata) {
618
586
  throw new Error("No updates provided");
619
587
  }
@@ -654,23 +622,6 @@ var OpenSearchVector = class extends vector.MastraVector {
654
622
  throw error;
655
623
  }
656
624
  }
657
- /**
658
- * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
659
- *
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.
665
- */
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
625
  /**
675
626
  * Deletes a vector by its ID.
676
627
  * @param indexName - The name of the index containing the vector.
@@ -678,9 +629,7 @@ var OpenSearchVector = class extends vector.MastraVector {
678
629
  * @returns A promise that resolves when the deletion is complete.
679
630
  * @throws Will throw an error if the deletion operation fails.
680
631
  */
681
- async deleteVector(...args) {
682
- const params = this.normalizeArgs("deleteVector", args);
683
- const { indexName, id } = params;
632
+ async deleteVector({ indexName, id }) {
684
633
  try {
685
634
  await this.client.delete({
686
635
  index: indexName,
package/dist/index.js CHANGED
@@ -362,21 +362,13 @@ var REVERSE_METRIC_MAPPING = {
362
362
  };
363
363
  var OpenSearchVector = class extends MastraVector {
364
364
  client;
365
- constructor(paramsOrUrl) {
365
+ /**
366
+ * Creates a new OpenSearchVector client.
367
+ *
368
+ * @param {string} url - The url of the OpenSearch node.
369
+ */
370
+ constructor({ url }) {
366
371
  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
- }
380
372
  this.client = new Client({ node: url });
381
373
  }
382
374
  /**
@@ -387,8 +379,7 @@ var OpenSearchVector = class extends MastraVector {
387
379
  * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
388
380
  * @returns {Promise<void>} A promise that resolves when the collection is created.
389
381
  */
390
- async createIndex(params) {
391
- const { indexName, dimension, metric = "cosine" } = params;
382
+ async createIndex({ indexName, dimension, metric = "cosine" }) {
392
383
  if (!Number.isInteger(dimension) || dimension <= 0) {
393
384
  throw new Error("Dimension must be a positive integer");
394
385
  }
@@ -443,13 +434,10 @@ var OpenSearchVector = class extends MastraVector {
443
434
  /**
444
435
  * Retrieves statistics about a vector index.
445
436
  *
446
- * @param params - The parameters for describing an index
447
- * @param params.indexName - The name of the index to describe
437
+ * @param {string} indexName - The name of the index to describe
448
438
  * @returns A promise that resolves to the index statistics including dimension, count and metric
449
439
  */
450
- async describeIndex(...args) {
451
- const params = this.normalizeArgs("describeIndex", args);
452
- const { indexName } = params;
440
+ async describeIndex({ indexName }) {
453
441
  const { body: indexInfo } = await this.client.indices.get({ index: indexName });
454
442
  const mappings = indexInfo[indexName]?.mappings;
455
443
  const embedding = mappings?.properties?.embedding;
@@ -467,9 +455,7 @@ var OpenSearchVector = class extends MastraVector {
467
455
  * @param {string} indexName - The name of the index to delete.
468
456
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
469
457
  */
470
- async deleteIndex(...args) {
471
- const params = this.normalizeArgs("deleteIndex", args);
472
- const { indexName } = params;
458
+ async deleteIndex({ indexName }) {
473
459
  try {
474
460
  await this.client.indices.delete({ index: indexName });
475
461
  } catch (error) {
@@ -485,8 +471,7 @@ var OpenSearchVector = class extends MastraVector {
485
471
  * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
486
472
  * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
487
473
  */
488
- async upsert(params) {
489
- const { indexName, vectors, metadata = [], ids } = params;
474
+ async upsert({ indexName, vectors, metadata = [], ids }) {
490
475
  const vectorIds = ids || vectors.map(() => crypto.randomUUID());
491
476
  const operations = [];
492
477
  const indexInfo = await this.describeIndex({ indexName });
@@ -526,8 +511,13 @@ var OpenSearchVector = class extends MastraVector {
526
511
  * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
527
512
  * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
528
513
  */
529
- async query(params) {
530
- const { indexName, queryVector, filter, topK = 10, includeVector = false } = params;
514
+ async query({
515
+ indexName,
516
+ queryVector,
517
+ filter,
518
+ topK = 10,
519
+ includeVector = false
520
+ }) {
531
521
  try {
532
522
  const translatedFilter = this.transformFilter(filter);
533
523
  const response = await this.client.search({
@@ -579,26 +569,6 @@ var OpenSearchVector = class extends MastraVector {
579
569
  const translator = new OpenSearchFilterTranslator();
580
570
  return translator.translate(filter);
581
571
  }
582
- /**
583
- * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
584
- *
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.
593
- */
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
572
  /**
603
573
  * Updates a vector by its ID with the provided vector and/or metadata.
604
574
  * @param indexName - The name of the index containing the vector.
@@ -609,9 +579,7 @@ var OpenSearchVector = class extends MastraVector {
609
579
  * @returns A promise that resolves when the update is complete.
610
580
  * @throws Will throw an error if no updates are provided or if the update operation fails.
611
581
  */
612
- async updateVector(...args) {
613
- const params = this.normalizeArgs("updateVector", args);
614
- const { indexName, id, update } = params;
582
+ async updateVector({ indexName, id, update }) {
615
583
  if (!update.vector && !update.metadata) {
616
584
  throw new Error("No updates provided");
617
585
  }
@@ -652,23 +620,6 @@ var OpenSearchVector = class extends MastraVector {
652
620
  throw error;
653
621
  }
654
622
  }
655
- /**
656
- * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
657
- *
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.
663
- */
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
623
  /**
673
624
  * Deletes a vector by its ID.
674
625
  * @param indexName - The name of the index containing the vector.
@@ -676,9 +627,7 @@ var OpenSearchVector = class extends MastraVector {
676
627
  * @returns A promise that resolves when the deletion is complete.
677
628
  * @throws Will throw an error if the deletion operation fails.
678
629
  */
679
- async deleteVector(...args) {
680
- const params = this.normalizeArgs("deleteVector", args);
681
- const { indexName, id } = params;
630
+ async deleteVector({ indexName, id }) {
682
631
  try {
683
632
  await this.client.delete({
684
633
  index: indexName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/opensearch",
3
- "version": "0.1.2-alpha.0",
3
+ "version": "0.2.0-alpha.1",
4
4
  "description": "OpenSearch vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -19,8 +19,7 @@
19
19
  "./package.json": "./package.json"
20
20
  },
21
21
  "dependencies": {
22
- "@opensearch-project/opensearch": "^3.4.0",
23
- "@mastra/core": "^0.9.5-alpha.0"
22
+ "@opensearch-project/opensearch": "^3.4.0"
24
23
  },
25
24
  "devDependencies": {
26
25
  "@microsoft/api-extractor": "^7.52.1",
@@ -29,7 +28,11 @@
29
28
  "tsup": "^8.4.0",
30
29
  "typescript": "^5.8.2",
31
30
  "vitest": "^3.0.8",
32
- "@internal/lint": "0.0.5"
31
+ "@internal/lint": "0.0.5",
32
+ "@mastra/core": "0.10.0-alpha.1"
33
+ },
34
+ "peerDependencies": {
35
+ "@mastra/core": "^0.9.4"
33
36
  },
34
37
  "scripts": {
35
38
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
@@ -4,7 +4,6 @@ import type {
4
4
  DeleteVectorParams,
5
5
  DescribeIndexParams,
6
6
  IndexStats,
7
- ParamsToArgs,
8
7
  QueryResult,
9
8
  QueryVectorParams,
10
9
  UpdateVectorParams,
@@ -30,33 +29,13 @@ const REVERSE_METRIC_MAPPING = {
30
29
  export class OpenSearchVector extends MastraVector {
31
30
  private client: OpenSearchClient;
32
31
 
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
32
  /**
39
33
  * Creates a new OpenSearchVector client.
40
34
  *
41
- * @param params - An object with a url property specifying the OpenSearch node.
35
+ * @param {string} url - The url of the OpenSearch node.
42
36
  */
43
- constructor(params: { url: string });
44
- constructor(paramsOrUrl: { url: string } | string) {
37
+ constructor({ url }: { url: string }) {
45
38
  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
- }
60
39
  this.client = new OpenSearchClient({ node: url });
61
40
  }
62
41
 
@@ -68,9 +47,7 @@ export class OpenSearchVector extends MastraVector {
68
47
  * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
69
48
  * @returns {Promise<void>} A promise that resolves when the collection is created.
70
49
  */
71
- async createIndex(params: CreateIndexParams): Promise<void> {
72
- const { indexName, dimension, metric = 'cosine' } = params;
73
-
50
+ async createIndex({ indexName, dimension, metric = 'cosine' }: CreateIndexParams): Promise<void> {
74
51
  if (!Number.isInteger(dimension) || dimension <= 0) {
75
52
  throw new Error('Dimension must be a positive integer');
76
53
  }
@@ -132,14 +109,10 @@ export class OpenSearchVector extends MastraVector {
132
109
  /**
133
110
  * Retrieves statistics about a vector index.
134
111
  *
135
- * @param params - The parameters for describing an index
136
- * @param params.indexName - The name of the index to describe
112
+ * @param {string} indexName - The name of the index to describe
137
113
  * @returns A promise that resolves to the index statistics including dimension, count and metric
138
114
  */
139
- async describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats> {
140
- const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
141
-
142
- const { indexName } = params;
115
+ async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {
143
116
  const { body: indexInfo } = await this.client.indices.get({ index: indexName });
144
117
  const mappings = indexInfo[indexName]?.mappings;
145
118
  const embedding: any = mappings?.properties?.embedding;
@@ -160,10 +133,7 @@ export class OpenSearchVector extends MastraVector {
160
133
  * @param {string} indexName - The name of the index to delete.
161
134
  * @returns {Promise<void>} A promise that resolves when the index is deleted.
162
135
  */
163
- async deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void> {
164
- const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
165
-
166
- const { indexName } = params;
136
+ async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
167
137
  try {
168
138
  await this.client.indices.delete({ index: indexName });
169
139
  } catch (error) {
@@ -180,9 +150,7 @@ export class OpenSearchVector extends MastraVector {
180
150
  * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
181
151
  * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
182
152
  */
183
- async upsert(params: UpsertVectorParams): Promise<string[]> {
184
- const { indexName, vectors, metadata = [], ids } = params;
185
-
153
+ async upsert({ indexName, vectors, metadata = [], ids }: UpsertVectorParams): Promise<string[]> {
186
154
  const vectorIds = ids || vectors.map(() => crypto.randomUUID());
187
155
  const operations = [];
188
156
 
@@ -232,9 +200,13 @@ export class OpenSearchVector extends MastraVector {
232
200
  * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
233
201
  * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
234
202
  */
235
- async query(params: QueryVectorParams): Promise<QueryResult[]> {
236
- const { indexName, queryVector, filter, topK = 10, includeVector = false } = params;
237
-
203
+ async query({
204
+ indexName,
205
+ queryVector,
206
+ filter,
207
+ topK = 10,
208
+ includeVector = false,
209
+ }: QueryVectorParams): Promise<QueryResult[]> {
238
210
  try {
239
211
  const translatedFilter = this.transformFilter(filter);
240
212
 
@@ -292,31 +264,6 @@ export class OpenSearchVector extends MastraVector {
292
264
  return translator.translate(filter);
293
265
  }
294
266
 
295
- /**
296
- * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
297
- *
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.
306
- */
307
- async updateIndexById(
308
- indexName: string,
309
- id: string,
310
- update: { vector?: number[]; metadata?: Record<string, any> },
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
267
  /**
321
268
  * Updates a vector by its ID with the provided vector and/or metadata.
322
269
  * @param indexName - The name of the index containing the vector.
@@ -327,9 +274,7 @@ export class OpenSearchVector extends MastraVector {
327
274
  * @returns A promise that resolves when the update is complete.
328
275
  * @throws Will throw an error if no updates are provided or if the update operation fails.
329
276
  */
330
- async updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void> {
331
- const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
332
- const { indexName, id, update } = params;
277
+ async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {
333
278
  if (!update.vector && !update.metadata) {
334
279
  throw new Error('No updates provided');
335
280
  }
@@ -387,24 +332,6 @@ export class OpenSearchVector extends MastraVector {
387
332
  }
388
333
  }
389
334
 
390
- /**
391
- * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
392
- *
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.
398
- */
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
335
  /**
409
336
  * Deletes a vector by its ID.
410
337
  * @param indexName - The name of the index containing the vector.
@@ -412,9 +339,7 @@ export class OpenSearchVector extends MastraVector {
412
339
  * @returns A promise that resolves when the deletion is complete.
413
340
  * @throws Will throw an error if the deletion operation fails.
414
341
  */
415
- async deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void> {
416
- const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
417
- const { indexName, id } = params;
342
+ async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {
418
343
  try {
419
344
  await this.client.delete({
420
345
  index: indexName,