@mastra/couchbase 0.0.0-vector-sources-20250516175436 → 0.0.0-vector-query-tool-provider-options-20250828222356

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/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
 
@@ -19,49 +20,47 @@ var CouchbaseVector = class extends vector.MastraVector {
19
20
  bucket;
20
21
  scope;
21
22
  vector_dimension;
22
- constructor(paramsOrConnectionString, username, password, bucketName, scopeName, collectionName) {
23
- let connectionString_, username_, password_, bucketName_, scopeName_, collectionName_;
24
- if (typeof paramsOrConnectionString === "object" && paramsOrConnectionString !== null && "connectionString" in paramsOrConnectionString) {
25
- connectionString_ = paramsOrConnectionString.connectionString;
26
- username_ = paramsOrConnectionString.username;
27
- password_ = paramsOrConnectionString.password;
28
- bucketName_ = paramsOrConnectionString.bucketName;
29
- scopeName_ = paramsOrConnectionString.scopeName;
30
- collectionName_ = paramsOrConnectionString.collectionName;
31
- } else {
32
- if (arguments.length > 1) {
33
- console.warn(
34
- "Deprecation Warning: CouchbaseVector constructor positional arguments are deprecated. Please use a single object parameter instead. This signature will be removed on May 20th, 2025."
35
- );
36
- }
37
- connectionString_ = paramsOrConnectionString;
38
- username_ = username;
39
- password_ = password;
40
- bucketName_ = bucketName;
41
- scopeName_ = scopeName;
42
- collectionName_ = collectionName;
43
- }
23
+ constructor({ connectionString, username, password, bucketName, scopeName, collectionName }) {
44
24
  super();
45
- const baseClusterPromise = couchbase.connect(connectionString_, {
46
- username: username_,
47
- password: password_,
48
- configProfile: "wanDevelopment"
49
- });
50
- const telemetry = this.__getTelemetry();
51
- this.clusterPromise = telemetry?.traceClass(baseClusterPromise, {
52
- spanNamePrefix: "couchbase-vector",
53
- attributes: {
54
- "vector.type": "couchbase"
55
- }
56
- }) ?? baseClusterPromise;
57
- this.cluster = null;
58
- this.bucketName = bucketName_;
59
- this.collectionName = collectionName_;
60
- this.scopeName = scopeName_;
61
- this.collection = null;
62
- this.bucket = null;
63
- this.scope = null;
64
- this.vector_dimension = null;
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
+ }
65
64
  }
66
65
  async getCollection() {
67
66
  if (!this.cluster) {
@@ -74,13 +73,12 @@ var CouchbaseVector = class extends vector.MastraVector {
74
73
  }
75
74
  return this.collection;
76
75
  }
77
- async createIndex(params) {
78
- const { indexName, dimension, metric = "dotproduct" } = params;
79
- await this.getCollection();
80
- if (!Number.isInteger(dimension) || dimension <= 0) {
81
- throw new Error("Dimension must be a positive integer");
82
- }
76
+ async createIndex({ indexName, dimension, metric = "dotproduct" }) {
83
77
  try {
78
+ await this.getCollection();
79
+ if (!Number.isInteger(dimension) || dimension <= 0) {
80
+ throw new Error("Dimension must be a positive integer");
81
+ }
84
82
  await this.scope.searchIndexes().upsertIndex({
85
83
  name: indexName,
86
84
  sourceName: this.bucketName,
@@ -161,122 +159,197 @@ var CouchbaseVector = class extends vector.MastraVector {
161
159
  }
162
160
  });
163
161
  this.vector_dimension = dimension;
164
- } catch (error) {
165
- const message = error?.message || error?.toString();
162
+ } catch (error$1) {
163
+ const message = error$1?.message || error$1?.toString();
166
164
  if (message && message.toLowerCase().includes("index exists")) {
167
165
  await this.validateExistingIndex(indexName, dimension, metric);
168
166
  return;
169
167
  }
170
- 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
+ );
171
181
  }
172
182
  }
173
- async upsert(params) {
174
- const { vectors, metadata, ids } = params;
175
- await this.getCollection();
176
- if (!vectors || vectors.length === 0) {
177
- throw new Error("No vectors provided");
178
- }
179
- if (this.vector_dimension) {
180
- for (const vector of vectors) {
181
- if (!vector || this.vector_dimension !== vector.length) {
182
- throw new Error("Vector dimension mismatch");
183
+ async upsert({ vectors, metadata, ids }) {
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
+ }
183
194
  }
184
195
  }
185
- }
186
- const pointIds = ids || vectors.map(() => crypto.randomUUID());
187
- const records = vectors.map((vector, i) => {
188
- const metadataObj = metadata?.[i] || {};
189
- const record = {
190
- embedding: vector,
191
- metadata: metadataObj
192
- };
193
- if (metadataObj.text) {
194
- record.content = metadataObj.text;
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]));
195
211
  }
196
- return record;
197
- });
198
- const allPromises = [];
199
- for (let i = 0; i < records.length; i++) {
200
- allPromises.push(this.collection.upsert(pointIds[i], records[i]));
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
+ );
201
223
  }
