@mastra/rag 0.1.20-alpha.0 → 0.1.20-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -7
- package/CHANGELOG.md +25 -0
- package/dist/_tsup-dts-rollup.d.cts +225 -86
- package/dist/_tsup-dts-rollup.d.ts +225 -86
- package/dist/index.cjs +417 -131
- package/dist/index.js +385 -99
- package/package.json +2 -3
- package/src/document/document.ts +6 -9
- package/src/document/extractors/base.ts +30 -0
- package/src/document/extractors/index.ts +1 -1
- package/src/document/extractors/keywords.test.ts +1 -1
- package/src/document/extractors/keywords.ts +7 -19
- package/src/document/extractors/questions.test.ts +1 -1
- package/src/document/extractors/questions.ts +7 -25
- package/src/document/extractors/summary.test.ts +1 -1
- package/src/document/extractors/summary.ts +7 -19
- package/src/document/extractors/title.test.ts +1 -1
- package/src/document/extractors/title.ts +7 -44
- package/src/document/extractors/types.ts +1 -1
- package/src/document/prompts/base.ts +77 -0
- package/src/document/prompts/format.ts +9 -0
- package/src/document/prompts/index.ts +15 -0
- package/src/document/prompts/prompt.ts +60 -0
- package/src/document/prompts/types.ts +29 -0
- package/src/document/schema/index.ts +3 -0
- package/src/document/schema/node.ts +187 -0
- package/src/document/schema/types.ts +40 -0
- package/src/document/transformers/html.ts +1 -1
- package/src/document/transformers/json.ts +1 -1
- package/src/document/transformers/markdown.ts +1 -1
- package/src/document/transformers/text.ts +1 -1
- package/src/document/transformers/transformer.ts +1 -1
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
import { BaseExtractor } from 'llamaindex';
|
|
2
|
-
import type { BaseNode } from 'llamaindex';
|
|
3
1
|
import { createTool } from '@mastra/core/tools';
|
|
4
|
-
import { Document } from 'llamaindex';
|
|
5
2
|
import type { EmbeddingModel } from 'ai';
|
|
6
|
-
import type { KeywordExtractPrompt } from 'llamaindex';
|
|
7
3
|
import type { MastraLanguageModel } from '@mastra/core/agent';
|
|
8
4
|
import type { MastraVector } from '@mastra/core/vector';
|
|
9
5
|
import type { QueryResult } from '@mastra/core/vector';
|
|
10
|
-
import type { QuestionExtractPrompt } from 'llamaindex';
|
|
11
|
-
import type { SummaryPrompt } from 'llamaindex';
|
|
12
6
|
import type { TiktokenEncoding } from 'js-tiktoken';
|
|
13
7
|
import type { TiktokenModel } from 'js-tiktoken';
|
|
14
|
-
import type { TitleCombinePrompt } from 'llamaindex';
|
|
15
|
-
import type { TitleExtractorPrompt } from 'llamaindex';
|
|
16
8
|
import type { VectorFilter } from '@mastra/core/vector/filter';
|
|
17
9
|
|
|
18
10
|
/**
|
|
@@ -23,9 +15,66 @@ declare const ASTRA_PROMPT = "When querying Astra, you can ONLY use the operator
|
|
|
23
15
|
export { ASTRA_PROMPT }
|
|
24
16
|
export { ASTRA_PROMPT as ASTRA_PROMPT_alias_1 }
|
|
25
17
|
|
|
26
|
-
declare
|
|
27
|
-
|
|
28
|
-
|
|
18
|
+
export declare abstract class BaseExtractor {
|
|
19
|
+
isTextNodeOnly: boolean;
|
|
20
|
+
abstract extract(nodes: BaseNode[]): Promise<Record<string, any>[]>;
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param nodes Nodes to extract metadata from.
|
|
24
|
+
* @returns Metadata extracted from the nodes.
|
|
25
|
+
*/
|
|
26
|
+
processNodes(nodes: BaseNode[]): Promise<BaseNode[]>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export declare const baseLLM: MastraLanguageModel;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Generic abstract class for retrievable nodes
|
|
33
|
+
*/
|
|
34
|
+
declare abstract class BaseNode<T extends Metadata = Metadata> {
|
|
35
|
+
id_: string;
|
|
36
|
+
metadata: T;
|
|
37
|
+
relationships: Partial<Record<NodeRelationship, RelatedNodeType<T>>>;
|
|
38
|
+
accessor hash: string;
|
|
39
|
+
protected constructor(init?: BaseNodeParams<T>);
|
|
40
|
+
abstract get type(): ObjectType;
|
|
41
|
+
abstract getContent(): string;
|
|
42
|
+
abstract getMetadataStr(): string;
|
|
43
|
+
get sourceNode(): RelatedNodeInfo<T> | undefined;
|
|
44
|
+
get prevNode(): RelatedNodeInfo<T> | undefined;
|
|
45
|
+
get nextNode(): RelatedNodeInfo<T> | undefined;
|
|
46
|
+
get parentNode(): RelatedNodeInfo<T> | undefined;
|
|
47
|
+
get childNodes(): RelatedNodeInfo<T>[] | undefined;
|
|
48
|
+
abstract generateHash(): string;
|
|
49
|
+
}
|
|
50
|
+
export { BaseNode }
|
|
51
|
+
export { BaseNode as BaseNode_alias_1 }
|
|
52
|
+
|
|
53
|
+
declare type BaseNodeParams<T extends Metadata = Metadata> = {
|
|
54
|
+
id_?: string | undefined;
|
|
55
|
+
metadata?: T | undefined;
|
|
56
|
+
relationships?: Partial<Record<NodeRelationship, RelatedNodeType<T>>> | undefined;
|
|
57
|
+
hash?: string | undefined;
|
|
58
|
+
};
|
|
59
|
+
export { BaseNodeParams }
|
|
60
|
+
export { BaseNodeParams as BaseNodeParams_alias_1 }
|
|
61
|
+
|
|
62
|
+
declare abstract class BasePromptTemplate<const TemplatesVar extends readonly string[] = string[]> {
|
|
63
|
+
templateVars: Set<string>;
|
|
64
|
+
options: Partial<Record<TemplatesVar[number] | (string & {}), string>>;
|
|
65
|
+
protected constructor(options: BasePromptTemplateOptions<TemplatesVar>);
|
|
66
|
+
abstract partialFormat(options: Partial<Record<TemplatesVar[number] | (string & {}), string>>): BasePromptTemplate<TemplatesVar>;
|
|
67
|
+
abstract format(options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>): string;
|
|
68
|
+
abstract formatMessages(options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>): ChatMessage[];
|
|
69
|
+
abstract get template(): string;
|
|
70
|
+
}
|
|
71
|
+
export { BasePromptTemplate }
|
|
72
|
+
export { BasePromptTemplate as BasePromptTemplate_alias_1 }
|
|
73
|
+
|
|
74
|
+
export declare type BasePromptTemplateOptions<TemplatesVar extends readonly string[]> = {
|
|
75
|
+
templateVars?: TemplatesVar | readonly string[];
|
|
76
|
+
options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>;
|
|
77
|
+
};
|
|
29
78
|
|
|
30
79
|
export declare class CharacterTransformer extends TextTransformer {
|
|
31
80
|
protected separator: string;
|
|
@@ -48,6 +97,12 @@ export declare class CharacterTransformer extends TextTransformer {
|
|
|
48
97
|
private __splitChunk;
|
|
49
98
|
}
|
|
50
99
|
|
|
100
|
+
export declare type ChatMessage<AdditionalMessageOptions extends object = object> = {
|
|
101
|
+
content: MessageContent;
|
|
102
|
+
role: MessageType;
|
|
103
|
+
options?: undefined | AdditionalMessageOptions;
|
|
104
|
+
};
|
|
105
|
+
|
|
51
106
|
declare const CHROMA_PROMPT = "When querying Chroma, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nRestrictions:\n- Regex patterns are not supported\n- Element operators are not supported\n- Only $and and $or logical operators are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Empty arrays in $in/$nin will return no results\n- If multiple top-level fields exist, they're wrapped in $and\n- Only logical operators ($and, $or) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$in\": [...] }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- Logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"$or\": [\n { \"inStock\": true },\n { \"preorder\": true }\n ]}\n ]\n}";
|
|
52
107
|
export { CHROMA_PROMPT }
|
|
53
108
|
export { CHROMA_PROMPT as CHROMA_PROMPT_alias_1 }
|
|
@@ -134,11 +189,41 @@ export { defaultGraphRagDescription }
|
|
|
134
189
|
export { defaultGraphRagDescription as defaultGraphRagDescription_alias_1 }
|
|
135
190
|
export { defaultGraphRagDescription as defaultGraphRagDescription_alias_2 }
|
|
136
191
|
|
|
192
|
+
declare const defaultKeywordExtractPrompt: KeywordExtractPrompt;
|
|
193
|
+
export { defaultKeywordExtractPrompt }
|
|
194
|
+
export { defaultKeywordExtractPrompt as defaultKeywordExtractPrompt_alias_1 }
|
|
195
|
+
|
|
196
|
+
declare const defaultQuestionExtractPrompt: PromptTemplate<readonly ["numQuestions", "context"]>;
|
|
197
|
+
export { defaultQuestionExtractPrompt }
|
|
198
|
+
export { defaultQuestionExtractPrompt as defaultQuestionExtractPrompt_alias_1 }
|
|
199
|
+
|
|
200
|
+
declare const defaultSummaryPrompt: SummaryPrompt;
|
|
201
|
+
export { defaultSummaryPrompt }
|
|
202
|
+
export { defaultSummaryPrompt as defaultSummaryPrompt_alias_1 }
|
|
203
|
+
|
|
204
|
+
declare const defaultTitleCombinePromptTemplate: PromptTemplate<readonly ["context"]>;
|
|
205
|
+
export { defaultTitleCombinePromptTemplate }
|
|
206
|
+
export { defaultTitleCombinePromptTemplate as defaultTitleCombinePromptTemplate_alias_1 }
|
|
207
|
+
|
|
208
|
+
declare const defaultTitleExtractorPromptTemplate: PromptTemplate<readonly ["context"]>;
|
|
209
|
+
export { defaultTitleExtractorPromptTemplate }
|
|
210
|
+
export { defaultTitleExtractorPromptTemplate as defaultTitleExtractorPromptTemplate_alias_1 }
|
|
211
|
+
|
|
137
212
|
declare const defaultVectorQueryDescription: () => string;
|
|
138
213
|
export { defaultVectorQueryDescription }
|
|
139
214
|
export { defaultVectorQueryDescription as defaultVectorQueryDescription_alias_1 }
|
|
140
215
|
export { defaultVectorQueryDescription as defaultVectorQueryDescription_alias_2 }
|
|
141
216
|
|
|
217
|
+
/**
|
|
218
|
+
* A document is just a special text node with a docId.
|
|
219
|
+
*/
|
|
220
|
+
declare class Document<T extends Metadata = Metadata> extends TextNode<T> {
|
|
221
|
+
constructor(init?: TextNodeParams<T>);
|
|
222
|
+
get type(): ObjectType;
|
|
223
|
+
}
|
|
224
|
+
export { Document }
|
|
225
|
+
export { Document as Document_alias_1 }
|
|
226
|
+
|
|
142
227
|
declare type ExtractKeyword = {
|
|
143
228
|
/**
|
|
144
229
|
* Comma-separated keywords extracted from the node. May be empty if extraction fails.
|
|
@@ -177,6 +262,14 @@ export { filterDescription }
|
|
|
177
262
|
export { filterDescription as filterDescription_alias_1 }
|
|
178
263
|
export { filterDescription as filterDescription_alias_2 }
|
|
179
264
|
|
|
265
|
+
/**
|
|
266
|
+
* Formats a string by replacing placeholders with values from the provided parameters.
|
|
267
|
+
* @param str The string to format.
|
|
268
|
+
* @param params A record of placeholder names to their corresponding values.
|
|
269
|
+
* @returns The formatted string.
|
|
270
|
+
*/
|
|
271
|
+
export declare function format(str: string, params: Record<string, string>): string;
|
|
272
|
+
|
|
180
273
|
export declare interface GraphChunk {
|
|
181
274
|
text: string;
|
|
182
275
|
metadata: Record<string, any>;
|
|
@@ -266,21 +359,8 @@ export { KeywordExtractArgs as KeywordExtractArgs_alias_1 }
|
|
|
266
359
|
* Extract keywords from a list of nodes.
|
|
267
360
|
*/
|
|
268
361
|
declare class KeywordExtractor extends BaseExtractor {
|
|
269
|
-
/**
|
|
270
|
-
* MastraLanguageModel instance.
|
|
271
|
-
* @type {MastraLanguageModel}
|
|
272
|
-
*/
|
|
273
362
|
llm: MastraLanguageModel;
|
|
274
|
-
/**
|
|
275
|
-
* Number of keywords to extract.
|
|
276
|
-
* @type {number}
|
|
277
|
-
* @default 5
|
|
278
|
-
*/
|
|
279
363
|
keywords: number;
|
|
280
|
-
/**
|
|
281
|
-
* The prompt template to use for the question extractor.
|
|
282
|
-
* @type {string}
|
|
283
|
-
*/
|
|
284
364
|
promptTemplate: KeywordExtractPrompt;
|
|
285
365
|
/**
|
|
286
366
|
* Constructor for the KeywordExtractor class.
|
|
@@ -315,6 +395,10 @@ declare class KeywordExtractor extends BaseExtractor {
|
|
|
315
395
|
export { KeywordExtractor }
|
|
316
396
|
export { KeywordExtractor as KeywordExtractor_alias_1 }
|
|
317
397
|
|
|
398
|
+
declare type KeywordExtractPrompt = PromptTemplate<['context', 'maxKeywords']>;
|
|
399
|
+
export { KeywordExtractPrompt }
|
|
400
|
+
export { KeywordExtractPrompt as KeywordExtractPrompt_alias_1 }
|
|
401
|
+
|
|
318
402
|
declare enum Language {
|
|
319
403
|
CPP = "cpp",
|
|
320
404
|
GO = "go",
|
|
@@ -418,6 +502,42 @@ export { MDocument }
|
|
|
418
502
|
export { MDocument as MDocument_alias_1 }
|
|
419
503
|
export { MDocument as MDocument_alias_2 }
|
|
420
504
|
|
|
505
|
+
/**
|
|
506
|
+
* Extended type for the content of a message that allows for multi-modal messages.
|
|
507
|
+
*/
|
|
508
|
+
export declare type MessageContent = string | MessageContentTextDetail[];
|
|
509
|
+
|
|
510
|
+
export declare type MessageContentTextDetail = {
|
|
511
|
+
type: 'text';
|
|
512
|
+
text: string;
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
export declare type MessageType = 'user' | 'assistant' | 'system' | 'memory' | 'developer';
|
|
516
|
+
|
|
517
|
+
declare type Metadata = Record<string, any>;
|
|
518
|
+
export { Metadata }
|
|
519
|
+
export { Metadata as Metadata_alias_1 }
|
|
520
|
+
|
|
521
|
+
declare enum NodeRelationship {
|
|
522
|
+
SOURCE = "SOURCE",
|
|
523
|
+
PREVIOUS = "PREVIOUS",
|
|
524
|
+
NEXT = "NEXT",
|
|
525
|
+
PARENT = "PARENT",
|
|
526
|
+
CHILD = "CHILD"
|
|
527
|
+
}
|
|
528
|
+
export { NodeRelationship }
|
|
529
|
+
export { NodeRelationship as NodeRelationship_alias_1 }
|
|
530
|
+
|
|
531
|
+
declare enum ObjectType {
|
|
532
|
+
TEXT = "TEXT",
|
|
533
|
+
IMAGE = "IMAGE",
|
|
534
|
+
INDEX = "INDEX",
|
|
535
|
+
DOCUMENT = "DOCUMENT",
|
|
536
|
+
IMAGE_DOCUMENT = "IMAGE_DOCUMENT"
|
|
537
|
+
}
|
|
538
|
+
export { ObjectType }
|
|
539
|
+
export { ObjectType as ObjectType_alias_1 }
|
|
540
|
+
|
|
421
541
|
declare const PGVECTOR_PROMPT = "When querying PG Vector, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n- $all: Match all values in array\n Example: { \"tags\": { \"$all\": [\"premium\", \"sale\"] } }\n- $elemMatch: Match array elements that meet all specified conditions\n Example: { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 100 } } } }\n- $contains: Check if array contains value\n Example: { \"tags\": { \"$contains\": \"premium\" } }\n\nLogical Operators:\n- $and: Logical AND\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n- $nor: Logical NOR\n Example: { \"$nor\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $size: Array length check\n Example: { \"tags\": { \"$size\": 2 } }\n- $regex: Pattern matching (PostgreSQL regex syntax)\n Example: { \"name\": { \"$regex\": \"^iphone\" } }\n- $options: Regex options (used with $regex)\n Example: { \"name\": { \"$regex\": \"iphone\", \"$options\": \"i\" } }\n\nRestrictions:\n- Direct RegExp patterns are supported\n- Nested fields are supported using dot notation\n- Multiple conditions on the same field are supported with both implicit and explicit $and\n- Array operations work on array fields only\n- Regex patterns must follow PostgreSQL syntax\n- Empty arrays in conditions are handled gracefully\n- Only logical operators ($and, $or, $not, $nor) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Invalid: { \"$gt\": 100 }\n Invalid: { \"$regex\": \"pattern\" }\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other logical operators ($and, $or, $nor):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\n- $elemMatch requires an object with conditions\n Valid: { \"array\": { \"$elemMatch\": { \"field\": \"value\" } } }\n Invalid: { \"array\": { \"$elemMatch\": \"value\" } }\n\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\", \"computers\"] } },\n { \"price\": { \"$gte\": 100, \"$lte\": 1000 } },\n { \"tags\": { \"$all\": [\"premium\", \"sale\"] } },\n { \"items\": { \"$elemMatch\": { \"price\": { \"$gt\": 50 }, \"inStock\": true } } },\n { \"$or\": [\n { \"name\": { \"$regex\": \"^iphone\", \"$options\": \"i\" } },\n { \"description\": { \"$regex\": \".*apple.*\" } }\n ]}\n ]\n}";
|
|
422
542
|
export { PGVECTOR_PROMPT }
|
|
423
543
|
export { PGVECTOR_PROMPT as PGVECTOR_PROMPT_alias_1 }
|
|
@@ -426,6 +546,21 @@ declare const PINECONE_PROMPT = "When querying Pinecone, you can ONLY use the op
|
|
|
426
546
|
export { PINECONE_PROMPT }
|
|
427
547
|
export { PINECONE_PROMPT as PINECONE_PROMPT_alias_1 }
|
|
428
548
|
|
|
549
|
+
declare class PromptTemplate<const TemplatesVar extends readonly string[] = string[]> extends BasePromptTemplate<TemplatesVar> {
|
|
550
|
+
#private;
|
|
551
|
+
constructor(options: PromptTemplateOptions<TemplatesVar>);
|
|
552
|
+
partialFormat(options: Partial<Record<TemplatesVar[number] | (string & {}), string>>): PromptTemplate<TemplatesVar>;
|
|
553
|
+
format(options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>): string;
|
|
554
|
+
formatMessages(options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>): ChatMessage[];
|
|
555
|
+
get template(): string;
|
|
556
|
+
}
|
|
557
|
+
export { PromptTemplate }
|
|
558
|
+
export { PromptTemplate as PromptTemplate_alias_1 }
|
|
559
|
+
|
|
560
|
+
export declare type PromptTemplateOptions<TemplatesVar extends readonly string[]> = BasePromptTemplateOptions<TemplatesVar> & {
|
|
561
|
+
template: string;
|
|
562
|
+
};
|
|
563
|
+
|
|
429
564
|
declare const QDRANT_PROMPT = "When querying Qdrant, you can ONLY use the operators listed below. Any other operators will be rejected.\nImportant: Don't explain how to construct the filter - use the specified operators and fields to search the content and return relevant results.\nIf a user tries to give an explicit operator that is not supported, reject the filter entirely and let them know that the operator is not supported.\n\nBasic Comparison Operators:\n- $eq: Exact match (default when using field: value)\n Example: { \"category\": \"electronics\" }\n- $ne: Not equal\n Example: { \"category\": { \"$ne\": \"electronics\" } }\n- $gt: Greater than\n Example: { \"price\": { \"$gt\": 100 } }\n- $gte: Greater than or equal\n Example: { \"price\": { \"$gte\": 100 } }\n- $lt: Less than\n Example: { \"price\": { \"$lt\": 100 } }\n- $lte: Less than or equal\n Example: { \"price\": { \"$lte\": 100 } }\n\nArray Operators:\n- $in: Match any value in array\n Example: { \"category\": { \"$in\": [\"electronics\", \"books\"] } }\n- $nin: Does not match any value in array\n Example: { \"category\": { \"$nin\": [\"electronics\", \"books\"] } }\n\nLogical Operators:\n- $and: Logical AND (implicit when using multiple conditions)\n Example: { \"$and\": [{ \"price\": { \"$gt\": 100 } }, { \"category\": \"electronics\" }] }\n- $or: Logical OR\n Example: { \"$or\": [{ \"price\": { \"$lt\": 50 } }, { \"category\": \"books\" }] }\n- $not: Logical NOT\n Example: { \"$not\": { \"category\": \"electronics\" } }\n\nElement Operators:\n- $exists: Check if field exists\n Example: { \"rating\": { \"$exists\": true } }\n\nSpecial Operators:\n- $regex: Pattern matching\n Example: { \"name\": { \"$regex\": \"iphone.*\" } }\n- $count: Array length/value count\n Example: { \"tags\": { \"$count\": { \"$gt\": 2 } } }\n- $geo: Geographical filters (supports radius, box, polygon)\n Example: {\n \"location\": {\n \"$geo\": {\n \"type\": \"radius\",\n \"center\": { \"lat\": 52.5, \"lon\": 13.4 },\n \"radius\": 10000\n }\n }\n }\n- $hasId: Match specific document IDs\n Example: { \"$hasId\": [\"doc1\", \"doc2\"] }\n- $hasVector: Check vector existence\n Example: { \"$hasVector\": \"\" }\n- $datetime: RFC 3339 datetime range\n Example: {\n \"created_at\": {\n \"$datetime\": {\n \"range\": {\n \"gt\": \"2024-01-01T00:00:00Z\",\n \"lt\": \"2024-12-31T23:59:59Z\"\n }\n }\n }\n }\n- $null: Check for null values\n Example: { \"field\": { \"$null\": true } }\n- $empty: Check for empty values\n Example: { \"array\": { \"$empty\": true } }\n- $nested: Nested object filters\n Example: {\n \"items[]\": {\n \"$nested\": {\n \"price\": { \"$gt\": 100 },\n \"stock\": { \"$gt\": 0 }\n }\n }\n }\n\nRestrictions:\n- Only logical operators ($and, $or, $not) and collection operators ($hasId, $hasVector) can be used at the top level\n- All other operators must be used within a field condition\n Valid: { \"field\": { \"$gt\": 100 } }\n Valid: { \"$and\": [...] }\n Valid: { \"$hasId\": [...] }\n Invalid: { \"$gt\": 100 }\n- Nested fields are supported using dot notation\n- Array fields with nested objects use [] suffix: \"items[]\"\n- Geo filtering requires specific format for radius, box, or polygon\n- Datetime values must be in RFC 3339 format\n- Empty arrays in conditions are handled as empty values\n- Null values are handled with $null operator\n- Empty values are handled with $empty operator\n- $regex uses standard regex syntax\n- $count can only be used with numeric comparison operators\n- $nested requires an object with conditions\n- Logical operators must contain field conditions, not direct operators\n Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n Invalid: { \"$and\": [{ \"$gt\": 100 }] }\n- $not operator:\n - Must be an object\n - Cannot be empty\n - Can be used at field level or top level\n - Valid: { \"$not\": { \"field\": \"value\" } }\n - Valid: { \"field\": { \"$not\": { \"$eq\": \"value\" } } }\n- Other logical operators ($and, $or):\n - Can only be used at top level or nested within other logical operators\n - Can not be used on a field level, or be nested inside a field\n - Can not be used inside an operator\n - Valid: { \"$and\": [{ \"field\": { \"$gt\": 100 } }] }\n - Valid: { \"$or\": [{ \"$and\": [{ \"field\": { \"$gt\": 100 } }] }] }\n - Invalid: { \"field\": { \"$and\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$or\": [{ \"$gt\": 100 }] } }\n - Invalid: { \"field\": { \"$gt\": { \"$and\": [{...}] } } }\nExample Complex Query:\n{\n \"$and\": [\n { \"category\": { \"$in\": [\"electronics\"] } },\n { \"price\": { \"$gt\": 100 } },\n { \"location\": {\n \"$geo\": {\n \"type\": \"radius\",\n \"center\": { \"lat\": 52.5, \"lon\": 13.4 },\n \"radius\": 5000\n }\n }},\n { \"items[]\": {\n \"$nested\": {\n \"price\": { \"$gt\": 50 },\n \"stock\": { \"$gt\": 0 }\n }\n }},\n { \"created_at\": {\n \"$datetime\": {\n \"range\": {\n \"gt\": \"2024-01-01T00:00:00Z\"\n }\n }\n }},\n { \"$or\": [\n { \"status\": { \"$ne\": \"discontinued\" } },\n { \"clearance\": true }\n ]}\n ]\n}";
|
|
430
565
|
export { QDRANT_PROMPT }
|
|
431
566
|
export { QDRANT_PROMPT as QDRANT_PROMPT_alias_1 }
|
|
@@ -444,31 +579,17 @@ declare type QuestionAnswerExtractArgs = {
|
|
|
444
579
|
export { QuestionAnswerExtractArgs }
|
|
445
580
|
export { QuestionAnswerExtractArgs as QuestionAnswerExtractArgs_alias_1 }
|
|
446
581
|
|
|
582
|
+
declare type QuestionExtractPrompt = PromptTemplate<['context', 'numQuestions']>;
|
|
583
|
+
export { QuestionExtractPrompt }
|
|
584
|
+
export { QuestionExtractPrompt as QuestionExtractPrompt_alias_1 }
|
|
585
|
+
|
|
447
586
|
/**
|
|
448
587
|
* Extract questions from a list of nodes.
|
|
449
588
|
*/
|
|
450
589
|
declare class QuestionsAnsweredExtractor extends BaseExtractor {
|
|
451
|
-
/**
|
|
452
|
-
* MastraLanguageModel instance.
|
|
453
|
-
* @type {MastraLanguageModel}
|
|
454
|
-
*/
|
|
455
590
|
llm: MastraLanguageModel;
|
|
456
|
-
/**
|
|
457
|
-
* Number of questions to generate.
|
|
458
|
-
* @type {number}
|
|
459
|
-
* @default 5
|
|
460
|
-
*/
|
|
461
591
|
questions: number;
|
|
462
|
-
/**
|
|
463
|
-
* The prompt template to use for the question extractor.
|
|
464
|
-
* @type {string}
|
|
465
|
-
*/
|
|
466
592
|
promptTemplate: QuestionExtractPrompt;
|
|
467
|
-
/**
|
|
468
|
-
* Wheter to use metadata for embeddings only
|
|
469
|
-
* @type {boolean}
|
|
470
|
-
* @default false
|
|
471
|
-
*/
|
|
472
593
|
embeddingOnly: boolean;
|
|
473
594
|
/**
|
|
474
595
|
* Constructor for the QuestionsAnsweredExtractor class.
|
|
@@ -611,6 +732,19 @@ export declare class RecursiveJsonTransformer {
|
|
|
611
732
|
}): Document[];
|
|
612
733
|
}
|
|
613
734
|
|
|
735
|
+
declare interface RelatedNodeInfo<T extends Metadata = Metadata> {
|
|
736
|
+
nodeId: string;
|
|
737
|
+
nodeType?: ObjectType;
|
|
738
|
+
metadata: T;
|
|
739
|
+
hash?: string;
|
|
740
|
+
}
|
|
741
|
+
export { RelatedNodeInfo }
|
|
742
|
+
export { RelatedNodeInfo as RelatedNodeInfo_alias_1 }
|
|
743
|
+
|
|
744
|
+
declare type RelatedNodeType<T extends Metadata = Metadata> = RelatedNodeInfo<T> | RelatedNodeInfo<T>[];
|
|
745
|
+
export { RelatedNodeType }
|
|
746
|
+
export { RelatedNodeType as RelatedNodeType_alias_1 }
|
|
747
|
+
|
|
614
748
|
declare function rerank(results: QueryResult[], query: string, model: MastraLanguageModel, options: RerankerFunctionOptions): Promise<RerankResult[]>;
|
|
615
749
|
export { rerank }
|
|
616
750
|
export { rerank as rerank_alias_1 }
|
|
@@ -660,9 +794,7 @@ export declare function splitTextOnTokens({ text, tokenizer }: {
|
|
|
660
794
|
tokenizer: Tokenizer;
|
|
661
795
|
}): string[];
|
|
662
796
|
|
|
663
|
-
declare const STRIP_REGEX: RegExp;
|
|
664
|
-
export { STRIP_REGEX }
|
|
665
|
-
export { STRIP_REGEX as STRIP_REGEX_alias_1 }
|
|
797
|
+
export declare const STRIP_REGEX: RegExp;
|
|
666
798
|
|
|
667
799
|
declare type SummaryExtractArgs = {
|
|
668
800
|
llm?: MastraLanguageModel;
|
|
@@ -680,20 +812,8 @@ export { SummaryExtractArgs as SummaryExtractArgs_alias_1 }
|
|
|
680
812
|
* @returns Array of summary results
|
|
681
813
|
*/
|
|
682
814
|
declare class SummaryExtractor extends BaseExtractor {
|
|
683
|
-
/**
|
|
684
|
-
* MastraLanguageModel instance.
|
|
685
|
-
* @type {MastraLanguageModel}
|
|
686
|
-
*/
|
|
687
815
|
private llm;
|
|
688
|
-
/**
|
|
689
|
-
* List of summaries to extract: 'self', 'prev', 'next'
|
|
690
|
-
* @type {string[]}
|
|
691
|
-
*/
|
|
692
816
|
summaries: string[];
|
|
693
|
-
/**
|
|
694
|
-
* The prompt template to use for the summary extractor.
|
|
695
|
-
* @type {string}
|
|
696
|
-
*/
|
|
697
817
|
promptTemplate: SummaryPrompt;
|
|
698
818
|
private selfSummary;
|
|
699
819
|
private prevSummary;
|
|
@@ -715,6 +835,10 @@ declare class SummaryExtractor extends BaseExtractor {
|
|
|
715
835
|
export { SummaryExtractor }
|
|
716
836
|
export { SummaryExtractor as SummaryExtractor_alias_1 }
|
|
717
837
|
|
|
838
|
+
declare type SummaryPrompt = PromptTemplate<['context']>;
|
|
839
|
+
export { SummaryPrompt }
|
|
840
|
+
export { SummaryPrompt as SummaryPrompt_alias_1 }
|
|
841
|
+
|
|
718
842
|
/**
|
|
719
843
|
* TODO: GraphRAG Enhancements
|
|
720
844
|
* - Add support for more edge types (sequential, hierarchical, citation, etc)
|
|
@@ -724,6 +848,42 @@ export { SummaryExtractor as SummaryExtractor_alias_1 }
|
|
|
724
848
|
*/
|
|
725
849
|
declare type SupportedEdgeType = 'semantic';
|
|
726
850
|
|
|
851
|
+
/**
|
|
852
|
+
* TextNode is the default node type for text.
|
|
853
|
+
*/
|
|
854
|
+
declare class TextNode<T extends Metadata = Metadata> extends BaseNode<T> {
|
|
855
|
+
text: string;
|
|
856
|
+
startCharIdx?: number;
|
|
857
|
+
endCharIdx?: number;
|
|
858
|
+
metadataSeparator: string;
|
|
859
|
+
constructor(init?: TextNodeParams<T>);
|
|
860
|
+
/**
|
|
861
|
+
* Generate a hash of the text node.
|
|
862
|
+
* The ID is not part of the hash as it can change independent of content.
|
|
863
|
+
* @returns
|
|
864
|
+
*/
|
|
865
|
+
generateHash(): string;
|
|
866
|
+
get type(): ObjectType;
|
|
867
|
+
getContent(): string;
|
|
868
|
+
getMetadataStr(): string;
|
|
869
|
+
getNodeInfo(): {
|
|
870
|
+
start: number | undefined;
|
|
871
|
+
end: number | undefined;
|
|
872
|
+
};
|
|
873
|
+
getText(): string;
|
|
874
|
+
}
|
|
875
|
+
export { TextNode }
|
|
876
|
+
export { TextNode as TextNode_alias_1 }
|
|
877
|
+
|
|
878
|
+
declare type TextNodeParams<T extends Metadata = Metadata> = BaseNodeParams<T> & {
|
|
879
|
+
text?: string | undefined;
|
|
880
|
+
startCharIdx?: number | undefined;
|
|
881
|
+
endCharIdx?: number | undefined;
|
|
882
|
+
metadataSeparator?: string | undefined;
|
|
883
|
+
};
|
|
884
|
+
export { TextNodeParams }
|
|
885
|
+
export { TextNodeParams as TextNodeParams_alias_1 }
|
|
886
|
+
|
|
727
887
|
export declare abstract class TextTransformer implements Transformer {
|
|
728
888
|
protected size: number;
|
|
729
889
|
protected overlap: number;
|
|
@@ -743,44 +903,19 @@ export declare abstract class TextTransformer implements Transformer {
|
|
|
743
903
|
protected mergeSplits(splits: string[], separator: string): string[];
|
|
744
904
|
}
|
|
745
905
|
|
|
906
|
+
declare type TitleCombinePrompt = PromptTemplate<['context']>;
|
|
907
|
+
export { TitleCombinePrompt }
|
|
908
|
+
export { TitleCombinePrompt as TitleCombinePrompt_alias_1 }
|
|
909
|
+
|
|
746
910
|
/**
|
|
747
911
|
* Extract title from a list of nodes.
|
|
748
912
|
*/
|
|
749
913
|
declare class TitleExtractor extends BaseExtractor {
|
|
750
|
-
/**
|
|
751
|
-
* MastraLanguageModel instance.
|
|
752
|
-
* @type {MastraLanguageModel}
|
|
753
|
-
*/
|
|
754
914
|
llm: MastraLanguageModel;
|
|
755
|
-
/**
|
|
756
|
-
* Can work for mixture of text and non-text nodes
|
|
757
|
-
* @type {boolean}
|
|
758
|
-
* @default false
|
|
759
|
-
*/
|
|
760
915
|
isTextNodeOnly: boolean;
|
|
761
|
-
/**
|
|
762
|
-
* Number of nodes to extrct titles from.
|
|
763
|
-
* @type {number}
|
|
764
|
-
* @default 5
|
|
765
|
-
*/
|
|
766
916
|
nodes: number;
|
|
767
|
-
/**
|
|
768
|
-
* The prompt template to use for the title extractor.
|
|
769
|
-
* @type {string}
|
|
770
|
-
*/
|
|
771
917
|
nodeTemplate: TitleExtractorPrompt;
|
|
772
|
-
/**
|
|
773
|
-
* The prompt template to merge title with..
|
|
774
|
-
* @type {string}
|
|
775
|
-
*/
|
|
776
918
|
combineTemplate: TitleCombinePrompt;
|
|
777
|
-
/**
|
|
778
|
-
* Constructor for the TitleExtractor class.
|
|
779
|
-
* @param {MastraLanguageModel} llm MastraLanguageModel instance.
|
|
780
|
-
* @param {number} nodes Number of nodes to extract titles from.
|
|
781
|
-
* @param {TitleExtractorPrompt} nodeTemplate The prompt template to use for the title extractor.
|
|
782
|
-
* @param {string} combineTemplate The prompt template to merge title with..
|
|
783
|
-
*/
|
|
784
919
|
constructor(options?: TitleExtractorsArgs);
|
|
785
920
|
/**
|
|
786
921
|
* Extract titles from a list of nodes.
|
|
@@ -796,6 +931,10 @@ declare class TitleExtractor extends BaseExtractor {
|
|
|
796
931
|
export { TitleExtractor }
|
|
797
932
|
export { TitleExtractor as TitleExtractor_alias_1 }
|
|
798
933
|
|
|
934
|
+
declare type TitleExtractorPrompt = PromptTemplate<['context']>;
|
|
935
|
+
export { TitleExtractorPrompt }
|
|
936
|
+
export { TitleExtractorPrompt as TitleExtractorPrompt_alias_1 }
|
|
937
|
+
|
|
799
938
|
declare type TitleExtractorsArgs = {
|
|
800
939
|
llm?: MastraLanguageModel;
|
|
801
940
|
nodes?: number;
|