@mastra/pg 1.31.0-alpha.1 → 1.31.0-alpha.2

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.
@@ -3,7 +3,7 @@ name: mastra-pg
3
3
  description: Documentation for @mastra/pg. Use when working with @mastra/pg APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "@mastra/pg"
6
- version: "1.31.0-alpha.1"
6
+ version: "1.31.0-alpha.2"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.31.0-alpha.1",
2
+ "version": "1.31.0-alpha.2",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -40,7 +40,7 @@ const chunks = await doc.chunk({
40
40
  overlap: 50,
41
41
  separators: ['\n'],
42
42
  extract: {
43
- metadata: true, // Optionally extract metadata
43
+ title: true, // Optionally extract a title for each chunk
44
44
  },
45
45
  })
46
46
  ```
@@ -50,23 +50,25 @@ console.log(results)
50
50
 
51
51
  The `topK` parameter specifies the maximum number of most similar results to return from the vector search.
52
52
 
53
- Results include both the text content and a similarity score:
53
+ Each result includes an `id`, a similarity `score`, and the stored `metadata`. When you store chunk text in metadata, it's available as `metadata.text`:
54
54
 
55
55
  ```ts
56
56
  [
57
57
  {
58
- text: 'Climate change poses significant challenges...',
58
+ id: 'chunk-1',
59
59
  score: 0.89,
60
- metadata: { source: 'article1.txt' },
60
+ metadata: { text: 'Climate change poses significant challenges...', source: 'article1.txt' },
61
61
  },
62
62
  {
63
- text: 'Rising temperatures affect crop yields...',
63
+ id: 'chunk-2',
64
64
  score: 0.82,
65
- metadata: { source: 'article1.txt' },
65
+ metadata: { text: 'Rising temperatures affect crop yields...', source: 'article1.txt' },
66
66
  },
67
67
  ]
