@mastra/upstash 1.4.4-alpha.0 → 1.4.4
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 +9 -167
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mastra/upstash
|
|
2
2
|
|
|
3
|
-
Upstash
|
|
3
|
+
Use Upstash Redis as serverless Mastra storage with REST credentials, namespaced keys, durable persistence, and deployment-friendly connections.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -8,142 +8,9 @@ Upstash provider for Mastra that includes both vector store and database storage
|
|
|
8
8
|
npm install @mastra/upstash
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
##
|
|
11
|
+
## Usage
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
import { UpstashVector } from '@mastra/upstash';
|
|
15
|
-
|
|
16
|
-
// In upstash they refer to the store as an index
|
|
17
|
-
const vectorStore = new UpstashVector({
|
|
18
|
-
url: process.env.UPSTASH_VECTOR_REST_URL,
|
|
19
|
-
token: process.env.UPSTASH_VECTOR_TOKEN
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// Add vectors
|
|
23
|
-
const vectors = [[0.1, 0.2, ...], [0.3, 0.4, ...]];
|
|
24
|
-
const metadata = [{ text: 'doc1' }, { text: 'doc2' }];
|
|
25
|
-
const ids = await vectorStore.upsert({
|
|
26
|
-
indexName: 'my-namespace',
|
|
27
|
-
vectors,
|
|
28
|
-
metadata
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// There is no store.createIndex call here, Upstash creates indexes (known as namespaces in Upstash) automatically
|
|
32
|
-
// when you upsert if that namespace does not exist yet.
|
|
33
|
-
|
|
34
|
-
// Query vectors
|
|
35
|
-
const results = await vectorStore.query({
|
|
36
|
-
indexName: 'my-namespace',
|
|
37
|
-
queryVector: [0.1, 0.2, ...],
|
|
38
|
-
topK: 10,
|
|
39
|
-
filter: { text: { $eq: 'doc1' } },
|
|
40
|
-
includeVector: false
|
|
41
|
-
});
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Hybrid Vector Search (Dense + Sparse)
|
|
45
|
-
|
|
46
|
-
Upstash supports hybrid search that combines semantic search (dense vectors) with keyword-based search (sparse vectors) for improved relevance and accuracy.
|
|
47
|
-
|
|
48
|
-
#### Upserting Hybrid Vectors
|
|
49
|
-
|
|
50
|
-
```typescript
|
|
51
|
-
import { UpstashVector } from '@mastra/upstash';
|
|
52
|
-
|
|
53
|
-
const vectorStore = new UpstashVector({
|
|
54
|
-
url: process.env.UPSTASH_VECTOR_REST_URL,
|
|
55
|
-
token: process.env.UPSTASH_VECTOR_TOKEN
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const vectors = [[0.1, 0.2, 0.3, ...], [0.4, 0.5, 0.6, ...]];
|
|
59
|
-
const sparseVectors = [
|
|
60
|
-
{ indices: [1, 5, 10], values: [0.8, 0.6, 0.4] },
|
|
61
|
-
{ indices: [2, 6, 11], values: [0.7, 0.5, 0.3] }
|
|
62
|
-
];
|
|
63
|
-
const metadata = [{ title: 'Document 1' }, { title: 'Document 2' }];
|
|
64
|
-
|
|
65
|
-
const ids = await vectorStore.upsert({
|
|
66
|
-
indexName: 'hybrid-index',
|
|
67
|
-
vectors,
|
|
68
|
-
sparseVectors,
|
|
69
|
-
metadata
|
|
70
|
-
});
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
#### Querying with Hybrid Search
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
import { FusionAlgorithm, QueryMode } from '@upstash/vector';
|
|
77
|
-
|
|
78
|
-
// Query with both dense and sparse vectors (default hybrid mode)
|
|
79
|
-
const results = await vectorStore.query({
|
|
80
|
-
indexName: 'hybrid-index',
|
|
81
|
-
queryVector: [0.1, 0.2, 0.3, ...],
|
|
82
|
-
sparseVector: { indices: [1, 5], values: [0.9, 0.7] },
|
|
83
|
-
topK: 10,
|
|
84
|
-
fusionAlgorithm: FusionAlgorithm.RRF,
|
|
85
|
-
includeVector: false
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Dense-only query (backward compatible)
|
|
89
|
-
const denseResults = await vectorStore.query({
|
|
90
|
-
indexName: 'hybrid-index',
|
|
91
|
-
queryVector: [0.1, 0.2, 0.3, ...],
|
|
92
|
-
topK: 10
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
// Query only the dense component for custom reranking
|
|
96
|
-
const denseOnlyResults = await vectorStore.query({
|
|
97
|
-
indexName: 'hybrid-index',
|
|
98
|
-
queryVector: [0.1, 0.2, 0.3, ...],
|
|
99
|
-
queryMode: QueryMode.DENSE,
|
|
100
|
-
topK: 10
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Query only the sparse component for custom reranking
|
|
104
|
-
const sparseOnlyResults = await vectorStore.query({
|
|
105
|
-
indexName: 'hybrid-index',
|
|
106
|
-
queryVector: [0.1, 0.2, 0.3, ...], // Still needed for dense index structure
|
|
107
|
-
sparseVector: { indices: [1, 5], values: [0.9, 0.7] },
|
|
108
|
-
queryMode: QueryMode.SPARSE,
|
|
109
|
-
topK: 10
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
// Explicit hybrid mode (same as default)
|
|
113
|
-
const explicitHybridResults = await vectorStore.query({
|
|
114
|
-
indexName: 'hybrid-index',
|
|
115
|
-
queryVector: [0.1, 0.2, 0.3, ...],
|
|
116
|
-
sparseVector: { indices: [1, 5], values: [0.9, 0.7] },
|
|
117
|
-
queryMode: QueryMode.HYBRID,
|
|
118
|
-
fusionAlgorithm: FusionAlgorithm.RRF,
|
|
119
|
-
topK: 10
|
|
120
|
-
});
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
#### Fusion Algorithms & Query Modes
|
|
124
|
-
|
|
125
|
-
Upstash provides built-in fusion algorithms to combine dense and sparse search results:
|
|
126
|
-
|
|
127
|
-
- **RRF (Reciprocal Rank Fusion)**: Default algorithm that combines rankings from both dense and sparse searches
|
|
128
|
-
- **DBSF (Distribution-Based Score Fusion)**
|
|
129
|
-
|
|
130
|
-
Query modes enable fine-grained control over hybrid index queries:
|
|
131
|
-
|
|
132
|
-
- **`QueryMode.HYBRID`**: Default mode that queries both dense and sparse components and fuses results
|
|
133
|
-
- **`QueryMode.DENSE`**: Query only the dense component, useful for custom reranking scenarios
|
|
134
|
-
- **`QueryMode.SPARSE`**: Query only the sparse component, useful for custom reranking scenarios
|
|
135
|
-
|
|
136
|
-
Use query modes when you want to implement custom fusion logic or need separate dense/sparse results for advanced reranking algorithms.
|
|
137
|
-
|
|
138
|
-
### Vector Store Configuration
|
|
139
|
-
|
|
140
|
-
The Upstash vector store requires the following configuration:
|
|
141
|
-
|
|
142
|
-
- `UPSTASH_VECTOR_REST_URL`: Your Upstash Vector REST URL
|
|
143
|
-
- `UPSTASH_VECTOR_TOKEN`: Your Upstash Vector REST token
|
|
144
|
-
- `UPSTASH_INDEX`: Name of the index to use
|
|
145
|
-
|
|
146
|
-
## Database Storage Usage
|
|
13
|
+
Configure the database credentials required by your provider.
|
|
147
14
|
|
|
148
15
|
```typescript
|
|
149
16
|
import { UpstashStore } from '@mastra/upstash';
|
|
@@ -154,39 +21,14 @@ const store = new UpstashStore({
|
|
|
154
21
|
});
|
|
155
22
|
```
|
|
156
23
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
The Upstash store requires the following configuration:
|
|
160
|
-
|
|
161
|
-
- `UPSTASH_REDIS_REST_URL`: Your Upstash Redis REST URL
|
|
162
|
-
- `UPSTASH_REDIS_REST_TOKEN`: Your Upstash Redis REST token
|
|
163
|
-
|
|
164
|
-
## Vector Store Methods
|
|
24
|
+
## Documentation
|
|
165
25
|
|
|
166
|
-
-
|
|
167
|
-
- `upsert({ indexName, vectors, sparseVectors?, metadata?, ids? })`: Add or update vectors (supports hybrid search)
|
|
168
|
-
- `query({ indexName, queryVector, sparseQueryVector?, topK?, filter?, includeVector?, includeMetadata?, mode?, fusionAlgorithm? })`: Search for similar vectors
|
|
169
|
-
- `updateVector({ indexName, id?, filter?, update })`: Update a single vector by ID or metadata filter
|
|
170
|
-
- `deleteVector({ indexName, id })`: Delete a single vector by ID
|
|
171
|
-
- `deleteVectors({ indexName, ids?, filter? })`: Delete multiple vectors by IDs or metadata filter
|
|
172
|
-
- `listIndexes()`: List all namespaces
|
|
173
|
-
- `describeIndex({ indexName })`: Get namespace statistics
|
|
174
|
-
- `deleteIndex({ indexName })`: Delete a namespace
|
|
26
|
+
- [Upstash](https://mastra.ai/integrations/databases/upstash)
|
|
175
27
|
|
|
176
|
-
##
|
|
28
|
+
## Changelog
|
|
177
29
|
|
|
178
|
-
-
|
|
179
|
-
- **Hybrid vector search** combining dense and sparse vectors
|
|
180
|
-
- **Advanced fusion algorithms** (RRF) for optimal search ranking
|
|
181
|
-
- Pay-per-use pricing
|
|
182
|
-
- Low latency global access
|
|
183
|
-
- REST API interface
|
|
184
|
-
- Built-in vector similarity search
|
|
185
|
-
- Durable storage for chat history and agent memory
|
|
186
|
-
- Backward compatible with existing dense vector implementations
|
|
30
|
+
See the [package changelog](https://github.com/mastra-ai/mastra/blob/main/stores/upstash/CHANGELOG.md) for version history and release notes.
|
|
187
31
|
|
|
188
|
-
##
|
|
32
|
+
## Support
|
|
189
33
|
|
|
190
|
-
|
|
191
|
-
- [Upstash Hybrid Indexes Documentation](https://docs.upstash.com/vector/features/hybridindexes)
|
|
192
|
-
- [Upstash Redis Documentation](https://docs.upstash.com/redis)
|
|
34
|
+
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/upstash",
|
|
3
|
-
"version": "1.4.4
|
|
3
|
+
"version": "1.4.4",
|
|
4
4
|
"description": "Upstash provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@upstash/redis": "^1.37.0",
|
|
24
24
|
"@upstash/vector": "^1.2.3",
|
|
25
|
-
"@mastra/redis": "1.4.3
|
|
25
|
+
"@mastra/redis": "1.4.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "22.20.1",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"tsx": "^4.23.1",
|
|
35
35
|
"typescript": "^7.0.2",
|
|
36
36
|
"vitest": "4.1.10",
|
|
37
|
-
"@internal/
|
|
38
|
-
"@internal/
|
|
39
|
-
"@internal/types-builder": "0.0.
|
|
40
|
-
"@mastra/core": "1.64.0
|
|
37
|
+
"@internal/lint": "0.0.130",
|
|
38
|
+
"@internal/storage-test-utils": "0.0.126",
|
|
39
|
+
"@internal/types-builder": "0.0.105",
|
|
40
|
+
"@mastra/core": "1.64.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@mastra/core": ">=1.61.0-0 <2.0.0-0"
|