@mastra/opensearch 0.1.1 → 0.1.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,23 +1,23 @@
1
1
 
2
- > @mastra/opensearch@0.1.1-alpha.4 build /home/runner/work/mastra/mastra/stores/opensearch
2
+ > @mastra/opensearch@0.1.2-alpha.0 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 11037ms
9
+ TSC ⚡️ Build success in 10177ms
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 9888ms
16
+ DTS ⚡️ Build success in 10541ms
17
17
  CLI Cleaning output folder
18
18
  ESM Build start
19
19
  CJS Build start
20
- ESM dist/index.js 23.06 KB
21
- ESM ⚡️ Build success in 932ms
22
- CJS dist/index.cjs 23.10 KB
23
- CJS ⚡️ Build success in 941ms
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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @mastra/opensearch
2
2
 
3
+ ## 0.1.2-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
8
+ - Updated dependencies [f53a6ac]
9
+ - Updated dependencies [eabdcd9]
10
+ - Updated dependencies [90be034]
11
+ - Updated dependencies [99f050a]
12
+ - Updated dependencies [d0ee3c6]
13
+ - Updated dependencies [23f258c]
14
+ - Updated dependencies [2672a05]
15
+ - @mastra/core@0.9.5-alpha.0
16
+
3
17
  ## 0.1.1
4
18
 
5
19
  ### Patch Changes
@@ -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
  *
@@ -136,10 +160,7 @@ declare class OpenSearchVector extends MastraVector {
136
160
  * @returns A promise that resolves when the update is complete.
137
161
  * @throws Will throw an error if no updates are provided or if the update operation fails.
138
162
  */
139
- updateVector(indexName: string, id: string, update: {
140
- vector?: number[];
141
- metadata?: Record<string, any>;
142
- }): Promise<void>;
163
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
143
164
  /**
144
165
  * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
145
166
  *
@@ -157,7 +178,7 @@ declare class OpenSearchVector extends MastraVector {
157
178
  * @returns A promise that resolves when the deletion is complete.
158
179
  * @throws Will throw an error if the deletion operation fails.
159
180
  */
160
- deleteVector(indexName: string, id: string): Promise<void>;
181
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
161
182
  }
162
183
  export { OpenSearchVector }
163
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
  *
@@ -136,10 +160,7 @@ declare class OpenSearchVector extends MastraVector {
136
160
  * @returns A promise that resolves when the update is complete.
137
161
  * @throws Will throw an error if no updates are provided or if the update operation fails.
138
162
  */
139
- updateVector(indexName: string, id: string, update: {
140
- vector?: number[];
141
- metadata?: Record<string, any>;
142
- }): Promise<void>;
163
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
143
164
  /**
144
165
  * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
145
166
  *
@@ -157,7 +178,7 @@ declare class OpenSearchVector extends MastraVector {
157
178
  * @returns A promise that resolves when the deletion is complete.
158
179
  * @throws Will throw an error if the deletion operation fails.
159
180
  */
160
- deleteVector(indexName: string, id: string): Promise<void>;
181
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
161
182
  }
162
183
  export { OpenSearchVector }
163
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 = {
@@ -575,7 +599,7 @@ var OpenSearchVector = class extends vector.MastraVector {
575
599
  Please use updateVector() instead.
576
600
  updateIndexById() will be removed on May 20th, 2025.`
577
601
  );
578
- await this.updateVector(indexName, id, update);
602
+ await this.updateVector({ indexName, id, update });
579
603
  }
580
604
  /**
581
605
  * Updates a vector by its ID with the provided vector and/or metadata.
@@ -587,7 +611,9 @@ var OpenSearchVector = class extends vector.MastraVector {
587
611
  * @returns A promise that resolves when the update is complete.
588
612
  * @throws Will throw an error if no updates are provided or if the update operation fails.
589
613
  */
590
- async updateVector(indexName, id, update) {
614
+ async updateVector(...args) {
615
+ const params = this.normalizeArgs("updateVector", args);
616
+ const { indexName, id, update } = params;
591
617
  if (!update.vector && !update.metadata) {
592
618
  throw new Error("No updates provided");
593
619
  }
@@ -606,7 +632,7 @@ var OpenSearchVector = class extends vector.MastraVector {
606
632
  id: source.id || id
607
633
  };
608
634
  if (update.vector) {
609
- const indexInfo = await this.describeIndex(indexName);
635
+ const indexInfo = await this.describeIndex({ indexName });
610
636
  this.validateVectorDimensions([update.vector], indexInfo.dimension);
611
637
  updatedDoc.embedding = update.vector;
612
638
  } else if (source.embedding) {
@@ -643,7 +669,7 @@ var OpenSearchVector = class extends vector.MastraVector {
643
669
  Please use deleteVector() instead.
644
670
  deleteIndexById() will be removed on May 20th, 2025.`
645
671
  );
646
- await this.deleteVector(indexName, id);
672
+ await this.deleteVector({ indexName, id });
647
673
  }
648
674
  /**
649
675
  * Deletes a vector by its ID.
@@ -652,7 +678,9 @@ var OpenSearchVector = class extends vector.MastraVector {
652
678
  * @returns A promise that resolves when the deletion is complete.
653
679
  * @throws Will throw an error if the deletion operation fails.
654
680
  */
