@mastra/convex 1.0.3 → 1.0.4-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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @mastra/convex
2
2
 
3
+ ## 1.0.4-alpha.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Add a clear runtime error when `queryVector` is omitted for vector stores that require a vector for queries. Previously, omitting `queryVector` would produce confusing SDK-level errors; now each store throws a structured `MastraError` with `ErrorCategory.USER` explaining that metadata-only queries are not supported by that backend. ([#13286](https://github.com/mastra-ai/mastra/pull/13286))
8
+
9
+ - Updated dependencies [[`df170fd`](https://github.com/mastra-ai/mastra/commit/df170fd139b55f845bfd2de8488b16435bd3d0da), [`ae55343`](https://github.com/mastra-ai/mastra/commit/ae5534397fc006fd6eef3e4f80c235bcdc9289ef), [`c290cec`](https://github.com/mastra-ai/mastra/commit/c290cec5bf9107225de42942b56b487107aa9dce), [`f03e794`](https://github.com/mastra-ai/mastra/commit/f03e794630f812b56e95aad54f7b1993dc003add), [`aa4a5ae`](https://github.com/mastra-ai/mastra/commit/aa4a5aedb80d8d6837bab8cbb2e301215d1ba3e9), [`de3f584`](https://github.com/mastra-ai/mastra/commit/de3f58408752a8d80a295275c7f23fc306cf7f4f), [`d3fb010`](https://github.com/mastra-ai/mastra/commit/d3fb010c98f575f1c0614452667396e2653815f6), [`702ee1c`](https://github.com/mastra-ai/mastra/commit/702ee1c41be67cc532b4dbe89bcb62143508f6f0), [`f495051`](https://github.com/mastra-ai/mastra/commit/f495051eb6496a720f637fc85b6d69941c12554c), [`e622f1d`](https://github.com/mastra-ai/mastra/commit/e622f1d3ab346a8e6aca6d1fe2eac99bd961e50b), [`861f111`](https://github.com/mastra-ai/mastra/commit/861f11189211b20ddb70d8df81a6b901fc78d11e), [`00f43e8`](https://github.com/mastra-ai/mastra/commit/00f43e8e97a80c82b27d5bd30494f10a715a1df9), [`1b6f651`](https://github.com/mastra-ai/mastra/commit/1b6f65127d4a0d6c38d0a1055cb84527db529d6b), [`96a1702`](https://github.com/mastra-ai/mastra/commit/96a1702ce362c50dda20c8b4a228b4ad1a36a17a), [`cb9f921`](https://github.com/mastra-ai/mastra/commit/cb9f921320913975657abb1404855d8c510f7ac5), [`114e7c1`](https://github.com/mastra-ai/mastra/commit/114e7c146ac682925f0fb37376c1be70e5d6e6e5), [`1b6f651`](https://github.com/mastra-ai/mastra/commit/1b6f65127d4a0d6c38d0a1055cb84527db529d6b), [`72df4a8`](https://github.com/mastra-ai/mastra/commit/72df4a8f9bf1a20cfd3d9006a4fdb597ad56d10a)]:
10
+ - @mastra/core@1.8.0-alpha.0
11
+
3
12
  ## 1.0.3
4
13
 
5
14
  ### Patch Changes
@@ -3,7 +3,7 @@ name: mastra-convex
3
3
  description: Documentation for @mastra/convex. Use when working with @mastra/convex APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/convex"
6
- version: "1.0.3"
6
+ version: "1.0.4-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.0.3",
2
+ "version": "1.0.4-alpha.0",
3
3
  "package": "@mastra/convex",
4
4
  "exports": {
5
5
  "mastraStorage": {
@@ -41,7 +41,7 @@ Before using `ConvexStore`, you need to set up the Convex schema and storage han
41
41
  In `convex/schema.ts`:
42
42
 
43
43
  ```typescript
44
- import { defineSchema } from 'convex/server';
44
+ import { defineSchema } from 'convex/server'
45
45
  import {
46
46
  mastraThreadsTable,
47
47
  mastraMessagesTable,
@@ -51,7 +51,7 @@ import {
51
51
  mastraVectorIndexesTable,
52
52
  mastraVectorsTable,
53
53
  mastraDocumentsTable,
54
- } from '@mastra/convex/schema';
54
+ } from '@mastra/convex/schema'
55
55
 
56
56
  export default defineSchema({
57
57
  mastra_threads: mastraThreadsTable,
@@ -62,7 +62,7 @@ export default defineSchema({
62
62
  mastra_vector_indexes: mastraVectorIndexesTable,
63
63
  mastra_vectors: mastraVectorsTable,
64
64
  mastra_documents: mastraDocumentsTable,
65
- });
65
+ })
66
66
  ```
67
67
 
68
68
  ### 2. Create the Storage Handler
@@ -70,9 +70,9 @@ export default defineSchema({
70
70
  In `convex/mastra/storage.ts`:
71
71
 
72
72
  ```typescript
73
- import { mastraStorage } from '@mastra/convex/server';
73
+ import { mastraStorage } from '@mastra/convex/server'
74
74
 
75
- export const handle = mastraStorage;
75
+ export const handle = mastraStorage
76
76
  ```
77
77
 
78
78
  ### 3. Deploy to Convex
@@ -86,13 +86,13 @@ npx convex deploy
86
86
  ## Usage
87
87
 
88
88
  ```typescript
89
- import { ConvexStore } from "@mastra/convex";
89
+ import { ConvexStore } from '@mastra/convex'
90
90
 
91
91
  const storage = new ConvexStore({
92
92
  id: 'convex-storage',
93
93
  deploymentUrl: process.env.CONVEX_URL!,
94
94
  adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
95
- });
95
+ })
96
96
  ```
97
97
 
98
98
  ## Parameters
@@ -106,22 +106,22 @@ const storage = new ConvexStore({
106
106
  ## Constructor Examples
107
107
 
108
108
  ```ts
109
- import { ConvexStore } from "@mastra/convex";
109
+ import { ConvexStore } from '@mastra/convex'
110
110
 
111
111
  // Basic configuration
112
112
  const store = new ConvexStore({
113
113
  id: 'convex-storage',
114
- deploymentUrl: "https://your-project.convex.cloud",
115
- adminAuthToken: "your-admin-token",
116
- });
114
+ deploymentUrl: 'https://your-project.convex.cloud',
115
+ adminAuthToken: 'your-admin-token',
116
+ })
117
117
 
118
118
  // With custom storage function path
119
119
  const storeCustom = new ConvexStore({
120
120
  id: 'convex-storage',
121
- deploymentUrl: "https://your-project.convex.cloud",
122
- adminAuthToken: "your-admin-token",
123
- storageFunction: "custom/path:handler",
124
- });
121
+ deploymentUrl: 'https://your-project.convex.cloud',
122
+ adminAuthToken: 'your-admin-token',
123
+ storageFunction: 'custom/path:handler',
124
+ })
125
125
  ```
126
126
 
127
127
  ## Additional Notes
@@ -45,13 +45,13 @@ Before using `ConvexVector`, you need to set up the Convex schema and storage ha
45
45
  ### Basic Configuration
46
46
 
47
47
  ```ts
48
- import { ConvexVector } from "@mastra/convex";
48
+ import { ConvexVector } from '@mastra/convex'
49
49
 
50
50
  const vectorStore = new ConvexVector({
51
51
  id: 'convex-vectors',
52
- deploymentUrl: "https://your-project.convex.cloud",
53
- adminAuthToken: "your-admin-token",
54
- });
52
+ deploymentUrl: 'https://your-project.convex.cloud',
53
+ adminAuthToken: 'your-admin-token',
54
+ })
55
55
  ```
56
56
 
57
57
  ### Custom Storage Function
@@ -59,10 +59,10 @@ const vectorStore = new ConvexVector({
59
59
  ```ts
60
60
  const vectorStore = new ConvexVector({
61
61
  id: 'convex-vectors',
62
- deploymentUrl: "https://your-project.convex.cloud",
63
- adminAuthToken: "your-admin-token",
64
- storageFunction: "custom/path:handler",
65
- });
62
+ deploymentUrl: 'https://your-project.convex.cloud',
63
+ adminAuthToken: 'your-admin-token',
64
+ storageFunction: 'custom/path:handler',
65
+ })
66
66
  ```
67
67
 
68
68
  ## Methods
@@ -77,9 +77,9 @@ const vectorStore = new ConvexVector({
77
77
 
78
78
  ```typescript
79
79
  await vectorStore.createIndex({
80
- indexName: "my_vectors",
80
+ indexName: 'my_vectors',
81
81
  dimension: 1536,
82
- });
82
+ })
83
83
  ```
84
84
 
85
85
  ### upsert()
@@ -127,7 +127,7 @@ const results = await vectorStore.query({
127
127
  Returns an array of index names as strings.
128
128
 
129
129
  ```typescript
130
- const indexes = await vectorStore.listIndexes();
130
+ const indexes = await vectorStore.listIndexes()
131
131
  // ["my_vectors", "embeddings", ...]
132
132
  ```
133
133
 
@@ -139,9 +139,9 @@ Returns:
139
139
 
140
140
  ```typescript
141
141
  interface IndexStats {
142
- dimension: number;
143
- count: number;
144
- metric: "cosine" | "euclidean" | "dotproduct";
142
+ dimension: number
143
+ count: number
144
+ metric: 'cosine' | 'euclidean' | 'dotproduct'
145
145
  }
146
146
  ```
147
147
 
@@ -152,7 +152,7 @@ interface IndexStats {
152
152
  Deletes the index and all its vectors.
153
153
 
154
154
  ```typescript
155
- await vectorStore.deleteIndex({ indexName: "my_vectors" });
155
+ await vectorStore.deleteIndex({ indexName: 'my_vectors' })
156
156
  ```
157
157
 
158
158
  ### updateVector()
@@ -170,22 +170,22 @@ Update a single vector by ID or by metadata filter. Either `id` or `filter` must
170
170
  ```typescript
171
171
  // Update by ID
172
172
  await vectorStore.updateVector({
173
- indexName: "my_vectors",
174
- id: "vector123",
173
+ indexName: 'my_vectors',
174
+ id: 'vector123',
175
175
  update: {
176
176
  vector: [0.1, 0.2, 0.3],
177
- metadata: { label: "updated" },
177
+ metadata: { label: 'updated' },
178
178
  },
179
- });
179
+ })
180
180
 
181
181
  // Update by filter
182
182
  await vectorStore.updateVector({
183
- indexName: "my_vectors",
184
- filter: { category: "product" },
183
+ indexName: 'my_vectors',
184
+ filter: { category: 'product' },
185
185
  update: {
186
- metadata: { status: "reviewed" },
186
+ metadata: { status: 'reviewed' },
187
187
  },
188
- });
188
+ })
189
189
  ```
190
190
 
191
191
  ### deleteVector()
@@ -195,7 +195,7 @@ await vectorStore.updateVector({
195
195
  **id:** (`string`): ID of the vector to delete
196
196
 
197
197
  ```typescript
198
- await vectorStore.deleteVector({ indexName: "my_vectors", id: "vector123" });
198
+ await vectorStore.deleteVector({ indexName: 'my_vectors', id: 'vector123' })
199
199
  ```
200
200
 
201
201
  ### deleteVectors()
@@ -211,15 +211,15 @@ Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` m
211
211
  ```typescript
212
212
  // Delete by IDs
213
213
  await vectorStore.deleteVectors({
214
- indexName: "my_vectors",
215
- ids: ["vec1", "vec2", "vec3"],
216
- });
214
+ indexName: 'my_vectors',
215
+ ids: ['vec1', 'vec2', 'vec3'],
216
+ })
217
217
 
218
218
  // Delete by filter
219
219
  await vectorStore.deleteVectors({
220
- indexName: "my_vectors",
221
- filter: { status: "archived" },
222
- });
220
+ indexName: 'my_vectors',
221
+ filter: { status: 'archived' },
222
+ })
223
223
  ```
224
224
 
225
225
  ## Response Types
@@ -228,10 +228,10 @@ Query results are returned in this format:
228
228
 
229
229
  ```typescript
230
230
  interface QueryResult {
231
- id: string;
232
- score: number;
233
- metadata: Record<string, any>;
234
- vector?: number[]; // Only included if includeVector is true
231
+ id: string
232
+ score: number
233
+ metadata: Record<string, any>
234
+ vector?: number[] // Only included if includeVector is true
235
235
  }
236
236
  ```
237
237
 
@@ -242,32 +242,29 @@ ConvexVector supports metadata filtering with various operators:
242
242
  ```typescript
243
243
  // Simple equality
244
244
  const results = await vectorStore.query({
245
- indexName: "my_vectors",
245
+ indexName: 'my_vectors',
246
246
  queryVector: embedding,
247
- filter: { category: "documents" },
248
- });
247
+ filter: { category: 'documents' },
248
+ })
249
249
 
250
250
  // Comparison operators
251
251
  const results = await vectorStore.query({
252
- indexName: "my_vectors",
252
+ indexName: 'my_vectors',
253
253
  queryVector: embedding,
254
254
  filter: {
255
255
  price: { $gt: 100 },
256
- status: { $in: ["active", "pending"] },
256
+ status: { $in: ['active', 'pending'] },
257
257
  },
258
- });
258
+ })
259
259
 
260
260
  // Logical operators
261
261
  const results = await vectorStore.query({
262
- indexName: "my_vectors",
262
+ indexName: 'my_vectors',
263
263
  queryVector: embedding,
264
264
  filter: {
265
- $and: [
266
- { category: "electronics" },
267
- { price: { $lte: 500 } },
268
- ],
265
+ $and: [{ category: 'electronics' }, { price: { $lte: 500 } }],
269
266
  },
270
- });
267
+ })
271
268
  ```
272
269
 
273
270
  ### Supported Filter Operators
package/dist/index.cjs CHANGED
@@ -993,6 +993,15 @@ var ConvexVector = class extends vector.MastraVector {
993
993
  includeVector = false,
994
994
  filter
995
995
  }) {
996
+ if (!queryVector) {
997
+ throw new error.MastraError({
998
+ id: storage.createVectorErrorId("CONVEX", "QUERY", "MISSING_VECTOR"),
999
+ text: "queryVector is required for Convex queries. Metadata-only queries are not supported by this vector store.",
1000
+ domain: error.ErrorDomain.STORAGE,
1001
+ category: error.ErrorCategory.USER,
1002
+ details: { indexName }
1003
+ });
1004
+ }
996
1005
  const vectors = await this.callStorage({
997
1006
  op: "queryTable",
998
1007
  tableName: this.vectorTable(indexName)