@mastra/pg 1.0.0-beta.1 → 1.0.0-beta.11

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +548 -0
  2. package/README.md +3 -0
  3. package/dist/index.cjs +3239 -2110
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +3232 -2108
  8. package/dist/index.js.map +1 -1
  9. package/dist/shared/config.d.ts +121 -31
  10. package/dist/shared/config.d.ts.map +1 -1
  11. package/dist/storage/client.d.ts +91 -0
  12. package/dist/storage/client.d.ts.map +1 -0
  13. package/dist/storage/db/index.d.ts +170 -0
  14. package/dist/storage/db/index.d.ts.map +1 -0
  15. package/dist/storage/domains/agents/index.d.ts +39 -0
  16. package/dist/storage/domains/agents/index.d.ts.map +1 -0
  17. package/dist/storage/domains/memory/index.d.ts +30 -11
  18. package/dist/storage/domains/memory/index.d.ts.map +1 -1
  19. package/dist/storage/domains/observability/index.d.ts +29 -36
  20. package/dist/storage/domains/observability/index.d.ts.map +1 -1
  21. package/dist/storage/domains/scores/index.d.ts +26 -29
  22. package/dist/storage/domains/scores/index.d.ts.map +1 -1
  23. package/dist/storage/domains/utils.d.ts +1 -5
  24. package/dist/storage/domains/utils.d.ts.map +1 -1
  25. package/dist/storage/domains/workflows/index.d.ts +30 -19
  26. package/dist/storage/domains/workflows/index.d.ts.map +1 -1
  27. package/dist/storage/index.d.ts +51 -195
  28. package/dist/storage/index.d.ts.map +1 -1
  29. package/dist/storage/performance-indexes/performance-test.d.ts +3 -1
  30. package/dist/storage/performance-indexes/performance-test.d.ts.map +1 -1
  31. package/dist/storage/test-utils.d.ts.map +1 -1
  32. package/dist/vector/index.d.ts +42 -6
  33. package/dist/vector/index.d.ts.map +1 -1
  34. package/dist/vector/sql-builder.d.ts +4 -0
  35. package/dist/vector/sql-builder.d.ts.map +1 -1
  36. package/dist/vector/types.d.ts +10 -0
  37. package/dist/vector/types.d.ts.map +1 -1
  38. package/package.json +6 -8
  39. package/dist/storage/domains/operations/index.d.ts +0 -119
  40. package/dist/storage/domains/operations/index.d.ts.map +0 -1
@@ -1,11 +1,17 @@
1
1
  import { MastraVector } from '@mastra/core/vector';
2
- import type { IndexStats, QueryResult, QueryVectorParams, CreateIndexParams, UpsertVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams } from '@mastra/core/vector';
2
+ import type { IndexStats, QueryResult, QueryVectorParams, CreateIndexParams, UpsertVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, DeleteVectorsParams, UpdateVectorParams } from '@mastra/core/vector';
3
3
  import * as pg from 'pg';
4
4
  import type { PgVectorConfig } from '../shared/config.js';
5
5
  import type { PGVectorFilter } from './filter.js';
