Beyond Compressing Everything: Contrastive Memory Learning for Selective Context Compression
Sikui Zhang, Haowei Liu, Ziyun Gan, Chunfeng Yuan, Guangze Gao, Nian Liu, Boyu Cai, Bo Li,
Key points
From the paper's conclusion- 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.
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. 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.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- From Long Context to Selective Memory:A Survey of Memory-Centric Compression for Large Language ModelsarXiv · 2026
- GACC-Bench: Benchmarking Goal-Adaptive Context Compression Ability across Large Language ModelsarXiv · 2026
- FlexComp: One Model for Every Ratio in Context CompressionarXiv · 2026
- Persistent Context Graphs for Efficient Memory Compaction in LLM AgentsarXiv · 2026
- HyCo 2 : Hybrid Context Compression with Global Semantics and Local EvidenceACM Transactions on Information Systems · 2026
- Latent Compaction with Test-Time TrainingarXiv · 2026