@mastra/opensearch 0.0.0-cloud-transporter-20250513033346

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 ADDED
@@ -0,0 +1,64 @@
1
+ # @mastra/opensearch
2
+
3
+ ## 0.0.0-cloud-transporter-20250513033346
4
+
5
+ ### Patch Changes
6
+
7
+ - c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
8
+ - Updated dependencies [396be50]
9
+ - Updated dependencies [ab80e7e]
10
+ - Updated dependencies [c3bd795]
11
+ - Updated dependencies [da082f8]
12
+ - Updated dependencies [a5810ce]
13
+ - Updated dependencies [3171b5b]
14
+ - Updated dependencies [973e5ac]
15
+ - Updated dependencies [daf942f]
16
+ - Updated dependencies [0b8b868]
17
+ - Updated dependencies [9e1eff5]
18
+ - Updated dependencies [6fa1ad1]
19
+ - Updated dependencies [c28d7a0]
20
+ - Updated dependencies [edf1e88]
21
+ - @mastra/core@0.0.0-cloud-transporter-20250513033346
22
+
23
+ ## 0.1.1-alpha.2
24
+
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [3171b5b]
28
+ - Updated dependencies [973e5ac]
29
+ - Updated dependencies [9e1eff5]
30
+ - @mastra/core@0.9.4-alpha.2
31
+
32
+ ## 0.1.1-alpha.1
33
+
34
+ ### Patch Changes
35
+
36
+ - Updated dependencies [ab80e7e]
37
+ - Updated dependencies [6fa1ad1]
38
+ - Updated dependencies [c28d7a0]
39
+ - Updated dependencies [edf1e88]
40
+ - @mastra/core@0.9.4-alpha.1
41
+
42
+ ## 0.1.1-alpha.0
43
+
44
+ ### Patch Changes
45
+
46
+ - Updated dependencies [daf942f]
47
+ - Updated dependencies [0b8b868]
48
+ - @mastra/core@0.9.4-alpha.0
49
+
50
+ ## 0.1.0
51
+
52
+ ### Patch Changes
53
+
54
+ - 4aeff69: feat: add OpenSearch vector storage support
55
+ - Updated dependencies [e450778]
56
+ - Updated dependencies [8902157]
57
+ - Updated dependencies [ca0dc88]
58
+ - Updated dependencies [526c570]
59
+ - Updated dependencies [d7a6a33]
60
+ - Updated dependencies [9cd1a46]
61
+ - Updated dependencies [b5d2de0]
62
+ - Updated dependencies [644f8ad]
63
+ - Updated dependencies [70dbf51]
64
+ - @mastra/core@0.9.3
package/LICENSE.md ADDED
@@ -0,0 +1,46 @@
1
+ # Elastic License 2.0 (ELv2)
2
+
3
+ Copyright (c) 2025 Mastra AI, Inc.
4
+
5
+ **Acceptance**
6
+ By using the software, you agree to all of the terms and conditions below.
7
+
8
+ **Copyright License**
9
+ The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below
10
+
11
+ **Limitations**
12
+ You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
13
+
14
+ You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
15
+
16
+ You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
17
+
18
+ **Patents**
19
+ The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
20
+
21
+ **Notices**
22
+ You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
23
+
24
+ If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
25
+
26
+ **No Other Rights**
27
+ These terms do not imply any licenses other than those expressly granted in these terms.
28
+
29
+ **Termination**
30
+ If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
31
+
32
+ **No Liability**
33
+ As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
34
+
35
+ **Definitions**
36
+ The _licensor_ is the entity offering these terms, and the _software_ is the software the licensor makes available under these terms, including any portion of it.
37
+
38
+ _you_ refers to the individual or entity agreeing to these terms.
39
+
40
+ _your company_ is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. _control_ means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
41
+
42
+ _your licenses_ are all the licenses granted to you for the software under these terms.
43
+
44
+ _use_ means anything you do with the software requiring one of your licenses.
45
+
46
+ _trademark_ means trademarks, service marks, and similar rights.
package/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # @mastra/opensearch
2
+
3
+ Vector store implementation for OpenSearch using the official @opensearch-project/opensearch SDK
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @mastra/opensearch
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { OpenSearchVector } from '@mastra/opensearch';
15
+
16
+ const vectorStore = new OpenSearchVector('http://localhost:9200');
17
+
18
+ // Create an index
19
+ await vectorStore.createIndex({ indexName: 'my-collection', dimension: 1536, metric: 'cosine' });
20
+
21
+ // Add vectors with documents
22
+ const vectors = [[0.1, 0.2, ...], [0.3, 0.4, ...]];
23
+ const metadata = [{ text: 'doc1' }, { text: 'doc2' }];
24
+ const ids = await vectorStore.upsert({ indexName: 'my-collection', vectors, metadata });
25
+
26
+ // Query vectors with document filtering
27
+ const results = await vectorStore.query({
28
+ indexName: 'my-collection',
29
+ queryVector: [0.1, 0.2, ...],
30
+ topK: 10, // topK
31
+ filter: { text: { $eq: 'doc1' } }, // metadata filter
32
+ includeVector: false, // includeVector
33
+ });
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ Required:
39
+
40
+ - `url`: URL of your OpenSearch instance
41
+
42
+ ## Features
43
+
44
+ - Vector similarity search with Cosine, Euclidean, and Dot Product metrics
45
+ - Metadata filtering
46
+ - Optional vector inclusion in query results
47
+ - Automatic UUID generation for vectors
48
+ - Built on top of @opensearch-project/opensearch SDK
49
+
50
+ ## Distance Metrics
51
+
52
+ The following distance metrics are supported:
53
+
54
+ - `cosine` → Cosine distance
55
+ - `euclidean` → Euclidean distance
56
+ - `dotproduct` → Dot product
57
+
58
+ ## Methods
59
+
60
+ - `createIndex({ indexName, dimension, metric? })`: Create a new collection
61
+ - `upsert({ indexName, vectors, metadata?, ids? })`: Add or update vectors
62
+ - `query({ indexName, queryVector, topK?, filter?, includeVector? })`: Search for similar vectors
63
+ - `listIndexes()`: List all collections
64
+ - `describeIndex(indexName)`: Get collection statistics
65
+ - `deleteIndex(indexName)`: Delete a collection
66
+
67
+ ## Related Links
68
+
69
+ - [OpenSearch Documentation](https://opensearch.org/docs/latest/about/)
70
+ - [OpenSearch REST API Reference](https://opensearch.org/docs/latest/api-reference/)
@@ -0,0 +1,165 @@
1
+ import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
+ import type { CreateIndexParams } from '@mastra/core';
3
+ import type { IndexStats } from '@mastra/core';
4
+ import { MastraVector } from '@mastra/core/vector';
5
+ import type { OperatorSupport } from '@mastra/core/vector/filter';
6
+ import type { QueryResult } from '@mastra/core';
7
+ import type { QueryVectorParams } from '@mastra/core';
8
+ import type { UpsertVectorParams } from '@mastra/core';
9
+ import type { VectorFilter } from '@mastra/core/vector/filter';
10
+
11
+ /**
12
+ * Translator for OpenSearch filter queries.
13
+ * Maintains OpenSearch-compatible syntax while ensuring proper validation
14
+ * and normalization of values.
15
+ */
16
+ export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
17
+ protected getSupportedOperators(): OperatorSupport;
18
+ translate(filter?: VectorFilter): VectorFilter;
19
+ private translateNode;
20
+ /**
21
+ * Handles translation of nested objects with dot notation fields
22
+ */
23
+ private translateNestedObject;
24
+ private translateLogicalOperator;
25
+ private translateFieldOperator;
26
+ /**
27
+ * Translates regex patterns to OpenSearch query syntax
28
+ */
29
+ private translateRegexOperator;
30
+ private addKeywordIfNeeded;
31
+ /**
32
+ * Helper method to handle special cases for the $not operator
33
+ */
34
+ private handleNotOperatorSpecialCases;
35
+ private translateOperator;
36
+ /**
37
+ * Translates field conditions to OpenSearch query syntax
38
+ * Handles special cases like range queries and multiple operators
39
+ */
40
+ private translateFieldConditions;
41
+ /**
42
+ * Checks if conditions can be optimized to a range query
43
+ */
44
+ private canOptimizeToRangeQuery;
45
+ /**
46
+ * Creates a range query from numeric operators
47
+ */
48
+ private createRangeQuery;
49
+ }
50
+
51
+ declare class OpenSearchVector extends MastraVector {
52
+ private client;
53
+ constructor(url: string);
54
+ /**
55
+ * Creates a new collection with the specified configuration.
56
+ *
57
+ * @param {string} indexName - The name of the collection to create.
58
+ * @param {number} dimension - The dimension of the vectors to be stored in the collection.
59
+ * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
60
+ * @returns {Promise<void>} A promise that resolves when the collection is created.
61
+ */
62
+ createIndex(params: CreateIndexParams): Promise<void>;
63
+ /**
64
+ * Lists all indexes.
65
+ *
66
+ * @returns {Promise<string[]>} A promise that resolves to an array of indexes.
67
+ */
68
+ listIndexes(): Promise<string[]>;
69
+ describeIndex(indexName: string): Promise<IndexStats>;
70
+ /**
71
+ * Deletes the specified index.
72
+ *
73
+ * @param {string} indexName - The name of the index to delete.
74
+ * @returns {Promise<void>} A promise that resolves when the index is deleted.
75
+ */
76
+ deleteIndex(indexName: string): Promise<void>;
77
+ /**
78
+ * Inserts or updates vectors in the specified collection.
79
+ *
80
+ * @param {string} indexName - The name of the collection to upsert into.
81
+ * @param {number[][]} vectors - An array of vectors to upsert.
82
+ * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
83
+ * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
84
+ * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
85
+ */
86
+ upsert(params: UpsertVectorParams): Promise<string[]>;
87
+ /**
88
+ * Queries the specified collection using a vector and optional filter.
89
+ *
90
+ * @param {string} indexName - The name of the collection to query.
91
+ * @param {number[]} queryVector - The vector to query with.
92
+ * @param {number} [topK] - The maximum number of results to return.
93
+ * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in OpenSearch, see the filtering reference: https://opensearch.org/docs/latest/query-dsl/
94
+ * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
95
+ * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
96
+ */
97
+ query(params: QueryVectorParams): Promise<QueryResult[]>;
98
+ /**
99
+ * Validates the dimensions of the vectors.
100
+ *
101
+ * @param {number[][]} vectors - The vectors to validate.
102
+ * @param {number} dimension - The dimension of the vectors.
103
+ * @returns {void}
104
+ */
105
+ private validateVectorDimensions;
106
+ /**
107
+ * Transforms the filter to the OpenSearch DSL.
108
+ *
109
+ * @param {VectorFilter} filter - The filter to transform.
110
+ * @returns {Record<string, any>} The transformed filter.
111
+ */
112
+ private transformFilter;
113
+ /**
114
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
115
+ *
116
+ * Updates a vector by its ID with the provided vector and/or metadata.
117
+ * @param indexName - The name of the index containing the vector.
118
+ * @param id - The ID of the vector to update.
119
+ * @param update - An object containing the vector and/or metadata to update.
120
+ * @param update.vector - An optional array of numbers representing the new vector.
121
+ * @param update.metadata - An optional record containing the new metadata.
122
+ * @returns A promise that resolves when the update is complete.
123
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
124
+ */
125
+ updateIndexById(indexName: string, id: string, update: {
126
+ vector?: number[];
127
+ metadata?: Record<string, any>;
128
+ }): Promise<void>;
129
+ /**
130
+ * Updates a vector by its ID with the provided vector and/or metadata.
131
+ * @param indexName - The name of the index containing the vector.
132
+ * @param id - The ID of the vector to update.
133
+ * @param update - An object containing the vector and/or metadata to update.
134
+ * @param update.vector - An optional array of numbers representing the new vector.
135
+ * @param update.metadata - An optional record containing the new metadata.
136
+ * @returns A promise that resolves when the update is complete.
137
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
138
+ */
139
+ updateVector(indexName: string, id: string, update: {
140
+ vector?: number[];
141
+ metadata?: Record<string, any>;
142
+ }): Promise<void>;
143
+ /**
144
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
145
+ *
146
+ * Deletes a vector by its ID.
147
+ * @param indexName - The name of the index containing the vector.
148
+ * @param id - The ID of the vector to delete.
149
+ * @returns A promise that resolves when the deletion is complete.
150
+ * @throws Will throw an error if the deletion operation fails.
151
+ */
152
+ deleteIndexById(indexName: string, id: string): Promise<void>;
153
+ /**
154
+ * Deletes a vector by its ID.
155
+ * @param indexName - The name of the index containing the vector.
156
+ * @param id - The ID of the vector to delete.
157
+ * @returns A promise that resolves when the deletion is complete.
158
+ * @throws Will throw an error if the deletion operation fails.
159
+ */
160
+ deleteVector(indexName: string, id: string): Promise<void>;
161
+ }
162
+ export { OpenSearchVector }
163
+ export { OpenSearchVector as OpenSearchVector_alias_1 }
164
+
165
+ export { }
@@ -0,0 +1,165 @@
1
+ import { BaseFilterTranslator } from '@mastra/core/vector/filter';
2
+ import type { CreateIndexParams } from '@mastra/core';
3
+ import type { IndexStats } from '@mastra/core';
4
+ import { MastraVector } from '@mastra/core/vector';
5
+ import type { OperatorSupport } from '@mastra/core/vector/filter';
6
+ import type { QueryResult } from '@mastra/core';
7
+ import type { QueryVectorParams } from '@mastra/core';
8
+ import type { UpsertVectorParams } from '@mastra/core';
9
+ import type { VectorFilter } from '@mastra/core/vector/filter';
10
+
11
+ /**
12
+ * Translator for OpenSearch filter queries.
13
+ * Maintains OpenSearch-compatible syntax while ensuring proper validation
14
+ * and normalization of values.
15
+ */
16
+ export declare class OpenSearchFilterTranslator extends BaseFilterTranslator {
17
+ protected getSupportedOperators(): OperatorSupport;
18
+ translate(filter?: VectorFilter): VectorFilter;
19
+ private translateNode;
20
+ /**
21
+ * Handles translation of nested objects with dot notation fields
22
+ */
23
+ private translateNestedObject;
24
+ private translateLogicalOperator;
25
+ private translateFieldOperator;
26
+ /**
27
+ * Translates regex patterns to OpenSearch query syntax
28
+ */
29
+ private translateRegexOperator;
30
+ private addKeywordIfNeeded;
31
+ /**
32
+ * Helper method to handle special cases for the $not operator
33
+ */
34
+ private handleNotOperatorSpecialCases;
35
+ private translateOperator;
36
+ /**
37
+ * Translates field conditions to OpenSearch query syntax
38
+ * Handles special cases like range queries and multiple operators
39
+ */
40
+ private translateFieldConditions;
41
+ /**
42
+ * Checks if conditions can be optimized to a range query
43
+ */
44
+ private canOptimizeToRangeQuery;
45
+ /**
46
+ * Creates a range query from numeric operators
47
+ */
48
+ private createRangeQuery;
49
+ }
50
+
51
+ declare class OpenSearchVector extends MastraVector {
52
+ private client;
53
+ constructor(url: string);
54
+ /**
55
+ * Creates a new collection with the specified configuration.
56
+ *
57
+ * @param {string} indexName - The name of the collection to create.
58
+ * @param {number} dimension - The dimension of the vectors to be stored in the collection.
59
+ * @param {'cosine' | 'euclidean' | 'dotproduct'} [metric=cosine] - The metric to use to sort vectors in the collection.
60
+ * @returns {Promise<void>} A promise that resolves when the collection is created.
61
+ */
62
+ createIndex(params: CreateIndexParams): Promise<void>;
63
+ /**
64
+ * Lists all indexes.
65
+ *
66
+ * @returns {Promise<string[]>} A promise that resolves to an array of indexes.
67
+ */
68
+ listIndexes(): Promise<string[]>;
69
+ describeIndex(indexName: string): Promise<IndexStats>;
70
+ /**
71
+ * Deletes the specified index.
72
+ *
73
+ * @param {string} indexName - The name of the index to delete.
74
+ * @returns {Promise<void>} A promise that resolves when the index is deleted.
75
+ */
76
+ deleteIndex(indexName: string): Promise<void>;
77
+ /**
78
+ * Inserts or updates vectors in the specified collection.
79
+ *
80
+ * @param {string} indexName - The name of the collection to upsert into.
81
+ * @param {number[][]} vectors - An array of vectors to upsert.
82
+ * @param {Record<string, any>[]} [metadata] - An optional array of metadata objects corresponding to each vector.
83
+ * @param {string[]} [ids] - An optional array of IDs corresponding to each vector. If not provided, new IDs will be generated.
84
+ * @returns {Promise<string[]>} A promise that resolves to an array of IDs of the upserted vectors.
85
+ */
86
+ upsert(params: UpsertVectorParams): Promise<string[]>;
87
+ /**
88
+ * Queries the specified collection using a vector and optional filter.
89
+ *
90
+ * @param {string} indexName - The name of the collection to query.
91
+ * @param {number[]} queryVector - The vector to query with.
92
+ * @param {number} [topK] - The maximum number of results to return.
93
+ * @param {Record<string, any>} [filter] - An optional filter to apply to the query. For more on filters in OpenSearch, see the filtering reference: https://opensearch.org/docs/latest/query-dsl/
94
+ * @param {boolean} [includeVectors=false] - Whether to include the vectors in the response.
95
+ * @returns {Promise<QueryResult[]>} A promise that resolves to an array of query results.
96
+ */
97
+ query(params: QueryVectorParams): Promise<QueryResult[]>;
98
+ /**
99
+ * Validates the dimensions of the vectors.
100
+ *
101
+ * @param {number[][]} vectors - The vectors to validate.
102
+ * @param {number} dimension - The dimension of the vectors.
103
+ * @returns {void}
104
+ */
105
+ private validateVectorDimensions;
106
+ /**
107
+ * Transforms the filter to the OpenSearch DSL.
108
+ *
109
+ * @param {VectorFilter} filter - The filter to transform.
110
+ * @returns {Record<string, any>} The transformed filter.
111
+ */
112
+ private transformFilter;
113
+ /**
114
+ * @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
115
+ *
116
+ * Updates a vector by its ID with the provided vector and/or metadata.
117
+ * @param indexName - The name of the index containing the vector.
118
+ * @param id - The ID of the vector to update.
119
+ * @param update - An object containing the vector and/or metadata to update.
120
+ * @param update.vector - An optional array of numbers representing the new vector.
121
+ * @param update.metadata - An optional record containing the new metadata.
122
+ * @returns A promise that resolves when the update is complete.
123
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
124
+ */
125
+ updateIndexById(indexName: string, id: string, update: {
126
+ vector?: number[];
127
+ metadata?: Record<string, any>;
128
+ }): Promise<void>;
129
+ /**
130
+ * Updates a vector by its ID with the provided vector and/or metadata.
131
+ * @param indexName - The name of the index containing the vector.
132
+ * @param id - The ID of the vector to update.
133
+ * @param update - An object containing the vector and/or metadata to update.
134
+ * @param update.vector - An optional array of numbers representing the new vector.
135
+ * @param update.metadata - An optional record containing the new metadata.
136
+ * @returns A promise that resolves when the update is complete.
137
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
138
+ */
139
+ updateVector(indexName: string, id: string, update: {
140
+ vector?: number[];
141
+ metadata?: Record<string, any>;
142
+ }): Promise<void>;
143
+ /**
144
+ * @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
145
+ *
146
+ * Deletes a vector by its ID.
147
+ * @param indexName - The name of the index containing the vector.
148
+ * @param id - The ID of the vector to delete.
149
+ * @returns A promise that resolves when the deletion is complete.
150
+ * @throws Will throw an error if the deletion operation fails.
151
+ */
152
+ deleteIndexById(indexName: string, id: string): Promise<void>;
153
+ /**
154
+ * Deletes a vector by its ID.
155
+ * @param indexName - The name of the index containing the vector.
156
+ * @param id - The ID of the vector to delete.
157
+ * @returns A promise that resolves when the deletion is complete.
158
+ * @throws Will throw an error if the deletion operation fails.
159
+ */
160
+ deleteVector(indexName: string, id: string): Promise<void>;
161
+ }
162
+ export { OpenSearchVector }
163
+ export { OpenSearchVector as OpenSearchVector_alias_1 }
164
+
165
+ export { }