Beyond Compressing Everything: Contrastive Memory Learning for Selective Context Compression

Sikui Zhang, Haowei Liu, Ziyun Gan, Chunfeng Yuan, Guangze Gao +7 more
11/12/2026
cs.CLcs.AI

Official code: scar-on/CoMem (1 star, Python, last commit 2026-11-12).

Abstract

As large language models (LLMs) advance toward increasingly long inputs, soft context compression offers a promising approach to efficient inference by converting long inputs into compact memory slots. Under limited memory budgets, effective context compression remains challenging because task-relevant evidence varies substantially across queries, ranging from localized evidence to multiple distant spans or information dispersed throughout the full document.

Show full abstract

Instead of compressing everything indiscriminately, we propose CoMem, a query-guided selective context compression framework that learns memory representations conditioned on both the document and the query. CoMem develops Contrastive Compressor Learning to achieve query-sensitive yet context-preserving memory representations. To inject a strong prior over query-dependent evidence distributions, we devise a same-context hard negative mining strategy by pairing a single document with multiple queries, requiring the compressor to selectively retain information according to each query's distinct evidence needs. To address the restricted information flow imposed by causal masking, we further enable bidirectional attention among memory slots. Experiments demonstrate that CoMem consistently outperforms existing context compression methods across compression ratios on question answering and RULER-NIAH benchmarks. Our code is available at https://github.com/scar-on/CoMem.

View on arXivView PDF

Code Implementations(1)

scar-on/CoMemOfficial100%
10Python, ShellNov 5, 20262 weeks agoNOASSERTION

Similar Papers

Cite this paper

@article{zhang2026beyond,
  title  = {Beyond Compressing Everything: Contrastive Memory Learning for Selective Context Compression},
  author = {Sikui Zhang and Haowei Liu and Ziyun Gan and Chunfeng Yuan and Guangze Gao and Nian Liu and Boyu Cai and Bo Li and Xiaolei Lv and Jun Gao and Bing Li and Weiming Hu},
  year   = {2026},
  eprint = {2611.16384},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2611.16384v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2611.16384.svg)](https://codeofpaper.com/paper/2611.16384)

Discussion