@mastra/couchbase 0.0.0-trigger-playground-ui-package-20250506151043 → 0.0.0-vector-sources-20250516175436

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 CHANGED
@@ -1,6 +1,121 @@
1
1
  # @mastra/couchbase
2
2
 
3
- ## 0.0.0-trigger-playground-ui-package-20250506151043
3
+ ## 0.0.0-vector-sources-20250516175436
4
+
5
+ ### Patch Changes
6
+
7
+ - d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
8
+ - Updated dependencies [f53a6ac]
9
+ - Updated dependencies [eabdcd9]
10
+ - Updated dependencies [d0ee3c6]
11
+ - Updated dependencies [23f258c]
12
+ - Updated dependencies [2672a05]
13
+ - @mastra/core@0.0.0-vector-sources-20250516175436
14
+
15
+ ## 0.0.4
16
+
17
+ ### Patch Changes
18
+
19
+ - c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
20
+ - Updated dependencies [396be50]
21
+ - Updated dependencies [ab80e7e]
22
+ - Updated dependencies [c3bd795]
23
+ - Updated dependencies [da082f8]
24
+ - Updated dependencies [a5810ce]
25
+ - Updated dependencies [3e9c131]
26
+ - Updated dependencies [3171b5b]
27
+ - Updated dependencies [973e5ac]
28
+ - Updated dependencies [daf942f]
29
+ - Updated dependencies [0b8b868]
30
+ - Updated dependencies [9e1eff5]
31
+ - Updated dependencies [6fa1ad1]
32
+ - Updated dependencies [c28d7a0]
33
+ - Updated dependencies [edf1e88]
34
+ - @mastra/core@0.9.4
35
+
36
+ ## 0.0.4-alpha.4
37
+
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [3e9c131]
41
+ - @mastra/core@0.9.4-alpha.4
42
+
43
+ ## 0.0.4-alpha.3
44
+
45
+ ### Patch Changes
46
+
47
+ - c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
48
+ - Updated dependencies [396be50]
49
+ - Updated dependencies [c3bd795]
50
+ - Updated dependencies [da082f8]
51
+ - Updated dependencies [a5810ce]
52
+ - @mastra/core@0.9.4-alpha.3
53
+
54
+ ## 0.0.4-alpha.2
55
+
56
+ ### Patch Changes
57
+
58
+ - Updated dependencies [3171b5b]
59
+ - Updated dependencies [973e5ac]
60
+ - Updated dependencies [9e1eff5]
61
+ - @mastra/core@0.9.4-alpha.2
62
+
63
+ ## 0.0.4-alpha.1
64
+
65
+ ### Patch Changes
66
+
67
+ - Updated dependencies [ab80e7e]
68
+ - Updated dependencies [6fa1ad1]
69
+ - Updated dependencies [c28d7a0]
70
+ - Updated dependencies [edf1e88]
71
+ - @mastra/core@0.9.4-alpha.1
72
+
73
+ ## 0.0.4-alpha.0
74
+
75
+ ### Patch Changes
76
+
77
+ - Updated dependencies [daf942f]
78
+ - Updated dependencies [0b8b868]
79
+ - @mastra/core@0.9.4-alpha.0
80
+
81
+ ## 0.0.3
82
+
83
+ ### Patch Changes
84
+
85
+ - 9cd1a46: [MASTRA-3338] update naming scheme for embedding index based on vector store rules and added duplicate index checks
86
+ - Updated dependencies [e450778]
87
+ - Updated dependencies [8902157]
88
+ - Updated dependencies [ca0dc88]
89
+ - Updated dependencies [526c570]
90
+ - Updated dependencies [d7a6a33]
91
+ - Updated dependencies [9cd1a46]
92
+ - Updated dependencies [b5d2de0]
93
+ - Updated dependencies [644f8ad]
94
+ - Updated dependencies [70dbf51]
95
+ - @mastra/core@0.9.3
96
+
97
+ ## 0.0.3-alpha.1
98
+
99
+ ### Patch Changes
100
+
101
+ - 9cd1a46: [MASTRA-3338] update naming scheme for embedding index based on vector store rules and added duplicate index checks
102
+ - Updated dependencies [e450778]
103
+ - Updated dependencies [8902157]
104
+ - Updated dependencies [ca0dc88]
105
+ - Updated dependencies [9cd1a46]
106
+ - Updated dependencies [70dbf51]
107
+ - @mastra/core@0.9.3-alpha.1
108
+
109
+ ## 0.0.3-alpha.0
110
+
111
+ ### Patch Changes
112
+
113
+ - Updated dependencies [526c570]
114
+ - Updated dependencies [b5d2de0]
115
+ - Updated dependencies [644f8ad]
116
+ - @mastra/core@0.9.3-alpha.0
117
+
118
+ ## 0.0.2
4
119
 
