@mastra/upstash 0.12.4-alpha.0 → 0.13.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 +8 -8
- package/CHANGELOG.md +38 -0
- package/README.md +98 -0
- package/dist/_tsup-dts-rollup.d.cts +30 -4
- package/dist/_tsup-dts-rollup.d.ts +30 -4
- package/dist/index.cjs +97 -36
- package/dist/index.js +97 -36
- package/package.json +4 -4
- package/src/storage/domains/memory/index.ts +70 -0
- package/src/storage/index.ts +5 -0
- package/src/vector/hybrid.test.ts +1455 -0
- package/src/vector/index.test.ts +2 -2
- package/src/vector/index.ts +40 -41
- package/src/vector/types.ts +26 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/upstash@0.
|
|
2
|
+
> @mastra/upstash@0.13.0-alpha.2 build /home/runner/work/mastra/mastra/stores/upstash
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.5.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 10556ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
|
+
[34mCLI[39m Target: es2022
|
|
11
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
12
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/upstash/dist/_tsup-dts-rollup.d.ts[39m
|
|
13
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
14
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/upstash/dist/_tsup-dts-rollup.d.cts[39m
|
|
15
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
-
[34mCLI[39m Target: es2022
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 15161ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
21
|
-
[32mESM[39m ⚡️ Build success in
|
|
22
|
-
[32mCJS[39m [1mdist/index.cjs [22m[
|
|
23
|
-
[32mCJS[39m ⚡️ Build success in
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m75.40 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 1933ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m76.30 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 1938ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,43 @@
|
|
|
1
1
|
# @mastra/upstash
|
|
2
2
|
|
|
3
|
+
## 0.13.0-alpha.2
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- f42c4c2: update peer deps for packages to latest core range
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- @mastra/core@0.12.0-alpha.5
|
|
12
|
+
|
|
13
|
+
## 0.12.4-alpha.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- b92bc89: Added hybrid search support to @mastra/upstash vector store. Supports sparse vectors, fusion algorithm, and query mode.
|
|
18
|
+
- b8efbb9: feat: add flexible deleteMessages method to memory API
|
|
19
|
+
- Added `memory.deleteMessages(input)` method that accepts multiple input types:
|
|
20
|
+
- Single message ID as string: `deleteMessages('msg-123')`
|
|
21
|
+
- Array of message IDs: `deleteMessages(['msg-1', 'msg-2'])`
|
|
22
|
+
- Message object with id property: `deleteMessages({ id: 'msg-123' })`
|
|
23
|
+
- Array of message objects: `deleteMessages([{ id: 'msg-1' }, { id: 'msg-2' }])`
|
|
24
|
+
- Implemented in all storage adapters (LibSQL, PostgreSQL, Upstash, InMemory)
|
|
25
|
+
- Added REST API endpoint: `POST /api/memory/messages/delete`
|
|
26
|
+
- Updated client SDK: `thread.deleteMessages()` accepts all input types
|
|
27
|
+
- Updates thread timestamps when messages are deleted
|
|
28
|
+
- Added comprehensive test coverage and documentation
|
|
29
|
+
|
|
30
|
+
- Updated dependencies [27cc97a]
|
|
31
|
+
- Updated dependencies [41daa63]
|
|
32
|
+
- Updated dependencies [254a36b]
|
|
33
|
+
- Updated dependencies [0b89602]
|
|
34
|
+
- Updated dependencies [4d37822]
|
|
35
|
+
- Updated dependencies [ff9c125]
|
|
36
|
+
- Updated dependencies [b8efbb9]
|
|
37
|
+
- Updated dependencies [71466e7]
|
|
38
|
+
- Updated dependencies [0c99fbe]
|
|
39
|
+
- @mastra/core@0.12.0-alpha.2
|
|
40
|
+
|
|
3
41
|
## 0.12.4-alpha.0
|
|
4
42
|
|
|
5
43
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -41,6 +41,100 @@ const results = await vectorStore.query({
|
|
|
41
41
|
});
|
|
42
42
|
```
|
|
43
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
|
+
|
|
44
138
|
### Vector Store Configuration
|
|
45
139
|
|
|
46
140
|
The Upstash vector store requires the following configuration:
|
|
@@ -70,13 +164,17 @@ The Upstash store requires the following configuration:
|
|
|
70
164
|
## Features
|
|
71
165
|
|
|
72
166
|
- Serverless vector database and key-value store
|
|
167
|
+
- **Hybrid vector search** combining dense and sparse vectors
|
|
168
|
+
- **Advanced fusion algorithms** (RRF) for optimal search ranking
|
|
73
169
|
- Pay-per-use pricing
|
|
74
170
|
- Low latency global access
|
|
75
171
|
- REST API interface
|
|
76
172
|
- Built-in vector similarity search
|
|
77
173
|
- Durable storage for chat history and agent memory
|
|
174
|
+
- Backward compatible with existing dense vector implementations
|
|
78
175
|
|
|
79
176
|
## Related Links
|
|
80
177
|
|
|
81
178
|
- [Upstash Vector Documentation](https://docs.upstash.com/vector)
|
|
179
|
+
- [Upstash Hybrid Indexes Documentation](https://docs.upstash.com/vector/features/hybridindexes)
|
|
82
180
|
- [Upstash Redis Documentation](https://docs.upstash.com/redis)
|
|
@@ -4,6 +4,7 @@ import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
|
4
4
|
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
5
|
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
6
6
|
import type { EvalRow } from '@mastra/core/storage';
|
|
7
|
+
import type { FusionAlgorithm } from '@upstash/vector';
|
|
7
8
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
9
|
import { LegacyEvalsStorage } from '@mastra/core/storage';
|
|
9
10
|
import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
@@ -17,6 +18,7 @@ import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
|
17
18
|
import type { OperatorValueMap } from '@mastra/core/vector/filter';
|
|
18
19
|
import type { PaginationArgs } from '@mastra/core/storage';
|
|
19
20
|
import type { PaginationInfo } from '@mastra/core/storage';
|
|
21
|
+
import type { QueryMode } from '@upstash/vector';
|
|
20
22
|
import type { QueryResult } from '@mastra/core/vector';
|
|
21
23
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
22
24
|
import type { Redis } from '@upstash/redis';
|
|
@@ -219,6 +221,7 @@ export declare class StoreMemoryUpstash extends MemoryStorage {
|
|
|
219
221
|
};
|
|
220
222
|
})[];
|
|
221
223
|
}): Promise<MastraMessageV2_2[]>;
|
|
224
|
+
deleteMessages(messageIds: string[]): Promise<void>;
|
|
222
225
|
}
|
|
223
226
|
|
|
224
227
|
export declare class StoreOperationsUpstash extends StoreOperations {
|
|
@@ -315,7 +318,16 @@ declare type UpstashOperatorValueMap = Omit<OperatorValueMap, '$options' | '$ele
|
|
|
315
318
|
$contains: string;
|
|
316
319
|
};
|
|
317
320
|
|
|
318
|
-
declare
|
|
321
|
+
export declare interface UpstashQueryVectorParams extends QueryVectorParams<UpstashVectorFilter> {
|
|
322
|
+
sparseVector?: UpstashSparseVector;
|
|
323
|
+
fusionAlgorithm?: FusionAlgorithm;
|
|
324
|
+
queryMode?: QueryMode;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export declare interface UpstashSparseVector {
|
|
328
|
+
indices: number[];
|
|
329
|
+
values: number[];
|
|
330
|
+
}
|
|
319
331
|
|
|
320
332
|
declare class UpstashStore extends MastraStorage {
|
|
321
333
|
private redis;
|
|
@@ -326,6 +338,7 @@ declare class UpstashStore extends MastraStorage {
|
|
|
326
338
|
resourceWorkingMemory: boolean;
|
|
327
339
|
hasColumn: boolean;
|
|
328
340
|
createTable: boolean;
|
|
341
|
+
deleteMessages: boolean;
|
|
329
342
|
};
|
|
330
343
|
/**
|
|
331
344
|
* @deprecated Use getEvals instead
|
|
@@ -472,6 +485,7 @@ declare class UpstashStore extends MastraStorage {
|
|
|
472
485
|
};
|
|
473
486
|
})[];
|
|
474
487
|
}): Promise<MastraMessageV2[]>;
|
|
488
|
+
deleteMessages(messageIds: string[]): Promise<void>;
|
|
475
489
|
getResourceById({ resourceId }: {
|
|
476
490
|
resourceId: string;
|
|
477
491
|
}): Promise<StorageResourceType | null>;
|
|
@@ -515,6 +529,18 @@ declare class UpstashStore extends MastraStorage {
|
|
|
515
529
|
export { UpstashStore }
|
|
516
530
|
export { UpstashStore as UpstashStore_alias_1 }
|
|
517
531
|
|
|
532
|
+
export declare interface UpstashUpdateVectorParams extends UpdateVectorParams {
|
|
533
|
+
update: {
|
|
534
|
+
vector?: number[];
|
|
535
|
+
metadata?: Record<string, any>;
|
|
536
|
+
sparseVector?: UpstashSparseVector;
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export declare interface UpstashUpsertVectorParams extends UpsertVectorParams {
|
|
541
|
+
sparseVectors?: UpstashSparseVector[];
|
|
542
|
+
}
|
|
543
|
+
|
|
518
544
|
declare class UpstashVector extends MastraVector<UpstashVectorFilter> {
|
|
519
545
|
private client;
|
|
520
546
|
/**
|
|
@@ -532,7 +558,7 @@ declare class UpstashVector extends MastraVector<UpstashVectorFilter> {
|
|
|
532
558
|
* @param {UpsertVectorParams} params - The parameters for the upsert operation.
|
|
533
559
|
* @returns {Promise<string[]>} A promise that resolves to the IDs of the upserted vectors.
|
|
534
560
|
*/
|
|
535
|
-
upsert({ indexName: namespace, vectors, metadata, ids }:
|
|
561
|
+
upsert({ indexName: namespace, vectors, metadata, ids, sparseVectors, }: UpstashUpsertVectorParams): Promise<string[]>;
|
|
536
562
|
/**
|
|
537
563
|
* Transforms a Mastra vector filter into an Upstash-compatible filter string.
|
|
538
564
|
* @param {UpstashVectorFilter} [filter] - The filter to transform.
|
|
@@ -550,7 +576,7 @@ declare class UpstashVector extends MastraVector<UpstashVectorFilter> {
|
|
|
550
576
|
* @param {QueryVectorParams} params - The parameters for the query operation. indexName is the namespace in Upstash.
|
|
551
577
|
* @returns {Promise<QueryResult[]>} A promise that resolves to the query results.
|
|
552
578
|
*/
|
|
553
|
-
query({ indexName: namespace, queryVector, topK, filter, includeVector, }: UpstashQueryVectorParams): Promise<QueryResult[]>;
|
|
579
|
+
query({ indexName: namespace, queryVector, topK, filter, includeVector, sparseVector, fusionAlgorithm, queryMode, }: UpstashQueryVectorParams): Promise<QueryResult[]>;
|
|
554
580
|
/**
|
|
555
581
|
* Lists all namespaces in the Upstash vector index, which correspond to indexes.
|
|
556
582
|
* @returns {Promise<string[]>} A promise that resolves to a list of index names.
|
|
@@ -579,7 +605,7 @@ declare class UpstashVector extends MastraVector<UpstashVectorFilter> {
|
|
|
579
605
|
* @returns A promise that resolves when the update is complete.
|
|
580
606
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
581
607
|
*/
|
|
582
|
-
updateVector({ indexName: namespace, id, update }:
|
|
608
|
+
updateVector({ indexName: namespace, id, update }: UpstashUpdateVectorParams): Promise<void>;
|
|
583
609
|
/**
|
|
584
610
|
* Deletes a vector by its ID.
|
|
585
611
|
* @param indexName - The name of the namespace containing the vector.
|
|
@@ -4,6 +4,7 @@ import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
|
4
4
|
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
5
5
|
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
6
6
|
import type { EvalRow } from '@mastra/core/storage';
|
|
7
|
+
import type { FusionAlgorithm } from '@upstash/vector';
|
|
7
8
|
import type { IndexStats } from '@mastra/core/vector';
|
|
8
9
|
import { LegacyEvalsStorage } from '@mastra/core/storage';
|
|
9
10
|
import type { MastraMessageContentV2 } from '@mastra/core/agent';
|
|
@@ -17,6 +18,7 @@ import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
|
17
18
|
import type { OperatorValueMap } from '@mastra/core/vector/filter';
|
|
18
19
|
import type { PaginationArgs } from '@mastra/core/storage';
|
|
19
20
|
import type { PaginationInfo } from '@mastra/core/storage';
|
|
21
|
+
import type { QueryMode } from '@upstash/vector';
|
|
20
22
|
import type { QueryResult } from '@mastra/core/vector';
|
|
21
23
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
22
24
|
import type { Redis } from '@upstash/redis';
|
|
@@ -219,6 +221,7 @@ export declare class StoreMemoryUpstash extends MemoryStorage {
|
|
|
219
221
|
};
|
|
220
222
|
})[];
|
|
221
223
|
}): Promise<MastraMessageV2_2[]>;
|
|
224
|
+
deleteMessages(messageIds: string[]): Promise<void>;
|
|
222
225
|
}
|
|
223
226
|
|
|
224
227
|
export declare class StoreOperationsUpstash extends StoreOperations {
|
|
@@ -315,7 +318,16 @@ declare type UpstashOperatorValueMap = Omit<OperatorValueMap, '$options' | '$ele
|
|
|
315
318
|
$contains: string;
|
|
316
319
|
};
|
|
317
320
|
|
|
318
|
-
declare
|
|
321
|
+
export declare interface UpstashQueryVectorParams extends QueryVectorParams<UpstashVectorFilter> {
|
|
322
|
+
sparseVector?: UpstashSparseVector;
|
|
323
|
+
fusionAlgorithm?: FusionAlgorithm;
|
|
324
|
+
queryMode?: QueryMode;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export declare interface UpstashSparseVector {
|
|
328
|
+
indices: number[];
|
|
329
|
+
values: number[];
|
|
330
|
+
}
|
|
319
331
|
|
|
320
332
|
declare class UpstashStore extends MastraStorage {
|
|
321
333
|
private redis;
|
|
@@ -326,6 +338,7 @@ declare class UpstashStore extends MastraStorage {
|
|
|
326
338
|
resourceWorkingMemory: boolean;
|
|
327
339
|
hasColumn: boolean;
|
|
328
340
|
createTable: boolean;
|
|
341
|
+
deleteMessages: boolean;
|
|
329
342
|
};
|
|
330
343
|
/**
|
|
331
344
|
* @deprecated Use getEvals instead
|
|
@@ -472,6 +485,7 @@ declare class UpstashStore extends MastraStorage {
|
|
|
472
485
|
};
|
|
473
486
|
})[];
|
|
474
487
|
}): Promise<MastraMessageV2[]>;
|
|
488
|
+
deleteMessages(messageIds: string[]): Promise<void>;
|
|
475
489
|
getResourceById({ resourceId }: {
|
|
476
490
|
resourceId: string;
|
|
477
491
|
}): Promise<StorageResourceType | null>;
|
|
@@ -515,6 +529,18 @@ declare class UpstashStore extends MastraStorage {
|
|
|
515
529
|
export { UpstashStore }
|
|
516
530
|
export { UpstashStore as UpstashStore_alias_1 }
|
|
517
531
|
|
|
532
|
+
export declare interface UpstashUpdateVectorParams extends UpdateVectorParams {
|
|
533
|
+
update: {
|
|
534
|
+
vector?: number[];
|
|
535
|
+
metadata?: Record<string, any>;
|
|
536
|
+
sparseVector?: UpstashSparseVector;
|
|
537
|
+
};
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export declare interface UpstashUpsertVectorParams extends UpsertVectorParams {
|
|
541
|
+
sparseVectors?: UpstashSparseVector[];
|
|
542
|
+
}
|
|
543
|
+
|
|
518
544
|
declare class UpstashVector extends MastraVector<UpstashVectorFilter> {
|
|
519
545
|
private client;
|
|
520
546
|
/**
|
|
@@ -532,7 +558,7 @@ declare class UpstashVector extends MastraVector<UpstashVectorFilter> {
|
|
|
532
558
|
* @param {UpsertVectorParams} params - The parameters for the upsert operation.
|
|
533
559
|
* @returns {Promise<string[]>} A promise that resolves to the IDs of the upserted vectors.
|
|
534
560
|
*/
|
|
535
|
-
upsert({ indexName: namespace, vectors, metadata, ids }:
|
|
561
|
+
upsert({ indexName: namespace, vectors, metadata, ids, sparseVectors, }: UpstashUpsertVectorParams): Promise<string[]>;
|
|
536
562
|
/**
|
|
537
563
|
* Transforms a Mastra vector filter into an Upstash-compatible filter string.
|
|
538
564
|
* @param {UpstashVectorFilter} [filter] - The filter to transform.
|
|
@@ -550,7 +576,7 @@ declare class UpstashVector extends MastraVector<UpstashVectorFilter> {
|
|
|
550
576
|
* @param {QueryVectorParams} params - The parameters for the query operation. indexName is the namespace in Upstash.
|
|
551
577
|
* @returns {Promise<QueryResult[]>} A promise that resolves to the query results.
|
|
552
578
|
*/
|
|
553
|
-
query({ indexName: namespace, queryVector, topK, filter, includeVector, }: UpstashQueryVectorParams): Promise<QueryResult[]>;
|
|
579
|
+
query({ indexName: namespace, queryVector, topK, filter, includeVector, sparseVector, fusionAlgorithm, queryMode, }: UpstashQueryVectorParams): Promise<QueryResult[]>;
|
|
554
580
|
/**
|
|
555
581
|
* Lists all namespaces in the Upstash vector index, which correspond to indexes.
|
|
556
582
|
* @returns {Promise<string[]>} A promise that resolves to a list of index names.
|
|
@@ -579,7 +605,7 @@ declare class UpstashVector extends MastraVector<UpstashVectorFilter> {
|
|
|
579
605
|
* @returns A promise that resolves when the update is complete.
|
|
580
606
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
581
607
|
*/
|
|
582
|
-
updateVector({ indexName: namespace, id, update }:
|
|
608
|
+
updateVector({ indexName: namespace, id, update }: UpstashUpdateVectorParams): Promise<void>;
|
|
583
609
|
/**
|
|
584
610
|
* Deletes a vector by its ID.
|
|
585
611
|
* @param indexName - The name of the namespace containing the vector.
|
package/dist/index.cjs
CHANGED
|
@@ -951,6 +951,60 @@ var StoreMemoryUpstash = class extends storage.MemoryStorage {
|
|
|
951
951
|
);
|
|
952
952
|
}
|
|
953
953
|
}
|
|
954
|
+
async deleteMessages(messageIds) {
|
|
955
|
+
if (!messageIds || messageIds.length === 0) {
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
try {
|
|
959
|
+
const threadIds = /* @__PURE__ */ new Set();
|
|
960
|
+
const messageKeys = [];
|
|
961
|
+
for (const messageId of messageIds) {
|
|
962
|
+
const pattern = getMessageKey("*", messageId);
|
|
963
|
+
const keys = await this.operations.scanKeys(pattern);
|
|
964
|
+
for (const key of keys) {
|
|
965
|
+
const message = await this.client.get(key);
|
|
966
|
+
if (message && message.id === messageId) {
|
|
967
|
+
messageKeys.push(key);
|
|
968
|
+
if (message.threadId) {
|
|
969
|
+
threadIds.add(message.threadId);
|
|
970
|
+
}
|
|
971
|
+
break;
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
if (messageKeys.length === 0) {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
const pipeline = this.client.pipeline();
|
|
979
|
+
for (const key of messageKeys) {
|
|
980
|
+
pipeline.del(key);
|
|
981
|
+
}
|
|
982
|
+
if (threadIds.size > 0) {
|
|
983
|
+
for (const threadId of threadIds) {
|
|
984
|
+
const threadKey = getKey(storage.TABLE_THREADS, { id: threadId });
|
|
985
|
+
const thread = await this.client.get(threadKey);
|
|
986
|
+
if (thread) {
|
|
987
|
+
const updatedThread = {
|
|
988
|
+
...thread,
|
|
989
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
990
|
+
};
|
|
991
|
+
pipeline.set(threadKey, processRecord(storage.TABLE_THREADS, updatedThread).processedRecord);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
await pipeline.exec();
|
|
996
|
+
} catch (error$1) {
|
|
997
|
+
throw new error.MastraError(
|
|
998
|
+
{
|
|
999
|
+
id: "STORAGE_UPSTASH_DELETE_MESSAGES_FAILED",
|
|
1000
|
+
domain: error.ErrorDomain.STORAGE,
|
|
1001
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
1002
|
+
details: { messageIds: messageIds.join(", ") }
|
|
1003
|
+
},
|
|
1004
|
+
error$1
|
|
1005
|
+
);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
954
1008
|
};
|
|
955
1009
|
var StoreOperationsUpstash = class extends storage.StoreOperations {
|
|
956
1010
|
client;
|
|
@@ -1615,7 +1669,8 @@ var UpstashStore = class extends storage.MastraStorage {
|
|
|
1615
1669
|
selectByIncludeResourceScope: true,
|
|
1616
1670
|
resourceWorkingMemory: true,
|
|
1617
1671
|
hasColumn: false,
|
|
1618
|
-
createTable: false
|
|
1672
|
+
createTable: false,
|
|
1673
|
+
deleteMessages: true
|
|
1619
1674
|
};
|
|
1620
1675
|
}
|
|
1621
1676
|
/**
|
|
@@ -1739,6 +1794,9 @@ var UpstashStore = class extends storage.MastraStorage {
|
|
|
1739
1794
|
async updateMessages(args) {
|
|
1740
1795
|
return this.stores.memory.updateMessages(args);
|
|
1741
1796
|
}
|
|
1797
|
+
async deleteMessages(messageIds) {
|
|
1798
|
+
return this.stores.memory.deleteMessages(messageIds);
|
|
1799
|
+
}
|
|
1742
1800
|
async getResourceById({ resourceId }) {
|
|
1743
1801
|
return this.stores.memory.getResourceById({ resourceId });
|
|
1744
1802
|
}
|
|
@@ -1995,11 +2053,18 @@ var UpstashVector = class extends vector.MastraVector {
|
|
|
1995
2053
|
* @param {UpsertVectorParams} params - The parameters for the upsert operation.
|
|
1996
2054
|
* @returns {Promise<string[]>} A promise that resolves to the IDs of the upserted vectors.
|
|
1997
2055
|
*/
|
|
1998
|
-
async upsert({
|
|
2056
|
+
async upsert({
|
|
2057
|
+
indexName: namespace,
|
|
2058
|
+
vectors,
|
|
2059
|
+
metadata,
|
|
2060
|
+
ids,
|
|
2061
|
+
sparseVectors
|
|
2062
|
+
}) {
|
|
1999
2063
|
const generatedIds = ids || vectors.map(() => crypto.randomUUID());
|
|
2000
2064
|
const points = vectors.map((vector, index) => ({
|
|
2001
2065
|
id: generatedIds[index],
|
|
2002
2066
|
vector,
|
|
2067
|
+
...sparseVectors?.[index] && { sparseVector: sparseVectors[index] },
|
|
2003
2068
|
metadata: metadata?.[index]
|
|
2004
2069
|
}));
|
|
2005
2070
|
try {
|
|
@@ -2046,7 +2111,10 @@ var UpstashVector = class extends vector.MastraVector {
|
|
|
2046
2111
|
queryVector,
|
|
2047
2112
|
topK = 10,
|
|
2048
2113
|
filter,
|
|
2049
|
-
includeVector = false
|
|
2114
|
+
includeVector = false,
|
|
2115
|
+
sparseVector,
|
|
2116
|
+
fusionAlgorithm,
|
|
2117
|
+
queryMode
|
|
2050
2118
|
}) {
|
|
2051
2119
|
try {
|
|
2052
2120
|
const ns = this.client.namespace(namespace);
|
|
@@ -2054,9 +2122,12 @@ var UpstashVector = class extends vector.MastraVector {
|
|
|
2054
2122
|
const results = await ns.query({
|
|
2055
2123
|
topK,
|
|
2056
2124
|
vector: queryVector,
|
|
2125
|
+
...sparseVector && { sparseVector },
|
|
2057
2126
|
includeVectors: includeVector,
|
|
2058
2127
|
includeMetadata: true,
|
|
2059
|
-
...filterString ? { filter: filterString } : {}
|
|
2128
|
+
...filterString ? { filter: filterString } : {},
|
|
2129
|
+
...fusionAlgorithm && { fusionAlgorithm },
|
|
2130
|
+
...queryMode && { queryMode }
|
|
2060
2131
|
});
|
|
2061
2132
|
return (results || []).map((result) => ({
|
|
2062
2133
|
id: `${result.id}`,
|
|
@@ -2152,40 +2223,30 @@ var UpstashVector = class extends vector.MastraVector {
|
|
|
2152
2223
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
2153
2224
|
*/
|
|
2154
2225
|
async updateVector({ indexName: namespace, id, update }) {
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
throw new error.MastraError(
|
|
2164
|
-
{
|
|
2165
|
-
id: "STORAGE_UPSTASH_VECTOR_UPDATE_VECTOR_FAILED",
|
|
2166
|
-
domain: error.ErrorDomain.STORAGE,
|
|
2167
|
-
category: error.ErrorCategory.THIRD_PARTY,
|
|
2168
|
-
details: { namespace, id }
|
|
2169
|
-
},
|
|
2170
|
-
error$1
|
|
2171
|
-
);
|
|
2226
|
+
if (!update.vector && !update.metadata && !update.sparseVector) {
|
|
2227
|
+
throw new error.MastraError({
|
|
2228
|
+
id: "STORAGE_UPSTASH_VECTOR_UPDATE_VECTOR_FAILED",
|
|
2229
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2230
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
2231
|
+
details: { namespace, id },
|
|
2232
|
+
text: "No update data provided"
|
|
2233
|
+
});
|
|
2172
2234
|
}
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
}
|
|
2181
|
-
const points = {
|
|
2182
|
-
id: updatePayload.id,
|
|
2183
|
-
vector: updatePayload.vector,
|
|
2184
|
-
metadata: updatePayload.metadata
|
|
2185
|
-
};
|
|
2186
|
-
await this.client.upsert(points, {
|
|
2187
|
-
namespace
|
|
2235
|
+
if (!update.vector && !update.sparseVector && update.metadata) {
|
|
2236
|
+
throw new error.MastraError({
|
|
2237
|
+
id: "STORAGE_UPSTASH_VECTOR_UPDATE_VECTOR_FAILED",
|
|
2238
|
+
domain: error.ErrorDomain.STORAGE,
|
|
2239
|
+
category: error.ErrorCategory.THIRD_PARTY,
|
|
2240
|
+
details: { namespace, id },
|
|
2241
|
+
text: "Both vector and metadata must be provided for an update"
|
|
2188
2242
|
});
|
|
2243
|
+
}
|
|
2244
|
+
try {
|
|
2245
|
+
const points = { id };
|
|
2246
|
+
if (update.vector) points.vector = update.vector;
|
|
2247
|
+
if (update.metadata) points.metadata = update.metadata;
|
|
2248
|
+
if (update.sparseVector) points.sparseVector = update.sparseVector;
|
|
2249
|
+
await this.client.upsert(points, { namespace });
|
|
2189
2250
|
} catch (error$1) {
|
|
2190
2251
|
throw new error.MastraError(
|
|
2191
2252
|
{
|