@mastra/upstash 0.3.4-alpha.1 → 0.3.4-alpha.3
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 -7
- package/CHANGELOG.md +20 -0
- package/dist/_tsup-dts-rollup.d.cts +43 -0
- package/dist/_tsup-dts-rollup.d.ts +43 -0
- package/dist/index.cjs +81 -23
- package/dist/index.js +81 -23
- package/package.json +2 -2
- package/src/vector/index.test.ts +5 -5
- package/src/vector/index.ts +91 -27
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/upstash@0.3.4-alpha.
|
|
2
|
+
> @mastra/upstash@0.3.4-alpha.3 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.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 9618ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/upstash/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/upstash/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 11439ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m31.78 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 1286ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m31.64 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 1286ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/upstash
|
|
2
2
|
|
|
3
|
+
## 0.3.4-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c3bd795: [MASTRA-3358] Deprecate updateIndexById and deleteIndexById
|
|
8
|
+
- Updated dependencies [396be50]
|
|
9
|
+
- Updated dependencies [c3bd795]
|
|
10
|
+
- Updated dependencies [da082f8]
|
|
11
|
+
- Updated dependencies [a5810ce]
|
|
12
|
+
- @mastra/core@0.9.4-alpha.3
|
|
13
|
+
|
|
14
|
+
## 0.3.4-alpha.2
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [3171b5b]
|
|
19
|
+
- Updated dependencies [973e5ac]
|
|
20
|
+
- Updated dependencies [9e1eff5]
|
|
21
|
+
- @mastra/core@0.9.4-alpha.2
|
|
22
|
+
|
|
3
23
|
## 0.3.4-alpha.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -156,11 +156,54 @@ declare class UpstashVector extends MastraVector {
|
|
|
156
156
|
metric: "cosine" | "euclidean" | "dotproduct";
|
|
157
157
|
}>;
|
|
158
158
|
deleteIndex(indexName: string): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
161
|
+
*
|
|
162
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
163
|
+
* @param indexName - The name of the index containing the vector.
|
|
164
|
+
* @param id - The ID of the vector to update.
|
|
165
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
166
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
167
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
168
|
+
* @returns A promise that resolves when the update is complete.
|
|
169
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
170
|
+
*/
|
|
159
171
|
updateIndexById(indexName: string, id: string, update: {
|
|
160
172
|
vector?: number[];
|
|
161
173
|
metadata?: Record<string, any>;
|
|
162
174
|
}): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
177
|
+
* @param indexName - The name of the index containing the vector.
|
|
178
|
+
* @param id - The ID of the vector to update.
|
|
179
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
180
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
181
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
182
|
+
* @returns A promise that resolves when the update is complete.
|
|
183
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
184
|
+
*/
|
|
185
|
+
updateVector(indexName: string, id: string, update: {
|
|
186
|
+
vector?: number[];
|
|
187
|
+
metadata?: Record<string, any>;
|
|
188
|
+
}): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
191
|
+
*
|
|
192
|
+
* Deletes a vector by its ID.
|
|
193
|
+
* @param indexName - The name of the index containing the vector.
|
|
194
|
+
* @param id - The ID of the vector to delete.
|
|
195
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
196
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
197
|
+
*/
|
|
163
198
|
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Deletes a vector by its ID.
|
|
201
|
+
* @param indexName - The name of the index containing the vector.
|
|
202
|
+
* @param id - The ID of the vector to delete.
|
|
203
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
204
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
205
|
+
*/
|
|
206
|
+
deleteVector(indexName: string, id: string): Promise<void>;
|
|
164
207
|
}
|
|
165
208
|
export { UpstashVector }
|
|
166
209
|
export { UpstashVector as UpstashVector_alias_1 }
|
|
@@ -156,11 +156,54 @@ declare class UpstashVector extends MastraVector {
|
|
|
156
156
|
metric: "cosine" | "euclidean" | "dotproduct";
|
|
157
157
|
}>;
|
|
158
158
|
deleteIndex(indexName: string): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
161
|
+
*
|
|
162
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
163
|
+
* @param indexName - The name of the index containing the vector.
|
|
164
|
+
* @param id - The ID of the vector to update.
|
|
165
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
166
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
167
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
168
|
+
* @returns A promise that resolves when the update is complete.
|
|
169
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
170
|
+
*/
|
|
159
171
|
updateIndexById(indexName: string, id: string, update: {
|
|
160
172
|
vector?: number[];
|
|
161
173
|
metadata?: Record<string, any>;
|
|
162
174
|
}): Promise<void>;
|
|
175
|
+
/**
|
|
176
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
177
|
+
* @param indexName - The name of the index containing the vector.
|
|
178
|
+
* @param id - The ID of the vector to update.
|
|
179
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
180
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
181
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
182
|
+
* @returns A promise that resolves when the update is complete.
|
|
183
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
184
|
+
*/
|
|
185
|
+
updateVector(indexName: string, id: string, update: {
|
|
186
|
+
vector?: number[];
|
|
187
|
+
metadata?: Record<string, any>;
|
|
188
|
+
}): Promise<void>;
|
|
189
|
+
/**
|
|
190
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
191
|
+
*
|
|
192
|
+
* Deletes a vector by its ID.
|
|
193
|
+
* @param indexName - The name of the index containing the vector.
|
|
194
|
+
* @param id - The ID of the vector to delete.
|
|
195
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
196
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
197
|
+
*/
|
|
163
198
|
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
199
|
+
/**
|
|
200
|
+
* Deletes a vector by its ID.
|
|
201
|
+
* @param indexName - The name of the index containing the vector.
|
|
202
|
+
* @param id - The ID of the vector to delete.
|
|
203
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
204
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
205
|
+
*/
|
|
206
|
+
deleteVector(indexName: string, id: string): Promise<void>;
|
|
164
207
|
}
|
|
165
208
|
export { UpstashVector }
|
|
166
209
|
export { UpstashVector as UpstashVector_alias_1 }
|
package/dist/index.cjs
CHANGED
|
@@ -734,36 +734,94 @@ var UpstashVector = class extends vector.MastraVector {
|
|
|
734
734
|
console.error("Failed to delete namespace:", error);
|
|
735
735
|
}
|
|
736
736
|
}
|
|
737
|
+
/**
|
|
738
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
739
|
+
*
|
|
740
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
741
|
+
* @param indexName - The name of the index containing the vector.
|
|
742
|
+
* @param id - The ID of the vector to update.
|
|
743
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
744
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
745
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
746
|
+
* @returns A promise that resolves when the update is complete.
|
|
747
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
748
|
+
*/
|
|
737
749
|
async updateIndexById(indexName, id, update) {
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
750
|
+
this.logger.warn(
|
|
751
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
752
|
+
Please use updateVector() instead.
|
|
753
|
+
updateIndexById() will be removed on May 20th, 2025.`
|
|
754
|
+
);
|
|
755
|
+
await this.updateVector(indexName, id, update);
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
759
|
+
* @param indexName - The name of the index containing the vector.
|
|
760
|
+
* @param id - The ID of the vector to update.
|
|
761
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
762
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
763
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
764
|
+
* @returns A promise that resolves when the update is complete.
|
|
765
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
766
|
+
*/
|
|
767
|
+
async updateVector(indexName, id, update) {
|
|
768
|
+
try {
|
|
769
|
+
if (!update.vector && !update.metadata) {
|
|
770
|
+
throw new Error("No update data provided");
|
|
771
|
+
}
|
|
772
|
+
if (!update.vector && update.metadata) {
|
|
773
|
+
throw new Error("Both vector and metadata must be provided for an update");
|
|
774
|
+
}
|
|
775
|
+
const updatePayload = { id };
|
|
776
|
+
if (update.vector) {
|
|
777
|
+
updatePayload.vector = update.vector;
|
|
778
|
+
}
|
|
779
|
+
if (update.metadata) {
|
|
780
|
+
updatePayload.metadata = update.metadata;
|
|
781
|
+
}
|
|
782
|
+
const points = {
|
|
783
|
+
id: updatePayload.id,
|
|
784
|
+
vector: updatePayload.vector,
|
|
785
|
+
metadata: updatePayload.metadata
|
|
786
|
+
};
|
|
787
|
+
await this.client.upsert(points, {
|
|
788
|
+
namespace: indexName
|
|
789
|
+
});
|
|
790
|
+
} catch (error) {
|
|
791
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
/**
|
|
795
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
796
|
+
*
|
|
797
|
+
* Deletes a vector by its ID.
|
|
798
|
+
* @param indexName - The name of the index containing the vector.
|
|
799
|
+
* @param id - The ID of the vector to delete.
|
|
800
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
801
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
802
|
+
*/
|
|
760
803
|
async deleteIndexById(indexName, id) {
|
|
804
|
+
this.logger.warn(
|
|
805
|
+
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
806
|
+
Please use deleteVector() instead.
|
|
807
|
+
deleteIndexById() will be removed on May 20th, 2025.`
|
|
808
|
+
);
|
|
809
|
+
await this.deleteVector(indexName, id);
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Deletes a vector by its ID.
|
|
813
|
+
* @param indexName - The name of the index containing the vector.
|
|
814
|
+
* @param id - The ID of the vector to delete.
|
|
815
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
816
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
817
|
+
*/
|
|
818
|
+
async deleteVector(indexName, id) {
|
|
761
819
|
try {
|
|
762
820
|
await this.client.delete(id, {
|
|
763
821
|
namespace: indexName
|
|
764
822
|
});
|
|
765
823
|
} catch (error) {
|
|
766
|
-
console.error(
|
|
824
|
+
console.error(`Failed to delete vector by id: ${id} for index name: ${indexName}:`, error);
|
|
767
825
|
}
|
|
768
826
|
}
|
|
769
827
|
};
|
package/dist/index.js
CHANGED
|
@@ -732,36 +732,94 @@ var UpstashVector = class extends MastraVector {
|
|
|
732
732
|
console.error("Failed to delete namespace:", error);
|
|
733
733
|
}
|
|
734
734
|
}
|
|
735
|
+
/**
|
|
736
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
737
|
+
*
|
|
738
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
739
|
+
* @param indexName - The name of the index containing the vector.
|
|
740
|
+
* @param id - The ID of the vector to update.
|
|
741
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
742
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
743
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
744
|
+
* @returns A promise that resolves when the update is complete.
|
|
745
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
746
|
+
*/
|
|
735
747
|
async updateIndexById(indexName, id, update) {
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
748
|
+
this.logger.warn(
|
|
749
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
750
|
+
Please use updateVector() instead.
|
|
751
|
+
updateIndexById() will be removed on May 20th, 2025.`
|
|
752
|
+
);
|
|
753
|
+
await this.updateVector(indexName, id, update);
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
757
|
+
* @param indexName - The name of the index containing the vector.
|
|
758
|
+
* @param id - The ID of the vector to update.
|
|
759
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
760
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
761
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
762
|
+
* @returns A promise that resolves when the update is complete.
|
|
763
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
764
|
+
*/
|
|
765
|
+
async updateVector(indexName, id, update) {
|
|
766
|
+
try {
|
|
767
|
+
if (!update.vector && !update.metadata) {
|
|
768
|
+
throw new Error("No update data provided");
|
|
769
|
+
}
|
|
770
|
+
if (!update.vector && update.metadata) {
|
|
771
|
+
throw new Error("Both vector and metadata must be provided for an update");
|
|
772
|
+
}
|
|
773
|
+
const updatePayload = { id };
|
|
774
|
+
if (update.vector) {
|
|
775
|
+
updatePayload.vector = update.vector;
|
|
776
|
+
}
|
|
777
|
+
if (update.metadata) {
|
|
778
|
+
updatePayload.metadata = update.metadata;
|
|
779
|
+
}
|
|
780
|
+
const points = {
|
|
781
|
+
id: updatePayload.id,
|
|
782
|
+
vector: updatePayload.vector,
|
|
783
|
+
metadata: updatePayload.metadata
|
|
784
|
+
};
|
|
785
|
+
await this.client.upsert(points, {
|
|
786
|
+
namespace: indexName
|
|
787
|
+
});
|
|
788
|
+
} catch (error) {
|
|
789
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
794
|
+
*
|
|
795
|
+
* Deletes a vector by its ID.
|
|
796
|
+
* @param indexName - The name of the index containing the vector.
|
|
797
|
+
* @param id - The ID of the vector to delete.
|
|
798
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
799
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
800
|
+
*/
|
|
758
801
|
async deleteIndexById(indexName, id) {
|
|
802
|
+
this.logger.warn(
|
|
803
|
+
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
804
|
+
Please use deleteVector() instead.
|
|
805
|
+
deleteIndexById() will be removed on May 20th, 2025.`
|
|
806
|
+
);
|
|
807
|
+
await this.deleteVector(indexName, id);
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Deletes a vector by its ID.
|
|
811
|
+
* @param indexName - The name of the index containing the vector.
|
|
812
|
+
* @param id - The ID of the vector to delete.
|
|
813
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
814
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
815
|
+
*/
|
|
816
|
+
async deleteVector(indexName, id) {
|
|
759
817
|
try {
|
|
760
818
|
await this.client.delete(id, {
|
|
761
819
|
namespace: indexName
|
|
762
820
|
});
|
|
763
821
|
} catch (error) {
|
|
764
|
-
console.error(
|
|
822
|
+
console.error(`Failed to delete vector by id: ${id} for index name: ${indexName}:`, error);
|
|
765
823
|
}
|
|
766
824
|
}
|
|
767
825
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/upstash",
|
|
3
|
-
"version": "0.3.4-alpha.
|
|
3
|
+
"version": "0.3.4-alpha.3",
|
|
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.34.5",
|
|
24
24
|
"@upstash/vector": "^1.2.1",
|
|
25
|
-
"@mastra/core": "^0.9.4-alpha.
|
|
25
|
+
"@mastra/core": "^0.9.4-alpha.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@microsoft/api-extractor": "^7.52.5",
|
package/src/vector/index.test.ts
CHANGED
|
@@ -140,7 +140,7 @@ describe.skipIf(!process.env.UPSTASH_VECTOR_URL || !process.env.UPSTASH_VECTOR_T
|
|
|
140
140
|
metadata: newMetaData,
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
-
await vectorStore.
|
|
143
|
+
await vectorStore.updateVector(testIndexName, idToBeUpdated, update);
|
|
144
144
|
|
|
145
145
|
await waitUntilVectorsIndexed(vectorStore, testIndexName, 3);
|
|
146
146
|
|
|
@@ -167,7 +167,7 @@ describe.skipIf(!process.env.UPSTASH_VECTOR_URL || !process.env.UPSTASH_VECTOR_T
|
|
|
167
167
|
metadata: newMetaData,
|
|
168
168
|
};
|
|
169
169
|
|
|
170
|
-
await expect(vectorStore.
|
|
170
|
+
await expect(vectorStore.updateVector(testIndexName, 'id', update)).rejects.toThrow(
|
|
171
171
|
'Both vector and metadata must be provided for an update',
|
|
172
172
|
);
|
|
173
173
|
});
|
|
@@ -183,7 +183,7 @@ describe.skipIf(!process.env.UPSTASH_VECTOR_URL || !process.env.UPSTASH_VECTOR_T
|
|
|
183
183
|
vector: newVector,
|
|
184
184
|
};
|
|
185
185
|
|
|
186
|
-
await vectorStore.
|
|
186
|
+
await vectorStore.updateVector(testIndexName, idToBeUpdated, update);
|
|
187
187
|
|
|
188
188
|
await waitUntilVectorsIndexed(vectorStore, testIndexName, 3);
|
|
189
189
|
|
|
@@ -198,7 +198,7 @@ describe.skipIf(!process.env.UPSTASH_VECTOR_URL || !process.env.UPSTASH_VECTOR_T
|
|
|
198
198
|
}, 500000);
|
|
199
199
|
|
|
200
200
|
it('should throw exception when no updates are given', async () => {
|
|
201
|
-
await expect(vectorStore.
|
|
201
|
+
await expect(vectorStore.updateVector(testIndexName, 'id', {})).rejects.toThrow('No update data provided');
|
|
202
202
|
});
|
|
203
203
|
});
|
|
204
204
|
|
|
@@ -214,7 +214,7 @@ describe.skipIf(!process.env.UPSTASH_VECTOR_URL || !process.env.UPSTASH_VECTOR_T
|
|
|
214
214
|
expect(ids).toHaveLength(3);
|
|
215
215
|
const idToBeDeleted = ids[0];
|
|
216
216
|
|
|
217
|
-
await vectorStore.
|
|
217
|
+
await vectorStore.deleteVector(testIndexName, idToBeDeleted);
|
|
218
218
|
|
|
219
219
|
const results: QueryResult[] = await vectorStore.query({
|
|
220
220
|
indexName: testIndexName,
|
package/src/vector/index.ts
CHANGED
|
@@ -98,7 +98,42 @@ export class UpstashVector extends MastraVector {
|
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
103
|
+
*
|
|
104
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
105
|
+
* @param indexName - The name of the index containing the vector.
|
|
106
|
+
* @param id - The ID of the vector to update.
|
|
107
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
108
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
109
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
110
|
+
* @returns A promise that resolves when the update is complete.
|
|
111
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
112
|
+
*/
|
|
101
113
|
async updateIndexById(
|
|
114
|
+
indexName: string,
|
|
115
|
+
id: string,
|
|
116
|
+
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
117
|
+
): Promise<void> {
|
|
118
|
+
this.logger.warn(
|
|
119
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
120
|
+
Please use updateVector() instead.
|
|
121
|
+
updateIndexById() will be removed on May 20th, 2025.`,
|
|
122
|
+
);
|
|
123
|
+
await this.updateVector(indexName, id, update);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
128
|
+
* @param indexName - The name of the index containing the vector.
|
|
129
|
+
* @param id - The ID of the vector to update.
|
|
130
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
131
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
132
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
133
|
+
* @returns A promise that resolves when the update is complete.
|
|
134
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
135
|
+
*/
|
|
136
|
+
async updateVector(
|
|
102
137
|
indexName: string,
|
|
103
138
|
id: string,
|
|
104
139
|
update: {
|
|
@@ -106,42 +141,71 @@ export class UpstashVector extends MastraVector {
|
|
|
106
141
|
metadata?: Record<string, any>;
|
|
107
142
|
},
|
|
108
143
|
): Promise<void> {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
144
|
+
try {
|
|
145
|
+
if (!update.vector && !update.metadata) {
|
|
146
|
+
throw new Error('No update data provided');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// The upstash client throws an exception as: 'This index requires dense vectors' when
|
|
150
|
+
// only metadata is present in the update object.
|
|
151
|
+
if (!update.vector && update.metadata) {
|
|
152
|
+
throw new Error('Both vector and metadata must be provided for an update');
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const updatePayload: any = { id: id };
|
|
156
|
+
if (update.vector) {
|
|
157
|
+
updatePayload.vector = update.vector;
|
|
158
|
+
}
|
|
159
|
+
if (update.metadata) {
|
|
160
|
+
updatePayload.metadata = update.metadata;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const points = {
|
|
164
|
+
id: updatePayload.id,
|
|
165
|
+
vector: updatePayload.vector,
|
|
166
|
+
metadata: updatePayload.metadata,
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
await this.client.upsert(points, {
|
|
170
|
+
namespace: indexName,
|
|
171
|
+
});
|
|
172
|
+
} catch (error: any) {
|
|
173
|
+
throw new Error(`Failed to update vector by id: ${id} for index name: ${indexName}: ${error.message}`);
|
|
125
174
|
}
|
|
126
|
-
|
|
127
|
-
const points = {
|
|
128
|
-
id: updatePayload.id,
|
|
129
|
-
vector: updatePayload.vector,
|
|
130
|
-
metadata: updatePayload.metadata,
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
await this.client.upsert(points, {
|
|
134
|
-
namespace: indexName,
|
|
135
|
-
});
|
|
136
175
|
}
|
|
137
176
|
|
|
177
|
+
/**
|
|
178
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
179
|
+
*
|
|
180
|
+
* Deletes a vector by its ID.
|
|
181
|
+
* @param indexName - The name of the index containing the vector.
|
|
182
|
+
* @param id - The ID of the vector to delete.
|
|
183
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
184
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
185
|
+
*/
|
|
138
186
|
async deleteIndexById(indexName: string, id: string): Promise<void> {
|
|
187
|
+
this.logger.warn(
|
|
188
|
+
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
189
|
+
Please use deleteVector() instead.
|
|
190
|
+
deleteIndexById() will be removed on May 20th, 2025.`,
|
|
191
|
+
);
|
|
192
|
+
await this.deleteVector(indexName, id);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Deletes a vector by its ID.
|
|
197
|
+
* @param indexName - The name of the index containing the vector.
|
|
198
|
+
* @param id - The ID of the vector to delete.
|
|
199
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
200
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
201
|
+
*/
|
|
202
|
+
async deleteVector(indexName: string, id: string): Promise<void> {
|
|
139
203
|
try {
|
|
140
204
|
await this.client.delete(id, {
|
|
141
205
|
namespace: indexName,
|
|
142
206
|
});
|
|
143
207
|
} catch (error) {
|
|
144
|
-
console.error(
|
|
208
|
+
console.error(`Failed to delete vector by id: ${id} for index name: ${indexName}:`, error);
|
|
145
209
|
}
|
|
146
210
|
}
|
|
147
211
|
}
|