@mastra/rag 1.3.4 → 2.0.0-beta.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.
- package/CHANGELOG.md +68 -13
- package/dist/document/extractors/keywords.d.ts.map +1 -1
- package/dist/document/extractors/questions.d.ts.map +1 -1
- package/dist/document/extractors/summary.d.ts.map +1 -1
- package/dist/document/extractors/title.d.ts.map +1 -1
- package/dist/document/types.d.ts +0 -4
- package/dist/document/types.d.ts.map +1 -1
- package/dist/document/validation.d.ts.map +1 -1
- package/dist/index.cjs +65 -886
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +66 -878
- package/dist/index.js.map +1 -1
- package/dist/rerank/relevance/mastra-agent/index.d.ts.map +1 -1
- package/dist/tools/graph-rag.d.ts.map +1 -1
- package/dist/tools/vector-query.d.ts.map +1 -1
- package/package.json +13 -14
- package/dist/utils/vector-prompts.d.ts +0 -32
- package/dist/utils/vector-prompts.d.ts.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -4143,17 +4143,18 @@ var TitleExtractor = class extends BaseExtractor {
|
|
|
4143
4143
|
let title = "";
|
|
4144
4144
|
if (this.llm.specificationVersion === "v2") {
|
|
4145
4145
|
const miniAgent = new agent.Agent({
|
|
4146
|
+
id: "title-extractor",
|
|
4146
4147
|
model: this.llm,
|
|
4147
4148
|
name: "title-extractor",
|
|
4148
4149
|
instructions: "You are a title extractor. You are given a list of nodes and you need to extract the title from the nodes."
|
|
4149
4150
|
});
|
|
4150
|
-
const result = await miniAgent.generate(
|
|
4151
|
-
|
|
4152
|
-
|
|
4153
|
-
);
|
|
4151
|
+
const result = await miniAgent.generate([
|
|
4152
|
+
{ role: "user", content: this.combineTemplate.format({ context: combinedTitles }) }
|
|
4153
|
+
]);
|
|
4154
4154
|
title = result.text;
|
|
4155
4155
|
} else {
|
|
4156
4156
|
const miniAgent = new agent.Agent({
|
|
4157
|
+
id: "title-extractor-v1",
|
|
4157
4158
|
model: this.llm,
|
|
4158
4159
|
name: "title-extractor",
|
|
4159
4160
|
instructions: "You are a title extractor. You are given a list of nodes and you need to extract the title from the nodes."
|
|
@@ -4172,6 +4173,7 @@ var TitleExtractor = class extends BaseExtractor {
|
|
|
4172
4173
|
}
|
|
4173
4174
|
async getTitlesCandidates(nodes) {
|
|
4174
4175
|
const miniAgent = new agent.Agent({
|
|
4176
|
+
id: "titles-candidates-extractor",
|
|
4175
4177
|
model: this.llm,
|
|
4176
4178
|
name: "titles-candidates-extractor",
|
|
4177
4179
|
instructions: "You are a titles candidates extractor. You are given a list of nodes and you need to extract the titles candidates from the nodes."
|
|
@@ -4179,10 +4181,9 @@ var TitleExtractor = class extends BaseExtractor {
|
|
|
4179
4181
|
const titleJobs = nodes.map(async (node) => {
|
|
4180
4182
|
let completion;
|
|
4181
4183
|
if (this.llm.specificationVersion === "v2") {
|
|
4182
|
-
const result = await miniAgent.generate(
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
);
|
|
4184
|
+
const result = await miniAgent.generate([
|
|
4185
|
+
{ role: "user", content: this.nodeTemplate.format({ context: node.getContent() }) }
|
|
4186
|
+
]);
|
|
4186
4187
|
completion = result.text;
|
|
4187
4188
|
} else {
|
|
4188
4189
|
const result = await miniAgent.generateLegacy([
|
|
@@ -4239,13 +4240,14 @@ var SummaryExtractor = class extends BaseExtractor {
|
|
|
4239
4240
|
context
|
|
4240
4241
|
});
|
|
4241
4242
|
const miniAgent = new agent.Agent({
|
|
4243
|
+
id: "summary-extractor",
|
|
4242
4244
|
model: this.llm,
|
|
4243
4245
|
name: "summary-extractor",
|
|
4244
4246
|
instructions: "You are a summary extractor. You are given a node and you need to extract the summary from the node."
|
|
4245
4247
|
});
|
|
4246
4248
|
let summary = "";
|
|
4247
4249
|
if (this.llm.specificationVersion === "v2") {
|
|
4248
|
-
const result = await miniAgent.generate([{ role: "user", content: prompt }]
|
|
4250
|
+
const result = await miniAgent.generate([{ role: "user", content: prompt }]);
|
|
4249
4251
|
summary = result.text;
|
|
4250
4252
|
} else {
|
|
4251
4253
|
const result = await miniAgent.generateLegacy([{ role: "user", content: prompt }]);
|
|
@@ -4324,13 +4326,14 @@ var QuestionsAnsweredExtractor = class extends BaseExtractor {
|
|
|
4324
4326
|
numQuestions: this.questions.toString()
|
|
4325
4327
|
});
|
|
4326
4328
|
const miniAgent = new agent.Agent({
|
|
4329
|
+
id: "question-extractor",
|
|
4327
4330
|
model: this.llm,
|
|
4328
4331
|
name: "question-extractor",
|
|
4329
4332
|
instructions: "You are a question extractor. You are given a node and you need to extract the questions from the node."
|
|
4330
4333
|
});
|
|
4331
4334
|
let questionsText = "";
|
|
4332
4335
|
if (this.llm.specificationVersion === "v2") {
|
|
4333
|
-
const result2 = await miniAgent.generate([{ role: "user", content: prompt }]
|
|
4336
|
+
const result2 = await miniAgent.generate([{ role: "user", content: prompt }]);
|
|
4334
4337
|
questionsText = result2.text;
|
|
4335
4338
|
} else {
|
|
4336
4339
|
const result2 = await miniAgent.generateLegacy([{ role: "user", content: prompt }]);
|
|
@@ -4396,23 +4399,21 @@ var KeywordExtractor = class extends BaseExtractor {
|
|
|
4396
4399
|
let keywords = "";
|
|
4397
4400
|
try {
|
|
4398
4401
|
const miniAgent = new agent.Agent({
|
|
4402
|
+
id: "keyword-extractor",
|
|
4399
4403
|
model: this.llm,
|
|
4400
4404
|
name: "keyword-extractor",
|
|
4401
4405
|
instructions: "You are a keyword extractor. You are given a node and you need to extract the keywords from the node."
|
|
4402
4406
|
});
|
|
4403
4407
|
if (this.llm.specificationVersion === "v2") {
|
|
4404
|
-
const result = await miniAgent.generate(
|
|
4405
|
-
|
|
4406
|
-
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
],
|
|
4414
|
-
{ format: "mastra" }
|
|
4415
|
-
);
|
|
4408
|
+
const result = await miniAgent.generate([
|
|
4409
|
+
{
|
|
4410
|
+
role: "user",
|
|
4411
|
+
content: this.promptTemplate.format({
|
|
4412
|
+
context: node.getContent(),
|
|
4413
|
+
maxKeywords: this.keywords.toString()
|
|
4414
|
+
})
|
|
4415
|
+
}
|
|
4416
|
+
]);
|
|
4416
4417
|
keywords = result.text;
|
|
4417
4418
|
} else {
|
|
4418
4419
|
const result = await miniAgent.generateLegacy([
|
|
@@ -6140,20 +6141,7 @@ var TokenTransformer = class _TokenTransformer extends TextTransformer {
|
|
|
6140
6141
|
});
|
|
6141
6142
|
}
|
|
6142
6143
|
};
|
|
6143
|
-
function handleDeprecatedSize(data) {
|
|
6144
|
-
if (data.size !== void 0) {
|
|
6145
|
-
console.warn(
|
|
6146
|
-
"[DEPRECATION] `size` is deprecated. Use `maxSize` instead. This will be removed in the next major version."
|
|
6147
|
-
);
|
|
6148
|
-
if (data.maxSize === void 0) {
|
|
6149
|
-
data.maxSize = data.size;
|
|
6150
|
-
}
|
|
6151
|
-
}
|
|
6152
|
-
const { size, ...rest } = data;
|
|
6153
|
-
return rest;
|
|
6154
|
-
}
|
|
6155
6144
|
var baseChunkOptionsSchema = zod.z.object({
|
|
6156
|
-
size: zod.z.number().positive().optional(),
|
|
6157
6145
|
maxSize: zod.z.number().positive().optional(),
|
|
6158
6146
|
overlap: zod.z.number().min(0).optional(),
|
|
6159
6147
|
lengthFunction: zod.z.function().optional(),
|
|
@@ -6214,15 +6202,15 @@ var semanticMarkdownChunkOptionsSchema = baseChunkOptionsSchema.extend({
|
|
|
6214
6202
|
}).strict();
|
|
6215
6203
|
var latexChunkOptionsSchema = baseChunkOptionsSchema.strict();
|
|
6216
6204
|
var validationSchemas = {
|
|
6217
|
-
character: characterChunkOptionsSchema
|
|
6218
|
-
recursive: recursiveChunkOptionsSchema
|
|
6219
|
-
sentence: sentenceChunkOptionsSchema
|
|
6220
|
-
token: tokenChunkOptionsSchema
|
|
6221
|
-
json: jsonChunkOptionsSchema
|
|
6222
|
-
html: htmlChunkOptionsSchema
|
|
6223
|
-
markdown: markdownChunkOptionsSchema
|
|
6224
|
-
"semantic-markdown": semanticMarkdownChunkOptionsSchema
|
|
6225
|
-
latex: latexChunkOptionsSchema
|
|
6205
|
+
character: characterChunkOptionsSchema,
|
|
6206
|
+
recursive: recursiveChunkOptionsSchema,
|
|
6207
|
+
sentence: sentenceChunkOptionsSchema,
|
|
6208
|
+
token: tokenChunkOptionsSchema,
|
|
6209
|
+
json: jsonChunkOptionsSchema,
|
|
6210
|
+
html: htmlChunkOptionsSchema,
|
|
6211
|
+
markdown: markdownChunkOptionsSchema,
|
|
6212
|
+
"semantic-markdown": semanticMarkdownChunkOptionsSchema,
|
|
6213
|
+
latex: latexChunkOptionsSchema
|
|
6226
6214
|
};
|
|
6227
6215
|
function validateChunkParams(strategy, params) {
|
|
6228
6216
|
const schema = validationSchemas[strategy];
|
|
@@ -6538,6 +6526,7 @@ var MastraAgentRelevanceScorer = class {
|
|
|
6538
6526
|
agent;
|
|
6539
6527
|
constructor(name14, model) {
|
|
6540
6528
|
this.agent = new agent.Agent({
|
|
6529
|
+
id: `relevance-scorer-${name14}`,
|
|
6541
6530
|
name: `Relevance Scorer ${name14}`,
|
|
6542
6531
|
instructions: `You are a specialized agent for evaluating the relevance of text to queries.
|
|
6543
6532
|
Your task is to rate how well a text passage answers a given query.
|
|
@@ -7057,26 +7046,26 @@ var convertToSources = (results) => {
|
|
|
7057
7046
|
return results.map((result) => {
|
|
7058
7047
|
if ("content" in result) {
|
|
7059
7048
|
return {
|
|
7060
|
-
id: result.id,
|
|
7049
|
+
id: result.id || "",
|
|
7061
7050
|
vector: result.embedding || [],
|
|
7062
|
-
score: result.score,
|
|
7051
|
+
score: result.score || 0,
|
|
7063
7052
|
metadata: result.metadata,
|
|
7064
7053
|
document: result.content || ""
|
|
7065
7054
|
};
|
|
7066
7055
|
}
|
|
7067
7056
|
if ("result" in result) {
|
|
7068
7057
|
return {
|
|
7069
|
-
id: result.result.id,
|
|
7058
|
+
id: result.result.id || "",
|
|
7070
7059
|
vector: result.result.vector || [],
|
|
7071
|
-
score: result.score,
|
|
7060
|
+
score: result.score || 0,
|
|
7072
7061
|
metadata: result.result.metadata,
|
|
7073
7062
|
document: result.result.document || ""
|
|
7074
7063
|
};
|
|
7075
7064
|
}
|
|
7076
7065
|
return {
|
|
7077
|
-
id: result.id,
|
|
7066
|
+
id: result.id || "",
|
|
7078
7067
|
vector: result.vector || [],
|
|
7079
|
-
score: result.score,
|
|
7068
|
+
score: result.score || 0,
|
|
7080
7069
|
metadata: result.metadata,
|
|
7081
7070
|
document: result.document || ""
|
|
7082
7071
|
};
|
|
@@ -7108,19 +7097,20 @@ var createGraphRAGTool = (options) => {
|
|
|
7108
7097
|
inputSchema,
|
|
7109
7098
|
outputSchema,
|
|
7110
7099
|
description: toolDescription,
|
|
7111
|
-
execute: async (
|
|
7112
|
-
const
|
|
7113
|
-
const
|
|
7100
|
+
execute: async (inputData, context) => {
|
|
7101
|
+
const { requestContext, mastra } = context || {};
|
|
7102
|
+
const indexName = requestContext?.get("indexName") ?? options.indexName;
|
|
7103
|
+
const vectorStoreName = requestContext?.get("vectorStoreName") ?? options.vectorStoreName;
|
|
7114
7104
|
if (!indexName) throw new Error(`indexName is required, got: ${indexName}`);
|
|
7115
7105
|
if (!vectorStoreName) throw new Error(`vectorStoreName is required, got: ${vectorStoreName}`);
|
|
7116
|
-
const includeSources =
|
|
7117
|
-
const randomWalkSteps =
|
|
7118
|
-
const restartProb =
|
|
7119
|
-
const topK =
|
|
7120
|
-
const filter =
|
|
7121
|
-
const queryText =
|
|
7122
|
-
const providerOptions =
|
|
7123
|
-
const enableFilter = !!
|
|
7106
|
+
const includeSources = requestContext?.get("includeSources") ?? options.includeSources ?? true;
|
|
7107
|
+
const randomWalkSteps = requestContext?.get("randomWalkSteps") ?? graphOptions.randomWalkSteps;
|
|
7108
|
+
const restartProb = requestContext?.get("restartProb") ?? graphOptions.restartProb;
|
|
7109
|
+
const topK = requestContext?.get("topK") ?? inputData.topK ?? 10;
|
|
7110
|
+
const filter = requestContext?.get("filter") ?? inputData.filter;
|
|
7111
|
+
const queryText = inputData.queryText;
|
|
7112
|
+
const providerOptions = requestContext?.get("providerOptions") ?? options.providerOptions;
|
|
7113
|
+
const enableFilter = !!requestContext?.get("filter") || (options.enableFilter ?? false);
|
|
7124
7114
|
const logger = mastra?.getLogger();
|
|
7125
7115
|
if (!logger) {
|
|
7126
7116
|
console.warn(
|
|
@@ -7227,21 +7217,22 @@ var createVectorQueryTool = (options) => {
|
|
|
7227
7217
|
description: toolDescription,
|
|
7228
7218
|
inputSchema,
|
|
7229
7219
|
outputSchema,
|
|
7230
|
-
execute: async (
|
|
7231
|
-
const
|
|
7232
|
-
const
|
|
7233
|
-
const
|
|
7234
|
-
const
|
|
7235
|
-
const
|
|
7236
|
-
const
|
|
7237
|
-
const
|
|
7238
|
-
const
|
|
7220
|
+
execute: async (inputData, context) => {
|
|
7221
|
+
const { requestContext, mastra } = context || {};
|
|
7222
|
+
const indexName = requestContext?.get("indexName") ?? options.indexName;
|
|
7223
|
+
const vectorStoreName = "vectorStore" in options ? storeName : requestContext?.get("vectorStoreName") ?? storeName;
|
|
7224
|
+
const includeVectors = requestContext?.get("includeVectors") ?? options.includeVectors ?? false;
|
|
7225
|
+
const includeSources = requestContext?.get("includeSources") ?? options.includeSources ?? true;
|
|
7226
|
+
const reranker = requestContext?.get("reranker") ?? options.reranker;
|
|
7227
|
+
const databaseConfig = requestContext?.get("databaseConfig") ?? options.databaseConfig;
|
|
7228
|
+
const model = requestContext?.get("model") ?? options.model;
|
|
7229
|
+
const providerOptions = requestContext?.get("providerOptions") ?? options.providerOptions;
|
|
7239
7230
|
if (!indexName) throw new Error(`indexName is required, got: ${indexName}`);
|
|
7240
7231
|
if (!vectorStoreName) throw new Error(`vectorStoreName is required, got: ${vectorStoreName}`);
|
|
7241
|
-
const topK =
|
|
7242
|
-
const filter =
|
|
7243
|
-
const queryText =
|
|
7244
|
-
const enableFilter = !!
|
|
7232
|
+
const topK = requestContext?.get("topK") ?? inputData.topK ?? 10;
|
|
7233
|
+
const filter = requestContext?.get("filter") ?? inputData.filter;
|
|
7234
|
+
const queryText = inputData.queryText;
|
|
7235
|
+
const enableFilter = !!requestContext?.get("filter") || (options.enableFilter ?? false);
|
|
7245
7236
|
const logger = mastra?.getLogger();
|
|
7246
7237
|
if (!logger) {
|
|
7247
7238
|
console.warn(
|
|
@@ -7350,823 +7341,11 @@ var createVectorQueryTool = (options) => {
|
|
|
7350
7341
|
});
|
|
7351
7342
|
};
|
|
7352
7343
|
|
|
7353
|
-
// src/utils/vector-prompts.ts
|
|
7354
|
-
var ASTRA_PROMPT = `When querying Astra, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
7355
|
-
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
7356
|
-
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.
|
|
7357
|
-
|
|
7358
|
-
Basic Comparison Operators:
|
|
7359
|
-
- $eq: Exact match (default when using field: value)
|
|
7360
|
-
Example: { "category": "electronics" }
|
|
7361
|
-
- $ne: Not equal
|
|
7362
|
-
Example: { "category": { "$ne": "electronics" } }
|
|
7363
|
-
- $gt: Greater than
|
|
7364
|
-
Example: { "price": { "$gt": 100 } }
|
|
7365
|
-
- $gte: Greater than or equal
|
|
7366
|
-
Example: { "price": { "$gte": 100 } }
|
|
7367
|
-
- $lt: Less than
|
|
7368
|
-
Example: { "price": { "$lt": 100 } }
|
|
7369
|
-
- $lte: Less than or equal
|
|
7370
|
-
Example: { "price": { "$lte": 100 } }
|
|
7371
|
-
|
|
7372
|
-
Array Operators:
|
|
7373
|
-
- $in: Match any value in array
|
|
7374
|
-
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
7375
|
-
- $nin: Does not match any value in array
|
|
7376
|
-
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
7377
|
-
- $all: Match all values in array
|
|
7378
|
-
Example: { "tags": { "$all": ["premium", "sale"] } }
|
|
7379
|
-
|
|
7380
|
-
Logical Operators:
|
|
7381
|
-
- $and: Logical AND (can be implicit or explicit)
|
|
7382
|
-
Implicit Example: { "price": { "$gt": 100 }, "category": "electronics" }
|
|
7383
|
-
Explicit Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
7384
|
-
- $or: Logical OR
|
|
7385
|
-
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7386
|
-
- $not: Logical NOT
|
|
7387
|
-
Example: { "$not": { "category": "electronics" } }
|
|
7388
|
-
|
|
7389
|
-
Element Operators:
|
|
7390
|
-
- $exists: Check if field exists
|
|
7391
|
-
Example: { "rating": { "$exists": true } }
|
|
7392
|
-
|
|
7393
|
-
Special Operators:
|
|
7394
|
-
- $size: Array length check
|
|
7395
|
-
Example: { "tags": { "$size": 2 } }
|
|
7396
|
-
|
|
7397
|
-
Restrictions:
|
|
7398
|
-
- Regex patterns are not supported
|
|
7399
|
-
- Only $and, $or, and $not logical operators are supported
|
|
7400
|
-
- Nested fields are supported using dot notation
|
|
7401
|
-
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
7402
|
-
- Empty arrays in $in/$nin will return no results
|
|
7403
|
-
- A non-empty array is required for $all operator
|
|
7404
|
-
- Only logical operators ($and, $or, $not) can be used at the top level
|
|
7405
|
-
- All other operators must be used within a field condition
|
|
7406
|
-
Valid: { "field": { "$gt": 100 } }
|
|
7407
|
-
Valid: { "$and": [...] }
|
|
7408
|
-
Invalid: { "$gt": 100 }
|
|
7409
|
-
- Logical operators must contain field conditions, not direct operators
|
|
7410
|
-
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7411
|
-
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
7412
|
-
- $not operator:
|
|
7413
|
-
- Must be an object
|
|
7414
|
-
- Cannot be empty
|
|
7415
|
-
- Can be used at field level or top level
|
|
7416
|
-
- Valid: { "$not": { "field": "value" } }
|
|
7417
|
-
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
7418
|
-
- Other logical operators ($and, $or):
|
|
7419
|
-
- Can only be used at top level or nested within other logical operators
|
|
7420
|
-
- Can not be used on a field level, or be nested inside a field
|
|
7421
|
-
- Can not be used inside an operator
|
|
7422
|
-
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7423
|
-
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
7424
|
-
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
7425
|
-
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
7426
|
-
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
7427
|
-
|
|
7428
|
-
Example Complex Query:
|
|
7429
|
-
{
|
|
7430
|
-
"$and": [
|
|
7431
|
-
{ "category": { "$in": ["electronics", "computers"] } },
|
|
7432
|
-
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
7433
|
-
{ "tags": { "$all": ["premium"] } },
|
|
7434
|
-
{ "rating": { "$exists": true, "$gt": 4 } },
|
|
7435
|
-
{ "$or": [
|
|
7436
|
-
{ "stock": { "$gt": 0 } },
|
|
7437
|
-
{ "preorder": true }
|
|
7438
|
-
]}
|
|
7439
|
-
]
|
|
7440
|
-
}`;
|
|
7441
|
-
var CHROMA_PROMPT = `When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
7442
|
-
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
7443
|
-
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.
|
|
7444
|
-
|
|
7445
|
-
Basic Comparison Operators:
|
|
7446
|
-
- $eq: Exact match (default when using field: value)
|
|
7447
|
-
Example: { "category": "electronics" }
|
|
7448
|
-
- $ne: Not equal
|
|
7449
|
-
Example: { "category": { "$ne": "electronics" } }
|
|
7450
|
-
- $gt: Greater than
|
|
7451
|
-
Example: { "price": { "$gt": 100 } }
|
|
7452
|
-
- $gte: Greater than or equal
|
|
7453
|
-
Example: { "price": { "$gte": 100 } }
|
|
7454
|
-
- $lt: Less than
|
|
7455
|
-
Example: { "price": { "$lt": 100 } }
|
|
7456
|
-
- $lte: Less than or equal
|
|
7457
|
-
Example: { "price": { "$lte": 100 } }
|
|
7458
|
-
|
|
7459
|
-
Array Operators:
|
|
7460
|
-
- $in: Match any value in array
|
|
7461
|
-
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
7462
|
-
- $nin: Does not match any value in array
|
|
7463
|
-
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
7464
|
-
|
|
7465
|
-
Logical Operators:
|
|
7466
|
-
- $and: Logical AND
|
|
7467
|
-
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
7468
|
-
- $or: Logical OR
|
|
7469
|
-
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7470
|
-
|
|
7471
|
-
Restrictions:
|
|
7472
|
-
- Regex patterns are not supported
|
|
7473
|
-
- Element operators are not supported
|
|
7474
|
-
- Only $and and $or logical operators are supported
|
|
7475
|
-
- Nested fields are supported using dot notation
|
|
7476
|
-
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
7477
|
-
- Empty arrays in $in/$nin will return no results
|
|
7478
|
-
- If multiple top-level fields exist, they're wrapped in $and
|
|
7479
|
-
- Only logical operators ($and, $or) can be used at the top level
|
|
7480
|
-
- All other operators must be used within a field condition
|
|
7481
|
-
Valid: { "field": { "$gt": 100 } }
|
|
7482
|
-
Valid: { "$and": [...] }
|
|
7483
|
-
Invalid: { "$gt": 100 }
|
|
7484
|
-
Invalid: { "$in": [...] }
|
|
7485
|
-
- Logical operators must contain field conditions, not direct operators
|
|
7486
|
-
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7487
|
-
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
7488
|
-
- Logical operators ($and, $or):
|
|
7489
|
-
- Can only be used at top level or nested within other logical operators
|
|
7490
|
-
- Can not be used on a field level, or be nested inside a field
|
|
7491
|
-
- Can not be used inside an operator
|
|
7492
|
-
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7493
|
-
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
7494
|
-
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
7495
|
-
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
7496
|
-
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
7497
|
-
Example Complex Query:
|
|
7498
|
-
{
|
|
7499
|
-
"$and": [
|
|
7500
|
-
{ "category": { "$in": ["electronics", "computers"] } },
|
|
7501
|
-
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
7502
|
-
{ "$or": [
|
|
7503
|
-
{ "inStock": true },
|
|
7504
|
-
{ "preorder": true }
|
|
7505
|
-
]}
|
|
7506
|
-
]
|
|
7507
|
-
}`;
|
|
7508
|
-
var LIBSQL_PROMPT = `When querying LibSQL Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
7509
|
-
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
7510
|
-
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.
|
|
7511
|
-
|
|
7512
|
-
Basic Comparison Operators:
|
|
7513
|
-
- $eq: Exact match (default when using field: value)
|
|
7514
|
-
Example: { "category": "electronics" }
|
|
7515
|
-
- $ne: Not equal
|
|
7516
|
-
Example: { "category": { "$ne": "electronics" } }
|
|
7517
|
-
- $gt: Greater than
|
|
7518
|
-
Example: { "price": { "$gt": 100 } }
|
|
7519
|
-
- $gte: Greater than or equal
|
|
7520
|
-
Example: { "price": { "$gte": 100 } }
|
|
7521
|
-
- $lt: Less than
|
|
7522
|
-
Example: { "price": { "$lt": 100 } }
|
|
7523
|
-
- $lte: Less than or equal
|
|
7524
|
-
Example: { "price": { "$lte": 100 } }
|
|
7525
|
-
|
|
7526
|
-
Array Operators:
|
|
7527
|
-
- $in: Match any value in array
|
|
7528
|
-
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
7529
|
-
- $nin: Does not match any value in array
|
|
7530
|
-
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
7531
|
-
- $all: Match all values in array
|
|
7532
|
-
Example: { "tags": { "$all": ["premium", "sale"] } }
|
|
7533
|
-
- $elemMatch: Match array elements that meet all specified conditions
|
|
7534
|
-
Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
|
|
7535
|
-
- $contains: Check if array contains value
|
|
7536
|
-
Example: { "tags": { "$contains": "premium" } }
|
|
7537
|
-
|
|
7538
|
-
Logical Operators:
|
|
7539
|
-
- $and: Logical AND (implicit when using multiple conditions)
|
|
7540
|
-
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
7541
|
-
- $or: Logical OR
|
|
7542
|
-
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7543
|
-
- $not: Logical NOT
|
|
7544
|
-
Example: { "$not": { "category": "electronics" } }
|
|
7545
|
-
- $nor: Logical NOR
|
|
7546
|
-
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7547
|
-
|
|
7548
|
-
Element Operators:
|
|
7549
|
-
- $exists: Check if field exists
|
|
7550
|
-
Example: { "rating": { "$exists": true } }
|
|
7551
|
-
|
|
7552
|
-
Special Operators:
|
|
7553
|
-
- $size: Array length check
|
|
7554
|
-
Example: { "tags": { "$size": 2 } }
|
|
7555
|
-
|
|
7556
|
-
Restrictions:
|
|
7557
|
-
- Regex patterns are not supported
|
|
7558
|
-
- Direct RegExp patterns will throw an error
|
|
7559
|
-
- Nested fields are supported using dot notation
|
|
7560
|
-
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
7561
|
-
- Array operations work on array fields only
|
|
7562
|
-
- Basic operators handle array values as JSON strings
|
|
7563
|
-
- Empty arrays in conditions are handled gracefully
|
|
7564
|
-
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
|
|
7565
|
-
- All other operators must be used within a field condition
|
|
7566
|
-
Valid: { "field": { "$gt": 100 } }
|
|
7567
|
-
Valid: { "$and": [...] }
|
|
7568
|
-
Invalid: { "$gt": 100 }
|
|
7569
|
-
Invalid: { "$contains": "value" }
|
|
7570
|
-
- Logical operators must contain field conditions, not direct operators
|
|
7571
|
-
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7572
|
-
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
7573
|
-
- $not operator:
|
|
7574
|
-
- Must be an object
|
|
7575
|
-
- Cannot be empty
|
|
7576
|
-
- Can be used at field level or top level
|
|
7577
|
-
- Valid: { "$not": { "field": "value" } }
|
|
7578
|
-
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
7579
|
-
- Other logical operators ($and, $or, $nor):
|
|
7580
|
-
- Can only be used at top level or nested within other logical operators
|
|
7581
|
-
- Can not be used on a field level, or be nested inside a field
|
|
7582
|
-
- Can not be used inside an operator
|
|
7583
|
-
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7584
|
-
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
7585
|
-
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
7586
|
-
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
7587
|
-
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
7588
|
-
- $elemMatch requires an object with conditions
|
|
7589
|
-
Valid: { "array": { "$elemMatch": { "field": "value" } } }
|
|
7590
|
-
Invalid: { "array": { "$elemMatch": "value" } }
|
|
7591
|
-
|
|
7592
|
-
Example Complex Query:
|
|
7593
|
-
{
|
|
7594
|
-
"$and": [
|
|
7595
|
-
{ "category": { "$in": ["electronics", "computers"] } },
|
|
7596
|
-
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
7597
|
-
{ "tags": { "$all": ["premium", "sale"] } },
|
|
7598
|
-
{ "items": { "$elemMatch": { "price": { "$gt": 50 }, "inStock": true } } },
|
|
7599
|
-
{ "$or": [
|
|
7600
|
-
{ "stock": { "$gt": 0 } },
|
|
7601
|
-
{ "preorder": true }
|
|
7602
|
-
]}
|
|
7603
|
-
]
|
|
7604
|
-
}`;
|
|
7605
|
-
var PGVECTOR_PROMPT = `When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
7606
|
-
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
7607
|
-
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.
|
|
7608
|
-
|
|
7609
|
-
Basic Comparison Operators:
|
|
7610
|
-
- $eq: Exact match (default when using field: value)
|
|
7611
|
-
Example: { "category": "electronics" }
|
|
7612
|
-
- $ne: Not equal
|
|
7613
|
-
Example: { "category": { "$ne": "electronics" } }
|
|
7614
|
-
- $gt: Greater than
|
|
7615
|
-
Example: { "price": { "$gt": 100 } }
|
|
7616
|
-
- $gte: Greater than or equal
|
|
7617
|
-
Example: { "price": { "$gte": 100 } }
|
|
7618
|
-
- $lt: Less than
|
|
7619
|
-
Example: { "price": { "$lt": 100 } }
|
|
7620
|
-
- $lte: Less than or equal
|
|
7621
|
-
Example: { "price": { "$lte": 100 } }
|
|
7622
|
-
|
|
7623
|
-
Array Operators:
|
|
7624
|
-
- $in: Match any value in array
|
|
7625
|
-
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
7626
|
-
- $nin: Does not match any value in array
|
|
7627
|
-
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
7628
|
-
- $all: Match all values in array
|
|
7629
|
-
Example: { "tags": { "$all": ["premium", "sale"] } }
|
|
7630
|
-
- $elemMatch: Match array elements that meet all specified conditions
|
|
7631
|
-
Example: { "items": { "$elemMatch": { "price": { "$gt": 100 } } } }
|
|
7632
|
-
- $contains: Check if array contains value
|
|
7633
|
-
Example: { "tags": { "$contains": "premium" } }
|
|
7634
|
-
|
|
7635
|
-
Logical Operators:
|
|
7636
|
-
- $and: Logical AND
|
|
7637
|
-
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
7638
|
-
- $or: Logical OR
|
|
7639
|
-
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7640
|
-
- $not: Logical NOT
|
|
7641
|
-
Example: { "$not": { "category": "electronics" } }
|
|
7642
|
-
- $nor: Logical NOR
|
|
7643
|
-
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7644
|
-
|
|
7645
|
-
Element Operators:
|
|
7646
|
-
- $exists: Check if field exists
|
|
7647
|
-
Example: { "rating": { "$exists": true } }
|
|
7648
|
-
|
|
7649
|
-
Special Operators:
|
|
7650
|
-
- $size: Array length check
|
|
7651
|
-
Example: { "tags": { "$size": 2 } }
|
|
7652
|
-
- $regex: Pattern matching (PostgreSQL regex syntax)
|
|
7653
|
-
Example: { "name": { "$regex": "^iphone" } }
|
|
7654
|
-
- $options: Regex options (used with $regex)
|
|
7655
|
-
Example: { "name": { "$regex": "iphone", "$options": "i" } }
|
|
7656
|
-
|
|
7657
|
-
Restrictions:
|
|
7658
|
-
- Direct RegExp patterns are supported
|
|
7659
|
-
- Nested fields are supported using dot notation
|
|
7660
|
-
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
7661
|
-
- Array operations work on array fields only
|
|
7662
|
-
- Regex patterns must follow PostgreSQL syntax
|
|
7663
|
-
- Empty arrays in conditions are handled gracefully
|
|
7664
|
-
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
|
|
7665
|
-
- All other operators must be used within a field condition
|
|
7666
|
-
Valid: { "field": { "$gt": 100 } }
|
|
7667
|
-
Valid: { "$and": [...] }
|
|
7668
|
-
Invalid: { "$gt": 100 }
|
|
7669
|
-
Invalid: { "$regex": "pattern" }
|
|
7670
|
-
- Logical operators must contain field conditions, not direct operators
|
|
7671
|
-
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7672
|
-
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
7673
|
-
- $not operator:
|
|
7674
|
-
- Must be an object
|
|
7675
|
-
- Cannot be empty
|
|
7676
|
-
- Can be used at field level or top level
|
|
7677
|
-
- Valid: { "$not": { "field": "value" } }
|
|
7678
|
-
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
7679
|
-
- Other logical operators ($and, $or, $nor):
|
|
7680
|
-
- Can only be used at top level or nested within other logical operators
|
|
7681
|
-
- Can not be used on a field level, or be nested inside a field
|
|
7682
|
-
- Can not be used inside an operator
|
|
7683
|
-
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7684
|
-
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
7685
|
-
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
7686
|
-
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
7687
|
-
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
7688
|
-
- $elemMatch requires an object with conditions
|
|
7689
|
-
Valid: { "array": { "$elemMatch": { "field": "value" } } }
|
|
7690
|
-
Invalid: { "array": { "$elemMatch": "value" } }
|
|
7691
|
-
|
|
7692
|
-
Example Complex Query:
|
|
7693
|
-
{
|
|
7694
|
-
"$and": [
|
|
7695
|
-
{ "category": { "$in": ["electronics", "computers"] } },
|
|
7696
|
-
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
7697
|
-
{ "tags": { "$all": ["premium", "sale"] } },
|
|
7698
|
-
{ "items": { "$elemMatch": { "price": { "$gt": 50 }, "inStock": true } } },
|
|
7699
|
-
{ "$or": [
|
|
7700
|
-
{ "name": { "$regex": "^iphone", "$options": "i" } },
|
|
7701
|
-
{ "description": { "$regex": ".*apple.*" } }
|
|
7702
|
-
]}
|
|
7703
|
-
]
|
|
7704
|
-
}`;
|
|
7705
|
-
var PINECONE_PROMPT = `When querying Pinecone, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
7706
|
-
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
7707
|
-
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.
|
|
7708
|
-
|
|
7709
|
-
Basic Comparison Operators:
|
|
7710
|
-
- $eq: Exact match (default when using field: value)
|
|
7711
|
-
Example: { "category": "electronics" }
|
|
7712
|
-
- $ne: Not equal
|
|
7713
|
-
Example: { "category": { "$ne": "electronics" } }
|
|
7714
|
-
- $gt: Greater than
|
|
7715
|
-
Example: { "price": { "$gt": 100 } }
|
|
7716
|
-
- $gte: Greater than or equal
|
|
7717
|
-
Example: { "price": { "$gte": 100 } }
|
|
7718
|
-
- $lt: Less than
|
|
7719
|
-
Example: { "price": { "$lt": 100 } }
|
|
7720
|
-
- $lte: Less than or equal
|
|
7721
|
-
Example: { "price": { "$lte": 100 } }
|
|
7722
|
-
|
|
7723
|
-
Array Operators:
|
|
7724
|
-
- $in: Match any value in array
|
|
7725
|
-
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
7726
|
-
- $nin: Does not match any value in array
|
|
7727
|
-
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
7728
|
-
- $all: Match all values in array
|
|
7729
|
-
Example: { "tags": { "$all": ["premium", "sale"] } }
|
|
7730
|
-
|
|
7731
|
-
Logical Operators:
|
|
7732
|
-
- $and: Logical AND (can be implicit or explicit)
|
|
7733
|
-
Implicit Example: { "price": { "$gt": 100 }, "category": "electronics" }
|
|
7734
|
-
Explicit Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
7735
|
-
- $or: Logical OR
|
|
7736
|
-
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7737
|
-
|
|
7738
|
-
Element Operators:
|
|
7739
|
-
- $exists: Check if field exists
|
|
7740
|
-
Example: { "rating": { "$exists": true } }
|
|
7741
|
-
|
|
7742
|
-
Restrictions:
|
|
7743
|
-
- Regex patterns are not supported
|
|
7744
|
-
- Only $and and $or logical operators are supported at the top level
|
|
7745
|
-
- Empty arrays in $in/$nin will return no results
|
|
7746
|
-
- A non-empty array is required for $all operator
|
|
7747
|
-
- Nested fields are supported using dot notation
|
|
7748
|
-
- Multiple conditions on the same field are supported with both implicit and explicit $and
|
|
7749
|
-
- At least one key-value pair is required in filter object
|
|
7750
|
-
- Empty objects and undefined values are treated as no filter
|
|
7751
|
-
- Invalid types in comparison operators will throw errors
|
|
7752
|
-
- All non-logical operators must be used within a field condition
|
|
7753
|
-
Valid: { "field": { "$gt": 100 } }
|
|
7754
|
-
Valid: { "$and": [...] }
|
|
7755
|
-
Invalid: { "$gt": 100 }
|
|
7756
|
-
- Logical operators must contain field conditions, not direct operators
|
|
7757
|
-
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7758
|
-
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
7759
|
-
- Logical operators ($and, $or):
|
|
7760
|
-
- Can only be used at top level or nested within other logical operators
|
|
7761
|
-
- Can not be used on a field level, or be nested inside a field
|
|
7762
|
-
- Can not be used inside an operator
|
|
7763
|
-
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7764
|
-
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
7765
|
-
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
7766
|
-
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
7767
|
-
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
7768
|
-
Example Complex Query:
|
|
7769
|
-
{
|
|
7770
|
-
"$and": [
|
|
7771
|
-
{ "category": { "$in": ["electronics", "computers"] } },
|
|
7772
|
-
{ "price": { "$gte": 100, "$lte": 1000 } },
|
|
7773
|
-
{ "tags": { "$all": ["premium", "sale"] } },
|
|
7774
|
-
{ "rating": { "$exists": true, "$gt": 4 } },
|
|
7775
|
-
{ "$or": [
|
|
7776
|
-
{ "stock": { "$gt": 0 } },
|
|
7777
|
-
{ "preorder": true }
|
|
7778
|
-
]}
|
|
7779
|
-
]
|
|
7780
|
-
}`;
|
|
7781
|
-
var QDRANT_PROMPT = `When querying Qdrant, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
7782
|
-
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
7783
|
-
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.
|
|
7784
|
-
|
|
7785
|
-
Basic Comparison Operators:
|
|
7786
|
-
- $eq: Exact match (default when using field: value)
|
|
7787
|
-
Example: { "category": "electronics" }
|
|
7788
|
-
- $ne: Not equal
|
|
7789
|
-
Example: { "category": { "$ne": "electronics" } }
|
|
7790
|
-
- $gt: Greater than
|
|
7791
|
-
Example: { "price": { "$gt": 100 } }
|
|
7792
|
-
- $gte: Greater than or equal
|
|
7793
|
-
Example: { "price": { "$gte": 100 } }
|
|
7794
|
-
- $lt: Less than
|
|
7795
|
-
Example: { "price": { "$lt": 100 } }
|
|
7796
|
-
- $lte: Less than or equal
|
|
7797
|
-
Example: { "price": { "$lte": 100 } }
|
|
7798
|
-
|
|
7799
|
-
Array Operators:
|
|
7800
|
-
- $in: Match any value in array
|
|
7801
|
-
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
7802
|
-
- $nin: Does not match any value in array
|
|
7803
|
-
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
7804
|
-
|
|
7805
|
-
Logical Operators:
|
|
7806
|
-
- $and: Logical AND (implicit when using multiple conditions)
|
|
7807
|
-
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
7808
|
-
- $or: Logical OR
|
|
7809
|
-
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7810
|
-
- $not: Logical NOT
|
|
7811
|
-
Example: { "$not": { "category": "electronics" } }
|
|
7812
|
-
|
|
7813
|
-
Element Operators:
|
|
7814
|
-
- $exists: Check if field exists
|
|
7815
|
-
Example: { "rating": { "$exists": true } }
|
|
7816
|
-
|
|
7817
|
-
Special Operators:
|
|
7818
|
-
- $regex: Pattern matching
|
|
7819
|
-
Example: { "name": { "$regex": "iphone.*" } }
|
|
7820
|
-
- $count: Array length/value count
|
|
7821
|
-
Example: { "tags": { "$count": { "$gt": 2 } } }
|
|
7822
|
-
- $geo: Geographical filters (supports radius, box, polygon)
|
|
7823
|
-
Example: {
|
|
7824
|
-
"location": {
|
|
7825
|
-
"$geo": {
|
|
7826
|
-
"type": "radius",
|
|
7827
|
-
"center": { "lat": 52.5, "lon": 13.4 },
|
|
7828
|
-
"radius": 10000
|
|
7829
|
-
}
|
|
7830
|
-
}
|
|
7831
|
-
}
|
|
7832
|
-
- $hasId: Match specific document IDs
|
|
7833
|
-
Example: { "$hasId": ["doc1", "doc2"] }
|
|
7834
|
-
- $hasVector: Check vector existence
|
|
7835
|
-
Example: { "$hasVector": "" }
|
|
7836
|
-
- $datetime: RFC 3339 datetime range
|
|
7837
|
-
Example: {
|
|
7838
|
-
"created_at": {
|
|
7839
|
-
"$datetime": {
|
|
7840
|
-
"range": {
|
|
7841
|
-
"gt": "2024-01-01T00:00:00Z",
|
|
7842
|
-
"lt": "2024-12-31T23:59:59Z"
|
|
7843
|
-
}
|
|
7844
|
-
}
|
|
7845
|
-
}
|
|
7846
|
-
}
|
|
7847
|
-
- $null: Check for null values
|
|
7848
|
-
Example: { "field": { "$null": true } }
|
|
7849
|
-
- $empty: Check for empty values
|
|
7850
|
-
Example: { "array": { "$empty": true } }
|
|
7851
|
-
- $nested: Nested object filters
|
|
7852
|
-
Example: {
|
|
7853
|
-
"items[]": {
|
|
7854
|
-
"$nested": {
|
|
7855
|
-
"price": { "$gt": 100 },
|
|
7856
|
-
"stock": { "$gt": 0 }
|
|
7857
|
-
}
|
|
7858
|
-
}
|
|
7859
|
-
}
|
|
7860
|
-
|
|
7861
|
-
Restrictions:
|
|
7862
|
-
- Only logical operators ($and, $or, $not) and collection operators ($hasId, $hasVector) can be used at the top level
|
|
7863
|
-
- All other operators must be used within a field condition
|
|
7864
|
-
Valid: { "field": { "$gt": 100 } }
|
|
7865
|
-
Valid: { "$and": [...] }
|
|
7866
|
-
Valid: { "$hasId": [...] }
|
|
7867
|
-
Invalid: { "$gt": 100 }
|
|
7868
|
-
- Nested fields are supported using dot notation
|
|
7869
|
-
- Array fields with nested objects use [] suffix: "items[]"
|
|
7870
|
-
- Geo filtering requires specific format for radius, box, or polygon
|
|
7871
|
-
- Datetime values must be in RFC 3339 format
|
|
7872
|
-
- Empty arrays in conditions are handled as empty values
|
|
7873
|
-
- Null values are handled with $null operator
|
|
7874
|
-
- Empty values are handled with $empty operator
|
|
7875
|
-
- $regex uses standard regex syntax
|
|
7876
|
-
- $count can only be used with numeric comparison operators
|
|
7877
|
-
- $nested requires an object with conditions
|
|
7878
|
-
- Logical operators must contain field conditions, not direct operators
|
|
7879
|
-
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7880
|
-
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
7881
|
-
- $not operator:
|
|
7882
|
-
- Must be an object
|
|
7883
|
-
- Cannot be empty
|
|
7884
|
-
- Can be used at field level or top level
|
|
7885
|
-
- Valid: { "$not": { "field": "value" } }
|
|
7886
|
-
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
7887
|
-
- Other logical operators ($and, $or):
|
|
7888
|
-
- Can only be used at top level or nested within other logical operators
|
|
7889
|
-
- Can not be used on a field level, or be nested inside a field
|
|
7890
|
-
- Can not be used inside an operator
|
|
7891
|
-
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7892
|
-
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
7893
|
-
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
7894
|
-
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
7895
|
-
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
7896
|
-
Example Complex Query:
|
|
7897
|
-
{
|
|
7898
|
-
"$and": [
|
|
7899
|
-
{ "category": { "$in": ["electronics"] } },
|
|
7900
|
-
{ "price": { "$gt": 100 } },
|
|
7901
|
-
{ "location": {
|
|
7902
|
-
"$geo": {
|
|
7903
|
-
"type": "radius",
|
|
7904
|
-
"center": { "lat": 52.5, "lon": 13.4 },
|
|
7905
|
-
"radius": 5000
|
|
7906
|
-
}
|
|
7907
|
-
}},
|
|
7908
|
-
{ "items[]": {
|
|
7909
|
-
"$nested": {
|
|
7910
|
-
"price": { "$gt": 50 },
|
|
7911
|
-
"stock": { "$gt": 0 }
|
|
7912
|
-
}
|
|
7913
|
-
}},
|
|
7914
|
-
{ "created_at": {
|
|
7915
|
-
"$datetime": {
|
|
7916
|
-
"range": {
|
|
7917
|
-
"gt": "2024-01-01T00:00:00Z"
|
|
7918
|
-
}
|
|
7919
|
-
}
|
|
7920
|
-
}},
|
|
7921
|
-
{ "$or": [
|
|
7922
|
-
{ "status": { "$ne": "discontinued" } },
|
|
7923
|
-
{ "clearance": true }
|
|
7924
|
-
]}
|
|
7925
|
-
]
|
|
7926
|
-
}`;
|
|
7927
|
-
var UPSTASH_PROMPT = `When querying Upstash Vector, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
7928
|
-
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
7929
|
-
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.
|
|
7930
|
-
|
|
7931
|
-
Basic Comparison Operators:
|
|
7932
|
-
- $eq: Exact match (default when using field: value)
|
|
7933
|
-
Example: { "category": "electronics" } or { "category": { "$eq": "electronics" } }
|
|
7934
|
-
- $ne: Not equal
|
|
7935
|
-
Example: { "category": { "$ne": "electronics" } }
|
|
7936
|
-
- $gt: Greater than
|
|
7937
|
-
Example: { "price": { "$gt": 100 } }
|
|
7938
|
-
- $gte: Greater than or equal
|
|
7939
|
-
Example: { "price": { "$gte": 100 } }
|
|
7940
|
-
- $lt: Less than
|
|
7941
|
-
Example: { "price": { "$lt": 100 } }
|
|
7942
|
-
- $lte: Less than or equal
|
|
7943
|
-
Example: { "price": { "$lte": 100 } }
|
|
7944
|
-
|
|
7945
|
-
Array Operators:
|
|
7946
|
-
- $in: Match any value in array
|
|
7947
|
-
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
7948
|
-
- $nin: Does not match any value in array
|
|
7949
|
-
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
7950
|
-
- $all: Matches all values in array
|
|
7951
|
-
Example: { "tags": { "$all": ["premium", "new"] } }
|
|
7952
|
-
|
|
7953
|
-
Logical Operators:
|
|
7954
|
-
- $and: Logical AND (implicit when using multiple conditions)
|
|
7955
|
-
Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
7956
|
-
- $or: Logical OR
|
|
7957
|
-
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7958
|
-
- $not: Logical NOT
|
|
7959
|
-
Example: { "$not": { "category": "electronics" } }
|
|
7960
|
-
- $nor: Logical NOR
|
|
7961
|
-
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
7962
|
-
|
|
7963
|
-
Element Operators:
|
|
7964
|
-
- $exists: Check if field exists
|
|
7965
|
-
Example: { "rating": { "$exists": true } }
|
|
7966
|
-
|
|
7967
|
-
Special Operators:
|
|
7968
|
-
- $regex: Pattern matching using glob syntax (only as operator, not direct RegExp)
|
|
7969
|
-
Example: { "name": { "$regex": "iphone*" } }
|
|
7970
|
-
- $contains: Check if array/string contains value
|
|
7971
|
-
Example: { "tags": { "$contains": "premium" } }
|
|
7972
|
-
|
|
7973
|
-
Restrictions:
|
|
7974
|
-
- Null/undefined values are not supported in any operator
|
|
7975
|
-
- Empty arrays are only supported in $in/$nin operators
|
|
7976
|
-
- Direct RegExp patterns are not supported, use $regex with glob syntax
|
|
7977
|
-
- Nested fields are supported using dot notation
|
|
7978
|
-
- Multiple conditions on same field are combined with AND
|
|
7979
|
-
- String values with quotes are automatically escaped
|
|
7980
|
-
- Only logical operators ($and, $or, $not, $nor) can be used at the top level
|
|
7981
|
-
- All other operators must be used within a field condition
|
|
7982
|
-
Valid: { "field": { "$gt": 100 } }
|
|
7983
|
-
Valid: { "$and": [...] }
|
|
7984
|
-
Invalid: { "$gt": 100 }
|
|
7985
|
-
- $regex uses glob syntax (*, ?) not standard regex patterns
|
|
7986
|
-
- $contains works on both arrays and string fields
|
|
7987
|
-
- Logical operators must contain field conditions, not direct operators
|
|
7988
|
-
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
7989
|
-
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
7990
|
-
- $not operator:
|
|
7991
|
-
- Must be an object
|
|
7992
|
-
- Cannot be empty
|
|
7993
|
-
- Can be used at field level or top level
|
|
7994
|
-
- Valid: { "$not": { "field": "value" } }
|
|
7995
|
-
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
7996
|
-
- Other logical operators ($and, $or, $nor):
|
|
7997
|
-
- Can only be used at top level or nested within other logical operators
|
|
7998
|
-
- Can not be used on a field level, or be nested inside a field
|
|
7999
|
-
- Can not be used inside an operator
|
|
8000
|
-
- Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
8001
|
-
- Valid: { "$or": [{ "$and": [{ "field": { "$gt": 100 } }] }] }
|
|
8002
|
-
- Invalid: { "field": { "$and": [{ "$gt": 100 }] } }
|
|
8003
|
-
- Invalid: { "field": { "$or": [{ "$gt": 100 }] } }
|
|
8004
|
-
- Invalid: { "field": { "$gt": { "$and": [{...}] } } }
|
|
8005
|
-
Example Complex Query:
|
|
8006
|
-
{
|
|
8007
|
-
"$and": [
|
|
8008
|
-
{ "category": { "$in": ["electronics", "computers"] } },
|
|
8009
|
-
{ "price": { "$gt": 100, "$lt": 1000 } },
|
|
8010
|
-
{ "tags": { "$all": ["premium", "new"] } },
|
|
8011
|
-
{ "name": { "$regex": "iphone*" } },
|
|
8012
|
-
{ "description": { "$contains": "latest" } },
|
|
8013
|
-
{ "$or": [
|
|
8014
|
-
{ "brand": "Apple" },
|
|
8015
|
-
{ "rating": { "$gte": 4.5 } }
|
|
8016
|
-
]}
|
|
8017
|
-
]
|
|
8018
|
-
}`;
|
|
8019
|
-
var VECTORIZE_PROMPT = `When querying Vectorize, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
8020
|
-
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
8021
|
-
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.
|
|
8022
|
-
|
|
8023
|
-
Basic Comparison Operators:
|
|
8024
|
-
- $eq: Exact match (default when using field: value)
|
|
8025
|
-
Example: { "category": "electronics" }
|
|
8026
|
-
- $ne: Not equal
|
|
8027
|
-
Example: { "category": { "$ne": "electronics" } }
|
|
8028
|
-
- $gt: Greater than
|
|
8029
|
-
Example: { "price": { "$gt": 100 } }
|
|
8030
|
-
- $gte: Greater than or equal
|
|
8031
|
-
Example: { "price": { "$gte": 100 } }
|
|
8032
|
-
- $lt: Less than
|
|
8033
|
-
Example: { "price": { "$lt": 100 } }
|
|
8034
|
-
- $lte: Less than or equal
|
|
8035
|
-
Example: { "price": { "$lte": 100 } }
|
|
8036
|
-
|
|
8037
|
-
Array Operators:
|
|
8038
|
-
- $in: Match any value in array
|
|
8039
|
-
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
8040
|
-
- $nin: Does not match any value in array
|
|
8041
|
-
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
8042
|
-
|
|
8043
|
-
Restrictions:
|
|
8044
|
-
- Regex patterns are not supported
|
|
8045
|
-
- Logical operators are not supported
|
|
8046
|
-
- Element operators are not supported
|
|
8047
|
-
- Fields must have a flat structure, as nested fields are not supported
|
|
8048
|
-
- Multiple conditions on the same field are supported
|
|
8049
|
-
- Empty arrays in $in/$nin will return no results
|
|
8050
|
-
- Filter keys cannot be longer than 512 characters
|
|
8051
|
-
- Filter keys cannot contain invalid characters ($, ", empty)
|
|
8052
|
-
- Filter size is limited to prevent oversized queries
|
|
8053
|
-
- Invalid types in operators return no results instead of throwing errors
|
|
8054
|
-
- Empty objects are accepted in filters
|
|
8055
|
-
- Metadata must use flat structure with dot notation (no nested objects)
|
|
8056
|
-
- Must explicitly create metadata indexes for filterable fields (limit 10 per index)
|
|
8057
|
-
- Can only effectively filter on indexed metadata fields
|
|
8058
|
-
- Metadata values can be strings, numbers, booleans, or homogeneous arrays
|
|
8059
|
-
- No operators can be used at the top level (no logical operators supported)
|
|
8060
|
-
- All operators must be used within a field condition
|
|
8061
|
-
Valid: { "field": { "$gt": 100 } }
|
|
8062
|
-
Invalid: { "$gt": 100 }
|
|
8063
|
-
Invalid: { "$in": [...] }
|
|
8064
|
-
|
|
8065
|
-
Example Complex Query:
|
|
8066
|
-
{
|
|
8067
|
-
"category": { "$in": ["electronics", "computers"] },
|
|
8068
|
-
"price": { "$gte": 100, "$lte": 1000 },
|
|
8069
|
-
"inStock": true
|
|
8070
|
-
}`;
|
|
8071
|
-
var MONGODB_PROMPT = `When querying MongoDB, you can ONLY use the operators listed below. Any other operators will be rejected.
|
|
8072
|
-
Important: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.
|
|
8073
|
-
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.
|
|
8074
|
-
|
|
8075
|
-
Basic Comparison Operators:
|
|
8076
|
-
- $eq: Exact match (default when using field: value)
|
|
8077
|
-
Example: { "category": "electronics" }
|
|
8078
|
-
- $ne: Not equal
|
|
8079
|
-
Example: { "category": { "$ne": "electronics" } }
|
|
8080
|
-
- $gt: Greater than
|
|
8081
|
-
Example: { "price": { "$gt": 100 } }
|
|
8082
|
-
- $gte: Greater than or equal
|
|
8083
|
-
Example: { "price": { "$gte": 100 } }
|
|
8084
|
-
- $lt: Less than
|
|
8085
|
-
Example: { "price": { "$lt": 100 } }
|
|
8086
|
-
- $lte: Less than or equal
|
|
8087
|
-
Example: { "price": { "$lte": 100 } }
|
|
8088
|
-
|
|
8089
|
-
Array Operators:
|
|
8090
|
-
- $in: Match any value in array
|
|
8091
|
-
Example: { "category": { "$in": ["electronics", "books"] } }
|
|
8092
|
-
- $nin: Does not match any value in array
|
|
8093
|
-
Example: { "category": { "$nin": ["electronics", "books"] } }
|
|
8094
|
-
- $all: Match all values in array
|
|
8095
|
-
Example: { "tags": { "$all": ["premium", "sale"] } }
|
|
8096
|
-
- $elemMatch: Match array elements by criteria
|
|
8097
|
-
Example: { "scores": { "$elemMatch": { "$gt": 80 } } }
|
|
8098
|
-
|
|
8099
|
-
Logical Operators:
|
|
8100
|
-
- $and: Logical AND (can be implicit or explicit)
|
|
8101
|
-
Implicit Example: { "price": { "$gt": 100 }, "category": "electronics" }
|
|
8102
|
-
Explicit Example: { "$and": [{ "price": { "$gt": 100 } }, { "category": "electronics" }] }
|
|
8103
|
-
- $or: Logical OR
|
|
8104
|
-
Example: { "$or": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
8105
|
-
- $not: Logical NOT
|
|
8106
|
-
Example: { "field": { "$not": { "$eq": "value" } } }
|
|
8107
|
-
- $nor: Logical NOR
|
|
8108
|
-
Example: { "$nor": [{ "price": { "$lt": 50 } }, { "category": "books" }] }
|
|
8109
|
-
|
|
8110
|
-
Element Operators:
|
|
8111
|
-
- $exists: Check if field exists
|
|
8112
|
-
Example: { "rating": { "$exists": true } }
|
|
8113
|
-
|
|
8114
|
-
Special Operators:
|
|
8115
|
-
- $regex: Regular expression match
|
|
8116
|
-
Example: { "title": { "$regex": "^laptop", "$options": "i" } }
|
|
8117
|
-
- $size: Array length check
|
|
8118
|
-
Example: { "tags": { "$size": 2 } }
|
|
8119
|
-
|
|
8120
|
-
Usage Notes:
|
|
8121
|
-
- You can use both 'filter' (for metadata fields) and 'documentFilter' (for document content fields).
|
|
8122
|
-
- Nested fields are supported using dot notation (e.g., "metadata.author.name").
|
|
8123
|
-
- Multiple conditions on the same field are supported with both implicit and explicit $and.
|
|
8124
|
-
- Empty arrays in $in/$nin will return no results.
|
|
8125
|
-
- All logical operators ($and, $or, $not, $nor) can be used at the top level or nested.
|
|
8126
|
-
- All other operators must be used within a field condition.
|
|
8127
|
-
Valid: { "field": { "$gt": 100 } }
|
|
8128
|
-
Valid: { "$and": [...] }
|
|
8129
|
-
Invalid: { "$gt": 100 }
|
|
8130
|
-
- $not operator:
|
|
8131
|
-
- Must be an object
|
|
8132
|
-
- Cannot be empty
|
|
8133
|
-
- Can be used at field level or top level
|
|
8134
|
-
- Valid: { "$not": { "field": "value" } }
|
|
8135
|
-
- Valid: { "field": { "$not": { "$eq": "value" } } }
|
|
8136
|
-
- Logical operators must contain field conditions, not direct operators
|
|
8137
|
-
Valid: { "$and": [{ "field": { "$gt": 100 } }] }
|
|
8138
|
-
Invalid: { "$and": [{ "$gt": 100 }] }
|
|
8139
|
-
- Regex uses standard MongoDB regex syntax (with optional $options).
|
|
8140
|
-
- Metadata values can be strings, numbers, booleans, or arrays.
|
|
8141
|
-
- Metadata and document fields can be filtered in the same query.
|
|
8142
|
-
|
|
8143
|
-
Example Complex Query:
|
|
8144
|
-
{
|
|
8145
|
-
"category": { "$in": ["electronics", "computers"] },
|
|
8146
|
-
"price": { "$gte": 100, "$lte": 1000 },
|
|
8147
|
-
"inStock": true,
|
|
8148
|
-
"title": { "$regex": "laptop", "$options": "i" },
|
|
8149
|
-
"$or": [
|
|
8150
|
-
{ "brand": "Apple" },
|
|
8151
|
-
{ "rating": { "$gte": 4.5 } }
|
|
8152
|
-
]
|
|
8153
|
-
}
|
|
8154
|
-
`;
|
|
8155
|
-
|
|
8156
|
-
exports.ASTRA_PROMPT = ASTRA_PROMPT;
|
|
8157
|
-
exports.CHROMA_PROMPT = CHROMA_PROMPT;
|
|
8158
7344
|
exports.CohereRelevanceScorer = CohereRelevanceScorer;
|
|
8159
7345
|
exports.GraphRAG = GraphRAG;
|
|
8160
|
-
exports.LIBSQL_PROMPT = LIBSQL_PROMPT;
|
|
8161
7346
|
exports.Language = Language;
|
|
8162
7347
|
exports.MDocument = MDocument;
|
|
8163
|
-
exports.MONGODB_PROMPT = MONGODB_PROMPT;
|
|
8164
7348
|
exports.MastraAgentRelevanceScorer = MastraAgentRelevanceScorer;
|
|
8165
|
-
exports.PGVECTOR_PROMPT = PGVECTOR_PROMPT;
|
|
8166
|
-
exports.PINECONE_PROMPT = PINECONE_PROMPT;
|
|
8167
|
-
exports.QDRANT_PROMPT = QDRANT_PROMPT;
|
|
8168
|
-
exports.UPSTASH_PROMPT = UPSTASH_PROMPT;
|
|
8169
|
-
exports.VECTORIZE_PROMPT = VECTORIZE_PROMPT;
|
|
8170
7349
|
exports.ZeroEntropyRelevanceScorer = ZeroEntropyRelevanceScorer;
|
|
8171
7350
|
exports.createDocumentChunkerTool = createDocumentChunkerTool;
|
|
8172
7351
|
exports.createGraphRAGTool = createGraphRAGTool;
|