@mastra/pg 0.3.1-alpha.4 → 0.3.1-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/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +9 -0
- package/dist/_tsup-dts-rollup.d.cts +8 -0
- package/dist/_tsup-dts-rollup.d.ts +8 -0
- package/dist/index.cjs +100 -0
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +100 -1
- package/package.json +2 -2
- package/src/index.ts +1 -0
- package/src/vector/index.ts +1 -0
- package/src/vector/prompt.ts +101 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/pg@0.3.1-alpha.
|
|
2
|
+
> @mastra/pg@0.3.1-alpha.5 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 11112ms
|
|
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 12313ms
|
|
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[32m54.79 KB[39m
|
|
21
|
+
[32mCJS[39m ⚡️ Build success in 1406ms
|
|
22
|
+
[32mESM[39m [1mdist/index.js [22m[32m54.31 KB[39m
|
|
23
|
+
[32mESM[39m ⚡️ Build success in 1407ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mastra/pg
|
|
2
2
|
|
|
3
|
+
## 0.3.1-alpha.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3e7b69d: Dynamic agent props
|
|
8
|
+
- 5f826d9: Moved vector store specific prompts from @mastra/rag to be exported from the store that the prompt belongs to, ie @mastra/pg
|
|
9
|
+
- Updated dependencies [3e7b69d]
|
|
10
|
+
- @mastra/core@0.9.1-alpha.5
|
|
11
|
+
|
|
3
12
|
## 0.3.1-alpha.4
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
|
@@ -249,6 +249,14 @@ declare class PgVector extends MastraVector {
|
|
|
249
249
|
export { PgVector }
|
|
250
250
|
export { PgVector as PgVector_alias_1 }
|
|
251
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Vector store specific prompt that details supported operators and examples.
|
|
254
|
+
* This prompt helps users construct valid filters for PG Vector.
|
|
255
|
+
*/
|
|
256
|
+
declare const PGVECTOR_PROMPT = "When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n- $elemMatch: Match array elements that meet all specified conditions\n Example: { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 100 } } } }\n- $contains: Check if array contains value\n Example: { \"tags\": { \"$contains\": \"premium\" } }\n\nLogical Operators:\n- $and: Logical AND (implicit when using multiple conditions)\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n- $nor: Logical NOR\n Example: { \"$nor\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Direct RegExp patterns will throw an error\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Array operations work on array fields only\n- Basic operators handle array values as JSON strings\n- Empty arrays in conditions are handled gracefully\n- Only logical operators ($and, $or, $not, $nor) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$contains\": \"value\" }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other logical operators ($and, $or, $nor):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n- $elemMatch requires an object with conditions\n Valid: { \"array\": { \"$elemMatch\": { \"field\": \"value\" } } }\n Invalid: { \"array\": { \"$elemMatch\": \"value\" } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
|
|
257
|
+
export { PGVECTOR_PROMPT }
|
|
258
|
+
export { PGVECTOR_PROMPT as PGVECTOR_PROMPT_alias_1 }
|
|
259
|
+
|
|
252
260
|
declare type PostgresConfig = {
|
|
253
261
|
schemaName?: string;
|
|
254
262
|
/**
|
|
@@ -249,6 +249,14 @@ declare class PgVector extends MastraVector {
|
|
|
249
249
|
export { PgVector }
|
|
250
250
|
export { PgVector as PgVector_alias_1 }
|
|
251
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Vector store specific prompt that details supported operators and examples.
|
|
254
|
+
* This prompt helps users construct valid filters for PG Vector.
|
|
255
|
+
*/
|
|
256
|
+
declare const PGVECTOR_PROMPT = "When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n- $elemMatch: Match array elements that meet all specified conditions\n Example: { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 100 } } } }\n- $contains: Check if array contains value\n Example: { \"tags\": { \"$contains\": \"premium\" } }\n\nLogical Operators:\n- $and: Logical AND (implicit when using multiple conditions)\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n- $nor: Logical NOR\n Example: { \"$nor\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n\nRestrictions:\n- Regex patterns are not supported\n- Direct RegExp patterns will throw an error\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Array operations work on array fields only\n- Basic operators handle array values as JSON strings\n- Empty arrays in conditions are handled gracefully\n- Only logical operators ($and, $or, $not, $nor) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$contains\": \"value\" }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other logical operators ($and, $or, $nor):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n- $elemMatch requires an object with conditions\n Valid: { \"array\": { \"$elemMatch\": { \"field\": \"value\" } } }\n Invalid: { \"array\": { \"$elemMatch\": \"value\" } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\"] } },\n { \"rating\": { \"$exists\": true, \"$gt\": 4 } },\n { \"$or\": [\n { \"stock\": { \"$gt\": 0 } },\n { \"preorder\": true }\n ]}\n ]\n}";
|
|
257
|
+
export { PGVECTOR_PROMPT }
|
|
258
|
+
export { PGVECTOR_PROMPT as PGVECTOR_PROMPT_alias_1 }
|
|
259
|
+
|
|
252
260
|
declare type PostgresConfig = {
|
|
253
261
|
schemaName?: string;
|
|
254
262
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -1544,5 +1544,105 @@ var PostgresStore = class extends storage.MastraStorage {
|
|
|
1544
1544
|
}
|
|
1545
1545
|
};
|
|
1546
1546
|
|
|
1547
|
+
// src/vector/prompt.ts
|
|
1548
|
+
var PGVECTOR_PROMPT = `When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
1549
|
+
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
1550
|
+
If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
|
|
1551
|
+
|
|
1552
|
+
Basic Comparison Operators:
|
|
1553
|
+
- $eq: Exact match (default when using field: value)
|
|
1554
|
+
Example: { "category": "electronics" }
|
|
1555
|
+
- $ne: Not equal
|
|
1556
|
+
Example: { "category": { "$ne": "electronics" } }
|
|
1557
|
+
- $gt: Greater than
|
|
1558
|
+
Example: { "price": { "$gt": 100 } }
|
|
1559
|
+
- $gte: Greater than or equal
|
|
1560
|
+
Example: { "price": { "$gte": 100 } }
|
|
1561
|
+
- $lt: Less than
|
|
1562
|
+
Example: { "price": { "$lt": 100 } }
|
|
1563
|
+
- $lte: Less than or equal
|
|
1564
|
+
Example: { "price": { "$lte": 100 } }
|
|
1565
|
+
|
|
1566
|
+
Array Operators:
|
|
1567
|
+
- $in: Match any value in array
|
|
1568
|
+
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
1569
|
+
- $nin: Does not match any value in array
|
|
1570
|
+
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
1571
|
+
- $all: Match all values in array
|
|
1572
|
+
Example: { "tags": { "$all": ["premium", "sale"] } }
|
|
1573
|
+
- $elemMatch: Match array elements that meet all specified conditions
|
|
1574
|
+
Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
|
|
1575
|
+
- $contains: Check if array contains value
|
|
1576
|
+
Example: { "tags": { "$contains": "premium" } }
|
|
1577
|
+
|
|
1578
|
+
Logical Operators:
|
|
1579
|
+
- $and: Logical AND (implicit when using multiple conditions)
|
|
1580
|
+
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
1581
|
+
- $or: Logical OR
|
|
1582
|
+
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
1583
|
+
- $not: Logical NOT
|
|
1584
|
+
Example: { "$not": { "category": "electronics" } }
|
|
1585
|
+
- $nor: Logical NOR
|
|
1586
|
+
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
1587
|
+
|
|
1588
|
+
Element Operators:
|
|
1589
|
+
- $exists: Check if field exists
|
|
1590
|
+
Example: { "rating": { "$exists": true } }
|
|
1591
|
+
|
|
1592
|
+
Special Operators:
|
|
1593
|
+
- $size: Array length check
|
|
1594
|
+
Example: { "tags": { "$size": 2 } }
|
|
1595
|
+
|
|
1596
|
+
Restrictions:
|
|
1597
|
+
- Regex patterns are not supported
|
|
1598
|
+
- Direct RegExp patterns will throw an error
|
|
1599
|
+
- Nested fields are supported using dot notation
|
|
1600
|
+
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
1601
|
+
- Array operations work on array fields only
|
|
1602
|
+
- Basic operators handle array values as JSON strings
|
|
1603
|
+
- Empty arrays in conditions are handled gracefully
|
|
1604
|
+
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
|
|
1605
|
+
- All other operators must be used within a field condition
|
|
1606
|
+
Valid: { "field": { "$gt": 100 } }
|
|
1607
|
+
Valid: { "$and": [...] }
|
|
1608
|
+
Invalid: { "$gt": 100 }
|
|
1609
|
+
Invalid: { "$contains": "value" }
|
|
1610
|
+
- Logical operators must contain field conditions, not direct operators
|
|
1611
|
+
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
1612
|
+
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
1613
|
+
- $not operator:
|
|
1614
|
+
- Must be an object
|
|
1615
|
+
- Cannot be empty
|
|
1616
|
+
- Can be used at field level or top level
|
|
1617
|
+
- Valid: { "$not": { "field": "value" } }
|
|
1618
|
+
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
1619
|
+
- Other logical operators ($and, $or, $nor):
|
|
1620
|
+
- Can only be used at top level or nested within other logical operators
|
|
1621
|
+
- Can not be used on a field level, or be nested inside a field
|
|
1622
|
+
- Can not be used inside an operator
|
|
1623
|
+
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
1624
|
+
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
1625
|
+
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
1626
|
+
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
1627
|
+
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
1628
|
+
- $elemMatch requires an object with conditions
|
|
1629
|
+
Valid: { "array": { "$elemMatch": { "field": "value" } } }
|
|
1630
|
+
Invalid: { "array": { "$elemMatch": "value" } }
|
|
1631
|
+
|
|
1632
|
+
Example Complex Query:
|
|
1633
|
+
{
|
|
1634
|
+
"$and": [
|
|
1635
|
+
{ "category": { "$in": ["electronics", "computers"] } },
|
|
1636
|
+
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
1637
|
+
{ "tags": { "$all": ["premium"] } },
|
|
1638
|
+
{ "rating": { "$exists": true, "$gt": 4 } },
|
|
1639
|
+
{ "$or": [
|
|
1640
|
+
{ "stock": { "$gt": 0 } },
|
|
1641
|
+
{ "preorder": true }
|
|
1642
|
+
]}
|
|
1643
|
+
]
|
|
1644
|
+
}`;
|
|
1645
|
+
|
|
1646
|
+
exports.PGVECTOR_PROMPT = PGVECTOR_PROMPT;
|
|
1547
1647
|
exports.PgVector = PgVector;
|
|
1548
1648
|
exports.PostgresStore = PostgresStore;
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1536,4 +1536,103 @@ var PostgresStore = class extends MastraStorage {
|
|
|
1536
1536
|
}
|
|
1537
1537
|
};
|
|
1538
1538
|
|
|
1539
|
-
|
|
1539
|
+
// src/vector/prompt.ts
|
|
1540
|
+
var PGVECTOR_PROMPT = `When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
1541
|
+
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
1542
|
+
If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
|
|
1543
|
+
|
|
1544
|
+
Basic Comparison Operators:
|
|
1545
|
+
- $eq: Exact match (default when using field: value)
|
|
1546
|
+
Example: { "category": "electronics" }
|
|
1547
|
+
- $ne: Not equal
|
|
1548
|
+
Example: { "category": { "$ne": "electronics" } }
|
|
1549
|
+
- $gt: Greater than
|
|
1550
|
+
Example: { "price": { "$gt": 100 } }
|
|
1551
|
+
- $gte: Greater than or equal
|
|
1552
|
+
Example: { "price": { "$gte": 100 } }
|
|
1553
|
+
- $lt: Less than
|
|
1554
|
+
Example: { "price": { "$lt": 100 } }
|
|
1555
|
+
- $lte: Less than or equal
|
|
1556
|
+
Example: { "price": { "$lte": 100 } }
|
|
1557
|
+
|
|
1558
|
+
Array Operators:
|
|
1559
|
+
- $in: Match any value in array
|
|
1560
|
+
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
1561
|
+
- $nin: Does not match any value in array
|
|
1562
|
+
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
1563
|
+
- $all: Match all values in array
|
|
1564
|
+
Example: { "tags": { "$all": ["premium", "sale"] } }
|
|
1565
|
+
- $elemMatch: Match array elements that meet all specified conditions
|
|
1566
|
+
Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
|
|
1567
|
+
- $contains: Check if array contains value
|
|
1568
|
+
Example: { "tags": { "$contains": "premium" } }
|
|
1569
|
+
|
|
1570
|
+
Logical Operators:
|
|
1571
|
+
- $and: Logical AND (implicit when using multiple conditions)
|
|
1572
|
+
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
1573
|
+
- $or: Logical OR
|
|
1574
|
+
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
1575
|
+
- $not: Logical NOT
|
|
1576
|
+
Example: { "$not": { "category": "electronics" } }
|
|
1577
|
+
- $nor: Logical NOR
|
|
1578
|
+
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
1579
|
+
|
|
1580
|
+
Element Operators:
|
|
1581
|
+
- $exists: Check if field exists
|
|
1582
|
+
Example: { "rating": { "$exists": true } }
|
|
1583
|
+
|
|
1584
|
+
Special Operators:
|
|
1585
|
+
- $size: Array length check
|
|
1586
|
+
Example: { "tags": { "$size": 2 } }
|
|
1587
|
+
|
|
1588
|
+
Restrictions:
|
|
1589
|
+
- Regex patterns are not supported
|
|
1590
|
+
- Direct RegExp patterns will throw an error
|
|
1591
|
+
- Nested fields are supported using dot notation
|
|
1592
|
+
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
1593
|
+
- Array operations work on array fields only
|
|
1594
|
+
- Basic operators handle array values as JSON strings
|
|
1595
|
+
- Empty arrays in conditions are handled gracefully
|
|
1596
|
+
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
|
|
1597
|
+
- All other operators must be used within a field condition
|
|
1598
|
+
Valid: { "field": { "$gt": 100 } }
|
|
1599
|
+
Valid: { "$and": [...] }
|
|
1600
|
+
Invalid: { "$gt": 100 }
|
|
1601
|
+
Invalid: { "$contains": "value" }
|
|
1602
|
+
- Logical operators must contain field conditions, not direct operators
|
|
1603
|
+
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
1604
|
+
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
1605
|
+
- $not operator:
|
|
1606
|
+
- Must be an object
|
|
1607
|
+
- Cannot be empty
|
|
1608
|
+
- Can be used at field level or top level
|
|
1609
|
+
- Valid: { "$not": { "field": "value" } }
|
|
1610
|
+
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
1611
|
+
- Other logical operators ($and, $or, $nor):
|
|
1612
|
+
- Can only be used at top level or nested within other logical operators
|
|
1613
|
+
- Can not be used on a field level, or be nested inside a field
|
|
1614
|
+
- Can not be used inside an operator
|
|
1615
|
+
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
1616
|
+
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
1617
|
+
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
1618
|
+
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
1619
|
+
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
1620
|
+
- $elemMatch requires an object with conditions
|
|
1621
|
+
Valid: { "array": { "$elemMatch": { "field": "value" } } }
|
|
1622
|
+
Invalid: { "array": { "$elemMatch": "value" } }
|
|
1623
|
+
|
|
1624
|
+
Example Complex Query:
|
|
1625
|
+
{
|
|
1626
|
+
"$and": [
|
|
1627
|
+
{ "category": { "$in": ["electronics", "computers"] } },
|
|
1628
|
+
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
1629
|
+
{ "tags": { "$all": ["premium"] } },
|
|
1630
|
+
{ "rating": { "$exists": true, "$gt": 4 } },
|
|
1631
|
+
{ "$or": [
|
|
1632
|
+
{ "stock": { "$gt": 0 } },
|
|
1633
|
+
{ "preorder": true }
|
|
1634
|
+
]}
|
|
1635
|
+
]
|
|
1636
|
+
}`;
|
|
1637
|
+
|
|
1638
|
+
export { PGVECTOR_PROMPT, PgVector, PostgresStore };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/pg",
|
|
3
|
-
"version": "0.3.1-alpha.
|
|
3
|
+
"version": "0.3.1-alpha.5",
|
|
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.1-alpha.
|
|
27
|
+
"@mastra/core": "^0.9.1-alpha.5"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@microsoft/api-extractor": "^7.52.5",
|
package/src/index.ts
CHANGED
package/src/vector/index.ts
CHANGED
|
@@ -519,6 +519,7 @@ export class PgVector extends MastraVector {
|
|
|
519
519
|
// Wait for the installation process to complete
|
|
520
520
|
await this.installVectorExtensionPromise;
|
|
521
521
|
}
|
|
522
|
+
|
|
522
523
|
async listIndexes(): Promise<string[]> {
|
|
523
524
|
const client = await this.pool.connect();
|
|
524
525
|
try {
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vector store specific prompt that details supported operators and examples.
|
|
3
|
+
* This prompt helps users construct valid filters for PG Vector.
|
|
4
|
+
*/
|
|
5
|
+
export const PGVECTOR_PROMPT = `When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
6
|
+
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
7
|
+
If a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.
|
|
8
|
+
|
|
9
|
+
Basic Comparison Operators:
|
|
10
|
+
- $eq: Exact match (default when using field: value)
|
|
11
|
+
Example: { "category": "electronics" }
|
|
12
|
+
- $ne: Not equal
|
|
13
|
+
Example: { "category": { "$ne": "electronics" } }
|
|
14
|
+
- $gt: Greater than
|
|
15
|
+
Example: { "price": { "$gt": 100 } }
|
|
16
|
+
- $gte: Greater than or equal
|
|
17
|
+
Example: { "price": { "$gte": 100 } }
|
|
18
|
+
- $lt: Less than
|
|
19
|
+
Example: { "price": { "$lt": 100 } }
|
|
20
|
+
- $lte: Less than or equal
|
|
21
|
+
Example: { "price": { "$lte": 100 } }
|
|
22
|
+
|
|
23
|
+
Array Operators:
|
|
24
|
+
- $in: Match any value in array
|
|
25
|
+
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
26
|
+
- $nin: Does not match any value in array
|
|
27
|
+
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
28
|
+
- $all: Match all values in array
|
|
29
|
+
Example: { "tags": { "$all": ["premium", "sale"] } }
|
|
30
|
+
- $elemMatch: Match array elements that meet all specified conditions
|
|
31
|
+
Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
|
|
32
|
+
- $contains: Check if array contains value
|
|
33
|
+
Example: { "tags": { "$contains": "premium" } }
|
|
34
|
+
|
|
35
|
+
Logical Operators:
|
|
36
|
+
- $and: Logical AND (implicit when using multiple conditions)
|
|
37
|
+
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
38
|
+
- $or: Logical OR
|
|
39
|
+
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
40
|
+
- $not: Logical NOT
|
|
41
|
+
Example: { "$not": { "category": "electronics" } }
|
|
42
|
+
- $nor: Logical NOR
|
|
43
|
+
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
44
|
+
|
|
45
|
+
Element Operators:
|
|
46
|
+
- $exists: Check if field exists
|
|
47
|
+
Example: { "rating": { "$exists": true } }
|
|
48
|
+
|
|
49
|
+
Special Operators:
|
|
50
|
+
- $size: Array length check
|
|
51
|
+
Example: { "tags": { "$size": 2 } }
|
|
52
|
+
|
|
53
|
+
Restrictions:
|
|
54
|
+
- Regex patterns are not supported
|
|
55
|
+
- Direct RegExp patterns will throw an error
|
|
56
|
+
- Nested fields are supported using dot notation
|
|
57
|
+
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
58
|
+
- Array operations work on array fields only
|
|
59
|
+
- Basic operators handle array values as JSON strings
|
|
60
|
+
- Empty arrays in conditions are handled gracefully
|
|
61
|
+
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
|
|
62
|
+
- All other operators must be used within a field condition
|
|
63
|
+
Valid: { "field": { "$gt": 100 } }
|
|
64
|
+
Valid: { "$and": [...] }
|
|
65
|
+
Invalid: { "$gt": 100 }
|
|
66
|
+
Invalid: { "$contains": "value" }
|
|
67
|
+
- Logical operators must contain field conditions, not direct operators
|
|
68
|
+
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
69
|
+
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
70
|
+
- $not operator:
|
|
71
|
+
- Must be an object
|
|
72
|
+
- Cannot be empty
|
|
73
|
+
- Can be used at field level or top level
|
|
74
|
+
- Valid: { "$not": { "field": "value" } }
|
|
75
|
+
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
76
|
+
- Other logical operators ($and, $or, $nor):
|
|
77
|
+
- Can only be used at top level or nested within other logical operators
|
|
78
|
+
- Can not be used on a field level, or be nested inside a field
|
|
79
|
+
- Can not be used inside an operator
|
|
80
|
+
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
81
|
+
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
82
|
+
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
83
|
+
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
84
|
+
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
85
|
+
- $elemMatch requires an object with conditions
|
|
86
|
+
Valid: { "array": { "$elemMatch": { "field": "value" } } }
|
|
87
|
+
Invalid: { "array": { "$elemMatch": "value" } }
|
|
88
|
+
|
|
89
|
+
Example Complex Query:
|
|
90
|
+
{
|
|
91
|
+
"$and": [
|
|
92
|
+
{ "category": { "$in": ["electronics", "computers"] } },
|
|
93
|
+
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
94
|
+
{ "tags": { "$all": ["premium"] } },
|
|
95
|
+
{ "rating": { "$exists": true, "$gt": 4 } },
|
|
96
|
+
{ "$or": [
|
|
97
|
+
{ "stock": { "$gt": 0 } },
|
|
98
|
+
{ "preorder": true }
|
|
99
|
+
]}
|
|
100
|
+
]
|
|
101
|
+
}`;
|