@mastra/couchbase 1.1.2-alpha.0 → 1.1.2

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/README.md CHANGED
@@ -2,277 +2,37 @@
2
2
 
3
3
  A Mastra vector store implementation for Couchbase, enabling powerful vector similarity search capabilities using the official Couchbase Node.js SDK (v4+). Leverages Couchbase Server's built-in Vector Search feature (available in version 7.6.4+).
4
4
 
5
- ## Features
6
-
7
- - 🚀 Vector similarity search powered by Couchbase Search Service.
8
- - 📐 Supports Cosine, Euclidean (L2 Norm), and Dot Product distance metrics.
9
- - 📄 Stores vectors and associated metadata within Couchbase documents in a specified Collection.
10
- - 🔧 Manages Couchbase Search Indexes specifically configured for vector search (Create, List, Describe, Delete).
11
- - 🆔 Automatic UUID generation for documents if IDs are not provided during upsert.
12
- - ☁️ Compatible with both self-hosted Couchbase Server (7.6.4+) and Couchbase Capella.
13
- - ⚙️ Uses the official Couchbase Node.js SDK v4+.
14
- - 📈 Built-in telemetry support for tracing operations via `@mastra/core`.
15
-
16
- ## Prerequisites
17
-
18
- - Couchbase Server (Version 7.6.4 or higher) or Couchbase Capella cluster with the **Search Service** enabled.
19
- - A configured **Bucket**, **Scope**, and **Collection** within your Couchbase cluster where vectors and metadata will be stored.
20
- - Couchbase user credentials (`username`, `password`) with permissions to ([Docs](https://docs.couchbase.com/cloud/get-started/connect.html#prerequisites)):
21
- - Connect to the cluster.
22
- - Read/write documents in the specified Collection (`kv` role usually covers this).
23
- - Manage Search Indexes (`search_admin` role on the relevant bucket/scope).
24
- - Node.js 22.13.0 or later.
25
-
26
5
  ## Installation
27
6
 
28
7
  ```bash
29
8
  npm install @mastra/couchbase
30
- # or using pnpm
31
- pnpm add @mastra/couchbase
32
- # or using yarn
33
- yarn add @mastra/couchbase
34
9
  ```
35
10
 
36
- ## Getting Started: A Quick Tutorial
11
+ ## Usage
37
12
 
38
- Let's set up `@mastra/couchbase` to store and search vectors in your Couchbase cluster.
39
-
40
- **Step 1: Connect to Your Cluster**
41
-
42
- Instantiate `CouchbaseVector` with your cluster details.
13
+ Configure the database credentials required by your provider.
43
14
 
44
15
  ```typescript
45
16
  import { CouchbaseVector } from '@mastra/couchbase';
46
17
 
47
- const connectionString = 'couchbases://your_cluster_host?ssl=no_verify'; // Use couchbases:// for Capella/TLS, couchbase:// for local/non-TLS
48
- const username = 'your_couchbase_user';
49
- const password = 'your_couchbase_password';
50
- const bucketName = 'your_vector_bucket';
51
- const scopeName = '_default'; // Or your custom scope name
52
- const collectionName = 'vector_data'; // Or your custom collection name
53
-
54
18
  const vectorStore = new CouchbaseVector({
55
- connectionString,
56
- username,
57
- password,
58
- bucketName,
59
- scopeName,
60
- collectionName,
19
+ connectionString: process.env.COUCHBASE_CONNECTION_STRING!,
20
+ username: process.env.COUCHBASE_USERNAME!,
21
+ password: process.env.COUCHBASE_PASSWORD!,
22
+ bucketName: 'vectors',
23
+ scopeName: '_default',
24
+ collectionName: 'documents',
61
25
  });
62
-
63
- console.log('CouchbaseVector instance created. Connecting...');
64
- ```
65
-
66
- _Note_: The actual connection to Couchbase happens lazily upon the first operation.
67
-
68
- **Step 2: Create a Vector Search Index**
69
-
70
- Define and create a Search Index specifically for vector search on your collection.
71
-
72
- ```typescript
73
- const indexName = 'my_vector_search_index';
74
- const vectorDimension = 1536; // Example: OpenAI embedding dimension
75
-
76
- try {
77
- await vectorStore.createIndex({
78
- indexName: indexName,
79
- dimension: vectorDimension,
80
- metric: 'cosine', // Or 'euclidean', 'dotproduct'
81
- });
82
- console.log(`Search index '${indexName}' created or updated successfully.`);
83
- } catch (error) {
84
- console.error(`Failed to create index '${indexName}':`, error);
85
- }
86
- ```
87
-
88
- _Note_: Index creation in Couchbase is asynchronous. It might take a short while for the index to become fully built and queryable.
89
-
90
- _Best practice_: Implement a delay or polling mechanism to ensure the index is ready using simple delay approach (`await new Promise(resolve => setTimeout(resolve, 2000));`) or implement a more robust solution that polls the index status
91
-
92
- **Step 3: Add Your Vectors (Upsert Documents)**
93
-
94
- Store your vectors and metadata as documents in the designated Couchbase collection.
95
-
96
- ```typescript
97
- const vectors = [
98
- Array(vectorDimension).fill(0.1), // Replace with your actual vectors
99
- Array(vectorDimension).fill(0.2),
100
- ];
101
- const metadata = [
102
- { source: 'doc1.txt', page: 1, category: 'finance' },
103
- { source: 'doc2.pdf', page: 5, text: 'This is the text content.', category: 'tech' }, // Example with text
104
- ];
105
-
106
- try {
107
- // IDs will be auto-generated UUIDs if not provided
108
- const ids = await vectorStore.upsert({
109
- indexName: indexName, // Required for dimension validation if tracked
110
- vectors: vectors,
111
- metadata: metadata,
112
- // ids: ['custom_id_1', 'custom_id_2'] // Optionally provide your own IDs
113
- });
114
- console.log('Upserted documents with IDs:', ids);
115
- } catch (error) {
116
- console.error('Failed to upsert vectors:', error);
117
- }
118
- ```
119
-
120
- _Note_: For large vector batches, Couchbase may need time to process and index all documents. Consider implementing appropriate waiting periods before querying newly inserted vectors like a simple delay (`await new Promise(resolve => setTimeout(resolve, 1000));`) for smaller batches
121
-
122
- Document structure in Couchbase will resemble:
123
-
124
- ```
125
- Document ID: <generated_or_provided_id>
126
- {
127
- "embedding": [0.1, ...],
128
- "metadata": { "source": "doc1.txt", "page": 1, "category": "finance" }
129
- }
130
26
  ```
131
27
 
132
- ```
133
- Document ID: <generated_or_provided_id>
134
- {
135
- "embedding": [0.2, ...],
136
- "metadata": { "source": "doc2.pdf", "page": 5, "text": "...", "category": "tech" },
137
- "content": "This is the text content." // 'content' field added if metadata.text exists
138
- }
139
- ```
140
-
141
- **Step 4: Find Similar Vectors (Query the Index)**
142
-
143
- Use the Search Index to find documents with vectors similar to your query vector.
144
-
145
- ```typescript
146
- const queryVector = Array(vectorDimension).fill(0.15); // Your query vector
147
- const k = 5; // Number of nearest neighbors to retrieve
148
- try {
149
- const results = await vectorStore.query({
150
- indexName: indexName,
151
- queryVector: queryVector,
152
- topK: k,
153
- });
154
- console.log(`Found ${results.length} similar results:`, results);
155
- } catch (error) {
156
- console.error('Failed to query vectors:', error);
157
- }
158
- ```
159
-
160
- _Note_: Metadata `filter` and `includeVector` not yet supported in `query()`
161
-
162
- Results format:
163
-
164
- ```
165
- [
166
- {
167
- id: string, // Document ID
168
- score: number, // Similarity score (higher is better for cosine/dotproduct, lower for euclidean)
169
- metadata: Record<string, any> // Fields stored in the index (typically includes 'metadata', 'content')
170
- },
171
- // ... more results
172
- ]
173
- ```
174
-
175
- **Step 5: Manage Indexes**
176
-
177
- List, inspect, or delete your vector search indexes.
178
-
179
- ```typescript
180
- try {
181
- // List all Search Indexes in the cluster (may include non-vector indexes)
182
- const indexes = await vectorStore.listIndexes();
183
- console.log('Available search indexes:', indexes);
184
- // Get details about our specific vector index
185
- for (const indexName of indexes) {
186
- const stats = await vectorStore.describeIndex(indexName);
187
- console.log(`Stats for index '${indexName}':`, stats);
188
- }
189
- // Delete the index when no longer needed
190
- await vectorStore.deleteIndex(indexName);
191
- console.log(`Search index '${indexName}' deleted.`);
192
- } catch (error) {
193
- console.error('Failed to manage indexes:', error);
194
- }
195
- ```
196
-
197
- _Note_: Deleting Index does NOT delete the vectors in the associated Couchbase Collection
198
-
199
- ## Advanced Couchbase Vector Usage
200
-
201
- - **Distance Metrics Mapping:**
202
- - The `metric` parameter in `createIndex` and `describeIndex` uses Mastra terms. These map to Couchbase index definitions as follows:
203
- - `cosine` → `cosine`
204
- - `euclidean` → `l2_norm`
205
- - `dotproduct` → `dot_product`
206
- - **Index Definition Details:**
207
- - The `createIndex` method constructs a Couchbase Search Index definition tailored for vector search. It indexes the `embedding` field (as type `vector`) and the `content` field (as type `text`), targeting documents within the specified `scopeName.collectionName`. It enables `store` and `docvalues` for these fields. For fine-grained control over the index definition (e.g., different analyzers, type mappings), you would need to use the Couchbase SDK or UI directly.
208
- - **Document Structure:**
209
- - Vectors are stored in the `embedding` field.
210
- - Metadata is stored in the `metadata` field.
211
- - If `metadata.text` exists, it's copied to the `content` field.
212
- - The `query` results currently return stored fields like `metadata` and `content` in the `metadata` property of the result object, but **not** the `embedding` field itself.
213
-
214
- ## API Reference (`CouchbaseVector` Methods)
215
-
216
- - `constructor(cnn_string, username, password, bucketName, scopeName, collectionName)`: Creates a new instance and prepares the connection promise.
217
- - `getCollection()`: (Primarily internal) Establishes connection lazily and gets the Couchbase `Collection` object.
218
- - `createIndex({ indexName, dimension, metric? })`: Creates or updates a Couchbase Search Index configured for vector search on the collection.
219
- - `upsert({ indexName, vectors, metadata?, ids? })`: Upserts documents containing vectors and metadata into the Couchbase collection. Returns the document IDs used.
220
- - `query({ indexName, queryVector, topK?, filter?, includeVector? })`: Queries the specified Search Index for similar vectors using Couchbase Vector Search. **Note:** `filter` and `includeVector` options are **not currently supported**.
221
- - `updateVector({ indexName, id, update })`: Updates a specific vector entry by its ID with new vector data and/or metadata. **Note:** Filter-based updates are not yet implemented.
222
- - `deleteVector({ indexName, id })`: Deletes a single vector by its ID.
223
- - `deleteVectors({ indexName, ids })`: Deletes multiple vectors by their IDs. **Note:** Filter-based deletion is not yet implemented.
224
- - `listIndexes()`: Lists the names of all Search Indexes in the cluster. Returns fully qualified names (e.g., `bucket.scope.index`).
225
- - `describeIndex({ indexName })`: Gets the configured dimension, metric (Mastra name), and document count for a specific Search Index (using its short name).
226
- - `deleteIndex({ indexName })`: Deletes a Search Index (using its short name).
227
- - `disconnect()`: Closes the Couchbase client connection. Should be called when done using the store.
228
-
229
- ## Configuration Details
230
-
231
- - **Required Constructor Parameters:**
232
- - `cnn_string`: Couchbase connection string (e.g., `couchbases://host?ssl=no_verify`, `couchbase://localhost`). See [Couchbase SDK Docs](https://docs.couchbase.com/nodejs-sdk/current/hello-world/connect.html) for all options.
233
- - `username`: Couchbase user with necessary permissions (see Prerequisites).
234
- - `password`: Password for the Couchbase user.
235
- - `bucketName`: Name of the target Couchbase Bucket.
236
- - `scopeName`: Name of the target Scope within the Bucket.
237
- - `collectionName`: Name of the target Collection within the Scope.
238
- - **Internal Connection Profile:** The library internally uses the `wanDevelopment` configuration profile when connecting via the Couchbase SDK. This profile adjusts certain timeouts suitable for development and some cloud environments. For production tuning, consider modifying the library or managing the SDK connection externally.
239
-
240
- ## Notes & Considerations
241
-
242
- - **Couchbase Version:** This integration requires **Couchbase Server 7.6.4+** or a compatible Couchbase Capella cluster with the **Search Service enabled**.
243
- - **Index Creation:** The `createIndex` method defines and creates/updates a Couchbase Search index configured for vector search. Index creation in Couchbase is asynchronous; allow a short time after creation before querying, especially on larger datasets.
244
- - **Data Storage:** Vectors and metadata are stored together as fields within standard Couchbase documents in the specified Collection.
245
- - The default field name for the vector embedding is `"embedding"`.
246
- - The default field name for metadata is `"metadata"`.
247
- - If `metadata` contains a `text` property, its value is also copied to a top-level `"content"` field in the document, which is indexed by the Search index created by this library.
248
- - **Upsert Independence:** The `upsert` operation adds/modifies documents directly in the Collection. It **does not depend on the Search index** existing at the time of upsert. You can insert data before or after creating the index. Couchbase allows multiple Search indexes over the same Collection data.
249
- - **Dimension Validation:**
250
- - This library _attempts_ to track the dimension specified during the last `createIndex` call within the same `CouchbaseVector` instance. If tracked, it performs a basic length check during `upsert`.
251
- - However, Couchbase itself **does not enforce vector dimensions at data ingest time**. Upserting a vector with a dimension different from what an index expects **will not cause an error during `upsert`**. Errors related to dimension mismatches will typically occur only during the `query` operation against that specific index.
252
- - **Asynchronous Operations & Consistency:** Be mindful of the asynchronous nature of index building and potential replication delays in Couchbase, especially in multi-node clusters. Add appropriate checks or delays in your application logic if immediate consistency after writes is required for subsequent queries.
253
- - **Index Creation Delays:** After creating a vector search index, allow sufficient time (typically 1-5 seconds for small datasets, longer for larger ones) before querying against it. The delay needed depends on data volume, cluster resources, and replication settings.
254
- - **Vector Insertion Processing:** When upserting large batches of vectors, the documents may not be immediately queryable. Consider implementing appropriate wait times or retry mechanisms when performing queries immediately after bulk inserts.
255
- - **Production Considerations:** For production environments, implement a more robust polling mechanism to check index status rather than fixed timeouts.
256
- - **Current Limitations:**
257
- - **Metadata Filtering:** The `filter` parameter in the `query` method is **not yet supported** by this library. Filtering must be done client-side after retrieving results or by using the Couchbase SDK's Search capabilities directly for more complex queries.
258
- - **Returning Vectors:** The `includeVector: true` option in the `query` method is **not yet supported**. To retrieve the vector embedding, you must fetch the full document using its ID (returned in the query results) via the Couchbase SDK's Key-Value operations (`collection.get(id)`).
259
- - **Index Count:** The `describeIndex` method currently **returns -1 for the count** of indexed documents. Use Couchbase tools (UI, CLI, SQL++ query on the collection, Search API) for accurate index statistics.
260
-
261
- ## Related Links
262
-
263
- - [Couchbase Vector Search Documentation](https://docs.couchbase.com/cloud/vector-search/vector-search.html)
264
- - [Couchbase Node.js SDK Documentation](https://docs.couchbase.com/nodejs-sdk/current/hello-world/start-using-sdk.html)
265
- - [Couchbase Query Language (SQL++) for working with documents](https://docs.couchbase.com/server/current/n1ql/n1ql-language-reference/index.html)
266
- - [Couchbase Search Service API / Index Definition](https://docs.couchbase.com/cloud/search/search-index-params.html)
28
+ ## Documentation
267
29
 
268
- ---
30
+ - [@mastra/couchbase documentation](https://mastra.ai/reference/vectors/couchbase)
269
31
 
270
- ## 📢 Support Policy
32
+ ## Changelog
271
33
 
272
- We truly appreciate your interest in this project!
273
- This project is **community-maintained**, which means it's **not officially supported** by our support team.
34
+ See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/stores/couchbase/CHANGELOG.md) for version history and release notes.
274
35
 
275
- If you need help, have found a bug, or want to contribute improvements, the best place to do that is right here — by [opening a GitHub issue](https://github.com/mastra-ai/mastra/issues) (Update this link to your project's issue tracker!).
276
- Our support portal is unable to assist with requests related to this project, so we kindly ask that all inquiries stay within GitHub.
36
+ ## Support
277
37
 
278
- Your collaboration helps us all move forward together thank you!
38
+ We have an [open community Discord](https://discord.gg/mastra-ai). Come and say hello and let us know if you have any questions or need any help getting things running.
@@ -3,7 +3,7 @@ name: mastra-couchbase
3
3
  description: Documentation for @mastra/couchbase. Use when working with @mastra/couchbase APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/couchbase"
6
- version: "1.1.2-alpha.0"
6
+ version: "1.1.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.1.2-alpha.0",
2
+ "version": "1.1.2",
3
3
  "package": "@mastra/couchbase",
4
4
  "exports": {},
5
5
  "modules": {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/couchbase",
3
- "version": "1.1.2-alpha.0",
3
+ "version": "1.1.2",
4
4
  "description": "Couchbase vector store provider for Mastra",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,10 +30,10 @@
30
30
  "tsx": "^4.23.1",
31
31
  "typescript": "^7.0.2",
32
32
  "vitest": "4.1.10",
33
- "@internal/lint": "0.0.129",
34
- "@internal/storage-test-utils": "0.0.125",
35
- "@internal/types-builder": "0.0.104",
36
- "@mastra/core": "1.64.0-alpha.2"
33
+ "@internal/lint": "0.0.130",
34
+ "@internal/storage-test-utils": "0.0.126",
35
+ "@internal/types-builder": "0.0.105",
36
+ "@mastra/core": "1.64.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "@mastra/core": ">=1.0.0-0 <2.0.0-0"