6
- import type { IndexConfig, IndexType } from './types.js';
6
+ import type { IndexConfig, IndexType, VectorType } from './types.js';
7
7
  export interface PGIndexStats extends IndexStats {
8
8
  type: IndexType;
9
+ /**
10
+ * The pgvector storage type used for this index.
11
+ * - 'vector': Full precision (4 bytes per dimension)
12
+ * - 'halfvec': Half precision (2 bytes per dimension)
13
+ */
14
+ vectorType: VectorType;
9
15
  config: {
10
16
  m?: number;
11
17
  efConstruction?: number;
@@ -29,22 +35,33 @@ interface PgQueryVectorParams extends QueryVectorParams<PGVectorFilter> {
29
35
  interface PgCreateIndexParams extends CreateIndexParams {
30
36
  indexConfig?: IndexConfig;
31
37
  buildIndex?: boolean;
38
+ /**
39
+ * The pgvector storage type for embeddings.
40
+ * - 'vector': Full precision (4 bytes per dimension), max 2000 dimensions for indexes (default)
41
+ * - 'halfvec': Half precision (2 bytes per dimension), max 4000 dimensions for indexes
42
+ *
43
+ * Use 'halfvec' for large dimension models like text-embedding-3-large (3072 dimensions)
44
+ */
45
+ vectorType?: VectorType;
32
46
  }
33
47
  interface PgDefineIndexParams {
34
48
  indexName: string;
35
49
  metric: 'cosine' | 'euclidean' | 'dotproduct';
36
50
  indexConfig: IndexConfig;
51
+ vectorType?: VectorType;
37
52
  }
38
53
  export declare class PgVector extends MastraVector<PGVectorFilter> {
39
54
  pool: pg.Pool;
40
55
  private describeIndexCache;
41
56
  private createdIndexes;
57
+ private indexVectorTypes;
42
58
  private mutexesByName;
43
59
  private schema?;
44
60
  private setupSchemaPromise;
45
61
  private installVectorExtensionPromise;
46
62
  private vectorExtensionInstalled;
47
63
  private vectorExtensionSchema;
64
+ private vectorExtensionVersion;
48
65
  private schemaSetupComplete;
49
66
  private cacheWarmupPromise;
50
67
  constructor(config: PgVectorConfig & {
@@ -52,24 +69,35 @@ export declare class PgVector extends MastraVector<PGVectorFilter> {
52
69
  });
53
70
  private getMutexByName;
54
71
  /**
55
- * Detects which schema contains the vector extension
72
+ * Detects which schema contains the vector extension and its version
56
73
  */
57
74
  private detectVectorExtensionSchema;
75
+ /**
76
+ * Checks if the installed pgvector version supports halfvec type.
77
+ * halfvec was introduced in pgvector 0.7.0.
78
+ */
79
+ private supportsHalfvec;
58
80
  /**
59
81
  * Gets the properly qualified vector type name
82
+ * @param vectorType - The type of vector storage ('vector' or 'halfvec')
60
83
  */
61
84
  private getVectorTypeName;
85
+ /**
86
+ * Gets the operator class for index creation based on metric and vector type.
87
+ * pgvector uses different operator classes for vector vs halfvec types.
88
+ */
89
+ private getMetricOperatorClass;
62
90
  private getTableName;
63
91
  private getSchemaName;
64
92
  transformFilter(filter?: PGVectorFilter): PGVectorFilter;
65
93
  getIndexInfo({ indexName }: DescribeIndexParams): Promise<PGIndexStats>;
66
94
  query({ indexName, queryVector, topK, filter, includeVector, minScore, ef, probes, }: PgQueryVectorParams): Promise<QueryResult[]>;
67
- upsert({ indexName, vectors, metadata, ids }: UpsertVectorParams): Promise<string[]>;
95
+ upsert({ indexName, vectors, metadata, ids, deleteFilter, }: UpsertVectorParams<PGVectorFilter>): Promise<string[]>;
68
96
  private hasher;
69
97
  private getIndexCacheKey;
70
98
  private cachedIndexExists;
71
99
  private setupSchema;
72
- createIndex({ indexName, dimension, metric, indexConfig, buildIndex, }: PgCreateIndexParams): Promise<void>;
100
+ createIndex({ indexName, dimension, metric, indexConfig, buildIndex, vectorType, }: PgCreateIndexParams): Promise<void>;
73
101
  buildIndex({ indexName, metric, indexConfig }: PgDefineIndexParams): Promise<void>;
74
102
  private setupIndex;
75
103
  private installVectorExtension;
@@ -94,7 +122,7 @@ export declare class PgVector extends MastraVector<PGVectorFilter> {
94
122
  * @returns A promise that resolves when the update is complete.
95
123
  * @throws Will throw an error if no updates are provided or if the update operation fails.
96
124
  */
97
- updateVector({ indexName, id, update }: UpdateVectorParams): Promise<void>;
125
+ updateVector({ indexName, id, filter, update }: UpdateVectorParams<PGVectorFilter>): Promise<void>;
98
126
  /**
99
127
  * Deletes a vector by its ID.
100
128
  * @param indexName - The name of the index containing the vector.
@@ -103,6 +131,14 @@ export declare class PgVector extends MastraVector<PGVectorFilter> {
103
131
  * @throws Will throw an error if the deletion operation fails.
104
132
  */
105
133
  deleteVector({ indexName, id }: DeleteVectorParams): Promise<void>;
134
+ /**
135
+ * Delete vectors matching a metadata filter.
136
+ * @param indexName - The name of the index containing the vectors.
137
+ * @param filter - The filter to match vectors for deletion.
138
+ * @returns A promise that resolves when the deletion is complete.
139
+ * @throws Will throw an error if the deletion operation fails.
140
+ */
141
+ deleteVectors({ indexName, filter, ids }: DeleteVectorsParams<PGVectorFilter>): Promise<void>;
106
142
  }
107
143
  export {};
108
144
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vector/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EACnB,MAAM,qBAAq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EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB9D,UAAU;IAchB;;;;;;;;;OASG;IACG,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,kBAAkB,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IA0IxG;;;;;;OAMG;IACG,YAAY,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BxE;;;;;;OAMG;IACG,aAAa,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,mBAAmB,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAkHpG"}
@@ -3,6 +3,10 @@ interface FilterResult {
3
3
  sql: string;
4
4
  values: any[];
5
5
  }
6
+ /**
7
+ * Build a filter query for DELETE operations (no minScore/topK parameters)
8
+ */
9
+ export declare function buildDeleteFilterQuery(filter: PGVectorFilter): FilterResult;
6
10
  export declare function buildFilterQuery(filter: PGVectorFilter, minScore: number, topK: number): FilterResult;
7
11
  export {};
8
12
  //# sourceMappingURL=sql-builder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sql-builder.d.ts","sourceRoot":"","sources":["../../src/vector/sql-builder.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAqO/C,UAAU,YAAY;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,GAAG,EAAE,CAAC;CACf;AAWD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAwGrG"}
1
+ {"version":3,"file":"sql-builder.d.ts","sourceRoot":"","sources":["../../src/vector/sql-builder.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAmP/C,UAAU,YAAY;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,GAAG,EAAE,CAAC;CACf;AAWD;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,cAAc,GAAG,YAAY,CAwG3E;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAwGrG"}
@@ -1,4 +1,14 @@
1
1
  export type IndexType = 'ivfflat' | 'hnsw' | 'flat';
2
+ /**
3
+ * pgvector storage types for embeddings.
4
+ * - 'vector': Full precision (4 bytes per dimension), max 2000 dimensions for indexes
5
+ * - 'halfvec': Half precision (2 bytes per dimension), max 4000 dimensions for indexes
6
+ *
7
+ * Use 'halfvec' for large dimension models like text-embedding-3-large (3072 dimensions)
8
+ *
9
+ * Note: 'halfvec' requires pgvector >= 0.7.0
10
+ */
11
+ export type VectorType = 'vector' | 'halfvec';
2
12
  interface IVFConfig {
3
13
  lists?: number;
4
14
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/vector/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD,UAAU,SAAS;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,UAAU;IAClB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/vector/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAEpD;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE9C,UAAU,SAAS;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,UAAU;IAClB,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,GAAG,CAAC,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pg",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.11",
4
4
  "description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -22,23 +22,21 @@
22
22
  "dependencies": {
23
23
  "async-mutex": "^0.5.0",
24
24
  "pg": "^8.16.3",
25
- "pg-promise": "^11.15.0",
26
25
  "xxhash-wasm": "^1.1.0"
27
26
  },
28
27
  "devDependencies": {
29
- "@microsoft/api-extractor": "^7.52.8",
30
28
  "@types/node": "22.13.17",
31
29
  "@types/pg": "^8.15.6",
32
- "@vitest/coverage-v8": "4.0.8",
33
- "@vitest/ui": "4.0.8",
30
+ "@vitest/coverage-v8": "4.0.12",
31
+ "@vitest/ui": "4.0.12",
34
32
  "eslint": "^9.37.0",
35
33
  "tsup": "^8.5.0",
36
34
  "typescript": "^5.8.3",
37
- "vitest": "^4.0.8",
35
+ "vitest": "4.0.12",
36
+ "@internal/storage-test-utils": "0.0.49",
38
37
  "@internal/lint": "0.0.53",
39
- "@mastra/core": "1.0.0-beta.3",
40
38
  "@internal/types-builder": "0.0.28",
41
- "@internal/storage-test-utils": "0.0.49"
39
+ "@mastra/core": "1.0.0-beta.19"
42
40
  },
43
41
  "peerDependencies": {
44
42
  "@mastra/core": ">=1.0.0-0 <2.0.0-0"
@@ -1,119 +0,0 @@
1
- import { StoreOperations } from '@mastra/core/storage';
2
- import type { StorageColumn, TABLE_NAMES, CreateIndexOptions, IndexInfo, StorageIndexStats } from '@mastra/core/storage';
3
- import type { IDatabase } from 'pg-promise';
4
- export type { CreateIndexOptions, IndexInfo, StorageIndexStats };
5
- export declare class StoreOperationsPG extends StoreOperations {
6
- client: IDatabase<{}>;
7
- schemaName?: string;
8
- private setupSchemaPromise;
9
- private schemaSetupComplete;
10
- constructor({ client, schemaName }: {
11
- client: IDatabase<{}>;
12
- schemaName?: string;
13
- });
14
- hasColumn(table: string, column: string): Promise<boolean>;
15
- /**
16
- * Prepares values for insertion, handling JSONB columns by stringifying them
17
- */
18
- private prepareValuesForInsert;
19
- /**
20
- * Adds timestamp Z columns to a record if timestamp columns exist
21
- */
22
- private addTimestampZColumns;
23
- /**
24
- * Prepares a value for database operations, handling Date objects and JSON serialization
25
- * This is schema-aware and only stringifies objects for JSONB columns
26
- */
27
- private prepareValue;
28
- private setupSchema;
29
- insert({ tableName, record }: {
30
- tableName: TABLE_NAMES;
31
- record: Record<string, any>;
32
- }): Promise<void>;
33
- clearTable({ tableName }: {
34
- tableName: TABLE_NAMES;
35
- }): Promise<void>;
36
- protected getDefaultValue(type: StorageColumn['type']): string;
37
- createTable({ tableName, schema, }: {
38
- tableName: TABLE_NAMES;
39
- schema: Record<string, StorageColumn>;
40
- }): Promise<void>;
41
- /**
42
- * Set up timestamp triggers for a table to automatically manage createdAt/updatedAt
43
- */
44
- private setupTimestampTriggers;
45
- /**
46
- * Alters table schema to add columns if they don't exist
47
- * @param tableName Name of the table
48
- * @param schema Schema of the table
49
- * @param ifNotExists Array of column names to add if they don't exist
50
- */
51
- alterTable({ tableName, schema, ifNotExists, }: {
52
- tableName: TABLE_NAMES;
53
- schema: Record<string, StorageColumn>;
54
- ifNotExists: string[];
55
- }): Promise<void>;
56
- load<R>({ tableName, keys }: {
57
- tableName: TABLE_NAMES;
58
- keys: Record<string, string>;
59
- }): Promise<R | null>;
60
- batchInsert({ tableName, records }: {
61
- tableName: TABLE_NAMES;
62
- records: Record<string, any>[];
63
- }): Promise<void>;
64
- dropTable({ tableName }: {
65
- tableName: TABLE_NAMES;
66
- }): Promise<void>;
67
- /**
68
- * Create a new index on a table
69
- */
70
- createIndex(options: CreateIndexOptions): Promise<void>;
71
- /**
72
- * Drop an existing index
73
- */
74
- dropIndex(indexName: string): Promise<void>;
75
- /**
76
- * List indexes for a specific table or all tables
77
- */
78
- listIndexes(tableName?: string): Promise<IndexInfo[]>;
79
- /**
80
- * Returns definitions for automatic performance indexes
81
- * These composite indexes cover both filtering and sorting in single index
82
- */
83
- protected getAutomaticIndexDefinitions(): CreateIndexOptions[];
84
- /**
85
- * Creates automatic indexes for optimal query performance
86
- * Uses getAutomaticIndexDefinitions() to determine which indexes to create
87
- */
88
- createAutomaticIndexes(): Promise<void>;
89
- /**
90
- * Get detailed statistics for a specific index
91
- */
92
- describeIndex(indexName: string): Promise<StorageIndexStats>;
93
- /**
94
- * Update a single record in the database
95
- */
96
- update({ tableName, keys, data, }: {
97
- tableName: TABLE_NAMES;
98
- keys: Record<string, any>;
99
- data: Record<string, any>;
100
- }): Promise<void>;
101
- /**
102
- * Update multiple records in a single batch transaction
103
- */
104
- batchUpdate({ tableName, updates, }: {
105
- tableName: TABLE_NAMES;
106
- updates: Array<{
107
- keys: Record<string, any>;
108
- data: Record<string, any>;
109
- }>;
110
- }): Promise<void>;
111
- /**
112
- * Delete multiple records by keys
113
- */
114
- batchDelete({ tableName, keys }: {
115
- tableName: TABLE_NAMES;
116
- keys: Record<string, any>[];
117
- }): Promise<void>;
118
- }
119
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/storage/domains/operations/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,eAAe,EAQhB,MAAM,sBAAsB,CAAC;AAC9B,OAAO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