@mastra/upstash 1.5.5-alpha.1 → 1.6.0-alpha.0

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.
@@ -3,7 +3,7 @@ name: mastra-upstash
3
3
  description: Documentation for @mastra/upstash. Use when working with @mastra/upstash APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/upstash"
6
- version: "1.5.5-alpha.1"
6
+ version: "1.6.0-alpha.0"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -21,12 +21,12 @@ Read the individual reference documents for detailed explanations and code examp
21
21
  ### Integrations
22
22
 
23
23
  - [Upstash](references/integrations-databases-upstash.md) - Use Upstash Redis as serverless Mastra storage with REST credentials, namespaced keys, durable persistence, and deployment-friendly connections.
24
+ - [Upstash](references/integrations-vectors-upstash.md) - Run serverless vector and hybrid search from Mastra with Upstash Vector, including metadata filtering and automatic index creation.
24
25
 
25
26
  ### Reference
26
27
 
27
28
  - [Retrieval, semantic search, reranking](references/reference-rag-retrieval.md) - After storing embeddings, you need to retrieve relevant chunks to answer user queries.
28
29
  - [Storing embeddings in a vector database](references/reference-rag-vector-databases.md) - After generating embeddings, you need to store them in a database that supports vector similarity search.
29
- - [Reference: Upstash vector store](references/reference-vectors-upstash.md) - Configure UpstashVector for serverless similarity and hybrid search, metadata filtering, index management, and vector operations with Upstash Vector.
30
30
 
31
31
 
32
32
  Read [assets/SOURCE_MAP.json](assets/SOURCE_MAP.json) for source code references.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.5-alpha.1",
