テキスト分割を始めましょう
さっそく分割してみましょう。text という文字列変数に、RAG に関する説明が入っています。あなたの役割は、この文字列を '.' 文字の出現箇所で分割することです。分割結果を確認して、この戦略がどのように機能したかを見てみましょう。
この演習はコースの一部です
LangChain で学ぶ Retrieval Augmented Generation (RAG)
演習の手順
'.'文字で分割し、チャンクサイズを75、チャンクのオーバーラップを10にする LangChain の文字ベースのテキストスプリッターを定義してください。- 定義した
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])