Warum naives Chunking den Abruf verschlechtert
Analysieren Sie konkrete Fehler beim Abruf, die durch schlechtes Chunking entstehen, darunter über Chunk-Grenzen hinweg aufgeteilte Antworten sowie verlorener Kontext aus Überschriften und Abschnittstiteln.
Warum naives Chunking den Abruf verschlechtert ist eine kostenlose AI Engineering Academy-Lektion auf CoddyKit. Dies ist Lektion 1 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des AI Engineering Academy-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der AI Engineering Academy-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
The Cost of Poor Chunking
Chunking is the process of splitting documents into smaller pieces before embedding them into a vector store. The way you chunk determines what context is available during retrieval. Poor chunking is one of the most common and impactful causes of RAG system failures.
Answers Split Across Boundaries
Imagine a document that says: 'The refund policy is 30 days from purchase. Customers must include the original receipt.' If a fixed-size splitter cuts after 'purchase.', these two sentences land in different chunks. A query about the refund policy may only retrieve the first half — making the model unable to mention the receipt requirement.
Lost Context from Headers
Documents often use section headers to provide meaning. Consider a table titled 'Pricing for Enterprise Plans' followed by rows of numbers. If the header and the table land in different chunks, the retrieved table chunk contains numbers with no label — the model cannot answer 'What is the Enterprise price?' correctly.
Fixed-Size Chunking Pitfalls
Fixed-size chunking splits text every N characters or tokens regardless of sentence boundaries. This is fast and simple but breaks mid-sentence frequently. A chunk ending with 'The model was trained on' and a following chunk starting with 'a dataset of 500 billion tokens' are each meaningless without the other.
from langchain.text_splitter import CharacterTextSplitter
# Naive fixed-size: may break mid-sentence
splitter = CharacterTextSplitter(chunk_size=200, chunk_overlap=0)
chunks = splitter.split_text(document_text)
print(f'Created {len(chunks)} chunks')
print('First chunk:', chunks[0])Overlap Does Not Always Help
A common fix is adding chunk overlap — repeating the last N tokens of a chunk at the start of the next. This helps with split sentences but introduces redundancy and can confuse retrievers when two highly similar chunks both get retrieved. Overlap is a band-aid, not a cure for structural chunking problems.
# Overlap helps partially but adds redundancy
splitter = CharacterTextSplitter(
chunk_size=500,
chunk_overlap=50 # last 50 chars repeated in next chunk
)
chunks = splitter.split_text(document_text)Measuring Retrieval Failure Rate
You can measure how often your chunking hurts retrieval by building a small golden evaluation set: a list of questions with known correct source passages. Then check how often the correct passage is in the top-k retrieved chunks. A low hit rate often reveals chunking problems before you even look at generation quality.
def hit_rate(queries_and_answers, retriever, k=5):
hits = 0
for query, expected_text in queries_and_answers:
results = retriever.retrieve(query, k=k)
retrieved_texts = [r.page_content for r in results]
if any(expected_text in text for text in retrieved_texts):
hits += 1
return hits / len(queries_and_answers)Code and Structured Data Problems
Code files, JSON, and tables have logical units — functions, objects, table rows — that should not be split. Splitting a Python function definition across two chunks means neither chunk is independently understandable. A retriever that finds the second chunk sees argument-less code with no context.
# Bad: splits code arbitrarily
bad_chunk_1 = 'def calculate_price(item, qty' # incomplete!
bad_chunk_2 = ', discount):\n return item.price * qty * (1 - discount)'
# Good: keep the full function together
good_chunk = 'def calculate_price(item, qty, discount):\n return item.price * qty * (1 - discount)'Long Documents and Middle Content Loss
Research on LLMs shows the 'lost in the middle' phenomenon: when many chunks are retrieved and stuffed into a prompt, the model pays attention to content near the beginning and end but tends to ignore the middle. Poor chunking that produces many small low-quality chunks makes this worse by diluting the relevant signal.
Diagnosing Bad Chunks Manually
A quick diagnostic is to print a random sample of your chunks and read them. Ask yourself: Is this chunk meaningful in isolation? If a user asked a question, could the model answer it from this chunk alone? Chunks that reference undefined pronouns ('He said that...'), incomplete code, or context-free numbers are red flags.
import random
def audit_chunks(chunks, sample_size=10):
sample = random.sample(chunks, min(sample_size, len(chunks)))
for i, chunk in enumerate(sample):
print(f'--- Chunk {i+1} ({len(chunk)} chars) ---')
print(chunk[:300])
print()When Chunk Size Is Too Large
Very large chunks hurt retrieval precision. A 2000-token chunk about a broad topic may match many queries but deliver too much noise to the LLM. The model has to find the needle in the haystack within that chunk. Smaller, focused chunks improve precision at the cost of potentially missing surrounding context.
Strategies That Fix These Problems
Better alternatives to naive fixed-size chunking include: sentence-boundary splitting that never cuts mid-sentence, semantic chunking that splits at topic boundaries, parent-child chunking that preserves broader context, and document-aware splitting that respects code functions, HTML tags, and Markdown headers. Each lesson ahead covers one of these.
Quick Check
Test your understanding of chunking failure modes from this lesson.
Lesson Recap
In this lesson you learned: naive fixed-size chunking breaks sentence and section boundaries, overlap is a partial fix but adds redundancy, and chunk quality directly determines retrieval hit rate. Next up we explore semantic chunking, which splits text at natural topic boundaries using embedding similarity.
Häufig gestellte Fragen
Ist die Lektion „Warum naives Chunking den Abruf verschlechtert“ kostenlos?
Ja — der vollständige Text von „Warum naives Chunking den Abruf verschlechtert“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des AI Engineering Academy-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der AI Engineering Academy-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Warum naives Chunking den Abruf verschlechtert“?
Analysieren Sie konkrete Fehler beim Abruf, die durch schlechtes Chunking entstehen, darunter über Chunk-Grenzen hinweg aufgeteilte Antworten sowie verlorener Kontext aus Überschriften und Abschnitts… Du übst AI Engineering Academy mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um AI Engineering Academy zu starten?
Keine Vorkenntnisse erforderlich. AI Engineering Academy auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 1 von 4.
Wie lange dauert die Lektion „Warum naives Chunking den Abruf verschlechtert“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser AI Engineering Academy-Lektion Code schreiben und ausführen?
Ja. Jede AI Engineering Academy-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Warum naives Chunking den Abruf verschlechtert
- Semantisches Chunking mit Embedding-Ähnlichkeit
- Parent-Child- und Small-to-Big-Retrieval
- Dokumentspezifische Strategien für Code und HTML