655
- async deleteVector(indexName, id) {
681
+ async deleteVector(...args) {
682
+ const params = this.normalizeArgs("deleteVector", args);
683
+ const { indexName, id } = params;
656
684
  try {
657
685
  await this.client.delete({
658
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 = {
@@ -573,7 +597,7 @@ var OpenSearchVector = class extends MastraVector {
573
597
  Please use updateVector() instead.
574
598
  updateIndexById() will be removed on May 20th, 2025.`
575
599
  );
576
- await this.updateVector(indexName, id, update);
600
+ await this.updateVector({ indexName, id, update });
577
601
  }
578
602
  /**
579
603
  * Updates a vector by its ID with the provided vector and/or metadata.
@@ -585,7 +609,9 @@ var OpenSearchVector = class extends MastraVector {
585
609
  * @returns A promise that resolves when the update is complete.
586
610
  * @throws Will throw an error if no updates are provided or if the update operation fails.
587
611
  */
588
- async updateVector(indexName, id, update) {
612
+ async updateVector(...args) {
613
+ const params = this.normalizeArgs("updateVector", args);
614
+ const { indexName, id, update } = params;
589
615
  if (!update.vector && !update.metadata) {
590
616
  throw new Error("No updates provided");
591
617
  }
@@ -604,7 +630,7 @@ var OpenSearchVector = class extends MastraVector {
604
630
  id: source.id || id
605
631
  };
606
632
  if (update.vector) {
607
- const indexInfo = await this.describeIndex(indexName);
633
+ const indexInfo = await this.describeIndex({ indexName });
608
634
  this.validateVectorDimensions([update.vector], indexInfo.dimension);
609
635
  updatedDoc.embedding = update.vector;
610
636
  } else if (source.embedding) {
@@ -641,7 +667,7 @@ var OpenSearchVector = class extends MastraVector {
641
667
  Please use deleteVector() instead.
642
668
  deleteIndexById() will be removed on May 20th, 2025.`
643
669
  );
644
- await this.deleteVector(indexName, id);
670
+ await this.deleteVector({ indexName, id });
645
671
  }
646
672
  /**
647
673
  * Deletes a vector by its ID.
@@ -650,7 +676,9 @@ var OpenSearchVector = class extends MastraVector {
650
676
  * @returns A promise that resolves when the deletion is complete.
651
677
  * @throws Will throw an error if the deletion operation fails.
652
678
  */
653
- async deleteVector(indexName, id) {
679
+ async deleteVector(...args) {
680
+ const params = this.normalizeArgs("deleteVector", args);
681
+ const { indexName, id } = params;
654
682
  try {
655
683
  await this.client.delete({
656
684
  index: indexName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/opensearch",
3
- "version": "0.1.1",
3
+ "version": "0.1.2-alpha.0",
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.9.4"
23
+ "@mastra/core": "^0.9.5-alpha.0"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@microsoft/api-extractor": "^7.52.1",
@@ -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.updateVector(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.updateVector(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.updateVector(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.updateVector(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.deleteVector(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);
@@ -265,7 +314,7 @@ export class OpenSearchVector extends MastraVector {
265
314
  Please use updateVector() instead.
266
315
  updateIndexById() will be removed on May 20th, 2025.`,
267
316
  );
268
- await this.updateVector(indexName, id, update);
317
+ await this.updateVector({ indexName, id, update });
269
318
  }
270
319
 
271
320
  /**
@@ -278,14 +327,9 @@ export class OpenSearchVector extends MastraVector {
278
327
  * @returns A promise that resolves when the update is complete.
279
328
  * @throws Will throw an error if no updates are provided or if the update operation fails.
280
329
  */
281
- async updateVector(
282
- indexName: string,
283
- id: string,
284
- update: {
285
- vector?: number[];
286
- metadata?: Record<string, any>;
287
- },
288
- ): Promise<void> {
330
+ async updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void> {
331
+ const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
332
+ const { indexName, id, update } = params;
289
333
  if (!update.vector && !update.metadata) {
290
334
  throw new Error('No updates provided');
291
335
  }
@@ -313,7 +357,7 @@ export class OpenSearchVector extends MastraVector {
313
357
  // Update vector if provided
314
358
  if (update.vector) {
315
359
  // Get index stats to check dimension
316
- const indexInfo = await this.describeIndex(indexName);
360
+ const indexInfo = await this.describeIndex({ indexName });
317
361
 
318
362
  // Validate vector dimensions
319
363
  this.validateVectorDimensions([update.vector], indexInfo.dimension);
@@ -358,7 +402,7 @@ export class OpenSearchVector extends MastraVector {
358
402
  Please use deleteVector() instead.
359
403
  deleteIndexById() will be removed on May 20th, 2025.`,
360
404
  );
361
- await this.deleteVector(indexName, id);
405
+ await this.deleteVector({ indexName, id });
362
406
  }
363
407
 
364
408
  /**
@@ -368,7 +412,9 @@ export class OpenSearchVector extends MastraVector {
368
412
  * @returns A promise that resolves when the deletion is complete.
369
413
  * @throws Will throw an error if the deletion operation fails.
370
414
  */
371
- async deleteVector(indexName: string, id: string): Promise<void> {
415
+ async deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void> {
416
+ const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
417
+ const { indexName, id } = params;
372
418
  try {
373
419
  await this.client.delete({
374
420
  index: indexName,