@mastra/pg 0.3.4-alpha.3 → 0.3.4-alpha.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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +11 -0
- package/dist/_tsup-dts-rollup.d.cts +46 -2
- package/dist/_tsup-dts-rollup.d.ts +46 -2
- package/dist/index.cjs +62 -2
- package/dist/index.js +62 -2
- package/package.json +2 -2
- package/src/storage/index.ts +2 -2
- package/src/vector/index.test.ts +6 -6
- package/src/vector/index.ts +68 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pg@0.3.4-alpha.
|
|
2
|
+
> @mastra/pg@0.3.4-alpha.4 build /home/runner/work/mastra/mastra/stores/pg
|
|
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 10750ms
|
|
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/pg/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/pg/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 11782ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mESM[39m [1mdist/index.js [22m[32m58.39 KB[39m
|
|
21
|
+
[32mESM[39m ⚡️ Build success in 1573ms
|
|
22
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m58.86 KB[39m
|
|
23
|
+
[32mCJS[39m ⚡️ Build success in 1575ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.3.4-alpha.4
|
|
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
|
+
|
|
3
14
|
## 0.3.4-alpha.3
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -213,7 +213,7 @@ declare class PgVector extends MastraVector {
|
|
|
213
213
|
private schemaSetupComplete;
|
|
214
214
|
/**
|
|
215
215
|
* @deprecated Passing connectionString as a string is deprecated.
|
|
216
|
-
* Use the object parameter instead. This signature will be removed on May 20th.
|
|
216
|
+
* Use the object parameter instead. This signature will be removed on May 20th, 2025.
|
|
217
217
|
*/
|
|
218
218
|
constructor(connectionString: string);
|
|
219
219
|
constructor(config: {
|
|
@@ -234,6 +234,7 @@ declare class PgVector extends MastraVector {
|
|
|
234
234
|
createIndex(...args: ParamsToArgs<PgCreateIndexParams> | PgCreateIndexArgs): Promise<void>;
|
|
235
235
|
/**
|
|
236
236
|
* @deprecated This function is deprecated. Use buildIndex instead
|
|
237
|
+
* This function will be removed on May 20th, 2025
|
|
237
238
|
*/
|
|
238
239
|
defineIndex(indexName: string, metric: "cosine" | "euclidean" | "dotproduct" | undefined, indexConfig: IndexConfig): Promise<void>;
|
|
239
240
|
buildIndex(...args: ParamsToArgs<PgDefineIndexParams> | PgDefineIndexArgs): Promise<void>;
|
|
@@ -244,11 +245,54 @@ declare class PgVector extends MastraVector {
|
|
|
244
245
|
deleteIndex(indexName: string): Promise<void>;
|
|
245
246
|
truncateIndex(indexName: string): Promise<void>;
|
|
246
247
|
disconnect(): Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
250
|
+
*
|
|
251
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
252
|
+
* @param indexName - The name of the index containing the vector.
|
|
253
|
+
* @param id - The ID of the vector to update.
|
|
254
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
255
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
256
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
257
|
+
* @returns A promise that resolves when the update is complete.
|
|
258
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
259
|
+
*/
|
|
247
260
|
updateIndexById(indexName: string, id: string, update: {
|
|
248
261
|
vector?: number[];
|
|
249
262
|
metadata?: Record<string, any>;
|
|
250
263
|
}): Promise<void>;
|
|
264
|
+
/**
|
|
265
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
266
|
+
* @param indexName - The name of the index containing the vector.
|
|
267
|
+
* @param id - The ID of the vector to update.
|
|
268
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
269
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
270
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
271
|
+
* @returns A promise that resolves when the update is complete.
|
|
272
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
273
|
+
*/
|
|
274
|
+
updateVector(indexName: string, id: string, update: {
|
|
275
|
+
vector?: number[];
|
|
276
|
+
metadata?: Record<string, any>;
|
|
277
|
+
}): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
280
|
+
*
|
|
281
|
+
* Deletes a vector by its ID.
|
|
282
|
+
* @param indexName - The name of the index containing the vector.
|
|
283
|
+
* @param id - The ID of the vector to delete.
|
|
284
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
285
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
286
|
+
*/
|
|
251
287
|
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* Deletes a vector by its ID.
|
|
290
|
+
* @param indexName - The name of the index containing the vector.
|
|
291
|
+
* @param id - The ID of the vector to delete.
|
|
292
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
293
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
294
|
+
*/
|
|
295
|
+
deleteVector(indexName: string, id: string): Promise<void>;
|
|
252
296
|
}
|
|
253
297
|
export { PgVector }
|
|
254
298
|
export { PgVector as PgVector_alias_1 }
|
|
@@ -264,7 +308,7 @@ export { PGVECTOR_PROMPT as PGVECTOR_PROMPT_alias_1 }
|
|
|
264
308
|
declare type PostgresConfig = {
|
|
265
309
|
schemaName?: string;
|
|
266
310
|
/**
|
|
267
|
-
* @deprecated Use `schemaName` instead. Support for `schema` will be removed
|
|
311
|
+
* @deprecated Use `schemaName` instead. Support for `schema` will be removed on May 20th, 2025.
|
|
268
312
|
*/
|
|
269
313
|
schema?: string;
|
|
270
314
|
} & ({
|
|
@@ -213,7 +213,7 @@ declare class PgVector extends MastraVector {
|
|
|
213
213
|
private schemaSetupComplete;
|
|
214
214
|
/**
|
|
215
215
|
* @deprecated Passing connectionString as a string is deprecated.
|
|
216
|
-
* Use the object parameter instead. This signature will be removed on May 20th.
|
|
216
|
+
* Use the object parameter instead. This signature will be removed on May 20th, 2025.
|
|
217
217
|
*/
|
|
218
218
|
constructor(connectionString: string);
|
|
219
219
|
constructor(config: {
|
|
@@ -234,6 +234,7 @@ declare class PgVector extends MastraVector {
|
|
|
234
234
|
createIndex(...args: ParamsToArgs<PgCreateIndexParams> | PgCreateIndexArgs): Promise<void>;
|
|
235
235
|
/**
|
|
236
236
|
* @deprecated This function is deprecated. Use buildIndex instead
|
|
237
|
+
* This function will be removed on May 20th, 2025
|
|
237
238
|
*/
|
|
238
239
|
defineIndex(indexName: string, metric: "cosine" | "euclidean" | "dotproduct" | undefined, indexConfig: IndexConfig): Promise<void>;
|
|
239
240
|
buildIndex(...args: ParamsToArgs<PgDefineIndexParams> | PgDefineIndexArgs): Promise<void>;
|
|
@@ -244,11 +245,54 @@ declare class PgVector extends MastraVector {
|
|
|
244
245
|
deleteIndex(indexName: string): Promise<void>;
|
|
245
246
|
truncateIndex(indexName: string): Promise<void>;
|
|
246
247
|
disconnect(): Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
250
|
+
*
|
|
251
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
252
|
+
* @param indexName - The name of the index containing the vector.
|
|
253
|
+
* @param id - The ID of the vector to update.
|
|
254
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
255
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
256
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
257
|
+
* @returns A promise that resolves when the update is complete.
|
|
258
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
259
|
+
*/
|
|
247
260
|
updateIndexById(indexName: string, id: string, update: {
|
|
248
261
|
vector?: number[];
|
|
249
262
|
metadata?: Record<string, any>;
|
|
250
263
|
}): Promise<void>;
|
|
264
|
+
/**
|
|
265
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
266
|
+
* @param indexName - The name of the index containing the vector.
|
|
267
|
+
* @param id - The ID of the vector to update.
|
|
268
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
269
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
270
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
271
|
+
* @returns A promise that resolves when the update is complete.
|
|
272
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
273
|
+
*/
|
|
274
|
+
updateVector(indexName: string, id: string, update: {
|
|
275
|
+
vector?: number[];
|
|
276
|
+
metadata?: Record<string, any>;
|
|
277
|
+
}): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
280
|
+
*
|
|
281
|
+
* Deletes a vector by its ID.
|
|
282
|
+
* @param indexName - The name of the index containing the vector.
|
|
283
|
+
* @param id - The ID of the vector to delete.
|
|
284
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
285
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
286
|
+
*/
|
|
251
287
|
deleteIndexById(indexName: string, id: string): Promise<void>;
|
|
288
|
+
/**
|
|
289
|
+
* Deletes a vector by its ID.
|
|
290
|
+
* @param indexName - The name of the index containing the vector.
|
|
291
|
+
* @param id - The ID of the vector to delete.
|
|
292
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
293
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
294
|
+
*/
|
|
295
|
+
deleteVector(indexName: string, id: string): Promise<void>;
|
|
252
296
|
}
|
|
253
297
|
export { PgVector }
|
|
254
298
|
export { PgVector as PgVector_alias_1 }
|
|
@@ -264,7 +308,7 @@ export { PGVECTOR_PROMPT as PGVECTOR_PROMPT_alias_1 }
|
|
|
264
308
|
declare type PostgresConfig = {
|
|
265
309
|
schemaName?: string;
|
|
266
310
|
/**
|
|
267
|
-
* @deprecated Use `schemaName` instead. Support for `schema` will be removed
|
|
311
|
+
* @deprecated Use `schemaName` instead. Support for `schema` will be removed on May 20th, 2025.
|
|
268
312
|
*/
|
|
269
313
|
schema?: string;
|
|
270
314
|
} & ({
|
package/dist/index.cjs
CHANGED
|
@@ -352,7 +352,7 @@ var PgVector = class extends vector.MastraVector {
|
|
|
352
352
|
Please use an object parameter instead:
|
|
353
353
|
new PgVector({ connectionString })
|
|
354
354
|
|
|
355
|
-
The string signature will be removed on May 20th.`
|
|
355
|
+
The string signature will be removed on May 20th, 2025.`
|
|
356
356
|
);
|
|
357
357
|
connectionString = config;
|
|
358
358
|
schemaName = void 0;
|
|
@@ -601,8 +601,10 @@ var PgVector = class extends vector.MastraVector {
|
|
|
601
601
|
}
|
|
602
602
|
/**
|
|
603
603
|
* @deprecated This function is deprecated. Use buildIndex instead
|
|
604
|
+
* This function will be removed on May 20th, 2025
|
|
604
605
|
*/
|
|
605
606
|
async defineIndex(indexName, metric = "cosine", indexConfig) {
|
|
607
|
+
console.warn("defineIndex is deprecated. Use buildIndex instead. This function will be removed on May 20th, 2025");
|
|
606
608
|
return this.buildIndex({ indexName, metric, indexConfig });
|
|
607
609
|
}
|
|
608
610
|
async buildIndex(...args) {
|
|
@@ -816,7 +818,37 @@ var PgVector = class extends vector.MastraVector {
|
|
|
816
818
|
async disconnect() {
|
|
817
819
|
await this.pool.end();
|
|
818
820
|
}
|
|
821
|
+
/**
|
|
822
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
823
|
+
*
|
|
824
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
825
|
+
* @param indexName - The name of the index containing the vector.
|
|
826
|
+
* @param id - The ID of the vector to update.
|
|
827
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
828
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
829
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
830
|
+
* @returns A promise that resolves when the update is complete.
|
|
831
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
832
|
+
*/
|
|
819
833
|
async updateIndexById(indexName, id, update) {
|
|
834
|
+
this.logger.warn(
|
|
835
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
836
|
+
Please use updateVector() instead.
|
|
837
|
+
updateIndexById() will be removed on May 20th, 2025.`
|
|
838
|
+
);
|
|
839
|
+
await this.updateVector(indexName, id, update);
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
843
|
+
* @param indexName - The name of the index containing the vector.
|
|
844
|
+
* @param id - The ID of the vector to update.
|
|
845
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
846
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
847
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
848
|
+
* @returns A promise that resolves when the update is complete.
|
|
849
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
850
|
+
*/
|
|
851
|
+
async updateVector(indexName, id, update) {
|
|
820
852
|
if (!update.vector && !update.metadata) {
|
|
821
853
|
throw new Error("No updates provided");
|
|
822
854
|
}
|
|
@@ -844,11 +876,37 @@ var PgVector = class extends vector.MastraVector {
|
|
|
844
876
|
WHERE vector_id = $1
|
|
845
877
|
`;
|
|
846
878
|
await client.query(query, values);
|
|
879
|
+
} catch (error) {
|
|
880
|
+
throw new Error(`Failed to update vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
847
881
|
} finally {
|
|
848
882
|
client.release();
|
|
849
883
|
}
|
|
850
884
|
}
|
|
885
|
+
/**
|
|
886
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
887
|
+
*
|
|
888
|
+
* Deletes a vector by its ID.
|
|
889
|
+
* @param indexName - The name of the index containing the vector.
|
|
890
|
+
* @param id - The ID of the vector to delete.
|
|
891
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
892
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
893
|
+
*/
|
|
851
894
|
async deleteIndexById(indexName, id) {
|
|
895
|
+
this.logger.warn(
|
|
896
|
+
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
897
|
+
Please use deleteVector() instead.
|
|
898
|
+
deleteIndexById() will be removed on May 20th, 2025.`
|
|
899
|
+
);
|
|
900
|
+
await this.deleteVector(indexName, id);
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Deletes a vector by its ID.
|
|
904
|
+
* @param indexName - The name of the index containing the vector.
|
|
905
|
+
* @param id - The ID of the vector to delete.
|
|
906
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
907
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
908
|
+
*/
|
|
909
|
+
async deleteVector(indexName, id) {
|
|
852
910
|
const client = await this.pool.connect();
|
|
853
911
|
try {
|
|
854
912
|
const tableName = this.getTableName(indexName);
|
|
@@ -857,6 +915,8 @@ var PgVector = class extends vector.MastraVector {
|
|
|
857
915
|
WHERE vector_id = $1
|
|
858
916
|
`;
|
|
859
917
|
await client.query(query, [id]);
|
|
918
|
+
} catch (error) {
|
|
919
|
+
throw new Error(`Failed to delete vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
860
920
|
} finally {
|
|
861
921
|
client.release();
|
|
862
922
|
}
|
|
@@ -889,7 +949,7 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
889
949
|
this.pgp = pgPromise__default.default();
|
|
890
950
|
if ("schema" in config && config.schema) {
|
|
891
951
|
console.warn(
|
|
892
|
-
'[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed
|
|
952
|
+
'[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed on May 20th, 2025.'
|
|
893
953
|
);
|
|
894
954
|
}
|
|
895
955
|
this.schema = config.schemaName ?? config.schema;
|
package/dist/index.js
CHANGED
|
@@ -344,7 +344,7 @@ var PgVector = class extends MastraVector {
|
|
|
344
344
|
Please use an object parameter instead:
|
|
345
345
|
new PgVector({ connectionString })
|
|
346
346
|
|
|
347
|
-
The string signature will be removed on May 20th.`
|
|
347
|
+
The string signature will be removed on May 20th, 2025.`
|
|
348
348
|
);
|
|
349
349
|
connectionString = config;
|
|
350
350
|
schemaName = void 0;
|
|
@@ -593,8 +593,10 @@ var PgVector = class extends MastraVector {
|
|
|
593
593
|
}
|
|
594
594
|
/**
|
|
595
595
|
* @deprecated This function is deprecated. Use buildIndex instead
|
|
596
|
+
* This function will be removed on May 20th, 2025
|
|
596
597
|
*/
|
|
597
598
|
async defineIndex(indexName, metric = "cosine", indexConfig) {
|
|
599
|
+
console.warn("defineIndex is deprecated. Use buildIndex instead. This function will be removed on May 20th, 2025");
|
|
598
600
|
return this.buildIndex({ indexName, metric, indexConfig });
|
|
599
601
|
}
|
|
600
602
|
async buildIndex(...args) {
|
|
@@ -808,7 +810,37 @@ var PgVector = class extends MastraVector {
|
|
|
808
810
|
async disconnect() {
|
|
809
811
|
await this.pool.end();
|
|
810
812
|
}
|
|
813
|
+
/**
|
|
814
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
815
|
+
*
|
|
816
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
817
|
+
* @param indexName - The name of the index containing the vector.
|
|
818
|
+
* @param id - The ID of the vector to update.
|
|
819
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
820
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
821
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
822
|
+
* @returns A promise that resolves when the update is complete.
|
|
823
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
824
|
+
*/
|
|
811
825
|
async updateIndexById(indexName, id, update) {
|
|
826
|
+
this.logger.warn(
|
|
827
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
828
|
+
Please use updateVector() instead.
|
|
829
|
+
updateIndexById() will be removed on May 20th, 2025.`
|
|
830
|
+
);
|
|
831
|
+
await this.updateVector(indexName, id, update);
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
835
|
+
* @param indexName - The name of the index containing the vector.
|
|
836
|
+
* @param id - The ID of the vector to update.
|
|
837
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
838
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
839
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
840
|
+
* @returns A promise that resolves when the update is complete.
|
|
841
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
842
|
+
*/
|
|
843
|
+
async updateVector(indexName, id, update) {
|
|
812
844
|
if (!update.vector && !update.metadata) {
|
|
813
845
|
throw new Error("No updates provided");
|
|
814
846
|
}
|
|
@@ -836,11 +868,37 @@ var PgVector = class extends MastraVector {
|
|
|
836
868
|
WHERE vector_id = $1
|
|
837
869
|
`;
|
|
838
870
|
await client.query(query, values);
|
|
871
|
+
} catch (error) {
|
|
872
|
+
throw new Error(`Failed to update vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
839
873
|
} finally {
|
|
840
874
|
client.release();
|
|
841
875
|
}
|
|
842
876
|
}
|
|
877
|
+
/**
|
|
878
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
879
|
+
*
|
|
880
|
+
* Deletes a vector by its ID.
|
|
881
|
+
* @param indexName - The name of the index containing the vector.
|
|
882
|
+
* @param id - The ID of the vector to delete.
|
|
883
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
884
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
885
|
+
*/
|
|
843
886
|
async deleteIndexById(indexName, id) {
|
|
887
|
+
this.logger.warn(
|
|
888
|
+
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
889
|
+
Please use deleteVector() instead.
|
|
890
|
+
deleteIndexById() will be removed on May 20th, 2025.`
|
|
891
|
+
);
|
|
892
|
+
await this.deleteVector(indexName, id);
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Deletes a vector by its ID.
|
|
896
|
+
* @param indexName - The name of the index containing the vector.
|
|
897
|
+
* @param id - The ID of the vector to delete.
|
|
898
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
899
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
900
|
+
*/
|
|
901
|
+
async deleteVector(indexName, id) {
|
|
844
902
|
const client = await this.pool.connect();
|
|
845
903
|
try {
|
|
846
904
|
const tableName = this.getTableName(indexName);
|
|
@@ -849,6 +907,8 @@ var PgVector = class extends MastraVector {
|
|
|
849
907
|
WHERE vector_id = $1
|
|
850
908
|
`;
|
|
851
909
|
await client.query(query, [id]);
|
|
910
|
+
} catch (error) {
|
|
911
|
+
throw new Error(`Failed to delete vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
852
912
|
} finally {
|
|
853
913
|
client.release();
|
|
854
914
|
}
|
|
@@ -881,7 +941,7 @@ var PostgresStore = class extends MastraStorage {
|
|
|
881
941
|
this.pgp = pgPromise();
|
|
882
942
|
if ("schema" in config && config.schema) {
|
|
883
943
|
console.warn(
|
|
884
|
-
'[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed
|
|
944
|
+
'[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed on May 20th, 2025.'
|
|
885
945
|
);
|
|
886
946
|
}
|
|
887
947
|
this.schema = config.schemaName ?? config.schema;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.3.4-alpha.
|
|
3
|
+
"version": "0.3.4-alpha.4",
|
|
4
4
|
"description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"pg": "^8.13.3",
|
|
25
25
|
"pg-promise": "^11.11.0",
|
|
26
26
|
"xxhash-wasm": "^1.1.0",
|
|
27
|
-
"@mastra/core": "^0.9.4-alpha.
|
|
27
|
+
"@mastra/core": "^0.9.4-alpha.3"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@microsoft/api-extractor": "^7.52.5",
|
package/src/storage/index.ts
CHANGED
|
@@ -23,7 +23,7 @@ import type { ISSLConfig } from 'pg-promise/typescript/pg-subset';
|
|
|
23
23
|
export type PostgresConfig = {
|
|
24
24
|
schemaName?: string;
|
|
25
25
|
/**
|
|
26
|
-
* @deprecated Use `schemaName` instead. Support for `schema` will be removed
|
|
26
|
+
* @deprecated Use `schemaName` instead. Support for `schema` will be removed on May 20th, 2025.
|
|
27
27
|
*/
|
|
28
28
|
schema?: string;
|
|
29
29
|
} & (
|
|
@@ -74,7 +74,7 @@ export class PostgresStore extends MastraStorage {
|
|
|
74
74
|
// Deprecation notice for schema (old option)
|
|
75
75
|
if ('schema' in config && config.schema) {
|
|
76
76
|
console.warn(
|
|
77
|
-
'[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed
|
|
77
|
+
'[DEPRECATION NOTICE] The "schema" option in PostgresStore is deprecated. Please use "schemaName" instead. Support for "schema" will be removed on May 20th, 2025.',
|
|
78
78
|
);
|
|
79
79
|
}
|
|
80
80
|
this.schema = config.schemaName ?? config.schema;
|
package/src/vector/index.test.ts
CHANGED
|
@@ -285,7 +285,7 @@ describe('PgVector', () => {
|
|
|
285
285
|
metadata: newMetaData,
|
|
286
286
|
};
|
|
287
287
|
|
|
288
|
-
await vectorDB.
|
|
288
|
+
await vectorDB.updateVector(testIndexName, idToBeUpdated, update);
|
|
289
289
|
|
|
290
290
|
const results: QueryResult[] = await vectorDB.query({
|
|
291
291
|
indexName: testIndexName,
|
|
@@ -311,7 +311,7 @@ describe('PgVector', () => {
|
|
|
311
311
|
metadata: newMetaData,
|
|
312
312
|
};
|
|
313
313
|
|
|
314
|
-
await vectorDB.
|
|
314
|
+
await vectorDB.updateVector(testIndexName, idToBeUpdated, update);
|
|
315
315
|
|
|
316
316
|
const results: QueryResult[] = await vectorDB.query({
|
|
317
317
|
indexName: testIndexName,
|
|
@@ -335,7 +335,7 @@ describe('PgVector', () => {
|
|
|
335
335
|
vector: newVector,
|
|
336
336
|
};
|
|
337
337
|
|
|
338
|
-
await vectorDB.
|
|
338
|
+
await vectorDB.updateVector(testIndexName, idToBeUpdated, update);
|
|
339
339
|
|
|
340
340
|
const results: QueryResult[] = await vectorDB.query({
|
|
341
341
|
indexName: testIndexName,
|
|
@@ -348,7 +348,7 @@ describe('PgVector', () => {
|
|
|
348
348
|
});
|
|
349
349
|
|
|
350
350
|
it('should throw exception when no updates are given', async () => {
|
|
351
|
-
await expect(vectorDB.
|
|
351
|
+
await expect(vectorDB.updateVector(testIndexName, 'id', {})).rejects.toThrow('No updates provided');
|
|
352
352
|
});
|
|
353
353
|
});
|
|
354
354
|
|
|
@@ -372,7 +372,7 @@ describe('PgVector', () => {
|
|
|
372
372
|
expect(ids).toHaveLength(3);
|
|
373
373
|
const idToBeDeleted = ids[0];
|
|
374
374
|
|
|
375
|
-
await vectorDB.
|
|
375
|
+
await vectorDB.deleteVector(testIndexName, idToBeDeleted);
|
|
376
376
|
|
|
377
377
|
const results: QueryResult[] = await vectorDB.query({
|
|
378
378
|
indexName: testIndexName,
|
|
@@ -2215,7 +2215,7 @@ describe('PgVector', () => {
|
|
|
2215
2215
|
});
|
|
2216
2216
|
|
|
2217
2217
|
// Test delete operation
|
|
2218
|
-
await customSchemaVectorDB.
|
|
2218
|
+
await customSchemaVectorDB.deleteVector(testIndexName, id!);
|
|
2219
2219
|
|
|
2220
2220
|
// Verify deletion
|
|
2221
2221
|
const results = await customSchemaVectorDB.query({
|
package/src/vector/index.ts
CHANGED
|
@@ -72,7 +72,7 @@ export class PgVector extends MastraVector {
|
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* @deprecated Passing connectionString as a string is deprecated.
|
|
75
|
-
* Use the object parameter instead. This signature will be removed on May 20th.
|
|
75
|
+
* Use the object parameter instead. This signature will be removed on May 20th, 2025.
|
|
76
76
|
*/
|
|
77
77
|
constructor(connectionString: string);
|
|
78
78
|
constructor(config: {
|
|
@@ -101,7 +101,7 @@ export class PgVector extends MastraVector {
|
|
|
101
101
|
Please use an object parameter instead:
|
|
102
102
|
new PgVector({ connectionString })
|
|
103
103
|
|
|
104
|
-
The string signature will be removed on May 20th.`,
|
|
104
|
+
The string signature will be removed on May 20th, 2025.`,
|
|
105
105
|
);
|
|
106
106
|
connectionString = config;
|
|
107
107
|
schemaName = undefined;
|
|
@@ -404,12 +404,14 @@ export class PgVector extends MastraVector {
|
|
|
404
404
|
|
|
405
405
|
/**
|
|
406
406
|
* @deprecated This function is deprecated. Use buildIndex instead
|
|
407
|
+
* This function will be removed on May 20th, 2025
|
|
407
408
|
*/
|
|
408
409
|
async defineIndex(
|
|
409
410
|
indexName: string,
|
|
410
411
|
metric: 'cosine' | 'euclidean' | 'dotproduct' = 'cosine',
|
|
411
412
|
indexConfig: IndexConfig,
|
|
412
413
|
): Promise<void> {
|
|
414
|
+
console.warn('defineIndex is deprecated. Use buildIndex instead. This function will be removed on May 20th, 2025');
|
|
413
415
|
return this.buildIndex({ indexName, metric, indexConfig });
|
|
414
416
|
}
|
|
415
417
|
|
|
@@ -678,7 +680,42 @@ export class PgVector extends MastraVector {
|
|
|
678
680
|
await this.pool.end();
|
|
679
681
|
}
|
|
680
682
|
|
|
683
|
+
/**
|
|
684
|
+
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
685
|
+
*
|
|
686
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
687
|
+
* @param indexName - The name of the index containing the vector.
|
|
688
|
+
* @param id - The ID of the vector to update.
|
|
689
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
690
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
691
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
692
|
+
* @returns A promise that resolves when the update is complete.
|
|
693
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
694
|
+
*/
|
|
681
695
|
async updateIndexById(
|
|
696
|
+
indexName: string,
|
|
697
|
+
id: string,
|
|
698
|
+
update: { vector?: number[]; metadata?: Record<string, any> },
|
|
699
|
+
): Promise<void> {
|
|
700
|
+
this.logger.warn(
|
|
701
|
+
`Deprecation Warning: updateIndexById() is deprecated.
|
|
702
|
+
Please use updateVector() instead.
|
|
703
|
+
updateIndexById() will be removed on May 20th, 2025.`,
|
|
704
|
+
);
|
|
705
|
+
await this.updateVector(indexName, id, update);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Updates a vector by its ID with the provided vector and/or metadata.
|
|
710
|
+
* @param indexName - The name of the index containing the vector.
|
|
711
|
+
* @param id - The ID of the vector to update.
|
|
712
|
+
* @param update - An object containing the vector and/or metadata to update.
|
|
713
|
+
* @param update.vector - An optional array of numbers representing the new vector.
|
|
714
|
+
* @param update.metadata - An optional record containing the new metadata.
|
|
715
|
+
* @returns A promise that resolves when the update is complete.
|
|
716
|
+
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
717
|
+
*/
|
|
718
|
+
async updateVector(
|
|
682
719
|
indexName: string,
|
|
683
720
|
id: string,
|
|
684
721
|
update: {
|
|
@@ -722,12 +759,39 @@ export class PgVector extends MastraVector {
|
|
|
722
759
|
`;
|
|
723
760
|
|
|
724
761
|
await client.query(query, values);
|
|
762
|
+
} catch (error: any) {
|
|
763
|
+
throw new Error(`Failed to update vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
725
764
|
} finally {
|
|
726
765
|
client.release();
|
|
727
766
|
}
|
|
728
767
|
}
|
|
729
768
|
|
|
769
|
+
/**
|
|
770
|
+
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
771
|
+
*
|
|
772
|
+
* Deletes a vector by its ID.
|
|
773
|
+
* @param indexName - The name of the index containing the vector.
|
|
774
|
+
* @param id - The ID of the vector to delete.
|
|
775
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
776
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
777
|
+
*/
|
|
730
778
|
async deleteIndexById(indexName: string, id: string): Promise<void> {
|
|
779
|
+
this.logger.warn(
|
|
780
|
+
`Deprecation Warning: deleteIndexById() is deprecated.
|
|
781
|
+
Please use deleteVector() instead.
|
|
782
|
+
deleteIndexById() will be removed on May 20th, 2025.`,
|
|
783
|
+
);
|
|
784
|
+
await this.deleteVector(indexName, id);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Deletes a vector by its ID.
|
|
789
|
+
* @param indexName - The name of the index containing the vector.
|
|
790
|
+
* @param id - The ID of the vector to delete.
|
|
791
|
+
* @returns A promise that resolves when the deletion is complete.
|
|
792
|
+
* @throws Will throw an error if the deletion operation fails.
|
|
793
|
+
*/
|
|
794
|
+
async deleteVector(indexName: string, id: string): Promise<void> {
|
|
731
795
|
const client = await this.pool.connect();
|
|
732
796
|
try {
|
|
733
797
|
const tableName = this.getTableName(indexName);
|
|
@@ -736,6 +800,8 @@ export class PgVector extends MastraVector {
|
|
|
736
800
|
WHERE vector_id = $1
|
|
737
801
|
`;
|
|
738
802
|
await client.query(query, [id]);
|
|
803
|
+
} catch (error: any) {
|
|
804
|
+
throw new Error(`Failed to delete vector by id: ${id} for index: ${indexName}: ${error.message}`);
|
|
739
805
|
} finally {
|
|
740
806
|
client.release();
|
|
741
807
|
}
|