Performance: Semantic chunking strategies
Semantic chunking affects how quickly and efficiently large text data is processed and rendered in applications using Langchain.
from langchain.text_splitter import RecursiveCharacterTextSplitter splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=100) chunks = splitter.split_text(text)
chunks = [text[i:i+1000] for i in range(0, len(text), 1000)]
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Naive fixed-size chunking | N/A | N/A | N/A | [X] Bad |
| Semantic-aware chunking with RecursiveCharacterTextSplitter | N/A | N/A | N/A | [OK] Good |
text = "Hello world. This is a test. Langchain helps chunk text." chunks = chunk_text(text, chunk_size=12, chunk_overlap=4) print(chunks)What is the expected output?
chunks = chunk_text(text, chunk_size=100, chunk_overlap=150)What is the likely cause of the error?
Pass the test and this pattern moves unknown