@mastra/rag 1.2.2 → 1.2.3-alpha.1

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.cjs +25 -9
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +25 -9
  5. package/dist/index.js.map +1 -1
  6. package/dist/tools/graph-rag.d.ts.map +1 -1
  7. package/dist/tools/types.d.ts +18 -5
  8. package/dist/tools/types.d.ts.map +1 -1
  9. package/dist/tools/vector-query.d.ts.map +1 -1
  10. package/dist/utils/vector-search.d.ts +6 -7
  11. package/dist/utils/vector-search.d.ts.map +1 -1
  12. package/package.json +19 -6
  13. package/.turbo/turbo-build.log +0 -4
  14. package/docker-compose.yaml +0 -22
  15. package/eslint.config.js +0 -6
  16. package/src/document/document.test.ts +0 -2975
  17. package/src/document/document.ts +0 -335
  18. package/src/document/extractors/base.ts +0 -30
  19. package/src/document/extractors/index.ts +0 -5
  20. package/src/document/extractors/keywords.test.ts +0 -125
  21. package/src/document/extractors/keywords.ts +0 -126
  22. package/src/document/extractors/questions.test.ts +0 -120
  23. package/src/document/extractors/questions.ts +0 -111
  24. package/src/document/extractors/summary.test.ts +0 -107
  25. package/src/document/extractors/summary.ts +0 -122
  26. package/src/document/extractors/title.test.ts +0 -121
  27. package/src/document/extractors/title.ts +0 -185
  28. package/src/document/extractors/types.ts +0 -40
  29. package/src/document/index.ts +0 -2
  30. package/src/document/prompts/base.ts +0 -77
  31. package/src/document/prompts/format.ts +0 -9
  32. package/src/document/prompts/index.ts +0 -15
  33. package/src/document/prompts/prompt.ts +0 -60
  34. package/src/document/prompts/types.ts +0 -29
  35. package/src/document/schema/index.ts +0 -3
  36. package/src/document/schema/node.ts +0 -187
  37. package/src/document/schema/types.ts +0 -40
  38. package/src/document/transformers/character.ts +0 -267
  39. package/src/document/transformers/html.ts +0 -346
  40. package/src/document/transformers/json.ts +0 -536
  41. package/src/document/transformers/latex.ts +0 -11
  42. package/src/document/transformers/markdown.ts +0 -239
  43. package/src/document/transformers/semantic-markdown.ts +0 -227
  44. package/src/document/transformers/sentence.ts +0 -314
  45. package/src/document/transformers/text.ts +0 -158
  46. package/src/document/transformers/token.ts +0 -137
  47. package/src/document/transformers/transformer.ts +0 -5
  48. package/src/document/types.ts +0 -145
  49. package/src/document/validation.ts +0 -158
  50. package/src/graph-rag/index.test.ts +0 -235
  51. package/src/graph-rag/index.ts +0 -306
  52. package/src/index.ts +0 -8
  53. package/src/rerank/index.test.ts +0 -150
  54. package/src/rerank/index.ts +0 -198
  55. package/src/rerank/relevance/cohere/index.ts +0 -56
  56. package/src/rerank/relevance/index.ts +0 -3
  57. package/src/rerank/relevance/mastra-agent/index.ts +0 -32
  58. package/src/rerank/relevance/zeroentropy/index.ts +0 -26
  59. package/src/tools/README.md +0 -153
  60. package/src/tools/document-chunker.ts +0 -34
  61. package/src/tools/graph-rag.test.ts +0 -115
  62. package/src/tools/graph-rag.ts +0 -154
  63. package/src/tools/index.ts +0 -3
  64. package/src/tools/types.ts +0 -110
  65. package/src/tools/vector-query-database-config.test.ts +0 -190
  66. package/src/tools/vector-query.test.ts +0 -418
  67. package/src/tools/vector-query.ts +0 -169
  68. package/src/utils/convert-sources.ts +0 -43
  69. package/src/utils/default-settings.ts +0 -38
  70. package/src/utils/index.ts +0 -3
  71. package/src/utils/tool-schemas.ts +0 -38
  72. package/src/utils/vector-prompts.ts +0 -832
  73. package/src/utils/vector-search.ts +0 -117
  74. package/tsconfig.build.json +0 -9
  75. package/tsconfig.json +0 -5
  76. package/tsup.config.ts +0 -17
  77. package/vitest.config.ts +0 -8
