27 LlamaIndex中的节点解析器使用指南

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

需要重新演唱

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值