@mastra/upstash 0.11.0-alpha.0 → 0.11.0-alpha.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/.turbo/turbo-build.log +7 -23
- package/CHANGELOG.md +23 -0
- package/README.md +4 -0
- package/dist/_tsup-dts-rollup.d.cts +44 -9
- package/dist/_tsup-dts-rollup.d.ts +44 -9
- package/dist/index.cjs +57 -43362
- package/dist/index.js +57 -43362
- package/package.json +3 -3
- package/src/storage/index.ts +1 -1
- package/src/vector/index.ts +54 -19
- package/dist/chunk-HSTZWXH7.js +0 -1666
- package/dist/chunk-IGKEDEDE.js +0 -12
- package/dist/chunk-N2CPQVE3.cjs +0 -35
- package/dist/chunk-U74OJRHU.cjs +0 -1678
- package/dist/getMachineId-bsd-HDZ73WR7.cjs +0 -30
- package/dist/getMachineId-bsd-KKIDU47O.js +0 -28
- package/dist/getMachineId-darwin-3PL23DL6.cjs +0 -31
- package/dist/getMachineId-darwin-UTKBTJ2U.js +0 -29
- package/dist/getMachineId-linux-K3QXQYAB.js +0 -23
- package/dist/getMachineId-linux-KYLPK3HC.cjs +0 -25
- package/dist/getMachineId-unsupported-DEDJN4ZS.cjs +0 -17
- package/dist/getMachineId-unsupported-VPWBQCK7.js +0 -15
- package/dist/getMachineId-win-L2EYIM5A.js +0 -30
- package/dist/getMachineId-win-ZTI2LRDJ.cjs +0 -52
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/upstash",
|
|
3
|
-
"version": "0.11.0-alpha.
|
|
3
|
+
"version": "0.11.0-alpha.2",
|
|
4
4
|
"description": "Upstash provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"tsup": "^8.5.0",
|
|
32
32
|
"typescript": "^5.8.3",
|
|
33
33
|
"vitest": "^3.2.3",
|
|
34
|
-
"@internal/storage-test-utils": "0.0.8",
|
|
35
34
|
"@internal/lint": "0.0.12",
|
|
36
|
-
"@mastra/core": "0.10.6-alpha.
|
|
35
|
+
"@mastra/core": "0.10.6-alpha.4",
|
|
36
|
+
"@internal/storage-test-utils": "0.0.8"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"@mastra/core": ">=0.10.4-0 <0.11.0"
|
package/src/storage/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { MessageList } from '@mastra/core/agent';
|
|
1
2
|
import type { MetricResult, TestInfo } from '@mastra/core/eval';
|
|
2
3
|
import type { StorageThreadType, MastraMessageV1, MastraMessageV2 } from '@mastra/core/memory';
|
|
3
4
|
import {
|
|
@@ -21,7 +22,6 @@ import type {
|
|
|
21
22
|
} from '@mastra/core/storage';
|
|
22
23
|
import type { WorkflowRunState } from '@mastra/core/workflows';
|
|
23
24
|
import { Redis } from '@upstash/redis';
|
|
24
|
-
import { MessageList } from '../../../../packages/core/dist/agent/index.cjs';
|
|
25
25
|
|
|
26
26
|
export interface UpstashConfig {
|
|
27
27
|
url: string;
|
package/src/vector/index.ts
CHANGED
|
@@ -18,6 +18,12 @@ import { UpstashFilterTranslator } from './filter';
|
|
|
18
18
|
export class UpstashVector extends MastraVector {
|
|
19
19
|
private client: Index;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new UpstashVector instance.
|
|
23
|
+
* @param {object} params - The parameters for the UpstashVector.
|
|
24
|
+
* @param {string} params.url - The URL of the Upstash vector index.
|
|
25
|
+
* @param {string} params.token - The token for the Upstash vector index.
|
|
26
|
+
*/
|
|
21
27
|
constructor({ url, token }: { url: string; token: string }) {
|
|
22
28
|
super();
|
|
23
29
|
this.client = new Index({
|
|
@@ -26,7 +32,12 @@ export class UpstashVector extends MastraVector {
|
|
|
26
32
|
});
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Upserts vectors into the index.
|
|
37
|
+
* @param {UpsertVectorParams} params - The parameters for the upsert operation.
|
|
38
|
+
* @returns {Promise<string[]>} A promise that resolves to the IDs of the upserted vectors.
|
|
39
|
+
*/
|
|
40
|
+
async upsert({ indexName: namespace, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]> {
|
|
30
41
|
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
31
42
|
|
|
32
43
|
const points = vectors.map((vector, index) => ({
|
|
@@ -36,28 +47,43 @@ export class UpstashVector extends MastraVector {
|
|
|
36
47
|
}));
|
|
37
48
|
|
|
38
49
|
await this.client.upsert(points, {
|
|
39
|
-
namespace
|
|
50
|
+
namespace,
|
|
40
51
|
});
|
|
41
52
|
return generatedIds;
|
|
42
53
|
}
|
|
43
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Transforms a Mastra vector filter into an Upstash-compatible filter string.
|
|
57
|
+
* @param {VectorFilter} [filter] - The filter to transform.
|
|
58
|
+
* @returns {string | undefined} The transformed filter string, or undefined if no filter is provided.
|
|
59
|
+
*/
|
|
44
60
|
transformFilter(filter?: VectorFilter) {
|
|
45
61
|
const translator = new UpstashFilterTranslator();
|
|
46
62
|
return translator.translate(filter);
|
|
47
63
|
}
|
|
48
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new index. For Upstash, this is a no-op as indexes (known as namespaces in Upstash) are created on-the-fly.
|
|
67
|
+
* @param {CreateIndexParams} _params - The parameters for creating the index (ignored).
|
|
68
|
+
* @returns {Promise<void>} A promise that resolves when the operation is complete.
|
|
69
|
+
*/
|
|
49
70
|
async createIndex(_params: CreateIndexParams): Promise<void> {
|
|
50
|
-
|
|
71
|
+
this.logger.debug('No need to call createIndex for Upstash');
|
|
51
72
|
}
|
|
52
73
|
|
|
74
|
+
/**
|
|
75
|
+
* Queries the vector index.
|
|
76
|
+
* @param {QueryVectorParams} params - The parameters for the query operation. indexName is the namespace in Upstash.
|
|
77
|
+
* @returns {Promise<QueryResult[]>} A promise that resolves to the query results.
|
|
78
|
+
*/
|
|
53
79
|
async query({
|
|
54
|
-
indexName,
|
|
80
|
+
indexName: namespace,
|
|
55
81
|
queryVector,
|
|
56
82
|
topK = 10,
|
|
57
83
|
filter,
|
|
58
84
|
includeVector = false,
|
|
59
85
|
}: QueryVectorParams): Promise<QueryResult[]> {
|
|
60
|
-
const ns = this.client.namespace(
|
|
86
|
+
const ns = this.client.namespace(namespace);
|
|
61
87
|
|
|
62
88
|
const filterString = this.transformFilter(filter);
|
|
63
89
|
const results = await ns.query({
|
|
@@ -77,6 +103,10 @@ export class UpstashVector extends MastraVector {
|
|
|
77
103
|
}));
|
|
78
104
|
}
|
|
79
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Lists all namespaces in the Upstash vector index, which correspond to indexes.
|
|
108
|
+
* @returns {Promise<string[]>} A promise that resolves to a list of index names.
|
|
109
|
+
*/
|
|
80
110
|
async listIndexes(): Promise<string[]> {
|
|
81
111
|
const indexes = await this.client.listNamespaces();
|
|
82
112
|
return indexes.filter(Boolean);
|
|
@@ -85,30 +115,35 @@ export class UpstashVector extends MastraVector {
|
|
|
85
115
|
/**
|
|
86
116
|
* Retrieves statistics about a vector index.
|
|
87
117
|
*
|
|
88
|
-
* @param {string} indexName - The name of the
|
|
118
|
+
* @param {string} indexName - The name of the namespace to describe
|
|
89
119
|
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
90
120
|
*/
|
|
91
|
-
async describeIndex({ indexName }: DescribeIndexParams): Promise<IndexStats> {
|
|
121
|
+
async describeIndex({ indexName: namespace }: DescribeIndexParams): Promise<IndexStats> {
|
|
92
122
|
const info = await this.client.info();
|
|
93
123
|
|
|
94
124
|
return {
|
|
95
125
|
dimension: info.dimension,
|
|
96
|
-
count: info.namespaces?.[
|
|
126
|
+
count: info.namespaces?.[namespace]?.vectorCount || 0,
|
|
97
127
|
metric: info?.similarityFunction?.toLowerCase() as 'cosine' | 'euclidean' | 'dotproduct',
|
|
98
128
|
};
|
|
99
129
|
}
|
|
100
130
|
|
|
101
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Deletes an index (namespace).
|
|
133
|
+
* @param {DeleteIndexParams} params - The parameters for the delete operation.
|
|
134
|
+
* @returns {Promise<void>} A promise that resolves when the deletion is complete.
|
|
135
|
+
*/
|
|
136
|
+
async deleteIndex({ indexName: namespace }: DeleteIndexParams): Promise<void> {
|
|
102
137
|
try {
|
|
103
|
-
await this.client.deleteNamespace(
|
|
138
|
+
await this.client.deleteNamespace(namespace);
|
|
104
139
|
} catch (error) {
|
|
105
|
-
|
|
140
|
+
this.logger.error('Failed to delete namespace:', error);
|
|
106
141
|
}
|
|
107
142
|
}
|
|
108
143
|
|
|
109
144
|
/**
|
|
110
145
|
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
111
|
-
* @param indexName - The name of the
|
|
146
|
+
* @param indexName - The name of the namespace containing the vector.
|
|
112
147
|
* @param id - The ID of the vector to update.
|
|
113
148
|
* @param update - An object containing the vector and/or metadata to update.
|
|
114
149
|
* @param update.vector - An optional array of numbers representing the new vector.
|
|
@@ -116,7 +151,7 @@ export class UpstashVector extends MastraVector {
|
|
|
116
151
|
* @returns A promise that resolves when the update is complete.
|
|
117
152
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
118
153
|
*/
|
|
119
|
-
async updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void> {
|
|
154
|
+
async updateVector({ indexName: namespace, id, update }: UpdateVectorParams): Promise<void> {
|
|
120
155
|
try {
|
|
121
156
|
if (!update.vector && !update.metadata) {
|
|
122
157
|
throw new Error('No update data provided');
|
|
@@ -143,27 +178,27 @@ export class UpstashVector extends MastraVector {
|
|
|
143
178
|
};
|
|
144
179
|
|
|
145
180
|
await this.client.upsert(points, {
|
|
146
|
-
namespace
|
|
181
|
+
namespace,
|
|
147
182
|
});
|
|
148
183
|
} catch (error: any) {
|
|
149
|
-
throw new Error(`Failed to update vector by id: ${id} for index name: ${
|
|
184
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${namespace}: ${error.message}`);
|
|
150
185
|
}
|
|
151
186
|
}
|
|
152
187
|
|
|
153
188
|
/**
|
|
154
189
|
* Deletes a vector by its ID.
|
|
155
|
-
* @param indexName - The name of the
|
|
190
|
+
* @param indexName - The name of the namespace containing the vector.
|
|
156
191
|
* @param id - The ID of the vector to delete.
|
|
157
192
|
* @returns A promise that resolves when the deletion is complete.
|
|
158
193
|
* @throws Will throw an error if the deletion operation fails.
|
|
159
194
|
*/
|
|
160
|
-
async deleteVector({ indexName, id }: DeleteVectorParams): Promise<void> {
|
|
195
|
+
async deleteVector({ indexName: namespace, id }: DeleteVectorParams): Promise<void> {
|
|
161
196
|
try {
|
|
162
197
|
await this.client.delete(id, {
|
|
163
|
-
namespace
|
|
198
|
+
namespace,
|
|
164
199
|
});
|
|
165
200
|
} catch (error) {
|
|
166
|
-
|
|
201
|
+
this.logger.error(`Failed to delete vector by id: ${id} for namespace: ${namespace}:`, error);
|
|
167
202
|
}
|
|
168
203
|
}
|
|
169
204
|
}
|