@mastra/couchbase 0.0.4 → 0.1.0-alpha.1
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 +35 -0
- package/dist/_tsup-dts-rollup.d.cts +29 -11
- package/dist/_tsup-dts-rollup.d.ts +29 -11
- package/dist/index.cjs +22 -16
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +22 -16
- package/docker-compose.yaml +12 -12
- package/package.json +6 -3
- package/src/vector/index.integration.test.ts +24 -22
- package/src/vector/index.ts +35 -28
- 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.1.0-alpha.1 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 8118ms
|
|
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 9975ms
|
|
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[32m10.
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m10.
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m10.74 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 497ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m10.80 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 499ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
# @mastra/couchbase
|
|
2
2
|
|
|
3
|
+
## 0.1.0-alpha.1
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 83da932: Move @mastra/core to peerdeps
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- a7292b0: BREAKING(@mastra/core, all vector stores): Vector store breaking changes (remove deprecated functions and positional arguments)
|
|
12
|
+
- Updated dependencies [b3a3d63]
|
|
13
|
+
- Updated dependencies [344f453]
|
|
14
|
+
- Updated dependencies [0a3ae6d]
|
|
15
|
+
- Updated dependencies [95911be]
|
|
16
|
+
- Updated dependencies [5eb5a99]
|
|
17
|
+
- Updated dependencies [7e632c5]
|
|
18
|
+
- Updated dependencies [1e9fbfa]
|
|
19
|
+
- Updated dependencies [b2ae5aa]
|
|
20
|
+
- Updated dependencies [a7292b0]
|
|
21
|
+
- Updated dependencies [0dcb9f0]
|
|
22
|
+
- @mastra/core@0.10.0-alpha.1
|
|
23
|
+
|
|
24
|
+
## 0.0.5-alpha.0
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
|
|
29
|
+
- Updated dependencies [f53a6ac]
|
|
30
|
+
- Updated dependencies [eabdcd9]
|
|
31
|
+
- Updated dependencies [90be034]
|
|
32
|
+
- Updated dependencies [99f050a]
|
|
33
|
+
- Updated dependencies [d0ee3c6]
|
|
34
|
+
- Updated dependencies [23f258c]
|
|
35
|
+
- Updated dependencies [2672a05]
|
|
36
|
+
- @mastra/core@0.9.5-alpha.0
|
|
37
|
+
|
|
3
38
|
## 0.0.4
|
|
4
39
|
|
|
5
40
|
### Patch Changes
|
|
@@ -1,9 +1,13 @@
|
|
|
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';
|
|
5
8
|
import type { QueryResult } from '@mastra/core/vector';
|
|
6
9
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
10
|
+
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
7
11
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
8
12
|
|
|
9
13
|
declare type CouchbaseMetric = 'cosine' | 'l2_norm' | 'dot_product';
|
|
@@ -18,14 +22,20 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
18
22
|
private bucket;
|
|
19
23
|
private scope;
|
|
20
24
|
private vector_dimension;
|
|
21
|
-
constructor(
|
|
25
|
+
constructor({ connectionString, username, password, bucketName, scopeName, collectionName }: CouchbaseVectorParams);
|
|
22
26
|
getCollection(): Promise<Collection>;
|
|
23
|
-
createIndex(
|
|
24
|
-
upsert(
|
|
25
|
-
query(
|
|
27
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
28
|
+
upsert({ vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
|
|
29
|
+
query({ indexName, queryVector, topK, includeVector }: QueryVectorParams): Promise<QueryResult[]>;
|
|
26
30
|
listIndexes(): Promise<string[]>;
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves statistics about a vector index.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} indexName - The name of the index to describe
|
|
35
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
36
|
+
*/
|
|
37
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
38
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
29
39
|
/**
|
|
30
40
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
31
41
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -36,10 +46,7 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
36
46
|
* @returns A promise that resolves when the update is complete.
|
|
37
47
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
38
48
|
*/
|
|
39
|
-
updateVector(
|
|
40
|
-
vector?: number[];
|
|
41
|
-
metadata?: Record<string, any>;
|
|
42
|
-
}): Promise<void>;
|
|
49
|
+
updateVector({ id, update }: UpdateVectorParams): Promise<void>;
|
|
43
50
|
/**
|
|
44
51
|
* Deletes a vector by its ID.
|
|
45
52
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -47,11 +54,22 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
47
54
|
* @returns A promise that resolves when the deletion is complete.
|
|
48
55
|
* @throws Will throw an error if the deletion operation fails.
|
|
49
56
|
*/
|
|
50
|
-
deleteVector(
|
|
57
|
+
deleteVector({ id }: DeleteVectorParams): Promise<void>;
|
|
51
58
|
}
|
|
52
59
|
export { CouchbaseVector }
|
|
53
60
|
export { CouchbaseVector as CouchbaseVector_alias_1 }
|
|
54
61
|
|
|
62
|
+
declare type CouchbaseVectorParams = {
|
|
63
|
+
connectionString: string;
|
|
64
|
+
username: string;
|
|
65
|
+
password: string;
|
|
66
|
+
bucketName: string;
|
|
67
|
+
scopeName: string;
|
|
68
|
+
collectionName: string;
|
|
69
|
+
};
|
|
70
|
+
export { CouchbaseVectorParams }
|
|
71
|
+
export { CouchbaseVectorParams as CouchbaseVectorParams_alias_1 }
|
|
72
|
+
|
|
55
73
|
declare const DISTANCE_MAPPING: Record<MastraMetric, CouchbaseMetric>;
|
|
56
74
|
export { DISTANCE_MAPPING }
|
|
57
75
|
export { DISTANCE_MAPPING as DISTANCE_MAPPING_alias_1 }
|
|
@@ -1,9 +1,13 @@
|
|
|
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';
|
|
5
8
|
import type { QueryResult } from '@mastra/core/vector';
|
|
6
9
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
10
|
+
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
7
11
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
8
12
|
|
|
9
13
|
declare type CouchbaseMetric = 'cosine' | 'l2_norm' | 'dot_product';
|
|
@@ -18,14 +22,20 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
18
22
|
private bucket;
|
|
19
23
|
private scope;
|
|
20
24
|
private vector_dimension;
|
|
21
|
-
constructor(
|
|
25
|
+
constructor({ connectionString, username, password, bucketName, scopeName, collectionName }: CouchbaseVectorParams);
|
|
22
26
|
getCollection(): Promise<Collection>;
|
|
23
|
-
createIndex(
|
|
24
|
-
upsert(
|
|
25
|
-
query(
|
|
27
|
+
createIndex({ indexName, dimension, metric }: CreateIndexParams): Promise<void>;
|
|
28
|
+
upsert({ vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
|
|
29
|
+
query({ indexName, queryVector, topK, includeVector }: QueryVectorParams): Promise<QueryResult[]>;
|
|
26
30
|
listIndexes(): Promise<string[]>;
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Retrieves statistics about a vector index.
|
|
33
|
+
*
|
|
34
|
+
* @param {string} indexName - The name of the index to describe
|
|
35
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
36
|
+
*/
|
|
37
|
+
describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats>;
|
|
38
|
+
deleteIndex({ indexName }: DeleteIndexParams): Promise<void>;
|
|
29
39
|
/**
|
|
30
40
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
31
41
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -36,10 +46,7 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
36
46
|
* @returns A promise that resolves when the update is complete.
|
|
37
47
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
38
48
|
*/
|
|
39
|
-
updateVector(
|
|
40
|
-
vector?: number[];
|
|
41
|
-
metadata?: Record<string, any>;
|
|
42
|
-
}): Promise<void>;
|
|
49
|
+
updateVector({ id, update }: UpdateVectorParams): Promise<void>;
|
|
43
50
|
/**
|
|
44
51
|
* Deletes a vector by its ID.
|
|
45
52
|
* @param indexName - The name of the index containing the vector.
|
|
@@ -47,11 +54,22 @@ declare class CouchbaseVector extends MastraVector {
|
|
|
47
54
|
* @returns A promise that resolves when the deletion is complete.
|
|
48
55
|
* @throws Will throw an error if the deletion operation fails.
|
|
49
56
|
*/
|
|
50
|
-
deleteVector(
|
|
57
|
+
deleteVector({ id }: DeleteVectorParams): Promise<void>;
|
|
51
58
|
}
|
|
52
59
|
export { CouchbaseVector }
|
|
53
60
|
export { CouchbaseVector as CouchbaseVector_alias_1 }
|
|
54
61
|
|
|
62
|
+
declare type CouchbaseVectorParams = {
|
|
63
|
+
connectionString: string;
|
|
64
|
+
username: string;
|
|
65
|
+
password: string;
|
|
66
|
+
bucketName: string;
|
|
67
|
+
scopeName: string;
|
|
68
|
+
collectionName: string;
|
|
69
|
+
};
|
|
70
|
+
export { CouchbaseVectorParams }
|
|
71
|
+
export { CouchbaseVectorParams as CouchbaseVectorParams_alias_1 }
|
|
72
|
+
|
|
55
73
|
declare const DISTANCE_MAPPING: Record<MastraMetric, CouchbaseMetric>;
|
|
56
74
|
export { DISTANCE_MAPPING }
|
|
57
75
|
export { DISTANCE_MAPPING as DISTANCE_MAPPING_alias_1 }
|
package/dist/index.cjs
CHANGED
|
@@ -19,9 +19,9 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
19
19
|
bucket;
|
|
20
20
|
scope;
|
|
21
21
|
vector_dimension;
|
|
22
|
-
constructor(
|
|
22
|
+
constructor({ connectionString, username, password, bucketName, scopeName, collectionName }) {
|
|
23
23
|
super();
|
|
24
|
-
const baseClusterPromise = couchbase.connect(
|
|
24
|
+
const baseClusterPromise = couchbase.connect(connectionString, {
|
|
25
25
|
username,
|
|
26
26
|
password,
|
|
27
27
|
configProfile: "wanDevelopment"
|
|
@@ -53,8 +53,7 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
53
53
|
}
|
|
54
54
|
return this.collection;
|
|
55
55
|
}
|
|
56
|
-
async createIndex(
|
|
57
|
-
const { indexName, dimension, metric = "dotproduct" } = params;
|
|
56
|
+
async createIndex({ indexName, dimension, metric = "dotproduct" }) {
|
|
58
57
|
await this.getCollection();
|
|
59
58
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
60
59
|
throw new Error("Dimension must be a positive integer");
|
|
@@ -149,8 +148,7 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
149
148
|
throw error;
|
|
150
149
|
}
|
|
151
150
|
}
|
|
152
|
-
async upsert(
|
|
153
|
-
const { vectors, metadata, ids } = params;
|
|
151
|
+
async upsert({ vectors, metadata, ids }) {
|
|
154
152
|
await this.getCollection();
|
|
155
153
|
if (!vectors || vectors.length === 0) {
|
|
156
154
|
throw new Error("No vectors provided");
|
|
@@ -181,10 +179,9 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
181
179
|
await Promise.all(allPromises);
|
|
182
180
|
return pointIds;
|
|
183
181
|
}
|
|
184
|
-
async query(
|
|
185
|
-
const { indexName, queryVector, topK = 10, includeVector = false } = params;
|
|
182
|
+
async query({ indexName, queryVector, topK = 10, includeVector = false }) {
|
|
186
183
|
await this.getCollection();
|
|
187
|
-
const index_stats = await this.describeIndex(indexName);
|
|
184
|
+
const index_stats = await this.describeIndex({ indexName });
|
|
188
185
|
if (queryVector.length !== index_stats.dimension) {
|
|
189
186
|
throw new Error(`Query vector dimension mismatch. Expected ${index_stats.dimension}, got ${queryVector.length}`);
|
|
190
187
|
}
|
|
@@ -221,7 +218,13 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
221
218
|
const indexes = await this.scope.searchIndexes().getAllIndexes();
|
|
222
219
|
return indexes?.map((index) => index.name) || [];
|
|
223
220
|
}
|
|
224
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Retrieves statistics about a vector index.
|
|
223
|
+
*
|
|
224
|
+
* @param {string} indexName - The name of the index to describe
|
|
225
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
226
|
+
*/
|
|
227
|
+
async describeIndex({ indexName }) {
|
|
225
228
|
await this.getCollection();
|
|
226
229
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
227
230
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -238,7 +241,7 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
238
241
|
)
|
|
239
242
|
};
|
|
240
243
|
}
|
|
241
|
-
async deleteIndex(indexName) {
|
|
244
|
+
async deleteIndex({ indexName }) {
|
|
242
245
|
await this.getCollection();
|
|
243
246
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
244
247
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -256,10 +259,13 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
256
259
|
* @returns A promise that resolves when the update is complete.
|
|
257
260
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
258
261
|
*/
|
|
259
|
-
async updateVector(
|
|
260
|
-
if (!
|
|
262
|
+
async updateVector({ id, update }) {
|
|
263
|
+
if (!update.vector && !update.metadata) {
|
|
261
264
|
throw new Error("No updates provided");
|
|
262
265
|
}
|
|
266
|
+
if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {
|
|
267
|
+
throw new Error("Vector dimension mismatch");
|
|
268
|
+
}
|
|
263
269
|
const collection = await this.getCollection();
|
|
264
270
|
try {
|
|
265
271
|
await collection.get(id);
|
|
@@ -270,8 +276,8 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
270
276
|
throw err;
|
|
271
277
|
}
|
|
272
278
|
const specs = [];
|
|
273
|
-
if (
|
|
274
|
-
if (
|
|
279
|
+
if (update.vector) specs.push(couchbase.MutateInSpec.replace("embedding", update.vector));
|
|
280
|
+
if (update.metadata) specs.push(couchbase.MutateInSpec.replace("metadata", update.metadata));
|
|
275
281
|
await collection.mutateIn(id, specs);
|
|
276
282
|
}
|
|
277
283
|
/**
|
|
@@ -281,7 +287,7 @@ var CouchbaseVector = class extends vector.MastraVector {
|
|
|
281
287
|
* @returns A promise that resolves when the deletion is complete.
|
|
282
288
|
* @throws Will throw an error if the deletion operation fails.
|
|
283
289
|
*/
|
|
284
|
-
async deleteVector(
|
|
290
|
+
async deleteVector({ id }) {
|
|
285
291
|
const collection = await this.getCollection();
|
|
286
292
|
try {
|
|
287
293
|
await collection.get(id);
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -17,9 +17,9 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
17
17
|
bucket;
|
|
18
18
|
scope;
|
|
19
19
|
vector_dimension;
|
|
20
|
-
constructor(
|
|
20
|
+
constructor({ connectionString, username, password, bucketName, scopeName, collectionName }) {
|
|
21
21
|
super();
|
|
22
|
-
const baseClusterPromise = connect(
|
|
22
|
+
const baseClusterPromise = connect(connectionString, {
|
|
23
23
|
username,
|
|
24
24
|
password,
|
|
25
25
|
configProfile: "wanDevelopment"
|
|
@@ -51,8 +51,7 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
51
51
|
}
|
|
52
52
|
return this.collection;
|
|
53
53
|
}
|
|
54
|
-
async createIndex(
|
|
55
|
-
const { indexName, dimension, metric = "dotproduct" } = params;
|
|
54
|
+
async createIndex({ indexName, dimension, metric = "dotproduct" }) {
|
|
56
55
|
await this.getCollection();
|
|
57
56
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
58
57
|
throw new Error("Dimension must be a positive integer");
|
|
@@ -147,8 +146,7 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
147
146
|
throw error;
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
|
-
async upsert(
|
|
151
|
-
const { vectors, metadata, ids } = params;
|
|
149
|
+
async upsert({ vectors, metadata, ids }) {
|
|
152
150
|
await this.getCollection();
|
|
153
151
|
if (!vectors || vectors.length === 0) {
|
|
154
152
|
throw new Error("No vectors provided");
|
|
@@ -179,10 +177,9 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
179
177
|
await Promise.all(allPromises);
|
|
180
178
|
return pointIds;
|
|
181
179
|
}
|
|
182
|
-
async query(
|
|
183
|
-
const { indexName, queryVector, topK = 10, includeVector = false } = params;
|
|
180
|
+
async query({ indexName, queryVector, topK = 10, includeVector = false }) {
|
|
184
181
|
await this.getCollection();
|
|
185
|
-
const index_stats = await this.describeIndex(indexName);
|
|
182
|
+
const index_stats = await this.describeIndex({ indexName });
|
|
186
183
|
if (queryVector.length !== index_stats.dimension) {
|
|
187
184
|
throw new Error(`Query vector dimension mismatch. Expected ${index_stats.dimension}, got ${queryVector.length}`);
|
|
188
185
|
}
|
|
@@ -219,7 +216,13 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
219
216
|
const indexes = await this.scope.searchIndexes().getAllIndexes();
|
|
220
217
|
return indexes?.map((index) => index.name) || [];
|
|
221
218
|
}
|
|
222
|
-
|
|
219
|
+
/**
|
|
220
|
+
* Retrieves statistics about a vector index.
|
|
221
|
+
*
|
|
222
|
+
* @param {string} indexName - The name of the index to describe
|
|
223
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
224
|
+
*/
|
|
225
|
+
async describeIndex({ indexName }) {
|
|
223
226
|
await this.getCollection();
|
|
224
227
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
225
228
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -236,7 +239,7 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
236
239
|
)
|
|
237
240
|
};
|
|
238
241
|
}
|
|
239
|
-
async deleteIndex(indexName) {
|
|
242
|
+
async deleteIndex({ indexName }) {
|
|
240
243
|
await this.getCollection();
|
|
241
244
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
242
245
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -254,10 +257,13 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
254
257
|
* @returns A promise that resolves when the update is complete.
|
|
255
258
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
256
259
|
*/
|
|
257
|
-
async updateVector(
|
|
258
|
-
if (!
|
|
260
|
+
async updateVector({ id, update }) {
|
|
261
|
+
if (!update.vector && !update.metadata) {
|
|
259
262
|
throw new Error("No updates provided");
|
|
260
263
|
}
|
|
264
|
+
if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {
|
|
265
|
+
throw new Error("Vector dimension mismatch");
|
|
266
|
+
}
|
|
261
267
|
const collection = await this.getCollection();
|
|
262
268
|
try {
|
|
263
269
|
await collection.get(id);
|
|
@@ -268,8 +274,8 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
268
274
|
throw err;
|
|
269
275
|
}
|
|
270
276
|
const specs = [];
|
|
271
|
-
if (
|
|
272
|
-
if (
|
|
277
|
+
if (update.vector) specs.push(MutateInSpec.replace("embedding", update.vector));
|
|
278
|
+
if (update.metadata) specs.push(MutateInSpec.replace("metadata", update.metadata));
|
|
273
279
|
await collection.mutateIn(id, specs);
|
|
274
280
|
}
|
|
275
281
|
/**
|
|
@@ -279,7 +285,7 @@ var CouchbaseVector = class extends MastraVector {
|
|
|
279
285
|
* @returns A promise that resolves when the deletion is complete.
|
|
280
286
|
* @throws Will throw an error if the deletion operation fails.
|
|
281
287
|
*/
|
|
282
|
-
async deleteVector(
|
|
288
|
+
async deleteVector({ id }) {
|
|
283
289
|
const collection = await this.getCollection();
|
|
284
290
|
try {
|
|
285
291
|
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.1.0-alpha.1",
|
|
4
4
|
"description": "Couchbase vector store provider for Mastra",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -19,8 +19,7 @@
|
|
|
19
19
|
"./package.json": "./package.json"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"couchbase": "^4.4.5"
|
|
23
|
-
"@mastra/core": "^0.9.4"
|
|
22
|
+
"couchbase": "^4.4.5"
|
|
24
23
|
},
|
|
25
24
|
"devDependencies": {
|
|
26
25
|
"@microsoft/api-extractor": "^7.52.1",
|
|
@@ -32,8 +31,12 @@
|
|
|
32
31
|
"tsup": "^8.4.0",
|
|
33
32
|
"typescript": "^5.8.2",
|
|
34
33
|
"vitest": "^3.0.9",
|
|
34
|
+
"@mastra/core": "0.10.0-alpha.1",
|
|
35
35
|
"@internal/lint": "0.0.5"
|
|
36
36
|
},
|
|
37
|
+
"peerDependencies": {
|
|
38
|
+
"@mastra/core": "^0.9.4"
|
|
39
|
+
},
|
|
37
40
|
"scripts": {
|
|
38
41
|
"build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
|
|
39
42
|
"build:watch": "pnpm build --watch",
|
|
@@ -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,10 @@ import type {
|
|
|
5
5
|
CreateIndexParams,
|
|
6
6
|
UpsertVectorParams,
|
|
7
7
|
QueryVectorParams,
|
|
8
|
+
DescribeIndexParams,
|
|
9
|
+
DeleteIndexParams,
|
|
10
|
+
DeleteVectorParams,
|
|
11
|
+
UpdateVectorParams,
|
|
8
12
|
} from '@mastra/core/vector';
|
|
9
13
|
import type { Bucket, Cluster, Collection, Scope } from 'couchbase';
|
|
10
14
|
import { MutateInSpec, connect, SearchRequest, VectorQuery, VectorSearch } from 'couchbase';
|
|
@@ -17,6 +21,15 @@ export const DISTANCE_MAPPING: Record<MastraMetric, CouchbaseMetric> = {
|
|
|
17
21
|
dotproduct: 'dot_product',
|
|
18
22
|
};
|
|
19
23
|
|
|
24
|
+
export type CouchbaseVectorParams = {
|
|
25
|
+
connectionString: string;
|
|
26
|
+
username: string;
|
|
27
|
+
password: string;
|
|
28
|
+
bucketName: string;
|
|
29
|
+
scopeName: string;
|
|
30
|
+
collectionName: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
20
33
|
export class CouchbaseVector extends MastraVector {
|
|
21
34
|
private clusterPromise: Promise<Cluster>;
|
|
22
35
|
private cluster: Cluster;
|
|
@@ -28,17 +41,10 @@ export class CouchbaseVector extends MastraVector {
|
|
|
28
41
|
private scope: Scope;
|
|
29
42
|
private vector_dimension: number;
|
|
30
43
|
|
|
31
|
-
constructor(
|
|
32
|
-
cnn_string: string,
|
|
33
|
-
username: string,
|
|
34
|
-
password: string,
|
|
35
|
-
bucketName: string,
|
|
36
|
-
scopeName: string,
|
|
37
|
-
collectionName: string,
|
|
38
|
-
) {
|
|
44
|
+
constructor({ connectionString, username, password, bucketName, scopeName, collectionName }: CouchbaseVectorParams) {
|
|
39
45
|
super();
|
|
40
46
|
|
|
41
|
-
const baseClusterPromise = connect(
|
|
47
|
+
const baseClusterPromise = connect(connectionString, {
|
|
42
48
|
username,
|
|
43
49
|
password,
|
|
44
50
|
configProfile: 'wanDevelopment',
|
|
@@ -76,8 +82,7 @@ export class CouchbaseVector extends MastraVector {
|
|
|
76
82
|
return this.collection;
|
|
77
83
|
}
|
|
78
84
|
|
|
79
|
-
async createIndex(
|
|
80
|
-
const { indexName, dimension, metric = 'dotproduct' as MastraMetric } = params;
|
|
85
|
+
async createIndex({ indexName, dimension, metric = 'dotproduct' as MastraMetric }: CreateIndexParams): Promise<void> {
|
|
81
86
|
await this.getCollection();
|
|
82
87
|
|
|
83
88
|
if (!Number.isInteger(dimension) || dimension <= 0) {
|
|
@@ -172,8 +177,7 @@ export class CouchbaseVector extends MastraVector {
|
|
|
172
177
|
}
|
|
173
178
|
}
|
|
174
179
|
|
|
175
|
-
async upsert(
|
|
176
|
-
const { vectors, metadata, ids } = params;
|
|
180
|
+
async upsert({ vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {
|
|
177
181
|
await this.getCollection();
|
|
178
182
|
|
|
179
183
|
if (!vectors || vectors.length === 0) {
|
|
@@ -210,12 +214,10 @@ export class CouchbaseVector extends MastraVector {
|
|
|
210
214
|
return pointIds;
|
|
211
215
|
}
|
|
212
216
|
|
|
213
|
-
async query(
|
|
214
|
-
const { indexName, queryVector, topK = 10, includeVector = false } = params;
|
|
215
|
-
|
|
217
|
+
async query({ indexName, queryVector, topK = 10, includeVector = false }: QueryVectorParams): Promise<QueryResult[]> {
|
|
216
218
|
await this.getCollection();
|
|
217
219
|
|
|
218
|
-
const index_stats = await this.describeIndex(indexName);
|
|
220
|
+
const index_stats = await this.describeIndex({ indexName });
|
|
219
221
|
if (queryVector.length !== index_stats.dimension) {
|
|
220
222
|
throw new Error(`Query vector dimension mismatch. Expected ${index_stats.dimension}, got ${queryVector.length}`);
|
|
221
223
|
}
|
|
@@ -255,7 +257,13 @@ export class CouchbaseVector extends MastraVector {
|
|
|
255
257
|
return indexes?.map(index => index.name) || [];
|
|
256
258
|
}
|
|
257
259
|
|
|
258
|
-
|
|
260
|
+
/**
|
|
261
|
+
* Retrieves statistics about a vector index.
|
|
262
|
+
*
|
|
263
|
+
* @param {string} indexName - The name of the index to describe
|
|
264
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
265
|
+
*/
|
|
266
|
+
async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {
|
|
259
267
|
await this.getCollection();
|
|
260
268
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
261
269
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -276,7 +284,7 @@ export class CouchbaseVector extends MastraVector {
|
|
|
276
284
|
};
|
|
277
285
|
}
|
|
278
286
|
|
|
279
|
-
async deleteIndex(indexName:
|
|
287
|
+
async deleteIndex({ indexName }: DeleteIndexParams): Promise<void> {
|
|
280
288
|
await this.getCollection();
|
|
281
289
|
if (!(await this.listIndexes()).includes(indexName)) {
|
|
282
290
|
throw new Error(`Index ${indexName} does not exist`);
|
|
@@ -295,14 +303,13 @@ export class CouchbaseVector extends MastraVector {
|
|
|
295
303
|
* @returns A promise that resolves when the update is complete.
|
|
296
304
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
297
305
|
*/
|
|
298
|
-
async updateVector(
|
|
299
|
-
|
|
300
|
-
id: string,
|
|
301
|
-
updates: { vector?: number[]; metadata?: Record<string, any> },
|
|
302
|
-
): Promise<void> {
|
|
303
|
-
if (!updates.vector && !updates.metadata) {
|
|
306
|
+
async updateVector({ id, update }: UpdateVectorParams): Promise<void> {
|
|
307
|
+
if (!update.vector && !update.metadata) {
|
|
304
308
|
throw new Error('No updates provided');
|
|
305
309
|
}
|
|
310
|
+
if (update.vector && this.vector_dimension && update.vector.length !== this.vector_dimension) {
|
|
311
|
+
throw new Error('Vector dimension mismatch');
|
|
312
|
+
}
|
|
306
313
|
const collection = await this.getCollection();
|
|
307
314
|
|
|
308
315
|
// Check if document exists
|
|
@@ -316,8 +323,8 @@ export class CouchbaseVector extends MastraVector {
|
|
|
316
323
|
}
|
|
317
324
|
|
|
318
325
|
const specs: MutateInSpec[] = [];
|
|
319
|
-
if (
|
|
320
|
-
if (
|
|
326
|
+
if (update.vector) specs.push(MutateInSpec.replace('embedding', update.vector));
|
|
327
|
+
if (update.metadata) specs.push(MutateInSpec.replace('metadata', update.metadata));
|
|
321
328
|
|
|
322
329
|
await collection.mutateIn(id, specs);
|
|
323
330
|
}
|
|
@@ -329,7 +336,7 @@ export class CouchbaseVector extends MastraVector {
|
|
|
329
336
|
* @returns A promise that resolves when the deletion is complete.
|
|
330
337
|
* @throws Will throw an error if the deletion operation fails.
|
|
331
338
|
*/
|
|
332
|
-
async deleteVector(
|
|
339
|
+
async deleteVector({ id }: DeleteVectorParams): Promise<void> {
|
|
333
340
|
const collection = await this.getCollection();
|
|
334
341
|
|
|
335
342
|
// 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
|
});
|