@mastra/pg 0.1.5 → 0.1.6-alpha.1

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.
@@ -1,18 +1,18 @@
1
1
 
2
- > @mastra/pg@0.1.5-alpha.2 build /home/runner/work/mastra/mastra/stores/pg
2
+ > @mastra/pg@0.1.6-alpha.1 build /home/runner/work/mastra/mastra/stores/pg
3
3
  > tsup src/index.ts --format esm --experimental-dts --clean --treeshake
4
4
 
5
5
  CLI Building entry: src/index.ts
6
6
  CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v8.3.6
8
8
  TSC Build start
9
- TSC ⚡️ Build success in 9453ms
9
+ TSC ⚡️ Build success in 10385ms
10
10
  DTS Build start
11
11
  CLI Target: es2022
12
12
  Analysis will use the bundled TypeScript version 5.7.3
13
13
  Writing package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts
14
- DTS ⚡️ Build success in 7106ms
14
+ DTS ⚡️ Build success in 5525ms
15
15
  CLI Cleaning output folder
16
16
  ESM Build start
17
- ESM dist/index.js 32.67 KB
18
- ESM ⚡️ Build success in 640ms
17
+ ESM dist/index.js 32.82 KB
18
+ ESM ⚡️ Build success in 642ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @mastra/pg
2
2
 
3
+ ## 0.1.6-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - 0d185b1: Ensure proper message sort order for tool calls and results when using Memory semanticRecall feature
8
+ - f6a1de3: Renamed defineIndex to buildIndex
9
+ - Updated dependencies [0d185b1]
10
+ - Updated dependencies [ed55f1d]
11
+ - Updated dependencies [8d13b14]
12
+ - Updated dependencies [3ee4831]
13
+ - Updated dependencies [108793c]
14
+ - Updated dependencies [5f28f44]
15
+ - @mastra/core@0.4.3-alpha.1
16
+
17
+ ## 0.1.6-alpha.0
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [06aa827]
22
+ - @mastra/core@0.4.3-alpha.0
23
+
3
24
  ## 0.1.5
4
25
 
5
26
  ### Patch Changes
@@ -1,23 +1,23 @@
1
- import { ArrayOperator } from '@mastra/core/filter';
1
+ import type { ArrayOperator } from '@mastra/core/filter';
2
2
  import { BaseFilterTranslator } from '@mastra/core/filter';
3
- import { BasicOperator } from '@mastra/core/filter';
4
- import { ElementOperator } from '@mastra/core/filter';
5
- import { EvalRow } from '@mastra/core/storage';
6
- import { Filter } from '@mastra/core/filter';
7
- import { IndexStats } from '@mastra/core/vector';
8
- import { LogicalOperator } from '@mastra/core/filter';
3
+ import type { BasicOperator } from '@mastra/core/filter';
4
+ import type { ElementOperator } from '@mastra/core/filter';
5
+ import type { EvalRow } from '@mastra/core/storage';
6
+ import type { Filter } from '@mastra/core/filter';
7
+ import type { IndexStats } from '@mastra/core/vector';
8
+ import type { LogicalOperator } from '@mastra/core/filter';
9
9
  import { MastraStorage } from '@mastra/core/storage';
10
10
  import { MastraVector } from '@mastra/core/vector';
11
- import { MessageType } from '@mastra/core/memory';
12
- import { NumericOperator } from '@mastra/core/filter';
13
- import { OperatorSupport } from '@mastra/core/filter';
14
- import { QueryResult } from '@mastra/core/vector';
15
- import { RegexOperator } from '@mastra/core/filter';
16
- import { StorageColumn } from '@mastra/core/storage';
17
- import { StorageGetMessagesArg } from '@mastra/core/storage';
18
- import { StorageThreadType } from '@mastra/core/memory';
19
- import { TABLE_NAMES } from '@mastra/core/storage';
20
- import { WorkflowRunState } from '@mastra/core/workflows';
11
+ import type { MessageType } from '@mastra/core/memory';
12
+ import type { NumericOperator } from '@mastra/core/filter';
13
+ import type { OperatorSupport } from '@mastra/core/filter';
14
+ import type { QueryResult } from '@mastra/core/vector';
15
+ import type { RegexOperator } from '@mastra/core/filter';
16
+ import type { StorageColumn } from '@mastra/core/storage';
17
+ import type { StorageGetMessagesArg } from '@mastra/core/storage';
18
+ import type { StorageThreadType } from '@mastra/core/memory';
19
+ import type { TABLE_NAMES } from '@mastra/core/storage';
20
+ import type { WorkflowRunState } from '@mastra/core/workflows';
21
21
 
