@mastra/couchbase 0.0.4 → 0.0.5-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 +14 -0
- package/dist/_tsup-dts-rollup.d.cts +33 -8
- package/dist/_tsup-dts-rollup.d.ts +33 -8
- package/dist/index.cjs +53 -14
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +53 -14
- package/docker-compose.yaml +12 -12
- package/package.json +2 -2
- package/src/vector/index.integration.test.ts +24 -22
- package/src/vector/index.ts +94 -18
- package/src/vector/index.unit.test.ts +54 -54
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/couchbase@0.0.
|
|
2
|
+
> @mastra/couchbase@0.0.5-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.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 6132ms
|
|
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 8893ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m12.31 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 502ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m12.37 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 503ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @mastra/couchbase
|
|
2
2
|
|
|
3
|
+
## 0.0.5-alpha.0
|
|
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 [90be034]
|
|
11
|
+
- Updated dependencies [99f050a]
|
|
12
|
+
- Updated dependencies [d0ee3c6]
|
|
13
|
+
- Updated dependencies [23f258c]
|
|
14
|
+
- Updated dependencies [2672a05]
|
|
15
|
+
- @mastra/core@0.9.5-alpha.0
|
|
16
|
+
|
|
3
17
|
## 0.0.4
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -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,14 +23,26 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
18
23
|
private bucket;
|
|
19
24
|
private scope;
|
|
20
25
|
private vector_dimension;
|
|
21
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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>;
|
|
29
46
|
/**
|
|
30
47
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
31
48
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -36,10 +53,7 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
36
53
|
* @returns A promise that resolves when the update is complete.
|
|
37
54
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
38
55
|
*/
|
|
39
|
-
updateVector(
|
|
40
|
-
vector?: number[];
|
|
41
|
-
metadata?: Record<string, any>;
|
|
42
|
-
}): Promise<void>;
|
|
56
|
+
updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
|
|
43
57
|
/**
|
|
44
58
|
* Deletes a vector by its ID.
|
|
45
59
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -47,11 +61,22 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
47
61
|
* @returns A promise that resolves when the deletion is complete.
|
|
48
62
|
* @throws Will throw an error if the deletion operation fails.
|
|
49
63
|
*/
|
|
50
|
-
deleteVector(
|
|
64
|
+
deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
|
|
51
65
|
}
|
|
52
66
|
export { CouchbaseVector }
|
|
53
67
|
export { CouchbaseVector as CouchbaseVector_alias_1 }
|
|
54
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
|
+
|
|
55
80
|
declare const DISTANCE_MAPPING: Record<MastraMetric, CouchbaseMetric>;
|
|
56
81
|
export { DISTANCE_MAPPING }
|
|
57
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,14 +23,26 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
18
23
|
private bucket;
|
|
19
24
|
private scope;
|
|
20
25
|
private vector_dimension;
|
|
21
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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>;
|
|
29
46
|
/**
|
|
30
47
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
31
48
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -36,10 +53,7 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
36
53
|
* @returns A promise that resolves when the update is complete.
|
|
37
54
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
38
55
|
*/
|
|
39
|
-
updateVector(
|
|
40
|
-
vector?: number[];
|
|
41
|
-
metadata?: Record<string, any>;
|
|
42
|
-
}): Promise<void>;
|
|
56
|
+
updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
|
|
43
57
|
/**
|
|
44
58
|
* Deletes a vector by its ID.
|
|
45
59
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -47,11 +61,22 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
47
61
|
* @returns A promise that resolves when the deletion is complete.
|
|
48
62
|
* @throws Will throw an error if the deletion operation fails.
|
|
49
63
|
*/
|
|
50
|
-
deleteVector(
|
|
64
|
+
deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
|
|
51
65
|
}
|
|
52
66
|
export { CouchbaseVector }
|
|
53
67
|
export { CouchbaseVector as CouchbaseVector_alias_1 }
|
|
54
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
|
+
|
|
55
80
|
declare const DISTANCE_MAPPING: Record<MastraMetric, CouchbaseMetric>;
|
|
56
81
|
export { DISTANCE_MAPPING }
|
|
57
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(
|
|
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(
|
|
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 =
|
|
38
|
-
this.collectionName =
|
|
39
|
-
this.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;
|
|
@@ -221,7 +242,16 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
221
242
|
const indexes = await this.scope.searchIndexes().getAllIndexes();
|
|
222
243
|
return indexes?.map((index) => index.name) || [];
|
|
223
244
|
}
|
|
224
|
-
|
|
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;
|
|
225
255
|
await this.getCollection();
|
|
226
256
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
227
257
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -238,7 +268,9 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
238
268
|
)
|
|
239
269
|
};
|
|
240
270
|
}
|
|
241
|
-
async deleteIndex(
|
|
271
|
+
async deleteIndex(...args) {
|
|
272
|
+
const params = this.normalizeArgs("deleteIndex", args);
|
|
273
|
+
const { indexName } = params;
|
|
242
274
|
await this.getCollection();
|
|
243
275
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
244
276
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -256,10 +288,15 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
256
288
|
* @returns A promise that resolves when the update is complete.
|
|
257
289
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
258
290
|
*/
|
|
259
|
-
async updateVector(
|
|
260
|
-
|
|
291
|
+
async updateVector(...args) {
|
|
292
|
+
const params = this.normalizeArgs("updateVector", args);
|
|
293
|
+
const { id, update } = params;
|
|
294
|
+
if (!update.vector && !update.metadata) {
|
|
261
295
|
throw new Error("No updates provided");
|
|
262
296
|
}
|
|
297
|
+
if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {
|
|
298
|
+
throw new Error("Vector dimension mismatch");
|
|
299
|
+
}
|
|
263
300
|
const collection = await this.getCollection();
|
|
264
301
|
try {
|
|
265
302
|
await collection.get(id);
|
|
@@ -270,8 +307,8 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
270
307
|
throw err;
|
|
271
308
|
}
|
|
272
309
|
const specs = [];
|
|
273
|
-
if (
|
|
274
|
-
if (
|
|
310
|
+
if (update.vector) specs.push(couchbase.MutateInSpec.replace("embedding", update.vector));
|
|
311
|
+
if (update.metadata) specs.push(couchbase.MutateInSpec.replace("metadata", update.metadata));
|
|
275
312
|
await collection.mutateIn(id, specs);
|
|
276
313
|
}
|
|
277
314
|
/**
|
|
@@ -281,7 +318,9 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
281
318
|
* @returns A promise that resolves when the deletion is complete.
|
|
282
319
|
* @throws Will throw an error if the deletion operation fails.
|
|
283
320
|
*/
|
|
284
|
-
async deleteVector(
|
|
321
|
+
async deleteVector(...args) {
|
|
322
|
+
const params = this.normalizeArgs("deleteVector", args);
|
|
323
|
+
const { id } = params;
|
|
285
324
|
const collection = await this.getCollection();
|
|
286
325
|
try {
|
|
287
326
|
await collection.get(id);
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,11 +17,32 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
17
17
|
bucket;
|
|
18
18
|
scope;
|
|
19
19
|
vector_dimension;
|
|
20
|
-
constructor(
|
|
20
|
+
constructor(paramsOrConnectionString, username, password, bucketName, scopeName, collectionName) {
|
|
21
|
+
let connectionString_, username_, password_, bucketName_, scopeName_, collectionName_;
|
|
22
|
+
if (typeof paramsOrConnectionString === "object" && paramsOrConnectionString !== null && "connectionString" in paramsOrConnectionString) {
|
|
23
|
+
connectionString_ = paramsOrConnectionString.connectionString;
|
|
24
|
+
username_ = paramsOrConnectionString.username;
|
|
25
|
+
password_ = paramsOrConnectionString.password;
|
|
26
|
+
bucketName_ = paramsOrConnectionString.bucketName;
|
|
27
|
+
scopeName_ = paramsOrConnectionString.scopeName;
|
|
28
|
+
collectionName_ = paramsOrConnectionString.collectionName;
|
|
29
|
+
} else {
|
|
30
|
+
if (arguments.length > 1) {
|
|
31
|
+
console.warn(
|
|
32
|
+
"Deprecation Warning: CouchbaseVector constructor positional arguments are deprecated. Please use a single object parameter instead. This signature will be removed on May 20th, 2025."
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
connectionString_ = paramsOrConnectionString;
|
|
36
|
+
username_ = username;
|
|
37
|
+
password_ = password;
|
|
38
|
+
bucketName_ = bucketName;
|
|
39
|
+
scopeName_ = scopeName;
|
|
40
|
+
collectionName_ = collectionName;
|
|
41
|
+
}
|
|
21
42
|
super();
|
|
22
|
-
const baseClusterPromise = connect(
|
|
23
|
-
username,
|
|
24
|
-
password,
|
|
43
|
+
const baseClusterPromise = connect(connectionString_, {
|
|
44
|
+
username: username_,
|
|
45
|
+
password: password_,
|
|
25
46
|
configProfile: "wanDevelopment"
|
|
26
47
|
});
|
|
27
48
|
const telemetry = this.__getTelemetry();
|
|
@@ -32,9 +53,9 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
32
53
|
}
|
|
33
54
|
}) ?? baseClusterPromise;
|
|
34
55
|
this.cluster = null;
|
|
35
|
-
this.bucketName =
|
|
36
|
-
this.collectionName =
|
|
37
|
-
this.scopeName =
|
|
56
|
+
this.bucketName = bucketName_;
|
|
57
|
+
this.collectionName = collectionName_;
|
|
58
|
+
this.scopeName = scopeName_;
|
|
38
59
|
this.collection = null;
|
|
39
60
|
this.bucket = null;
|
|
40
61
|
this.scope = null;
|
|
@@ -219,7 +240,16 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
219
240
|
const indexes = await this.scope.searchIndexes().getAllIndexes();
|
|
220
241
|
return indexes?.map((index) => index.name) || [];
|
|
221
242
|
}
|
|
222
|
-
|
|
243
|
+
/**
|
|
244
|
+
* Retrieves statistics about a vector index.
|
|
245
|
+
*
|
|
246
|
+
* @param params - The parameters for describing an index
|
|
247
|
+
* @param params.indexName - The name of the index to describe
|
|
248
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
249
|
+
*/
|
|
250
|
+
async describeIndex(...args) {
|
|
251
|
+
const params = this.normalizeArgs("describeIndex", args);
|
|
252
|
+
const { indexName } = params;
|
|
223
253
|
await this.getCollection();
|
|
224
254
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
225
255
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -236,7 +266,9 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
236
266
|
)
|
|
237
267
|
};
|
|
238
268
|
}
|
|
239
|
-
async deleteIndex(
|
|
269
|
+
async deleteIndex(...args) {
|
|
270
|
+
const params = this.normalizeArgs("deleteIndex", args);
|
|
271
|
+
const { indexName } = params;
|
|
240
272
|
await this.getCollection();
|
|
241
273
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
242
274
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -254,10 +286,15 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
254
286
|
* @returns A promise that resolves when the update is complete.
|
|
255
287
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
256
288
|
*/
|
|
257
|
-
async updateVector(
|
|
258
|
-
|
|
289
|
+
async updateVector(...args) {
|
|
290
|
+
const params = this.normalizeArgs("updateVector", args);
|
|
291
|
+
const { id, update } = params;
|
|
292
|
+
if (!update.vector && !update.metadata) {
|
|
259
293
|
throw new Error("No updates provided");
|
|
260
294
|
}
|
|
295
|
+
if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {
|
|
296
|
+
throw new Error("Vector dimension mismatch");
|
|
297
|
+
}
|
|
261
298
|
const collection = await this.getCollection();
|
|
262
299
|
try {
|
|
263
300
|
await collection.get(id);
|
|
@@ -268,8 +305,8 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
268
305
|
throw err;
|
|
269
306
|
}
|
|
270
307
|
const specs = [];
|
|
271
|
-
if (
|
|
272
|
-
if (
|
|
308
|
+
if (update.vector) specs.push(MutateInSpec.replace("embedding", update.vector));
|
|
309
|
+
if (update.metadata) specs.push(MutateInSpec.replace("metadata", update.metadata));
|
|
273
310
|
await collection.mutateIn(id, specs);
|
|
274
311
|
}
|
|
275
312
|
/**
|
|
@@ -279,7 +316,9 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
279
316
|
* @returns A promise that resolves when the deletion is complete.
|
|
280
317
|
* @throws Will throw an error if the deletion operation fails.
|
|
281
318
|
*/
|
|
282
|
-
async deleteVector(
|
|
319
|
+
async deleteVector(...args) {
|
|
320
|
+
const params = this.normalizeArgs("deleteVector", args);
|
|
321
|
+
const { id } = params;
|
|
283
322
|
const collection = await this.getCollection();
|
|
284
323
|
try {
|
|
285
324
|
await collection.get(id);
|
package/docker-compose.yaml
CHANGED
|
@@ -2,20 +2,20 @@ services:
|
|
|
2
2
|
mastra_couchbase_testing:
|
|
3
3
|
image: couchbase:enterprise-7.6.4
|
|
4
4
|
ports:
|
|
5
|
-
-
|
|
6
|
-
-
|
|
7
|
-
-
|
|
5
|
+
- '8091-8095:8091-8095'
|
|
6
|
+
- '11210:11210'
|
|
7
|
+
- '9102:9102'
|
|
8
8
|
expose:
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
9
|
+
- '8091'
|
|
10
|
+
- '8092'
|
|
11
|
+
- '8093'
|
|
12
|
+
- '8094'
|
|
13
|
+
- '8095'
|
|
14
|
+
- '9102'
|
|
15
|
+
- '11210'
|
|
16
16
|
healthcheck: # checks couchbase server is up
|
|
17
|
-
test: [
|
|
17
|
+
test: ['CMD', 'curl', '-v', 'http://localhost:8091/pools']
|
|
18
18
|
interval: 20s
|
|
19
19
|
timeout: 20s
|
|
20
20
|
retries: 5
|
|
21
|
-
container_name: mastra_couchbase_testing
|
|
21
|
+
container_name: mastra_couchbase_testing
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/couchbase",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5-alpha.0",
|
|
4
4
|
"description": "Couchbase vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"couchbase": "^4.4.5",
|
|
23
|
-
"@mastra/core": "^0.9.
|
|
23
|
+
"@mastra/core": "^0.9.5-alpha.0"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@microsoft/api-extractor": "^7.52.1",
|
|
@@ -173,14 +173,14 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
173
173
|
|
|
174
174
|
describe('Connection', () => {
|
|
175
175
|
it('should connect to couchbase', async () => {
|
|
176
|
-
couchbase_client = new CouchbaseVector(
|
|
176
|
+
couchbase_client = new CouchbaseVector({
|
|
177
177
|
connectionString,
|
|
178
178
|
username,
|
|
179
179
|
password,
|
|
180
|
-
test_bucketName,
|
|
181
|
-
test_scopeName,
|
|
182
|
-
test_collectionName,
|
|
183
|
-
);
|
|
180
|
+
bucketName: test_bucketName,
|
|
181
|
+
scopeName: test_scopeName,
|
|
182
|
+
collectionName: test_collectionName,
|
|
183
|
+
});
|
|
184
184
|
expect(couchbase_client).toBeDefined();
|
|
185
185
|
const collection = await couchbase_client.getCollection();
|
|
186
186
|
expect(collection).toBeDefined();
|
|
@@ -211,14 +211,14 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
211
211
|
}, 50000);
|
|
212
212
|
|
|
213
213
|
it('should describe index', async () => {
|
|
214
|
-
const stats = await couchbase_client.describeIndex(test_indexName);
|
|
214
|
+
const stats = await couchbase_client.describeIndex({ indexName: test_indexName });
|
|
215
215
|
expect(stats.dimension).toBe(dimension);
|
|
216
216
|
expect(stats.metric).toBe('euclidean'); // similiarity(=="l2_norm") is mapped to euclidean in couchbase
|
|
217
217
|
expect(typeof stats.count).toBe('number');
|
|
218
218
|
}, 50000);
|
|
219
219
|
|
|
220
220
|
it('should delete index', async () => {
|
|
221
|
-
await couchbase_client.deleteIndex(test_indexName);
|
|
221
|
+
await couchbase_client.deleteIndex({ indexName: test_indexName });
|
|
222
222
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
223
223
|
await expect(scope.searchIndexes().getIndex(test_indexName)).rejects.toThrowError();
|
|
224
224
|
}, 50000);
|
|
@@ -246,7 +246,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
246
246
|
}, 50000);
|
|
247
247
|
|
|
248
248
|
afterAll(async () => {
|
|
249
|
-
await couchbase_client.deleteIndex(test_indexName);
|
|
249
|
+
await couchbase_client.deleteIndex({ indexName: test_indexName });
|
|
250
250
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
251
251
|
}, 50000);
|
|
252
252
|
|
|
@@ -387,7 +387,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
387
387
|
ids.forEach(id => expect(typeof id).toBe('string'));
|
|
388
388
|
|
|
389
389
|
// Count is not supported by Couchbase
|
|
390
|
-
const stats = await couchbase_client.describeIndex(test_indexName);
|
|
390
|
+
const stats = await couchbase_client.describeIndex({ indexName: test_indexName });
|
|
391
391
|
expect(stats.count).toBe(-1);
|
|
392
392
|
});
|
|
393
393
|
|
|
@@ -431,7 +431,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
431
431
|
metadata: newMetaData,
|
|
432
432
|
};
|
|
433
433
|
|
|
434
|
-
await couchbase_client.updateVector(test_indexName, idToBeUpdated, update);
|
|
434
|
+
await couchbase_client.updateVector({ indexName: test_indexName, id: idToBeUpdated, update });
|
|
435
435
|
|
|
436
436
|
const result = await collection.get(idToBeUpdated);
|
|
437
437
|
expect(result.content.embedding).toEqual(newVector);
|
|
@@ -451,7 +451,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
451
451
|
metadata: newMetaData,
|
|
452
452
|
};
|
|
453
453
|
|
|
454
|
-
await couchbase_client.updateVector(test_indexName, idToBeUpdated, update);
|
|
454
|
+
await couchbase_client.updateVector({ indexName: test_indexName, id: idToBeUpdated, update });
|
|
455
455
|
|
|
456
456
|
const result = await collection.get(idToBeUpdated);
|
|
457
457
|
expect(result.content.embedding).toEqual(testVectors[0]);
|
|
@@ -469,14 +469,16 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
469
469
|
vector: newVector,
|
|
470
470
|
};
|
|
471
471
|
|
|
472
|
-
await couchbase_client.updateVector(test_indexName, idToBeUpdated, update);
|
|
472
|
+
await couchbase_client.updateVector({ indexName: test_indexName, id: idToBeUpdated, update });
|
|
473
473
|
|
|
474
474
|
const result = await collection.get(idToBeUpdated);
|
|
475
475
|
expect(result.content.embedding).toEqual(newVector);
|
|
476
476
|
});
|
|
477
477
|
|
|
478
478
|
it('should throw exception when no updates are given', async () => {
|
|
479
|
-
await expect(couchbase_client.updateVector(test_indexName, 'id', {})).rejects.toThrow(
|
|
479
|
+
await expect(couchbase_client.updateVector({ indexName: test_indexName, id: 'id', update: {} })).rejects.toThrow(
|
|
480
|
+
'No updates provided',
|
|
481
|
+
);
|
|
480
482
|
});
|
|
481
483
|
|
|
482
484
|
it('should delete the vector by id', async () => {
|
|
@@ -484,7 +486,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
484
486
|
expect(ids).toHaveLength(3);
|
|
485
487
|
const idToBeDeleted = ids[0];
|
|
486
488
|
|
|
487
|
-
await couchbase_client.deleteVector(test_indexName, idToBeDeleted);
|
|
489
|
+
await couchbase_client.deleteVector({ indexName: test_indexName, id: idToBeDeleted });
|
|
488
490
|
|
|
489
491
|
try {
|
|
490
492
|
await collection.get(idToBeDeleted);
|
|
@@ -521,7 +523,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
521
523
|
expect(allIndexes.find(idx => idx.name === nonExistentIndex)).toBeUndefined();
|
|
522
524
|
|
|
523
525
|
// Now test the couchbase_client method
|
|
524
|
-
await expect(couchbase_client.describeIndex(nonExistentIndex)).rejects.toThrow();
|
|
526
|
+
await expect(couchbase_client.describeIndex({ indexName: nonExistentIndex })).rejects.toThrow();
|
|
525
527
|
}, 50000);
|
|
526
528
|
|
|
527
529
|
it('should throw error when deleting a non-existent index', async () => {
|
|
@@ -532,7 +534,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
532
534
|
expect(allIndexes.find(idx => idx.name === nonExistentIndex)).toBeUndefined();
|
|
533
535
|
|
|
534
536
|
// Now test the couchbase_client method
|
|
535
|
-
await expect(couchbase_client.deleteIndex(nonExistentIndex)).rejects.toThrow();
|
|
537
|
+
await expect(couchbase_client.deleteIndex({ indexName: nonExistentIndex })).rejects.toThrow();
|
|
536
538
|
}, 50000);
|
|
537
539
|
|
|
538
540
|
it('should throw error for empty vectors array in upsert', async () => {
|
|
@@ -601,7 +603,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
601
603
|
infoSpy.mockRestore();
|
|
602
604
|
warnSpy.mockRestore();
|
|
603
605
|
// Cleanup
|
|
604
|
-
await couchbase_client.deleteIndex(duplicateIndexName);
|
|
606
|
+
await couchbase_client.deleteIndex({ indexName: duplicateIndexName });
|
|
605
607
|
}
|
|
606
608
|
}, 50000);
|
|
607
609
|
});
|
|
@@ -611,7 +613,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
611
613
|
const indexes = await couchbase_client.listIndexes();
|
|
612
614
|
if (indexes.length > 0) {
|
|
613
615
|
for (const index of indexes) {
|
|
614
|
-
await couchbase_client.deleteIndex(index);
|
|
616
|
+
await couchbase_client.deleteIndex({ indexName: index });
|
|
615
617
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
616
618
|
}
|
|
617
619
|
}
|
|
@@ -674,7 +676,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
674
676
|
expect((couchbase_client as any).vector_dimension).toBe(testDimension);
|
|
675
677
|
|
|
676
678
|
// Delete the index
|
|
677
|
-
await couchbase_client.deleteIndex(testIndexName);
|
|
679
|
+
await couchbase_client.deleteIndex({ indexName: testIndexName });
|
|
678
680
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
679
681
|
|
|
680
682
|
// Verify dimension is reset
|
|
@@ -690,7 +692,7 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
690
692
|
const indexes = await couchbase_client.listIndexes();
|
|
691
693
|
if (indexes.length > 0) {
|
|
692
694
|
for (const index of indexes) {
|
|
693
|
-
await couchbase_client.deleteIndex(index);
|
|
695
|
+
await couchbase_client.deleteIndex({ indexName: index });
|
|
694
696
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
695
697
|
}
|
|
696
698
|
}
|
|
@@ -719,11 +721,11 @@ describe('Integration Testing CouchbaseVector', async () => {
|
|
|
719
721
|
expect(similarityParam).toBe(couchbaseMetric);
|
|
720
722
|
|
|
721
723
|
// Verify through our API
|
|
722
|
-
const stats = await couchbase_client.describeIndex(testIndexName);
|
|
724
|
+
const stats = await couchbase_client.describeIndex({ indexName: testIndexName });
|
|
723
725
|
expect(stats.metric).toBe(mastraMetric);
|
|
724
726
|
|
|
725
727
|
// Clean up
|
|
726
|
-
await couchbase_client.deleteIndex(testIndexName);
|
|
728
|
+
await couchbase_client.deleteIndex({ indexName: testIndexName });
|
|
727
729
|
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
728
730
|
}
|
|
729
731
|
}, 50000);
|
package/src/vector/index.ts
CHANGED
|
@@ -5,6 +5,11 @@ import type {
|
|
|
5
5
|
CreateIndexParams,
|
|
6
6
|
UpsertVectorParams,
|
|
7
7
|
QueryVectorParams,
|
|
8
|
+
DescribeIndexParams,
|
|
9
|
+
ParamsToArgs,
|
|
10
|
+
DeleteIndexParams,
|
|
11
|
+
DeleteVectorParams,
|
|
12
|
+
UpdateVectorParams,
|
|
8
13
|
} from '@mastra/core/vector';
|
|
9
14
|
import type { Bucket, Cluster, Collection, Scope } from 'couchbase';
|
|
10
15
|
import { MutateInSpec, connect, SearchRequest, VectorQuery, VectorSearch } from 'couchbase';
|
|
@@ -17,6 +22,15 @@ export const DISTANCE_MAPPING: Record<MastraMetric, CouchbaseMetric> = {
|
|
|
17
22
|
dotproduct: 'dot_product',
|
|
18
23
|
};
|
|
19
24
|
|
|
25
|
+
export type CouchbaseVectorParams = {
|
|
26
|
+
connectionString: string;
|
|
27
|
+
username: string;
|
|
28
|
+
password: string;
|
|
29
|
+
bucketName: string;
|
|
30
|
+
scopeName: string;
|
|
31
|
+
collectionName: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
20
34
|
export class CouchbaseVector extends MastraVector {
|
|
21
35
|
private clusterPromise: Promise<Cluster>;
|
|
22
36
|
private cluster: Cluster;
|
|
@@ -28,19 +42,66 @@ export class CouchbaseVector extends MastraVector {
|
|
|
28
42
|
private scope: Scope;
|
|
29
43
|
private vector_dimension: number;
|
|
30
44
|
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Passing parameters as positional arguments is deprecated.
|
|
47
|
+
* Use the object parameter instead. This signature will be removed on May 20th, 2025.
|
|
48
|
+
*/
|
|
31
49
|
constructor(
|
|
32
|
-
|
|
50
|
+
connectionString: string,
|
|
33
51
|
username: string,
|
|
34
52
|
password: string,
|
|
35
53
|
bucketName: string,
|
|
36
54
|
scopeName: string,
|
|
37
55
|
collectionName: string,
|
|
56
|
+
);
|
|
57
|
+
constructor(params: CouchbaseVectorParams);
|
|
58
|
+
constructor(
|
|
59
|
+
paramsOrConnectionString: CouchbaseVectorParams | string,
|
|
60
|
+
username?: string,
|
|
61
|
+
password?: string,
|
|
62
|
+
bucketName?: string,
|
|
63
|
+
scopeName?: string,
|
|
64
|
+
collectionName?: string,
|
|
38
65
|
) {
|
|
66
|
+
let connectionString_: string,
|
|
67
|
+
username_: string,
|
|
68
|
+
password_: string,
|
|
69
|
+
bucketName_: string,
|
|
70
|
+
scopeName_: string,
|
|
71
|
+
collectionName_: string;
|
|
72
|
+
|
|
73
|
+
if (
|
|
74
|
+
typeof paramsOrConnectionString === 'object' &&
|
|
75
|
+
paramsOrConnectionString !== null &&
|
|
76
|
+
'connectionString' in paramsOrConnectionString
|
|
77
|
+
) {
|
|
78
|
+
// Object params (preferred)
|
|
79
|
+
connectionString_ = paramsOrConnectionString.connectionString as string;
|
|
80
|
+
username_ = paramsOrConnectionString.username;
|
|
81
|
+
password_ = paramsOrConnectionString.password;
|
|
82
|
+
bucketName_ = paramsOrConnectionString.bucketName;
|
|
83
|
+
scopeName_ = paramsOrConnectionString.scopeName;
|
|
84
|
+
collectionName_ = paramsOrConnectionString.collectionName;
|
|
85
|
+
} else {
|
|
86
|
+
// Positional args (deprecated)
|
|
87
|
+
if (arguments.length > 1) {
|
|
88
|
+
console.warn(
|
|
89
|
+
'Deprecation Warning: CouchbaseVector constructor positional arguments are deprecated. Please use a single object parameter instead. This signature will be removed on May 20th, 2025.',
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
connectionString_ = paramsOrConnectionString as string;
|
|
93
|
+
username_ = username!;
|
|
94
|
+
password_ = password!;
|
|
95
|
+
bucketName_ = bucketName!;
|
|
96
|
+
scopeName_ = scopeName!;
|
|
97
|
+
collectionName_ = collectionName!;
|
|
98
|
+
}
|
|
99
|
+
|
|
39
100
|
super();
|
|
40
101
|
|
|
41
|
-
const baseClusterPromise = connect(
|
|
42
|
-
username,
|
|
43
|
-
password,
|
|
102
|
+
const baseClusterPromise = connect(connectionString_, {
|
|
103
|
+
username: username_,
|
|
104
|
+
password: password_,
|
|
44
105
|
configProfile: 'wanDevelopment',
|
|
45
106
|
});
|
|
46
107
|
|
|
@@ -53,9 +114,9 @@ export class CouchbaseVector extends MastraVector {
|
|
|
53
114
|
},
|
|
54
115
|
}) ?? baseClusterPromise;
|
|
55
116
|
this.cluster = null as unknown as Cluster;
|
|
56
|
-
this.bucketName =
|
|
57
|
-
this.collectionName =
|
|
58
|
-
this.scopeName =
|
|
117
|
+
this.bucketName = bucketName_;
|
|
118
|
+
this.collectionName = collectionName_;
|
|
119
|
+
this.scopeName = scopeName_;
|
|
59
120
|
this.collection = null as unknown as Collection;
|
|
60
121
|
this.bucket = null as unknown as Bucket;
|
|
61
122
|
this.scope = null as unknown as Scope;
|
|
@@ -255,7 +316,16 @@ export class CouchbaseVector extends MastraVector {
|
|
|
255
316
|
return indexes?.map(index => index.name) || [];
|
|
256
317
|
}
|
|
257
318
|
|
|
258
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Retrieves statistics about a vector index.
|
|
321
|
+
*
|
|
322
|
+
* @param params - The parameters for describing an index
|
|
323
|
+
* @param params.indexName - The name of the index to describe
|
|
324
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
325
|
+
*/
|
|
326
|
+
async describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<IndexStats> {
|
|
327
|
+
const params = this.normalizeArgs<DescribeIndexParams>('describeIndex', args);
|
|
328
|
+
const { indexName } = params;
|
|
259
329
|
await this.getCollection();
|
|
260
330
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
261
331
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -276,7 +346,9 @@ export class CouchbaseVector extends MastraVector {
|
|
|
276
346
|
};
|
|
277
347
|
}
|
|
278
348
|
|
|
279
|
-
async deleteIndex(
|
|
349
|
+
async deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void> {
|
|
350
|
+
const params = this.normalizeArgs<DeleteIndexParams>('deleteIndex', args);
|
|
351
|
+
const { indexName } = params;
|
|
280
352
|
await this.getCollection();
|
|
281
353
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
282
354
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -295,14 +367,15 @@ export class CouchbaseVector extends MastraVector {
|
|
|
295
367
|
* @returns A promise that resolves when the update is complete.
|
|
296
368
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
297
369
|
*/
|
|
298
|
-
async updateVector(
|
|
299
|
-
|
|
300
|
-
id
|
|
301
|
-
|
|
302
|
-
): Promise<void> {
|
|
303
|
-
if (!updates.vector && !updates.metadata) {
|
|
370
|
+
async updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void> {
|
|
371
|
+
const params = this.normalizeArgs<UpdateVectorParams>('updateVector', args);
|
|
372
|
+
const { id, update } = params;
|
|
373
|
+
if (!update.vector && !update.metadata) {
|
|
304
374
|
throw new Error('No updates provided');
|
|
305
375
|
}
|
|
376
|
+
if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {
|
|
377
|
+
throw new Error('Vector dimension mismatch');
|
|
378
|
+
}
|
|
306
379
|
const collection = await this.getCollection();
|
|
307
380
|
|
|
308
381
|
// Check if document exists
|
|
@@ -316,8 +389,8 @@ export class CouchbaseVector extends MastraVector {
|
|
|
316
389
|
}
|
|
317
390
|
|
|
318
391
|
const specs: MutateInSpec[] = [];
|
|
319
|
-
if (
|
|
320
|
-
if (
|
|
392
|
+
if (update.vector) specs.push(MutateInSpec.replace('embedding', update.vector));
|
|
393
|
+
if (update.metadata) specs.push(MutateInSpec.replace('metadata', update.metadata));
|
|
321
394
|
|
|
322
395
|
await collection.mutateIn(id, specs);
|
|
323
396
|
}
|
|
@@ -329,7 +402,10 @@ export class CouchbaseVector extends MastraVector {
|
|
|
329
402
|
* @returns A promise that resolves when the deletion is complete.
|
|
330
403
|
* @throws Will throw an error if the deletion operation fails.
|
|
331
404
|
*/
|
|
332
|
-
async deleteVector(
|
|
405
|
+
async deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void> {
|
|
406
|
+
const params = this.normalizeArgs<DeleteVectorParams>('deleteVector', args);
|
|
407
|
+
|
|
408
|
+
const { id } = params;
|
|
333
409
|
const collection = await this.getCollection();
|
|
334
410
|
|
|
335
411
|
// Check if document exists
|
|
@@ -165,14 +165,14 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
165
165
|
});
|
|
166
166
|
|
|
167
167
|
it('should connect to couchbase', async () => {
|
|
168
|
-
couchbase_client = new CouchbaseVector(
|
|
169
|
-
'COUCHBASE_CONNECTION_STRING',
|
|
170
|
-
'COUCHBASE_USERNAME',
|
|
171
|
-
'COUCHBASE_PASSWORD',
|
|
172
|
-
test_bucketName,
|
|
173
|
-
test_scopeName,
|
|
174
|
-
test_collectionName,
|
|
175
|
-
);
|
|
168
|
+
couchbase_client = new CouchbaseVector({
|
|
169
|
+
connectionString: 'COUCHBASE_CONNECTION_STRING',
|
|
170
|
+
username: 'COUCHBASE_USERNAME',
|
|
171
|
+
password: 'COUCHBASE_PASSWORD',
|
|
172
|
+
bucketName: test_bucketName,
|
|
173
|
+
scopeName: test_scopeName,
|
|
174
|
+
collectionName: test_collectionName,
|
|
175
|
+
});
|
|
176
176
|
expect(mockCouchbaseConnectFn).toHaveBeenCalledTimes(1);
|
|
177
177
|
expect(mockCouchbaseConnectFn).toHaveBeenCalledWith('COUCHBASE_CONNECTION_STRING', {
|
|
178
178
|
username: 'COUCHBASE_USERNAME',
|
|
@@ -200,14 +200,14 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
200
200
|
describe('Index Operations', () => {
|
|
201
201
|
beforeAll(async () => {
|
|
202
202
|
clearAllMocks();
|
|
203
|
-
couchbase_client = new CouchbaseVector(
|
|
204
|
-
'COUCHBASE_CONNECTION_STRING',
|
|
205
|
-
'COUCHBASE_USERNAME',
|
|
206
|
-
'COUCHBASE_PASSWORD',
|
|
207
|
-
test_bucketName,
|
|
208
|
-
test_scopeName,
|
|
209
|
-
test_collectionName,
|
|
210
|
-
);
|
|
203
|
+
couchbase_client = new CouchbaseVector({
|
|
204
|
+
connectionString: 'COUCHBASE_CONNECTION_STRING',
|
|
205
|
+
username: 'COUCHBASE_USERNAME',
|
|
206
|
+
password: 'COUCHBASE_PASSWORD',
|
|
207
|
+
bucketName: test_bucketName,
|
|
208
|
+
scopeName: test_scopeName,
|
|
209
|
+
collectionName: test_collectionName,
|
|
210
|
+
});
|
|
211
211
|
await couchbase_client.getCollection();
|
|
212
212
|
});
|
|
213
213
|
|
|
@@ -311,7 +311,7 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
311
311
|
}, 50000);
|
|
312
312
|
|
|
313
313
|
it('should describe index', async () => {
|
|
314
|
-
const stats = await couchbase_client.describeIndex(test_indexName);
|
|
314
|
+
const stats = await couchbase_client.describeIndex({ indexName: test_indexName });
|
|
315
315
|
|
|
316
316
|
expect(mockScopeSearchIndexesFn).toHaveBeenCalledTimes(2);
|
|
317
317
|
|
|
@@ -328,7 +328,7 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
328
328
|
}, 50000);
|
|
329
329
|
|
|
330
330
|
it('should delete index', async () => {
|
|
331
|
-
await couchbase_client.deleteIndex(test_indexName);
|
|
331
|
+
await couchbase_client.deleteIndex({ indexName: test_indexName });
|
|
332
332
|
|
|
333
333
|
expect(mockScopeSearchIndexesFn).toHaveBeenCalledTimes(2);
|
|
334
334
|
|
|
@@ -343,14 +343,14 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
343
343
|
|
|
344
344
|
describe('Vector Operations', () => {
|
|
345
345
|
beforeAll(async () => {
|
|
346
|
-
couchbase_client = new CouchbaseVector(
|
|
347
|
-
'COUCHBASE_CONNECTION_STRING',
|
|
348
|
-
'COUCHBASE_USERNAME',
|
|
349
|
-
'COUCHBASE_PASSWORD',
|
|
350
|
-
test_bucketName,
|
|
351
|
-
test_scopeName,
|
|
352
|
-
test_collectionName,
|
|
353
|
-
);
|
|
346
|
+
couchbase_client = new CouchbaseVector({
|
|
347
|
+
connectionString: 'COUCHBASE_CONNECTION_STRING',
|
|
348
|
+
username: 'COUCHBASE_USERNAME',
|
|
349
|
+
password: 'COUCHBASE_PASSWORD',
|
|
350
|
+
bucketName: test_bucketName,
|
|
351
|
+
scopeName: test_scopeName,
|
|
352
|
+
collectionName: test_collectionName,
|
|
353
|
+
});
|
|
354
354
|
|
|
355
355
|
await couchbase_client.getCollection();
|
|
356
356
|
});
|
|
@@ -510,14 +510,14 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
510
510
|
describe('Error Cases and Edge Cases', () => {
|
|
511
511
|
beforeAll(async () => {
|
|
512
512
|
clearAllMocks();
|
|
513
|
-
couchbase_client = new CouchbaseVector(
|
|
514
|
-
'COUCHBASE_CONNECTION_STRING',
|
|
515
|
-
'COUCHBASE_USERNAME',
|
|
516
|
-
'COUCHBASE_PASSWORD',
|
|
517
|
-
test_bucketName,
|
|
518
|
-
test_scopeName,
|
|
519
|
-
test_collectionName,
|
|
520
|
-
);
|
|
513
|
+
couchbase_client = new CouchbaseVector({
|
|
514
|
+
connectionString: 'COUCHBASE_CONNECTION_STRING',
|
|
515
|
+
username: 'COUCHBASE_USERNAME',
|
|
516
|
+
password: 'COUCHBASE_PASSWORD',
|
|
517
|
+
bucketName: test_bucketName,
|
|
518
|
+
scopeName: test_scopeName,
|
|
519
|
+
collectionName: test_collectionName,
|
|
520
|
+
});
|
|
521
521
|
await couchbase_client.getCollection();
|
|
522
522
|
});
|
|
523
523
|
|
|
@@ -542,13 +542,13 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
542
542
|
});
|
|
543
543
|
|
|
544
544
|
it('should throw error when describing a non-existent index', async () => {
|
|
545
|
-
await expect(couchbase_client.describeIndex('non_existent_index')).rejects.toThrow(
|
|
545
|
+
await expect(couchbase_client.describeIndex({ indexName: 'non_existent_index' })).rejects.toThrow(
|
|
546
546
|
`Index non_existent_index does not exist`,
|
|
547
547
|
);
|
|
548
548
|
});
|
|
549
549
|
|
|
550
550
|
it('should throw error when deleting a non-existent index', async () => {
|
|
551
|
-
await expect(couchbase_client.deleteIndex('non_existent_index')).rejects.toThrow(
|
|
551
|
+
await expect(couchbase_client.deleteIndex({ indexName: 'non_existent_index' })).rejects.toThrow(
|
|
552
552
|
`Index non_existent_index does not exist`,
|
|
553
553
|
);
|
|
554
554
|
});
|
|
@@ -577,14 +577,14 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
577
577
|
describe('Vector Dimension Tracking', () => {
|
|
578
578
|
beforeEach(async () => {
|
|
579
579
|
clearAllMocks();
|
|
580
|
-
couchbase_client = new CouchbaseVector(
|
|
581
|
-
'COUCHBASE_CONNECTION_STRING',
|
|
582
|
-
'COUCHBASE_USERNAME',
|
|
583
|
-
'COUCHBASE_PASSWORD',
|
|
584
|
-
test_bucketName,
|
|
585
|
-
test_scopeName,
|
|
586
|
-
test_collectionName,
|
|
587
|
-
);
|
|
580
|
+
couchbase_client = new CouchbaseVector({
|
|
581
|
+
connectionString: 'COUCHBASE_CONNECTION_STRING',
|
|
582
|
+
username: 'COUCHBASE_USERNAME',
|
|
583
|
+
password: 'COUCHBASE_PASSWORD',
|
|
584
|
+
bucketName: test_bucketName,
|
|
585
|
+
scopeName: test_scopeName,
|
|
586
|
+
collectionName: test_collectionName,
|
|
587
|
+
});
|
|
588
588
|
await couchbase_client.getCollection();
|
|
589
589
|
});
|
|
590
590
|
|
|
@@ -637,7 +637,7 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
637
637
|
clearAllMocks();
|
|
638
638
|
|
|
639
639
|
// Delete the index
|
|
640
|
-
await couchbase_client.deleteIndex(test_indexName);
|
|
640
|
+
await couchbase_client.deleteIndex({ indexName: test_indexName });
|
|
641
641
|
|
|
642
642
|
// Verify dimension is reset
|
|
643
643
|
expect((couchbase_client as any).vector_dimension).toBeNull();
|
|
@@ -647,14 +647,14 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
647
647
|
describe('Implementation Details', () => {
|
|
648
648
|
beforeEach(async () => {
|
|
649
649
|
clearAllMocks();
|
|
650
|
-
couchbase_client = new CouchbaseVector(
|
|
651
|
-
'COUCHBASE_CONNECTION_STRING',
|
|
652
|
-
'COUCHBASE_USERNAME',
|
|
653
|
-
'COUCHBASE_PASSWORD',
|
|
654
|
-
test_bucketName,
|
|
655
|
-
test_scopeName,
|
|
656
|
-
test_collectionName,
|
|
657
|
-
);
|
|
650
|
+
couchbase_client = new CouchbaseVector({
|
|
651
|
+
connectionString: 'COUCHBASE_CONNECTION_STRING',
|
|
652
|
+
username: 'COUCHBASE_USERNAME',
|
|
653
|
+
password: 'COUCHBASE_PASSWORD',
|
|
654
|
+
bucketName: test_bucketName,
|
|
655
|
+
scopeName: test_scopeName,
|
|
656
|
+
collectionName: test_collectionName,
|
|
657
|
+
});
|
|
658
658
|
await couchbase_client.getCollection();
|
|
659
659
|
});
|
|
660
660
|
|
|
@@ -713,7 +713,7 @@ describe('Unit Testing CouchbaseVector', () => {
|
|
|
713
713
|
},
|
|
714
714
|
});
|
|
715
715
|
|
|
716
|
-
const stats = await couchbase_client.describeIndex(test_indexName);
|
|
716
|
+
const stats = await couchbase_client.describeIndex({ indexName: test_indexName });
|
|
717
717
|
expect(stats.metric).toBe(mastraMetric);
|
|
718
718
|
}
|
|
719
719
|
});
|