@mastra/convex 1.5.6-alpha.0 → 1.5.6
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 +16 -202
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,224 +1,38 @@
|
|
|
1
1
|
# @mastra/convex
|
|
2
2
|
|
|
3
|
-
Convex
|
|
3
|
+
`@mastra/convex` provides Convex-backed storage, vector search, and server caching for Mastra applications. It includes development-scale and native vector implementations, along with server-side Convex definitions and handlers.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
- `ConvexVector` stores embeddings inside Convex and performs development-scale cosine similarity search.
|
|
7
|
-
- `ConvexNativeVector` uses Convex native vector search for production workloads.
|
|
8
|
-
- `ConvexServerCache` stores Mastra server cache entries in Convex for durable stream replay and response caching.
|
|
9
|
-
- `@mastra/convex/server` exposes the required Convex table definitions, storage mutation, cache handlers, and native vector handlers.
|
|
10
|
-
|
|
11
|
-
## Quick start
|
|
12
|
-
|
|
13
|
-
### 1. Install
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
pnpm add @mastra/convex
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
### 2. Set up Convex schema
|
|
20
|
-
|
|
21
|
-
In `convex/schema.ts`:
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
import { defineSchema } from 'convex/server';
|
|
25
|
-
import {
|
|
26
|
-
mastraThreadsTable,
|
|
27
|
-
mastraMessagesTable,
|
|
28
|
-
mastraResourcesTable,
|
|
29
|
-
mastraWorkflowSnapshotsTable,
|
|
30
|
-
mastraScoresTable,
|
|
31
|
-
mastraSchedulesTable,
|
|
32
|
-
mastraScheduleTriggersTable,
|
|
33
|
-
mastraChannelInstallationsTable,
|
|
34
|
-
mastraChannelConfigTable,
|
|
35
|
-
mastraBackgroundTasksTable,
|
|
36
|
-
mastraObservationalMemoryTable,
|
|
37
|
-
mastraVectorIndexesTable,
|
|
38
|
-
mastraVectorsTable,
|
|
39
|
-
mastraCacheTable,
|
|
40
|
-
mastraCacheListItemsTable,
|
|
41
|
-
mastraDocumentsTable,
|
|
42
|
-
} from '@mastra/convex/schema';
|
|
43
|
-
|
|
44
|
-
export default defineSchema({
|
|
45
|
-
mastra_threads: mastraThreadsTable,
|
|
46
|
-
mastra_messages: mastraMessagesTable,
|
|
47
|
-
mastra_resources: mastraResourcesTable,
|
|
48
|
-
mastra_workflow_snapshots: mastraWorkflowSnapshotsTable,
|
|
49
|
-
mastra_scorers: mastraScoresTable,
|
|
50
|
-
mastra_schedules: mastraSchedulesTable,
|
|
51
|
-
mastra_schedule_triggers: mastraScheduleTriggersTable,
|
|
52
|
-
mastra_channel_installations: mastraChannelInstallationsTable,
|
|
53
|
-
mastra_channel_config: mastraChannelConfigTable,
|
|
54
|
-
mastra_background_tasks: mastraBackgroundTasksTable,
|
|
55
|
-
mastra_observational_memory: mastraObservationalMemoryTable,
|
|
56
|
-
mastra_vector_indexes: mastraVectorIndexesTable,
|
|
57
|
-
mastra_vectors: mastraVectorsTable,
|
|
58
|
-
mastra_cache: mastraCacheTable,
|
|
59
|
-
mastra_cache_list_items: mastraCacheListItemsTable,
|
|
60
|
-
mastra_documents: mastraDocumentsTable,
|
|
61
|
-
});
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### 3. Create the storage and cache handlers
|
|
65
|
-
|
|
66
|
-
In `convex/mastra/storage.ts`:
|
|
67
|
-
|
|
68
|
-
```ts
|
|
69
|
-
import { mastraStorage } from '@mastra/convex/server';
|
|
70
|
-
|
|
71
|
-
export const handle = mastraStorage;
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
In `convex/mastra/cache.ts`:
|
|
75
|
-
|
|
76
|
-
```ts
|
|
77
|
-
import { mastraCache } from '@mastra/convex/server';
|
|
78
|
-
|
|
79
|
-
export const handle = mastraCache;
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### 4. Deploy to Convex
|
|
5
|
+
## Installation
|
|
83
6
|
|
|
84
7
|
```bash
|
|
85
|
-
|
|
86
|
-
# or for production
|
|
87
|
-
npx convex deploy
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### 5. Use in Mastra
|
|
91
|
-
|
|
92
|
-
```ts
|
|
93
|
-
import { ConvexServerCache, ConvexStore } from '@mastra/convex';
|
|
94
|
-
|
|
95
|
-
const storage = new ConvexStore({
|
|
96
|
-
id: 'convex',
|
|
97
|
-
deploymentUrl: process.env.CONVEX_URL!,
|
|
98
|
-
adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
|
|
99
|
-
storageFunction: 'mastra/storage:handle', // default
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const cache = new ConvexServerCache({
|
|
103
|
-
deploymentUrl: process.env.CONVEX_URL!,
|
|
104
|
-
adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
|
|
105
|
-
cacheFunction: 'mastra/cache:handle', // default
|
|
106
|
-
requestTimeoutMs: 30_000, // default
|
|
107
|
-
});
|
|
8
|
+
npm install @mastra/convex
|
|
108
9
|
```
|
|
109
10
|
|
|
110
|
-
|
|
111
|
-
Use this cache for durable replay of moderate-frequency events; batch high-frequency token streams or use a lower-latency cache backend.
|
|
11
|
+
## Usage
|
|
112
12
|
|
|
113
|
-
|
|
13
|
+
Create a vector store with your Convex deployment URL and an admin auth token. Use `ConvexNativeVector` for production-scale native vector search, or `ConvexVector` for development-scale search implemented by the package.
|
|
114
14
|
|
|
115
|
-
```
|
|
116
|
-
import {
|
|
15
|
+
```typescript
|
|
16
|
+
import { ConvexNativeVector } from '@mastra/convex';
|
|
117
17
|
|
|
118
|
-
const
|
|
18
|
+
const vectorStore = new ConvexNativeVector({
|
|
119
19
|
id: 'convex-vectors',
|
|
120
20
|
deploymentUrl: process.env.CONVEX_URL!,
|
|
121
21
|
adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
|
|
122
22
|
});
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
`ConvexVector` scans stored vectors through the storage handler and computes similarity in the adapter. Use it for local development, tests, and small datasets.
|
|
126
|
-
|
|
127
|
-
For native Convex vector search, define a dedicated table in `convex/schema.ts`:
|
|
128
|
-
|
|
129
|
-
```ts
|
|
130
|
-
import { defineSchema } from 'convex/server';
|
|
131
|
-
import { defineMastraNativeVectorTable } from '@mastra/convex/schema';
|
|
132
|
-
|
|
133
|
-
export default defineSchema({
|
|
134
|
-
docs_vectors: defineMastraNativeVectorTable({
|
|
135
|
-
dimensions: 1536,
|
|
136
|
-
}),
|
|
137
|
-
});
|
|
138
|
-
```
|
|
139
23
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
import { mastraNativeVectorAction, mastraNativeVectorMutation, mastraNativeVectorQuery } from '@mastra/convex/server';
|
|
144
|
-
|
|
145
|
-
export const query = mastraNativeVectorAction;
|
|
146
|
-
export const read = mastraNativeVectorQuery;
|
|
147
|
-
export const write = mastraNativeVectorMutation;
|
|
148
|
-
```
|
|
149
|
-
|
|
150
|
-
Configure the native vector adapter:
|
|
151
|
-
|
|
152
|
-
```ts
|
|
153
|
-
import { ConvexNativeVector } from '@mastra/convex';
|
|
154
|
-
|
|
155
|
-
const vector = new ConvexNativeVector({
|
|
156
|
-
id: 'convex-native-vectors',
|
|
157
|
-
deploymentUrl: process.env.CONVEX_URL!,
|
|
158
|
-
adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
|
|
159
|
-
indexes: {
|
|
160
|
-
docs: {
|
|
161
|
-
tableName: 'docs_vectors',
|
|
162
|
-
vectorIndexName: 'by_embedding',
|
|
163
|
-
dimension: 1536,
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
});
|
|
24
|
+
await vectorStore.createIndex({ indexName: 'documents', dimension: 1536 });
|
|
167
25
|
```
|
|
168
26
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
## Architecture
|
|
172
|
-
|
|
173
|
-
This adapter uses **typed Convex tables** for each Mastra domain:
|
|
174
|
-
|
|
175
|
-
| Domain | Convex Table | Purpose |
|
|
176
|
-
| -------------------- | ------------------------------------------------------- | -------------------------------- |
|
|
177
|
-
| Threads | `mastra_threads` | Conversation threads |
|
|
178
|
-
| Messages | `mastra_messages` | Chat messages |
|
|
179
|
-
| Resources | `mastra_resources` | User working memory |
|
|
180
|
-
| Workflows | `mastra_workflow_snapshots` | Workflow state |
|
|
181
|
-
| Scorers | `mastra_scorers` | Evaluation data |
|
|
182
|
-
| Schedules | `mastra_schedules` | Workflow schedules |
|
|
183
|
-
| Triggers | `mastra_schedule_triggers` | Schedule history |
|
|
184
|
-
| Channels | `mastra_channel_installations`, `mastra_channel_config` | Channel installations and config |
|
|
185
|
-
| Background Tasks | `mastra_background_tasks` | Background task state |
|
|
186
|
-
| Observational Memory | `mastra_observational_memory` | Observational memory generations |
|
|
187
|
-
| Vector Indexes | `mastra_vector_indexes` | Index metadata |
|
|
188
|
-
| Vectors | `mastra_vectors` | Embeddings |
|
|
189
|
-
| Cache | `mastra_cache` | Cache metadata |
|
|
190
|
-
| Cache Items | `mastra_cache_list_items` | Cache list entries |
|
|
191
|
-
| Fallback | `mastra_documents` | Unknown tables |
|
|
192
|
-
|
|
193
|
-
All typed tables include:
|
|
194
|
-
|
|
195
|
-
- An `id` field for Mastra's record ID (distinct from Convex's auto-generated `_id`)
|
|
196
|
-
- A `by_record_id` index for efficient lookups by Mastra ID
|
|
197
|
-
|
|
198
|
-
Schedule due reads and trigger-history reads use bounded Convex queries to avoid deployment read limits. When no explicit trigger-history limit is provided, the adapter returns the newest 100 rows. Schedule listing is capped at 8,000 rows per call. Schedule rows also store a normalized `workflow_id` alongside the serialized target so workflow filters can run inside Convex before the listing cap is applied.
|
|
27
|
+
## Documentation
|
|
199
28
|
|
|
200
|
-
|
|
29
|
+
- [Convex integration guide](https://mastra.ai/integrations/databases/convex)
|
|
30
|
+
- [Convex vector reference](https://mastra.ai/reference/vectors/convex)
|
|
201
31
|
|
|
202
|
-
|
|
32
|
+
## Changelog
|
|
203
33
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
Upgrading from a version without observational memory: add `mastraObservationalMemoryTable` to your `convex/schema.ts` (as shown in the quick start) and run `npx convex deploy` again.
|
|
207
|
-
|
|
208
|
-
Active observations and buffered chunks share one Convex document, which is subject to Convex's 1 MiB document size limit. Default observational memory thresholds stay well below this limit; extremely large custom thresholds can exceed it.
|
|
209
|
-
|
|
210
|
-
## Testing
|
|
211
|
-
|
|
212
|
-
Set the following environment variables before running tests:
|
|
213
|
-
|
|
214
|
-
- `CONVEX_TEST_URL` – the Convex deployment URL (e.g., `https://your-name.convex.cloud`)
|
|
215
|
-
- `CONVEX_TEST_ADMIN_KEY` – an admin token for that deployment
|
|
216
|
-
- `CONVEX_TEST_STORAGE_FUNCTION` _(optional)_ – override if you mounted `mastraStorage` elsewhere
|
|
217
|
-
|
|
218
|
-
```bash
|
|
219
|
-
pnpm --filter @mastra/convex test
|
|
220
|
-
```
|
|
34
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/stores/convex/CHANGELOG.md) for version history and release notes.
|
|
221
35
|
|
|
222
|
-
##
|
|
36
|
+
## Support
|
|
223
37
|
|
|
224
|
-
|
|
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.
|
package/dist/docs/SKILL.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/convex",
|
|
3
|
-
"version": "1.5.6
|
|
3
|
+
"version": "1.5.6",
|
|
4
4
|
"description": "Convex provider for Mastra - includes both storage and vector adapters plus Convex server helpers",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -52,10 +52,10 @@
|
|
|
52
52
|
"tsx": "^4.23.1",
|
|
53
53
|
"typescript": "^7.0.2",
|
|
54
54
|
"vitest": "4.1.10",
|
|
55
|
-
"@internal/lint": "0.0.
|
|
56
|
-
"@internal/storage-test-utils": "0.0.
|
|
57
|
-
"@internal/types-builder": "0.0.
|
|
58
|
-
"@mastra/core": "1.64.0
|
|
55
|
+
"@internal/lint": "0.0.130",
|
|
56
|
+
"@internal/storage-test-utils": "0.0.126",
|
|
57
|
+
"@internal/types-builder": "0.0.105",
|
|
58
|
+
"@mastra/core": "1.64.0"
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@mastra/core": ">=1.53.0-0 <2.0.0-0"
|