@mastra/pg 1.23.0-alpha.3 → 1.23.0-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.
@@ -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.23.0-alpha.3"
6
+ version: "1.23.0-alpha.4"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.23.0-alpha.3",
2
+ "version": "1.23.0-alpha.4",
3
3
  "package": "@mastra/pg",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -79,7 +79,7 @@ const queryTool = createVectorQueryTool({
79
79
 
80
80
  The tool returns an object with:
81
81
 
82
- **relevantContext** (`string`): Combined text from the most relevant document chunks
82
+ **relevantContext** (`any[]`): Array of metadata objects for the most relevant chunks, in rank order (one entry per result). The chunk text is available at relevantContext\[i].text when it was stored in metadata during ingestion.
83
83
 
84
84
  **sources** (`QueryResult[]`): Array of full retrieval result objects. Each object contains all information needed to reference the original document, chunk, and similarity score.
85
85
 
@@ -95,6 +95,8 @@ The tool returns an object with:
95
95
  }
96
96
  ```
97
97
 
98
+ `document` is only populated by vector stores whose `query()` returns document content, such as Chroma, Elasticsearch, LanceDB, and MongoDB. For other stores, such as PgVector, it's an empty string. Read the chunk text from `sources[i].metadata.text` (or whichever metadata key you stored it under).
99
+
98
100
  ## Default tool description
99
101
 
100
102
  The default description focuses on:
@@ -489,7 +491,7 @@ The tool is created with:
489
491
 
490
492
  - **ID**: `VectorQuery {vectorStoreName} {indexName} Tool`
491
493
  - **Input Schema**: Requires queryText and filter objects
492
- - **Output Schema**: Returns relevantContext string
494
+ - **Output Schema**: Returns `relevantContext` (array of chunk metadata) and `sources` (array of `QueryResult`)
493
495
 
494
496
  ## Related
495
497
 
package/dist/index.cjs CHANGED
@@ -21,6 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
+ let crypto$1 = require("crypto");
24
25
  let _mastra_core_error = require("@mastra/core/error");
25
26
  let _mastra_core_storage = require("@mastra/core/storage");
26
27
  _mastra_core_storage = __toESM(_mastra_core_storage, 1);
@@ -34,7 +35,6 @@ xxhash_wasm = __toESM(xxhash_wasm, 1);
34
35
  let pg_connection_string = require("pg-connection-string");
35
36
  let _mastra_core_vector_filter = require("@mastra/core/vector/filter");
36
37
  let _mastra_core_base = require("@mastra/core/base");
37
- let crypto$1 = require("crypto");
38
38
  let _mastra_core_agent = require("@mastra/core/agent");
39
39
  let _mastra_core_features = require("@mastra/core/features");
40
40
  let _mastra_core_evals = require("@mastra/core/evals");
@@ -828,6 +828,8 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
828
828
  AND attnum > 0
829
829
  AND NOT attisdropped`, [tableName])).rowCount === 0) return;
830
830
  await client.query(`ALTER TABLE ${tableName} ADD COLUMN IF NOT EXISTS namespace VARCHAR(255) NOT NULL DEFAULT '${DEFAULT_NAMESPACE}'`);
831
+ const namespaceIndexName = this.getNamespaceIndexName(parsedIndexName);
832
+ await client.query(`CREATE UNIQUE INDEX IF NOT EXISTS "${namespaceIndexName}" ON ${tableName} (namespace, vector_id)`);
831
833
  const legacyConstraints = await client.query(`SELECT c.conname
832
834
  FROM pg_constraint c
833
835
  WHERE c.conrelid = to_regclass($1)
@@ -837,8 +839,21 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
837
839
  const parsedConstraintName = (0, _mastra_core_utils.parseSqlIdentifier)(conname, "constraint name");
838
840
  await client.query(`ALTER TABLE ${tableName} DROP CONSTRAINT "${parsedConstraintName}"`);
839
841
  }
840
- const namespaceIndexName = (0, _mastra_core_utils.parseSqlIdentifier)(`${parsedIndexName}_namespace_vector_id_idx`, "index name");
841
- await client.query(`CREATE UNIQUE INDEX IF NOT EXISTS "${namespaceIndexName}" ON ${tableName} (namespace, vector_id)`);
842
+ }
843
+ /**
844
+ * Name of the unique (namespace, vector_id) index for a table.
845
+ *
846
+ * The full `<index>_namespace_vector_id_idx` name is kept whenever it fits so tables that
847
+ * were already migrated keep matching `IF NOT EXISTS`. Longer index names would exceed
848
+ * Postgres' 63-char identifier limit, so those fall back to a truncated prefix plus a hash
849
+ * of the index name to distinguish tables that
850
+ * share a long prefix.
851
+ */
852
+ getNamespaceIndexName(parsedIndexName) {
853
+ const fullName = `${parsedIndexName}_namespace_vector_id_idx`;
854
+ if (fullName.length <= 63) return fullName;
855
+ const suffix = `_ns_${(0, crypto$1.createHash)("sha256").update(parsedIndexName).digest("hex").slice(0, 32)}_idx`;
856
+ return `${parsedIndexName.slice(0, 63 - suffix.length)}${suffix}`;
842
857
  }
843
858
  transformFilter(filter) {
844
859
  return new PGFilterTranslator().translate(filter);