@mastra/pg 1.23.0-alpha.2 → 1.23.0-alpha.3
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/index.cjs +7 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/vector/index.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/docs/SKILL.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -936,12 +936,12 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
936
936
|
client.release();
|
|
937
937
|
}
|
|
938
938
|
}
|
|
939
|
+
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
939
940
|
const client = await this.pool.connect();
|
|
940
941
|
try {
|
|
941
942
|
await this.ensureSearchPath(client);
|
|
942
943
|
await client.query("BEGIN");
|
|
943
944
|
const { sql: filterQuery, values: filterValues } = buildFilterQuery(this.transformFilter(filter), minScore, topK);
|
|
944
|
-
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
945
945
|
const metric = indexInfo.metric ?? "cosine";
|
|
946
946
|
const ops = this.getVectorOps(indexInfo.vectorType, metric);
|
|
947
947
|
const vectorStr = ops.formatVector(queryVector, indexInfo.dimension);
|
|
@@ -1016,6 +1016,7 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1016
1016
|
async upsert({ indexName, vectors, metadata, ids, deleteFilter, namespace = DEFAULT_NAMESPACE }) {
|
|
1017
1017
|
(0, _mastra_core_vector.validateUpsertInput)("PG", vectors, metadata, ids);
|
|
1018
1018
|
const { tableName } = this.getTableName(indexName);
|
|
1019
|
+
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
1019
1020
|
const client = await this.pool.connect();
|
|
1020
1021
|
try {
|
|
1021
1022
|
await this.ensureSearchPath(client);
|
|
@@ -1037,7 +1038,6 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1037
1038
|
}
|
|
1038
1039
|
}
|
|
1039
1040
|
const vectorIds = ids || vectors.map(() => crypto.randomUUID());
|
|
1040
|
-
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
1041
1041
|
const qualifiedVectorType = this.getVectorTypeName(indexInfo.vectorType, indexInfo.dimension);
|
|
1042
1042
|
const ops = this.getVectorOps(indexInfo.vectorType, indexInfo.metric ?? "cosine");
|
|
1043
1043
|
if (new Set(vectorIds).size !== vectorIds.length) for (let i = 0; i < vectors.length; i++) {
|
|
@@ -1325,7 +1325,7 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1325
1325
|
let existingIndexInfo = null;
|
|
1326
1326
|
let dimension = 0;
|
|
1327
1327
|
try {
|
|
1328
|
-
existingIndexInfo = await this.
|
|
1328
|
+
existingIndexInfo = await this.describeIndexMetadata({ indexName }, client);
|
|
1329
1329
|
dimension = existingIndexInfo.dimension;
|
|
1330
1330
|
if (isConfigEmpty && existingIndexInfo.metric === metric) if (existingIndexInfo.type === "flat") this.logger?.debug(`No index exists for ${vectorIndexName}, will create default ivfflat index`);
|
|
1331
1331
|
else {
|
|
@@ -1529,8 +1529,8 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1529
1529
|
* {@link describeIndex} it issues no `COUNT(*)`, so its cost does not grow with the
|
|
1530
1530
|
* number of rows in the table.
|
|
1531
1531
|
*/
|
|
1532
|
-
async describeIndexMetadata({ indexName }) {
|
|
1533
|
-
const client = await this.pool.connect();
|
|
1532
|
+
async describeIndexMetadata({ indexName }, existingClient) {
|
|
1533
|
+
const client = existingClient ?? await this.pool.connect();
|
|
1534
1534
|
try {
|
|
1535
1535
|
const { tableName, parsedIndexName } = this.getTableName(indexName);
|
|
1536
1536
|
const tableExists = await client.query(`
|
|
@@ -1590,7 +1590,6 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1590
1590
|
config
|
|
1591
1591
|
};
|
|
1592
1592
|
} catch (e) {
|
|
1593
|
-
await client.query("ROLLBACK");
|
|
1594
1593
|
const mastraError = new _mastra_core_error.MastraError({
|
|
1595
1594
|
id: (0, _mastra_core_storage.createVectorErrorId)("PG", "DESCRIBE_INDEX", "FAILED"),
|
|
1596
1595
|
domain: _mastra_core_error.ErrorDomain.MASTRA_VECTOR,
|
|
@@ -1600,7 +1599,7 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1600
1599
|
this.logger?.trackException(mastraError);
|
|
1601
1600
|
throw mastraError;
|
|
1602
1601
|
} finally {
|
|
1603
|
-
client.release();
|
|
1602
|
+
if (!existingClient) client.release();
|
|
1604
1603
|
}
|
|
1605
1604
|
}
|
|
1606
1605
|
/**
|
|
@@ -1705,10 +1704,10 @@ var PgVector = class extends _mastra_core_vector.MastraVector {
|
|
|
1705
1704
|
category: _mastra_core_error.ErrorCategory.USER,
|
|
1706
1705
|
details: { indexName }
|
|
1707
1706
|
});
|
|
1707
|
+
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
1708
1708
|
client = await this.pool.connect();
|
|
1709
1709
|
await this.ensureSearchPath(client);
|
|
1710
1710
|
const { tableName } = this.getTableName(indexName);
|
|
1711
|
-
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
1712
1711
|
const qualifiedVectorType = this.getVectorTypeName(indexInfo.vectorType, indexInfo.dimension);
|
|
1713
1712
|
const ops = this.getVectorOps(indexInfo.vectorType, indexInfo.metric ?? "cosine");
|
|
1714
1713
|
let updateParts = [];
|