Keeping Both Ends of a Reference When Compressing Long Documents

Long-document models fail in a specific and repeatable way. A defined term on page 2 governs a clause on page 14, or a function defined in one file is called in another, and the model has to connect the two. As the distance between the two ends grows, current systems stop making the connection. This holds for models that read the whole document and for systems that shrink the prompt first. We propose to take these connections out of the model's hands. A cheap deterministic pass reads the document's own structure (definitions, section numbers, cross-references, symbol tables, citation records) and produces a small "reference ledger" of which spans point to which other spans. We then use the ledger in two ways during prompt compression. It protects both ends of every relevant link from being pruned. It also moves each definition so it sits directly beside the text that uses it, which turns a dependency spanning tens of thousands of tokens into one spanning a few dozen.

The opportunity is concrete. On final legal-contract review, the best model reaches only 0.750 macro recall, and recall drops once a reference sits more than 10,000 characters from its target (ContractScrub). Attention-based prompt compression keeps 90–100% of full-prompt performance on general benchmarks but degrades on code debugging at aggressive keep rates, where distributed dependencies matter (Cross-Family Speculative Prefill). We think these are the same failure. The two ends of a link are far apart, and nothing in the attention pattern or the draft model's importance scores guarantees that both ends survive and get connected. Structural metadata can guarantee this, and it costs almost nothing to compute.

Core Claim

Distance-dependent failures in long-document tasks can be largely removed by a compression step that is constrained by metadata. Such a step preserves every query-relevant definition–use link and places the two endpoints next to each other. The claim is falsifiable in a specific way. If it holds, the curve of recall against reference distance on ContractScrub should flatten. Code Debug accuracy at a 15% keep rate should recover toward the full-prompt level. Generic benchmarks such as RULER should not get worse. If a flat glossary prepended to the prompt achieves the same flattening, then placing definitions beside their uses is not the active ingredient, and the claim reduces to "give the model a symbol table."

This builds on two pieces of prior work. The first is the side-information idea: metadata computed outside the token stream can steer a model without spending input positions. Hoang et al. showed this by fusing title and keyword vectors before the softmax of a recurrent language model, which lowered TED perplexity from 53.1 to 51.1 (Incorporating Side Information into RNNLMs). GRIT showed it by replacing raw table rows with a compact schema of primary-key/foreign-key links found using probabilistic sketches, which cut memory by over 97% and improved multi-join Spider queries by up to 19.71% (GRIT). We carry GRIT's move of "discover the relations cheaply, then hand the model a compact relational view" from database tables over to unstructured long documents and code. The second piece is compression: we reuse the draft-model token scoring and contiguous-position trick from Cross-Family Speculative Prefill. The departures from that work are two. Its token choice is purely attention-driven, whereas ours is constrained by the ledger. It also preserves the original token order, whereas we reorder deliberately.

Research Program

The ledger builder is domain-specific but shallow, and it never calls the target model. For contracts, it extracts defined-term declarations ("'Closing Date' means…"), capitalized-term uses, section-number cross-references ("pursuant to Section 7.2"), and exhibit mentions. For code, it builds a symbol table of definitions and call sites from a parser. For multi-document inputs such as Ref-Long-Paper, it records each document's index along with its title and citation metadata. That citation metadata is the one place where genuinely external, cross-resource side information enters. Following GRIT, candidate uses are matched to definitions using exact and fuzzy string containment, with Bloom filters when documents are large. Each ledger entry is a pair (use span, definition span) with a confidence score.

Compression then works as follows. Let $s_i$ be the draft model's importance score for token $i$, $B$ the token budget, and $L_q$ the set of ledger links whose use span is itself among the high-scoring tokens for query $q$. We choose the kept set $K$ as

$$K = \arg\max_{|K| \le B} \sum_{i \in K} s_i \quad \text{subject to } \mathrm{def}(\ell) \subseteq K \text{ for all } \ell \in L_q,$$

where $\mathrm{def}(\ell)$ is the definition span of link $\ell$. In words, we fill the budget greedily by score after first reserving room for the definitions the kept text depends on. The reordering step then inserts each protected definition span, marked with lightweight source tags in the style of MISTI's title and section separator tokens, immediately after its first kept use. The tags record the original location, so the model can still cite provenance. Contiguous position IDs are assigned as in Speculative Prefill. The whole procedure needs no training.

The analysis centers on distance. For every gold error or answer, we record the character distance between the dependent spans and bin results by that distance. This lets us test directly whether the ContractScrub distance penalty is a property of the model or of how the prompt is laid out.

Baselines

