mlsanityData to 7 Oct 2026

Writing in the Margins: Better Inference Pattern for Long Context Retrieval

arXiv 2408.14906 ↗First posted 27 Aug 2024cs.CL cs.IRcited by 7

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

  1. 2017Attention Is All You Needcited by 59,932
  2. 2024The Llama 3 Herd of Modelscited by 14,192
  3. 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,302
  4. 2020Retrieval-Augmented Generation for Knowledge-Intensive NLP Taskscited by 9,160
  5. 2021Evaluating Large Language Models Trained on Codecited by 8,053
  6. 2023Efficient Memory Management for Large Language Model Serving with PagedAttentioncited by 5,767
  7. 2021RoFormer: Enhanced Transformer with Rotary Position Embeddingcited by 4,581
  8. 2018HotpotQA: A Dataset for Diverse, Explainable Multi-hop Question Answeringcited by 3,686
  9. 2021Program Synthesis with Large Language Modelscited by 3,509
  10. 2023Lost in the Middle: How Language Models Use Long Contextscited by 3,383
  11. 2023Tree of Thoughts: Deliberate Problem Solving with Large Language Modelscited by 3,155
  12. 2024Phi-3 Technical Report: A Highly Capable Language Model Locally on Your Phonecited by 1,883
25 more
  1. 2019Transformer-XL: Attentive Language Models Beyond a Fixed-Length Contextcited by 1,830
  2. 2018Know What You Don't Know: Unanswerable Questions for SQuADcited by 1,538
  3. 2023LongBench: A Bilingual, Multitask Benchmark for Long Context Understandingcited by 1,378
  4. 2024RULER: What's the Real Context Size of Your Long-Context Language Models?cited by 1,270
  5. 2020Leveraging Passage Retrieval with Generative Models for Open Domain Question Answeringcited by 1,203
  6. 2023Graph of Thoughts: Solving Elaborate Problems with Large Language Modelscited by 873
  7. 2021Show Your Work: Scratchpads for Intermediate Computation with Language Modelscited by 871
  8. 2019Generalization through Memorization: Nearest Neighbor Language Modelscited by 788
  9. 2023YaRN: Efficient Context Window Extension of Large Language Modelscited by 584
  10. 2023Learning to Compress Prompts with Gist Tokenscited by 379
  11. 2024MultiHop-RAG: Benchmarking Retrieval-Augmented Generation for Multi-Hop Queriescited by 253
  12. 2023Landmark Attention: Random-Access Infinite Context Length for Transformerscited by 206
  13. 2022Exploring Length Generalization in Large Language Modelscited by 204
  14. 2023LooGLE: Can Long-Context Language Models Understand Long Contexts?cited by 200
  15. 2023What Algorithms can Transformers Learn? A Study in Length Generalizationcited by 198
  16. 2024Leave No Context Behind: Efficient Infinite Context Transformers with Infini-attentioncited by 194
  17. 2023In-context Autoencoder for Context Compression in a Large Language Modelcited by 190
  18. 2023SARATHI: Efficient LLM Inference by Piggybacking Decodes with Chunked Prefillscited by 187
  19. 2023ZeroSCROLLS: A Zero-Shot Benchmark for Long Text Understandingcited by 175
  20. 2023Focused Transformer: Contrastive Training for Context Scalingcited by 133
  21. 2020Entities as Experts: Sparse Memory Access with Entity Supervisioncited by 100
  22. 2022Efficient Long-Text Understanding with Short-Text Modelscited by 71
  23. 2020Learning Associative Inference Using Fast Weight Memorycited by 51
  24. 2020INT: An Inequality Benchmark for Evaluating Generalization in Theorem Provingcited by 44
  25. 2022Relational Memory Augmented Language Modelscited by 24

Built on by

Cited by year

Citing papers per year: 2024: 1; 2025: 6.

7 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2024Inference Scaling for Long-Context Retrieval Augmented Generation
  2. 2025Grounding Long-Context Reasoning with Contextual Normalization for Retrieval-Augmented Generation
  3. 2024Contextual Compression in Retrieval-Augmented Generation for Large Language Models: A Survey
  4. 2025RAPID: Long-Context Inference with Retrieval-Augmented Speculative Decoding
  5. 2024BABILong: Testing the Limits of LLMs with Long Context Reasoning-in-a-Haystack
  6. 2023Retrieval meets Long Context Large Language Models
  7. 2025Eliciting In-context Retrieval and Reasoning for Long-context Large Language Models
  8. 2025Beyond RAG vs. Long-Context: Learning Distraction-Aware Retrieval for Efficient Knowledge Grounding