202
- await Promise.all(allPromises);
203
- return pointIds;
204
224
  }
205
- async query(params) {
206
- const { indexName, queryVector, topK = 10, includeVector = false } = params;
207
- await this.getCollection();
208
- const index_stats = await this.describeIndex(indexName);
209
- if (queryVector.length !== index_stats.dimension) {
210
- throw new Error(`Query vector dimension mismatch. Expected ${index_stats.dimension}, got ${queryVector.length}`);
211
- }
212
- let request = couchbase.SearchRequest.create(
213
- couchbase.VectorSearch.fromVectorQuery(couchbase.VectorQuery.create("embedding", queryVector).numCandidates(topK))
214
- );
215
- const results = await this.scope.search(indexName, request, {
216
- fields: ["*"]
217
- });
218
- if (includeVector) {
219
- throw new Error("Including vectors in search results is not yet supported by the Couchbase vector store");
220
- }
221
- const output = [];
222
- for (const match of results.rows) {
223
- const cleanedMetadata = {};
224
- const fields = match.fields || {};
225
- for (const key in fields) {
226
- if (Object.prototype.hasOwnProperty.call(fields, key)) {
227
- const newKey = key.startsWith("metadata.") ? key.substring("metadata.".length) : key;
228
- cleanedMetadata[newKey] = fields[key];
229
- }
225
+ async query({ indexName, queryVector, topK = 10, includeVector = false }) {
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
+ );
230
233
  }
231
- output.push({
232
- id: match.id,
233
- score: match.score || 0,
234
- metadata: cleanedMetadata
235
- // Use the cleaned metadata object
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: ["*"]
236
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
+ );
237
274
  }
238
- return output;
239
275
  }
240
276
  async listIndexes() {
241
- await this.getCollection();
242
- const indexes = await this.scope.searchIndexes().getAllIndexes();
243
- return indexes?.map((index) => index.name) || [];
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
+ }
244
291
  }
245
292
  /**
246
293
  * Retrieves statistics about a vector index.
247
294
  *
248
- * @param params - The parameters for describing an index
249
- * @param params.indexName - The name of the index to describe
295
+ * @param {string} indexName - The name of the index to describe
250
296
  * @returns A promise that resolves to the index statistics including dimension, count and metric
251
297
  */
