@mastra/pg 0.3.4-alpha.2 → 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 +18 -0
- package/dist/_tsup-dts-rollup.d.cts +46 -2
- package/dist/_tsup-dts-rollup.d.ts +46 -2
- package/dist/index.cjs +78 -4
- package/dist/index.js +78 -4
- package/package.json +2 -2
- package/src/storage/index.ts +4 -4
- package/src/vector/index.test.ts +26 -6
- package/src/vector/index.ts +87 -4
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
|
-
[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[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,23 @@
|
|
|
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
|
+
|
|
14
|
+
## 0.3.4-alpha.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- 2836734: [MASTRA-3391] fix describe index for custom schema
|
|
19
|
+
- a3fc60c: fix whereClause condition for fromDate and toDate in pg getTraces
|
|
20
|
+
|
|
3
21
|
## 0.3.4-alpha.2
|
|
4
22
|
|
|
5
23
|
### 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) {
|
|
@@ -718,6 +720,18 @@ var PgVector = class extends vector.MastraVector {
|
|
|
718
720
|
const client = await this.pool.connect();
|
|
719
721
|
try {
|
|
720
722
|
const tableName = this.getTableName(indexName);
|
|
723
|
+
const tableExistsQuery = `
|
|
724
|
+
SELECT 1
|
|
725
|
+
FROM information_schema.columns
|
|
726
|
+
WHERE table_schema = $1
|
|
727
|
+
AND table_name = $2
|
|
728
|
+
AND udt_name = 'vector'
|
|
729
|
+
LIMIT 1;
|
|
730
|
+
`;
|
|
731
|
+
const tableExists = await client.query(tableExistsQuery, [this.schema || "public", indexName]);
|
|
732
|
+
if (tableExists.rows.length === 0) {
|
|
733
|
+
throw new Error(`Vector table ${tableName} does not exist`);
|
|
734
|
+
}
|
|
721
735
|
const dimensionQuery = `
|
|
722
736
|
SELECT atttypmod as dimension
|
|
723
737
|
FROM pg_attribute
|
|
@@ -737,12 +751,14 @@ var PgVector = class extends vector.MastraVector {
|
|
|
737
751
|
JOIN pg_class c ON i.indexrelid = c.oid
|
|
738
752
|
JOIN pg_am am ON c.relam = am.oid
|
|
739
753
|
JOIN pg_opclass opclass ON i.indclass[0] = opclass.oid
|
|
740
|
-
|
|
754
|
+
JOIN pg_namespace n ON c.relnamespace = n.oid
|
|
755
|
+
WHERE c.relname = $1
|
|
756
|
+
AND n.nspname = $2;
|
|
741
757
|
`;
|
|
742
758
|
const [dimResult, countResult, indexResult] = await Promise.all([
|
|
743
759
|
client.query(dimensionQuery, [tableName]),
|
|
744
760
|
client.query(countQuery),
|
|
745
|
-
client.query(indexQuery)
|
|
761
|
+
client.query(indexQuery, [`${indexName}_vector_idx`, this.schema || "public"])
|
|
746
762
|
]);
|
|
747
763
|
const { index_method, index_def, operator_class } = indexResult.rows[0] || {
|
|
748
764
|
index_method: "flat",
|
|
@@ -802,7 +818,37 @@ var PgVector = class extends vector.MastraVector {
|
|
|
802
818
|
async disconnect() {
|
|
803
819
|
await this.pool.end();
|
|
804
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
|
+
*/
|
|
805
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) {
|
|
806
852
|
if (!update.vector && !update.metadata) {
|
|
807
853
|
throw new Error("No updates provided");
|
|
808
854
|
}
|
|
@@ -830,11 +876,37 @@ var PgVector = class extends vector.MastraVector {
|
|
|
830
876
|
WHERE vector_id = $1
|
|
831
877
|
`;
|
|
832
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}`);
|
|
833
881
|
} finally {
|
|
834
882
|
client.release();
|
|
835
883
|
}
|
|
836
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
|
+
*/
|
|
837
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) {
|
|
838
910
|
const client = await this.pool.connect();
|
|
839
911
|
try {
|
|
840
912
|
const tableName = this.getTableName(indexName);
|
|
@@ -843,6 +915,8 @@ var PgVector = class extends vector.MastraVector {
|
|
|
843
915
|
WHERE vector_id = $1
|
|
844
916
|
`;
|
|
845
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}`);
|
|
846
920
|
} finally {
|
|
847
921
|
client.release();
|
|
848
922
|
}
|
|
@@ -875,7 +949,7 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
875
949
|
this.pgp = pgPromise__default.default();
|
|
876
950
|
if ("schema" in config && config.schema) {
|
|
877
951
|
console.warn(
|
|
878
|
-
'[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.'
|
|
879
953
|
);
|
|
880
954
|
}
|
|
881
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) {
|
|
@@ -710,6 +712,18 @@ var PgVector = class extends MastraVector {
|
|
|
710
712
|
const client = await this.pool.connect();
|
|
711
713
|
try {
|
|
712
714
|
const tableName = this.getTableName(indexName);
|
|
715
|
+
const tableExistsQuery = `
|
|
716
|
+
SELECT 1
|
|
717
|
+
FROM information_schema.columns
|
|
718
|
+
WHERE table_schema = $1
|
|
719
|
+
AND table_name = $2
|
|
720
|
+
AND udt_name = 'vector'
|
|
721
|
+
LIMIT 1;
|
|
722
|
+
`;
|
|
723
|
+
const tableExists = await client.query(tableExistsQuery, [this.schema || "public", indexName]);
|
|
724
|
+
if (tableExists.rows.length === 0) {
|
|
725
|
+
throw new Error(`Vector table ${tableName} does not exist`);
|
|
726
|
+
}
|
|
713
727
|
const dimensionQuery = `
|
|
714
728
|
SELECT atttypmod as dimension
|
|
715
729
|
FROM pg_attribute
|
|
@@ -729,12 +743,14 @@ var PgVector = class extends MastraVector {
|
|
|
729
743
|
JOIN pg_class c ON i.indexrelid = c.oid
|
|
730
744
|
JOIN pg_am am ON c.relam = am.oid
|
|
731
745
|
JOIN pg_opclass opclass ON i.indclass[0] = opclass.oid
|
|
732
|
-
|
|
746
|
+
JOIN pg_namespace n ON c.relnamespace = n.oid
|
|
747
|
+
WHERE c.relname = $1
|
|
748
|
+
AND n.nspname = $2;
|
|
733
749
|
`;
|
|
734
750
|
const [dimResult, countResult, indexResult] = await Promise.all([
|
|
735
751
|
client.query(dimensionQuery, [tableName]),
|
|
736
752
|
client.query(countQuery),
|
|
737
|
-
client.query(indexQuery)
|
|
753
|
+
client.query(indexQuery, [`${indexName}_vector_idx`, this.schema || "public"])
|
|
738
754
|
]);
|
|
739
755
|
const { index_method, index_def, operator_class } = indexResult.rows[0] || {
|
|
740
756
|
index_method: "flat",
|
|
@@ -794,7 +810,37 @@ var PgVector = class extends MastraVector {
|
|
|
794
810
|
async disconnect() {
|
|
795
811
|
await this.pool.end();
|
|
796
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
|
+
*/
|
|
797
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) {
|
|
798
844
|
if (!update.vector && !update.metadata) {
|
|
799
845
|
throw new Error("No updates provided");
|
|
800
846
|
}
|
|
@@ -822,11 +868,37 @@ var PgVector = class extends MastraVector {
|
|
|
822
868
|
WHERE vector_id = $1
|
|
823
869
|
`;
|
|
824
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}`);
|
|
825
873
|
} finally {
|
|
826
874
|
client.release();
|
|
827
875
|
}
|
|
828
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
|
+
*/
|
|
829
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) {
|
|
830
902
|
const client = await this.pool.connect();
|
|
831
903
|
try {
|
|
832
904
|
const tableName = this.getTableName(indexName);
|
|
@@ -835,6 +907,8 @@ var PgVector = class extends MastraVector {
|
|
|
835
907
|
WHERE vector_id = $1
|
|
836
908
|
`;
|
|
837
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}`);
|
|
838
912
|
} finally {
|
|
839
913
|
client.release();
|
|
840
914
|
}
|
|
@@ -867,7 +941,7 @@ var PostgresStore = class extends MastraStorage {
|
|
|
867
941
|
this.pgp = pgPromise();
|
|
868
942
|
if ("schema" in config && config.schema) {
|
|
869
943
|
console.warn(
|
|
870
|
-
'[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.'
|
|
871
945
|
);
|
|
872
946
|
}
|
|
873
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;
|
|
@@ -203,11 +203,11 @@ export class PostgresStore extends MastraStorage {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
if (fromDate) {
|
|
206
|
-
conditions.push(`createdAt >=
|
|
206
|
+
conditions.push(`createdAt >= \$${idx++}`);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
if (toDate) {
|
|
210
|
-
conditions.push(`createdAt <=
|
|
210
|
+
conditions.push(`createdAt <= \$${idx++}`);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
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,
|
|
@@ -2139,6 +2139,26 @@ describe('PgVector', () => {
|
|
|
2139
2139
|
}
|
|
2140
2140
|
});
|
|
2141
2141
|
|
|
2142
|
+
it('should describe index in custom schema', async () => {
|
|
2143
|
+
// Create index in custom schema
|
|
2144
|
+
await customSchemaVectorDB.createIndex({
|
|
2145
|
+
indexName: testIndexName,
|
|
2146
|
+
dimension: 3,
|
|
2147
|
+
metric: 'dotproduct',
|
|
2148
|
+
indexConfig: { type: 'hnsw' },
|
|
2149
|
+
});
|
|
2150
|
+
// Insert a vector
|
|
2151
|
+
await customSchemaVectorDB.upsert({ indexName: testIndexName, vectors: [[1, 2, 3]] });
|
|
2152
|
+
// Describe the index
|
|
2153
|
+
const stats = await customSchemaVectorDB.describeIndex(testIndexName);
|
|
2154
|
+
expect(stats).toMatchObject({
|
|
2155
|
+
dimension: 3,
|
|
2156
|
+
metric: 'dotproduct',
|
|
2157
|
+
type: 'hnsw',
|
|
2158
|
+
count: 1,
|
|
2159
|
+
});
|
|
2160
|
+
});
|
|
2161
|
+
|
|
2142
2162
|
it('should allow same index name in different schemas', async () => {
|
|
2143
2163
|
// Create same index name in both schemas
|
|
2144
2164
|
await vectorDB.createIndex({ indexName: testIndexName, dimension: 3 });
|
|
@@ -2195,7 +2215,7 @@ describe('PgVector', () => {
|
|
|
2195
2215
|
});
|
|
2196
2216
|
|
|
2197
2217
|
// Test delete operation
|
|
2198
|
-
await customSchemaVectorDB.
|
|
2218
|
+
await customSchemaVectorDB.deleteVector(testIndexName, id!);
|
|
2199
2219
|
|
|
2200
2220
|
// Verify deletion
|
|
2201
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
|
|
|
@@ -555,6 +557,21 @@ export class PgVector extends MastraVector {
|
|
|
555
557
|
try {
|
|
556
558
|
const tableName = this.getTableName(indexName);
|
|
557
559
|
|
|
560
|
+
// Check if table exists with a vector column
|
|
561
|
+
const tableExistsQuery = `
|
|
562
|
+
SELECT 1
|
|
563
|
+
FROM information_schema.columns
|
|
564
|
+
WHERE table_schema = $1
|
|
565
|
+
AND table_name = $2
|
|
566
|
+
AND udt_name = 'vector'
|
|
567
|
+
LIMIT 1;
|
|
568
|
+
`;
|
|
569
|
+
const tableExists = await client.query(tableExistsQuery, [this.schema || 'public', indexName]);
|
|
570
|
+
|
|
571
|
+
if (tableExists.rows.length === 0) {
|
|
572
|
+
throw new Error(`Vector table ${tableName} does not exist`);
|
|
573
|
+
}
|
|
574
|
+
|
|
558
575
|
// Get vector dimension
|
|
559
576
|
const dimensionQuery = `
|
|
560
577
|
SELECT atttypmod as dimension
|
|
@@ -579,13 +596,15 @@ export class PgVector extends MastraVector {
|
|
|
579
596
|
JOIN pg_class c ON i.indexrelid = c.oid
|
|
580
597
|
JOIN pg_am am ON c.relam = am.oid
|
|
581
598
|
JOIN pg_opclass opclass ON i.indclass[0] = opclass.oid
|
|
582
|
-
|
|
599
|
+
JOIN pg_namespace n ON c.relnamespace = n.oid
|
|
600
|
+
WHERE c.relname = $1
|
|
601
|
+
AND n.nspname = $2;
|
|
583
602
|
`;
|
|
584
603
|
|
|
585
604
|
const [dimResult, countResult, indexResult] = await Promise.all([
|
|
586
605
|
client.query(dimensionQuery, [tableName]),
|
|
587
606
|
client.query(countQuery),
|
|
588
|
-
client.query(indexQuery),
|
|
607
|
+
client.query(indexQuery, [`${indexName}_vector_idx`, this.schema || 'public']),
|
|
589
608
|
]);
|
|
590
609
|
|
|
591
610
|
const { index_method, index_def, operator_class } = indexResult.rows[0] || {
|
|
@@ -661,7 +680,42 @@ export class PgVector extends MastraVector {
|
|
|
661
680
|
await this.pool.end();
|
|
662
681
|
}
|
|
663
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
|
+
*/
|
|
664
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(
|
|
665
719
|
indexName: string,
|
|
666
720
|
id: string,
|
|
667
721
|
update: {
|
|
@@ -705,12 +759,39 @@ export class PgVector extends MastraVector {
|
|
|
705
759
|
`;
|
|
706
760
|
|
|
707
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}`);
|
|
708
764
|
} finally {
|
|
709
765
|
client.release();
|
|
710
766
|
}
|
|
711
767
|
}
|
|
712
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
|
+
*/
|
|
713
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> {
|
|
714
795
|
const client = await this.pool.connect();
|
|
715
796
|
try {
|
|
716
797
|
const tableName = this.getTableName(indexName);
|
|
@@ -719,6 +800,8 @@ export class PgVector extends MastraVector {
|
|
|
719
800
|
WHERE vector_id = $1
|
|
720
801
|
`;
|
|
721
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}`);
|
|
722
805
|
} finally {
|
|
723
806
|
client.release();
|
|
724
807
|
}
|