@mastra/pg 1.23.0-alpha.3 → 1.23.0-alpha.5
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/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/reference-tools-vector-query-tool.md +4 -2
- package/dist/index.cjs +23 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +23 -3
- package/dist/index.js.map +1 -1
- package/dist/storage/factory-storage.d.ts.map +1 -1
- package/dist/vector/index.d.ts +10 -0
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +4 -4
package/dist/docs/SKILL.md
CHANGED
|
@@ -79,7 +79,7 @@ const queryTool = createVectorQueryTool({
|
|
|
79
79
|
|
|
80
80
|
The tool returns an object with:
|
|
81
81
|
|
|
82
|
-
**relevantContext** (`
|
|
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
|
|
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
|
-
|
|
841
|
-
|
|
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);
|
|
@@ -23042,6 +23057,11 @@ var PgFactoryStorage = class extends _mastra_core_storage.FactoryStorage {
|
|
|
23042
23057
|
if (!spec.nullable || spec.type === "uuid-pk" || spec.primaryKey) continue;
|
|
23043
23058
|
await this.#pool.query(`ALTER TABLE "${schema.name}" ALTER COLUMN "${name}" DROP NOT NULL`);
|
|
23044
23059
|
}
|
|
23060
|
+
for (const [name, spec] of Object.entries(schema.columns)) {
|
|
23061
|
+
if (spec.type !== "bigint") continue;
|
|
23062
|
+
const { rows } = await this.#pool.query(`SELECT data_type FROM information_schema.columns WHERE table_schema = current_schema() AND table_name = $1 AND column_name = $2`, [schema.name, name]);
|
|
23063
|
+
if (rows[0]?.data_type === "integer") await this.#pool.query(`ALTER TABLE "${schema.name}" ALTER COLUMN "${name}" TYPE BIGINT`);
|
|
23064
|
+
}
|
|
23045
23065
|
for (const index of schema.uniqueIndexes ?? []) {
|
|
23046
23066
|
assertIdentifier("index", index.name);
|
|
23047
23067
|
index.columns.forEach((column) => assertIdentifier("column", column));
|