LlamaIndex中的节点解析器使用指南
在LlamaIndex中,节点解析器是一个简单的抽象,它接受一组文档,并将它们分割成节点对象,每个节点是父文档的一个特定块。当一个文档被分割成节点时,它的所有属性(如元数据、文本和元数据模板等)都会继承给子节点。你可以在这里阅读更多关于节点和文档属性的信息。
入门指南
独立使用
节点解析器可以单独使用:
from llama_index.core import Document
from llama_index.core.node_parser import SentenceSplitter
node_parser = SentenceSplitter(chunk_size=1024, chunk_overlap=20)
nodes = node_parser.get_nodes_from_documents(
[Document(text="long text")], show_progress=False
)
转换使用
节点解析器可以包含在任何一组转换中,通过摄取管道:
from llama_index.core import SimpleDirectoryReader
from llama_index.core.ingestion import IngestionPipeline
from llama_index.core.node_parser import TokenTextSplitter
documents = SimpleDirectoryReader("./data").load_data()
pipeline = IngestionPipeline(transformations=[TokenTextSplitter(), ...])
nodes = pipeline.run(documents=documents)
索引使用
或者在转换或全局设置中设置,以便在使用.from_documents()
构建索引时自动使用:
from llama_index.core i