Skip to content
Snippets Groups Projects
Commit 88d42ccd authored by Marcus Schiesser's avatar Marcus Schiesser Committed by Marcus Schiesser
Browse files

refactor: move node parsers to own package

parent a0686fb1
No related branches found
No related tags found
No related merge requests found
import { CallbackManager } from "./callbacks/CallbackManager";
import { BaseEmbedding, OpenAIEmbedding } from "./embeddings";
import { LLM, OpenAI } from "./llm/LLM";
import { NodeParser, SimpleNodeParser } from "./NodeParser";
import { LLM, OpenAI } from "./llm";
import { NodeParser, SimpleNodeParser } from "./nodeParsers";
import { PromptHelper } from "./PromptHelper";
/**
......
......@@ -2,7 +2,6 @@ export * from "./ChatEngine";
export * from "./ChatHistory";
export * from "./GlobalsHelper";
export * from "./Node";
export * from "./NodeParser";
export * from "./OutputParser";
export * from "./Prompt";
export * from "./PromptHelper";
......@@ -18,6 +17,7 @@ export * from "./constants";
export * from "./embeddings";
export * from "./indices";
export * from "./llm";
export * from "./nodeParsers";
export * from "./readers/AssemblyAI";
export * from "./readers/CSVReader";
export * from "./readers/HTMLReader";
......
......@@ -4,9 +4,10 @@ import {
ImageDocument,
NodeRelationship,
TextNode,
} from "./Node";
import { SentenceSplitter } from "./TextSplitter";
import { DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE } from "./constants";
} from "../Node";
import { SentenceSplitter } from "../TextSplitter";
import { DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE } from "../constants";
import { NodeParser } from "./types";
/**
* Splits the text of a document into smaller parts.
......@@ -14,25 +15,23 @@ import { DEFAULT_CHUNK_OVERLAP, DEFAULT_CHUNK_SIZE } from "./constants";
* @param textSplitter - The text splitter to use.
* @returns An array of text splits.
*/
export function getTextSplitsFromDocument(
function getTextSplitsFromDocument(
document: Document,
textSplitter: SentenceSplitter,
) {
const text = document.getText();
const splits = textSplitter.splitText(text);
return splits;
return textSplitter.splitText(text);
}
/**
* Generates an array of nodes from a document.
* @param document - The document to generate nodes from.
* @param doc
* @param textSplitter - The text splitter to use.
* @param includeMetadata - Whether to include metadata in the nodes.
* @param includePrevNextRel - Whether to include previous and next relationships in the nodes.
* @returns An array of nodes.
*/
export function getNodesFromDocument(
function getNodesFromDocument(
doc: BaseNode,
textSplitter: SentenceSplitter,
includeMetadata: boolean = true,
......@@ -74,18 +73,6 @@ export function getNodesFromDocument(
return nodes;
}
/**
* A NodeParser generates Nodes from Documents
*/
export interface NodeParser {
/**
* Generates an array of nodes from an array of documents.
* @param documents - The documents to generate nodes from.
* @returns An array of nodes.
*/
getNodesFromDocuments(documents: BaseNode[]): BaseNode[];
}
/**
* SimpleNodeParser is the default NodeParser. It splits documents into TextNodes using a splitter, by default SentenceSplitter
*/
......
export * from "./SimpleNodeParser";
export * from "./types";
import { BaseNode } from "../Node";
/**
* A NodeParser generates Nodes from Documents
*/
export interface NodeParser {
/**
* Generates an array of nodes from an array of documents.
* @param documents - The documents to generate nodes from.
* @returns An array of nodes.
*/
getNodesFromDocuments(documents: BaseNode[]): BaseNode[];
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment