@caleblawson/rag
Version:
The Retrieval-Augmented Generation (RAG) module contains document processing and embedding utilities.
833 lines (770 loc) • 34.7 kB
text/typescript
/**
* @deprecated These prompts have been moved to their respective vector store packages.
* Import them directly from the vector store package instead:
* - ASTRA_PROMPT: @mastra/astra/vector/prompt
* - CHROMA_PROMPT: @mastra/chroma/vector/prompt
* - LIBSQL_PROMPT: @mastra/libsql/vector/prompt
* - PGVECTOR_PROMPT: @mastra/pg/vector/prompt
* - PINECONE_PROMPT: @mastra/pinecone/vector/prompt
* - QDRANT_PROMPT: @mastra/qdrant/vector/prompt
* - UPSTASH_PROMPT: @mastra/upstash/vector/prompt
* - VECTORIZE_PROMPT: @mastra/vectorize/vector/prompt
* - MONGODB_PROMPT: @mastra/mongodb/vector/prompt
*/
/** @deprecated Import from @mastra/astra instead */
export const ASTRA_PROMPT = `When querying Astra, you can ONLY use the operators listed below. Any other operators will be rejected.
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
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.
Basic Comparison Operators:
- $eq: Exact match (default when using field: value)
Example: { "category": "electronics" }
- $ne: Not equal
Example: { "category": { "$ne": "electronics" } }
- $gt: Greater than
Example: { "price": { "$gt": 100 } }
- $gte: Greater than or equal
Example: { "price": { "$gte": 100 } }
- $lt: Less than
Example: { "price": { "$lt": 100 } }
- $lte: Less than or equal
Example: { "price": { "$lte": 100 } }
Array Operators:
- $in: Match any value in array
Example: { "category": { "$in": ["electronics", "books"] } }
- $nin: Does not match any value in array
Example: { "category": { "$nin": ["electronics", "books"] } }
- $all: Match all values in array
Example: { "tags": { "$all": ["premium", "sale"] } }
Logical Operators:
- $and: Logical AND (can be implicit or explicit)
Implicit Example: { "price": { "$gt": 100 }, "category": "electronics" }
Explicit Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
- $or: Logical OR
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
- $not: Logical NOT
Example: { "$not": { "category": "electronics" } }
Element Operators:
- $exists: Check if field exists
Example: { "rating": { "$exists": true } }
Special Operators:
- $size: Array length check
Example: { "tags": { "$size": 2 } }
Restrictions:
- Regex patterns are not supported
- Only $and, $or, and $not logical operators are supported
- Nested fields are supported using dot notation
- Multiple conditions on the same field are supported with both implicit and explicit $and
- Empty arrays in $in/$nin will return no results
- A non-empty array is required for $all operator
- Only logical operators ($and, $or, $not) can be used at the top level
- All other operators must be used within a field condition
Valid: { "field": { "$gt": 100 } }
Valid: { "$and": [...] }
Invalid: { "$gt": 100 }
- Logical operators must contain field conditions, not direct operators
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
Invalid: { "$and": [{ "$gt": 100 }] }
- $not operator:
- Must be an object
- Cannot be empty
- Can be used at field level or top level
- Valid: { "$not": { "field": "value" } }
- Valid: { "field": { "$not": { "$eq": "value" } } }
- Other logical operators ($and, $or):
- Can only be used at top level or nested within other logical operators
- Can not be used on a field level, or be nested inside a field
- Can not be used inside an operator
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
Example Complex Query:
{
"$and": [
{ "category": { "$in": ["electronics", "computers"] } },
{ "price": { "$gte": 100, "$lte": 1000 } },
{ "tags": { "$all": ["premium"] } },
{ "rating": { "$exists": true, "$gt": 4 } },
{ "$or": [
{ "stock": { "$gt": 0 } },
{ "preorder": true }
]}
]
}`;
/** @deprecated Import from @mastra/chroma instead */
export const CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
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.
Basic Comparison Operators:
- $eq: Exact match (default when using field: value)
Example: { "category": "electronics" }
- $ne: Not equal
Example: { "category": { "$ne": "electronics" } }
- $gt: Greater than
Example: { "price": { "$gt": 100 } }
- $gte: Greater than or equal
Example: { "price": { "$gte": 100 } }
- $lt: Less than
Example: { "price": { "$lt": 100 } }
- $lte: Less than or equal
Example: { "price": { "$lte": 100 } }
Array Operators:
- $in: Match any value in array
Example: { "category": { "$in": ["electronics", "books"] } }
- $nin: Does not match any value in array
Example: { "category": { "$nin": ["electronics", "books"] } }
Logical Operators:
- $and: Logical AND
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
- $or: Logical OR
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
Restrictions:
- Regex patterns are not supported
- Element operators are not supported
- Only $and and $or logical operators are supported
- Nested fields are supported using dot notation
- Multiple conditions on the same field are supported with both implicit and explicit $and
- Empty arrays in $in/$nin will return no results
- If multiple top-level fields exist, they're wrapped in $and
- Only logical operators ($and, $or) can be used at the top level
- All other operators must be used within a field condition
Valid: { "field": { "$gt": 100 } }
Valid: { "$and": [...] }
Invalid: { "$gt": 100 }
Invalid: { "$in": [...] }
- Logical operators must contain field conditions, not direct operators
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
Invalid: { "$and": [{ "$gt": 100 }] }
- Logical operators ($and, $or):
- Can only be used at top level or nested within other logical operators
- Can not be used on a field level, or be nested inside a field
- Can not be used inside an operator
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
Example Complex Query:
{
"$and": [
{ "category": { "$in": ["electronics", "computers"] } },
{ "price": { "$gte": 100, "$lte": 1000 } },
{ "$or": [
{ "inStock": true },
{ "preorder": true }
]}
]
}`;
/** @deprecated Import from @mastra/libsql instead */
export const LIBSQL_PROMPT = `When querying LibSQL Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
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.
Basic Comparison Operators:
- $eq: Exact match (default when using field: value)
Example: { "category": "electronics" }
- $ne: Not equal
Example: { "category": { "$ne": "electronics" } }
- $gt: Greater than
Example: { "price": { "$gt": 100 } }
- $gte: Greater than or equal
Example: { "price": { "$gte": 100 } }
- $lt: Less than
Example: { "price": { "$lt": 100 } }
- $lte: Less than or equal
Example: { "price": { "$lte": 100 } }
Array Operators:
- $in: Match any value in array
Example: { "category": { "$in": ["electronics", "books"] } }
- $nin: Does not match any value in array
Example: { "category": { "$nin": ["electronics", "books"] } }
- $all: Match all values in array
Example: { "tags": { "$all": ["premium", "sale"] } }
- $elemMatch: Match array elements that meet all specified conditions
Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
- $contains: Check if array contains value
Example: { "tags": { "$contains": "premium" } }
Logical Operators:
- $and: Logical AND (implicit when using multiple conditions)
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
- $or: Logical OR
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
- $not: Logical NOT
Example: { "$not": { "category": "electronics" } }
- $nor: Logical NOR
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
Element Operators:
- $exists: Check if field exists
Example: { "rating": { "$exists": true } }
Special Operators:
- $size: Array length check
Example: { "tags": { "$size": 2 } }
Restrictions:
- Regex patterns are not supported
- Direct RegExp patterns will throw an error
- Nested fields are supported using dot notation
- Multiple conditions on the same field are supported with both implicit and explicit $and
- Array operations work on array fields only
- Basic operators handle array values as JSON strings
- Empty arrays in conditions are handled gracefully
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
- All other operators must be used within a field condition
Valid: { "field": { "$gt": 100 } }
Valid: { "$and": [...] }
Invalid: { "$gt": 100 }
Invalid: { "$contains": "value" }
- Logical operators must contain field conditions, not direct operators
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
Invalid: { "$and": [{ "$gt": 100 }] }
- $not operator:
- Must be an object
- Cannot be empty
- Can be used at field level or top level
- Valid: { "$not": { "field": "value" } }
- Valid: { "field": { "$not": { "$eq": "value" } } }
- Other logical operators ($and, $or, $nor):
- Can only be used at top level or nested within other logical operators
- Can not be used on a field level, or be nested inside a field
- Can not be used inside an operator
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
- $elemMatch requires an object with conditions
Valid: { "array": { "$elemMatch": { "field": "value" } } }
Invalid: { "array": { "$elemMatch": "value" } }
Example Complex Query:
{
"$and": [
{ "category": { "$in": ["electronics", "computers"] } },
{ "price": { "$gte": 100, "$lte": 1000 } },
{ "tags": { "$all": ["premium", "sale"] } },
{ "items": { "$elemMatch": { "price": { "$gt": 50 }, "inStock": true } } },
{ "$or": [
{ "stock": { "$gt": 0 } },
{ "preorder": true }
]}
]
}`;
/** @deprecated Import from @mastra/pg instead */
export const PGVECTOR_PROMPT = `When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
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.
Basic Comparison Operators:
- $eq: Exact match (default when using field: value)
Example: { "category": "electronics" }
- $ne: Not equal
Example: { "category": { "$ne": "electronics" } }
- $gt: Greater than
Example: { "price": { "$gt": 100 } }
- $gte: Greater than or equal
Example: { "price": { "$gte": 100 } }
- $lt: Less than
Example: { "price": { "$lt": 100 } }
- $lte: Less than or equal
Example: { "price": { "$lte": 100 } }
Array Operators:
- $in: Match any value in array
Example: { "category": { "$in": ["electronics", "books"] } }
- $nin: Does not match any value in array
Example: { "category": { "$nin": ["electronics", "books"] } }
- $all: Match all values in array
Example: { "tags": { "$all": ["premium", "sale"] } }
- $elemMatch: Match array elements that meet all specified conditions
Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
- $contains: Check if array contains value
Example: { "tags": { "$contains": "premium" } }
Logical Operators:
- $and: Logical AND
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
- $or: Logical OR
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
- $not: Logical NOT
Example: { "$not": { "category": "electronics" } }
- $nor: Logical NOR
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
Element Operators:
- $exists: Check if field exists
Example: { "rating": { "$exists": true } }
Special Operators:
- $size: Array length check
Example: { "tags": { "$size": 2 } }
- $regex: Pattern matching (PostgreSQL regex syntax)
Example: { "name": { "$regex": "^iphone" } }
- $options: Regex options (used with $regex)
Example: { "name": { "$regex": "iphone", "$options": "i" } }
Restrictions:
- Direct RegExp patterns are supported
- Nested fields are supported using dot notation
- Multiple conditions on the same field are supported with both implicit and explicit $and
- Array operations work on array fields only
- Regex patterns must follow PostgreSQL syntax
- Empty arrays in conditions are handled gracefully
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
- All other operators must be used within a field condition
Valid: { "field": { "$gt": 100 } }
Valid: { "$and": [...] }
Invalid: { "$gt": 100 }
Invalid: { "$regex": "pattern" }
- Logical operators must contain field conditions, not direct operators
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
Invalid: { "$and": [{ "$gt": 100 }] }
- $not operator:
- Must be an object
- Cannot be empty
- Can be used at field level or top level
- Valid: { "$not": { "field": "value" } }
- Valid: { "field": { "$not": { "$eq": "value" } } }
- Other logical operators ($and, $or, $nor):
- Can only be used at top level or nested within other logical operators
- Can not be used on a field level, or be nested inside a field
- Can not be used inside an operator
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
- $elemMatch requires an object with conditions
Valid: { "array": { "$elemMatch": { "field": "value" } } }
Invalid: { "array": { "$elemMatch": "value" } }
Example Complex Query:
{
"$and": [
{ "category": { "$in": ["electronics", "computers"] } },
{ "price": { "$gte": 100, "$lte": 1000 } },
{ "tags": { "$all": ["premium", "sale"] } },
{ "items": { "$elemMatch": { "price": { "$gt": 50 }, "inStock": true } } },
{ "$or": [
{ "name": { "$regex": "^iphone", "$options": "i" } },
{ "description": { "$regex": ".*apple.*" } }
]}
]
}`;
/** @deprecated Import from @mastra/pinecone instead */
export const PINECONE_PROMPT = `When querying Pinecone, you can ONLY use the operators listed below. Any other operators will be rejected.
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
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.
Basic Comparison Operators:
- $eq: Exact match (default when using field: value)
Example: { "category": "electronics" }
- $ne: Not equal
Example: { "category": { "$ne": "electronics" } }
- $gt: Greater than
Example: { "price": { "$gt": 100 } }
- $gte: Greater than or equal
Example: { "price": { "$gte": 100 } }
- $lt: Less than
Example: { "price": { "$lt": 100 } }
- $lte: Less than or equal
Example: { "price": { "$lte": 100 } }
Array Operators:
- $in: Match any value in array
Example: { "category": { "$in": ["electronics", "books"] } }
- $nin: Does not match any value in array
Example: { "category": { "$nin": ["electronics", "books"] } }
- $all: Match all values in array
Example: { "tags": { "$all": ["premium", "sale"] } }
Logical Operators:
- $and: Logical AND (can be implicit or explicit)
Implicit Example: { "price": { "$gt": 100 }, "category": "electronics" }
Explicit Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
- $or: Logical OR
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
Element Operators:
- $exists: Check if field exists
Example: { "rating": { "$exists": true } }
Restrictions:
- Regex patterns are not supported
- Only $and and $or logical operators are supported at the top level
- Empty arrays in $in/$nin will return no results
- A non-empty array is required for $all operator
- Nested fields are supported using dot notation
- Multiple conditions on the same field are supported with both implicit and explicit $and
- At least one key-value pair is required in filter object
- Empty objects and undefined values are treated as no filter
- Invalid types in comparison operators will throw errors
- All non-logical operators must be used within a field condition
Valid: { "field": { "$gt": 100 } }
Valid: { "$and": [...] }
Invalid: { "$gt": 100 }
- Logical operators must contain field conditions, not direct operators
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
Invalid: { "$and": [{ "$gt": 100 }] }
- Logical operators ($and, $or):
- Can only be used at top level or nested within other logical operators
- Can not be used on a field level, or be nested inside a field
- Can not be used inside an operator
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
Example Complex Query:
{
"$and": [
{ "category": { "$in": ["electronics", "computers"] } },
{ "price": { "$gte": 100, "$lte": 1000 } },
{ "tags": { "$all": ["premium", "sale"] } },
{ "rating": { "$exists": true, "$gt": 4 } },
{ "$or": [
{ "stock": { "$gt": 0 } },
{ "preorder": true }
]}
]
}`;
/** @deprecated Import from @mastra/qdrant instead */
export const QDRANT_PROMPT = `When querying Qdrant, you can ONLY use the operators listed below. Any other operators will be rejected.
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
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.
Basic Comparison Operators:
- $eq: Exact match (default when using field: value)
Example: { "category": "electronics" }
- $ne: Not equal
Example: { "category": { "$ne": "electronics" } }
- $gt: Greater than
Example: { "price": { "$gt": 100 } }
- $gte: Greater than or equal
Example: { "price": { "$gte": 100 } }
- $lt: Less than
Example: { "price": { "$lt": 100 } }
- $lte: Less than or equal
Example: { "price": { "$lte": 100 } }
Array Operators:
- $in: Match any value in array
Example: { "category": { "$in": ["electronics", "books"] } }
- $nin: Does not match any value in array
Example: { "category": { "$nin": ["electronics", "books"] } }
Logical Operators:
- $and: Logical AND (implicit when using multiple conditions)
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
- $or: Logical OR
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
- $not: Logical NOT
Example: { "$not": { "category": "electronics" } }
Element Operators:
- $exists: Check if field exists
Example: { "rating": { "$exists": true } }
Special Operators:
- $regex: Pattern matching
Example: { "name": { "$regex": "iphone.*" } }
- $count: Array length/value count
Example: { "tags": { "$count": { "$gt": 2 } } }
- $geo: Geographical filters (supports radius, box, polygon)
Example: {
"location": {
"$geo": {
"type": "radius",
"center": { "lat": 52.5, "lon": 13.4 },
"radius": 10000
}
}
}
- $hasId: Match specific document IDs
Example: { "$hasId": ["doc1", "doc2"] }
- $hasVector: Check vector existence
Example: { "$hasVector": "" }
- $datetime: RFC 3339 datetime range
Example: {
"created_at": {
"$datetime": {
"range": {
"gt": "2024-01-01T00:00:00Z",
"lt": "2024-12-31T23:59:59Z"
}
}
}
}
- $null: Check for null values
Example: { "field": { "$null": true } }
- $empty: Check for empty values
Example: { "array": { "$empty": true } }
- $nested: Nested object filters
Example: {
"items[]": {
"$nested": {
"price": { "$gt": 100 },
"stock": { "$gt": 0 }
}
}
}
Restrictions:
- Only logical operators ($and, $or, $not) and collection operators ($hasId, $hasVector) can be used at the top level
- All other operators must be used within a field condition
Valid: { "field": { "$gt": 100 } }
Valid: { "$and": [...] }
Valid: { "$hasId": [...] }
Invalid: { "$gt": 100 }
- Nested fields are supported using dot notation
- Array fields with nested objects use [] suffix: "items[]"
- Geo filtering requires specific format for radius, box, or polygon
- Datetime values must be in RFC 3339 format
- Empty arrays in conditions are handled as empty values
- Null values are handled with $null operator
- Empty values are handled with $empty operator
- $regex uses standard regex syntax
- $count can only be used with numeric comparison operators
- $nested requires an object with conditions
- Logical operators must contain field conditions, not direct operators
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
Invalid: { "$and": [{ "$gt": 100 }] }
- $not operator:
- Must be an object
- Cannot be empty
- Can be used at field level or top level
- Valid: { "$not": { "field": "value" } }
- Valid: { "field": { "$not": { "$eq": "value" } } }
- Other logical operators ($and, $or):
- Can only be used at top level or nested within other logical operators
- Can not be used on a field level, or be nested inside a field
- Can not be used inside an operator
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
Example Complex Query:
{
"$and": [
{ "category": { "$in": ["electronics"] } },
{ "price": { "$gt": 100 } },
{ "location": {
"$geo": {
"type": "radius",
"center": { "lat": 52.5, "lon": 13.4 },
"radius": 5000
}
}},
{ "items[]": {
"$nested": {
"price": { "$gt": 50 },
"stock": { "$gt": 0 }
}
}},
{ "created_at": {
"$datetime": {
"range": {
"gt": "2024-01-01T00:00:00Z"
}
}
}},
{ "$or": [
{ "status": { "$ne": "discontinued" } },
{ "clearance": true }
]}
]
}`;
/** @deprecated Import from @mastra/upstash instead */
export const UPSTASH_PROMPT = `When querying Upstash Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
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.
Basic Comparison Operators:
- $eq: Exact match (default when using field: value)
Example: { "category": "electronics" } or { "category": { "$eq": "electronics" } }
- $ne: Not equal
Example: { "category": { "$ne": "electronics" } }
- $gt: Greater than
Example: { "price": { "$gt": 100 } }
- $gte: Greater than or equal
Example: { "price": { "$gte": 100 } }
- $lt: Less than
Example: { "price": { "$lt": 100 } }
- $lte: Less than or equal
Example: { "price": { "$lte": 100 } }
Array Operators:
- $in: Match any value in array
Example: { "category": { "$in": ["electronics", "books"] } }
- $nin: Does not match any value in array
Example: { "category": { "$nin": ["electronics", "books"] } }
- $all: Matches all values in array
Example: { "tags": { "$all": ["premium", "new"] } }
Logical Operators:
- $and: Logical AND (implicit when using multiple conditions)
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
- $or: Logical OR
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
- $not: Logical NOT
Example: { "$not": { "category": "electronics" } }
- $nor: Logical NOR
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
Element Operators:
- $exists: Check if field exists
Example: { "rating": { "$exists": true } }
Special Operators:
- $regex: Pattern matching using glob syntax (only as operator, not direct RegExp)
Example: { "name": { "$regex": "iphone*" } }
- $contains: Check if array/string contains value
Example: { "tags": { "$contains": "premium" } }
Restrictions:
- Null/undefined values are not supported in any operator
- Empty arrays are only supported in $in/$nin operators
- Direct RegExp patterns are not supported, use $regex with glob syntax
- Nested fields are supported using dot notation
- Multiple conditions on same field are combined with AND
- String values with quotes are automatically escaped
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
- All other operators must be used within a field condition
Valid: { "field": { "$gt": 100 } }
Valid: { "$and": [...] }
Invalid: { "$gt": 100 }
- $regex uses glob syntax (*, ?) not standard regex patterns
- $contains works on both arrays and string fields
- Logical operators must contain field conditions, not direct operators
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
Invalid: { "$and": [{ "$gt": 100 }] }
- $not operator:
- Must be an object
- Cannot be empty
- Can be used at field level or top level
- Valid: { "$not": { "field": "value" } }
- Valid: { "field": { "$not": { "$eq": "value" } } }
- Other logical operators ($and, $or, $nor):
- Can only be used at top level or nested within other logical operators
- Can not be used on a field level, or be nested inside a field
- Can not be used inside an operator
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
Example Complex Query:
{
"$and": [
{ "category": { "$in": ["electronics", "computers"] } },
{ "price": { "$gt": 100, "$lt": 1000 } },
{ "tags": { "$all": ["premium", "new"] } },
{ "name": { "$regex": "iphone*" } },
{ "description": { "$contains": "latest" } },
{ "$or": [
{ "brand": "Apple" },
{ "rating": { "$gte": 4.5 } }
]}
]
}`;
/** @deprecated Import from @mastra/vectorize instead */
export const VECTORIZE_PROMPT = `When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
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.
Basic Comparison Operators:
- $eq: Exact match (default when using field: value)
Example: { "category": "electronics" }
- $ne: Not equal
Example: { "category": { "$ne": "electronics" } }
- $gt: Greater than
Example: { "price": { "$gt": 100 } }
- $gte: Greater than or equal
Example: { "price": { "$gte": 100 } }
- $lt: Less than
Example: { "price": { "$lt": 100 } }
- $lte: Less than or equal
Example: { "price": { "$lte": 100 } }
Array Operators:
- $in: Match any value in array
Example: { "category": { "$in": ["electronics", "books"] } }
- $nin: Does not match any value in array
Example: { "category": { "$nin": ["electronics", "books"] } }
Restrictions:
- Regex patterns are not supported
- Logical operators are not supported
- Element operators are not supported
- Fields must have a flat structure, as nested fields are not supported
- Multiple conditions on the same field are supported
- Empty arrays in $in/$nin will return no results
- Filter keys cannot be longer than 512 characters
- Filter keys cannot contain invalid characters ($, ", empty)
- Filter size is limited to prevent oversized queries
- Invalid types in operators return no results instead of throwing errors
- Empty objects are accepted in filters
- Metadata must use flat structure with dot notation (no nested objects)
- Must explicitly create metadata indexes for filterable fields (limit 10 per index)
- Can only effectively filter on indexed metadata fields
- Metadata values can be strings, numbers, booleans, or homogeneous arrays
- No operators can be used at the top level (no logical operators supported)
- All operators must be used within a field condition
Valid: { "field": { "$gt": 100 } }
Invalid: { "$gt": 100 }
Invalid: { "$in": [...] }
Example Complex Query:
{
"category": { "$in": ["electronics", "computers"] },
"price": { "$gte": 100, "$lte": 1000 },
"inStock": true
}`;
/** @deprecated Import from @mastra/mongodb instead */
export const MONGODB_PROMPT = `When querying MongoDB, you can ONLY use the operators listed below. Any other operators will be rejected.
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
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.
Basic Comparison Operators:
- $eq: Exact match (default when using field: value)
Example: { "category": "electronics" }
- $ne: Not equal
Example: { "category": { "$ne": "electronics" } }
- $gt: Greater than
Example: { "price": { "$gt": 100 } }
- $gte: Greater than or equal
Example: { "price": { "$gte": 100 } }
- $lt: Less than
Example: { "price": { "$lt": 100 } }
- $lte: Less than or equal
Example: { "price": { "$lte": 100 } }
Array Operators:
- $in: Match any value in array
Example: { "category": { "$in": ["electronics", "books"] } }
- $nin: Does not match any value in array
Example: { "category": { "$nin": ["electronics", "books"] } }
- $all: Match all values in array
Example: { "tags": { "$all": ["premium", "sale"] } }
- $elemMatch: Match array elements by criteria
Example: { "scores": { "$elemMatch": { "$gt": 80 } } }
Logical Operators:
- $and: Logical AND (can be implicit or explicit)
Implicit Example: { "price": { "$gt": 100 }, "category": "electronics" }
Explicit Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
- $or: Logical OR
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
- $not: Logical NOT
Example: { "field": { "$not": { "$eq": "value" } } }
- $nor: Logical NOR
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
Element Operators:
- $exists: Check if field exists
Example: { "rating": { "$exists": true } }
Special Operators:
- $regex: Regular expression match
Example: { "title": { "$regex": "^laptop", "$options": "i" } }
- $size: Array length check
Example: { "tags": { "$size": 2 } }
Usage Notes:
- You can use both 'filter' (for metadata fields) and 'documentFilter' (for document content fields).
- Nested fields are supported using dot notation (e.g., "metadata.author.name").
- Multiple conditions on the same field are supported with both implicit and explicit $and.
- Empty arrays in $in/$nin will return no results.
- All logical operators ($and, $or, $not, $nor) can be used at the top level or nested.
- All other operators must be used within a field condition.
Valid: { "field": { "$gt": 100 } }
Valid: { "$and": [...] }
Invalid: { "$gt": 100 }
- $not operator:
- Must be an object
- Cannot be empty
- Can be used at field level or top level
- Valid: { "$not": { "field": "value" } }
- Valid: { "field": { "$not": { "$eq": "value" } } }
- Logical operators must contain field conditions, not direct operators
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
Invalid: { "$and": [{ "$gt": 100 }] }
- Regex uses standard MongoDB regex syntax (with optional $options).
- Metadata values can be strings, numbers, booleans, or arrays.
- Metadata and document fields can be filtered in the same query.
Example Complex Query:
{
"category": { "$in": ["electronics", "computers"] },
"price": { "$gte": 100, "$lte": 1000 },
"inStock": true,
"title": { "$regex": "laptop", "$options": "i" },
"$or": [
{ "brand": "Apple" },
{ "rating": { "$gte": 4.5 } }
]
}
`;