mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-18 00:24:30 -04:00
c818e90cfc
Co-authored-by: Alex Yang <himself65@outlook.com>
1.0 KiB
1.0 KiB
sidebar_position
| sidebar_position |
|---|
| 3 |
NodeParser
The NodeParser in LlamaIndex is responbile for splitting Document objects into more manageable Node objects. When you call .fromDocuments(), the NodeParser from the ServiceContext is used to do this automatically for you. Alternatively, you can use it to split documents ahead of time.
import { Document, SimpleNodeParser } from "llamaindex";
const nodeParser = new SimpleNodeParser();
const nodes = nodeParser.getNodesFromDocuments([
new Document({ text: "I am 10 years old. John is 20 years old." }),
]);
TextSplitter
The underlying text splitter will split text by sentences. It can also be used as a standalone module for splitting raw text.
import { SentenceSplitter } from "llamaindex";
const splitter = new SentenceSplitter({ chunkSize: 1 });
const textSplits = splitter.splitText("Hello World");