22
22
  export declare const baseTestConfigs: {
23
23
  smokeTests: {
@@ -173,7 +173,11 @@ declare class PgVector extends MastraVector {
173
173
  }): Promise<QueryResult[]>;
174
174
  upsert(indexName: string, vectors: number[][], metadata?: Record<string, any>[], ids?: string[]): Promise<string[]>;
175
175
  createIndex(indexName: string, dimension: number, metric?: 'cosine' | 'euclidean' | 'dotproduct', indexConfig?: IndexConfig, defineIndex?: boolean): Promise<void>;
176
+ /**
177
+ * @deprecated This function is deprecated. Use buildIndex instead
178
+ */
176
179
  defineIndex(indexName: string, metric: "cosine" | "euclidean" | "dotproduct" | undefined, indexConfig: IndexConfig): Promise<void>;
180
+ buildIndex(indexName: string, metric: "cosine" | "euclidean" | "dotproduct" | undefined, indexConfig: IndexConfig): Promise<void>;
177
181
  listIndexes(): Promise<string[]>;
178
182
  describeIndex(indexName: string): Promise<PGIndexStats>;
179
183
  deleteIndex(indexName: string): Promise<void>;
@@ -199,7 +203,7 @@ declare class PostgresStore extends MastraStorage {
199
203
  private db;
200
204
  private pgp;
201
205
  constructor(config: PostgresConfig);
202
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]>;
206
+ getEvalsByAgentName(_agentName: string, _type?: 'test' | 'live'): Promise<EvalRow[]>;
203
207
  batchInsert({ tableName, records }: {
204
208
  tableName: TABLE_NAMES;
205
209
  records: Record<string, any>[];
package/dist/index.js CHANGED
@@ -1,9 +1,7 @@
1
1
  import { MastraVector } from '@mastra/core/vector';
2
2
  import pg from 'pg';
3
3
  import { BaseFilterTranslator } from '@mastra/core/filter';
4
- import '@mastra/core/memory';
5
4
  import { MastraStorage } from '@mastra/core/storage';
6
- import '@mastra/core/workflows';
7
5
  import pgPromise from 'pg-promise';
8
6
 
9
7
  // src/vector/index.ts
@@ -73,6 +71,8 @@ var PGFilterTranslator = class extends BaseFilterTranslator {
73
71
  return { $regex: flags ? `(?${flags})${pattern}` : pattern };
74
72
  }
75
73
  };
74
+
75
+ // src/vector/sql-builder.ts
76
76
  var createBasicOperator = (symbol) => {
77
77
  return (key, paramIndex) => ({
78
78
  sql: `CASE
@@ -420,7 +420,13 @@ var PgVector = class extends MastraVector {
420
420
  client.release();
421
421
  }
422
422
  }
423
+ /**
424
+ * @deprecated This function is deprecated. Use buildIndex instead
425
+ */
423
426
  async defineIndex(indexName, metric = "cosine", indexConfig) {
427
+ return this.buildIndex(indexName, metric, indexConfig);
428
+ }
429
+ async buildIndex(indexName, metric = "cosine", indexConfig) {
424
430
  const client = await this.pool.connect();
425
431
  try {
426
432
  await client.query(`DROP INDEX IF EXISTS ${indexName}_vector_idx`);
@@ -576,7 +582,7 @@ var PostgresStore = class extends MastraStorage {
576
582
  }
577
583
  );
578
584
  }
579
- getEvalsByAgentName(agentName, type) {
585
+ getEvalsByAgentName(_agentName, _type) {
580
586
  throw new Error("Method not implemented.");
581
587
  }
582
588
  async batchInsert({ tableName, records }) {
@@ -874,11 +880,11 @@ var PostgresStore = class extends MastraStorage {
874
880
  WITH ordered_messages AS (
875
881
  SELECT
876
882
  *,
877
- ROW_NUMBER() OVER (ORDER BY "createdAt") as row_num
883
+ ROW_NUMBER() OVER (ORDER BY "createdAt" DESC) as row_num
878
884
  FROM "${MastraStorage.TABLE_MESSAGES}"
879
885
  WHERE thread_id = $1
880
886
  )
881
- SELECT DISTINCT ON (m.id)
887
+ SELECT
882
888
  m.id,
883
889
  m.content,
884
890
  m.role,
@@ -898,7 +904,7 @@ var PostgresStore = class extends MastraStorage {
898
904
  (m.row_num <= target.row_num + $4 AND m.row_num > target.row_num)
899
905
  )
900
906
  )
901
- ORDER BY m.id, m."createdAt"
907
+ ORDER BY m."createdAt" DESC
902
908
  `,
903
909
  [
904
910
  threadId,
@@ -932,7 +938,7 @@ var PostgresStore = class extends MastraStorage {
932
938
  if (typeof message.content === "string") {
933
939
  try {
934
940
  message.content = JSON.parse(message.content);
935
- } catch (e) {
941
+ } catch {
936
942
  }
937
943
  }
938
944
  });
@@ -0,0 +1,6 @@
1
+ import { createConfig } from '@internal/lint/eslint';
2
+
3
+ const config = await createConfig();
4
+
5
+ /** @type {import("eslint").Linter.Config[]} */
6
+ export default [...config.map(conf => ({ ...conf, ignores: [...(conf.ignores || []), '**/vitest.perf.config.ts'] }))];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/pg",
3
- "version": "0.1.5",
3
+ "version": "0.1.6-alpha.1",
4
4
  "description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -17,7 +17,7 @@
17
17
  "dependencies": {
18
18
  "pg": "^8.13.1",
19
19
  "pg-promise": "^11.5.4",
20
- "@mastra/core": "^0.4.2"
20
+ "@mastra/core": "^0.4.3-alpha.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@microsoft/api-extractor": "^7.49.2",
@@ -25,7 +25,9 @@
25
25
  "@types/pg": "^8.11.10",
26
26
  "tsup": "^8.0.1",
27
27
  "typescript": "^5.7.3",
28
- "vitest": "^3.0.4"
28
+ "vitest": "^3.0.4",
29
+ "eslint": "^9.20.1",
30
+ "@internal/lint": "0.0.0"
29
31
  },
30
32
  "scripts": {
31
33
  "build": "tsup src/index.ts --format esm --experimental-dts --clean --treeshake",
@@ -38,6 +40,7 @@
38
40
  "posttest:perf": "docker compose -f docker-compose.perf.yaml down -v",
39
41
  "pretest:watch": "docker compose up -d",
40
42
  "test:watch": "vitest watch",
41
- "posttest:watch": "docker compose down -v"
43
+ "posttest:watch": "docker compose down -v",
44
+ "lint": "eslint ."
42
45
  }
43
46
  }
@@ -1,8 +1,9 @@
1
- import { WorkflowRunState } from '@mastra/core/workflows';
2
1
  import { randomUUID } from 'crypto';
2
+ import type { WorkflowRunState } from '@mastra/core/workflows';
3
3
  import { describe, it, expect, beforeAll, beforeEach, afterAll } from 'vitest';
4
4
 
5
- import { PostgresStore, type PostgresConfig } from '.';
5
+ import { PostgresStore } from '.';
6
+ import type { PostgresConfig } from '.';
6
7
 
7
8
  const TEST_CONFIG: PostgresConfig = {
8
9
  host: process.env.POSTGRES_HOST || 'localhost',
@@ -1,22 +1,9 @@
1
- import { type MessageType, type StorageThreadType } from '@mastra/core/memory';
2
- import {
3
- MastraStorage,
4
- type EvalRow,
5
- type StorageColumn,
6
- type StorageGetMessagesArg,
7
- type TABLE_NAMES,
8
- } from '@mastra/core/storage';
9
- import { type WorkflowRunState } from '@mastra/core/workflows';
1
+ import type { MessageType, StorageThreadType } from '@mastra/core/memory';
2
+ import { MastraStorage } from '@mastra/core/storage';
3
+ import type { EvalRow, StorageColumn, StorageGetMessagesArg, TABLE_NAMES } from '@mastra/core/storage';
4
+ import type { WorkflowRunState } from '@mastra/core/workflows';
10
5
  import pgPromise from 'pg-promise';
11
6
 
12
- function safelyParseJSON(json: string): any {
13
- try {
14
- return JSON.parse(json);
15
- } catch (e) {
16
- return {};
17
- }
18
- }
19
-
20
7
  export type PostgresConfig =
21
8
  | {
22
9
  host: string;
@@ -49,7 +36,7 @@ export class PostgresStore extends MastraStorage {
49
36
  );
50
37
  }
51
38
 
52
- getEvalsByAgentName(agentName: string, type?: 'test' | 'live'): Promise<EvalRow[]> {
39
+ getEvalsByAgentName(_agentName: string, _type?: 'test' | 'live'): Promise<EvalRow[]> {
53
40
  throw new Error('Method not implemented.');
54
41
  }
55
42
 
@@ -424,11 +411,11 @@ export class PostgresStore extends MastraStorage {
424
411
  WITH ordered_messages AS (
425
412
  SELECT
426
413
  *,
427
- ROW_NUMBER() OVER (ORDER BY "createdAt") as row_num
414
+ ROW_NUMBER() OVER (ORDER BY "createdAt" DESC) as row_num
428
415
  FROM "${MastraStorage.TABLE_MESSAGES}"
429
416
  WHERE thread_id = $1
430
417
  )
431
- SELECT DISTINCT ON (m.id)
418
+ SELECT
432
419
  m.id,
433
420
  m.content,
434
421
  m.role,
@@ -448,7 +435,7 @@ export class PostgresStore extends MastraStorage {
448
435
  (m.row_num <= target.row_num + $4 AND m.row_num > target.row_num)
449
436
  )
450
437
  )
451
- ORDER BY m.id, m."createdAt"
438
+ ORDER BY m."createdAt" DESC
452
439
  `,
453
440
  [
454
441
  threadId,
@@ -490,7 +477,7 @@ export class PostgresStore extends MastraStorage {
490
477
  if (typeof message.content === 'string') {
491
478
  try {
492
479
  message.content = JSON.parse(message.content);
493
- } catch (e) {
480
+ } catch {
494
481
  // If parsing fails, leave as string
495
482
  }
496
483
  }
@@ -1,4 +1,5 @@
1
- import { BaseFilterTranslator, type FieldCondition, type Filter, type OperatorSupport } from '@mastra/core/filter';
1
+ import { BaseFilterTranslator } from '@mastra/core/filter';
2
+ import type { FieldCondition, Filter, OperatorSupport } from '@mastra/core/filter';
2
3
 
3
4
  /**
4
5
  * Translates MongoDB-style filters to PG compatible filters.
@@ -187,7 +187,7 @@ describe('PgVector', () => {
187
187
  beforeAll(async () => {
188
188
  try {
189
189
  await vectorDB.deleteIndex(indexName);
190
- } catch (e) {
190
+ } catch {
191
191
  // Ignore if doesn't exist
192
192
  }
193
193
  await vectorDB.createIndex(indexName, 3);
@@ -248,7 +248,7 @@ describe('PgVector', () => {
248
248
  beforeAll(async () => {
249
249
  try {
250
250
  await vectorDB.deleteIndex(indexName);
251
- } catch (e) {
251
+ } catch {
252
252
  // Ignore if doesn't exist
253
253
  }
254
254
  await vectorDB.createIndex(indexName, 3);
@@ -1,10 +1,11 @@
1
1
  import type { Filter } from '@mastra/core/filter';
2
- import { type IndexStats, type QueryResult, MastraVector } from '@mastra/core/vector';
2
+ import { MastraVector } from '@mastra/core/vector';
3
+ import type { IndexStats, QueryResult } from '@mastra/core/vector';
3
4
  import pg from 'pg';
4
5
 
5
6
  import { PGFilterTranslator } from './filter';
6
7
  import { buildFilterQuery } from './sql-builder';
7
- import { type IndexConfig, type IndexType } from './types';
8
+ import type { IndexConfig, IndexType } from './types';
8
9
 
9
10
  export interface PGIndexStats extends IndexStats {
10
11
  type: IndexType;
@@ -203,10 +204,21 @@ export class PgVector extends MastraVector {
203
204
  }
204
205
  }
205
206
 
207
+ /**
208
+ * @deprecated This function is deprecated. Use buildIndex instead
209
+ */
206
210
  async defineIndex(
207
211
  indexName: string,
208
212
  metric: 'cosine' | 'euclidean' | 'dotproduct' = 'cosine',
209
213
  indexConfig: IndexConfig,
214
+ ): Promise<void> {
215
+ return this.buildIndex(indexName, metric, indexConfig);
216
+ }
217
+
218
+ async buildIndex(
219
+ indexName: string,
220
+ metric: 'cosine' | 'euclidean' | 'dotproduct' = 'cosine',
221
+ indexConfig: IndexConfig,
210
222
  ): Promise<void> {
211
223
  const client = await this.pool.connect();
212
224
  try {
@@ -1,6 +1,6 @@
1
- import { type IndexConfig, type IndexType } from './types';
1
+ import type { IndexConfig, IndexType } from './types';
2
2
 
3
- import { PgVector } from '.';
3
+ import type { PgVector } from '.';
4
4
 
5
5
  export interface TestResult {
6
6
  distribution: string;
@@ -1,11 +1,11 @@
1
- import {
2
- type BasicOperator,
3
- type NumericOperator,
4
- type ArrayOperator,
5
- type ElementOperator,
6
- type LogicalOperator,
7
- type RegexOperator,
8
- type Filter,
1
+ import type {
2
+ BasicOperator,
3
+ NumericOperator,
4
+ ArrayOperator,
5
+ ElementOperator,
6
+ LogicalOperator,
7
+ RegexOperator,
8
+ Filter,
9
9
  } from '@mastra/core/filter';
10
10
 
11
11
  export type OperatorType =
@@ -1,10 +1,9 @@
1
1
  import pg from 'pg';
2
2
  import { describe, it, beforeAll, afterAll, beforeEach, afterEach } from 'vitest';
3
3
 
4
+ import type { TestConfig, TestResult } from './performance.helpers';
4
5
  import {
5
6
  baseTestConfigs,
6
- TestConfig,
7
- TestResult,
8
7
  calculateTimeout,
9
8
  generateRandomVectors,
10
9
  findNearestBruteForce,
@@ -19,7 +18,7 @@ import {
19
18
  getHNSWConfig,
20
19
  getIndexDescription,
21
20
  } from './performance.helpers';
22
- import { IndexConfig, IndexType } from './types';
21
+ import type { IndexConfig, IndexType } from './types';
23
22
 
24
23
  import { PgVector } from '.';
25
24
 
@@ -178,7 +177,7 @@ describe('PostgreSQL Index Performance', () => {
178
177
  await batchedBulkUpsert(vectorDB, testIndexName, testVectors, batchSizes);
179
178
  if (indexType === 'hnsw' || rebuild) {
180
179
  console.log('rebuilding index');
181
- await vectorDB.defineIndex(testIndexName, 'cosine', indexConfig);
180
+ await vectorDB.buildIndex(testIndexName, 'cosine', indexConfig);
182
181
  console.log('index rebuilt');
183
182
  }
184
183
  await smartWarmup(vectorDB, testIndexName, indexType, testConfig.dimension, testConfig.k);