2
+ "version": "1.6.0-alpha.0",
3
3
  "package": "@mastra/upstash",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -18,13 +18,13 @@ The UpstashVector class provides vector search using [Upstash Vector](https://up
18
18
 
19
19
  ### `createIndex()`
20
20
 
21
- Note: This method is a no-op for Upstash as indexes are created automatically.
21
+ Note: This method is a no-op for Upstash. Indexes (Upstash namespaces) are created automatically on first write, and the parameters below are ignored.
22
22
 
23
23
  **indexName** (`string`): Name of the index to create
24
24
 
25
25
  **dimension** (`number`): Vector dimension (must match your embedding model)
26
26
 
27
- **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Distance metric for similarity search (Default: `cosine`)
27
+ **metric** (`'cosine' | 'euclidean' | 'dotproduct'`): Ignored. The metric is set on the Upstash index itself.
28
28
 
29
29
  ### `upsert()`
30
30
 
@@ -70,7 +70,7 @@ Returns:
70
70
  interface IndexStats {
71
71
  dimension: number
72
72
  count: number
73
- metric: 'cosine' | 'euclidean' | 'dotproduct'
73
+ metric?: 'cosine' | 'euclidean' | 'dotproduct'
74
74
  }
75
75
  ```
76
76
 
@@ -82,10 +82,14 @@ interface IndexStats {
82
82
 
83
83
  **indexName** (`string`): Name of the index to update
84
84
 
85
- **id** (`string`): ID of the item to update
85
+ **id** (`string`): ID of the item to update. Mutually exclusive with filter.
86
+
87
+ **filter** (`Record<string, any>`): Metadata filter matching up to 1,000 items to update. Mutually exclusive with id. Must not be empty.
86
88
 
87
89
  **update** (`object`): Update object containing vector, sparse vector, and/or metadata
88
90
 
91
+ Provide exactly one of `id` or `filter`.
92
+
89
93
  The `update` object can have the following properties:
90
94
 
91
95
  - `vector` (optional): An array of numbers representing the new dense vector.
@@ -100,6 +104,18 @@ The `update` object can have the following properties:
100
104
 
101
105
  Attempts to delete an item by its ID from the specified index. Logs an error message if the deletion fails.
102
106
 
107
+ ### `deleteVectors()`
108
+
109
+ Delete multiple vectors by IDs or by metadata filter. Either `ids` or `filter` must be provided, but not both, and neither can be empty.
110
+
111
+ Filter deletion runs one approximate query with `topK: 1000` and deletes the returned IDs. `deleteVectors()` returns `Promise<void>` and does not report how many vectors it deleted, so repeating the call cannot guarantee complete deletion. Use [Upstash's filter-delete API](https://upstash.com/docs/vector/api/endpoints/delete) when complete filter deletion is required. Deleting by `ids` isn't subject to this query limit.
112
+
113
+ **indexName** (`string`): Namespace to delete from
114
+
115
+ **ids** (`string[]`): Array of vector IDs to delete (mutually exclusive with filter)
116
+
117
+ **filter** (`Record<string, any>`): Metadata filter to identify vectors to delete (mutually exclusive with ids). Only the first 1,000 matches are deleted
118
+
103
119
  ## Hybrid vector search
104
120
 
105
121
  Upstash Vector supports hybrid search that combines semantic search (dense vectors) with keyword-based search (sparse vectors) for improved relevance and accuracy.
@@ -35,7 +35,7 @@ MongoDB Vector Search is a good solution for teams who want to consolidate vecto
35
35
 
36
36
  ### Using VoyageAI with MongoDB
37
37
 
38
- MongoDB works directly with VoyageAI's embedding models, which are optimized for retrieval tasks. For complete examples and specialized models, see the [VoyageAI embeddings documentation](https://mastra.ai/models/embeddings) and [MongoDB vector reference](https://mastra.ai/reference/vectors/mongodb).
38
+ MongoDB works directly with VoyageAI's embedding models, which are optimized for retrieval tasks. For complete examples and specialized models, see the [VoyageAI embeddings documentation](https://mastra.ai/models/embeddings) and [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb).
39
39
 
40
40
  ### Hybrid Search (Vector + Full-Text)
41
41
 
@@ -52,7 +52,7 @@ const results = await store.hybridQuery({
52
52
  })
53
53
  ```
54
54
 
55
- See the [MongoDB vector reference](https://mastra.ai/reference/vectors/mongodb) for details on `createSearchIndex()`, `textQuery()`, and `hybridQuery()`.
55
+ See the [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb) for details on `createSearchIndex()`, `textQuery()`, and `hybridQuery()`.
56
56
 
57
57
  ### Automated Embedding
58
58
 
@@ -75,7 +75,7 @@ const results = await store.query({
75
75
  })
76
76
  ```
77
77
 
78
- Automated Embedding is a MongoDB Preview feature and needs a deployment where it's available. See the [MongoDB vector reference](https://mastra.ai/reference/vectors/mongodb) for the supported options and requirements.
78
+ Automated Embedding is a MongoDB Preview feature and needs a deployment where it's available. See the [MongoDB vector reference](https://mastra.ai/integrations/vectors/mongodb) for the supported options and requirements.
79
79
 
80
80
  **PgVector**:
81
81
 
package/dist/index.cjs CHANGED
@@ -187,7 +187,9 @@ function toStorageRecord(task) {
187
187
  suspendedAt: task.suspendedAt?.toISOString() ?? null,
188
188
  completedAt: task.completedAt?.toISOString() ?? null,
189
189
  ownerId: task.ownerId ?? null,
190
- leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null
190
+ leaseExpiresAt: task.leaseExpiresAt?.toISOString() ?? null,
191
+ expiresAt: task.expiresAt?.toISOString() ?? null,
192
+ metadata: task.metadata ?? null
191
193
  };
192
194
  }
193
195
  function fromStorageRecord(record) {
@@ -212,10 +214,13 @@ function fromStorageRecord(record) {
212
214
  suspendedAt: record.suspendedAt ? new Date(record.suspendedAt) : void 0,
213
215
  completedAt: record.completedAt ? new Date(record.completedAt) : void 0,
214
216
  ownerId: record.ownerId ?? void 0,
215
- leaseExpiresAt: record.leaseExpiresAt ? new Date(record.leaseExpiresAt) : void 0
217
+ leaseExpiresAt: record.leaseExpiresAt ? new Date(record.leaseExpiresAt) : void 0,
218
+ expiresAt: record.expiresAt ? new Date(record.expiresAt) : void 0,
219
+ metadata: record.metadata ?? void 0
216
220
  };
217
221
  }
218
222
  var BackgroundTasksUpstash = class extends _mastra_core_storage.BackgroundTasksStorage {
223
+ supportsTaskExpiry = true;
219
224
  client;
220
225
  #db;
221
226
  constructor(config) {
@@ -244,6 +249,8 @@ var BackgroundTasksUpstash = class extends _mastra_core_storage.BackgroundTasksS
244
249
  if ("completedAt" in update) patch.completedAt = update.completedAt?.toISOString() ?? null;
245
250
  if ("ownerId" in update) patch.ownerId = update.ownerId ?? null;
246
251
  if ("leaseExpiresAt" in update) patch.leaseExpiresAt = update.leaseExpiresAt?.toISOString() ?? null;
252
+ if ("expiresAt" in update) patch.expiresAt = update.expiresAt?.toISOString() ?? null;
253
+ if ("metadata" in update) patch.metadata = update.metadata ?? null;
247
254
  if (Object.keys(patch).length === 0) return false;
248
255
  const key = getKey(_mastra_core_storage.TABLE_BACKGROUND_TASKS, { id: taskId });
249
256
  const result = await this.client.eval(`
@@ -261,6 +268,9 @@ var BackgroundTasksUpstash = class extends _mastra_core_storage.BackgroundTasksS
261
268
  if ARGV[5] == '1' then
262
269
  if normalize(record.leaseExpiresAt) ~= normalize(cjson.decode(ARGV[6])) then return 0 end
263
270
  end
271
+ if ARGV[7] == '1' then
272
+ if normalize(record.suspendedAt) ~= normalize(cjson.decode(ARGV[8])) then return 0 end
273
+ end
264
274
  local patch = cjson.decode(ARGV[2])
265
275
  for field, value in pairs(patch) do record[field] = value end
266
276
  redis.call('SET', KEYS[1], cjson.encode(record))
@@ -271,7 +281,9 @@ var BackgroundTasksUpstash = class extends _mastra_core_storage.BackgroundTasksS
271
281
  options?.expectedOwnerId !== void 0 ? "1" : "0",
272
282
  JSON.stringify(options?.expectedOwnerId ?? null),
273
283
  options?.expectedLeaseExpiresAt !== void 0 ? "1" : "0",
274
- JSON.stringify(options?.expectedLeaseExpiresAt?.toISOString() ?? null)
284
+ JSON.stringify(options?.expectedLeaseExpiresAt?.toISOString() ?? null),
285
+ options?.expectedSuspendedAt !== void 0 ? "1" : "0",
286
+ JSON.stringify(options?.expectedSuspendedAt?.toISOString() ?? null)
275
287
  ]);