68
68
  ```
69
69
 
70
+ Results can also include `vector` when you set `includeVector: true`, and `document` when the store returns the original document (Chroma only).
71
+
70
72
  ## Advanced retrieval options
71
73
 
72
74
  ### Metadata Filtering
package/dist/index.cjs CHANGED
@@ -2499,7 +2499,8 @@ async function loadSchemaSnapshot(client, schemaName) {
2499
2499
  const schema = schemaName || "public";
2500
2500
  const [tableRows, columnRows, indexRows] = await Promise.all([
2501
2501
  client.manyOrNone(`SELECT tablename FROM pg_catalog.pg_tables WHERE schemaname = $1`, [schema]),
2502
- client.manyOrNone(`SELECT c.relname AS table_name, a.attname AS column_name, format_type(a.atttypid, a.atttypmod) AS data_type
2502
+ client.manyOrNone(`SELECT c.relname AS table_name, a.attname AS column_name, format_type(a.atttypid, a.atttypmod) AS data_type,
2503
+ a.attnotnull AS not_null
2503
2504
  FROM pg_catalog.pg_class c
2504
2505
  JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
2505
2506
  JOIN pg_catalog.pg_attribute a ON a.attrelid = c.oid
@@ -2515,6 +2516,7 @@ async function loadSchemaSnapshot(client, schemaName) {
2515
2516
  ]);
2516
2517
  const columns = /* @__PURE__ */ new Map();
2517
2518
  const columnTypes = /* @__PURE__ */ new Map();
2519
+ const notNullColumns = /* @__PURE__ */ new Map();
2518
2520
  for (const row of columnRows) {
2519
2521
  let set = columns.get(row.table_name);
2520
2522
  if (!set) {
@@ -2528,6 +2530,14 @@ async function loadSchemaSnapshot(client, schemaName) {
2528
2530
  columnTypes.set(row.table_name, types);
2529
2531
  }
2530
2532
  types.set(row.column_name, row.data_type);
2533
+ if (row.not_null) {
2534
+ let notNull = notNullColumns.get(row.table_name);
2535
+ if (!notNull) {
2536
+ notNull = /* @__PURE__ */ new Set();
2537
+ notNullColumns.set(row.table_name, notNull);
2538
+ }
2539
+ notNull.add(row.column_name);
2540
+ }
2531
2541
  }
2532
2542
  const indexes = /* @__PURE__ */ new Set();
2533
2543
  const replicaIdentityIndexes = /* @__PURE__ */ new Set();
@@ -2544,6 +2554,7 @@ async function loadSchemaSnapshot(client, schemaName) {
2544
2554
  tables: new Set(tableRows.map((r) => r.tablename)),
2545
2555
  columns,
2546
2556
  columnTypes,
2557
+ notNullColumns,
2547
2558
  indexes,
2548
2559
  replicaIdentityIndexes,
2549
2560
  primaryKeyIndexes,
@@ -3622,6 +3633,33 @@ MIGRATION REQUIRED: Duplicate spans detected in ${duplicateInfo.tableName}\n====
3622
3633
  this.columnTypeCache.delete(tableName);
3623
3634
  }
3624
3635
  }
3636
+ /**
3637
+ * Drops NOT NULL from `columns` on `tableName` where it is still set. Answered
3638
+ * from the init snapshot when one is installed, so a converged schema issues
3639
+ * no query and never takes the ACCESS EXCLUSIVE lock.
3640
+ */
3641
+ async dropNotNull({ tableName, columns }) {
3642
+ const parsedColumns = columns.map((c) => (0, _mastra_core_utils.parseSqlIdentifier)(c, "column name"));
3643
+ const snapshot = this.schemaSnapshot;
3644
+ let toAlter;
3645
+ if (snapshot) {
3646
+ const notNull = snapshot.notNullColumns.get(tableName);
3647
+ toAlter = parsedColumns.filter((c) => notNull?.has(c));
3648
+ } else toAlter = (await this.client.any(`SELECT column_name FROM information_schema.columns
3649
+ WHERE table_schema = $1 AND table_name = $2 AND column_name = ANY($3) AND is_nullable = 'NO'`, [
3650
+ this.schemaName || "public",
3651
+ tableName,
3652
+ parsedColumns
3653
+ ])).map((r) => r.column_name);
3654
+ if (toAlter.length === 0) return;
3655
+ const fullTableName = getTableName$6({
3656
+ indexName: tableName,
3657
+ schemaName: getSchemaName$6(this.schemaName)
3658
+ });
3659
+ await this.client.none(`ALTER TABLE ${fullTableName} ${toAlter.map((c) => `ALTER COLUMN "${c}" DROP NOT NULL`).join(", ")}`);
3660
+ const notNull = snapshot?.notNullColumns.get(tableName);
3661
+ for (const c of toAlter) notNull?.delete(c);
3662
+ }
3625
3663
  async load({ tableName, keys }) {
3626
3664
  try {
3627
3665
  const keyEntries = Object.entries(keys).map(([key, value]) => [(0, _mastra_core_utils.parseSqlIdentifier)(key, "column name"), value]);
@@ -7112,6 +7150,10 @@ var ExperimentsPG = class ExperimentsPG extends _mastra_core_storage.Experiments
7112
7150
  "scorerIds"
7113
7151
  ]
7114
7152
  });
7153
+ await this.#db.dropNotNull({
7154
+ tableName: _mastra_core_storage.TABLE_EXPERIMENTS,
7155
+ columns: ["targetType", "targetId"]
7156
+ });
7115
7157
  await this.#db.alterTable({
7116
7158
  tableName: _mastra_core_storage.TABLE_EXPERIMENT_RESULTS,
7117
7159
  schema: _mastra_core_storage.EXPERIMENT_RESULTS_SCHEMA,
@@ -23515,7 +23557,7 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
23515
23557
  async dangerouslyClearAll() {
23516
23558
  await this.#db.clearTable({ tableName: _mastra_core_storage.TABLE_WORKFLOW_SNAPSHOT });
23517
23559
  }
23518
- async updateWorkflowResults({ workflowName, runId, stepId, result, requestContext }) {
23560
+ async updateWorkflowResults({ workflowName, runId, stepId, result, requestContext, state }) {
23519
23561
  try {
23520
23562
  return await this.#db.client.tx(async (t) => {
23521
23563
  const tableName = getTableName({
@@ -23546,7 +23588,8 @@ var WorkflowsPG = class WorkflowsPG extends _mastra_core_storage.WorkflowsStorag
23546
23588
  snapshot,
23547
23589
  stepId,
23548
23590
  result,
23549
- requestContext
23591
+ requestContext,
23592
+ state
23550
23593
  });
23551
23594
  const now = /* @__PURE__ */ new Date();
23552
23595
  const sanitizedSnapshot = toPgJson(snapshot);