@mastra/couchbase 0.0.0-working-memory-per-user-20250620163010 → 0.0.0-zod-v4-compat-part-2-20250822105954
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 +100 -3
- package/LICENSE.md +11 -42
- package/dist/index.cjs +274 -129
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +272 -127
- package/dist/index.js.map +1 -0
- package/dist/{_tsup-dts-rollup.d.cts → vector/index.d.ts} +16 -35
- package/dist/vector/index.d.ts.map +1 -0
- package/package.json +9 -9
- package/src/vector/index.ts +284 -141
- package/src/vector/index.unit.test.ts +1 -1
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/dist/_tsup-dts-rollup.d.ts +0 -80
- package/dist/index.d.cts +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,112 @@
|
|
|
1
1
|
# @mastra/couchbase
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-zod-v4-compat-part-2-20250822105954
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- Updated dependencies [
|
|
7
|
+
- Updated dependencies [94f4812]
|
|
8
|
+
- Updated dependencies [e202b82]
|
|
9
|
+
- Updated dependencies [e00f6a0]
|
|
10
|
+
- Updated dependencies [35c5798]
|
|
11
|
+
- @mastra/core@0.0.0-zod-v4-compat-part-2-20250822105954
|
|
12
|
+
|
|
13
|
+
## 0.11.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- f42c4c2: update peer deps for packages to latest core range
|
|
18
|
+
- Updated dependencies [510e2c8]
|
|
19
|
+
- Updated dependencies [2f72fb2]
|
|
20
|
+
- Updated dependencies [27cc97a]
|
|
21
|
+
- Updated dependencies [3f89307]
|
|
22
|
+
- Updated dependencies [9eda7d4]
|
|
23
|
+
- Updated dependencies [9d49408]
|
|
24
|
+
- Updated dependencies [41daa63]
|
|
25
|
+
- Updated dependencies [ad0a58b]
|
|
26
|
+
- Updated dependencies [254a36b]
|
|
27
|
+
- Updated dependencies [2ecf658]
|
|
28
|
+
- Updated dependencies [7a7754f]
|
|
29
|
+
- Updated dependencies [fc92d80]
|
|
30
|
+
- Updated dependencies [e0f73c6]
|
|
31
|
+
- Updated dependencies [0b89602]
|
|
32
|
+
- Updated dependencies [4d37822]
|
|
33
|
+
- Updated dependencies [23a6a7c]
|
|
34
|
+
- Updated dependencies [cda801d]
|
|
35
|
+
- Updated dependencies [a77c823]
|
|
36
|
+
- Updated dependencies [ff9c125]
|
|
37
|
+
- Updated dependencies [09bca64]
|
|
38
|
+
- Updated dependencies [b8efbb9]
|
|
39
|
+
- Updated dependencies [71466e7]
|
|
40
|
+
- Updated dependencies [0c99fbe]
|
|
41
|
+
- @mastra/core@0.12.0
|
|
42
|
+
|
|
43
|
+
## 0.11.2-alpha.0
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- f42c4c2: update peer deps for packages to latest core range
|
|
48
|
+
- @mastra/core@0.12.0-alpha.5
|
|
49
|
+
|
|
50
|
+
## 0.11.1
|
|
51
|
+
|
|
52
|
+
### Patch Changes
|
|
53
|
+
|
|
54
|
+
- ce088f5: Update all peerdeps to latest core
|
|
55
|
+
- @mastra/core@0.11.1
|
|
56
|
+
|
|
57
|
+
## 0.11.0
|
|
58
|
+
|
|
59
|
+
### Minor Changes
|
|
60
|
+
|
|
61
|
+
- 8a3bfd2: Update peerdeps to latest core
|
|
62
|
+
|
|
63
|
+
### Patch Changes
|
|
64
|
+
|
|
65
|
+
- 0e17048: Throw mastra errors in storage packages
|
|
66
|
+
- Updated dependencies [15e9d26]
|
|
67
|
+
- Updated dependencies [d1baedb]
|
|
8
68
|
- Updated dependencies [d8f2d19]
|
|
69
|
+
- Updated dependencies [4d21bf2]
|
|
70
|
+
- Updated dependencies [07d6d88]
|
|
9
71
|
- Updated dependencies [9d52b17]
|
|
10
72
|
- Updated dependencies [2097952]
|
|
73
|
+
- Updated dependencies [792c4c0]
|
|
74
|
+
- Updated dependencies [5d74aab]
|
|
75
|
+
- Updated dependencies [a8b194f]
|
|
76
|
+
- Updated dependencies [4fb0cc2]
|
|
77
|
+
- Updated dependencies [d2a7a31]
|
|
78
|
+
- Updated dependencies [502fe05]
|
|
79
|
+
- Updated dependencies [144eb0b]
|
|
11
80
|
- Updated dependencies [8ba1b51]
|
|
12
|
-
|
|
81
|
+
- Updated dependencies [4efcfa0]
|
|
82
|
+
- Updated dependencies [0e17048]
|
|
83
|
+
- @mastra/core@0.10.7
|
|
84
|
+
|
|
85
|
+
## 0.11.0-alpha.1
|
|
86
|
+
|
|
87
|
+
### Minor Changes
|
|
88
|
+
|
|
89
|
+
- 8a3bfd2: Update peerdeps to latest core
|
|
90
|
+
|
|
91
|
+
### Patch Changes
|
|
92
|
+
|
|
93
|
+
- Updated dependencies [792c4c0]
|
|
94
|
+
- Updated dependencies [502fe05]
|
|
95
|
+
- Updated dependencies [4efcfa0]
|
|
96
|
+
- @mastra/core@0.10.7-alpha.3
|
|
97
|
+
|
|
98
|
+
## 0.10.4-alpha.0
|
|
99
|
+
|
|
100
|
+
### Patch Changes
|
|
101
|
+
|
|
102
|
+
- 0e17048: Throw mastra errors in storage packages
|
|
103
|
+
- Updated dependencies [d1baedb]
|
|
104
|
+
- Updated dependencies [4d21bf2]
|
|
105
|
+
- Updated dependencies [2097952]
|
|
106
|
+
- Updated dependencies [4fb0cc2]
|
|
107
|
+
- Updated dependencies [d2a7a31]
|
|
108
|
+
- Updated dependencies [0e17048]
|
|
109
|
+
- @mastra/core@0.10.7-alpha.1
|
|
13
110
|
|
|
14
111
|
## 0.10.3
|
|
15
112
|
|
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 couchbase = require('couchbase');
|
|
5
6
|
|
|
@@ -21,26 +22,45 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
21
22
|
vector_dimension;
|
|
22
23
|
constructor({ connectionString, username, password, bucketName, scopeName, collectionName }) {
|
|
23
24
|
super();
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
25
|
+
try {
|
|
26
|
+
const baseClusterPromise = couchbase.connect(connectionString, {
|
|
27
|
+
username,
|
|
28
|
+
password,
|
|
29
|
+
configProfile: "wanDevelopment"
|
|
30
|
+
});
|
|
31
|
+
const telemetry = this.__getTelemetry();
|
|
32
|
+
this.clusterPromise = telemetry?.traceClass(baseClusterPromise, {
|
|
33
|
+
spanNamePrefix: "couchbase-vector",
|
|
34
|
+
attributes: {
|
|
35
|
+
"vector.type": "couchbase"
|
|
36
|
+
}
|
|
37
|
+
}) ?? baseClusterPromise;
|
|
38
|
+
this.cluster = null;
|
|
39
|
+
this.bucketName = bucketName;
|
|
40
|
+
this.collectionName = collectionName;
|
|
41
|
+
this.scopeName = scopeName;
|
|
42
|
+
this.collection = null;
|
|
43
|
+
this.bucket = null;
|
|
44
|
+
this.scope = null;
|
|
45
|
+
this.vector_dimension = null;
|
|
46
|
+
} catch (error$1) {
|
|
47
|
+
throw new error.MastraError(
|
|
48
|
+
{
|
|
49
|
+
id: "COUCHBASE_VECTOR_INITIALIZE_FAILED",
|
|
50
|
+
domain: error.ErrorDomain.STORAGE,
|
|
51
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
52
|
+
details: {
|
|
53
|
+
connectionString,
|
|
54
|
+
username,
|
|
55
|
+
password,
|
|
56
|
+
bucketName,
|
|
57
|
+
scopeName,
|
|
58
|
+
collectionName
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
error$1
|
|
62
|
+
);
|
|
63
|
+
}
|
|
44
64
|
}
|
|
45
65
|
async getCollection() {
|
|
46
66
|
if (!this.cluster) {
|
|
@@ -54,11 +74,11 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
54
74
|
return this.collection;
|
|
55
75
|
}
|
|
56
76
|
async createIndex({ indexName, dimension, metric = "dotproduct" }) {
|
|
57
|
-
await this.getCollection();
|
|
58
|
-
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
59
|
-
throw new Error("Dimension must be a positive integer");
|
|
60
|
-
}
|
|
61
77
|
try {
|
|
78
|
+
await this.getCollection();
|
|
79
|
+
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
80
|
+
throw new Error("Dimension must be a positive integer");
|
|
81
|
+
}
|
|
62
82
|
await this.scope.searchIndexes().upsertIndex({
|
|
63
83
|
name: indexName,
|
|
64
84
|
sourceName: this.bucketName,
|
|
@@ -139,84 +159,135 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
139
159
|
}
|
|
140
160
|
});
|
|
141
161
|
this.vector_dimension = dimension;
|
|
142
|
-
} catch (error) {
|
|
143
|
-
const message = error?.message || error?.toString();
|
|
162
|
+
} catch (error$1) {
|
|
163
|
+
const message = error$1?.message || error$1?.toString();
|
|
144
164
|
if (message && message.toLowerCase().includes("index exists")) {
|
|
145
165
|
await this.validateExistingIndex(indexName, dimension, metric);
|
|
146
166
|
return;
|
|
147
167
|
}
|
|
148
|
-
throw error
|
|
168
|
+
throw new error.MastraError(
|
|
169
|
+
{
|
|
170
|
+
id: "COUCHBASE_VECTOR_CREATE_INDEX_FAILED",
|
|
171
|
+
domain: error.ErrorDomain.STORAGE,
|
|
172
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
173
|
+
details: {
|
|
174
|
+
indexName,
|
|
175
|
+
dimension,
|
|
176
|
+
metric
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
error$1
|
|
180
|
+
);
|
|
149
181
|
}
|
|
150
182
|
}
|
|
151
183
|
async upsert({ vectors, metadata, ids }) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
184
|
+
try {
|
|
185
|
+
await this.getCollection();
|
|
186
|
+
if (!vectors || vectors.length === 0) {
|
|
187
|
+
throw new Error("No vectors provided");
|
|
188
|
+
}
|
|
189
|
+
if (this.vector_dimension) {
|
|
190
|
+
for (const vector of vectors) {
|
|
191
|
+
if (!vector || this.vector_dimension !== vector.length) {
|
|
192
|
+
throw new Error("Vector dimension mismatch");
|
|
193
|
+
}
|
|
160
194
|
}
|
|
161
195
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
196
|
+
const pointIds = ids || vectors.map(() => crypto.randomUUID());
|
|
197
|
+
const records = vectors.map((vector, i) => {
|
|
198
|
+
const metadataObj = metadata?.[i] || {};
|
|
199
|
+
const record = {
|
|
200
|
+
embedding: vector,
|
|
201
|
+
metadata: metadataObj
|
|
202
|
+
};
|
|
203
|
+
if (metadataObj.text) {
|
|
204
|
+
record.content = metadataObj.text;
|
|
205
|
+
}
|
|
206
|
+
return record;
|
|
207
|
+
});
|
|
208
|
+
const allPromises = [];
|
|
209
|
+
for (let i = 0; i < records.length; i++) {
|
|
210
|
+
allPromises.push(this.collection.upsert(pointIds[i], records[i]));
|
|
172
211
|
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
212
|
+
await Promise.all(allPromises);
|
|
213
|
+
return pointIds;
|
|
214
|
+
} catch (error$1) {
|
|
215
|
+
throw new error.MastraError(
|
|
216
|
+
{
|
|
217
|
+
id: "COUCHBASE_VECTOR_UPSERT_FAILED",
|
|
218
|
+
domain: error.ErrorDomain.STORAGE,
|
|
219
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
220
|
+
},
|
|
221
|
+
error$1
|
|
222
|
+
);
|
|
178
223
|
}
|
|
179
|
-
await Promise.all(allPromises);
|
|
180
|
-
return pointIds;
|
|
181
224
|
}
|
|
182
225
|
async query({ indexName, queryVector, topK = 10, includeVector = false }) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
);
|
|
191
|
-
const results = await this.scope.search(indexName, request, {
|
|
192
|
-
fields: ["*"]
|
|
193
|
-
});
|
|
194
|
-
if (includeVector) {
|
|
195
|
-
throw new Error("Including vectors in search results is not yet supported by the Couchbase vector store");
|
|
196
|
-
}
|
|
197
|
-
const output = [];
|
|
198
|
-
for (const match of results.rows) {
|
|
199
|
-
const cleanedMetadata = {};
|
|
200
|
-
const fields = match.fields || {};
|
|
201
|
-
for (const key in fields) {
|
|
202
|
-
if (Object.prototype.hasOwnProperty.call(fields, key)) {
|
|
203
|
-
const newKey = key.startsWith("metadata.") ? key.substring("metadata.".length) : key;
|
|
204
|
-
cleanedMetadata[newKey] = fields[key];
|
|
205
|
-
}
|
|
226
|
+
try {
|
|
227
|
+
await this.getCollection();
|
|
228
|
+
const index_stats = await this.describeIndex({ indexName });
|
|
229
|
+
if (queryVector.length !== index_stats.dimension) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`Query vector dimension mismatch. Expected ${index_stats.dimension}, got ${queryVector.length}`
|
|
232
|
+
);
|
|
206
233
|
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
234
|
+
let request = couchbase.SearchRequest.create(
|
|
235
|
+
couchbase.VectorSearch.fromVectorQuery(couchbase.VectorQuery.create("embedding", queryVector).numCandidates(topK))
|
|
236
|
+
);
|
|
237
|
+
const results = await this.scope.search(indexName, request, {
|
|
238
|
+
fields: ["*"]
|
|
212
239
|
});
|
|
240
|
+
if (includeVector) {
|
|
241
|
+
throw new Error("Including vectors in search results is not yet supported by the Couchbase vector store");
|
|
242
|
+
}
|
|
243
|
+
const output = [];
|
|
244
|
+
for (const match of results.rows) {
|
|
245
|
+
const cleanedMetadata = {};
|
|
246
|
+
const fields = match.fields || {};
|
|
247
|
+
for (const key in fields) {
|
|
248
|
+
if (Object.prototype.hasOwnProperty.call(fields, key)) {
|
|
249
|
+
const newKey = key.startsWith("metadata.") ? key.substring("metadata.".length) : key;
|
|
250
|
+
cleanedMetadata[newKey] = fields[key];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
output.push({
|
|
254
|
+
id: match.id,
|
|
255
|
+
score: match.score || 0,
|
|
256
|
+
metadata: cleanedMetadata
|
|
257
|
+
// Use the cleaned metadata object
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
return output;
|
|
261
|
+
} catch (error$1) {
|
|
262
|
+
throw new error.MastraError(
|
|
263
|
+
{
|
|
264
|
+
id: "COUCHBASE_VECTOR_QUERY_FAILED",
|
|
265
|
+
domain: error.ErrorDomain.STORAGE,
|
|
266
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
267
|
+
details: {
|
|
268
|
+
indexName,
|
|
269
|
+
topK
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
error$1
|
|
273
|
+
);
|
|
213
274
|
}
|
|
214
|
-
return output;
|
|
215
275
|
}
|
|
216
276
|
async listIndexes() {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
277
|
+
try {
|
|
278
|
+
await this.getCollection();
|
|
279
|
+
const indexes = await this.scope.searchIndexes().getAllIndexes();
|
|
280
|
+
return indexes?.map((index) => index.name) || [];
|
|
281
|
+
} catch (error$1) {
|
|
282
|
+
throw new error.MastraError(
|
|
283
|
+
{
|
|
284
|
+
id: "COUCHBASE_VECTOR_LIST_INDEXES_FAILED",
|
|
285
|
+
domain: error.ErrorDomain.STORAGE,
|
|
286
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
287
|
+
},
|
|
288
|
+
error$1
|
|
289
|
+
);
|
|
290
|
+
}
|
|
220
291
|
}
|
|
221
292
|
/**
|
|
222
293
|
* Retrieves statistics about a vector index.
|
|
@@ -225,29 +296,60 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
225
296
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
226
297
|
*/
|
|
227
298
|
async describeIndex({ indexName }) {
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
299
|
+
try {
|
|
300
|
+
await this.getCollection();
|
|
301
|
+
if (!(await this.listIndexes()).includes(indexName)) {
|
|
302
|
+
throw new Error(`Index ${indexName} does not exist`);
|
|
303
|
+
}
|
|
304
|
+
const index = await this.scope.searchIndexes().getIndex(indexName);
|
|
305
|
+
const dimensions = index.params.mapping?.types?.[`${this.scopeName}.${this.collectionName}`]?.properties?.embedding?.fields?.[0]?.dims;
|
|
306
|
+
const count = -1;
|
|
307
|
+
const metric = index.params.mapping?.types?.[`${this.scopeName}.${this.collectionName}`]?.properties?.embedding?.fields?.[0]?.similarity;
|
|
308
|
+
return {
|
|
309
|
+
dimension: dimensions,
|
|
310
|
+
count,
|
|
311
|
+
metric: Object.keys(DISTANCE_MAPPING).find(
|
|
312
|
+
(key) => DISTANCE_MAPPING[key] === metric
|
|
313
|
+
)
|
|
314
|
+
};
|
|
315
|
+
} catch (error$1) {
|
|
316
|
+
throw new error.MastraError(
|
|
317
|
+
{
|
|
318
|
+
id: "COUCHBASE_VECTOR_DESCRIBE_INDEX_FAILED",
|
|
319
|
+
domain: error.ErrorDomain.STORAGE,
|
|
320
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
321
|
+
details: {
|
|
322
|
+
indexName
|
|
323
|
+
}
|
|
324
|
+
},
|
|
325
|
+
error$1
|
|
326
|
+
);
|
|
231
327
|
}
|
|
232
|
-
const index = await this.scope.searchIndexes().getIndex(indexName);
|
|
233
|
-
const dimensions = index.params.mapping?.types?.[`${this.scopeName}.${this.collectionName}`]?.properties?.embedding?.fields?.[0]?.dims;
|
|
234
|
-
const count = -1;
|
|
235
|
-
const metric = index.params.mapping?.types?.[`${this.scopeName}.${this.collectionName}`]?.properties?.embedding?.fields?.[0]?.similarity;
|
|
236
|
-
return {
|
|
237
|
-
dimension: dimensions,
|
|
238
|
-
count,
|
|
239
|
-
metric: Object.keys(DISTANCE_MAPPING).find(
|
|
240
|
-
(key) => DISTANCE_MAPPING[key] === metric
|
|
241
|
-
)
|
|
242
|
-
};
|
|
243
328
|
}
|
|
244
329
|
async deleteIndex({ indexName }) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
330
|
+
try {
|
|
331
|
+
await this.getCollection();
|
|
332
|
+
if (!(await this.listIndexes()).includes(indexName)) {
|
|
333
|
+
throw new Error(`Index ${indexName} does not exist`);
|
|
334
|
+
}
|
|
335
|
+
await this.scope.searchIndexes().dropIndex(indexName);
|
|
336
|
+
this.vector_dimension = null;
|
|
337
|
+
} catch (error$1) {
|
|
338
|
+
if (error$1 instanceof error.MastraError) {
|
|
339
|
+
throw error$1;
|
|
340
|
+
}
|
|
341
|
+
throw new error.MastraError(
|
|
342
|
+
{
|
|
343
|
+
id: "COUCHBASE_VECTOR_DELETE_INDEX_FAILED",
|
|
344
|
+
domain: error.ErrorDomain.STORAGE,
|
|
345
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
346
|
+
details: {
|
|
347
|
+
indexName
|
|
348
|
+
}
|
|
349
|
+
},
|
|
350
|
+
error$1
|
|
351
|
+
);
|
|
248
352
|
}
|
|
249
|
-
await this.scope.searchIndexes().dropIndex(indexName);
|
|
250
|
-
this.vector_dimension = null;
|
|
251
353
|
}
|
|
252
354
|
/**
|
|
253
355
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
@@ -260,25 +362,41 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
260
362
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
261
363
|
*/
|
|
262
364
|
async updateVector({ id, update }) {
|
|
263
|
-
if (!update.vector && !update.metadata) {
|
|
264
|
-
throw new Error("No updates provided");
|
|
265
|
-
}
|
|
266
|
-
if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {
|
|
267
|
-
throw new Error("Vector dimension mismatch");
|
|
268
|
-
}
|
|
269
|
-
const collection = await this.getCollection();
|
|
270
365
|
try {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
366
|
+
if (!update.vector && !update.metadata) {
|
|
367
|
+
throw new Error("No updates provided");
|
|
368
|
+
}
|
|
369
|
+
if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {
|
|
370
|
+
throw new Error("Vector dimension mismatch");
|
|
371
|
+
}
|
|
372
|
+
const collection = await this.getCollection();
|
|
373
|
+
try {
|
|
374
|
+
await collection.get(id);
|
|
375
|
+
} catch (err) {
|
|
376
|
+
if (err.code === 13 || err.message?.includes("document not found")) {
|
|
377
|
+
throw new Error(`Vector with id ${id} does not exist`);
|
|
378
|
+
}
|
|
379
|
+
throw err;
|
|
275
380
|
}
|
|
276
|
-
|
|
381
|
+
const specs = [];
|
|
382
|
+
if (update.vector) specs.push(couchbase.MutateInSpec.replace("embedding", update.vector));
|
|
383
|
+
if (update.metadata) specs.push(couchbase.MutateInSpec.replace("metadata", update.metadata));
|
|
384
|
+
await collection.mutateIn(id, specs);
|
|
385
|
+
} catch (error$1) {
|
|
386
|
+
throw new error.MastraError(
|
|
387
|
+
{
|
|
388
|
+
id: "COUCHBASE_VECTOR_UPDATE_FAILED",
|
|
389
|
+
domain: error.ErrorDomain.STORAGE,
|
|
390
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
391
|
+
details: {
|
|
392
|
+
id,
|
|
393
|
+
hasVectorUpdate: !!update.vector,
|
|
394
|
+
hasMetadataUpdate: !!update.metadata
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
error$1
|
|
398
|
+
);
|
|
277
399
|
}
|
|
278
|
-
const specs = [];
|
|
279
|
-
if (update.vector) specs.push(couchbase.MutateInSpec.replace("embedding", update.vector));
|
|
280
|
-
if (update.metadata) specs.push(couchbase.MutateInSpec.replace("metadata", update.metadata));
|
|
281
|
-
await collection.mutateIn(id, specs);
|
|
282
400
|
}
|
|
283
401
|
/**
|
|
284
402
|
* Deletes a vector by its ID.
|
|
@@ -288,24 +406,51 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
288
406
|
* @throws Will throw an error if the deletion operation fails.
|
|
289
407
|
*/
|
|
290
408
|
async deleteVector({ id }) {
|
|
291
|
-
const collection = await this.getCollection();
|
|
292
409
|
try {
|
|
293
|
-
await
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
410
|
+
const collection = await this.getCollection();
|
|
411
|
+
try {
|
|
412
|
+
await collection.get(id);
|
|
413
|
+
} catch (err) {
|
|
414
|
+
if (err.code === 13 || err.message?.includes("document not found")) {
|
|
415
|
+
throw new Error(`Vector with id ${id} does not exist`);
|
|
416
|
+
}
|
|
417
|
+
throw err;
|
|
297
418
|
}
|
|
298
|
-
|
|
419
|
+
await collection.remove(id);
|
|
420
|
+
} catch (error$1) {
|
|
421
|
+
throw new error.MastraError(
|
|
422
|
+
{
|
|
423
|
+
id: "COUCHBASE_VECTOR_DELETE_FAILED",
|
|
424
|
+
domain: error.ErrorDomain.STORAGE,
|
|
425
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
426
|
+
details: {
|
|
427
|
+
id
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
error$1
|
|
431
|
+
);
|
|
299
432
|
}
|
|
300
|
-
await collection.remove(id);
|
|
301
433
|
}
|
|
302
434
|
async disconnect() {
|
|
303
|
-
|
|
304
|
-
|
|
435
|
+
try {
|
|
436
|
+
if (!this.cluster) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
await this.cluster.close();
|
|
440
|
+
} catch (error$1) {
|
|
441
|
+
throw new error.MastraError(
|
|
442
|
+
{
|
|
443
|
+
id: "COUCHBASE_VECTOR_DISCONNECT_FAILED",
|
|
444
|
+
domain: error.ErrorDomain.STORAGE,
|
|
445
|
+
category: error.ErrorCategory.THIRD_PARTY
|
|
446
|
+
},
|
|
447
|
+
error$1
|
|
448
|
+
);
|
|
305
449
|
}
|
|
306
|
-
await this.cluster.close();
|
|
307
450
|
}
|
|
308
451
|
};
|
|
309
452
|
|
|
310
453
|
exports.CouchbaseVector = CouchbaseVector;
|
|
311
454
|
exports.DISTANCE_MAPPING = DISTANCE_MAPPING;
|
|
455
|
+
//# sourceMappingURL=index.cjs.map
|
|
456
|
+
//# sourceMappingURL=index.cjs.map
|