@@ -1,832 +0,0 @@
1
- /**
2
- * @deprecated These prompts have been moved to their respective vector store packages.
3
- * Import them directly from the vector store package instead:
4
- * - ASTRA_PROMPT: @mastra/astra/vector/prompt
5
- * - CHROMA_PROMPT: @mastra/chroma/vector/prompt
6
- * - LIBSQL_PROMPT: @mastra/libsql/vector/prompt
7
- * - PGVECTOR_PROMPT: @mastra/pg/vector/prompt
8
- * - PINECONE_PROMPT: @mastra/pinecone/vector/prompt
9
- * - QDRANT_PROMPT: @mastra/qdrant/vector/prompt
10
- * - UPSTASH_PROMPT: @mastra/upstash/vector/prompt
11
- * - VECTORIZE_PROMPT: @mastra/vectorize/vector/prompt
12
- * - MONGODB_PROMPT: @mastra/mongodb/vector/prompt
13
- */
14
-
15
- /** @deprecated Import from @mastra/astra instead */
16
- export const ASTRA_PROMPT = `When querying Astra, you can ONLY use the operators listed below. Any other operators will be rejected.
17
- Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
18
- 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.
19
-
20
- Basic Comparison Operators:
21
- - $eq: Exact match (default when using field: value)
22
- Example: { "category": "electronics" }
23
- - $ne: Not equal
24
- Example: { "category": { "$ne": "electronics" } }
25
- - $gt: Greater than
26
- Example: { "price": { "$gt": 100 } }
27
- - $gte: Greater than or equal
28
- Example: { "price": { "$gte": 100 } }
29
- - $lt: Less than
30
- Example: { "price": { "$lt": 100 } }
31
- - $lte: Less than or equal
32
- Example: { "price": { "$lte": 100 } }
33
-
34
- Array Operators:
35
- - $in: Match any value in array
36
- Example: { "category": { "$in": ["electronics", "books"] } }
37
- - $nin: Does not match any value in array
38
- Example: { "category": { "$nin": ["electronics", "books"] } }
39
- - $all: Match all values in array
40
- Example: { "tags": { "$all": ["premium", "sale"] } }
41
-
42
- Logical Operators:
43
- - $and: Logical AND (can be implicit or explicit)
44
- Implicit Example: { "price": { "$gt": 100 }, "category": "electronics" }
45
- Explicit Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
46
- - $or: Logical OR
47
- Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
48
- - $not: Logical NOT
49
- Example: { "$not": { "category": "electronics" } }
50
-
51
- Element Operators:
52
- - $exists: Check if field exists
53
- Example: { "rating": { "$exists": true } }
54
-
55
- Special Operators:
56
- - $size: Array length check
57
- Example: { "tags": { "$size": 2 } }
58
-
59
- Restrictions:
60
- - Regex patterns are not supported
61
- - Only $and, $or, and $not logical operators are supported
62
- - Nested fields are supported using dot notation
63
- - Multiple conditions on the same field are supported with both implicit and explicit $and
64
- - Empty arrays in $in/$nin will return no results
65
- - A non-empty array is required for $all operator
66
- - Only logical operators ($and, $or, $not) can be used at the top level
67
- - All other operators must be used within a field condition
68
- Valid: { "field": { "$gt": 100 } }
69
- Valid: { "$and": [...] }
70
- Invalid: { "$gt": 100 }
71
- - Logical operators must contain field conditions, not direct operators
72
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
73
- Invalid: { "$and": [{ "$gt": 100 }] }
74
- - $not operator:
75
- - Must be an object
76
- - Cannot be empty
77
- - Can be used at field level or top level
78
- - Valid: { "$not": { "field": "value" } }
79
- - Valid: { "field": { "$not": { "$eq": "value" } } }
80
- - Other logical operators ($and, $or):
81
- - Can only be used at top level or nested within other logical operators
82
- - Can not be used on a field level, or be nested inside a field
83
- - Can not be used inside an operator
84
- - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
85
- - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
86
- - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
87
- - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
88
- - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
89
-
90
- Example Complex Query:
91
- {
92
- "$and": [
93
- { "category": { "$in": ["electronics", "computers"] } },
94
- { "price": { "$gte": 100, "$lte": 1000 } },
95
- { "tags": { "$all": ["premium"] } },
96
- { "rating": { "$exists": true, "$gt": 4 } },
97
- { "$or": [
98
- { "stock": { "$gt": 0 } },
99
- { "preorder": true }
100
- ]}
101
- ]
102
- }`;
103
-
104
- /** @deprecated Import from @mastra/chroma instead */
105
- export const CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.
106
- Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
107
- 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.
108
-
109
- Basic Comparison Operators:
110
- - $eq: Exact match (default when using field: value)
111
- Example: { "category": "electronics" }
112
- - $ne: Not equal
113
- Example: { "category": { "$ne": "electronics" } }
114
- - $gt: Greater than
115
- Example: { "price": { "$gt": 100 } }
116
- - $gte: Greater than or equal
117
- Example: { "price": { "$gte": 100 } }
118
- - $lt: Less than
119
- Example: { "price": { "$lt": 100 } }
120
- - $lte: Less than or equal
121
- Example: { "price": { "$lte": 100 } }
122
-
123
- Array Operators:
124
- - $in: Match any value in array
125
- Example: { "category": { "$in": ["electronics", "books"] } }
126
- - $nin: Does not match any value in array
127
- Example: { "category": { "$nin": ["electronics", "books"] } }
128
-
129
- Logical Operators:
130
- - $and: Logical AND
131
- Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
132
- - $or: Logical OR
133
- Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
134
-
135
- Restrictions:
136
- - Regex patterns are not supported
137
- - Element operators are not supported
138
- - Only $and and $or logical operators are supported
139
- - Nested fields are supported using dot notation
140
- - Multiple conditions on the same field are supported with both implicit and explicit $and
141
- - Empty arrays in $in/$nin will return no results
142
- - If multiple top-level fields exist, they're wrapped in $and
143
- - Only logical operators ($and, $or) can be used at the top level
144
- - All other operators must be used within a field condition
145
- Valid: { "field": { "$gt": 100 } }
146
- Valid: { "$and": [...] }
147
- Invalid: { "$gt": 100 }
148
- Invalid: { "$in": [...] }
149
- - Logical operators must contain field conditions, not direct operators
150
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
151
- Invalid: { "$and": [{ "$gt": 100 }] }
152
- - Logical operators ($and, $or):
153
- - Can only be used at top level or nested within other logical operators
154
- - Can not be used on a field level, or be nested inside a field
155
- - Can not be used inside an operator
156
- - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
157
- - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
158
- - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
159
- - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
160
- - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
161
- Example Complex Query:
162
- {
163
- "$and": [
164
- { "category": { "$in": ["electronics", "computers"] } },
165
- { "price": { "$gte": 100, "$lte": 1000 } },
166
- { "$or": [
167
- { "inStock": true },
168
- { "preorder": true }
169
- ]}
170
- ]
171
- }`;
172
-
173
- /** @deprecated Import from @mastra/libsql instead */
174
- export const LIBSQL_PROMPT = `When querying LibSQL Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
175
- Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
176
- 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.
177
-
178
- Basic Comparison Operators:
179
- - $eq: Exact match (default when using field: value)
180
- Example: { "category": "electronics" }
181
- - $ne: Not equal
182
- Example: { "category": { "$ne": "electronics" } }
183
- - $gt: Greater than
184
- Example: { "price": { "$gt": 100 } }
185
- - $gte: Greater than or equal
186
- Example: { "price": { "$gte": 100 } }
187
- - $lt: Less than
188
- Example: { "price": { "$lt": 100 } }
189
- - $lte: Less than or equal
190
- Example: { "price": { "$lte": 100 } }
191
-
192
- Array Operators:
193
- - $in: Match any value in array
194
- Example: { "category": { "$in": ["electronics", "books"] } }
195
- - $nin: Does not match any value in array
196
- Example: { "category": { "$nin": ["electronics", "books"] } }
197
- - $all: Match all values in array
198
- Example: { "tags": { "$all": ["premium", "sale"] } }
199
- - $elemMatch: Match array elements that meet all specified conditions
200
- Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
201
- - $contains: Check if array contains value
202
- Example: { "tags": { "$contains": "premium" } }
203
-
204
- Logical Operators:
205
- - $and: Logical AND (implicit when using multiple conditions)
206
- Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
207
- - $or: Logical OR
208
- Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
209
- - $not: Logical NOT
210
- Example: { "$not": { "category": "electronics" } }
211
- - $nor: Logical NOR
212
- Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
213
-
214
- Element Operators:
215
- - $exists: Check if field exists
216
- Example: { "rating": { "$exists": true } }
217
-
218
- Special Operators:
219
- - $size: Array length check
220
- Example: { "tags": { "$size": 2 } }
221
-
222
- Restrictions:
223
- - Regex patterns are not supported
224
- - Direct RegExp patterns will throw an error
225
- - Nested fields are supported using dot notation
226
- - Multiple conditions on the same field are supported with both implicit and explicit $and
227
- - Array operations work on array fields only
228
- - Basic operators handle array values as JSON strings
229
- - Empty arrays in conditions are handled gracefully
230
- - Only logical operators ($and, $or, $not, $nor) can be used at the top level
231
- - All other operators must be used within a field condition
232
- Valid: { "field": { "$gt": 100 } }
233
- Valid: { "$and": [...] }
234
- Invalid: { "$gt": 100 }
235
- Invalid: { "$contains": "value" }
236
- - Logical operators must contain field conditions, not direct operators
237
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
238
- Invalid: { "$and": [{ "$gt": 100 }] }
239
- - $not operator:
240
- - Must be an object
241
- - Cannot be empty
242
- - Can be used at field level or top level
243
- - Valid: { "$not": { "field": "value" } }
244
- - Valid: { "field": { "$not": { "$eq": "value" } } }
245
- - Other logical operators ($and, $or, $nor):
246
- - Can only be used at top level or nested within other logical operators
247
- - Can not be used on a field level, or be nested inside a field
248
- - Can not be used inside an operator
249
- - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
250
- - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
251
- - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
252
- - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
253
- - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
254
- - $elemMatch requires an object with conditions
255
- Valid: { "array": { "$elemMatch": { "field": "value" } } }
256
- Invalid: { "array": { "$elemMatch": "value" } }
257
-
258
- Example Complex Query:
259
- {
260
- "$and": [
261
- { "category": { "$in": ["electronics", "computers"] } },
262
- { "price": { "$gte": 100, "$lte": 1000 } },
263
- { "tags": { "$all": ["premium", "sale"] } },
264
- { "items": { "$elemMatch": { "price": { "$gt": 50 }, "inStock": true } } },
265
- { "$or": [
266
- { "stock": { "$gt": 0 } },
267
- { "preorder": true }
268
- ]}
269
- ]
270
- }`;
271
-
272
- /** @deprecated Import from @mastra/pg instead */
273
- export const PGVECTOR_PROMPT = `When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
274
- Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
275
- 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.
276
-
277
- Basic Comparison Operators:
278
- - $eq: Exact match (default when using field: value)
279
- Example: { "category": "electronics" }
280
- - $ne: Not equal
281
- Example: { "category": { "$ne": "electronics" } }
282
- - $gt: Greater than
283
- Example: { "price": { "$gt": 100 } }
284
- - $gte: Greater than or equal
285
- Example: { "price": { "$gte": 100 } }
286
- - $lt: Less than
287
- Example: { "price": { "$lt": 100 } }
288
- - $lte: Less than or equal
289
- Example: { "price": { "$lte": 100 } }
290
-
291
- Array Operators:
292
- - $in: Match any value in array
293
- Example: { "category": { "$in": ["electronics", "books"] } }
294
- - $nin: Does not match any value in array
295
- Example: { "category": { "$nin": ["electronics", "books"] } }
296
- - $all: Match all values in array
297
- Example: { "tags": { "$all": ["premium", "sale"] } }
298
- - $elemMatch: Match array elements that meet all specified conditions
299
- Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
300
- - $contains: Check if array contains value
301
- Example: { "tags": { "$contains": "premium" } }
302
-
303
- Logical Operators:
304
- - $and: Logical AND
305
- Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
306
- - $or: Logical OR
307
- Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
308
- - $not: Logical NOT
309
- Example: { "$not": { "category": "electronics" } }
310
- - $nor: Logical NOR
311
- Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
312
-
313
- Element Operators:
314
- - $exists: Check if field exists
315
- Example: { "rating": { "$exists": true } }
316
-
317
- Special Operators:
318
- - $size: Array length check
319
- Example: { "tags": { "$size": 2 } }
320
- - $regex: Pattern matching (PostgreSQL regex syntax)
321
- Example: { "name": { "$regex": "^iphone" } }
322
- - $options: Regex options (used with $regex)
323
- Example: { "name": { "$regex": "iphone", "$options": "i" } }
324
-
325
- Restrictions:
326
- - Direct RegExp patterns are supported
327
- - Nested fields are supported using dot notation
328
- - Multiple conditions on the same field are supported with both implicit and explicit $and
329
- - Array operations work on array fields only
330
- - Regex patterns must follow PostgreSQL syntax
331
- - Empty arrays in conditions are handled gracefully
332
- - Only logical operators ($and, $or, $not, $nor) can be used at the top level
333
- - All other operators must be used within a field condition
334
- Valid: { "field": { "$gt": 100 } }
335
- Valid: { "$and": [...] }
336
- Invalid: { "$gt": 100 }
337
- Invalid: { "$regex": "pattern" }
338
- - Logical operators must contain field conditions, not direct operators
339
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
340
- Invalid: { "$and": [{ "$gt": 100 }] }
341
- - $not operator:
342
- - Must be an object
343
- - Cannot be empty
344
- - Can be used at field level or top level
345
- - Valid: { "$not": { "field": "value" } }
346
- - Valid: { "field": { "$not": { "$eq": "value" } } }
347
- - Other logical operators ($and, $or, $nor):
348
- - Can only be used at top level or nested within other logical operators
349
- - Can not be used on a field level, or be nested inside a field
350
- - Can not be used inside an operator
351
- - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
352
- - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
353
- - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
354
- - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
355
- - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
356
- - $elemMatch requires an object with conditions
357
- Valid: { "array": { "$elemMatch": { "field": "value" } } }
358
- Invalid: { "array": { "$elemMatch": "value" } }
359
-
360
- Example Complex Query:
361
- {
362
- "$and": [
363
- { "category": { "$in": ["electronics", "computers"] } },
364
- { "price": { "$gte": 100, "$lte": 1000 } },
365
- { "tags": { "$all": ["premium", "sale"] } },
366
- { "items": { "$elemMatch": { "price": { "$gt": 50 }, "inStock": true } } },
367
- { "$or": [
368
- { "name": { "$regex": "^iphone", "$options": "i" } },
369
- { "description": { "$regex": ".*apple.*" } }
370
- ]}
371
- ]
372
- }`;
373
-
374
- /** @deprecated Import from @mastra/pinecone instead */
375
- export const PINECONE_PROMPT = `When querying Pinecone, you can ONLY use the operators listed below. Any other operators will be rejected.
376
- Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
377
- 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.
378
-
379
- Basic Comparison Operators:
380
- - $eq: Exact match (default when using field: value)
381
- Example: { "category": "electronics" }
382
- - $ne: Not equal
383
- Example: { "category": { "$ne": "electronics" } }
384
- - $gt: Greater than
385
- Example: { "price": { "$gt": 100 } }
386
- - $gte: Greater than or equal
387
- Example: { "price": { "$gte": 100 } }
388
- - $lt: Less than
389
- Example: { "price": { "$lt": 100 } }
390
- - $lte: Less than or equal
391
- Example: { "price": { "$lte": 100 } }
392
-
393
- Array Operators:
394
- - $in: Match any value in array
395
- Example: { "category": { "$in": ["electronics", "books"] } }
396
- - $nin: Does not match any value in array
397
- Example: { "category": { "$nin": ["electronics", "books"] } }
398
- - $all: Match all values in array
399
- Example: { "tags": { "$all": ["premium", "sale"] } }
400
-
401
- Logical Operators:
402
- - $and: Logical AND (can be implicit or explicit)
403
- Implicit Example: { "price": { "$gt": 100 }, "category": "electronics" }
404
- Explicit Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
405
- - $or: Logical OR
406
- Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
407
-
408
- Element Operators:
409
- - $exists: Check if field exists
410
- Example: { "rating": { "$exists": true } }
411
-
412
- Restrictions:
413
- - Regex patterns are not supported
414
- - Only $and and $or logical operators are supported at the top level
415
- - Empty arrays in $in/$nin will return no results
416
- - A non-empty array is required for $all operator
417
- - Nested fields are supported using dot notation
418
- - Multiple conditions on the same field are supported with both implicit and explicit $and
419
- - At least one key-value pair is required in filter object
420
- - Empty objects and undefined values are treated as no filter
421
- - Invalid types in comparison operators will throw errors
422
- - All non-logical operators must be used within a field condition
423
- Valid: { "field": { "$gt": 100 } }
424
- Valid: { "$and": [...] }
425
- Invalid: { "$gt": 100 }
426
- - Logical operators must contain field conditions, not direct operators
427
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
428
- Invalid: { "$and": [{ "$gt": 100 }] }
429
- - Logical operators ($and, $or):
430
- - Can only be used at top level or nested within other logical operators
431
- - Can not be used on a field level, or be nested inside a field
432
- - Can not be used inside an operator
433
- - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
434
- - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
435
- - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
436
- - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
437
- - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
438
- Example Complex Query:
439
- {
440
- "$and": [
441
- { "category": { "$in": ["electronics", "computers"] } },
442
- { "price": { "$gte": 100, "$lte": 1000 } },
443
- { "tags": { "$all": ["premium", "sale"] } },
444
- { "rating": { "$exists": true, "$gt": 4 } },
445
- { "$or": [
446
- { "stock": { "$gt": 0 } },
447
- { "preorder": true }
448
- ]}
449
- ]
450
- }`;
451
-
452
- /** @deprecated Import from @mastra/qdrant instead */
453
- export const QDRANT_PROMPT = `When querying Qdrant, you can ONLY use the operators listed below. Any other operators will be rejected.
454
- Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
455
- 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.
456
-
457
- Basic Comparison Operators:
458
- - $eq: Exact match (default when using field: value)
459
- Example: { "category": "electronics" }
460
- - $ne: Not equal
461
- Example: { "category": { "$ne": "electronics" } }
462
- - $gt: Greater than
463
- Example: { "price": { "$gt": 100 } }
464
- - $gte: Greater than or equal
465
- Example: { "price": { "$gte": 100 } }
466
- - $lt: Less than
467
- Example: { "price": { "$lt": 100 } }
468
- - $lte: Less than or equal
469
- Example: { "price": { "$lte": 100 } }
470
-
471
- Array Operators:
472
- - $in: Match any value in array
473
- Example: { "category": { "$in": ["electronics", "books"] } }
474
- - $nin: Does not match any value in array
475
- Example: { "category": { "$nin": ["electronics", "books"] } }
476
-
477
- Logical Operators:
478
- - $and: Logical AND (implicit when using multiple conditions)
479
- Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
480
- - $or: Logical OR
481
- Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
482
- - $not: Logical NOT
483
- Example: { "$not": { "category": "electronics" } }
484
-
485
- Element Operators:
486
- - $exists: Check if field exists
487
- Example: { "rating": { "$exists": true } }
488
-
489
- Special Operators:
490
- - $regex: Pattern matching
491
- Example: { "name": { "$regex": "iphone.*" } }
492
- - $count: Array length/value count
493
- Example: { "tags": { "$count": { "$gt": 2 } } }
494
- - $geo: Geographical filters (supports radius, box, polygon)
495
- Example: {
496
- "location": {
497
- "$geo": {
498
- "type": "radius",
499
- "center": { "lat": 52.5, "lon": 13.4 },
500
- "radius": 10000
501
- }
502
- }
503
- }
504
- - $hasId: Match specific document IDs
505
- Example: { "$hasId": ["doc1", "doc2"] }
506
- - $hasVector: Check vector existence
507
- Example: { "$hasVector": "" }
508
- - $datetime: RFC 3339 datetime range
509
- Example: {
510
- "created_at": {
511
- "$datetime": {
512
- "range": {
513
- "gt": "2024-01-01T00:00:00Z",
514
- "lt": "2024-12-31T23:59:59Z"
515
- }
516
- }
517
- }
518
- }
519
- - $null: Check for null values
520
- Example: { "field": { "$null": true } }
521
- - $empty: Check for empty values
522
- Example: { "array": { "$empty": true } }
523
- - $nested: Nested object filters
524
- Example: {
525
- "items[]": {
526
- "$nested": {
527
- "price": { "$gt": 100 },
528
- "stock": { "$gt": 0 }
529
- }
530
- }
531
- }
532
-
533
- Restrictions:
534
- - Only logical operators ($and, $or, $not) and collection operators ($hasId, $hasVector) can be used at the top level
535
- - All other operators must be used within a field condition
536
- Valid: { "field": { "$gt": 100 } }
537
- Valid: { "$and": [...] }
538
- Valid: { "$hasId": [...] }
539
- Invalid: { "$gt": 100 }
540
- - Nested fields are supported using dot notation
541
- - Array fields with nested objects use [] suffix: "items[]"
542
- - Geo filtering requires specific format for radius, box, or polygon
543
- - Datetime values must be in RFC 3339 format
544
- - Empty arrays in conditions are handled as empty values
545
- - Null values are handled with $null operator
546
- - Empty values are handled with $empty operator
547
- - $regex uses standard regex syntax
548
- - $count can only be used with numeric comparison operators
549
- - $nested requires an object with conditions
550
- - Logical operators must contain field conditions, not direct operators
551
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
552
- Invalid: { "$and": [{ "$gt": 100 }] }
553
- - $not operator:
554
- - Must be an object
555
- - Cannot be empty
556
- - Can be used at field level or top level
557
- - Valid: { "$not": { "field": "value" } }
558
- - Valid: { "field": { "$not": { "$eq": "value" } } }
559
- - Other logical operators ($and, $or):
560
- - Can only be used at top level or nested within other logical operators
561
- - Can not be used on a field level, or be nested inside a field
562
- - Can not be used inside an operator
563
- - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
564
- - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
565
- - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
566
- - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
567
- - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
568
- Example Complex Query:
569
- {
570
- "$and": [
571
- { "category": { "$in": ["electronics"] } },
572
- { "price": { "$gt": 100 } },
573
- { "location": {
574
- "$geo": {
575
- "type": "radius",
576
- "center": { "lat": 52.5, "lon": 13.4 },
577
- "radius": 5000
578
- }
579
- }},
580
- { "items[]": {
581
- "$nested": {
582
- "price": { "$gt": 50 },
583
- "stock": { "$gt": 0 }
584
- }
585
- }},
586
- { "created_at": {
587
- "$datetime": {
588
- "range": {
589
- "gt": "2024-01-01T00:00:00Z"
590
- }
591
- }
592
- }},
593
- { "$or": [
594
- { "status": { "$ne": "discontinued" } },
595
- { "clearance": true }
596
- ]}
597
- ]
598
- }`;
599
-
600
- /** @deprecated Import from @mastra/upstash instead */
601
- export const UPSTASH_PROMPT = `When querying Upstash Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
602
- Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
603
- 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.
604
-
605
- Basic Comparison Operators:
606
- - $eq: Exact match (default when using field: value)
607
- Example: { "category": "electronics" } or { "category": { "$eq": "electronics" } }
608
- - $ne: Not equal
609
- Example: { "category": { "$ne": "electronics" } }
610
- - $gt: Greater than
611
- Example: { "price": { "$gt": 100 } }
612
- - $gte: Greater than or equal
613
- Example: { "price": { "$gte": 100 } }
614
- - $lt: Less than
615
- Example: { "price": { "$lt": 100 } }
616
- - $lte: Less than or equal
617
- Example: { "price": { "$lte": 100 } }
618
-
619
- Array Operators:
620
- - $in: Match any value in array
621
- Example: { "category": { "$in": ["electronics", "books"] } }
622
- - $nin: Does not match any value in array
623
- Example: { "category": { "$nin": ["electronics", "books"] } }
624
- - $all: Matches all values in array
625
- Example: { "tags": { "$all": ["premium", "new"] } }
626
-
627
- Logical Operators:
628
- - $and: Logical AND (implicit when using multiple conditions)
629
- Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
630
- - $or: Logical OR
631
- Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
632
- - $not: Logical NOT
633
- Example: { "$not": { "category": "electronics" } }
634
- - $nor: Logical NOR
635
- Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
636
-
637
- Element Operators:
638
- - $exists: Check if field exists
639
- Example: { "rating": { "$exists": true } }
640
-
641
- Special Operators:
642
- - $regex: Pattern matching using glob syntax (only as operator, not direct RegExp)
643
- Example: { "name": { "$regex": "iphone*" } }
644
- - $contains: Check if array/string contains value
645
- Example: { "tags": { "$contains": "premium" } }
646
-
647
- Restrictions:
648
- - Null/undefined values are not supported in any operator
649
- - Empty arrays are only supported in $in/$nin operators
650
- - Direct RegExp patterns are not supported, use $regex with glob syntax
651
- - Nested fields are supported using dot notation
652
- - Multiple conditions on same field are combined with AND
653
- - String values with quotes are automatically escaped
654
- - Only logical operators ($and, $or, $not, $nor) can be used at the top level
655
- - All other operators must be used within a field condition
656
- Valid: { "field": { "$gt": 100 } }
657
- Valid: { "$and": [...] }
658
- Invalid: { "$gt": 100 }
659
- - $regex uses glob syntax (*, ?) not standard regex patterns
660
- - $contains works on both arrays and string fields
661
- - Logical operators must contain field conditions, not direct operators
662
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
663
- Invalid: { "$and": [{ "$gt": 100 }] }
664
- - $not operator:
665
- - Must be an object
666
- - Cannot be empty
667
- - Can be used at field level or top level
668
- - Valid: { "$not": { "field": "value" } }
669
- - Valid: { "field": { "$not": { "$eq": "value" } } }
670
- - Other logical operators ($and, $or, $nor):
671
- - Can only be used at top level or nested within other logical operators
672
- - Can not be used on a field level, or be nested inside a field
673
- - Can not be used inside an operator
674
- - Valid: { "$and": [{ "field": { "$gt": 100 } }] }
675
- - Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
676
- - Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
677
- - Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
678
- - Invalid: { "field": { "$gt": { "$and": [{...}] } } }
679
- Example Complex Query:
680
- {
681
- "$and": [
682
- { "category": { "$in": ["electronics", "computers"] } },
683
- { "price": { "$gt": 100, "$lt": 1000 } },
684
- { "tags": { "$all": ["premium", "new"] } },
685
- { "name": { "$regex": "iphone*" } },
686
- { "description": { "$contains": "latest" } },
687
- { "$or": [
688
- { "brand": "Apple" },
689
- { "rating": { "$gte": 4.5 } }
690
- ]}
691
- ]
692
- }`;
693
-
694
- /** @deprecated Import from @mastra/vectorize instead */
695
- export const VECTORIZE_PROMPT = `When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.
696
- Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
697
- 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.
698
-
699
- Basic Comparison Operators:
700
- - $eq: Exact match (default when using field: value)
701
- Example: { "category": "electronics" }
702
- - $ne: Not equal
703
- Example: { "category": { "$ne": "electronics" } }
704
- - $gt: Greater than
705
- Example: { "price": { "$gt": 100 } }
706
- - $gte: Greater than or equal
707
- Example: { "price": { "$gte": 100 } }
708
- - $lt: Less than
709
- Example: { "price": { "$lt": 100 } }
710
- - $lte: Less than or equal
711
- Example: { "price": { "$lte": 100 } }
712
-
713
- Array Operators:
714
- - $in: Match any value in array
715
- Example: { "category": { "$in": ["electronics", "books"] } }
716
- - $nin: Does not match any value in array
717
- Example: { "category": { "$nin": ["electronics", "books"] } }
718
-
719
- Restrictions:
720
- - Regex patterns are not supported
721
- - Logical operators are not supported
722
- - Element operators are not supported
723
- - Fields must have a flat structure, as nested fields are not supported
724
- - Multiple conditions on the same field are supported
725
- - Empty arrays in $in/$nin will return no results
726
- - Filter keys cannot be longer than 512 characters
727
- - Filter keys cannot contain invalid characters ($, ", empty)
728
- - Filter size is limited to prevent oversized queries
729
- - Invalid types in operators return no results instead of throwing errors
730
- - Empty objects are accepted in filters
731
- - Metadata must use flat structure with dot notation (no nested objects)
732
- - Must explicitly create metadata indexes for filterable fields (limit 10 per index)
733
- - Can only effectively filter on indexed metadata fields
734
- - Metadata values can be strings, numbers, booleans, or homogeneous arrays
735
- - No operators can be used at the top level (no logical operators supported)
736
- - All operators must be used within a field condition
737
- Valid: { "field": { "$gt": 100 } }
738
- Invalid: { "$gt": 100 }
739
- Invalid: { "$in": [...] }
740
-
741
- Example Complex Query:
742
- {
743
- "category": { "$in": ["electronics", "computers"] },
744
- "price": { "$gte": 100, "$lte": 1000 },
745
- "inStock": true
746
- }`;
747
-
748
- /** @deprecated Import from @mastra/mongodb instead */
749
- export const MONGODB_PROMPT = `When querying MongoDB, you can ONLY use the operators listed below. Any other operators will be rejected.
750
- Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
751
- 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.
752
-
753
- Basic Comparison Operators:
754
- - $eq: Exact match (default when using field: value)
755
- Example: { "category": "electronics" }
756
- - $ne: Not equal
757
- Example: { "category": { "$ne": "electronics" } }
758
- - $gt: Greater than
759
- Example: { "price": { "$gt": 100 } }
760
- - $gte: Greater than or equal
761
- Example: { "price": { "$gte": 100 } }
762
- - $lt: Less than
763
- Example: { "price": { "$lt": 100 } }
764
- - $lte: Less than or equal
765
- Example: { "price": { "$lte": 100 } }
766
-
767
- Array Operators:
768
- - $in: Match any value in array
769
- Example: { "category": { "$in": ["electronics", "books"] } }
770
- - $nin: Does not match any value in array
771
- Example: { "category": { "$nin": ["electronics", "books"] } }
772
- - $all: Match all values in array
773
- Example: { "tags": { "$all": ["premium", "sale"] } }
774
- - $elemMatch: Match array elements by criteria
775
- Example: { "scores": { "$elemMatch": { "$gt": 80 } } }
776
-
777
- Logical Operators:
778
- - $and: Logical AND (can be implicit or explicit)
779
- Implicit Example: { "price": { "$gt": 100 }, "category": "electronics" }
780
- Explicit Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
781
- - $or: Logical OR
782
- Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
783
- - $not: Logical NOT
784
- Example: { "field": { "$not": { "$eq": "value" } } }
785
- - $nor: Logical NOR
786
- Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
787
-
788
- Element Operators:
789
- - $exists: Check if field exists
790
- Example: { "rating": { "$exists": true } }
791
-
792
- Special Operators:
793
- - $regex: Regular expression match
794
- Example: { "title": { "$regex": "^laptop", "$options": "i" } }
795
- - $size: Array length check
796
- Example: { "tags": { "$size": 2 } }
797
-
798
- Usage Notes:
799
- - You can use both 'filter' (for metadata fields) and 'documentFilter' (for document content fields).
800
- - Nested fields are supported using dot notation (e.g., "metadata.author.name").
801
- - Multiple conditions on the same field are supported with both implicit and explicit $and.
802
- - Empty arrays in $in/$nin will return no results.
803
- - All logical operators ($and, $or, $not, $nor) can be used at the top level or nested.
804
- - All other operators must be used within a field condition.
805
- Valid: { "field": { "$gt": 100 } }
806
- Valid: { "$and": [...] }
807
- Invalid: { "$gt": 100 }
808
- - $not operator:
809
- - Must be an object
810
- - Cannot be empty
811
- - Can be used at field level or top level
812
- - Valid: { "$not": { "field": "value" } }
813
- - Valid: { "field": { "$not": { "$eq": "value" } } }
814
- - Logical operators must contain field conditions, not direct operators
815
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
816
- Invalid: { "$and": [{ "$gt": 100 }] }
817
- - Regex uses standard MongoDB regex syntax (with optional $options).
818
- - Metadata values can be strings, numbers, booleans, or arrays.
819
- - Metadata and document fields can be filtered in the same query.
820
-
821
- Example Complex Query:
822
- {
823
- "category": { "$in": ["electronics", "computers"] },
824
- "price": { "$gte": 100, "$lte": 1000 },
825
- "inStock": true,
826
- "title": { "$regex": "laptop", "$options": "i" },
827
- "$or": [
828
- { "brand": "Apple" },
829
- { "rating": { "$gte": 4.5 } }
830
- ]
831
- }
832
- `;