5
120
  ### Patch Changes
6
121
 
@@ -19,8 +134,20 @@
19
134
  - Updated dependencies [17826a9]
20
135
  - Updated dependencies [7d8b7c7]
21
136
  - Updated dependencies [fba031f]
137
+ - Updated dependencies [3a5f1e1]
22
138
  - Updated dependencies [51e6923]
23
- - @mastra/core@0.0.0-trigger-playground-ui-package-20250506151043
139
+ - Updated dependencies [8398d89]
140
+ - @mastra/core@0.9.2
141
+
142
+ ## 0.0.2-alpha.1
143
+
144
+ ### Patch Changes
145
+
146
+ - Updated dependencies [6052aa6]
147
+ - Updated dependencies [7d8b7c7]
148
+ - Updated dependencies [3a5f1e1]
149
+ - Updated dependencies [8398d89]
150
+ - @mastra/core@0.9.2-alpha.6
24
151
 
25
152
  ## 0.0.2-alpha.0
26
153
 
@@ -1,9 +1,14 @@
1
1
  import type { Collection } from 'couchbase';
2
2
  import type { CreateIndexParams } from '@mastra/core/vector';
3
+ import type { DeleteIndexParams } from '@mastra/core/vector';
4
+ import type { DeleteVectorParams } from '@mastra/core/vector';
5
+ import type { DescribeIndexParams } from '@mastra/core/vector';
3
6
  import type { IndexStats } from '@mastra/core/vector';
4
7
  import { MastraVector } from '@mastra/core/vector';
8
+ import type { ParamsToArgs } from '@mastra/core/vector';
5
9
  import type { QueryResult } from '@mastra/core/vector';
6
10
  import type { QueryVectorParams } from '@mastra/core/vector';
11
+ import type { UpdateVectorParams } from '@mastra/core/vector';
7
12
  import type { UpsertVectorParams } from '@mastra/core/vector';
8
13
 
9
14
  declare type CouchbaseMetric = 'cosine' | 'l2_norm' | 'dot_product';
