रिट्रीवल के लिए बाहरी डेटा को स्प्लिट करना

LangChain के साथ LLM एप्लिकेशन विकसित करना

Jonathan Bennion

AI Engineer & LangChain Contributor

RAG डेवलपमेंट स्टेप्स

जनरल RAG वर्कफ़्लो: एक डॉक्यूमेंट लोडर, डॉक्यूमेंट स्प्लिटर, और स्टोरेज व रिट्रीवल प्रोसेस.

  • Document splitting: डॉक्यूमेंट को chunks में बाँटें
  • LLM की context window{{1}} में फिट करने के लिए डॉक्यूमेंट तोड़ें
LangChain के साथ LLM एप्लिकेशन विकसित करना

स्प्लिटिंग के बारे में सोचना...

"Attention is All You Need" पेपर की भूमिका का पहला पैराग्राफ.

Line 1:

Recurrent neural networks, long short-term memory [13] and gated recurrent [7] neural networks

Line 2:

in particular, have been firmly established as state of the art approaches in sequence modeling and
1 https://arxiv.org/abs/1706.03762
LangChain के साथ LLM एप्लिकेशन विकसित करना

Chunk overlap

"Attention is All You Need" पेपर की भूमिका का पहला पैराग्राफ, दो chunks में ओवरलैप के साथ स्प्लिट किया हुआ.

LangChain के साथ LLM एप्लिकेशन विकसित करना

सबसे अच्छा डॉक्यूमेंट स्प्लिटिंग स्ट्रैटेजी क्या है?

शब्द "context" को अलग-अलग अक्षरों में chunk किया हुआ.

 

  1. CharacterTextSplitter
  2. RecursiveCharacterTextSplitter
  3. और भी कई
1 Wikipedia Commons
LangChain के साथ LLM एप्लिकेशन विकसित करना
quote = '''One machine can do the work of fifty ordinary humans.\nNo machine can do
the work of one extraordinary human.'''
len(quote)
103
chunk_size = 24
chunk_overlap = 3
1 Elbert Hubbard
LangChain के साथ LLM एप्लिकेशन विकसित करना
from langchain_text_splitters import CharacterTextSplitter


ct_splitter = CharacterTextSplitter( separator='.', chunk_size=chunk_size, chunk_overlap=chunk_overlap)
docs = ct_splitter.split_text(quote) print(docs)
print([len(doc) for doc in docs])
['One machine can do the work of fifty ordinary humans',
 'No machine can do the work of one extraordinary human']

[52, 53]
  • सेपरेटर पर स्प्लिट करें ताकि लंबाई chunk_size से कम हो, लेकिन हर बार सफल नहीं होगा!
LangChain के साथ LLM एप्लिकेशन विकसित करना
from langchain_text_splitters import RecursiveCharacterTextSplitter


rc_splitter = RecursiveCharacterTextSplitter( separators=["\n\n", "\n", " ", ""], chunk_size=chunk_size, chunk_overlap=chunk_overlap)
docs = rc_splitter.split_text(quote) print(docs)
LangChain के साथ LLM एप्लिकेशन विकसित करना

RecursiveCharacterTextSplitter

  • separators=["\n\n", "\n", " ", ""]
['One machine can do the',
 'work of fifty ordinary',
 'humans.',
 'No machine can do the',
 'work of one',
 'extraordinary human.']
  1. पैराग्राफ से स्प्लिट आज़माएँ: "\n\n"
  2. वाक्य से स्प्लिट आज़माएँ: "\n"
  3. शब्दों से स्प्लिट आज़माएँ: " "
LangChain के साथ LLM एप्लिकेशन विकसित करना

HTML के साथ RecursiveCharacterTextSplitter

from langchain_community.document_loaders import UnstructuredHTMLLoader 
from langchain_text_splitters import RecursiveCharacterTextSplitter


loader = UnstructuredHTMLLoader("white_house_executive_order_nov_2023.html") data = loader.load()
rc_splitter = RecursiveCharacterTextSplitter( chunk_size=chunk_size, chunk_overlap=chunk_overlap, separators=['.'])
docs = rc_splitter.split_documents(data) print(docs[0])
Document(page_content="To search this site, enter a search term [...]
LangChain के साथ LLM एप्लिकेशन विकसित करना

अभ्यास करते हैं!

LangChain के साथ LLM एप्लिकेशन विकसित करना

Preparing Video For Download...