Writing in the Margins: Better Inference Pattern for Long Context Retrieval
Not on the map. Why?
Abstract (arXiv)
In this paper, we introduce Writing in the Margins (WiM), a new inference pattern for Large Language Models designed to optimize the handling of long input sequences in retrieval-oriented tasks. This approach leverages the chunked prefill of the key-value cache to perform segment-wise inference, which enables efficient processing of extensive contexts along with the generation and classification of intermediate information ("margins") that guide the model towards specific tasks. This method increases computational overhead marginally while significantly enhancing the performance of off-the-shelf models without the need for fine-tuning. Specifically, we observe that WiM provides an average enhancement of 7.5% in accuracy for reasoning skills (HotpotQA, MultiHop-RAG) and more than a 30.0% increase in the F1-score for aggregation tasks (CWE). Additionally, we show how the proposed pattern fits into an interactive retrieval design that provides end-users with ongoing updates about the progress of context processing, and pinpoints the integration of relevant information into the final response. We release our implementation of WiM using Hugging Face Transformers library at https://github.com/writer/writing-in-the-margins.
Key facts. Cited by 7 papers in the map (data through 7 Oct 2026). Builds on 37 of its 50 references that are in the map. First posted on arXiv 27 Aug 2024.
Builds on
37 of 50 references.
References · 37
- 2017Attention Is All You Needcited by 59,932
- 2024The Llama 3 Herd of Modelscited by 14,192
- 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,302
- 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2023Efficient Memory Management for Large Language Model Serving with PagedAttentioncited by 5,767
- 2021RoFormer: Enhanced Transformer with Rotary Position Embeddingcited by 4,581
- 2018HotpotQA: A Dataset for Diverse, Explainable Multi-hop Question Answeringcited by 3,686
- 2021Program Synthesis with Large Language Modelscited by 3,509
- 2023Lost in the Middle: How Language Models Use Long Contextscited by 3,383
- 2023Tree of Thoughts: Deliberate Problem Solving with Large Language Modelscited by 3,155
- 2024Phi-3 Technical Report: A Highly Capable Language Model Locally on Your Phonecited by 1,883
25 more
- 2019Transformer-XL: Attentive Language Models Beyond a Fixed-Length Contextcited by 1,830
- 2018Know What You Don't Know: Unanswerable Questions for SQuADcited by 1,538
- 2023LongBench: A Bilingual, Multitask Benchmark for Long Context Understandingcited by 1,378
- 2024RULER: What's the Real Context Size of Your Long-Context Language Models?cited by 1,270
- 2020Leveraging Passage Retrieval with Generative Models for Open Domain Question Answeringcited by 1,203
- 2023Graph of Thoughts: Solving Elaborate Problems with Large Language Modelscited by 873
- 2021Show Your Work: Scratchpads for Intermediate Computation with Language Modelscited by 871
- 2019Generalization through Memorization: Nearest Neighbor Language Modelscited by 788
- 2023YaRN: Efficient Context Window Extension of Large Language Modelscited by 584
- 2023Learning to Compress Prompts with Gist Tokenscited by 379
- 2024MultiHop-RAG: Benchmarking Retrieval-Augmented Generation for Multi-Hop Queriescited by 253
- 2023Landmark Attention: Random-Access Infinite Context Length for Transformerscited by 206
- 2022Exploring Length Generalization in Large Language Modelscited by 204
- 2023LooGLE: Can Long-Context Language Models Understand Long Contexts?cited by 200
- 2023What Algorithms can Transformers Learn? A Study in Length Generalizationcited by 198
- 2024Leave No Context Behind: Efficient Infinite Context Transformers with Infini-attentioncited by 194
- 2023In-context Autoencoder for Context Compression in a Large Language Modelcited by 190
- 2023SARATHI: Efficient LLM Inference by Piggybacking Decodes with Chunked Prefillscited by 187
- 2023ZeroSCROLLS: A Zero-Shot Benchmark for Long Text Understandingcited by 175
- 2023Focused Transformer: Contrastive Training for Context Scalingcited by 133
- 2020Entities as Experts: Sparse Memory Access with Entity Supervisioncited by 100
- 2022Efficient Long-Text Understanding with Short-Text Modelscited by 71
- 2020Learning Associative Inference Using Fast Weight Memorycited by 51
- 2020INT: An Inequality Benchmark for Evaluating Generalization in Theorem Provingcited by 44
- 2022Relational Memory Augmented Language Modelscited by 24
Built on by
Citing papers per year: 2024: 1; 2025: 6.
7 papers.
- 2025A Survey of Context Engineering for Large Language Modelscited by 120
- 2025Cartridges: Lightweight and general-purpose long context representations via self-studycited by 74
- 2024Star Attention: Efficient LLM Inference over Long Sequencescited by 25
- 2025Minions: Cost-efficient Collaboration Between On-device and Cloud Language Modelscited by 17
- 2025Unstructured Evidence Attribution for Long Context Query Focused Summarizationcited by 5
- 2025KV Pareto: Systems-Level Optimization of KV Cache and Model Compression for Long Context Inferencecited by 4
- 2025Stress Testing Factual Consistency Metrics for Long-Document Summarizationcited by 2
- 2025KV Pareto: Systems-Level Optimization of KV Cache and Model Compression for Long Context Inference1 Dec 2025
- 2025Stress Testing Factual Consistency Metrics for Long-Document Summarization10 Nov 2025
- 2025A Survey of Context Engineering for Large Language Models17 Jul 2025
- 2025Cartridges: Lightweight and general-purpose long context representations via self-study6 Jun 2025
- 2025Minions: Cost-efficient Collaboration Between On-device and Cloud Language Models21 Feb 2025
- 2025Unstructured Evidence Attribution for Long Context Query Focused Summarization20 Feb 2025
- 2024Star Attention: Efficient LLM Inference over Long Sequences26 Nov 2024
Similar, not cited
Close in wording, no citation either way
- 2024Inference Scaling for Long-Context Retrieval Augmented Generation
- 2025Grounding Long-Context Reasoning with Contextual Normalization for Retrieval-Augmented Generation
- 2024Contextual Compression in Retrieval-Augmented Generation for Large Language Models: A Survey
- 2025RAPID: Long-Context Inference with Retrieval-Augmented Speculative Decoding
- 2024BABILong: Testing the Limits of LLMs with Long Context Reasoning-in-a-Haystack
- 2023Retrieval meets Long Context Large Language Models
- 2025Eliciting In-context Retrieval and Reasoning for Long-context Large Language Models
- 2025Beyond RAG vs. Long-Context: Learning Distraction-Aware Retrieval for Efficient Knowledge Grounding