276
288
  return Number(result) === 1;
277
289
  }
@@ -298,6 +310,7 @@ var BackgroundTasksUpstash = class extends _mastra_core_storage.BackgroundTasksS
298
310
  if (filter.threadId) tasks = tasks.filter((t) => t.threadId === filter.threadId);
299
311
  if (filter.resourceId) tasks = tasks.filter((t) => t.resourceId === filter.resourceId);
300
312
  if (filter.runId) tasks = tasks.filter((t) => t.runId === filter.runId);
313
+ if (filter.hasExpiresAt !== void 0) tasks = tasks.filter((t) => t.expiresAt != null === filter.hasExpiresAt);
301
314
  if (filter.toolName) tasks = tasks.filter((t) => t.toolName === filter.toolName);
302
315
  if (filter.toolCallId) tasks = tasks.filter((t) => t.toolCallId === filter.toolCallId);
303
316
  const dateCol = filter.dateFilterBy ?? "createdAt";
@@ -1488,7 +1501,7 @@ var StoreMemoryUpstash = class extends _mastra_core_storage.MemoryStorage {
1488
1501
  const aValue = new Date(a[field]).getTime();
1489
1502
  const bValue = new Date(b[field]).getTime();
1490
1503
  if (direction === "ASC") return aValue - bValue;
1491
- else return bValue - aValue;
1504
+ return bValue - aValue;
1492
1505
  });
1493
1506
  }
1494
1507
  async cloneThread(args) {