@mastra/convex 0.0.0-fix-local-pkg-cwd-20251226155239 → 0.0.0-jail-fs-20260105160110
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 +118 -3
- 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 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -23
- package/dist/index.js.map +1 -1
- package/dist/storage/domains/memory/index.d.ts.map +1 -1
- package/dist/storage/index.d.ts +6 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/package.json +8 -7
|
@@ -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];
|
|
@@ -877,19 +869,6 @@ var ConvexStore = class extends storage.MastraStorage {
|
|
|
877
869
|
scores
|
|
878
870
|
};
|
|
879
871
|
}
|
|
880
|
-
get supports() {
|
|
881
|
-
return {
|
|
882
|
-
selectByIncludeResourceScope: true,
|
|
883
|
-
resourceWorkingMemory: true,
|
|
884
|
-
hasColumn: false,
|
|
885
|
-
createTable: false,
|
|
886
|
-
deleteMessages: true,
|
|
887
|
-
observability: false,
|
|
888
|
-
indexManagement: false,
|
|
889
|
-
listScoresBySpan: false,
|
|
890
|
-
agents: false
|
|
891
|
-
};
|
|
892
|
-
}
|
|
893
872
|
};
|
|
894
873
|
var INDEX_METADATA_TABLE = "mastra_vector_indexes";
|
|
895
874
|
var ConvexVector = class extends vector.MastraVector {
|