@mastra/opensearch 0.0.0-pass-headers-for-create-mastra-client-20250529200245 → 0.0.0-scorers-api-v2-20250801171841
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 +213 -2
- package/LICENSE.md +11 -42
- package/dist/index.cjs +130 -53
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +122 -45
- package/dist/index.js.map +1 -0
- package/dist/vector/filter.d.ts +47 -0
- package/dist/vector/filter.d.ts.map +1 -0
- package/dist/vector/index.d.ts +101 -0
- package/dist/vector/index.d.ts.map +1 -0
- package/dist/vector/prompt.d.ts +6 -0
- package/dist/vector/prompt.d.ts.map +1 -0
- package/package.json +13 -13
- package/src/vector/filter.test.ts +55 -54
- package/src/vector/filter.ts +23 -5
- package/src/vector/index.test.ts +4 -5
- package/src/vector/index.ts +134 -55
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/.turbo/turbo-build.log +0 -23
- package/dist/_tsup-dts-rollup.d.cts +0 -159
- package/dist/_tsup-dts-rollup.d.ts +0 -159
- package/dist/index.d.cts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,226 @@
|
|
|
1
1
|
# @mastra/opensearch
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-scorers-api-v2-20250801171841
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
+
- Updated dependencies [c6f12c7]
|
|
8
|
+
- @mastra/core@0.0.0-scorers-api-v2-20250801171841
|
|
9
|
+
|
|
10
|
+
## 0.11.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- f42c4c2: update peer deps for packages to latest core range
|
|
15
|
+
- Updated dependencies [510e2c8]
|
|
16
|
+
- Updated dependencies [2f72fb2]
|
|
17
|
+
- Updated dependencies [27cc97a]
|
|
18
|
+
- Updated dependencies [3f89307]
|
|
19
|
+
- Updated dependencies [9eda7d4]
|
|
20
|
+
- Updated dependencies [9d49408]
|
|
21
|
+
- Updated dependencies [41daa63]
|
|
22
|
+
- Updated dependencies [ad0a58b]
|
|
23
|
+
- Updated dependencies [254a36b]
|
|
24
|
+
- Updated dependencies [2ecf658]
|
|
25
|
+
- Updated dependencies [7a7754f]
|
|
26
|
+
- Updated dependencies [fc92d80]
|
|
27
|
+
- Updated dependencies [e0f73c6]
|
|
28
|
+
- Updated dependencies [0b89602]
|
|
29
|
+
- Updated dependencies [4d37822]
|
|
30
|
+
- Updated dependencies [23a6a7c]
|
|
31
|
+
- Updated dependencies [cda801d]
|
|
32
|
+
- Updated dependencies [a77c823]
|
|
33
|
+
- Updated dependencies [ff9c125]
|
|
34
|
+
- Updated dependencies [09bca64]
|
|
35
|
+
- Updated dependencies [b8efbb9]
|
|
36
|
+
- Updated dependencies [71466e7]
|
|
37
|
+
- Updated dependencies [0c99fbe]
|
|
38
|
+
- @mastra/core@0.12.0
|
|
39
|
+
|
|
40
|
+
## 0.11.2-alpha.0
|
|
41
|
+
|
|
42
|
+
### Patch Changes
|
|
43
|
+
|
|
44
|
+
- f42c4c2: update peer deps for packages to latest core range
|
|
45
|
+
- @mastra/core@0.12.0-alpha.5
|
|
46
|
+
|
|
47
|
+
## 0.11.1
|
|
48
|
+
|
|
49
|
+
### Patch Changes
|
|
50
|
+
|
|
51
|
+
- ce088f5: Update all peerdeps to latest core
|
|
52
|
+
- @mastra/core@0.11.1
|
|
53
|
+
|
|
54
|
+
## 0.11.0
|
|
55
|
+
|
|
56
|
+
### Minor Changes
|
|
57
|
+
|
|
58
|
+
- 8a3bfd2: Update peerdeps to latest core
|
|
59
|
+
|
|
60
|
+
### Patch Changes
|
|
61
|
+
|
|
62
|
+
- 144eb0b: [MASTRA-3669] Metadata Filter Types
|
|
63
|
+
- 0e17048: Throw mastra errors in storage packages
|
|
64
|
+
- Updated dependencies [15e9d26]
|
|
65
|
+
- Updated dependencies [d1baedb]
|
|
66
|
+
- Updated dependencies [d8f2d19]
|
|
67
|
+
- Updated dependencies [4d21bf2]
|
|
68
|
+
- Updated dependencies [07d6d88]
|
|
69
|
+
- Updated dependencies [9d52b17]
|
|
70
|
+
- Updated dependencies [2097952]
|
|
71
|
+
- Updated dependencies [792c4c0]
|
|
72
|
+
- Updated dependencies [5d74aab]
|
|
73
|
+
- Updated dependencies [a8b194f]
|
|
74
|
+
- Updated dependencies [4fb0cc2]
|
|
75
|
+
- Updated dependencies [d2a7a31]
|
|
76
|
+
- Updated dependencies [502fe05]
|
|
77
|
+
- Updated dependencies [144eb0b]
|
|
78
|
+
- Updated dependencies [8ba1b51]
|
|
79
|
+
- Updated dependencies [4efcfa0]
|
|
80
|
+
- Updated dependencies [0e17048]
|
|
81
|
+
- @mastra/core@0.10.7
|
|
82
|
+
|
|
83
|
+
## 0.11.0-alpha.2
|
|
84
|
+
|
|
85
|
+
### Minor Changes
|
|
86
|
+
|
|
87
|
+
- 8a3bfd2: Update peerdeps to latest core
|
|
88
|
+
|
|
89
|
+
### Patch Changes
|
|
90
|
+
|
|
91
|
+
- Updated dependencies [792c4c0]
|
|
92
|
+
- Updated dependencies [502fe05]
|
|
93
|
+
- Updated dependencies [4efcfa0]
|
|
94
|
+
- @mastra/core@0.10.7-alpha.3
|
|
95
|
+
|
|
96
|
+
## 0.10.4-alpha.1
|
|
97
|
+
|
|
98
|
+
### Patch Changes
|
|
99
|
+
|
|
100
|
+
- 144eb0b: [MASTRA-3669] Metadata Filter Types
|
|
101
|
+
- Updated dependencies [15e9d26]
|
|
102
|
+
- Updated dependencies [07d6d88]
|
|
103
|
+
- Updated dependencies [5d74aab]
|
|
104
|
+
- Updated dependencies [144eb0b]
|
|
105
|
+
- @mastra/core@0.10.7-alpha.2
|
|
106
|
+
|
|
107
|
+
## 0.10.4-alpha.0
|
|
108
|
+
|
|
109
|
+
### Patch Changes
|
|
110
|
+
|
|
111
|
+
- 0e17048: Throw mastra errors in storage packages
|
|
112
|
+
- Updated dependencies [d1baedb]
|
|
113
|
+
- Updated dependencies [4d21bf2]
|
|
114
|
+
- Updated dependencies [2097952]
|
|
115
|
+
- Updated dependencies [4fb0cc2]
|
|
116
|
+
- Updated dependencies [d2a7a31]
|
|
117
|
+
- Updated dependencies [0e17048]
|
|
118
|
+
- @mastra/core@0.10.7-alpha.1
|
|
119
|
+
|
|
120
|
+
## 0.10.3
|
|
121
|
+
|
|
122
|
+
### Patch Changes
|
|
123
|
+
|
|
124
|
+
- 63f6b7d: dependencies updates:
|
|
125
|
+
- Updated dependency [`@opensearch-project/opensearch@^3.5.1` ↗︎](https://www.npmjs.com/package/@opensearch-project/opensearch/v/3.5.1) (from `^3.4.0`, in `dependencies`)
|
|
126
|
+
- Updated dependencies [63f6b7d]
|
|
127
|
+
- Updated dependencies [12a95fc]
|
|
128
|
+
- Updated dependencies [4b0f8a6]
|
|
129
|
+
- Updated dependencies [51264a5]
|
|
130
|
+
- Updated dependencies [8e6f677]
|
|
131
|
+
- Updated dependencies [d70c420]
|
|
132
|
+
- Updated dependencies [ee9af57]
|
|
133
|
+
- Updated dependencies [36f1c36]
|
|
134
|
+
- Updated dependencies [2a16996]
|
|
135
|
+
- Updated dependencies [10d352e]
|
|
136
|
+
- Updated dependencies [9589624]
|
|
137
|
+
- Updated dependencies [53d3c37]
|
|
138
|
+
- Updated dependencies [751c894]
|
|
139
|
+
- Updated dependencies [577ce3a]
|
|
140
|
+
- Updated dependencies [9260b3a]
|
|
141
|
+
- @mastra/core@0.10.6
|
|
142
|
+
|
|
143
|
+
## 0.10.3-alpha.0
|
|
144
|
+
|
|
145
|
+
### Patch Changes
|
|
146
|
+
|
|
147
|
+
- 63f6b7d: dependencies updates:
|
|
148
|
+
- Updated dependency [`@opensearch-project/opensearch@^3.5.1` ↗︎](https://www.npmjs.com/package/@opensearch-project/opensearch/v/3.5.1) (from `^3.4.0`, in `dependencies`)
|
|
149
|
+
- Updated dependencies [63f6b7d]
|
|
150
|
+
- Updated dependencies [36f1c36]
|
|
151
|
+
- Updated dependencies [10d352e]
|
|
152
|
+
- Updated dependencies [53d3c37]
|
|
153
|
+
- @mastra/core@0.10.6-alpha.0
|
|
154
|
+
|
|
155
|
+
## 0.10.2
|
|
156
|
+
|
|
157
|
+
### Patch Changes
|
|
158
|
+
|
|
159
|
+
- 66f4424: Update peerdeps
|
|
160
|
+
- Updated dependencies [d1ed912]
|
|
161
|
+
- Updated dependencies [f6fd25f]
|
|
162
|
+
- Updated dependencies [dffb67b]
|
|
163
|
+
- Updated dependencies [f1f1f1b]
|
|
164
|
+
- Updated dependencies [925ab94]
|
|
165
|
+
- Updated dependencies [f9816ae]
|
|
166
|
+
- Updated dependencies [82090c1]
|
|
167
|
+
- Updated dependencies [1b443fd]
|
|
168
|
+
- Updated dependencies [ce97900]
|
|
169
|
+
- Updated dependencies [f1309d3]
|
|
170
|
+
- Updated dependencies [14a2566]
|
|
171
|
+
- Updated dependencies [f7f8293]
|
|
172
|
+
- Updated dependencies [48eddb9]
|
|
173
|
+
- @mastra/core@0.10.4
|
|
174
|
+
|
|
175
|
+
## 0.10.2-alpha.0
|
|
176
|
+
|
|
177
|
+
### Patch Changes
|
|
178
|
+
|
|
179
|
+
- 66f4424: Update peerdeps
|
|
180
|
+
|
|
181
|
+
## 0.10.1
|
|
182
|
+
|
|
183
|
+
### Patch Changes
|
|
184
|
+
|
|
185
|
+
- f0d559f: Fix peerdeps for alpha channel
|
|
7
186
|
- 915ca1a: Added disconnect function for couchbase and added docs
|
|
8
187
|
Added prompt for OpenSearchVector
|
|
9
188
|
- Updated dependencies [ee77e78]
|
|
10
189
|
- Updated dependencies [592a2db]
|
|
11
190
|
- Updated dependencies [e5dc18d]
|
|
12
|
-
|
|
191
|
+
- Updated dependencies [ab5adbe]
|
|
192
|
+
- Updated dependencies [1e8bb40]
|
|
193
|
+
- Updated dependencies [1b5fc55]
|
|
194
|
+
- Updated dependencies [195c428]
|
|
195
|
+
- Updated dependencies [f73e11b]
|
|
196
|
+
- Updated dependencies [37643b8]
|
|
197
|
+
- Updated dependencies [99fd6cf]
|
|
198
|
+
- Updated dependencies [c5bf1ce]
|
|
199
|
+
- Updated dependencies [add596e]
|
|
200
|
+
- Updated dependencies [8dc94d8]
|
|
201
|
+
- Updated dependencies [ecebbeb]
|
|
202
|
+
- Updated dependencies [79d5145]
|
|
203
|
+
- Updated dependencies [12b7002]
|
|
204
|
+
- Updated dependencies [2901125]
|
|
205
|
+
- @mastra/core@0.10.2
|
|
206
|
+
|
|
207
|
+
## 0.10.1-alpha.1
|
|
208
|
+
|
|
209
|
+
### Patch Changes
|
|
210
|
+
|
|
211
|
+
- f0d559f: Fix peerdeps for alpha channel
|
|
212
|
+
- Updated dependencies [1e8bb40]
|
|
213
|
+
- @mastra/core@0.10.2-alpha.2
|
|
214
|
+
|
|
215
|
+
## 0.10.1-alpha.0
|
|
216
|
+
|
|
217
|
+
### Patch Changes
|
|
218
|
+
|
|
219
|
+
- 915ca1a: Added disconnect function for couchbase and added docs
|
|
220
|
+
Added prompt for OpenSearchVector
|
|
221
|
+
- Updated dependencies [ee77e78]
|
|
222
|
+
- Updated dependencies [2901125]
|
|
223
|
+
- @mastra/core@0.10.2-alpha.1
|
|
13
224
|
|
|
14
225
|
## 0.10.0
|
|
15
226
|
|
package/LICENSE.md
CHANGED
|
@@ -1,46 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Apache License 2.0
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2025
|
|
3
|
+
Copyright (c) 2025 Kepler Software, Inc.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
7
8
|
|
|
8
|
-
|
|
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
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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.
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var error = require('@mastra/core/error');
|
|
3
4
|
var vector = require('@mastra/core/vector');
|
|
4
5
|
var opensearch = require('@opensearch-project/opensearch');
|
|
5
6
|
var filter = require('@mastra/core/vector/filter');
|
|
@@ -11,7 +12,6 @@ var OpenSearchFilterTranslator = class extends filter.BaseFilterTranslator {
|
|
|
11
12
|
...filter.BaseFilterTranslator.DEFAULT_OPERATORS,
|
|
12
13
|
logical: ["$and", "$or", "$not"],
|
|
13
14
|
array: ["$in", "$nin", "$all"],
|
|
14
|
-
element: ["$exists"],
|
|
15
15
|
regex: ["$regex"],
|
|
16
16
|
custom: []
|
|
17
17
|
};
|
|
@@ -383,7 +383,13 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
383
383
|
*/
|
|
384
384
|
async createIndex({ indexName, dimension, metric = "cosine" }) {
|
|
385
385
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
386
|
-
throw new
|
|
386
|
+
throw new error.MastraError({
|
|
387
|
+
id: "STORAGE_OPENSEARCH_VECTOR_CREATE_INDEX_INVALID_ARGS",
|
|
388
|
+
domain: error.ErrorDomain.STORAGE,
|
|
389
|
+
category: error.ErrorCategory.USER,
|
|
390
|
+
text: "Dimension must be a positive integer",
|
|
391
|
+
details: { indexName, dimension }
|
|
392
|
+
});
|
|
387
393
|
}
|
|
388
394
|
try {
|
|
389
395
|
await this.client.indices.create({
|
|
@@ -408,14 +414,21 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
408
414
|
}
|
|
409
415
|
}
|
|
410
416
|
});
|
|
411
|
-
} catch (error) {
|
|
412
|
-
const message = error?.message || error?.toString();
|
|
417
|
+
} catch (error$1) {
|
|
418
|
+
const message = error$1?.message || error$1?.toString();
|
|
413
419
|
if (message && message.toLowerCase().includes("already exists")) {
|
|
414
420
|
await this.validateExistingIndex(indexName, dimension, metric);
|
|
415
421
|
return;
|
|
416
422
|
}
|
|
417
|
-
|
|
418
|
-
|
|
423
|
+
throw new error.MastraError(
|
|
424
|
+
{
|
|
425
|
+
id: "STORAGE_OPENSEARCH_VECTOR_CREATE_INDEX_FAILED",
|
|
426
|
+
domain: error.ErrorDomain.STORAGE,
|
|
427
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
428
|
+
details: { indexName, dimension, metric }
|
|
429
|
+
},
|
|
430
|
+
error$1
|
|
431
|
+
);
|
|
419
432
|
}
|
|
420
433
|
}
|
|
421
434
|
/**
|
|
@@ -428,9 +441,15 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
428
441
|
const response = await this.client.cat.indices({ format: "json" });
|
|
429
442
|
const indexes = response.body.map((record) => record.index).filter((index) => index !== void 0);
|
|
430
443
|
return indexes;
|
|
431
|
-
} catch (error) {
|
|
432
|
-
|
|
433
|
-
|
|
444
|
+
} catch (error$1) {
|
|
445
|
+
throw new error.MastraError(
|
|
446
|
+
{
|
|
447
|
+
id: "STORAGE_OPENSEARCH_VECTOR_LIST_INDEXES_FAILED",
|
|
448
|
+
domain: error.ErrorDomain.STORAGE,
|
|
449
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
450
|
+
},
|
|
451
|
+
error$1
|
|
452
|
+
);
|
|
434
453
|
}
|
|
435
454
|
}
|
|
436
455
|
/**
|
|
@@ -460,8 +479,18 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
460
479
|
async deleteIndex({ indexName }) {
|
|
461
480
|
try {
|
|
462
481
|
await this.client.indices.delete({ index: indexName });
|
|
463
|
-
} catch (error) {
|
|
464
|
-
|
|
482
|
+
} catch (error$1) {
|
|
483
|
+
const mastraError = new error.MastraError(
|
|
484
|
+
{
|
|
485
|
+
id: "STORAGE_OPENSEARCH_VECTOR_DELETE_INDEX_FAILED",
|
|
486
|
+
domain: error.ErrorDomain.STORAGE,
|
|
487
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
488
|
+
details: { indexName }
|
|
489
|
+
},
|
|
490
|
+
error$1
|
|
491
|
+
);
|
|
492
|
+
this.logger?.error(mastraError.toString());
|
|
493
|
+
this.logger?.trackException(mastraError);
|
|
465
494
|
}
|
|
466
495
|
}
|
|
467
496
|
/**
|
|
@@ -476,31 +505,38 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
476
505
|
async upsert({ indexName, vectors, metadata = [], ids }) {
|
|
477
506
|
const vectorIds = ids || vectors.map(() => crypto.randomUUID());
|
|
478
507
|
const operations = [];
|
|
479
|
-
const indexInfo = await this.describeIndex({ indexName });
|
|
480
|
-
this.validateVectorDimensions(vectors, indexInfo.dimension);
|
|
481
|
-
for (let i = 0; i < vectors.length; i++) {
|
|
482
|
-
const operation = {
|
|
483
|
-
index: {
|
|
484
|
-
_index: indexName,
|
|
485
|
-
_id: vectorIds[i]
|
|
486
|
-
}
|
|
487
|
-
};
|
|
488
|
-
const document = {
|
|
489
|
-
id: vectorIds[i],
|
|
490
|
-
embedding: vectors[i],
|
|
491
|
-
metadata: metadata[i] || {}
|
|
492
|
-
};
|
|
493
|
-
operations.push(operation);
|
|
494
|
-
operations.push(document);
|
|
495
|
-
}
|
|
496
508
|
try {
|
|
509
|
+
const indexInfo = await this.describeIndex({ indexName });
|
|
510
|
+
this.validateVectorDimensions(vectors, indexInfo.dimension);
|
|
511
|
+
for (let i = 0; i < vectors.length; i++) {
|
|
512
|
+
const operation = {
|
|
513
|
+
index: {
|
|
514
|
+
_index: indexName,
|
|
515
|
+
_id: vectorIds[i]
|
|
516
|
+
}
|
|
517
|
+
};
|
|
518
|
+
const document = {
|
|
519
|
+
id: vectorIds[i],
|
|
520
|
+
embedding: vectors[i],
|
|
521
|
+
metadata: metadata[i] || {}
|
|
522
|
+
};
|
|
523
|
+
operations.push(operation);
|
|
524
|
+
operations.push(document);
|
|
525
|
+
}
|
|
497
526
|
if (operations.length > 0) {
|
|
498
527
|
await this.client.bulk({ body: operations, refresh: true });
|
|
499
528
|
}
|
|
500
529
|
return vectorIds;
|
|
501
|
-
} catch (error) {
|
|
502
|
-
|
|
503
|
-
|
|
530
|
+
} catch (error$1) {
|
|
531
|
+
throw new error.MastraError(
|
|
532
|
+
{
|
|
533
|
+
id: "STORAGE_OPENSEARCH_VECTOR_UPSERT_FAILED",
|
|
534
|
+
domain: error.ErrorDomain.STORAGE,
|
|
535
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
536
|
+
details: { indexName, vectorCount: vectors?.length || 0 }
|
|
537
|
+
},
|
|
538
|
+
error$1
|
|
539
|
+
);
|
|
504
540
|
}
|
|
505
541
|
}
|
|
506
542
|
/**
|
|
@@ -544,9 +580,16 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
544
580
|
};
|
|
545
581
|
});
|
|
546
582
|
return results;
|
|
547
|
-
} catch (error) {
|
|
548
|
-
|
|
549
|
-
|
|
583
|
+
} catch (error$1) {
|
|
584
|
+
throw new error.MastraError(
|
|
585
|
+
{
|
|
586
|
+
id: "STORAGE_OPENSEARCH_VECTOR_QUERY_FAILED",
|
|
587
|
+
domain: error.ErrorDomain.STORAGE,
|
|
588
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
589
|
+
details: { indexName, topK }
|
|
590
|
+
},
|
|
591
|
+
error$1
|
|
592
|
+
);
|
|
550
593
|
}
|
|
551
594
|
}
|
|
552
595
|
/**
|
|
@@ -564,7 +607,7 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
564
607
|
/**
|
|
565
608
|
* Transforms the filter to the OpenSearch DSL.
|
|
566
609
|
*
|
|
567
|
-
* @param {
|
|
610
|
+
* @param {OpenSearchVectorFilter} filter - The filter to transform.
|
|
568
611
|
* @returns {Record<string, any>} The transformed filter.
|
|
569
612
|
*/
|
|
570
613
|
transformFilter(filter) {
|
|
@@ -582,44 +625,68 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
582
625
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
583
626
|
*/
|
|
584
627
|
async updateVector({ indexName, id, update }) {
|
|
585
|
-
|
|
586
|
-
throw new Error("No updates provided");
|
|
587
|
-
}
|
|
628
|
+
let existingDoc;
|
|
588
629
|
try {
|
|
589
|
-
|
|
630
|
+
if (!update.vector && !update.metadata) {
|
|
631
|
+
throw new Error("No updates provided");
|
|
632
|
+
}
|
|
633
|
+
const { body } = await this.client.get({
|
|
590
634
|
index: indexName,
|
|
591
635
|
id
|
|
592
636
|
}).catch(() => {
|
|
593
637
|
throw new Error(`Document with ID ${id} not found in index ${indexName}`);
|
|
594
638
|
});
|
|
595
|
-
if (!
|
|
639
|
+
if (!body || !body._source) {
|
|
596
640
|
throw new Error(`Document with ID ${id} has no source data in index ${indexName}`);
|
|
597
641
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
642
|
+
existingDoc = body;
|
|
643
|
+
} catch (error$1) {
|
|
644
|
+
throw new error.MastraError(
|
|
645
|
+
{
|
|
646
|
+
id: "STORAGE_OPENSEARCH_VECTOR_UPDATE_VECTOR_FAILED",
|
|
647
|
+
domain: error.ErrorDomain.STORAGE,
|
|
648
|
+
category: error.ErrorCategory.USER,
|
|
649
|
+
details: { indexName, id }
|
|
650
|
+
},
|
|
651
|
+
error$1
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
const source = existingDoc._source;
|
|
655
|
+
const updatedDoc = {
|
|
656
|
+
id: source?.id || id
|
|
657
|
+
};
|
|
658
|
+
try {
|
|
602
659
|
if (update.vector) {
|
|
660
|
+
console.log(`1`);
|
|
603
661
|
const indexInfo = await this.describeIndex({ indexName });
|
|
662
|
+
console.log(`2`);
|
|
604
663
|
this.validateVectorDimensions([update.vector], indexInfo.dimension);
|
|
605
664
|
updatedDoc.embedding = update.vector;
|
|
606
|
-
} else if (source
|
|
665
|
+
} else if (source?.embedding) {
|
|
607
666
|
updatedDoc.embedding = source.embedding;
|
|
608
667
|
}
|
|
609
668
|
if (update.metadata) {
|
|
610
669
|
updatedDoc.metadata = update.metadata;
|
|
611
670
|
} else {
|
|
612
|
-
updatedDoc.metadata = source
|
|
671
|
+
updatedDoc.metadata = source?.metadata || {};
|
|
613
672
|
}
|
|
673
|
+
console.log(`3`);
|
|
614
674
|
await this.client.index({
|
|
615
675
|
index: indexName,
|
|
616
676
|
id,
|
|
617
677
|
body: updatedDoc,
|
|
618
678
|
refresh: true
|
|
619
679
|
});
|
|
620
|
-
} catch (error) {
|
|
621
|
-
|
|
622
|
-
|
|
680
|
+
} catch (error$1) {
|
|
681
|
+
throw new error.MastraError(
|
|
682
|
+
{
|
|
683
|
+
id: "STORAGE_OPENSEARCH_VECTOR_UPDATE_VECTOR_FAILED",
|
|
684
|
+
domain: error.ErrorDomain.STORAGE,
|
|
685
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
686
|
+
details: { indexName, id }
|
|
687
|
+
},
|
|
688
|
+
error$1
|
|
689
|
+
);
|
|
623
690
|
}
|
|
624
691
|
}
|
|
625
692
|
/**
|
|
@@ -636,13 +703,23 @@ var OpenSearchVector = class extends vector.MastraVector {
|
|
|
636
703
|
id,
|
|
637
704
|
refresh: true
|
|
638
705
|
});
|
|
639
|
-
} catch (error) {
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
throw error;
|
|
706
|
+
} catch (error$1) {
|
|
707
|
+
if (error$1 && typeof error$1 === "object" && "statusCode" in error$1 && error$1.statusCode === 404) {
|
|
708
|
+
return;
|
|
643
709
|
}
|
|
710
|
+
throw new error.MastraError(
|
|
711
|
+
{
|
|
712
|
+
id: "STORAGE_OPENSEARCH_VECTOR_DELETE_VECTOR_FAILED",
|
|
713
|
+
domain: error.ErrorDomain.STORAGE,
|
|
714
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
715
|
+
details: { indexName, id }
|
|
716
|
+
},
|
|
717
|
+
error$1
|
|
718
|
+
);
|
|
644
719
|
}
|
|
645
720
|
}
|
|
646
721
|
};
|
|
647
722
|
|
|
648
723
|
exports.OpenSearchVector = OpenSearchVector;
|
|
724
|
+
//# sourceMappingURL=index.cjs.map
|
|
725
|
+
//# sourceMappingURL=index.cjs.map
|