เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

เริ่มต้นใช้งานการแบ่งข้อความ

ถึงเวลาลองแบ่งข้อความกันแล้ว! มีข้อความเกี่ยวกับ RAG เก็บอยู่ในตัวแปรสตริง text งานของคุณคือแบ่งสตริงนี้ที่ตำแหน่งของอักขระ '.' จากนั้นตรวจสอบผลลัพธ์เพื่อดูว่ากลยุทธ์นี้ได้ผลเป็นอย่างไร

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Retrieval Augmented Generation (RAG) ด้วย LangChain

ดูคอร์ส

คำแนะนำการฝึกหัด

  • กำหนด character text splitter ของ LangChain ให้แบ่งข้อความที่อักขระ '.' โดยกำหนด chunk size เป็น 75 และ chunk overlap เป็น 10
  • แบ่ง text โดยใช้ text_splitter ที่กำหนดไว้

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

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])
แก้ไขและรันโค้ด