@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/index.js
CHANGED
|
@@ -912,12 +912,12 @@ var PgVector = class extends MastraVector {
|
|
|
912
912
|
client.release();
|
|
913
913
|
}
|
|
914
914
|
}
|
|
915
|
+
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
915
916
|
const client = await this.pool.connect();
|
|
916
917
|
try {
|
|
917
918
|
await this.ensureSearchPath(client);
|
|
918
919
|
await client.query("BEGIN");
|
|
919
920
|
const { sql: filterQuery, values: filterValues } = buildFilterQuery(this.transformFilter(filter), minScore, topK);
|
|
920
|
-
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
921
921
|
const metric = indexInfo.metric ?? "cosine";
|
|
922
922
|
const ops = this.getVectorOps(indexInfo.vectorType, metric);
|
|
923
923
|
const vectorStr = ops.formatVector(queryVector, indexInfo.dimension);
|
|
@@ -992,6 +992,7 @@ var PgVector = class extends MastraVector {
|
|
|
992
992
|
async upsert({ indexName, vectors, metadata, ids, deleteFilter, namespace = DEFAULT_NAMESPACE }) {
|
|
993
993
|
validateUpsertInput("PG", vectors, metadata, ids);
|
|
994
994
|
const { tableName } = this.getTableName(indexName);
|
|
995
|
+
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
995
996
|
const client = await this.pool.connect();
|
|
996
997
|
try {
|
|
997
998
|
await this.ensureSearchPath(client);
|
|
@@ -1013,7 +1014,6 @@ var PgVector = class extends MastraVector {
|
|
|
1013
1014
|
}
|
|
1014
1015
|
}
|
|
1015
1016
|
const vectorIds = ids || vectors.map(() => crypto.randomUUID());
|
|
1016
|
-
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
1017
1017
|
const qualifiedVectorType = this.getVectorTypeName(indexInfo.vectorType, indexInfo.dimension);
|
|
1018
1018
|
const ops = this.getVectorOps(indexInfo.vectorType, indexInfo.metric ?? "cosine");
|
|
1019
1019
|
if (new Set(vectorIds).size !== vectorIds.length) for (let i = 0; i < vectors.length; i++) {
|
|
@@ -1301,7 +1301,7 @@ var PgVector = class extends MastraVector {
|
|
|
1301
1301
|
let existingIndexInfo = null;
|
|
1302
1302
|
let dimension = 0;
|
|
1303
1303
|
try {
|
|
1304
|
-
existingIndexInfo = await this.
|
|
1304
|
+
existingIndexInfo = await this.describeIndexMetadata({ indexName }, client);
|
|
1305
1305
|
dimension = existingIndexInfo.dimension;
|
|
1306
1306
|
if (isConfigEmpty && existingIndexInfo.metric === metric) if (existingIndexInfo.type === "flat") this.logger?.debug(`No index exists for ${vectorIndexName}, will create default ivfflat index`);
|
|
1307
1307
|
else {
|
|
@@ -1505,8 +1505,8 @@ var PgVector = class extends MastraVector {
|
|
|
1505
1505
|
* {@link describeIndex} it issues no `COUNT(*)`, so its cost does not grow with the
|
|
1506
1506
|
* number of rows in the table.
|
|
1507
1507
|
*/
|
|
1508
|
-
async describeIndexMetadata({ indexName }) {
|
|
1509
|
-
const client = await this.pool.connect();
|
|
1508
|
+
async describeIndexMetadata({ indexName }, existingClient) {
|
|
1509
|
+
const client = existingClient ?? await this.pool.connect();
|
|
1510
1510
|
try {
|
|
1511
1511
|
const { tableName, parsedIndexName } = this.getTableName(indexName);
|
|
1512
1512
|
const tableExists = await client.query(`
|
|
@@ -1566,7 +1566,6 @@ var PgVector = class extends MastraVector {
|
|
|
1566
1566
|
config
|
|
1567
1567
|
};
|
|
1568
1568
|
} catch (e) {
|
|
1569
|
-
await client.query("ROLLBACK");
|
|
1570
1569
|
const mastraError = new MastraError({
|
|
1571
1570
|
id: createVectorErrorId("PG", "DESCRIBE_INDEX", "FAILED"),
|
|
1572
1571
|
domain: ErrorDomain.MASTRA_VECTOR,
|
|
@@ -1576,7 +1575,7 @@ var PgVector = class extends MastraVector {
|
|
|
1576
1575
|
this.logger?.trackException(mastraError);
|
|
1577
1576
|
throw mastraError;
|
|
1578
1577
|
} finally {
|
|
1579
|
-
client.release();
|
|
1578
|
+
if (!existingClient) client.release();
|
|
1580
1579
|
}
|
|
1581
1580
|
}
|
|
1582
1581
|
/**
|
|
@@ -1681,10 +1680,10 @@ var PgVector = class extends MastraVector {
|
|
|
1681
1680
|
category: ErrorCategory.USER,
|
|
1682
1681
|
details: { indexName }
|
|
1683
1682
|
});
|
|
1683
|
+
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
1684
1684
|
client = await this.pool.connect();
|
|
1685
1685
|
await this.ensureSearchPath(client);
|
|
1686
1686
|
const { tableName } = this.getTableName(indexName);
|
|
1687
|
-
const indexInfo = await this.getIndexMetadata({ indexName });
|
|
1688
1687
|
const qualifiedVectorType = this.getVectorTypeName(indexInfo.vectorType, indexInfo.dimension);
|
|
1689
1688
|
const ops = this.getVectorOps(indexInfo.vectorType, indexInfo.metric ?? "cosine");
|
|
1690
1689
|
let updateParts = [];
|