@mastra/pg 0.3.4 → 0.3.5-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +15 -0
- package/dist/_tsup-dts-rollup.d.cts +19 -31
- package/dist/_tsup-dts-rollup.d.ts +19 -31
- package/dist/index.cjs +151 -90
- package/dist/index.js +151 -90
- package/docker-compose.perf.yaml +9 -9
- package/package.json +2 -2
- package/src/storage/index.ts +12 -6
- package/src/vector/index.test.ts +53 -51
- package/src/vector/index.ts +47 -21
- package/src/vector/sql-builder.ts +110 -77
- package/src/vector/vector.performance.test.ts +2 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pg@0.3.
|
|
2
|
+
> @mastra/pg@0.3.5-alpha.0 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 9464ms
|
|
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 12331ms
|
|
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[32m61.67 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 1494ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m61.16 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 1495ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.3.5-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- eabdcd9: [MASTRA-3451] SQL Injection Protection
|
|
8
|
+
- d0ee3c6: Change all public functions and constructors in vector stores to use named args and prepare to phase out positional args
|
|
9
|
+
- Updated dependencies [f53a6ac]
|
|
10
|
+
- Updated dependencies [eabdcd9]
|
|
11
|
+
- Updated dependencies [90be034]
|
|
12
|
+
- Updated dependencies [99f050a]
|
|
13
|
+
- Updated dependencies [d0ee3c6]
|
|
14
|
+
- Updated dependencies [23f258c]
|
|
15
|
+
- Updated dependencies [2672a05]
|
|
16
|
+
- @mastra/core@0.9.5-alpha.0
|
|
17
|
+
|
|
3
18
|
## 0.3.4
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import type { ArrayOperator } from '@mastra/core/vector/filter';
|
|
2
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
3
|
-
import type { BasicOperator } from '@mastra/core/vector/filter';
|
|
4
2
|
import type { CreateIndexArgs } from '@mastra/core/vector';
|
|
5
3
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
6
|
-
import type {
|
|
4
|
+
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
5
|
+
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
6
|
+
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
7
7
|
import type { EvalRow } from '@mastra/core/storage';
|
|
8
8
|
import type { IndexStats } from '@mastra/core/vector';
|
|
9
9
|
import type { ISSLConfig } from 'pg-promise/typescript/pg-subset';
|
|
10
|
-
import type { LogicalOperator } from '@mastra/core/vector/filter';
|
|
11
10
|
import { MastraStorage } from '@mastra/core/storage';
|
|
12
11
|
import { MastraVector } from '@mastra/core/vector';
|
|
13
12
|
import type { MessageType } from '@mastra/core/memory';
|
|
14
|
-
import type { NumericOperator } from '@mastra/core/vector/filter';
|
|
15
13
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
16
14
|
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
17
15
|
import pg from 'pg';
|
|
18
16
|
import type { QueryResult } from '@mastra/core/vector';
|
|
19
17
|
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
20
18
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
21
|
-
import type { RegexOperator } from '@mastra/core/vector/filter';
|
|
22
19
|
import type { StorageColumn } from '@mastra/core/storage';
|
|
23
20
|
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
24
21
|
import type { StorageThreadType } from '@mastra/core/memory';
|
|
25
22
|
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
23
|
+
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
26
24
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
27
25
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
28
26
|
import type { WorkflowRun } from '@mastra/core/storage';
|
|
@@ -62,7 +60,7 @@ export declare const baseTestConfigs: {
|
|
|
62
60
|
}[];
|
|
63
61
|
};
|
|
64
62
|
|
|
65
|
-
export declare function buildFilterQuery(filter: VectorFilter, minScore: number): FilterResult;
|
|
63
|
+
export declare function buildFilterQuery(filter: VectorFilter, minScore: number, topK: number): FilterResult;
|
|
66
64
|
|
|
67
65
|
export declare const calculateRecall: (actual: number[], expected: number[], k: number) => number;
|
|
68
66
|
|
|
@@ -70,15 +68,7 @@ export declare const calculateTimeout: (dimension: number, size: number, k: numb
|
|
|
70
68
|
|
|
71
69
|
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
declare type FilterOperator = {
|
|
76
|
-
sql: string;
|
|
77
|
-
needsValue: boolean;
|
|
78
|
-
transformValue?: () => any;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export declare interface FilterResult {
|
|
71
|
+
declare interface FilterResult {
|
|
82
72
|
sql: string;
|
|
83
73
|
values: any[];
|
|
84
74
|
}
|
|
@@ -116,8 +106,6 @@ export declare function getSearchEf(k: number, m: number): {
|
|
|
116
106
|
|
|
117
107
|
export declare const groupBy: <T, K extends keyof T>(array: T[], key: K | ((item: T) => string), reducer?: (group: T[]) => any) => Record<string, any>;
|
|
118
108
|
|
|
119
|
-
export declare const handleKey: (key: string) => string;
|
|
120
|
-
|
|
121
109
|
declare interface HNSWConfig {
|
|
122
110
|
m?: number;
|
|
123
111
|
efConstruction?: number;
|
|
@@ -137,10 +125,6 @@ declare interface IVFConfig {
|
|
|
137
125
|
|
|
138
126
|
export declare function measureLatency<T>(fn: () => Promise<T>): Promise<[number, T]>;
|
|
139
127
|
|
|
140
|
-
declare type OperatorFn = (key: string, paramIndex: number, value?: any) => FilterOperator;
|
|
141
|
-
|
|
142
|
-
export declare type OperatorType = BasicOperator | NumericOperator | ArrayOperator | ElementOperator | LogicalOperator | '$contains' | Exclude<RegexOperator, '$options'>;
|
|
143
|
-
|
|
144
128
|
declare type PgCreateIndexArgs = [...CreateIndexArgs, IndexConfig?, boolean?];
|
|
145
129
|
|
|
146
130
|
declare interface PgCreateIndexParams extends CreateIndexParams {
|
|
@@ -224,7 +208,7 @@ declare class PgVector extends MastraVector {
|
|
|
224
208
|
private getMutexByName;
|
|
225
209
|
private getTableName;
|
|
226
210
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
227
|
-
getIndexInfo(
|
|
211
|
+
getIndexInfo(...args: ParamsToArgs<DescribeIndexParams>): Promise<PGIndexStats>;
|
|
228
212
|
query(...args: ParamsToArgs<PgQueryVectorParams> | PgQueryVectorArgs): Promise<QueryResult[]>;
|
|
229
213
|
upsert(...args: ParamsToArgs<UpsertVectorParams>): Promise<string[]>;
|
|
230
214
|
private hasher;
|
|
@@ -241,9 +225,16 @@ declare class PgVector extends MastraVector {
|
|
|
241
225
|
private setupIndex;
|
|
242
226
|
private installVectorExtension;
|
|
243
227
|
listIndexes(): Promise<string[]>;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Retrieves statistics about a vector index.
|
|
230
|
+
*
|
|
231
|
+
* @param params - The parameters for describing an index
|
|
232
|
+
* @param params.indexName - The name of the index to describe
|
|
233
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
234
|
+
*/
|
|
235
|
+
describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<PGIndexStats>;
|
|
236
|
+
deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
|
|
237
|
+
truncateIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
|
|
247
238
|
disconnect(): Promise<void>;
|
|
248
239
|
/**
|
|
249
240
|
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
@@ -271,10 +262,7 @@ declare class PgVector extends MastraVector {
|
|
|
271
262
|
* @returns A promise that resolves when the update is complete.
|
|
272
263
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
273
264
|
*/
|
|
274
|
-
updateVector(
|
|
275
|
-
vector?: number[];
|
|
276
|
-
metadata?: Record<string, any>;
|
|
277
|
-
}): Promise<void>;
|
|
265
|
+
updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
|
|
278
266
|
/**
|
|
279
267
|
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
280
268
|
*
|
|
@@ -292,7 +280,7 @@ declare class PgVector extends MastraVector {
|
|
|
292
280
|
* @returns A promise that resolves when the deletion is complete.
|
|
293
281
|
* @throws Will throw an error if the deletion operation fails.
|
|
294
282
|
*/
|
|
295
|
-
deleteVector(
|
|
283
|
+
deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
|
|
296
284
|
}
|
|
297
285
|
export { PgVector }
|
|
298
286
|
export { PgVector as PgVector_alias_1 }
|
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import type { ArrayOperator } from '@mastra/core/vector/filter';
|
|
2
1
|
import { BaseFilterTranslator } from '@mastra/core/vector/filter';
|
|
3
|
-
import type { BasicOperator } from '@mastra/core/vector/filter';
|
|
4
2
|
import type { CreateIndexArgs } from '@mastra/core/vector';
|
|
5
3
|
import type { CreateIndexParams } from '@mastra/core/vector';
|
|
6
|
-
import type {
|
|
4
|
+
import type { DeleteIndexParams } from '@mastra/core/vector';
|
|
5
|
+
import type { DeleteVectorParams } from '@mastra/core/vector';
|
|
6
|
+
import type { DescribeIndexParams } from '@mastra/core/vector';
|
|
7
7
|
import type { EvalRow } from '@mastra/core/storage';
|
|
8
8
|
import type { IndexStats } from '@mastra/core/vector';
|
|
9
9
|
import type { ISSLConfig } from 'pg-promise/typescript/pg-subset';
|
|
10
|
-
import type { LogicalOperator } from '@mastra/core/vector/filter';
|
|
11
10
|
import { MastraStorage } from '@mastra/core/storage';
|
|
12
11
|
import { MastraVector } from '@mastra/core/vector';
|
|
13
12
|
import type { MessageType } from '@mastra/core/memory';
|
|
14
|
-
import type { NumericOperator } from '@mastra/core/vector/filter';
|
|
15
13
|
import type { OperatorSupport } from '@mastra/core/vector/filter';
|
|
16
14
|
import type { ParamsToArgs } from '@mastra/core/vector';
|
|
17
15
|
import pg from 'pg';
|
|
18
16
|
import type { QueryResult } from '@mastra/core/vector';
|
|
19
17
|
import type { QueryVectorArgs } from '@mastra/core/vector';
|
|
20
18
|
import type { QueryVectorParams } from '@mastra/core/vector';
|
|
21
|
-
import type { RegexOperator } from '@mastra/core/vector/filter';
|
|
22
19
|
import type { StorageColumn } from '@mastra/core/storage';
|
|
23
20
|
import type { StorageGetMessagesArg } from '@mastra/core/storage';
|
|
24
21
|
import type { StorageThreadType } from '@mastra/core/memory';
|
|
25
22
|
import type { TABLE_NAMES } from '@mastra/core/storage';
|
|
23
|
+
import type { UpdateVectorParams } from '@mastra/core/vector';
|
|
26
24
|
import type { UpsertVectorParams } from '@mastra/core/vector';
|
|
27
25
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
28
26
|
import type { WorkflowRun } from '@mastra/core/storage';
|
|
@@ -62,7 +60,7 @@ export declare const baseTestConfigs: {
|
|
|
62
60
|
}[];
|
|
63
61
|
};
|
|
64
62
|
|
|
65
|
-
export declare function buildFilterQuery(filter: VectorFilter, minScore: number): FilterResult;
|
|
63
|
+
export declare function buildFilterQuery(filter: VectorFilter, minScore: number, topK: number): FilterResult;
|
|
66
64
|
|
|
67
65
|
export declare const calculateRecall: (actual: number[], expected: number[], k: number) => number;
|
|
68
66
|
|
|
@@ -70,15 +68,7 @@ export declare const calculateTimeout: (dimension: number, size: number, k: numb
|
|
|
70
68
|
|
|
71
69
|
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
declare type FilterOperator = {
|
|
76
|
-
sql: string;
|
|
77
|
-
needsValue: boolean;
|
|
78
|
-
transformValue?: () => any;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
export declare interface FilterResult {
|
|
71
|
+
declare interface FilterResult {
|
|
82
72
|
sql: string;
|
|
83
73
|
values: any[];
|
|
84
74
|
}
|
|
@@ -116,8 +106,6 @@ export declare function getSearchEf(k: number, m: number): {
|
|
|
116
106
|
|
|
117
107
|
export declare const groupBy: <T, K extends keyof T>(array: T[], key: K | ((item: T) => string), reducer?: (group: T[]) => any) => Record<string, any>;
|
|
118
108
|
|
|
119
|
-
export declare const handleKey: (key: string) => string;
|
|
120
|
-
|
|
121
109
|
declare interface HNSWConfig {
|
|
122
110
|
m?: number;
|
|
123
111
|
efConstruction?: number;
|
|
@@ -137,10 +125,6 @@ declare interface IVFConfig {
|
|
|
137
125
|
|
|
138
126
|
export declare function measureLatency<T>(fn: () => Promise<T>): Promise<[number, T]>;
|
|
139
127
|
|
|
140
|
-
declare type OperatorFn = (key: string, paramIndex: number, value?: any) => FilterOperator;
|
|
141
|
-
|
|
142
|
-
export declare type OperatorType = BasicOperator | NumericOperator | ArrayOperator | ElementOperator | LogicalOperator | '$contains' | Exclude<RegexOperator, '$options'>;
|
|
143
|
-
|
|
144
128
|
declare type PgCreateIndexArgs = [...CreateIndexArgs, IndexConfig?, boolean?];
|
|
145
129
|
|
|
146
130
|
declare interface PgCreateIndexParams extends CreateIndexParams {
|
|
@@ -224,7 +208,7 @@ declare class PgVector extends MastraVector {
|
|
|
224
208
|
private getMutexByName;
|
|
225
209
|
private getTableName;
|
|
226
210
|
transformFilter(filter?: VectorFilter): VectorFilter;
|
|
227
|
-
getIndexInfo(
|
|
211
|
+
getIndexInfo(...args: ParamsToArgs<DescribeIndexParams>): Promise<PGIndexStats>;
|
|
228
212
|
query(...args: ParamsToArgs<PgQueryVectorParams> | PgQueryVectorArgs): Promise<QueryResult[]>;
|
|
229
213
|
upsert(...args: ParamsToArgs<UpsertVectorParams>): Promise<string[]>;
|
|
230
214
|
private hasher;
|
|
@@ -241,9 +225,16 @@ declare class PgVector extends MastraVector {
|
|
|
241
225
|
private setupIndex;
|
|
242
226
|
private installVectorExtension;
|
|
243
227
|
listIndexes(): Promise<string[]>;
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Retrieves statistics about a vector index.
|
|
230
|
+
*
|
|
231
|
+
* @param params - The parameters for describing an index
|
|
232
|
+
* @param params.indexName - The name of the index to describe
|
|
233
|
+
* @returns A promise that resolves to the index statistics including dimension, count and metric
|
|
234
|
+
*/
|
|
235
|
+
describeIndex(...args: ParamsToArgs<DescribeIndexParams>): Promise<PGIndexStats>;
|
|
236
|
+
deleteIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
|
|
237
|
+
truncateIndex(...args: ParamsToArgs<DeleteIndexParams>): Promise<void>;
|
|
247
238
|
disconnect(): Promise<void>;
|
|
248
239
|
/**
|
|
249
240
|
* @deprecated Use {@link updateVector} instead. This method will be removed on May 20th, 2025.
|
|
@@ -271,10 +262,7 @@ declare class PgVector extends MastraVector {
|
|
|
271
262
|
* @returns A promise that resolves when the update is complete.
|
|
272
263
|
* @throws Will throw an error if no updates are provided or if the update operation fails.
|
|
273
264
|
*/
|
|
274
|
-
updateVector(
|
|
275
|
-
vector?: number[];
|
|
276
|
-
metadata?: Record<string, any>;
|
|
277
|
-
}): Promise<void>;
|
|
265
|
+
updateVector(...args: ParamsToArgs<UpdateVectorParams>): Promise<void>;
|
|
278
266
|
/**
|
|
279
267
|
* @deprecated Use {@link deleteVector} instead. This method will be removed on May 20th, 2025.
|
|
280
268
|
*
|
|
@@ -292,7 +280,7 @@ declare class PgVector extends MastraVector {
|
|
|
292
280
|
* @returns A promise that resolves when the deletion is complete.
|
|
293
281
|
* @throws Will throw an error if the deletion operation fails.
|
|
294
282
|
*/
|
|
295
|
-
deleteVector(
|
|
283
|
+
deleteVector(...args: ParamsToArgs<DeleteVectorParams>): Promise<void>;
|
|
296
284
|
}
|
|
297
285
|
export { PgVector }
|
|
298
286
|
export { PgVector as PgVector_alias_1 }
|