@mastra/couchbase 0.0.0-vnext-inngest-20250506132005 → 0.0.0-vnext-inngest-20250508110322

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,27 @@
1
1
  # @mastra/couchbase
2
2
 
3
- ## 0.0.0-vnext-inngest-20250506132005
3
+ ## 0.0.0-vnext-inngest-20250508110322
4
+
5
+ ### Patch Changes
6
+
7
+ - 9cd1a46: [MASTRA-3338] update naming scheme for embedding index based on vector store rules and added duplicate index checks
8
+ - Updated dependencies [526c570]
9
+ - Updated dependencies [9cd1a46]
10
+ - Updated dependencies [b5d2de0]
11
+ - Updated dependencies [644f8ad]
12
+ - Updated dependencies [70dbf51]
13
+ - @mastra/core@0.0.0-vnext-inngest-20250508110322
14
+
15
+ ## 0.0.3-alpha.0
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [526c570]
20
+ - Updated dependencies [b5d2de0]
21
+ - Updated dependencies [644f8ad]
22
+ - @mastra/core@0.9.3-alpha.0
23
+
24
+ ## 0.0.2
4
25
 
5
26
  ### Patch Changes
6
27
 
@@ -17,9 +38,22 @@
17
38
  - Updated dependencies [0097d50]
18
39
  - Updated dependencies [7eeb2bc]
19
40
  - Updated dependencies [17826a9]
41
+ - Updated dependencies [7d8b7c7]
20
42
  - Updated dependencies [fba031f]
43
+ - Updated dependencies [3a5f1e1]
21
44
  - Updated dependencies [51e6923]
22
- - @mastra/core@0.0.0-vnext-inngest-20250506132005
45
+ - Updated dependencies [8398d89]
46
+ - @mastra/core@0.9.2
47
+
48
+ ## 0.0.2-alpha.1
49
+
50
+ ### Patch Changes
51
+
52
+ - Updated dependencies [6052aa6]
53
+ - Updated dependencies [7d8b7c7]
54
+ - Updated dependencies [3a5f1e1]
55
+ - Updated dependencies [8398d89]
56
+ - @mastra/core@0.9.2-alpha.6
23
57
 
24
58
  ## 0.0.2-alpha.0
25
59
 