@@ -18,18 +23,60 @@ declare class CouchbaseVector extends MastraVector {
18
23
  private bucket;
19
24
  private scope;
20
25
  private vector_dimension;
21
- constructor(cnn_string: string, username: string, password: string, bucketName: string, scopeName: string, collectionName: string);
26
+ /**
27
+ * @deprecated Passing parameters as positional arguments is deprecated.
28
+ * Use the object parameter instead. This signature will be removed on May 20th, 2025.
29
+ */
30
+ constructor(connectionString: string, username: string, password: string, bucketName: string, scopeName: string, collectionName: string);
31
+ constructor(params: CouchbaseVectorParams);
22
32
  getCollection(): Promise<Collection>;
23
33
  createIndex(params: CreateIndexParams): Promise<void>;
24
34
  upsert(params: UpsertVectorParams): Promise<string[]>;
25
35
  query(params: QueryVectorParams): Promise<QueryResult[]>;
26
36
  listIndexes(): Promise<string[]>;
27
- describeIndex(indexName: string): Promise<IndexStats>;
28
- deleteIndex(indexName: string): Promise<void>;
37
+ /**
38
+ * Retrieves statistics about a vector index.
39
+ *
40
+ * @param params - The parameters for describing an index
41
+ * @param params.indexName - The name of the index to describe
42
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
43
+ */
44
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
45
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
46
+ /**
47
+ * Updates a vector by its ID with the provided vector and/or metadata.
48
+ * @param indexName - The name of the index containing the vector.
49
+ * @param id - The ID of the vector to update.
50
+ * @param update - An object containing the vector and/or metadata to update.
51
+ * @param update.vector - An optional array of numbers representing the new vector.
52
+ * @param update.metadata - An optional record containing the new metadata.
53
+ * @returns A promise that resolves when the update is complete.
54
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
55
+ */
56
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
57
+ /**
58
+ * Deletes a vector by its ID.
59
+ * @param indexName - The name of the index containing the vector.
60
+ * @param id - The ID of the vector to delete.
61
+ * @returns A promise that resolves when the deletion is complete.
62
+ * @throws Will throw an error if the deletion operation fails.
63
+ */
64
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
29
65
  }
30
66
  export { CouchbaseVector }
31
67
  export { CouchbaseVector as CouchbaseVector_alias_1 }
32
68
 
69
+ declare type CouchbaseVectorParams = {
70
+ connectionString: string;
71
+ username: string;
72
+ password: string;
73
+ bucketName: string;
74
+ scopeName: string;
75
+ collectionName: string;
76
+ };
77
+ export { CouchbaseVectorParams }
78
+ export { CouchbaseVectorParams as CouchbaseVectorParams_alias_1 }
79
+
33
80
  declare const DISTANCE_MAPPING: Record<MastraMetric, CouchbaseMetric>;
34
81
  export { DISTANCE_MAPPING }
35
82
  export { DISTANCE_MAPPING as DISTANCE_MAPPING_alias_1 }
@@ -1,9 +1,14 @@
1
1
  import type { Collection } from 'couchbase';
2
2
  import type { CreateIndexParams } from '@mastra/core/vector';
3
+ import type { DeleteIndexParams } from '@mastra/core/vector';
4
+ import type { DeleteVectorParams } from '@mastra/core/vector';
5
+ import type { DescribeIndexParams } from '@mastra/core/vector';
3
6
  import type { IndexStats } from '@mastra/core/vector';
4
7
  import { MastraVector } from '@mastra/core/vector';
8
+ import type { ParamsToArgs } from '@mastra/core/vector';
5
9
  import type { QueryResult } from '@mastra/core/vector';
6
10
  import type { QueryVectorParams } from '@mastra/core/vector';
11
+ import type { UpdateVectorParams } from '@mastra/core/vector';
7
12
  import type { UpsertVectorParams } from '@mastra/core/vector';
8
13
 
9
14
  declare type CouchbaseMetric = 'cosine' | 'l2_norm' | 'dot_product';
