@mastra/convex 0.1.0-beta.7 → 0.1.0-beta.8
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 +49 -0
- package/dist/docs/README.md +32 -0
- package/dist/docs/SKILL.md +46 -0
- package/dist/docs/SOURCE_MAP.json +63 -0
- package/dist/docs/storage/01-reference.md +140 -0
- package/dist/docs/vectors/01-reference.md +240 -0
- package/dist/index.cjs +1 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -10
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/package.json +8 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @mastra/convex
|
|
2
2
|
|
|
3
|
+
## 0.1.0-beta.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Add embedded documentation support for Mastra packages ([#11472](https://github.com/mastra-ai/mastra/pull/11472))
|
|
8
|
+
|
|
9
|
+
Mastra packages now include embedded documentation in the published npm package under `dist/docs/`. This enables coding agents and AI assistants to understand and use the framework by reading documentation directly from `node_modules`.
|
|
10
|
+
|
|
11
|
+
Each package includes:
|
|
12
|
+
- **SKILL.md** - Entry point explaining the package's purpose and capabilities
|
|
13
|
+
- **SOURCE_MAP.json** - Machine-readable index mapping exports to types and implementation files
|
|
14
|
+
- **Topic folders** - Conceptual documentation organized by feature area
|
|
15
|
+
|
|
16
|
+
Documentation is driven by the `packages` frontmatter field in MDX files, which maps docs to their corresponding packages. CI validation ensures all docs include this field.
|
|
17
|
+
|
|
18
|
+
- Added `startExclusive` and `endExclusive` options to `dateRange` filter for message queries. ([#11479](https://github.com/mastra-ai/mastra/pull/11479))
|
|
19
|
+
|
|
20
|
+
**What changed:** The `filter.dateRange` parameter in `listMessages()` and `Memory.recall()` now supports `startExclusive` and `endExclusive` boolean options. When set to `true`, messages with timestamps exactly matching the boundary are excluded from results.
|
|
21
|
+
|
|
22
|
+
**Why this matters:** Enables cursor-based pagination for chat applications. When new messages arrive during a session, offset-based pagination can skip or duplicate messages. Using `endExclusive: true` with the oldest message's timestamp as a cursor ensures consistent pagination without gaps or duplicates.
|
|
23
|
+
|
|
24
|
+
**Example:**
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
// Get first page
|
|
28
|
+
const page1 = await memory.recall({
|
|
29
|
+
threadId: 'thread-123',
|
|
30
|
+
perPage: 10,
|
|
31
|
+
orderBy: { field: 'createdAt', direction: 'DESC' },
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Get next page using cursor-based pagination
|
|
35
|
+
const oldestMessage = page1.messages[page1.messages.length - 1];
|
|
36
|
+
const page2 = await memory.recall({
|
|
37
|
+
threadId: 'thread-123',
|
|
38
|
+
perPage: 10,
|
|
39
|
+
orderBy: { field: 'createdAt', direction: 'DESC' },
|
|
40
|
+
filter: {
|
|
41
|
+
dateRange: {
|
|
42
|
+
end: oldestMessage.createdAt,
|
|
43
|
+
endExclusive: true, // Excludes the cursor message
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- Updated dependencies [[`d2d3e22`](https://github.com/mastra-ai/mastra/commit/d2d3e22a419ee243f8812a84e3453dd44365ecb0), [`bc72b52`](https://github.com/mastra-ai/mastra/commit/bc72b529ee4478fe89ecd85a8be47ce0127b82a0), [`05b8bee`](https://github.com/mastra-ai/mastra/commit/05b8bee9e50e6c2a4a2bf210eca25ee212ca24fa), [`c042bd0`](https://github.com/mastra-ai/mastra/commit/c042bd0b743e0e86199d0cb83344ca7690e34a9c), [`940a2b2`](https://github.com/mastra-ai/mastra/commit/940a2b27480626ed7e74f55806dcd2181c1dd0c2), [`e0941c3`](https://github.com/mastra-ai/mastra/commit/e0941c3d7fc75695d5d258e7008fd5d6e650800c), [`0c0580a`](https://github.com/mastra-ai/mastra/commit/0c0580a42f697cd2a7d5973f25bfe7da9055038a), [`28f5f89`](https://github.com/mastra-ai/mastra/commit/28f5f89705f2409921e3c45178796c0e0d0bbb64), [`e601b27`](https://github.com/mastra-ai/mastra/commit/e601b272c70f3a5ecca610373aa6223012704892), [`3d3366f`](https://github.com/mastra-ai/mastra/commit/3d3366f31683e7137d126a3a57174a222c5801fb), [`5a4953f`](https://github.com/mastra-ai/mastra/commit/5a4953f7d25bb15ca31ed16038092a39cb3f98b3), [`eb9e522`](https://github.com/mastra-ai/mastra/commit/eb9e522ce3070a405e5b949b7bf5609ca51d7fe2), [`20e6f19`](https://github.com/mastra-ai/mastra/commit/20e6f1971d51d3ff6dd7accad8aaaae826d540ed), [`4f0b3c6`](https://github.com/mastra-ai/mastra/commit/4f0b3c66f196c06448487f680ccbb614d281e2f7), [`74c4f22`](https://github.com/mastra-ai/mastra/commit/74c4f22ed4c71e72598eacc346ba95cdbc00294f), [`81b6a8f`](https://github.com/mastra-ai/mastra/commit/81b6a8ff79f49a7549d15d66624ac1a0b8f5f971), [`e4d366a`](https://github.com/mastra-ai/mastra/commit/e4d366aeb500371dd4210d6aa8361a4c21d87034), [`a4f010b`](https://github.com/mastra-ai/mastra/commit/a4f010b22e4355a5fdee70a1fe0f6e4a692cc29e), [`73b0bb3`](https://github.com/mastra-ai/mastra/commit/73b0bb394dba7c9482eb467a97ab283dbc0ef4db), [`5627a8c`](https://github.com/mastra-ai/mastra/commit/5627a8c6dc11fe3711b3fa7a6ffd6eb34100a306), [`3ff45d1`](https://github.com/mastra-ai/mastra/commit/3ff45d10e0c80c5335a957ab563da72feb623520), [`251df45`](https://github.com/mastra-ai/mastra/commit/251df4531407dfa46d805feb40ff3fb49769f455), [`f894d14`](https://github.com/mastra-ai/mastra/commit/f894d148946629af7b1f452d65a9cf864cec3765), [`c2b9547`](https://github.com/mastra-ai/mastra/commit/c2b9547bf435f56339f23625a743b2147ab1c7a6), [`580b592`](https://github.com/mastra-ai/mastra/commit/580b5927afc82fe460dfdf9a38a902511b6b7e7f), [`58e3931`](https://github.com/mastra-ai/mastra/commit/58e3931af9baa5921688566210f00fb0c10479fa), [`08bb631`](https://github.com/mastra-ai/mastra/commit/08bb631ae2b14684b2678e3549d0b399a6f0561e), [`4fba91b`](https://github.com/mastra-ai/mastra/commit/4fba91bec7c95911dc28e369437596b152b04cd0), [`12b0cc4`](https://github.com/mastra-ai/mastra/commit/12b0cc4077d886b1a552637dedb70a7ade93528c)]:
|
|
50
|
+
- @mastra/core@1.0.0-beta.20
|
|
51
|
+
|
|
3
52
|
## 0.1.0-beta.7
|
|
4
53
|
|
|
5
54
|
### Patch Changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# @mastra/convex Documentation
|
|
2
|
+
|
|
3
|
+
> Embedded documentation for coding agents
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Read the skill overview
|
|
9
|
+
cat docs/SKILL.md
|
|
10
|
+
|
|
11
|
+
# Get the source map
|
|
12
|
+
cat docs/SOURCE_MAP.json
|
|
13
|
+
|
|
14
|
+
# Read topic documentation
|
|
15
|
+
cat docs/<topic>/01-overview.md
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Structure
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
docs/
|
|
22
|
+
├── SKILL.md # Entry point
|
|
23
|
+
├── README.md # This file
|
|
24
|
+
├── SOURCE_MAP.json # Export index
|
|
25
|
+
├── storage/ (1 files)
|
|
26
|
+
├── vectors/ (1 files)
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Version
|
|
30
|
+
|
|
31
|
+
Package: @mastra/convex
|
|
32
|
+
Version: 0.1.0-beta.8
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: mastra-convex-docs
|
|
3
|
+
description: Documentation for @mastra/convex. Includes links to type definitions and readable implementation code in dist/.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# @mastra/convex Documentation
|
|
7
|
+
|
|
8
|
+
> **Version**: 0.1.0-beta.8
|
|
9
|
+
> **Package**: @mastra/convex
|
|
10
|
+
|
|
11
|
+
## Quick Navigation
|
|
12
|
+
|
|
13
|
+
Use SOURCE_MAP.json to find any export:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
cat docs/SOURCE_MAP.json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Each export maps to:
|
|
20
|
+
- **types**: `.d.ts` file with JSDoc and API signatures
|
|
21
|
+
- **implementation**: `.js` chunk file with readable source
|
|
22
|
+
- **docs**: Conceptual documentation in `docs/`
|
|
23
|
+
|
|
24
|
+
## Top Exports
|
|
25
|
+
|
|
26
|
+
- mastraStorage: dist/index.d.ts
|
|
27
|
+
- TABLE_MESSAGES: dist/index.d.ts
|
|
28
|
+
- TABLE_RESOURCES: dist/index.d.ts
|
|
29
|
+
- TABLE_SCORERS: dist/index.d.ts
|
|
30
|
+
- TABLE_THREADS: dist/index.d.ts
|
|
31
|
+
- TABLE_WORKFLOW_SNAPSHOT: dist/index.d.ts
|
|
32
|
+
- mastraDocumentsTable: dist/index.d.ts
|
|
33
|
+
- mastraMessagesTable: dist/index.d.ts
|
|
34
|
+
- mastraResourcesTable: dist/index.d.ts
|
|
35
|
+
- mastraScoresTable: dist/index.d.ts
|
|
36
|
+
- mastraThreadsTable: dist/index.d.ts
|
|
37
|
+
- mastraVectorIndexesTable: dist/index.d.ts
|
|
38
|
+
- mastraVectorsTable: dist/index.d.ts
|
|
39
|
+
- mastraWorkflowSnapshotsTable: dist/index.d.ts
|
|
40
|
+
|
|
41
|
+
See SOURCE_MAP.json for the complete list.
|
|
42
|
+
|
|
43
|
+
## Available Topics
|
|
44
|
+
|
|
45
|
+
- [Storage](storage/) - 1 file(s)
|
|
46
|
+
- [Vectors](vectors/) - 1 file(s)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.1.0-beta.8",
|
|
3
|
+
"package": "@mastra/convex",
|
|
4
|
+
"exports": {
|
|
5
|
+
"mastraStorage": {
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"implementation": "dist/chunk-KSAPIIEJ.js"
|
|
8
|
+
},
|
|
9
|
+
"TABLE_MESSAGES": {
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
12
|
+
},
|
|
13
|
+
"TABLE_RESOURCES": {
|
|
14
|
+
"types": "dist/index.d.ts",
|
|
15
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
16
|
+
},
|
|
17
|
+
"TABLE_SCORERS": {
|
|
18
|
+
"types": "dist/index.d.ts",
|
|
19
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
20
|
+
},
|
|
21
|
+
"TABLE_THREADS": {
|
|
22
|
+
"types": "dist/index.d.ts",
|
|
23
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
24
|
+
},
|
|
25
|
+
"TABLE_WORKFLOW_SNAPSHOT": {
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
28
|
+
},
|
|
29
|
+
"mastraDocumentsTable": {
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
32
|
+
},
|
|
33
|
+
"mastraMessagesTable": {
|
|
34
|
+
"types": "dist/index.d.ts",
|
|
35
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
36
|
+
},
|
|
37
|
+
"mastraResourcesTable": {
|
|
38
|
+
"types": "dist/index.d.ts",
|
|
39
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
40
|
+
},
|
|
41
|
+
"mastraScoresTable": {
|
|
42
|
+
"types": "dist/index.d.ts",
|
|
43
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
44
|
+
},
|
|
45
|
+
"mastraThreadsTable": {
|
|
46
|
+
"types": "dist/index.d.ts",
|
|
47
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
48
|
+
},
|
|
49
|
+
"mastraVectorIndexesTable": {
|
|
50
|
+
"types": "dist/index.d.ts",
|
|
51
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
52
|
+
},
|
|
53
|
+
"mastraVectorsTable": {
|
|
54
|
+
"types": "dist/index.d.ts",
|
|
55
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
56
|
+
},
|
|
57
|
+
"mastraWorkflowSnapshotsTable": {
|
|
58
|
+
"types": "dist/index.d.ts",
|
|
59
|
+
"implementation": "dist/chunk-HXB4DWFE.js"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
"modules": {}
|
|
63
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# Storage API Reference
|
|
2
|
+
|
|
3
|
+
> API reference for storage - 1 entries
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Reference: Convex Storage
|
|
9
|
+
|
|
10
|
+
> Documentation for the Convex storage implementation in Mastra.
|
|
11
|
+
|
|
12
|
+
The Convex storage implementation provides a serverless storage solution using [Convex](https://convex.dev), a full-stack TypeScript development platform with real-time sync and automatic caching.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @mastra/convex@beta
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Convex Setup
|
|
21
|
+
|
|
22
|
+
Before using `ConvexStore`, you need to set up the Convex schema and storage handler in your Convex project.
|
|
23
|
+
|
|
24
|
+
### 1. Set up Convex Schema
|
|
25
|
+
|
|
26
|
+
In `convex/schema.ts`:
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { defineSchema } from 'convex/server';
|
|
30
|
+
import {
|
|
31
|
+
mastraThreadsTable,
|
|
32
|
+
mastraMessagesTable,
|
|
33
|
+
mastraResourcesTable,
|
|
34
|
+
mastraWorkflowSnapshotsTable,
|
|
35
|
+
mastraScoresTable,
|
|
36
|
+
mastraVectorIndexesTable,
|
|
37
|
+
mastraVectorsTable,
|
|
38
|
+
mastraDocumentsTable,
|
|
39
|
+
} from '@mastra/convex/schema';
|
|
40
|
+
|
|
41
|
+
export default defineSchema({
|
|
42
|
+
mastra_threads: mastraThreadsTable,
|
|
43
|
+
mastra_messages: mastraMessagesTable,
|
|
44
|
+
mastra_resources: mastraResourcesTable,
|
|
45
|
+
mastra_workflow_snapshots: mastraWorkflowSnapshotsTable,
|
|
46
|
+
mastra_scorers: mastraScoresTable,
|
|
47
|
+
mastra_vector_indexes: mastraVectorIndexesTable,
|
|
48
|
+
mastra_vectors: mastraVectorsTable,
|
|
49
|
+
mastra_documents: mastraDocumentsTable,
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### 2. Create the Storage Handler
|
|
54
|
+
|
|
55
|
+
In `convex/mastra/storage.ts`:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
import { mastraStorage } from '@mastra/convex/server';
|
|
59
|
+
|
|
60
|
+
export const handle = mastraStorage;
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 3. Deploy to Convex
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
npx convex dev
|
|
67
|
+
# or for production
|
|
68
|
+
npx convex deploy
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Usage
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { ConvexStore } from "@mastra/convex";
|
|
75
|
+
|
|
76
|
+
const storage = new ConvexStore({
|
|
77
|
+
id: 'convex-storage',
|
|
78
|
+
deploymentUrl: process.env.CONVEX_URL!,
|
|
79
|
+
adminAuthToken: process.env.CONVEX_ADMIN_KEY!,
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Parameters
|
|
84
|
+
|
|
85
|
+
## Constructor Examples
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
import { ConvexStore } from "@mastra/convex";
|
|
89
|
+
|
|
90
|
+
// Basic configuration
|
|
91
|
+
const store = new ConvexStore({
|
|
92
|
+
id: 'convex-storage',
|
|
93
|
+
deploymentUrl: "https://your-project.convex.cloud",
|
|
94
|
+
adminAuthToken: "your-admin-token",
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// With custom storage function path
|
|
98
|
+
const storeCustom = new ConvexStore({
|
|
99
|
+
id: 'convex-storage',
|
|
100
|
+
deploymentUrl: "https://your-project.convex.cloud",
|
|
101
|
+
adminAuthToken: "your-admin-token",
|
|
102
|
+
storageFunction: "custom/path:handler",
|
|
103
|
+
});
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Additional Notes
|
|
107
|
+
|
|
108
|
+
### Schema Management
|
|
109
|
+
|
|
110
|
+
The storage implementation uses typed Convex tables for each Mastra domain:
|
|
111
|
+
|
|
112
|
+
| Domain | Convex Table | Purpose |
|
|
113
|
+
| -------------- | --------------------------- | -------------------- |
|
|
114
|
+
| Threads | `mastra_threads` | Conversation threads |
|
|
115
|
+
| Messages | `mastra_messages` | Chat messages |
|
|
116
|
+
| Resources | `mastra_resources` | User working memory |
|
|
117
|
+
| Workflows | `mastra_workflow_snapshots` | Workflow state |
|
|
118
|
+
| Scorers | `mastra_scorers` | Evaluation data |
|
|
119
|
+
| Fallback | `mastra_documents` | Unknown tables |
|
|
120
|
+
|
|
121
|
+
### Architecture
|
|
122
|
+
|
|
123
|
+
All typed tables include:
|
|
124
|
+
|
|
125
|
+
- An `id` field for Mastra's record ID (distinct from Convex's auto-generated `_id`)
|
|
126
|
+
- A `by_record_id` index for efficient lookups by Mastra ID
|
|
127
|
+
|
|
128
|
+
This design ensures compatibility with Mastra's storage contract while leveraging Convex's automatic indexing and real-time capabilities.
|
|
129
|
+
|
|
130
|
+
### Environment Variables
|
|
131
|
+
|
|
132
|
+
Set these environment variables for your deployment:
|
|
133
|
+
|
|
134
|
+
- `CONVEX_URL` – Your Convex deployment URL
|
|
135
|
+
- `CONVEX_ADMIN_KEY` – Admin authentication token (get from Convex dashboard)
|
|
136
|
+
|
|
137
|
+
## Related
|
|
138
|
+
|
|
139
|
+
- [Convex Vector Store](../vectors/convex)
|
|
140
|
+
- [Convex Documentation](https://docs.convex.dev/)
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# Vectors API Reference
|
|
2
|
+
|
|
3
|
+
> API reference for vectors - 1 entries
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## Reference: Convex Vector Store
|
|
9
|
+
|
|
10
|
+
> Documentation for the ConvexVector class in Mastra, which provides vector search using Convex.
|
|
11
|
+
|
|
12
|
+
The ConvexVector class provides vector storage and similarity search using [Convex](https://convex.dev). It stores embeddings inside Convex and performs cosine similarity search.
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @mastra/convex@beta
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Convex Setup
|
|
21
|
+
|
|
22
|
+
Before using `ConvexVector`, you need to set up the Convex schema and storage handler. See [Convex Storage Setup](../storage/convex#convex-setup) for setup instructions.
|
|
23
|
+
|
|
24
|
+
## Constructor Options
|
|
25
|
+
|
|
26
|
+
## Constructor Examples
|
|
27
|
+
|
|
28
|
+
### Basic Configuration
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { ConvexVector } from "@mastra/convex";
|
|
32
|
+
|
|
33
|
+
const vectorStore = new ConvexVector({
|
|
34
|
+
id: 'convex-vectors',
|
|
35
|
+
deploymentUrl: "https://your-project.convex.cloud",
|
|
36
|
+
adminAuthToken: "your-admin-token",
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Custom Storage Function
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
const vectorStore = new ConvexVector({
|
|
44
|
+
id: 'convex-vectors',
|
|
45
|
+
deploymentUrl: "https://your-project.convex.cloud",
|
|
46
|
+
adminAuthToken: "your-admin-token",
|
|
47
|
+
storageFunction: "custom/path:handler",
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Methods
|
|
52
|
+
|
|
53
|
+
### createIndex()
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
await vectorStore.createIndex({
|
|
57
|
+
indexName: "my_vectors",
|
|
58
|
+
dimension: 1536,
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### upsert()
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
await vectorStore.upsert({
|
|
66
|
+
indexName: "my_vectors",
|
|
67
|
+
vectors: [[0.1, 0.2, 0.3, ...]],
|
|
68
|
+
metadata: [{ label: "example" }],
|
|
69
|
+
ids: ["vec-1"],
|
|
70
|
+
});
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### query()
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const results = await vectorStore.query({
|
|
77
|
+
indexName: "my_vectors",
|
|
78
|
+
queryVector: [0.1, 0.2, 0.3, ...],
|
|
79
|
+
topK: 5,
|
|
80
|
+
filter: { category: "documents" },
|
|
81
|
+
});
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### listIndexes()
|
|
85
|
+
|
|
86
|
+
Returns an array of index names as strings.
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
const indexes = await vectorStore.listIndexes();
|
|
90
|
+
// ["my_vectors", "embeddings", ...]
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### describeIndex()
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
interface IndexStats {
|
|
99
|
+
dimension: number;
|
|
100
|
+
count: number;
|
|
101
|
+
metric: "cosine" | "euclidean" | "dotproduct";
|
|
102
|
+
}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### deleteIndex()
|
|
106
|
+
|
|
107
|
+
Deletes the index and all its vectors.
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
await vectorStore.deleteIndex({ indexName: "my_vectors" });
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### updateVector()
|
|
114
|
+
|
|
115
|
+
Update a single vector by ID or by metadata filter. Either `id` or `filter` must be provided, but not both.
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// Update by ID
|
|
119
|
+
await vectorStore.updateVector({
|
|
120
|
+
indexName: "my_vectors",
|
|
121
|
+
id: "vector123",
|
|
122
|
+
update: {
|
|
123
|
+
vector: [0.1, 0.2, 0.3],
|
|
124
|
+
metadata: { label: "updated" },
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Update by filter
|
|
129
|
+
await vectorStore.updateVector({
|
|
130
|
+
indexName: "my_vectors",
|
|
131
|
+
filter: { category: "product" },
|
|
132
|
+
update: {
|
|
133
|
+
metadata: { status: "reviewed" },
|
|
134
|
+
},
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### deleteVector()
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
await vectorStore.deleteVector({ indexName: "my_vectors", id: "vector123" });
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### deleteVectors()
|
|
145
|
+
|
|
146
|
+
Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both.
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
// Delete by IDs
|
|
150
|
+
await vectorStore.deleteVectors({
|
|
151
|
+
indexName: "my_vectors",
|
|
152
|
+
ids: ["vec1", "vec2", "vec3"],
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Delete by filter
|
|
156
|
+
await vectorStore.deleteVectors({
|
|
157
|
+
indexName: "my_vectors",
|
|
158
|
+
filter: { status: "archived" },
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Response Types
|
|
163
|
+
|
|
164
|
+
Query results are returned in this format:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
interface QueryResult {
|
|
168
|
+
id: string;
|
|
169
|
+
score: number;
|
|
170
|
+
metadata: Record<string, any>;
|
|
171
|
+
vector?: number[]; // Only included if includeVector is true
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Metadata Filtering
|
|
176
|
+
|
|
177
|
+
ConvexVector supports metadata filtering with various operators:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// Simple equality
|
|
181
|
+
const results = await vectorStore.query({
|
|
182
|
+
indexName: "my_vectors",
|
|
183
|
+
queryVector: embedding,
|
|
184
|
+
filter: { category: "documents" },
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// Comparison operators
|
|
188
|
+
const results = await vectorStore.query({
|
|
189
|
+
indexName: "my_vectors",
|
|
190
|
+
queryVector: embedding,
|
|
191
|
+
filter: {
|
|
192
|
+
price: { $gt: 100 },
|
|
193
|
+
status: { $in: ["active", "pending"] },
|
|
194
|
+
},
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
// Logical operators
|
|
198
|
+
const results = await vectorStore.query({
|
|
199
|
+
indexName: "my_vectors",
|
|
200
|
+
queryVector: embedding,
|
|
201
|
+
filter: {
|
|
202
|
+
$and: [
|
|
203
|
+
{ category: "electronics" },
|
|
204
|
+
{ price: { $lte: 500 } },
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Supported Filter Operators
|
|
211
|
+
|
|
212
|
+
| Operator | Description |
|
|
213
|
+
| -------- | ----------- |
|
|
214
|
+
| `$eq` | Equal to |
|
|
215
|
+
| `$ne` | Not equal to |
|
|
216
|
+
| `$gt` | Greater than |
|
|
217
|
+
| `$gte` | Greater than or equal |
|
|
218
|
+
| `$lt` | Less than |
|
|
219
|
+
| `$lte` | Less than or equal |
|
|
220
|
+
| `$in` | In array |
|
|
221
|
+
| `$nin` | Not in array |
|
|
222
|
+
| `$and` | Logical AND |
|
|
223
|
+
| `$or` | Logical OR |
|
|
224
|
+
|
|
225
|
+
## Architecture
|
|
226
|
+
|
|
227
|
+
ConvexVector stores vectors in the `mastra_vectors` table with the following structure:
|
|
228
|
+
|
|
229
|
+
- `id`: Unique vector identifier
|
|
230
|
+
- `indexName`: Name of the index
|
|
231
|
+
- `embedding`: The vector data (array of floats)
|
|
232
|
+
- `metadata`: Optional JSON metadata
|
|
233
|
+
|
|
234
|
+
Vector similarity search is performed using cosine similarity, computed in the Convex function.
|
|
235
|
+
|
|
236
|
+
## Related
|
|
237
|
+
|
|
238
|
+
- [Convex Storage](../storage/convex)
|
|
239
|
+
- [Metadata Filters](../rag/metadata-filters)
|
|
240
|
+
- [Convex Documentation](https://docs.convex.dev/)
|
package/dist/index.cjs
CHANGED
|
@@ -295,15 +295,7 @@ var MemoryConvex = class extends storage.MemoryStorage {
|
|
|
295
295
|
if (resourceId) {
|
|
296
296
|
rows = rows.filter((row) => row.resourceId === resourceId);
|
|
297
297
|
}
|
|
298
|
-
|
|
299
|
-
const { start, end } = filter.dateRange;
|
|
300
|
-
rows = rows.filter((row) => {
|
|
301
|
-
const created = new Date(row.createdAt).getTime();
|
|
302
|
-
if (start && created < start.getTime()) return false;
|
|
303
|
-
if (end && created > end.getTime()) return false;
|
|
304
|
-
return true;
|
|
305
|
-
});
|
|
306
|
-
}
|
|
298
|
+
rows = storage.filterByDateRange(rows, (row) => new Date(row.createdAt), filter?.dateRange);
|
|
307
299
|
rows.sort((a, b) => {
|
|
308
300
|
const aValue = field === "createdAt" || field === "updatedAt" ? new Date(a[field]).getTime() : a[field];
|
|
309
301
|
const bValue = field === "createdAt" || field === "updatedAt" ? new Date(b[field]).getTime() : b[field];
|