28 LlamaIndex中的摄取管道:数据转换与缓存管理

LlamaIndex中的摄取管道:数据转换与缓存管理

在LlamaIndex中,摄取管道(IngestionPipeline)使用了一种称为“转换”(Transformations)的概念来处理输入数据。这些转换应用于你的输入数据,结果节点要么返回,要么插入到向量数据库中(如果提供了的话)。每个节点+转换组合都会被缓存,以便后续运行(如果缓存被持久化)时使用相同的节点+转换组合可以利用缓存结果,节省时间。

要查看摄取管道实际使用的交互式示例,请查看RAG CLI

使用模式

最简单的使用方法是实例化一个摄取管道,如下所示:

from llama_index.core import Document
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.core.node_parser import SentenceSplitter
from llama_index.core.extractors import TitleExtractor
from llama_index.core.ingestion import IngestionPipeline, IngestionCache

# 创建带有转换的管道
pipeline = IngestionPipeline(
    transformations=[
        SentenceSplitter(chunk_size=25, chunk_overlap=0),
        TitleExtractor(),
        OpenAIEmbedding(),
    ]
)

# 运行管道
nodes = pipeline.run(documents=[Document.example()])

请注意,在实际场景中,你会从SimpleDirectoryReader或Llama Hub中的其他读取器获取文档。

连接到向量数据库

运行摄取管道时,你还可以选择自动将结果节点插入到远程向量存储中。然后,你可以稍后从该向量存储构建索引。

from llama_index.core import Document
from llama_index
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

需要重新演唱

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

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

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

打赏作者

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

抵扣说明:

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

余额充值