llamaindex 摄取管道(Ingestion Pipeline)

摄取管道(Ingestion Pipeline)

概念解释

摄取管道(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.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
from llama_index.vector_stores.qdrant import QdrantVectorStore

import qdrant_client

client = qdrant_client.QdrantClient(location=":memory:")
vector_store = QdrantVectorStore(client=client, collection_name="test_store"
为标题 'Ingestion Pipeline 0.21.1' 编写正则表达式,需要考虑匹配的灵活度。以下是几种不同场景下的正则表达式示例及解释: ### 精确匹配 如果需要精确匹配 'Ingestion Pipeline 0.21.1' 这个标题,可以使用以下正则表达式: ```regex ^Ingestion Pipeline 0\.21\.1$ ``` 解释: - `^` 表示字符串的开始。 - `Ingestion Pipeline 0\.21\.1` 是精确匹配的内容,其中 `.` 是特殊字符,需要使用 `\.` 进行转义。 - `$` 表示字符串的结束。 ### 匹配版本号部分 如果想匹配标题中版本号部分可变的情况,例如 'Ingestion Pipeline 0.21.1'、'Ingestion Pipeline 1.2.3' 等,可以使用以下正则表达式: ```regex ^Ingestion Pipeline \d+\.\d+\.\d+$ ``` 解释: - `^` 表示字符串的开始。 - `Ingestion Pipeline` 是固定匹配的部分。 - `\d+` 表示匹配一个或多个数字。 - `\.` 是对 `.` 进行转义。 - `$` 表示字符串的结束。 ### 匹配更宽泛的标题 如果标题中 'Ingestion Pipeline' 部分也可能有一些变化,例如大小写不同或者有额外的空格等,可以使用以下正则表达式: ```regex ^[Ii]ngestion [Pp]ipeline \d+\.\d+\.\d+$ ``` 解释: - `^` 表示字符串的开始。 - `[Ii]` 表示匹配 `I` 或 `i`。 - `[Pp]` 表示匹配 `P` 或 `p`。 - `\d+` 表示匹配一个或多个数字。 - `\.` 是对 `.` 进行转义。 - `$` 表示字符串的结束。 ### Python 代码示例 以下是使用 Python 代码测试上述正则表达式的示例: ```python import re # 精确匹配 pattern1 = r'^Ingestion Pipeline 0\.21\.1$' text1 = 'Ingestion Pipeline 0.21.1' match1 = re.match(pattern1, text1) print(f"精确匹配结果: {bool(match1)}") # 匹配版本号部分 pattern2 = r'^Ingestion Pipeline \d+\.\d+\.\d+$' text2 = 'Ingestion Pipeline 1.2.3' match2 = re.match(pattern2, text2) print(f"匹配版本号部分结果: {bool(match2)}") # 匹配更宽泛的标题 pattern3 = r'^[Ii]ngestion [Pp]ipeline \d+\.\d+\.\d+$' text3 = 'ingestion pipeline 0.21.1' match3 = re.match(pattern3, text3) print(f"匹配更宽泛的标题结果: {bool(match3)}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

需要重新演唱

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

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

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

打赏作者

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

抵扣说明:

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

余额充值