開始使用免費開始

文字分割入門

開始分割吧!已提供一段關於 RAG 的敘述,儲存在字串變數 text 中。你的任務是遇到 '.' 字元就將這個字串切開。檢視分割結果,看看這個策略的表現如何。

本練習屬於課程

使用 LangChain 的 Retrieval Augmented Generation(RAG)

檢視課程

練習說明

  • 定義一個 LangChain 的字元文字分割器,以 '.' 字元作為分隔,chunk size 設為 75chunk 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])
編輯並執行程式碼