Performance: Overlap and chunk boundaries
This concept affects how quickly and efficiently text data is processed and retrieved in Langchain, impacting response time and memory usage.
text_chunks = [] chunk_size = 500 overlap = 50 for i in range(0, len(text), chunk_size - overlap): text_chunks.append(text[i:i+chunk_size]) embeddings = [embed(chunk) for chunk in text_chunks]
text_chunks = text.split('\n\n') # Splitting only by paragraphs without overlap embeddings = [embed(chunk) for chunk in text_chunks]
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No overlap chunking | N/A | N/A | N/A | [X] Bad |
| Overlap chunking with controlled boundaries | N/A | N/A | N/A | [OK] Good |
splitter = RecursiveCharacterTextSplitter(chunk_size=50, chunk_overlap=10) text = "abcdefghij" * 10 chunks = splitter.split_text(text) print(len(chunks))What will be the output number of chunks?
splitter = RecursiveCharacterTextSplitter(chunk_size=50, chunk_overlap=60) chunks = splitter.split_text(long_text)What is the likely cause of the error?
Pass the test and this pattern moves unknown