Skip to content

Context Rot: Quality Degradation with Increasing Context

Summary

Context Rot is the systematic decline in model accuracy as the length of the input context increases, even within the stated limit.

Definition

Context Rot (context degradation) is a phenomenon where the quality of LLM generation monotonically decreases as the number of tokens in the input grows, regardless of whether the query fits within the context window. Unlike a hard limit breach, degradation occurs gradually: the model starts ignoring parts of the instruction, losing facts from the middle of the input, and mixing entities.

Key difference from Lost in the Middle: the latter describes positional unevenness of attention, whereas Context Rot tracks a general decline in quality as a function of length.

Mechanisms

Factor Influence
Positional encoding Weakening signal at longer distances
Noise accumulation Relevant tokens blurred by irrelevant ones
Instruction conflict Contradictory instructions in different parts of the input
Limited attention capacity Weight distribution over a large number of positions
graph LR
    A[Short context] --> B[High accuracy]
    A --> C[Stable instruction following]
    D[Long context] --> E[Accuracy drop]
    D --> F[Facts lost]
    D --> G[Ignoring parts of prompt]

Measurement

Degradation is assessed through controlled experiments: the same task is presented with varying amounts of irrelevant context. Metrics include accuracy, faithfulness, and the proportion of correct extractions.

import statistics

def measure_context_rot(model, task, filler_sizes):
    results = []
    for size in filler_sizes:
        prompt = task + "\n" + ("noise " * size)
        answer = model.generate(prompt)
        results.append({
            "tokens": size,
            "correct": evaluate(answer, task.expected),
        })
    return results

Practical Techniques

Relation to Other Concepts

Context Rot directly impacts the quality of RAG systems: an increase in the number of extracted chunks does not always improve accuracy. When designing a RAG pipeline, limit the amount of input context and test for degradation on evaluation sets.