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