@mastra/upstash 1.5.5 → 1.6.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"
6
+ version: "1.6.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",
2
+ "version": "1.6.0",
3
3
  "package": "@mastra/upstash",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -104,6 +104,18 @@ The `update` object can have the following properties:
104
104
 
105
105
  Attempts to delete an item by its ID from the specified index. Logs an error message if the deletion fails.
106
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
+
107
119
  ## Hybrid vector search
108
120
 
109
121
  Upstash Vector supports hybrid search that combines semantic search (dense vectors) with keyword-based search (sparse vectors) for improved relevance and accuracy.
@@ -251,7 +251,11 @@ const results = await pgVector.query({
251
251
  })
252
252
  ```
253
253
 
254
- Postgres vector indexes (HNSW and IVFFlat) can't restrict that search to rows matching a condition. When a filter is present, pgVector instead compares the query vector against every matching row and returns the closest `topK`. Results are exact, but the work grows with the number of rows the filter matches. Indexing the metadata column speeds up row retrieval. The distance comparisons still happen per row.
254
+ With an HNSW index on pgvector 0.8.0 or newer, PostgreSQL searches the index and skips rows that don't match the filter. When the index search can't fill `topK`, pgVector reruns the query as an exact search.
255
+
256
+ With IVFFlat, or HNSW on older pgvector versions, pgVector compares the query vector against every matching row. Results are exact, but the work grows with the number of matching rows.
257
+
258
+ Indexing the metadata fields you filter on speeds up both cases and gives PostgreSQL the row counts it needs to choose between them.
255
259
 
256
260
  ### Vector Query Tool
257
261
 
@@ -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";