文本分割入门
开始分割吧!已为您提供了一段关于 RAG 的陈述,保存在字符串变量 text 中。您的任务是按 '.' 字符出现的位置来切分该字符串。请查看分割结果,了解这种策略的效果。
本练习是课程的一部分
使用 LangChain 的 Retrieval Augmented Generation (RAG)
练习说明
- 定义一个 LangChain 的字符文本分割器,使其按
'.'字符进行切分,chunk size为75,chunk overlap为10。 - 使用您定义的
text_splitter来分割text。
交互式实操练习
通过完成这段示例代码来试试这个练习。
text = '''RAG (retrieval augmented generation) is an advanced NLP model that combines retrieval mechanisms with generative capabilities. RAG aims to improve the accuracy and relevance of its outputs by grounding responses in precise, contextually appropriate data.'''
# Define a text splitter that splits on the '.' character
text_splitter = ____(
____,
____,
____
)
# Split the text using text_splitter
chunks = text_splitter.____
print(chunks)
print([len(chunk) for chunk in chunks])