Reviewing a contract depends on following threads across the document. "Licensed Product" is defined on page one and used on page eleven. A party named in the preamble must be named the same way in every later obligation. A cap stated in one section must match the figure restated in another. Language models are poor at following these threads. On ContractScrub, a benchmark of attorney-annotated drafting errors in real contracts, recall drops sharply once a reference sits more than 10,000 characters from the clause it depends on. This happens even though the 10–15 page contracts fit easily inside a modern context window (ContractScrub). The failure therefore comes from attention spreading too thin over a long document, and running out of memory is a separate, additional problem. A related negative result from the inference-efficiency literature points the same way: compressing the model's working memory without regard to content discards exactly the spans a task depends on (The Pitfalls of KV Cache Compression).
We propose to organize a model's working memory around named, human-readable concept clusters, which we call threads: one per defined term, party, numeric quantity, and clause type. The memory budget is allocated so that every thread relevant to the clause under review keeps its defining text. A "KV cache" is the store of per-token key and value vectors a transformer keeps so it can attend back to earlier text. Pruning it is the standard way to fit long inputs into fixed memory. Here the pruning is driven by discrete concept clusters instead of raw vector similarity. Each flagged or missed error then comes with a trace showing which threads were active and which of their spans survived. The setting is a compact 8B model specialized on contract review. We test two claims. The first is that concept-structured retention flattens the distance penalty, possibly beating full context, as unstructured selective attention has been reported to do on general benchmarks. The second is that the cluster trace is faithful enough to tell whether a miss came from forgetting or from faulty reasoning.
Core Claim
The claim is that a non-contiguous, concept-labeled partition of a long document is the right unit for allocating attention memory in thread-structured domain tasks. Allocating budget fairly across the threads that are active at decoding time should recover cross-clause errors that both full-context prompting and similarity-based cache clustering miss. It should also yield explanations that can be checked by intervening on the cache.
Three bodies of work motivate and constrain this. KV-cache clustering methods already show that grouping tokens saves memory without large accuracy loss. ClusterAttn runs density-based clustering on attention scores to keep head-specific token clusters. CentroidKV merges similar key states into centroids. CHESS builds a page/chunk/grid hierarchy and selects coarse-to-fine against a recent query. CHESS also reports that a 1% budget can outperform the full cache on LongBenchV2 (33.2 vs. 30.2), which motivates our hope of beating full context. Its "distraction phase" at intermediate budgets is a warning that retention can hurt. All three methods form clusters as geometric artifacts with no names and no tie to document semantics, and none is evaluated on legal or clinical tasks. We supply the clusters from document semantics and keep their selection machinery as the comparison.
The Pitfalls of KV Cache Compression supplies the allocation principle. Its "fair eviction" gives each prompt span a proportional retention budget, which fixes instructions being disproportionately forgotten. Its spans are contiguous and hand-marked. Contract threads are neither: a defined term's definition and its forty uses are scattered. We generalize fair eviction from contiguous spans to overlapping concept clusters that are discovered automatically.
Topic-bottleneck classifiers supply the clustering method. CANTM trains a variational topic model jointly with a BERT classifier, so that topics align with classes. On COVID-19 disinformation it reaches 63.34% accuracy against 58.78% for BERT and 48.17% for SCHOLAR, and its topic perplexity is 749 against 8518 for LDA. TopicBERT pairs a bag-of-words topic model with a BERT encoder that reads only a short partition of the text. It shows that a global topic signal can stand in for full-sequence attention in document classification. Both apply topics only at the input, to short or medium documents, and never touch generation-time memory. We reuse CANTM's classification-aware topic training, with CUAD's 41 clause types as the supervising labels, and apply the resulting clusters inside the cache during decoding.
Research Program
The system has three parts.
The first is a thread extractor that runs once per contract. It segments the contract into sentence-level spans and assigns each span to zero or more threads. Lexical threads come from a deterministic pass that finds defined terms (quoted capitalized definitions), party names, section cross-references, and numeric amounts. Each such thread has an anchor span, the definition or first statement. Semantic threads come from a classification-aware neural topic model in the style of CANTM. It is trained on the CUAD contracts not used in ContractScrub, with the 41 clause categories from CUAD as supervision. Each semantic thread is named by its top words and its aligned clause type. A span that paraphrases an obligation, such as "the Indemnifying Party shall hold harmless…", can thus join the indemnification thread without sharing a defined term.
The second is thread-fair retention during decoding. At each review step, the active threads $A$ are those the current clause, plus a short recent-token window, belongs to. Each active thread $c$ gets a retention budget
$$b_c = \max\!\left(m,\; B \cdot \frac{w_c}{\sum_{c' \in A} w_{c'}}\right),$$
where $B$ is the total token budget for thread-routed memory, $w_c$ is the attention mass the current query places on thread $c$'s spans (estimated from page-level key summaries, as in CHESS), and $m$ is a floor that guarantees every active thread's anchor span is kept. Within a thread, tokens are ranked by attention as in standard eviction. A fixed sink-and-recent window is always kept. The floor $m$ addresses the selective-amnesia failure. The attention weighting $w_c$ keeps the scheme from spending budget on irrelevant threads, which is our hypothesis for avoiding the distraction phase.
The third is domain specialization and traces. We fine-tune Llama-3.1-8B-Instruct, a model already used in the CentroidKV evaluations, to perform scrubbing. The training data are held-out CUAD contracts with synthetically inserted errors of the nine ContractScrub categories, following that benchmark's insertion protocol, with the 44 ContractScrub contracts strictly excluded. The model is trained under the same retention policy it will use at test time, so it learns to work from the retained memory. Each output error is logged with its active threads, their names, and the fraction of each thread's tokens retained. Interpretability is tested by intervention rather than by inspecting the logs: deleting a thread's anchor from the cache should cause the predicted change in output.
The work does not shorten the prefill pass over the prompt. That cost stays quadratic, and we report it.
Baselines
The naive reference point is the same specialized 8B model given the full contract with no cache pruning, and with a chain-of-thought prompt as a second condition. ContractScrub reports chain-of-thought adds about 0.10 recall for top models. If thread-fair retention cannot match this, it at best saves memory. Beating it on items more than 10,000 characters from their anchor is the central result.
The strongest external reference is frontier full-context prompting as reported by ContractScrub. GPT-5.5 reached a macro-average recall of 0.750, no model exceeded F1 of 0.650, and models averaged 0.351 recall on undefined capitalized terms. We cannot rerun those systems under matched compute, so we compare against these published numbers on the identical 44-contract, 3,014-task set with the benchmark's own multiset scorer. Our success criterion is an 8B model that matches 0.750 macro recall or exceeds 0.650 F1 at a fraction of the reported $1.38 per contract.
The strongest compression competitors are ClusterAttn, CentroidKV, CHESS, and fair eviction with automatic contiguous spans (sections split by headings). They run on the same base and fine-tuned checkpoints at matched retained-token budgets of 5%, 10%, 25%, and 50%. Each method gets the same number of hyperparameter configurations, tuned on a synthetic development set drawn from non-ContractScrub CUAD contracts. No reported result was found on Lacuna for any of these methods on ContractScrub or CUAD, so all of those numbers will be produced here. Beating them means higher recall at every matched budget, and a smaller recall drop between the near and far distance buckets.
The key ablation keeps our allocation rule and anchor floor fixed but swaps the cluster source. One variant uses unlabeled key-similarity clusters, as in CentroidKV. Another uses lexical threads only. A third uses semantic threads only. If unlabeled clusters perform as well, the semantic bottleneck adds nothing to accuracy, and its only remaining value is the trace. We would report that outcome as such.
Why not just…?
Why not just prepend a glossary of defined terms to every chunk? This is the most serious threat. A regex-built glossary directly targets missing and undefined defined terms and costs almost nothing. We run it as a baseline with the same model, in both chunked and full-context variants. We expect it to match our method on defined-term categories. Our claim rests on the non-lexical categories, such as incorrect party references in paraphrased obligations, inconsistent language, and numeric restatements. A glossary does not reach those categories, and the reported 0.351 recall on undefined terms suggests even lexical threads are not trivially solved. If the glossary matches us across all categories, we will report that the cache mechanism is unnecessary for contracts of this length. The cluster trace would then remain only as an analysis tool.
Why not just use fair eviction with sections as spans? Section-level fair eviction protects each part of the document but cannot keep a page-one definition specifically when page eleven needs it. The definition competes for budget with every other sentence of its section. The thread-versus-section comparison at matched budget isolates exactly this difference. If sections perform as well, non-contiguity does not matter for these documents.
Why not just pass the full contract to a long-context frontier model? The contracts already fit, and the distance penalty and 0.650 F1 ceiling are measured in exactly that setting. Larger scale also does not appear to cure it: ContractScrub found the 397B Qwen 3.5 performed like o4-mini. For 100-page CUAD contracts, full attention also runs into memory. ClusterAttn reports out-of-memory failures near 40k tokens on an A100-80GB GPU.
Why not just retrieve or compress the relevant context with a trained compressor, as in CORE-RAG? CORE-RAG trains a 1–3B compressor with reinforcement learning on downstream QA reward. It keeps about 3–6% of tokens and beats full documents by 3.3 exact-match points on Natural Questions. Its output, however, is free-form rewritten text. LegalHalluLens shows 65–74% hallucination rates on obligation and numeric claims, so a rewritten contract can introduce the very errors scrubbing is meant to find. We include a retrieve-anchors-then-review pipeline: BM25 over spans, keyed on the terms in the current clause. It isolates whether keeping the anchors in the cache adds anything beyond putting them back in the prompt.
Proposed Experiments
The primary evaluation is ContractScrub. We report macro recall, F1, per-category recall, and recall bucketed by the character distance between error and anchor (under 2k, 2–10k, over 10k). The decisive check is the slope across distance buckets. Thread-fair retention should cut the far-bucket drop by at least half relative to full context and to every compression baseline at matched budget, while holding the near-bucket recall.
Budget sweeps from 5% to 50% test whether the method shows the distraction-phase dip that CHESS reports for unstructured selection.
The memory-bound regime is CUAD clause extraction on full 100+ page contracts. We use AUPR and precision at 80% recall. The published references are DeBERTa-xlarge at 47.8% AUPR and 44.0% precision at 80% recall, obtained with sliding windows. The test is whether thread-routed memory on the 8B model beats sliding windows at the same peak memory.
Interpretability gets a causal test. For a sample of correctly flagged far-distance errors, we evict the anchor of the thread the trace names and measure the recall drop. We compare against evicting a random retained span of equal length. The trace counts as faithful if the targeted eviction causes a markedly larger drop. For misses, we classify each one as "anchor evicted" or "anchor retained" from the logs. Restoring the anchor should recover a substantial share of the evicted-anchor misses and few of the retained-anchor misses.
As a transfer check, without new labels, we apply the same extractor to medication and diagnosis threads on MedAlign. There, GPT-4 lost 8.3% accuracy when its context was cut from 32k to 2k tokens. We ask only whether thread-fair retention at a 2k budget closes part of that gap, scored with the benchmark's clinician-aligned protocol on a small rated subset.
References
- ContractScrub: A benchmark for final review of legal contracts
- The Pitfalls of KV Cache Compression
- ClusterAttn: KV Cache Compression under Intrinsic Attention Clustering
- Efficient Long-Context LLM Inference via KV Cache Clustering
- CHESS: Context-aware Hierarchical Efficient Semantic Selection for Long-Context LLM Inference
- Classification aware neural topic model for COVID-19 disinformation categorisation
- TopicBERT for Energy Efficient Document Classification
- CUAD: An Expert-Annotated NLP Dataset for Legal Contract Review
- Less Is More: Elevating RAG via Performance-Driven Context Compression
- LegalHalluLens: Typed Hallucination Failure Modes and Calibrated Multi-Agent Debate Mitigation
- MedAlign: A Clinician-Generated Dataset for Instruction Following with Electronic Medical Records