package/dist/index.cjs CHANGED
@@ -59,86 +59,95 @@ var CouchbaseVector = class extends vector.MastraVector {
59
59
  if (!Number.isInteger(dimension) || dimension <= 0) {
60
60
  throw new Error("Dimension must be a positive integer");
61
61
  }
62
- await this.scope.searchIndexes().upsertIndex({
63
- name: indexName,
64
- sourceName: this.bucketName,
65
- type: "fulltext-index",
66
- params: {
67
- doc_config: {
68
- docid_prefix_delim: "",
69
- docid_regexp: "",
70
- mode: "scope.collection.type_field",
71
- type_field: "type"
72
- },
73
- mapping: {
74
- default_analyzer: "standard",
75
- default_datetime_parser: "dateTimeOptional",
76
- default_field: "_all",
77
- default_mapping: {
78
- dynamic: true,
79
- enabled: false
62
+ try {
63
+ await this.scope.searchIndexes().upsertIndex({
64
+ name: indexName,
65
+ sourceName: this.bucketName,
66
+ type: "fulltext-index",
67
+ params: {
68
+ doc_config: {
69
+ docid_prefix_delim: "",
70
+ docid_regexp: "",
71
+ mode: "scope.collection.type_field",
72
+ type_field: "type"
80
73
  },
81
- default_type: "_default",
82
- docvalues_dynamic: true,
83
- // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
84
- index_dynamic: true,
85
- store_dynamic: true,
86
- // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
87
- type_field: "_type",
88
- types: {
89
- [`${this.scopeName}.${this.collectionName}`]: {
74
+ mapping: {
75
+ default_analyzer: "standard",
76
+ default_datetime_parser: "dateTimeOptional",
77
+ default_field: "_all",
78
+ default_mapping: {
90
79
  dynamic: true,
91
- enabled: true,
92
- properties: {
93
- embedding: {
94
- enabled: true,
95
- fields: [
96
- {
97
- dims: dimension,
98
- index: true,
99
- name: "embedding",
100
- similarity: DISTANCE_MAPPING[metric],
101
- type: "vector",
102
- vector_index_optimized_for: "recall",
103
- store: true,
104
- // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
105
- docvalues: true,
106
- // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
107
- include_term_vectors: true
108
- // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
109
- }
110
- ]
111
- },
112
- content: {
113
- enabled: true,
114
- fields: [
115
- {
116
- index: true,
117
- name: "content",
118
- store: true,
119
- type: "text"
120
- }
121
- ]
80
+ enabled: false
81
+ },
82
+ default_type: "_default",
83
+ docvalues_dynamic: true,
84
+ // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
85
+ index_dynamic: true,
86
+ store_dynamic: true,
87
+ // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
88
+ type_field: "_type",
89
+ types: {
90
+ [`${this.scopeName}.${this.collectionName}`]: {
91
+ dynamic: true,
92
+ enabled: true,
93
+ properties: {
94
+ embedding: {
95
+ enabled: true,
96
+ fields: [
97
+ {
98
+ dims: dimension,
99
+ index: true,
100
+ name: "embedding",
101
+ similarity: DISTANCE_MAPPING[metric],
102
+ type: "vector",
103
+ vector_index_optimized_for: "recall",
104
+ store: true,
105
+ // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
106
+ docvalues: true,
107
+ // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
108
+ include_term_vectors: true
109
+ // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
110
+ }
111
+ ]
112
+ },
113
+ content: {
114
+ enabled: true,
115
+ fields: [
116
+ {
117
+ index: true,
118
+ name: "content",
119
+ store: true,
120
+ type: "text"
121
+ }
122
+ ]
123
+ }
122
124
  }
123
125
  }
124
126
  }
127
+ },
128
+ store: {
129
+ indexType: "scorch",
130
+ segmentVersion: 16
125
131
  }
126
132
  },
127
- store: {
128
- indexType: "scorch",
129
- segmentVersion: 16
133
+ sourceUuid: "",
134
+ sourceParams: {},
135
+ sourceType: "gocbcore",
136
+ planParams: {
137
+ maxPartitionsPerPIndex: 64,
138
+ indexPartitions: 16,
139
+ numReplicas: 0
130
140
  }
131
- },
132
- sourceUuid: "",
133
- sourceParams: {},
134
- sourceType: "gocbcore",
135
- planParams: {
136
- maxPartitionsPerPIndex: 64,
137
- indexPartitions: 16,
138
- numReplicas: 0
141
+ });
142
+ this.vector_dimension = dimension;
143
+ } catch (error) {
144
+ const message = error?.message || error?.toString();
145
+ if (message && message.toLowerCase().includes("index exists")) {
146
+ await this.validateExistingIndex(indexName, dimension, metric);
147
+ return;
139
148
  }
140
- });
141
- this.vector_dimension = dimension;
149
+ throw error;
150
+ }
142
151
  }
143
152
  async upsert(params) {
144
153
  const { vectors, metadata, ids } = params;
package/dist/index.js CHANGED
@@ -57,86 +57,95 @@ var CouchbaseVector = class extends MastraVector {
57
57
  if (!Number.isInteger(dimension) || dimension <= 0) {
58
58
  throw new Error("Dimension must be a positive integer");
59
59
  }
60
- await this.scope.searchIndexes().upsertIndex({
61
- name: indexName,
62
- sourceName: this.bucketName,
63
- type: "fulltext-index",
64
- params: {
65
- doc_config: {
66
- docid_prefix_delim: "",
67
- docid_regexp: "",
68
- mode: "scope.collection.type_field",
69
- type_field: "type"
70
- },
71
- mapping: {
72
- default_analyzer: "standard",
73
- default_datetime_parser: "dateTimeOptional",
74
- default_field: "_all",
75
- default_mapping: {
76
- dynamic: true,
77
- enabled: false
60
+ try {
61
+ await this.scope.searchIndexes().upsertIndex({
62
+ name: indexName,
63
+ sourceName: this.bucketName,
64
+ type: "fulltext-index",
65
+ params: {
66
+ doc_config: {
67
+ docid_prefix_delim: "",
68
+ docid_regexp: "",
69
+ mode: "scope.collection.type_field",
70
+ type_field: "type"
78
71
  },
79
- default_type: "_default",
80
- docvalues_dynamic: true,
81
- // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
82
- index_dynamic: true,
83
- store_dynamic: true,
84
- // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
85
- type_field: "_type",
86
- types: {
87
- [`${this.scopeName}.${this.collectionName}`]: {
72
+ mapping: {
73
+ default_analyzer: "standard",
74
+ default_datetime_parser: "dateTimeOptional",
75
+ default_field: "_all",
76
+ default_mapping: {
88
77
  dynamic: true,
89
- enabled: true,
90
- properties: {
91
- embedding: {
92
- enabled: true,
93
- fields: [
94
- {
95
- dims: dimension,
96
- index: true,
97
- name: "embedding",
98
- similarity: DISTANCE_MAPPING[metric],
99
- type: "vector",
100
- vector_index_optimized_for: "recall",
101
- store: true,
102
- // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
103
- docvalues: true,
104
- // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
105
- include_term_vectors: true
106
- // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
107
- }
108
- ]
109
- },
110
- content: {
111
- enabled: true,
112
- fields: [
113
- {
114
- index: true,
115
- name: "content",
116
- store: true,
117
- type: "text"
118
- }
119
- ]
78
+ enabled: false
79
+ },
80
+ default_type: "_default",
81
+ docvalues_dynamic: true,
82
+ // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
83
+ index_dynamic: true,
84
+ store_dynamic: true,
85
+ // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
86
+ type_field: "_type",
87
+ types: {
88
+ [`${this.scopeName}.${this.collectionName}`]: {
89
+ dynamic: true,
90
+ enabled: true,
91
+ properties: {
92
+ embedding: {
93
+ enabled: true,
94
+ fields: [
95
+ {
96
+ dims: dimension,
97
+ index: true,
98
+ name: "embedding",
99
+ similarity: DISTANCE_MAPPING[metric],
100
+ type: "vector",
101
+ vector_index_optimized_for: "recall",
102
+ store: true,
103
+ // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
104
+ docvalues: true,
105
+ // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
106
+ include_term_vectors: true
107
+ // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
108
+ }
109
+ ]
110
+ },
111
+ content: {
112
+ enabled: true,
113
+ fields: [
114
+ {
115
+ index: true,
116
+ name: "content",
117
+ store: true,
118
+ type: "text"
119
+ }
120
+ ]
121
+ }
120
122
  }
121
123
  }
122
124
  }
125
+ },
126
+ store: {
127
+ indexType: "scorch",
128
+ segmentVersion: 16
123
129
  }
124
130
  },
125
- store: {
126
- indexType: "scorch",
127
- segmentVersion: 16
131
+ sourceUuid: "",
132
+ sourceParams: {},
133
+ sourceType: "gocbcore",
134
+ planParams: {
135
+ maxPartitionsPerPIndex: 64,
136
+ indexPartitions: 16,
137
+ numReplicas: 0
128
138
  }
129
- },
130
- sourceUuid: "",
131
- sourceParams: {},
132
- sourceType: "gocbcore",
133
- planParams: {
134
- maxPartitionsPerPIndex: 64,
135
- indexPartitions: 16,
136
- numReplicas: 0
139
+ });
140
+ this.vector_dimension = dimension;
141
+ } catch (error) {
142
+ const message = error?.message || error?.toString();
143
+ if (message && message.toLowerCase().includes("index exists")) {
144
+ await this.validateExistingIndex(indexName, dimension, metric);
145
+ return;
137
146
  }
138
- });
139
- this.vector_dimension = dimension;
147
+ throw error;
148
+ }
140
149
  }
141
150
  async upsert(params) {
142
151
  const { vectors, metadata, ids } = params;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/couchbase",
3
- "version": "0.0.0-vnext-inngest-20250506132005",
3
+ "version": "0.0.0-vnext-inngest-20250508110322",
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.0.0-vnext-inngest-20250506132005"
23
+ "@mastra/core": "0.0.0-vnext-inngest-20250508110322"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@microsoft/api-extractor": "^7.52.1",
@@ -32,7 +32,7 @@
32
32
  "tsup": "^8.4.0",
33
33
  "typescript": "^5.8.2",
34
34
  "vitest": "^3.0.9",
35
- "@internal/lint": "0.0.0-vnext-inngest-20250506132005"
35
+ "@internal/lint": "0.0.0-vnext-inngest-20250508110322"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting",
@@ -3,10 +3,11 @@
3
3
  // The tests will automatically start and configure the required Couchbase container.
4
4
 
5
5
  import { execSync } from 'child_process';
6
+ import { randomUUID } from 'crypto';
6
7
  import axios from 'axios';
7
8
  import type { Cluster, Bucket, Scope, Collection } from 'couchbase';
8
9
  import { connect } from 'couchbase';
9
- import { describe, it, expect, beforeAll, afterAll } from 'vitest';
10
+ import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest';
10
11
  import { CouchbaseVector, DISTANCE_MAPPING } from './index';
11
12
 
12
13
  const containerName = 'mastra_couchbase_testing';
@@ -431,6 +432,66 @@ describe('Integration Testing CouchbaseVector', async () => {
431
432
  }),
432
433
  ).rejects.toThrow('No vectors provided');
433
434
  }, 50000);
435
+
436
+ it('should handle non-existent index queries', async () => {
437
+ await expect(
438
+ couchbase_client.query({ indexName: 'non-existent-index', queryVector: [1, 2, 3] }),
439
+ ).rejects.toThrow();
440
+ }, 50000);
441
+
442
+ it('should handle duplicate index creation gracefully', async () => {
443
+ const duplicateIndexName = `duplicate-test-${randomUUID()}`;
444
+ const dimension = 768;
445
+ const infoSpy = vi.spyOn(couchbase_client['logger'], 'info');
446
+ const warnSpy = vi.spyOn(couchbase_client['logger'], 'warn');
447
+
448
+ try {
449
+ // Create index first time
450
+ await couchbase_client.createIndex({
451
+ indexName: duplicateIndexName,
452
+ dimension,
453
+ metric: 'cosine',
454
+ });
455
+
456
+ // Try to create with same dimensions - should not throw
457
+ await expect(
458
+ couchbase_client.createIndex({
459
+ indexName: duplicateIndexName,
460
+ dimension,
461
+ metric: 'cosine',
462
+ }),
463
+ ).resolves.not.toThrow();
464
+
465
+ expect(infoSpy).toHaveBeenCalledWith(expect.stringContaining('already exists with'));
466
+
467
+ // Try to create with same dimensions and different metric - should not throw
468
+ await expect(
469
+ couchbase_client.createIndex({
470
+ indexName: duplicateIndexName,
471
+ dimension,
472
+ metric: 'euclidean',
473
+ }),
474
+ ).resolves.not.toThrow();
475
+
476
+ expect(warnSpy).toHaveBeenCalledWith(expect.stringContaining('Attempted to create index with metric'));
477
+
478
+ // Try to create with different dimensions - should throw
479
+ await expect(
480
+ couchbase_client.createIndex({
481
+ indexName: duplicateIndexName,
482
+ dimension: dimension + 1,
483
+ metric: 'cosine',
484
+ }),
485
+ ).rejects.toThrow(
486
+ `Index "${duplicateIndexName}" already exists with ${dimension} dimensions, but ${dimension + 1} dimensions were requested`,
487
+ );
488
+ } finally {
489
+ infoSpy.mockRestore();
490
+ warnSpy.mockRestore();
491
+ // Cleanup
492
+ await couchbase_client.deleteIndex(duplicateIndexName);
493
+ }
494
+ }, 50000);
434
495
  });
435
496
 
436
497
  describe('Vector Dimension Tracking', () => {
@@ -84,81 +84,92 @@ export class CouchbaseVector extends MastraVector {
84
84
  throw new Error('Dimension must be a positive integer');
85
85
  }
86
86
 
87
- await this.scope.searchIndexes().upsertIndex({
88
- name: indexName,
89
- sourceName: this.bucketName,
90
- type: 'fulltext-index',
91
- params: {
92
- doc_config: {
93
- docid_prefix_delim: '',
94
- docid_regexp: '',
95
- mode: 'scope.collection.type_field',
96
- type_field: 'type',
97
- },
98
- mapping: {
99
- default_analyzer: 'standard',
100
- default_datetime_parser: 'dateTimeOptional',
101
- default_field: '_all',
102
- default_mapping: {
103
- dynamic: true,
104
- enabled: false,
87
+ try {
88
+ await this.scope.searchIndexes().upsertIndex({
89
+ name: indexName,
90
+ sourceName: this.bucketName,
91
+ type: 'fulltext-index',
92
+ params: {
93
+ doc_config: {
94
+ docid_prefix_delim: '',
95
+ docid_regexp: '',
96
+ mode: 'scope.collection.type_field',
97
+ type_field: 'type',
105
98
  },
106
- default_type: '_default',
107
- docvalues_dynamic: true, // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
108
- index_dynamic: true,
109
- store_dynamic: true, // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
110
- type_field: '_type',
111
- types: {
112
- [`${this.scopeName}.${this.collectionName}`]: {
99
+ mapping: {
100
+ default_analyzer: 'standard',
101
+ default_datetime_parser: 'dateTimeOptional',
102
+ default_field: '_all',
103
+ default_mapping: {
113
104
  dynamic: true,
114
- enabled: true,
115
- properties: {
116
- embedding: {
117
- enabled: true,
118
- fields: [
119
- {
120
- dims: dimension,
121
- index: true,
122
- name: 'embedding',
123
- similarity: DISTANCE_MAPPING[metric],
124
- type: 'vector',
125
- vector_index_optimized_for: 'recall',
126
- store: true, // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
127
- docvalues: true, // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
128
- include_term_vectors: true, // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
129
- },
130
- ],
131
- },
132
- content: {
133
- enabled: true,
134
- fields: [
135
- {
136
- index: true,
137
- name: 'content',
138
- store: true,
139
- type: 'text',
140
- },
141
- ],
105
+ enabled: false,
106
+ },
107
+ default_type: '_default',
108
+ docvalues_dynamic: true, // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
109
+ index_dynamic: true,
110
+ store_dynamic: true, // [Doc](https://docs.couchbase.com/server/current/search/search-index-params.html#params) mentions this attribute is required for vector search to return the indexed field
111
+ type_field: '_type',
112
+ types: {
113
+ [`${this.scopeName}.${this.collectionName}`]: {
114
+ dynamic: true,
115
+ enabled: true,
116
+ properties: {
117
+ embedding: {
118
+ enabled: true,
119
+ fields: [
120
+ {
121
+ dims: dimension,
122
+ index: true,
123
+ name: 'embedding',
124
+ similarity: DISTANCE_MAPPING[metric],
125
+ type: 'vector',
126
+ vector_index_optimized_for: 'recall',
127
+ store: true, // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
128
+ docvalues: true, // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
129
+ include_term_vectors: true, // CHANGED due to https://docs.couchbase.com/server/current/search/search-index-params.html#fields
130
+ },
131
+ ],
132
+ },
133
+ content: {
134
+ enabled: true,
135
+ fields: [
136
+ {
137
+ index: true,
138
+ name: 'content',
139
+ store: true,
140
+ type: 'text',
141
+ },
142
+ ],
143
+ },
142
144
  },
143
145
  },
144
146
  },
145
147
  },
148
+ store: {
149
+ indexType: 'scorch',
150
+ segmentVersion: 16,
151
+ },
146
152
  },
147
- store: {
148
- indexType: 'scorch',
149
- segmentVersion: 16,
153
+ sourceUuid: '',
154
+ sourceParams: {},
155
+ sourceType: 'gocbcore',
156
+ planParams: {
157
+ maxPartitionsPerPIndex: 64,
158
+ indexPartitions: 16,
159
+ numReplicas: 0,
150
160
  },
151
- },
152
- sourceUuid: '',
153
- sourceParams: {},
154
- sourceType: 'gocbcore',
155
- planParams: {
156
- maxPartitionsPerPIndex: 64,
157
- indexPartitions: 16,
158
- numReplicas: 0,
159
- },
160
- });
161
- this.vector_dimension = dimension;
161
+ });
162
+ this.vector_dimension = dimension;
163
+ } catch (error: any) {
164
+ // Check for 'already exists' error (Couchbase may throw a 400 or 409, or have a message)
165
+ const message = error?.message || error?.toString();
166
+ if (message && message.toLowerCase().includes('index exists')) {
167
+ // Fetch index info and check dimension
168
+ await this.validateExistingIndex(indexName, dimension, metric);
169
+ return;
170
+ }
171
+ throw error;
172
+ }
162
173
  }
163
174
 
164
175
  async upsert(params: UpsertVectorParams): Promise<string[]> {