@@ -18,18 +23,60 @@ declare class CouchbaseVector extends MastraVector {
18
23
  private bucket;
19
24
  private scope;
20
25
  private vector_dimension;
21
- constructor(cnn_string: string, username: string, password: string, bucketName: string, scopeName: string, collectionName: string);
26
+ /**
27
+ * @deprecated Passing parameters as positional arguments is deprecated.
28
+ * Use the object parameter instead. This signature will be removed on May 20th, 2025.
29
+ */
30
+ constructor(connectionString: string, username: string, password: string, bucketName: string, scopeName: string, collectionName: string);
31
+ constructor(params: CouchbaseVectorParams);
22
32
  getCollection(): Promise<Collection>;
23
33
  createIndex(params: CreateIndexParams): Promise<void>;
24
34
  upsert(params: UpsertVectorParams): Promise<string[]>;
25
35
  query(params: QueryVectorParams): Promise<QueryResult[]>;
26
36
  listIndexes(): Promise<string[]>;
27
- describeIndex(indexName: string): Promise<IndexStats>;
28
- deleteIndex(indexName: string): Promise<void>;
37
+ /**
38
+ * Retrieves statistics about a vector index.
39
+ *
40
+ * @param params - The parameters for describing an index
41
+ * @param params.indexName - The name of the index to describe
42
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
43
+ */
44
+ describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats>;
45
+ deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
46
+ /**
47
+ * Updates a vector by its ID with the provided vector and/or metadata.
48
+ * @param indexName - The name of the index containing the vector.
49
+ * @param id - The ID of the vector to update.
50
+ * @param update - An object containing the vector and/or metadata to update.
51
+ * @param update.vector - An optional array of numbers representing the new vector.
52
+ * @param update.metadata - An optional record containing the new metadata.
53
+ * @returns A promise that resolves when the update is complete.
54
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
55
+ */
56
+ updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
57
+ /**
58
+ * Deletes a vector by its ID.
59
+ * @param indexName - The name of the index containing the vector.
60
+ * @param id - The ID of the vector to delete.
61
+ * @returns A promise that resolves when the deletion is complete.
62
+ * @throws Will throw an error if the deletion operation fails.
63
+ */
64
+ deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
29
65
  }
30
66
  export { CouchbaseVector }
31
67
  export { CouchbaseVector as CouchbaseVector_alias_1 }
32
68
 
69
+ declare type CouchbaseVectorParams = {
70
+ connectionString: string;
71
+ username: string;
72
+ password: string;
73
+ bucketName: string;
74
+ scopeName: string;
75
+ collectionName: string;
76
+ };
77
+ export { CouchbaseVectorParams }
78
+ export { CouchbaseVectorParams as CouchbaseVectorParams_alias_1 }
79
+
33
80
  declare const DISTANCE_MAPPING: Record<MastraMetric, CouchbaseMetric>;
34
81
  export { DISTANCE_MAPPING }
35
82
  export { DISTANCE_MAPPING as DISTANCE_MAPPING_alias_1 }
