@mastra/couchbase 0.10.3 → 0.10.4-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.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +13 -0
- package/dist/index.cjs +272 -129
- package/dist/index.js +270 -127
- package/package.json +2 -2
- package/src/vector/index.ts +284 -141
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/couchbase@0.10.
|
|
2
|
+
> @mastra/couchbase@0.10.4-alpha.0 build /home/runner/work/mastra/mastra/stores/couchbase
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 7500ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/couchbase/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/couchbase/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 9034ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m14.55 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 690ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m14.29 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 699ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mastra/couchbase
|
|
2
2
|
|
|
3
|
+
## 0.10.4-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 0e17048: Throw mastra errors in storage packages
|
|
8
|
+
- Updated dependencies [d1baedb]
|
|
9
|
+
- Updated dependencies [4d21bf2]
|
|
10
|
+
- Updated dependencies [2097952]
|
|
11
|
+
- Updated dependencies [4fb0cc2]
|
|
12
|
+
- Updated dependencies [d2a7a31]
|
|
13
|
+
- Updated dependencies [0e17048]
|
|
14
|
+
- @mastra/core@0.10.7-alpha.1
|
|
15
|
+
|
|
3
16
|
## 0.10.3
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
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,22 +406,47 @@ 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
|
|