252
- async describeIndex(...args) {
253
- const params = this.normalizeArgs("describeIndex", args);
254
- const { indexName } = params;
255
- await this.getCollection();
256
- if (!(await this.listIndexes()).includes(indexName)) {
257
- throw new Error(`Index ${indexName} does not exist`);
298
+ async describeIndex({ indexName }) {
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
+ );
258
327
  }
259
- const index = await this.scope.searchIndexes().getIndex(indexName);
260
- const dimensions = index.params.mapping?.types?.[`${this.scopeName}.${this.collectionName}`]?.properties?.embedding?.fields?.[0]?.dims;
261
- const count = -1;
262
- const metric = index.params.mapping?.types?.[`${this.scopeName}.${this.collectionName}`]?.properties?.embedding?.fields?.[0]?.similarity;
263
- return {
264
- dimension: dimensions,
265
- count,
266
- metric: Object.keys(DISTANCE_MAPPING).find(
267
- (key) => DISTANCE_MAPPING[key] === metric
268
- )
269
- };
270
328
  }
271
- async deleteIndex(...args) {
272
- const params = this.normalizeArgs("deleteIndex", args);
273
- const { indexName } = params;
274
- await this.getCollection();
275
- if (!(await this.listIndexes()).includes(indexName)) {
276
- throw new Error(`Index ${indexName} does not exist`);
329
+ async deleteIndex({ indexName }) {
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
+ );
277
352
  }
278
- await this.scope.searchIndexes().dropIndex(indexName);
279
- this.vector_dimension = null;
280
353
  }
281
354
  /**
282
355
  * Updates a vector by its ID with the provided vector and/or metadata.
@@ -288,28 +361,42 @@ var CouchbaseVector = class extends vector.MastraVector {
288
361
  * @returns A promise that resolves when the update is complete.
289
362
  * @throws Will throw an error if no updates are provided or if the update operation fails.
290
363
  */
291
- async updateVector(...args) {
292
- const params = this.normalizeArgs("updateVector", args);
293
- const { id, update } = params;
294
- if (!update.vector && !update.metadata) {
295
- throw new Error("No updates provided");
296
- }
297
- if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {
298
- throw new Error("Vector dimension mismatch");
299
- }
300
- const collection = await this.getCollection();
364
+ async updateVector({ id, update }) {
301
365
  try {
302
- await collection.get(id);
303
- } catch (err) {
304
- if (err.code === 13 || err.message?.includes("document not found")) {
305
- throw new Error(`Vector with id ${id} does not exist`);
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;
306
380
  }
307
- throw err;
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
+ );
308
399
  }
309
- const specs = [];
310
- if (update.vector) specs.push(couchbase.MutateInSpec.replace("embedding", update.vector));
311
- if (update.metadata) specs.push(couchbase.MutateInSpec.replace("metadata", update.metadata));
312
- await collection.mutateIn(id, specs);
313
400
  }
314
401
  /**
315
402
  * Deletes a vector by its ID.
@@ -318,21 +405,52 @@ var CouchbaseVector = class extends vector.MastraVector {
318
405
  * @returns A promise that resolves when the deletion is complete.
319
406
  * @throws Will throw an error if the deletion operation fails.
320
407
  */
321
- async deleteVector(...args) {
322
- const params = this.normalizeArgs("deleteVector", args);
323
- const { id } = params;
324
- const collection = await this.getCollection();
408
+ async deleteVector({ id }) {
325
409
  try {
326
- await collection.get(id);
327
- } catch (err) {
328
- if (err.code === 13 || err.message?.includes("document not found")) {
329
- throw new Error(`Vector with id ${id} does not exist`);
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;
330
418
  }
331
- throw err;
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
+ );
432
+ }
433
+ }
434
+ async disconnect() {
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
+ );
332
449
  }
333
- await collection.remove(id);
334
450
  }
335
451
  };
336
452
 
337
453
  exports.CouchbaseVector = CouchbaseVector;
338
454
  exports.DISTANCE_MAPPING = DISTANCE_MAPPING;
