@mastra/pg 0.3.4-alpha.1 → 0.3.4-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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +16 -0
- package/dist/index.cjs +16 -2
- package/dist/index.js +16 -2
- package/package.json +2 -2
- package/src/storage/index.ts +2 -2
- package/src/vector/index.test.ts +20 -0
- package/src/vector/index.ts +19 -2
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pg@0.3.4-alpha.
|
|
2
|
+
> @mastra/pg@0.3.4-alpha.3 build /home/runner/work/mastra/mastra/stores/pg
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --experimental-dts --clean --treeshake=smallest --splitting
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
6
6
|
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
7
|
[34mCLI[39m tsup v8.4.0
|
|
8
8
|
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in
|
|
9
|
+
[32mTSC[39m ⚡️ Build success in 9567ms
|
|
10
10
|
[34mDTS[39m Build start
|
|
11
11
|
[34mCLI[39m Target: es2022
|
|
12
12
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
13
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
14
|
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
15
|
[36mWriting package typings: /home/runner/work/mastra/mastra/stores/pg/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 11821ms
|
|
17
17
|
[34mCLI[39m Cleaning output folder
|
|
18
18
|
[34mESM[39m Build start
|
|
19
19
|
[34mCJS[39m Build start
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[
|
|
23
|
-
[
|
|
20
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m55.91 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 1357ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m55.43 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 1359ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.3.4-alpha.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 2836734: [MASTRA-3391] fix describe index for custom schema
|
|
8
|
+
- a3fc60c: fix whereClause condition for fromDate and toDate in pg getTraces
|
|
9
|
+
|
|
10
|
+
## 0.3.4-alpha.2
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [3171b5b]
|
|
15
|
+
- Updated dependencies [973e5ac]
|
|
16
|
+
- Updated dependencies [9e1eff5]
|
|
17
|
+
- @mastra/core@0.9.4-alpha.2
|
|
18
|
+
|
|
3
19
|
## 0.3.4-alpha.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -718,6 +718,18 @@ var PgVector = class extends vector.MastraVector {
|
|
|
718
718
|
const client = await this.pool.connect();
|
|
719
719
|
try {
|
|
720
720
|
const tableName = this.getTableName(indexName);
|
|
721
|
+
const tableExistsQuery = `
|
|
722
|
+
SELECT 1
|
|
723
|
+
FROM information_schema.columns
|
|
724
|
+
WHERE table_schema = $1
|
|
725
|
+
AND table_name = $2
|
|
726
|
+
AND udt_name = 'vector'
|
|
727
|
+
LIMIT 1;
|
|
728
|
+
`;
|
|
729
|
+
const tableExists = await client.query(tableExistsQuery, [this.schema || "public", indexName]);
|
|
730
|
+
if (tableExists.rows.length === 0) {
|
|
731
|
+
throw new Error(`Vector table ${tableName} does not exist`);
|
|
732
|
+
}
|
|
721
733
|
const dimensionQuery = `
|
|
722
734
|
SELECT atttypmod as dimension
|
|
723
735
|
FROM pg_attribute
|
|
@@ -737,12 +749,14 @@ var PgVector = class extends vector.MastraVector {
|
|
|
737
749
|
JOIN pg_class c ON i.indexrelid = c.oid
|
|
738
750
|
JOIN pg_am am ON c.relam = am.oid
|
|
739
751
|
JOIN pg_opclass opclass ON i.indclass[0] = opclass.oid
|
|
740
|
-
|
|
752
|
+
JOIN pg_namespace n ON c.relnamespace = n.oid
|
|
753
|
+
WHERE c.relname = $1
|
|
754
|
+
AND n.nspname = $2;
|
|
741
755
|
`;
|
|
742
756
|
const [dimResult, countResult, indexResult] = await Promise.all([
|
|
743
757
|
client.query(dimensionQuery, [tableName]),
|
|
744
758
|
client.query(countQuery),
|
|
745
|
-
client.query(indexQuery)
|
|
759
|
+
client.query(indexQuery, [`${indexName}_vector_idx`, this.schema || "public"])
|
|
746
760
|
]);
|
|
747
761
|
const { index_method, index_def, operator_class } = indexResult.rows[0] || {
|
|
748
762
|
index_method: "flat",
|
package/dist/index.js
CHANGED
|
@@ -710,6 +710,18 @@ var PgVector = class extends MastraVector {
|
|
|
710
710
|
const client = await this.pool.connect();
|
|
711
711
|
try {
|
|
712
712
|
const tableName = this.getTableName(indexName);
|
|
713
|
+
const tableExistsQuery = `
|
|
714
|
+
SELECT 1
|
|
715
|
+
FROM information_schema.columns
|
|
716
|
+
WHERE table_schema = $1
|
|
717
|
+
AND table_name = $2
|
|
718
|
+
AND udt_name = 'vector'
|
|
719
|
+
LIMIT 1;
|
|
720
|
+
`;
|
|
721
|
+
const tableExists = await client.query(tableExistsQuery, [this.schema || "public", indexName]);
|
|
722
|
+
if (tableExists.rows.length === 0) {
|
|
723
|
+
throw new Error(`Vector table ${tableName} does not exist`);
|
|
724
|
+
}
|
|
713
725
|
const dimensionQuery = `
|
|
714
726
|
SELECT atttypmod as dimension
|
|
715
727
|
FROM pg_attribute
|
|
@@ -729,12 +741,14 @@ var PgVector = class extends MastraVector {
|
|
|
729
741
|
JOIN pg_class c ON i.indexrelid = c.oid
|
|
730
742
|
JOIN pg_am am ON c.relam = am.oid
|
|
731
743
|
JOIN pg_opclass opclass ON i.indclass[0] = opclass.oid
|
|
732
|
-
|
|
744
|
+
JOIN pg_namespace n ON c.relnamespace = n.oid
|
|
745
|
+
WHERE c.relname = $1
|
|
746
|
+
AND n.nspname = $2;
|
|
733
747
|
`;
|
|
734
748
|
const [dimResult, countResult, indexResult] = await Promise.all([
|
|
735
749
|
client.query(dimensionQuery, [tableName]),
|
|
736
750
|
client.query(countQuery),
|
|
737
|
-
client.query(indexQuery)
|
|
751
|
+
client.query(indexQuery, [`${indexName}_vector_idx`, this.schema || "public"])
|
|
738
752
|
]);
|
|
739
753
|
const { index_method, index_def, operator_class } = indexResult.rows[0] || {
|
|
740
754
|
index_method: "flat",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.3.4-alpha.
|
|
3
|
+
"version": "0.3.4-alpha.3",
|
|
4
4
|
"description": "Postgres provider for Mastra - includes both vector and db storage capabilities",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"pg": "^8.13.3",
|
|
25
25
|
"pg-promise": "^11.11.0",
|
|
26
26
|
"xxhash-wasm": "^1.1.0",
|
|
27
|
-
"@mastra/core": "^0.9.4-alpha.
|
|
27
|
+
"@mastra/core": "^0.9.4-alpha.2"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@microsoft/api-extractor": "^7.52.5",
|
package/src/storage/index.ts
CHANGED
|
@@ -203,11 +203,11 @@ export class PostgresStore extends MastraStorage {
|
|
|
203
203
|
}
|
|
204
204
|
|
|
205
205
|
if (fromDate) {
|
|
206
|
-
conditions.push(`createdAt >=
|
|
206
|
+
conditions.push(`createdAt >= \$${idx++}`);
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
if (toDate) {
|
|
210
|
-
conditions.push(`createdAt <=
|
|
210
|
+
conditions.push(`createdAt <= \$${idx++}`);
|
|
211
211
|
}
|
|
212
212
|
|
|
213
213
|
const whereClause = conditions.length > 0 ? `WHERE ${conditions.join(' AND ')}` : '';
|
package/src/vector/index.test.ts
CHANGED
|
@@ -2139,6 +2139,26 @@ describe('PgVector', () => {
|
|
|
2139
2139
|
}
|
|
2140
2140
|
});
|
|
2141
2141
|
|
|
2142
|
+
it('should describe index in custom schema', async () => {
|
|
2143
|
+
// Create index in custom schema
|
|
2144
|
+
await customSchemaVectorDB.createIndex({
|
|
2145
|
+
indexName: testIndexName,
|
|
2146
|
+
dimension: 3,
|
|
2147
|
+
metric: 'dotproduct',
|
|
2148
|
+
indexConfig: { type: 'hnsw' },
|
|
2149
|
+
});
|
|
2150
|
+
// Insert a vector
|
|
2151
|
+
await customSchemaVectorDB.upsert({ indexName: testIndexName, vectors: [[1, 2, 3]] });
|
|
2152
|
+
// Describe the index
|
|
2153
|
+
const stats = await customSchemaVectorDB.describeIndex(testIndexName);
|
|
2154
|
+
expect(stats).toMatchObject({
|
|
2155
|
+
dimension: 3,
|
|
2156
|
+
metric: 'dotproduct',
|
|
2157
|
+
type: 'hnsw',
|
|
2158
|
+
count: 1,
|
|
2159
|
+
});
|
|
2160
|
+
});
|
|
2161
|
+
|
|
2142
2162
|
it('should allow same index name in different schemas', async () => {
|
|
2143
2163
|
// Create same index name in both schemas
|
|
2144
2164
|
await vectorDB.createIndex({ indexName: testIndexName, dimension: 3 });
|
package/src/vector/index.ts
CHANGED
|
@@ -555,6 +555,21 @@ export class PgVector extends MastraVector {
|
|
|
555
555
|
try {
|
|
556
556
|
const tableName = this.getTableName(indexName);
|
|
557
557
|
|
|
558
|
+
// Check if table exists with a vector column
|
|
559
|
+
const tableExistsQuery = `
|
|
560
|
+
SELECT 1
|
|
561
|
+
FROM information_schema.columns
|
|
562
|
+
WHERE table_schema = $1
|
|
563
|
+
AND table_name = $2
|
|
564
|
+
AND udt_name = 'vector'
|
|
565
|
+
LIMIT 1;
|
|
566
|
+
`;
|
|
567
|
+
const tableExists = await client.query(tableExistsQuery, [this.schema || 'public', indexName]);
|
|
568
|
+
|
|
569
|
+
if (tableExists.rows.length === 0) {
|
|
570
|
+
throw new Error(`Vector table ${tableName} does not exist`);
|
|
571
|
+
}
|
|
572
|
+
|
|
558
573
|
// Get vector dimension
|
|
559
574
|
const dimensionQuery = `
|
|
560
575
|
SELECT atttypmod as dimension
|
|
@@ -579,13 +594,15 @@ export class PgVector extends MastraVector {
|
|
|
579
594
|
JOIN pg_class c ON i.indexrelid = c.oid
|
|
580
595
|
JOIN pg_am am ON c.relam = am.oid
|
|
581
596
|
JOIN pg_opclass opclass ON i.indclass[0] = opclass.oid
|
|
582
|
-
|
|
597
|
+
JOIN pg_namespace n ON c.relnamespace = n.oid
|
|
598
|
+
WHERE c.relname = $1
|
|
599
|
+
AND n.nspname = $2;
|
|
583
600
|
`;
|
|
584
601
|
|
|
585
602
|
const [dimResult, countResult, indexResult] = await Promise.all([
|
|
586
603
|
client.query(dimensionQuery, [tableName]),
|
|
587
604
|
client.query(countQuery),
|
|
588
|
-
client.query(indexQuery),
|
|
605
|
+
client.query(indexQuery, [`${indexName}_vector_idx`, this.schema || 'public']),
|
|
589
606
|
]);
|
|
590
607
|
|
|
591
608
|
const { index_method, index_def, operator_class } = indexResult.rows[0] || {
|