The naive reference point is the target model reading the full document, or reading a truncated version when the document exceeds the window. For ContractScrub, the strongest existing number is GPT-5.5 at 0.750 macro recall, with no model above 0.650 F1 (ContractScrub). We will not beat a frontier model with a smaller target model in absolute terms. Our claim is therefore relative: on the same open target model, ledger-constrained compression should raise recall on references beyond 10,000 characters to within the range of its short-distance recall. We also run the full-context frontier configuration where budget allows, reported with chain-of-thought prompting, since the file reports that chain of thought adds about 0.10 recall.

The strongest compression competitor is Cross-Family Speculative Prefill, a Qwen draft model pruning prompts for a LLaMA target. It is the closest method: training-free, same setting, and it reports 90–100% retention on RULER and LongBench. We run it with the identical draft model, target model, and keep rates of 15%, 30%, and 50%. For Code Debug, no reported numeric result was found on Lacuna for InfiniteBench Code Debug at a 15% keep rate, only a "noticeable drop." We therefore reproduce it ourselves. Beating it means higher accuracy at equal token budget on Code Debug and ContractScrub, and no loss larger than one point on RULER.

We also include CORE-RAG, which trains a compressor with reinforcement learning against Exact Match and F1 rewards and reports +3.3 EM on NQ over full documents (Less Is More). We run it on the multi-document QA subsets where its reward applies, at a matched token budget. Our method has no training cost, and we report that asymmetry explicitly rather than hiding it.

Three ablations isolate the key ingredients. Protection-only keeps definitions but leaves them in their original positions. Glossary-prepend places all protected definitions in a block at the top of the prompt. Oracle-ledger uses gold links. We also inject noise into the ledger at 10–30% false and missing links, because KALM warns that errors in upstream entity linking cascade into the downstream model.

Why not just…?

Why not just use a model with a 128k window and read everything? On ContractScrub, full-context frontier models still show the distance penalty and plateau at 0.750 recall. On Ref-Long, GPT-4o scores 14% against 92% for humans at 24k tokens (Ref-Long). Latency is also a cost: uncompressed 128k prompts take 46 seconds to first token in the Speculative Prefill measurements. The full-context arm of our experiments directly measures whether our compressed prompts close the distance gap that long windows leave open.

Why not just prepend a glossary or symbol table? This is the most serious threat. It is exactly the "concatenate metadata into the prompt" move. For short documents, it may well match our method. The glossary-prepend ablation settles the question. If reordering matters, glossary-prepend should flatten the distance curve less than co-location does, because the glossary merely moves the long-range dependency to a new position; it does not remove it. The finding that fusion placement mattered for side information in recurrent models (Incorporating Side Information into RNNLMs) is a reason to expect placement effects, but it does not prove them. If glossary-prepend matches co-location, we will report the simpler method as the result.

Why not just write a rule-based checker? For some ContractScrub categories, a script could plausibly outperform LLMs. Undefined capitalized terms, where models reach only 0.351 recall, are a clear case. We include a ledger-only rule baseline that flags any use without a matching definition. The proposal's value lies in the error classes rules cannot judge: a term used inconsistently with its definition, or a cross-reference pointing to the wrong clause. For those, the rules find the candidate pairs and the model judges them. Results are reported per category so that any categories where the rules alone win are visible.

Why not just retrieve chunks with BM25 or dense search? Chunk retrieval matches the query, not the dependency. A clause's definition rarely shares vocabulary with the question. BM25 left about 30% irrelevant records in MedAlign, and graph-structured memory beat both BM25 and neural retrieval on long-document QA in JERR. We include top-$k$ BM25 at a matched budget as an additional arm.

Proposed Experiments

The primary testbed is ContractScrub: 44 contracts and 3,014 tasks, scored by recall and F1 per error category and binned by reference distance. The secondary testbed is InfiniteBench Code Debug at the three keep rates. Ref-Long-Paper serves as the multi-document provenance test; the best reported result there is Qwen2.5-72B at 40.00% Exact Match. RULER and LongBench act as controls that the method must not damage. All arms share a LLaMA target with a 32k window, a Qwen draft model, identical token budgets, and a single prompt template tuned once on a held-out set of five contracts.

The decisive check is the slope of recall against distance. Suppose ledger-constrained co-location brings recall beyond 10,000 characters to within five points of recall under 2,000 characters, while Speculative Prefill and glossary-prepend leave a gap of ten points or more. That result supports the claim that layout, not model capacity, drives the distance penalty. If the gap persists under the oracle ledger, the claim is wrong, and the failure lies in the model's reasoning rather than in which tokens survive. The noise-injection curve then tells practitioners how accurate a ledger must be before this approach pays off.