455
+ //# sourceMappingURL=index.cjs.map
456
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/vector/index.ts"],"names":["MastraVector","connect","error","MastraError","ErrorDomain","ErrorCategory","SearchRequest","VectorSearch","VectorQuery","MutateInSpec"],"mappings":";;;;;;;AAkBO,IAAM,gBAAA,GAA0D;AAAA,EACrE,MAAA,EAAQ,QAAA;AAAA,EACR,SAAA,EAAW,SAAA;AAAA,EACX,UAAA,EAAY;AACd;AAWO,IAAM,eAAA,GAAN,cAA8BA,mBAAA,CAAa;AAAA,EACxC,cAAA;AAAA,EACA,OAAA;AAAA,EACA,UAAA;AAAA,EACA,cAAA;AAAA,EACA,SAAA;AAAA,EACA,UAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AAAA,EACA,gBAAA;AAAA,EA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GAAA,EAAU;AACjB,QAAA,IAAI,IAAI,IAAA,KAAS,EAAA,IAAM,IAAI,OAAA,EAAS,QAAA,CAAS,oBAAoB,CAAA,EAAG;AAClE,UAAA,MAAM,IAAI,KAAA,CAAM,CAAA,eAAA,EAAkB,EAAE,CAAA,eAAA,CAAiB,CAAA;AAAA,QACvD;AACA,QAAA,MAAM,GAAA;AAAA,MACR;AAEA,MAAA,MAAM,UAAA,CAAW,OAAO,EAAE,CAAA;AAAA,IAC5B,SAASA,OAAA,EAAO;AACd,MAAA,MAAM,IAAIC,iBAAA;AAAA,QACR;AAAA,UACE,EAAA,EAAI,gCAAA;AAAA,UACJ,QAAQC,iBAAA,CAAY,OAAA;AAAA,UACpB,UAAUC,mBAAA,CAAc,WAAA;AAAA,UACxB,OAAA,EAAS;AAAA,YACP;AAAA;AACF,SACF;AAAA,QACAH;AAAA,OACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,UAAA,GAAa;AACjB,IAAA,IAAI;AACF,MAAA,IAAI,CAAC,KAAK,OAAA,EAAS;AACjB,QAAA;AAAA,MACF;AACA,MAAA,MAAM,IAAA,CAAK,QAAQ,KAAA,EAAM;AAAA,IAC3B,SAASA,OAAA,EAAO;AACd,MAAA,MAAM,IAAIC,iBAAA;AAAA,QACR;AAAA,UACE,EAAA,EAAI,oCAAA;AAAA,UACJ,QAAQC,iBAAA,CAAY,OAAA;AAAA,UACpB,UAAUC,mBAAA,CAAc;AAAA,SAC1B;AAAA,QACAH;AAAA,OACF;AAAA,IACF;AAAA,EACF;AACF","file":"index.cjs","sourcesContent":["import { ErrorCategory, ErrorDomain, MastraError } from '@mastra/core/error';\nimport { MastraVector } from '@mastra/core/vector';\nimport type {\n QueryResult,\n IndexStats,\n CreateIndexParams,\n UpsertVectorParams,\n QueryVectorParams,\n DescribeIndexParams,\n DeleteIndexParams,\n DeleteVectorParams,\n UpdateVectorParams,\n} from '@mastra/core/vector';\nimport type { Bucket, Cluster, Collection, Scope } from 'couchbase';\nimport { MutateInSpec, connect, SearchRequest, VectorQuery, VectorSearch } from 'couchbase';\n\ntype MastraMetric = 'cosine' | 'euclidean' | 'dotproduct';\ntype CouchbaseMetric = 'cosine' | 'l2_norm' | 'dot_product';\nexport const DISTANCE_MAPPING: Record<MastraMetric, CouchbaseMetric> = {\n cosine: 'cosine',\n euclidean: 'l2_norm',\n dotproduct: 'dot_product',\n};\n\nexport type CouchbaseVectorParams = {\n connectionString: string;\n username: string;\n password: string;\n bucketName: string;\n scopeName: string;\n collectionName: string;\n};\n\nexport class CouchbaseVector extends MastraVector {\n private clusterPromise: Promise<Cluster>;\n private cluster: Cluster;\n private bucketName: string;\n private collectionName: string;\n private scopeName: string;\n private collection: Collection;\n private bucket: Bucket;\n private scope: Scope;\n private vector_dimension: number;\n\n constructor({ connectionString, username, password, bucketName, scopeName, collectionName }: CouchbaseVectorParams) {\n super();\n\n try {\n const baseClusterPromise = connect(connectionString, {\n username,\n password,\n configProfile: 'wanDevelopment',\n });\n\n const telemetry = this.__getTelemetry();\n this.clusterPromise =\n telemetry?.traceClass(baseClusterPromise, {\n spanNamePrefix: 'couchbase-vector',\n attributes: {\n 'vector.type': 'couchbase',\n },\n }) ?? baseClusterPromise;\n this.cluster = null as unknown as Cluster;\n this.bucketName = bucketName;\n this.collectionName = collectionName;\n this.scopeName = scopeName;\n this.collection = null as unknown as Collection;\n this.bucket = null as unknown as Bucket;\n this.scope = null as unknown as Scope;\n this.vector_dimension = null as unknown as number;\n } catch (error) {\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_INITIALIZE_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n connectionString,\n username,\n password,\n bucketName,\n scopeName,\n collectionName,\n },\n },\n error,\n );\n }\n }\n\n async getCollection() {\n if (!this.cluster) {\n this.cluster = await this.clusterPromise;\n }\n\n if (!this.collection) {\n this.bucket = this.cluster.bucket(this.bucketName);\n this.scope = this.bucket.scope(this.scopeName);\n this.collection = this.scope.collection(this.collectionName);\n }\n\n return this.collection;\n }\n\n async createIndex({ indexName, dimension, metric = 'dotproduct' as MastraMetric }: CreateIndexParams): Promise<void> {\n try {\n await this.getCollection();\n\n if (!Number.isInteger(dimension) || dimension <= 0) {\n throw new Error('Dimension must be a positive integer');\n }\n\n await this.scope.searchIndexes().upsertIndex({\n name: indexName,\n sourceName: this.bucketName,\n type: 'fulltext-index',\n params: {\n doc_config: {\n docid_prefix_delim: '',\n docid_regexp: '',\n mode: 'scope.collection.type_field',\n type_field: 'type',\n },\n mapping: {\n default_analyzer: 'standard',\n default_datetime_parser: 'dateTimeOptional',\n default_field: '_all',\n default_mapping: {\n dynamic: true,\n enabled: false,\n },\n default_type: '_default',\n docvalues_dynamic: true, // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field\n index_dynamic: true,\n store_dynamic: true, // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field\n type_field: '_type',\n types: {\n [`${this.scopeName}.${this.collectionName}`]: {\n dynamic: true,\n enabled: true,\n properties: {\n embedding: {\n enabled: true,\n fields: [\n {\n dims: dimension,\n index: true,\n name: 'embedding',\n similarity: DISTANCE_MAPPING[metric],\n type: 'vector',\n vector_index_optimized_for: 'recall',\n store: true, // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields\n docvalues: true, // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields\n include_term_vectors: true, // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields\n },\n ],\n },\n content: {\n enabled: true,\n fields: [\n {\n index: true,\n name: 'content',\n store: true,\n type: 'text',\n },\n ],\n },\n },\n },\n },\n },\n store: {\n indexType: 'scorch',\n segmentVersion: 16,\n },\n },\n sourceUuid: '',\n sourceParams: {},\n sourceType: 'gocbcore',\n planParams: {\n maxPartitionsPerPIndex: 64,\n indexPartitions: 16,\n numReplicas: 0,\n },\n });\n this.vector_dimension = dimension;\n } catch (error: any) {\n // Check for 'already exists' error (Couchbase may throw a 400 or 409, or have a message)\n const message = error?.message || error?.toString();\n if (message && message.toLowerCase().includes('index exists')) {\n // Fetch index info and check dimension\n await this.validateExistingIndex(indexName, dimension, metric);\n return;\n }\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_CREATE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n dimension,\n metric,\n },\n },\n error,\n );\n }\n }\n\n async upsert({ vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {\n try {\n await this.getCollection();\n\n if (!vectors || vectors.length === 0) {\n throw new Error('No vectors provided');\n }\n if (this.vector_dimension) {\n for (const vector of vectors) {\n if (!vector || this.vector_dimension !== vector.length) {\n throw new Error('Vector dimension mismatch');\n }\n }\n }\n\n const pointIds = ids || vectors.map(() => crypto.randomUUID());\n const records = vectors.map((vector, i) => {\n const metadataObj = metadata?.[i] || {};\n const record: Record<string, any> = {\n embedding: vector,\n metadata: metadataObj,\n };\n // If metadata has a text field, save it as content\n if (metadataObj.text) {\n record.content = metadataObj.text;\n }\n return record;\n });\n\n const allPromises = [];\n for (let i = 0; i < records.length; i++) {\n allPromises.push(this.collection.upsert(pointIds[i]!, records[i]));\n }\n await Promise.all(allPromises);\n\n return pointIds;\n } catch (error) {\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_UPSERT_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n async query({ indexName, queryVector, topK = 10, includeVector = false }: QueryVectorParams): Promise<QueryResult[]> {\n try {\n await this.getCollection();\n\n const index_stats = await this.describeIndex({ indexName });\n if (queryVector.length !== index_stats.dimension) {\n throw new Error(\n `Query vector dimension mismatch. Expected ${index_stats.dimension}, got ${queryVector.length}`,\n );\n }\n\n let request = SearchRequest.create(\n VectorSearch.fromVectorQuery(VectorQuery.create('embedding', queryVector).numCandidates(topK)),\n );\n const results = await this.scope.search(indexName, request, {\n fields: ['*'],\n });\n\n if (includeVector) {\n throw new Error('Including vectors in search results is not yet supported by the Couchbase vector store');\n }\n const output = [];\n for (const match of results.rows) {\n const cleanedMetadata: Record<string, any> = {};\n const fields = (match.fields as Record<string, any>) || {}; // Ensure fields is an object\n for (const key in fields) {\n if (Object.prototype.hasOwnProperty.call(fields, key)) {\n const newKey = key.startsWith('metadata.') ? key.substring('metadata.'.length) : key;\n cleanedMetadata[newKey] = fields[key];\n }\n }\n output.push({\n id: match.id as string,\n score: (match.score as number) || 0,\n metadata: cleanedMetadata, // Use the cleaned metadata object\n });\n }\n return output;\n } catch (error) {\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_QUERY_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n topK,\n },\n },\n error,\n );\n }\n }\n\n async listIndexes(): Promise<string[]> {\n try {\n await this.getCollection();\n const indexes = await this.scope.searchIndexes().getAllIndexes();\n return indexes?.map(index => index.name) || [];\n } catch (error) {\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_LIST_INDEXES_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n\n /**\n * Retrieves statistics about a vector index.\n *\n * @param {string} indexName - The name of the index to describe\n * @returns A promise that resolves to the index statistics including dimension, count and metric\n */\n async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {\n try {\n await this.getCollection();\n if (!(await this.listIndexes()).includes(indexName)) {\n throw new Error(`Index ${indexName} does not exist`);\n }\n const index = await this.scope.searchIndexes().getIndex(indexName);\n const dimensions =\n index.params.mapping?.types?.[`${this.scopeName}.${this.collectionName}`]?.properties?.embedding?.fields?.[0]\n ?.dims;\n const count = -1; // Not added support yet for adding a count of documents covered by an index\n const metric = index.params.mapping?.types?.[`${this.scopeName}.${this.collectionName}`]?.properties?.embedding\n ?.fields?.[0]?.similarity as CouchbaseMetric;\n return {\n dimension: dimensions,\n count: count,\n metric: Object.keys(DISTANCE_MAPPING).find(\n key => DISTANCE_MAPPING[key as MastraMetric] === metric,\n ) as MastraMetric,\n };\n } catch (error) {\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_DESCRIBE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n },\n },\n error,\n );\n }\n }\n\n async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {\n try {\n await this.getCollection();\n if (!(await this.listIndexes()).includes(indexName)) {\n throw new Error(`Index ${indexName} does not exist`);\n }\n await this.scope.searchIndexes().dropIndex(indexName);\n this.vector_dimension = null as unknown as number;\n } catch (error) {\n if (error instanceof MastraError) {\n throw error;\n }\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_DELETE_INDEX_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n indexName,\n },\n },\n error,\n );\n }\n }\n\n /**\n * Updates a vector by its ID with the provided vector and/or metadata.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to update.\n * @param update - An object containing the vector and/or metadata to update.\n * @param update.vector - An optional array of numbers representing the new vector.\n * @param update.metadata - An optional record containing the new metadata.\n * @returns A promise that resolves when the update is complete.\n * @throws Will throw an error if no updates are provided or if the update operation fails.\n */\n async updateVector({ id, update }: UpdateVectorParams): Promise<void> {\n try {\n if (!update.vector && !update.metadata) {\n throw new Error('No updates provided');\n }\n if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {\n throw new Error('Vector dimension mismatch');\n }\n const collection = await this.getCollection();\n\n // Check if document exists\n try {\n await collection.get(id);\n } catch (err: any) {\n if (err.code === 13 || err.message?.includes('document not found')) {\n throw new Error(`Vector with id ${id} does not exist`);\n }\n throw err;\n }\n\n const specs: MutateInSpec[] = [];\n if (update.vector) specs.push(MutateInSpec.replace('embedding', update.vector));\n if (update.metadata) specs.push(MutateInSpec.replace('metadata', update.metadata));\n\n await collection.mutateIn(id, specs);\n } catch (error) {\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_UPDATE_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n id,\n hasVectorUpdate: !!update.vector,\n hasMetadataUpdate: !!update.metadata,\n },\n },\n error,\n );\n }\n }\n\n /**\n * Deletes a vector by its ID.\n * @param indexName - The name of the index containing the vector.\n * @param id - The ID of the vector to delete.\n * @returns A promise that resolves when the deletion is complete.\n * @throws Will throw an error if the deletion operation fails.\n */\n async deleteVector({ id }: DeleteVectorParams): Promise<void> {\n try {\n const collection = await this.getCollection();\n\n // Check if document exists\n try {\n await collection.get(id);\n } catch (err: any) {\n if (err.code === 13 || err.message?.includes('document not found')) {\n throw new Error(`Vector with id ${id} does not exist`);\n }\n throw err;\n }\n\n await collection.remove(id);\n } catch (error) {\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_DELETE_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n details: {\n id,\n },\n },\n error,\n );\n }\n }\n\n async disconnect() {\n try {\n if (!this.cluster) {\n return;\n }\n await this.cluster.close();\n } catch (error) {\n throw new MastraError(\n {\n id: 'COUCHBASE_VECTOR_DISCONNECT_FAILED',\n domain: ErrorDomain.STORAGE,\n category: ErrorCategory.THIRD_PARTY,\n },\n error,\n );\n }\n }\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,2 @@
1
- export { DISTANCE_MAPPING } from './_tsup-dts-rollup.js';
2
- export { CouchbaseVectorParams } from './_tsup-dts-rollup.js';
3
- export { CouchbaseVector } from './_tsup-dts-rollup.js';
1
+ export * from './vector/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}