@mastra/rag 1.0.5 → 1.0.6
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 +2 -21
- package/CHANGELOG.md +25 -0
- package/dist/document/document.d.ts +32 -0
- package/dist/document/document.d.ts.map +1 -0
- package/dist/document/extractors/base.d.ts +12 -0
- package/dist/document/extractors/base.d.ts.map +1 -0
- package/dist/document/extractors/index.d.ts +6 -0
- package/dist/document/extractors/index.d.ts.map +1 -0
- package/dist/document/extractors/keywords.d.ts +50 -0
- package/dist/document/extractors/keywords.d.ts.map +1 -0
- package/dist/document/extractors/questions.d.ts +42 -0
- package/dist/document/extractors/questions.d.ts.map +1 -0
- package/dist/document/extractors/summary.d.ts +39 -0
- package/dist/document/extractors/summary.d.ts.map +1 -0
- package/dist/document/extractors/title.d.ts +31 -0
- package/dist/document/extractors/title.d.ts.map +1 -0
- package/dist/document/extractors/types.d.ts +27 -0
- package/dist/document/extractors/types.d.ts.map +1 -0
- package/dist/document/index.d.ts +3 -0
- package/dist/document/index.d.ts.map +1 -0
- package/dist/document/prompts/base.d.ts +19 -0
- package/dist/document/prompts/base.d.ts.map +1 -0
- package/dist/document/prompts/format.d.ts +8 -0
- package/dist/document/prompts/format.d.ts.map +1 -0
- package/dist/document/prompts/index.d.ts +4 -0
- package/dist/document/prompts/index.d.ts.map +1 -0
- package/dist/document/prompts/prompt.d.ts +12 -0
- package/dist/document/prompts/prompt.d.ts.map +1 -0
- package/dist/document/prompts/types.d.ts +22 -0
- package/dist/document/prompts/types.d.ts.map +1 -0
- package/dist/document/schema/index.d.ts +4 -0
- package/dist/document/schema/index.d.ts.map +1 -0
- package/dist/document/schema/node.d.ts +53 -0
- package/dist/document/schema/node.d.ts.map +1 -0
- package/dist/document/schema/types.d.ts +35 -0
- package/dist/document/schema/types.d.ts.map +1 -0
- package/dist/document/transformers/character.d.ts +46 -0
- package/dist/document/transformers/character.d.ts.map +1 -0
- package/dist/document/transformers/html.d.ts +26 -0
- package/dist/document/transformers/html.d.ts.map +1 -0
- package/dist/document/transformers/json.d.ts +91 -0
- package/dist/document/transformers/json.d.ts.map +1 -0
- package/dist/document/transformers/latex.d.ts +12 -0
- package/dist/document/transformers/latex.d.ts.map +1 -0
- package/dist/document/transformers/markdown.d.ts +25 -0
- package/dist/document/transformers/markdown.d.ts.map +1 -0
- package/dist/document/transformers/text.d.ts +22 -0
- package/dist/document/transformers/text.d.ts.map +1 -0
- package/dist/document/transformers/token.d.ts +46 -0
- package/dist/document/transformers/token.d.ts.map +1 -0
- package/dist/document/transformers/transformer.d.ts +5 -0
- package/dist/document/transformers/transformer.d.ts.map +1 -0
- package/dist/document/types.d.ts +66 -0
- package/dist/document/types.d.ts.map +1 -0
- package/dist/graph-rag/index.d.ts +57 -0
- package/dist/graph-rag/index.d.ts.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +9 -33
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/rerank/index.d.ts +44 -0
- package/dist/rerank/index.d.ts.map +1 -0
- package/dist/rerank/relevance/cohere/index.d.ts +8 -0
- package/dist/rerank/relevance/cohere/index.d.ts.map +1 -0
- package/dist/rerank/relevance/index.d.ts +4 -0
- package/dist/rerank/relevance/index.d.ts.map +1 -0
- package/dist/rerank/relevance/mastra-agent/index.d.ts +8 -0
- package/dist/rerank/relevance/mastra-agent/index.d.ts.map +1 -0
- package/dist/rerank/relevance/zeroentropy/index.d.ts +8 -0
- package/dist/rerank/relevance/zeroentropy/index.d.ts.map +1 -0
- package/dist/tools/document-chunker.d.ts +7 -0
- package/dist/tools/document-chunker.d.ts.map +1 -0
- package/dist/tools/graph-rag.d.ts +26 -0
- package/dist/tools/graph-rag.d.ts.map +1 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/types.d.ts +97 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/vector-query.d.ts +26 -0
- package/dist/tools/vector-query.d.ts.map +1 -0
- package/dist/utils/convert-sources.d.ts +18 -0
- package/dist/utils/convert-sources.d.ts.map +1 -0
- package/dist/utils/default-settings.d.ts +6 -0
- package/dist/utils/default-settings.d.ts.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/tool-schemas.d.ts +63 -0
- package/dist/utils/tool-schemas.d.ts.map +1 -0
- package/dist/utils/vector-prompts.d.ts +32 -0
- package/dist/utils/vector-prompts.d.ts.map +1 -0
- package/dist/utils/vector-search.d.ts +23 -0
- package/dist/utils/vector-search.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/document/extractors/keywords.test.ts +15 -9
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -1
- package/tsup.config.ts +22 -0
- package/dist/_tsup-dts-rollup.d.cts +0 -1307
- package/dist/_tsup-dts-rollup.d.ts +0 -1307
- package/dist/index.d.cts +0 -33
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,23 +1,4 @@
|
|
|
1
1
|
|
|
2
|
-
> @mastra/rag@1.0.
|
|
3
|
-
> tsup
|
|
2
|
+
> @mastra/rag@1.0.6-alpha.0 build /home/runner/work/mastra/mastra/packages/rag
|
|
3
|
+
> tsup --silent --config tsup.config.ts
|
|
4
4
|
|
|
5
|
-
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
-
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
-
[34mCLI[39m tsup v8.5.0
|
|
8
|
-
[34mTSC[39m Build start
|
|
9
|
-
[32mTSC[39m ⚡️ Build success in 15653ms
|
|
10
|
-
[34mDTS[39m Build start
|
|
11
|
-
[34mCLI[39m Target: es2022
|
|
12
|
-
Analysis will use the bundled TypeScript version 5.8.3
|
|
13
|
-
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/rag/dist/_tsup-dts-rollup.d.ts[39m
|
|
14
|
-
Analysis will use the bundled TypeScript version 5.8.3
|
|
15
|
-
[36mWriting package typings: /home/runner/work/mastra/mastra/packages/rag/dist/_tsup-dts-rollup.d.cts[39m
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in 13572ms
|
|
17
|
-
[34mCLI[39m Cleaning output folder
|
|
18
|
-
[34mESM[39m Build start
|
|
19
|
-
[34mCJS[39m Build start
|
|
20
|
-
[32mCJS[39m [1mdist/index.cjs [22m[32m248.32 KB[39m
|
|
21
|
-
[32mCJS[39m ⚡️ Build success in 5173ms
|
|
22
|
-
[32mESM[39m [1mdist/index.js [22m[32m246.24 KB[39m
|
|
23
|
-
[32mESM[39m ⚡️ Build success in 5175ms
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @mastra/rag
|
|
2
2
|
|
|
3
|
+
## 1.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 613eec3: dependencies updates:
|
|
8
|
+
- Updated dependency [`node-html-better-parser@^1.5.2` ↗︎](https://www.npmjs.com/package/node-html-better-parser/v/1.5.2) (from `^1.5.1`, in `dependencies`)
|
|
9
|
+
- Updated dependencies [33dcb07]
|
|
10
|
+
- Updated dependencies [d0d9500]
|
|
11
|
+
- Updated dependencies [d30b1a0]
|
|
12
|
+
- Updated dependencies [bff87f7]
|
|
13
|
+
- Updated dependencies [b4a8df0]
|
|
14
|
+
- @mastra/core@0.12.1
|
|
15
|
+
|
|
16
|
+
## 1.0.6-alpha.0
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 613eec3: dependencies updates:
|
|
21
|
+
- Updated dependency [`node-html-better-parser@^1.5.2` ↗︎](https://www.npmjs.com/package/node-html-better-parser/v/1.5.2) (from `^1.5.1`, in `dependencies`)
|
|
22
|
+
- Updated dependencies [33dcb07]
|
|
23
|
+
- Updated dependencies [d30b1a0]
|
|
24
|
+
- Updated dependencies [bff87f7]
|
|
25
|
+
- Updated dependencies [b4a8df0]
|
|
26
|
+
- @mastra/core@0.12.1-alpha.0
|
|
27
|
+
|
|
3
28
|
## 1.0.5
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Document as Chunk } from './schema';
|
|
2
|
+
import type { ChunkOptions, ChunkParams, ExtractParams } from './types';
|
|
3
|
+
export declare class MDocument {
|
|
4
|
+
private chunks;
|
|
5
|
+
private type;
|
|
6
|
+
constructor({ docs, type }: {
|
|
7
|
+
docs: {
|
|
8
|
+
text: string;
|
|
9
|
+
metadata?: Record<string, any>;
|
|
10
|
+
}[];
|
|
11
|
+
type: string;
|
|
12
|
+
});
|
|
13
|
+
extractMetadata({ title, summary, questions, keywords }: ExtractParams): Promise<MDocument>;
|
|
14
|
+
static fromText(text: string, metadata?: Record<string, any>): MDocument;
|
|
15
|
+
static fromHTML(html: string, metadata?: Record<string, any>): MDocument;
|
|
16
|
+
static fromMarkdown(markdown: string, metadata?: Record<string, any>): MDocument;
|
|
17
|
+
static fromJSON(jsonString: string, metadata?: Record<string, any>): MDocument;
|
|
18
|
+
private defaultStrategy;
|
|
19
|
+
private chunkBy;
|
|
20
|
+
chunkRecursive(options?: ChunkOptions): Promise<void>;
|
|
21
|
+
chunkCharacter(options?: ChunkOptions): Promise<void>;
|
|
22
|
+
chunkHTML(options?: ChunkOptions): Promise<void>;
|
|
23
|
+
chunkJSON(options?: ChunkOptions): Promise<void>;
|
|
24
|
+
chunkLatex(options?: ChunkOptions): Promise<void>;
|
|
25
|
+
chunkToken(options?: ChunkOptions): Promise<void>;
|
|
26
|
+
chunkMarkdown(options?: ChunkOptions): Promise<void>;
|
|
27
|
+
chunk(params?: ChunkParams): Promise<Chunk[]>;
|
|
28
|
+
getDocs(): Chunk[];
|
|
29
|
+
getText(): string[];
|
|
30
|
+
getMetadata(): Record<string, any>[];
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../src/document/document.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,IAAI,KAAK,EAAgC,MAAM,UAAU,CAAC;AAQ3E,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAiB,aAAa,EAAE,MAAM,SAAS,CAAC;AAEvF,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAU;IACxB,OAAO,CAAC,IAAI,CAAS;gBAET,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;SAAE,EAAE,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE;IAOhG,eAAe,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC;IAmDjG,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS;IAYxE,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS;IAYxE,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS;IAYhF,MAAM,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS;IAY9E,OAAO,CAAC,eAAe;YAeT,OAAO;IA4Bf,cAAc,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBrD,cAAc,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAUrD,SAAS,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBhD,SAAS,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBhD,UAAU,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAMjD,UAAU,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAUjD,aAAa,CAAC,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAapD,KAAK,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAenD,OAAO,IAAI,KAAK,EAAE;IAIlB,OAAO,IAAI,MAAM,EAAE;IAInB,WAAW,IAAI,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE;CAGrC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BaseNode } from '../schema';
|
|
2
|
+
export declare abstract class BaseExtractor {
|
|
3
|
+
isTextNodeOnly: boolean;
|
|
4
|
+
abstract extract(nodes: BaseNode[]): Promise<Record<string, any>[]>;
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param nodes Nodes to extract metadata from.
|
|
8
|
+
* @returns Metadata extracted from the nodes.
|
|
9
|
+
*/
|
|
10
|
+
processNodes(nodes: BaseNode[]): Promise<BaseNode[]>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAK1C,8BAAsB,aAAa;IACjC,cAAc,EAAE,OAAO,CAAQ;IAE/B,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC;IAEnE;;;;OAIG;IACG,YAAY,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAc3D"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { TitleExtractor } from './title';
|
|
2
|
+
export { SummaryExtractor } from './summary';
|
|
3
|
+
export { QuestionsAnsweredExtractor } from './questions';
|
|
4
|
+
export { KeywordExtractor } from './keywords';
|
|
5
|
+
export type { KeywordExtractArgs, QuestionAnswerExtractArgs, SummaryExtractArgs, TitleExtractorsArgs } from './types';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,kBAAkB,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { MastraLanguageModel } from '@mastra/core/agent';
|
|
2
|
+
import type { KeywordExtractPrompt } from '../prompts';
|
|
3
|
+
import type { BaseNode } from '../schema';
|
|
4
|
+
import { BaseExtractor } from './base';
|
|
5
|
+
import type { KeywordExtractArgs } from './types';
|
|
6
|
+
type ExtractKeyword = {
|
|
7
|
+
/**
|
|
8
|
+
* Comma-separated keywords extracted from the node. May be empty if extraction fails.
|
|
9
|
+
*/
|
|
10
|
+
excerptKeywords: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Extract keywords from a list of nodes.
|
|
14
|
+
*/
|
|
15
|
+
export declare class KeywordExtractor extends BaseExtractor {
|
|
16
|
+
llm: MastraLanguageModel;
|
|
17
|
+
keywords: number;
|
|
18
|
+
promptTemplate: KeywordExtractPrompt;
|
|
19
|
+
/**
|
|
20
|
+
* Constructor for the KeywordExtractor class.
|
|
21
|
+
* @param {MastraLanguageModel} llm MastraLanguageModel instance.
|
|
22
|
+
* @param {number} keywords Number of keywords to extract.
|
|
23
|
+
* @param {string} [promptTemplate] Optional custom prompt template (must include {context})
|
|
24
|
+
* @throws {Error} If keywords is less than 1.
|
|
25
|
+
*/
|
|
26
|
+
constructor(options?: KeywordExtractArgs);
|
|
27
|
+
/**
|
|
28
|
+
*
|
|
29
|
+
* @param node Node to extract keywords from.
|
|
30
|
+
* @returns Keywords extracted from the node.
|
|
31
|
+
*/
|
|
32
|
+
/**
|
|
33
|
+
* Extract keywords from a node. Returns an object with a comma-separated string of keywords, or an empty string if extraction fails.
|
|
34
|
+
* Adds error handling for malformed/empty LLM output.
|
|
35
|
+
*/
|
|
36
|
+
extractKeywordsFromNodes(node: BaseNode): Promise<ExtractKeyword>;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param nodes Nodes to extract keywords from.
|
|
40
|
+
* @returns Keywords extracted from the nodes.
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* Extract keywords from an array of nodes. Always returns an array (may be empty).
|
|
44
|
+
* @param nodes Nodes to extract keywords from.
|
|
45
|
+
* @returns Array of keyword extraction results.
|
|
46
|
+
*/
|
|
47
|
+
extract(nodes: BaseNode[]): Promise<Array<ExtractKeyword>>;
|
|
48
|
+
}
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=keywords.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keywords.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/keywords.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,KAAK,cAAc,GAAG;IACpB;;OAEG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,GAAG,EAAE,mBAAmB,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAK;IACrB,cAAc,EAAE,oBAAoB,CAAC;IAErC;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE,kBAAkB;IAexC;;;;OAIG;IACH;;;OAGG;IACG,wBAAwB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC;IAwCvE;;;;OAIG;IACH;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;CAKjE"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { MastraLanguageModel } from '@mastra/core/agent';
|
|
2
|
+
import type { QuestionExtractPrompt } from '../prompts';
|
|
3
|
+
import type { BaseNode } from '../schema';
|
|
4
|
+
import { BaseExtractor } from './base';
|
|
5
|
+
import type { QuestionAnswerExtractArgs } from './types';
|
|
6
|
+
type ExtractQuestion = {
|
|
7
|
+
/**
|
|
8
|
+
* Questions extracted from the node as a string (may be empty if extraction fails).
|
|
9
|
+
*/
|
|
10
|
+
questionsThisExcerptCanAnswer: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Extract questions from a list of nodes.
|
|
14
|
+
*/
|
|
15
|
+
export declare class QuestionsAnsweredExtractor extends BaseExtractor {
|
|
16
|
+
llm: MastraLanguageModel;
|
|
17
|
+
questions: number;
|
|
18
|
+
promptTemplate: QuestionExtractPrompt;
|
|
19
|
+
embeddingOnly: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Constructor for the QuestionsAnsweredExtractor class.
|
|
22
|
+
* @param {MastraLanguageModel} llm MastraLanguageModel instance.
|
|
23
|
+
* @param {number} questions Number of questions to generate.
|
|
24
|
+
* @param {QuestionExtractPrompt['template']} promptTemplate Optional custom prompt template (should include {context}).
|
|
25
|
+
* @param {boolean} embeddingOnly Whether to use metadata for embeddings only.
|
|
26
|
+
*/
|
|
27
|
+
constructor(options?: QuestionAnswerExtractArgs);
|
|
28
|
+
/**
|
|
29
|
+
* Extract answered questions from a node.
|
|
30
|
+
* @param {BaseNode} node Node to extract questions from.
|
|
31
|
+
* @returns {Promise<Array<ExtractQuestion> | Array<{}>>} Questions extracted from the node.
|
|
32
|
+
*/
|
|
33
|
+
extractQuestionsFromNode(node: BaseNode): Promise<ExtractQuestion>;
|
|
34
|
+
/**
|
|
35
|
+
* Extract answered questions from a list of nodes.
|
|
36
|
+
* @param {BaseNode[]} nodes Nodes to extract questions from.
|
|
37
|
+
* @returns {Promise<Array<ExtractQuestion> | Array<{}>>} Questions extracted from the nodes.
|
|
38
|
+
*/
|
|
39
|
+
extract(nodes: BaseNode[]): Promise<Array<ExtractQuestion> | Array<object>>;
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=questions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"questions.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/questions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,SAAS,CAAC;AAEzD,KAAK,eAAe,GAAG;IACrB;;OAEG;IACH,6BAA6B,EAAE,MAAM,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,qBAAa,0BAA2B,SAAQ,aAAa;IAC3D,GAAG,EAAE,mBAAmB,CAAC;IACzB,SAAS,EAAE,MAAM,CAAK;IACtB,cAAc,EAAE,qBAAqB,CAAC;IACtC,aAAa,EAAE,OAAO,CAAS;IAE/B;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE,yBAAyB;IAkB/C;;;;OAIG;IACG,wBAAwB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IA0CxE;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,eAAe,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;CAKlF"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SummaryPrompt } from '../prompts';
|
|
2
|
+
import type { BaseNode } from '../schema';
|
|
3
|
+
import { BaseExtractor } from './base';
|
|
4
|
+
import type { SummaryExtractArgs } from './types';
|
|
5
|
+
type ExtractSummary = {
|
|
6
|
+
sectionSummary?: string;
|
|
7
|
+
prevSectionSummary?: string;
|
|
8
|
+
nextSectionSummary?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Summarize an array of nodes using a custom LLM.
|
|
12
|
+
*
|
|
13
|
+
* @param nodes Array of node-like objects
|
|
14
|
+
* @param options Summary extraction options
|
|
15
|
+
* @returns Array of summary results
|
|
16
|
+
*/
|
|
17
|
+
export declare class SummaryExtractor extends BaseExtractor {
|
|
18
|
+
private llm;
|
|
19
|
+
summaries: string[];
|
|
20
|
+
promptTemplate: SummaryPrompt;
|
|
21
|
+
private selfSummary;
|
|
22
|
+
private prevSummary;
|
|
23
|
+
private nextSummary;
|
|
24
|
+
constructor(options?: SummaryExtractArgs);
|
|
25
|
+
/**
|
|
26
|
+
* Extract summary from a node.
|
|
27
|
+
* @param {BaseNode} node Node to extract summary from.
|
|
28
|
+
* @returns {Promise<string>} Summary extracted from the node.
|
|
29
|
+
*/
|
|
30
|
+
generateNodeSummary(node: BaseNode): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Extract summaries from a list of nodes.
|
|
33
|
+
* @param {BaseNode[]} nodes Nodes to extract summaries from.
|
|
34
|
+
* @returns {Promise<ExtractSummary[]>} Summaries extracted from the nodes.
|
|
35
|
+
*/
|
|
36
|
+
extract(nodes: BaseNode[]): Promise<ExtractSummary[]>;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=summary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summary.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/summary.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD,KAAK,cAAc,GAAG;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,aAAa;IACjD,OAAO,CAAC,GAAG,CAAsB;IACjC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,cAAc,EAAE,aAAa,CAAC;IAC9B,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,WAAW,CAAU;IAC7B,OAAO,CAAC,WAAW,CAAU;gBACjB,OAAO,CAAC,EAAE,kBAAkB;IAsBxC;;;;OAIG;IACG,mBAAmB,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAmC1D;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;CAqB5D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MastraLanguageModel } from '@mastra/core/agent';
|
|
2
|
+
import type { TitleCombinePrompt, TitleExtractorPrompt } from '../prompts';
|
|
3
|
+
import type { BaseNode } from '../schema';
|
|
4
|
+
import { BaseExtractor } from './base';
|
|
5
|
+
import type { TitleExtractorsArgs } from './types';
|
|
6
|
+
type ExtractTitle = {
|
|
7
|
+
documentTitle: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Extract title from a list of nodes.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TitleExtractor extends BaseExtractor {
|
|
13
|
+
llm: MastraLanguageModel;
|
|
14
|
+
isTextNodeOnly: boolean;
|
|
15
|
+
nodes: number;
|
|
16
|
+
nodeTemplate: TitleExtractorPrompt;
|
|
17
|
+
combineTemplate: TitleCombinePrompt;
|
|
18
|
+
constructor(options?: TitleExtractorsArgs);
|
|
19
|
+
/**
|
|
20
|
+
* Extract titles from a list of nodes.
|
|
21
|
+
* @param {BaseNode[]} nodes Nodes to extract titles from.
|
|
22
|
+
* @returns {Promise<BaseNode<ExtractTitle>[]>} Titles extracted from the nodes.
|
|
23
|
+
*/
|
|
24
|
+
extract(nodes: BaseNode[]): Promise<Array<ExtractTitle>>;
|
|
25
|
+
private filterNodes;
|
|
26
|
+
private separateNodesByDocument;
|
|
27
|
+
private extractTitles;
|
|
28
|
+
private getTitlesCandidates;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
|
31
|
+
//# sourceMappingURL=title.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"title.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/title.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAE9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE3E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAEvC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAEnD,KAAK,YAAY,GAAG;IAClB,aAAa,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF;;GAEG;AACH,qBAAa,cAAe,SAAQ,aAAa;IAC/C,GAAG,EAAE,mBAAmB,CAAC;IACzB,cAAc,EAAE,OAAO,CAAS;IAChC,KAAK,EAAE,MAAM,CAAK;IAClB,YAAY,EAAE,oBAAoB,CAAC;IACnC,eAAe,EAAE,kBAAkB,CAAC;gBAExB,OAAO,CAAC,EAAE,mBAAmB;IAqBzC;;;;OAIG;IACG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IAoC9D,OAAO,CAAC,WAAW;IASnB,OAAO,CAAC,uBAAuB;YAYjB,aAAa;YAoCb,mBAAmB;CA8BlC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { MastraLanguageModel } from '@mastra/core/agent';
|
|
2
|
+
import type { KeywordExtractPrompt, QuestionExtractPrompt, SummaryPrompt, TitleExtractorPrompt, TitleCombinePrompt } from '../prompts';
|
|
3
|
+
export type KeywordExtractArgs = {
|
|
4
|
+
llm?: MastraLanguageModel;
|
|
5
|
+
keywords?: number;
|
|
6
|
+
promptTemplate?: KeywordExtractPrompt['template'];
|
|
7
|
+
};
|
|
8
|
+
export type QuestionAnswerExtractArgs = {
|
|
9
|
+
llm?: MastraLanguageModel;
|
|
10
|
+
questions?: number;
|
|
11
|
+
promptTemplate?: QuestionExtractPrompt['template'];
|
|
12
|
+
embeddingOnly?: boolean;
|
|
13
|
+
};
|
|
14
|
+
export type SummaryExtractArgs = {
|
|
15
|
+
llm?: MastraLanguageModel;
|
|
16
|
+
summaries?: string[];
|
|
17
|
+
promptTemplate?: SummaryPrompt['template'];
|
|
18
|
+
};
|
|
19
|
+
export type TitleExtractorsArgs = {
|
|
20
|
+
llm?: MastraLanguageModel;
|
|
21
|
+
nodes?: number;
|
|
22
|
+
nodeTemplate?: TitleExtractorPrompt['template'];
|
|
23
|
+
combineTemplate?: TitleCombinePrompt['template'];
|
|
24
|
+
};
|
|
25
|
+
export declare const STRIP_REGEX: RegExp;
|
|
26
|
+
export declare const baseLLM: MastraLanguageModel;
|
|
27
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/document/extractors/types.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAEpB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC;CACnD,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,qBAAqB,CAAC,UAAU,CAAC,CAAC;IACnD,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,cAAc,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,GAAG,CAAC,EAAE,mBAAmB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC;IAChD,eAAe,CAAC,EAAE,kBAAkB,CAAC,UAAU,CAAC,CAAC;CAClD,CAAC;AAEF,eAAO,MAAM,WAAW,QAAmB,CAAC;AAG5C,eAAO,MAAM,OAAO,EAAE,mBAAsC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/document/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BasePromptTemplateOptions, ChatMessage, PromptTemplateOptions } from './types';
|
|
2
|
+
export declare abstract class BasePromptTemplate<const TemplatesVar extends readonly string[] = string[]> {
|
|
3
|
+
templateVars: Set<string>;
|
|
4
|
+
options: Partial<Record<TemplatesVar[number] | (string & {}), string>>;
|
|
5
|
+
protected constructor(options: BasePromptTemplateOptions<TemplatesVar>);
|
|
6
|
+
abstract partialFormat(options: Partial<Record<TemplatesVar[number] | (string & {}), string>>): BasePromptTemplate<TemplatesVar>;
|
|
7
|
+
abstract format(options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>): string;
|
|
8
|
+
abstract formatMessages(options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>): ChatMessage[];
|
|
9
|
+
abstract get template(): string;
|
|
10
|
+
}
|
|
11
|
+
export declare class PromptTemplate<const TemplatesVar extends readonly string[] = string[]> extends BasePromptTemplate<TemplatesVar> {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(options: PromptTemplateOptions<TemplatesVar>);
|
|
14
|
+
partialFormat(options: Partial<Record<TemplatesVar[number] | (string & {}), string>>): PromptTemplate<TemplatesVar>;
|
|
15
|
+
format(options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>): string;
|
|
16
|
+
formatMessages(options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>): ChatMessage[];
|
|
17
|
+
get template(): string;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/document/prompts/base.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,yBAAyB,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAE7F,8BAAsB,kBAAkB,CAAC,KAAK,CAAC,YAAY,SAAS,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE;IAC9F,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAa;IACtC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAM;IAE5E,SAAS,aAAa,OAAO,EAAE,yBAAyB,CAAC,YAAY,CAAC;IAUtE,QAAQ,CAAC,aAAa,CACpB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,GACrE,kBAAkB,CAAC,YAAY,CAAC;IAEnC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM;IAEhG,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,WAAW,EAAE;IAE/G,QAAQ,KAAK,QAAQ,IAAI,MAAM,CAAC;CACjC;AAED,qBAAa,cAAc,CACzB,KAAK,CAAC,YAAY,SAAS,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CACvD,SAAQ,kBAAkB,CAAC,YAAY,CAAC;;gBAG5B,OAAO,EAAE,qBAAqB,CAAC,YAAY,CAAC;IAMxD,aAAa,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,cAAc,CAAC,YAAY,CAAC;IAenH,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM;IASvF,cAAc,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,GAAG,WAAW,EAAE;IAUtG,IAAI,QAAQ,IAAI,MAAM,CAErB;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a string by replacing placeholders with values from the provided parameters.
|
|
3
|
+
* @param str The string to format.
|
|
4
|
+
* @param params A record of placeholder names to their corresponding values.
|
|
5
|
+
* @returns The formatted string.
|
|
6
|
+
*/
|
|
7
|
+
export declare function format(str: string, params: Record<string, string>): string;
|
|
8
|
+
//# sourceMappingURL=format.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../../../src/document/prompts/format.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAEjE"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { BasePromptTemplate, PromptTemplate } from './base';
|
|
2
|
+
export { defaultKeywordExtractPrompt, defaultQuestionExtractPrompt, defaultSummaryPrompt, defaultTitleCombinePromptTemplate, defaultTitleExtractorPromptTemplate, } from './prompt';
|
|
3
|
+
export type { KeywordExtractPrompt, QuestionExtractPrompt, SummaryPrompt, TitleCombinePrompt, TitleExtractorPrompt, } from './prompt';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/document/prompts/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC5D,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,oBAAoB,EACpB,iCAAiC,EACjC,mCAAmC,GACpC,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PromptTemplate } from './base';
|
|
2
|
+
export type SummaryPrompt = PromptTemplate<['context']>;
|
|
3
|
+
export type KeywordExtractPrompt = PromptTemplate<['context', 'maxKeywords']>;
|
|
4
|
+
export type QuestionExtractPrompt = PromptTemplate<['context', 'numQuestions']>;
|
|
5
|
+
export type TitleExtractorPrompt = PromptTemplate<['context']>;
|
|
6
|
+
export type TitleCombinePrompt = PromptTemplate<['context']>;
|
|
7
|
+
export declare const defaultSummaryPrompt: SummaryPrompt;
|
|
8
|
+
export declare const defaultKeywordExtractPrompt: KeywordExtractPrompt;
|
|
9
|
+
export declare const defaultQuestionExtractPrompt: PromptTemplate<readonly ["numQuestions", "context"]>;
|
|
10
|
+
export declare const defaultTitleExtractorPromptTemplate: PromptTemplate<readonly ["context"]>;
|
|
11
|
+
export declare const defaultTitleCombinePromptTemplate: PromptTemplate<readonly ["context"]>;
|
|
12
|
+
//# sourceMappingURL=prompt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../../src/document/prompts/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC,MAAM,MAAM,aAAa,GAAG,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AACxD,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,CAAC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC;AAC9E,MAAM,MAAM,qBAAqB,GAAG,cAAc,CAAC,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAC;AAChF,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AAC/D,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;AAE7D,eAAO,MAAM,oBAAoB,EAAE,aAUjC,CAAC;AAEH,eAAO,MAAM,2BAA2B,EAAE,oBAWxC,CAAC;AAEH,eAAO,MAAM,4BAA4B,sDAYvC,CAAC;AAEH,eAAO,MAAM,mCAAmC,sCAK9C,CAAC;AAEH,eAAO,MAAM,iCAAiC,sCAK5C,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type MessageType = 'user' | 'assistant' | 'system' | 'memory' | 'developer';
|
|
2
|
+
export type MessageContentTextDetail = {
|
|
3
|
+
type: 'text';
|
|
4
|
+
text: string;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Extended type for the content of a message that allows for multi-modal messages.
|
|
8
|
+
*/
|
|
9
|
+
export type MessageContent = string | MessageContentTextDetail[];
|
|
10
|
+
export type ChatMessage<AdditionalMessageOptions extends object = object> = {
|
|
11
|
+
content: MessageContent;
|
|
12
|
+
role: MessageType;
|
|
13
|
+
options?: undefined | AdditionalMessageOptions;
|
|
14
|
+
};
|
|
15
|
+
export type BasePromptTemplateOptions<TemplatesVar extends readonly string[]> = {
|
|
16
|
+
templateVars?: TemplatesVar | readonly string[];
|
|
17
|
+
options?: Partial<Record<TemplatesVar[number] | (string & {}), string>>;
|
|
18
|
+
};
|
|
19
|
+
export type PromptTemplateOptions<TemplatesVar extends readonly string[]> = BasePromptTemplateOptions<TemplatesVar> & {
|
|
20
|
+
template: string;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/document/prompts/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;AAEnF,MAAM,MAAM,wBAAwB,GAAG;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,wBAAwB,EAAE,CAAC;AAEjE,MAAM,MAAM,WAAW,CAAC,wBAAwB,SAAS,MAAM,GAAG,MAAM,IAAI;IAC1E,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,CAAC,EAAE,SAAS,GAAG,wBAAwB,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,yBAAyB,CAAC,YAAY,SAAS,SAAS,MAAM,EAAE,IAAI;IAC9E,YAAY,CAAC,EACT,YAAY,GAEZ,SAAS,MAAM,EAAE,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;CACzE,CAAC;AAEF,MAAM,MAAM,qBAAqB,CAAC,YAAY,SAAS,SAAS,MAAM,EAAE,IAAI,yBAAyB,CAAC,YAAY,CAAC,GAAG;IACpH,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/document/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACvD,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { NodeRelationship, ObjectType } from './types';
|
|
2
|
+
import type { Metadata, RelatedNodeInfo, RelatedNodeType, BaseNodeParams, TextNodeParams } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Generic abstract class for retrievable nodes
|
|
5
|
+
*/
|
|
6
|
+
export declare abstract class BaseNode<T extends Metadata = Metadata> {
|
|
7
|
+
id_: string;
|
|
8
|
+
metadata: T;
|
|
9
|
+
relationships: Partial<Record<NodeRelationship, RelatedNodeType<T>>>;
|
|
10
|
+
accessor hash: string;
|
|
11
|
+
protected constructor(init?: BaseNodeParams<T>);
|
|
12
|
+
abstract get type(): ObjectType;
|
|
13
|
+
abstract getContent(): string;
|
|
14
|
+
abstract getMetadataStr(): string;
|
|
15
|
+
get sourceNode(): RelatedNodeInfo<T> | undefined;
|
|
16
|
+
get prevNode(): RelatedNodeInfo<T> | undefined;
|
|
17
|
+
get nextNode(): RelatedNodeInfo<T> | undefined;
|
|
18
|
+
get parentNode(): RelatedNodeInfo<T> | undefined;
|
|
19
|
+
get childNodes(): RelatedNodeInfo<T>[] | undefined;
|
|
20
|
+
abstract generateHash(): string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* TextNode is the default node type for text.
|
|
24
|
+
*/
|
|
25
|
+
export declare class TextNode<T extends Metadata = Metadata> extends BaseNode<T> {
|
|
26
|
+
text: string;
|
|
27
|
+
startCharIdx?: number;
|
|
28
|
+
endCharIdx?: number;
|
|
29
|
+
metadataSeparator: string;
|
|
30
|
+
constructor(init?: TextNodeParams<T>);
|
|
31
|
+
/**
|
|
32
|
+
* Generate a hash of the text node.
|
|
33
|
+
* The ID is not part of the hash as it can change independent of content.
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
generateHash(): string;
|
|
37
|
+
get type(): ObjectType;
|
|
38
|
+
getContent(): string;
|
|
39
|
+
getMetadataStr(): string;
|
|
40
|
+
getNodeInfo(): {
|
|
41
|
+
start: number | undefined;
|
|
42
|
+
end: number | undefined;
|
|
43
|
+
};
|
|
44
|
+
getText(): string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A document is just a special text node with a docId.
|
|
48
|
+
*/
|
|
49
|
+
export declare class Document<T extends Metadata = Metadata> extends TextNode<T> {
|
|
50
|
+
constructor(init?: TextNodeParams<T>);
|
|
51
|
+
get type(): ObjectType;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=node.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../../src/document/schema/node.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE1G;;GAEG;AACH,8BAAsB,QAAQ,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ;IAC1D,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,CAAC,CAAC;IACZ,aAAa,EAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAGrE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAM;IAE3B,SAAS,aAAa,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC;IAO9C,QAAQ,KAAK,IAAI,IAAI,UAAU,CAAC;IAEhC,QAAQ,CAAC,UAAU,IAAI,MAAM;IAE7B,QAAQ,CAAC,cAAc,IAAI,MAAM;IAEjC,IAAI,UAAU,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,CAQ/C;IAED,IAAI,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,CAQ7C;IAED,IAAI,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,CAQ7C;IAED,IAAI,UAAU,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,CAQ/C;IAED,IAAI,UAAU,IAAI,eAAe,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAQjD;IAED,QAAQ,CAAC,YAAY,IAAI,MAAM;CAChC;AAED;;GAEG;AACH,qBAAa,QAAQ,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IACtE,IAAI,EAAE,MAAM,CAAC;IAEb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;gBAEd,IAAI,GAAE,cAAc,CAAC,CAAC,CAAM;IAaxC;;;;OAIG;IACH,YAAY;IAQZ,IAAI,IAAI,eAEP;IAED,UAAU,IAAI,MAAM;IAKpB,cAAc,IAAI,MAAM;IAMxB,WAAW;;;;IAIX,OAAO;CAGR;AAED;;GAEG;AACH,qBAAa,QAAQ,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;gBAC1D,IAAI,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC;IAIpC,IAAI,IAAI,eAEP;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare enum NodeRelationship {
|
|
2
|
+
SOURCE = "SOURCE",
|
|
3
|
+
PREVIOUS = "PREVIOUS",
|
|
4
|
+
NEXT = "NEXT",
|
|
5
|
+
PARENT = "PARENT",
|
|
6
|
+
CHILD = "CHILD"
|
|
7
|
+
}
|
|
8
|
+
export declare enum ObjectType {
|
|
9
|
+
TEXT = "TEXT",
|
|
10
|
+
IMAGE = "IMAGE",
|
|
11
|
+
INDEX = "INDEX",
|
|
12
|
+
DOCUMENT = "DOCUMENT",
|
|
13
|
+
IMAGE_DOCUMENT = "IMAGE_DOCUMENT"
|
|
14
|
+
}
|
|
15
|
+
export type Metadata = Record<string, any>;
|
|
16
|
+
export interface RelatedNodeInfo<T extends Metadata = Metadata> {
|
|
17
|
+
nodeId: string;
|
|
18
|
+
nodeType?: ObjectType;
|
|
19
|
+
metadata: T;
|
|
20
|
+
hash?: string;
|
|
21
|
+
}
|
|
22
|
+
export type RelatedNodeType<T extends Metadata = Metadata> = RelatedNodeInfo<T> | RelatedNodeInfo<T>[];
|
|
23
|
+
export type BaseNodeParams<T extends Metadata = Metadata> = {
|
|
24
|
+
id_?: string | undefined;
|
|
25
|
+
metadata?: T | undefined;
|
|
26
|
+
relationships?: Partial<Record<NodeRelationship, RelatedNodeType<T>>> | undefined;
|
|
27
|
+
hash?: string | undefined;
|
|
28
|
+
};
|
|
29
|
+
export type TextNodeParams<T extends Metadata = Metadata> = BaseNodeParams<T> & {
|
|
30
|
+
text?: string | undefined;
|
|
31
|
+
startCharIdx?: number | undefined;
|
|
32
|
+
endCharIdx?: number | undefined;
|
|
33
|
+
metadataSeparator?: string | undefined;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/document/schema/types.ts"],"names":[],"mappings":"AAAA,oBAAY,gBAAgB;IAC1B,MAAM,WAAW;IACjB,QAAQ,aAAa;IACrB,IAAI,SAAS;IACb,MAAM,WAAW;IACjB,KAAK,UAAU;CAChB;AAED,oBAAY,UAAU;IACpB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,KAAK,UAAU;IACf,QAAQ,aAAa;IACrB,cAAc,mBAAmB;CAClC;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE3C,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ;IAC5D,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,QAAQ,EAAE,CAAC,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC;AAEvG,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI;IAC1D,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IAClF,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ,IAAI,cAAc,CAAC,CAAC,CAAC,GAAG;IAC9E,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACxC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Language } from '../types';
|
|
2
|
+
import type { ChunkOptions } from '../types';
|
|
3
|
+
import { TextTransformer } from './text';
|
|
4
|
+
export declare class CharacterTransformer extends TextTransformer {
|
|
5
|
+
protected separator: string;
|
|
6
|
+
protected isSeparatorRegex: boolean;
|
|
7
|
+
constructor({ separator, isSeparatorRegex, options, }: {
|
|
8
|
+
separator?: string;
|
|
9
|
+
isSeparatorRegex?: boolean;
|
|
10
|
+
options?: {
|
|
11
|
+
size?: number;
|
|
12
|
+
overlap?: number;
|
|
13
|
+
lengthFunction?: (text: string) => number;
|
|
14
|
+
keepSeparator?: boolean | 'start' | 'end';
|
|
15
|
+
addStartIndex?: boolean;
|
|
16
|
+
stripWhitespace?: boolean;
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
splitText({ text }: {
|
|
20
|
+
text: string;
|
|
21
|
+
}): string[];
|
|
22
|
+
private __splitChunk;
|
|
23
|
+
}
|
|
24
|
+
export declare class RecursiveCharacterTransformer extends TextTransformer {
|
|
25
|
+
protected separators: string[];
|
|
26
|
+
protected isSeparatorRegex: boolean;
|
|
27
|
+
constructor({ separators, isSeparatorRegex, options, }: {
|
|
28
|
+
separators?: string[];
|
|
29
|
+
isSeparatorRegex?: boolean;
|
|
30
|
+
options?: ChunkOptions;
|
|
31
|
+
});
|
|
32
|
+
private _splitText;
|
|
33
|
+
splitText({ text }: {
|
|
34
|
+
text: string;
|
|
35
|
+
}): string[];
|
|
36
|
+
static fromLanguage(language: Language, options?: {
|
|
37
|
+
size?: number;
|
|
38
|
+
chunkOverlap?: number;
|
|
39
|
+
lengthFunction?: (text: string) => number;
|
|
40
|
+
keepSeparator?: boolean | 'start' | 'end';
|
|
41
|
+
addStartIndex?: boolean;
|
|
42
|
+
stripWhitespace?: boolean;
|
|
43
|
+
}): RecursiveCharacterTransformer;
|
|
44
|
+
static getSeparatorsForLanguage(language: Language): string[];
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=character.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"character.d.ts","sourceRoot":"","sources":["../../../src/document/transformers/character.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7C,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AA+CzC,qBAAa,oBAAqB,SAAQ,eAAe;IACvD,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAC;gBAExB,EACV,SAAkB,EAClB,gBAAwB,EACxB,OAAY,GACb,EAAE;QACD,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,OAAO,CAAC,EAAE;YACR,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,OAAO,CAAC,EAAE,MAAM,CAAC;YACjB,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;YAC1C,aAAa,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;YAC1C,aAAa,CAAC,EAAE,OAAO,CAAC;YACxB,eAAe,CAAC,EAAE,OAAO,CAAC;SAC3B,CAAC;KACH;IAMD,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE;IAqB/C,OAAO,CAAC,YAAY;CAyBrB;AAED,qBAAa,6BAA8B,SAAQ,eAAe;IAChE,SAAS,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC;IAC/B,SAAS,CAAC,gBAAgB,EAAE,OAAO,CAAC;gBAExB,EACV,UAAU,EACV,gBAAwB,EACxB,OAAY,GACb,EAAE;QACD,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QACtB,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,OAAO,CAAC,EAAE,YAAY,CAAC;KACxB;IAMD,OAAO,CAAC,UAAU;IAuDlB,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,EAAE;IAI/C,MAAM,CAAC,YAAY,CACjB,QAAQ,EAAE,QAAQ,EAClB,OAAO,GAAE;QACP,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,cAAc,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;QAC1C,aAAa,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,KAAK,CAAC;QAC1C,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB,eAAe,CAAC,EAAE,OAAO,CAAC;KACtB,GACL,6BAA6B;IAKhC,MAAM,CAAC,wBAAwB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,EAAE;CA+E9D"}
|