package/dist/index.cjs CHANGED
@@ -19,11 +19,32 @@ var CouchbaseVector = class extends vector.MastraVector {
19
19
  bucket;
20
20
  scope;
21
21
  vector_dimension;
22
- constructor(cnn_string, username, password, bucketName, scopeName, collectionName) {
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
44
  super();
24
- const baseClusterPromise = couchbase.connect(cnn_string, {
25
- username,
26
- password,
45
+ const baseClusterPromise = couchbase.connect(connectionString_, {
46
+ username: username_,
47
+ password: password_,
27
48
  configProfile: "wanDevelopment"
28
49
  });
29
50
  const telemetry = this.__getTelemetry();
@@ -34,9 +55,9 @@ var CouchbaseVector = class extends vector.MastraVector {
34
55
  }
35
56
  }) ?? baseClusterPromise;
36
57
  this.cluster = null;
37
- this.bucketName = bucketName;
38
- this.collectionName = collectionName;
39
- this.scopeName = scopeName;
58
+ this.bucketName = bucketName_;
59
+ this.collectionName = collectionName_;
60
+ this.scopeName = scopeName_;
40
61
  this.collection = null;
41
62
  this.bucket = null;
42
63
  this.scope = null;
@@ -59,86 +80,95 @@ var CouchbaseVector = class extends vector.MastraVector {
59
80
  if (!Number.isInteger(dimension) || dimension <= 0) {
60
81
  throw new Error("Dimension must be a positive integer");
61
82
  }
62
- await this.scope.searchIndexes().upsertIndex({
63
- name: indexName,
64
- sourceName: this.bucketName,
65
- type: "fulltext-index",
66
- params: {
67
- doc_config: {
68
- docid_prefix_delim: "",
69
- docid_regexp: "",
70
- mode: "scope.collection.type_field",
71
- type_field: "type"
72
- },
73
- mapping: {
74
- default_analyzer: "standard",
75
- default_datetime_parser: "dateTimeOptional",
76
- default_field: "_all",
77
- default_mapping: {
78
- dynamic: true,
79
- enabled: false
83
+ try {
84
+ await this.scope.searchIndexes().upsertIndex({
85
+ name: indexName,
86
+ sourceName: this.bucketName,
87
+ type: "fulltext-index",
88
+ params: {
89
+ doc_config: {
90
+ docid_prefix_delim: "",
91
+ docid_regexp: "",
92
+ mode: "scope.collection.type_field",
93
+ type_field: "type"
80
94
  },
81
- default_type: "_default",
82
- docvalues_dynamic: true,
83
- // [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
84
- index_dynamic: true,
85
- store_dynamic: true,
86
- // [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
87
- type_field: "_type",
88
- types: {
89
- [`${this.scopeName}.${this.collectionName}`]: {
95
+ mapping: {
96
+ default_analyzer: "standard",
97
+ default_datetime_parser: "dateTimeOptional",
98
+ default_field: "_all",
99
+ default_mapping: {
90
100
  dynamic: true,
91
- enabled: true,
92
- properties: {
93
- embedding: {
94
- enabled: true,
95
- fields: [
96
- {
97
- dims: dimension,
98
- index: true,
99
- name: "embedding",
100
- similarity: DISTANCE_MAPPING[metric],
101
- type: "vector",
102
- vector_index_optimized_for: "recall",
103
- store: true,
104
- // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
105
- docvalues: true,
106
- // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
107
- include_term_vectors: true
108
- // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
109
- }
110
- ]
111
- },
112
- content: {
113
- enabled: true,
114
- fields: [
115
- {
116
- index: true,
117
- name: "content",
118
- store: true,
119
- type: "text"
120
- }
121
- ]
101
+ enabled: false
102
+ },
103
+ default_type: "_default",
104
+ docvalues_dynamic: true,
105
+ // [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
106
+ index_dynamic: true,
107
+ store_dynamic: true,
108
+ // [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
109
+ type_field: "_type",
110
+ types: {
111
+ [`${this.scopeName}.${this.collectionName}`]: {
112
+ dynamic: true,
113
+ enabled: true,
114
+ properties: {
115
+ embedding: {
116
+ enabled: true,
117
+ fields: [
118
+ {
119
+ dims: dimension,
120
+ index: true,
121
+ name: "embedding",
122
+ similarity: DISTANCE_MAPPING[metric],
123
+ type: "vector",
124
+ vector_index_optimized_for: "recall",
125
+ store: true,
126
+ // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
127
+ docvalues: true,
128
+ // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
129
+ include_term_vectors: true
130
+ // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
131
+ }
132
+ ]
133
+ },
134
+ content: {
135
+ enabled: true,
136
+ fields: [
137
+ {
138
+ index: true,
139
+ name: "content",
140
+ store: true,
141
+ type: "text"
142
+ }
143
+ ]
144
+ }
122
145
  }
123
146
  }
124
147
  }
148
+ },
149
+ store: {
150
+ indexType: "scorch",
151
+ segmentVersion: 16
125
152
  }
126
153
  },
127
- store: {
128
- indexType: "scorch",
129
- segmentVersion: 16
154
+ sourceUuid: "",
155
+ sourceParams: {},
156
+ sourceType: "gocbcore",
157
+ planParams: {
158
+ maxPartitionsPerPIndex: 64,
159
+ indexPartitions: 16,
160
+ numReplicas: 0
130
161
  }
131
- },
132
- sourceUuid: "",
133
- sourceParams: {},
134
- sourceType: "gocbcore",
135
- planParams: {
136
- maxPartitionsPerPIndex: 64,
137
- indexPartitions: 16,
138
- numReplicas: 0
162
+ });
163
+ this.vector_dimension = dimension;
164
+ } catch (error) {
165
+ const message = error?.message || error?.toString();
166
+ if (message && message.toLowerCase().includes("index exists")) {
167
+ await this.validateExistingIndex(indexName, dimension, metric);
168
+ return;
139
169
  }
140
- });
141
- this.vector_dimension = dimension;
170
+ throw error;
171
+ }
142
172
  }
143
173
  async upsert(params) {
144
174
  const { vectors, metadata, ids } = params;
@@ -212,7 +242,16 @@ var CouchbaseVector = class extends vector.MastraVector {
212
242
  const indexes = await this.scope.searchIndexes().getAllIndexes();
213
243
  return indexes?.map((index) => index.name) || [];
214
244
  }
215
- async describeIndex(indexName) {
245
+ /**
246
+ * Retrieves statistics about a vector index.
247
+ *
248
+ * @param params - The parameters for describing an index
249
+ * @param params.indexName - The name of the index to describe
250
+ * @returns A promise that resolves to the index statistics including dimension, count and metric
251
+ */
252
+ async describeIndex(...args) {
253
+ const params = this.normalizeArgs("describeIndex", args);
254
+ const { indexName } = params;
216
255
  await this.getCollection();
217
256
  if (!(await this.listIndexes()).includes(indexName)) {
218
257
  throw new Error(`Index ${indexName} does not exist`);
@@ -229,7 +268,9 @@ var CouchbaseVector = class extends vector.MastraVector {
229
268
  )
230
269
  };
231
270
  }
232
- async deleteIndex(indexName) {
271
+ async deleteIndex(...args) {
272
+ const params = this.normalizeArgs("deleteIndex", args);
273
+ const { indexName } = params;
233
274
  await this.getCollection();
234
275
  if (!(await this.listIndexes()).includes(indexName)) {
235
276
  throw new Error(`Index ${indexName} does not exist`);
@@ -237,6 +278,60 @@ var CouchbaseVector = class extends vector.MastraVector {
237
278
  await this.scope.searchIndexes().dropIndex(indexName);
238
279
  this.vector_dimension = null;
239
280
  }
281
+ /**
282
+ * Updates a vector by its ID with the provided vector and/or metadata.
283
+ * @param indexName - The name of the index containing the vector.
284
+ * @param id - The ID of the vector to update.
285
+ * @param update - An object containing the vector and/or metadata to update.
286
+ * @param update.vector - An optional array of numbers representing the new vector.
287
+ * @param update.metadata - An optional record containing the new metadata.
288
+ * @returns A promise that resolves when the update is complete.
289
+ * @throws Will throw an error if no updates are provided or if the update operation fails.
290
+ */
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();
301
+ 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`);
306
+ }
307
+ throw err;
308
+ }
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
+ }
314
+ /**
315
+ * Deletes a vector by its ID.
316
+ * @param indexName - The name of the index containing the vector.
317
+ * @param id - The ID of the vector to delete.
318
+ * @returns A promise that resolves when the deletion is complete.
319
+ * @throws Will throw an error if the deletion operation fails.
320
+ */
321
+ async deleteVector(...args) {
322
+ const params = this.normalizeArgs("deleteVector", args);
323
+ const { id } = params;
324
+ const collection = await this.getCollection();
325
+ 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`);
330
+ }
331
+ throw err;
332
+ }
333
+ await collection.remove(id);
334
+ }
240
335
  };
241
336
 
242
337
  exports.CouchbaseVector = CouchbaseVector;
package/dist/index.d.cts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { DISTANCE_MAPPING } from './_tsup-dts-rollup.cjs';
2
+ export { CouchbaseVectorParams } from './_tsup-dts-rollup.cjs';
2
3
  export { CouchbaseVector } from './_tsup-dts-rollup.cjs';
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { DISTANCE_MAPPING } from './_tsup-dts-rollup.js';
2
+ export { CouchbaseVectorParams } from './_tsup-dts-rollup.js';
2
3
  export { CouchbaseVector } from './_tsup-dts-rollup.js';