Encoding Context into LLM Weights: What Makes It Context?
Organizations: The University of Melbourne · RIKEN Center for Advanced Intelligence Project · The University of Tokyo · TMLR Group, Hong Kong Baptist University
Abstract
Longer contexts allow large language models (LLMs) to condition their predictions on more information, but inference costs grow prohibitively with context length. An emerging alternative uses test-time updates to encode context as temporary changes to model weights. However, encoding this information into weights that already represent general knowledge obscures its role as context, so the LLM may fail to use it properly to condition subsequent inference. To restore this contextual role, we first associate each context with an identifier during encoding, thereby distinguishing the newly encoded information from pre-existing knowledge. Invoking the identifier at inference then enables the LLM to recite the encoded context. Nevertheless, successful recitation does not ensure that the LLM will use the recalled information as context. We therefore further introduce a prompting framework that explicitly guides the LLM to use this information as context. Across diverse controlled tasks and practical benchmarks, our method outperformed the baseline using only off-the-shelf LLMs, showing its advances in context encoding.
Figures & tables
| LLM | Method | Prompt | Recall | Recognition | Continuation | Retention |
|---|---|---|---|---|---|---|
| Qwen3.5-4B | TCE | – | 6.1 | 0.5 | 0.0 | 100.0 |
| ACE | ci_short | 52.3 | 91.9 | 46.4 | 99.0 | |
| ACE | ci_v1 | 55.3 | 81.7 | 48.8 | 100.0 | |
| ACE | ci_v2 | 60.4 | 80.7 | 28.0 | 100.0 | |
| Qwen3.5-9B | TCE | – | 4.6 | 2.0 | 1.2 | 100.0 |
| ACE | ci_short | 40.1 | 96.4 | 9.5 | 100.0 |
| LLM | Method | Prompt | Counterfact | Dispute | Outdated | Counterfact |
|---|---|---|---|---|---|---|
| (two-sided) | ||||||
| Qwen3.5-4B | TCE | – | 3.5 | 7.0 | 5.9 | 0.5 |
| ACE | ci_short | 86.5 | 83.7 | 88.2 | 20.0 | |
| ACE | ci_v1 | 92.5 | 95.3 | 100.0 | 27.5 | |
| ACE | ci_v2 | 93.0 | 90.7 | 94.1 | 28.0 | |
| Qwen3.5-9B | TCE | – | 14.0 | 11.6 | 10.0 | 6.0 |
| LLM | Method | RULER | LongBench | LongBench v2 | ||
|---|---|---|---|---|---|---|
| NIAH-1 | NIAH-2 | NIAH-3 | ||||
| Qwen3.5-4B | Gold Standard | 100 | 100 | 100 | 20.8 | 2.5 |
| TCE | 98 | 7 | 0 | 8.8 | 0.0 | |
| ACE | 100 | 35 | 15 | 9.0 | 2.0 | |
| Qwen3.5-9B | Gold Standard | 100 | 100 | 100 | 20.3 | 3.0 |
| TCE | 88 | 7 | 1 | 8.2 | 2.5 | |
Appendix figures & tables36 assets
Supplementary material from the paper’s appendix.
Appendix
| LLM | Method | Cue | Recall | Recognition |
|---|---|---|---|---|
| Qwen3.5-4B | TCE | – | 6.1 | 0.5 |
| TCE-AM | – | 7.1 | 10.7 | |
| TCE-AM | UID | 5.6 | 35.5 | |
| ACE | ci_short | 52.3 | 91.9 | |
| Qwen3.5-9B | TCE | – | 4.6 | 2.0 |
| TCE-AM | – | 1.5 | 3.6 |
| LLM | Method | Recall | Recognition |
|---|---|---|---|
| Qwen3.5-4B | ACE w/o | 4.1 | 21.3 |
| ACE w/o | 37.1 | 49.7 | |
| ACE with TCE inference | 32.5 | 81.2 | |
| ACE w/o encoding | 0.0 | 0.0 | |
| ACE | 55.3 | 81.7 | |
| Qwen3.5-9B | ACE w/o | 7.6 | 17.3 |
| Method | Fast Weights | Recall | Recognition | Continuation | Retention | Counterfact | Dispute |
|---|---|---|---|---|---|---|---|
| TCE | FFN-1 | 6.1 | 0.5 | 0.0 | 100.0 | 3.5 | 7.0 |
| FFN-2 | 4.1 | 7.6 | 0.0 | 68.0 | 3.0 | 7.0 | |
| FFN-3 | 9.1 | 4.1 | 3.6 | 43.0 | 9.5 | 4.7 | |
| ATTN-1 | 5.6 | 0.0 | 0.0 | 84.0 | 0.5 | 2.3 | |
| ATTN-2 | 11.7 | 0.0 | 0.0 | 74.0 | 1.0 | 2.3 | |
| ATTN-3 | 9.6 | 0.0 | 0.0 | 69.0 | 2.5 | 2.3 |
| Method | Fast Weights | Recall | Recognition | Continuation | Retention | Counterfact | Dispute |
|---|---|---|---|---|---|---|---|
| TCE | FFN-1 | 4.6 | 2.0 | 1.2 | 100.0 | 14.0 | 11.6 |
| FFN-2 | 10.2 | 0.5 | 26.2 | 100.0 | 26.5 | 11.6 | |
| FFN-3 | 17.3 | 0.5 | 26.8 | 100.0 | 10.5 | 7.0 | |
| ATTN-1 | 14.2 | 0.0 | 0.6 | 100.0 | 19.5 | 14.0 | |
| ATTN-2 | 17.8 | 0.0 | 2.4 | 100.0 | 31.0 | 14.0 | |
| ATTN-3 | 23.9 | 0.0 | 2.4 | 100.0 | 35.5 | 16.3 |
| Method | Prompt | Recall | Recognition | Continuation | Retention | |
|---|---|---|---|---|---|---|
| 0.1 | TCE | – | 6.1 | 0.5 | 0.0 | 100.0 |
| ACE | ci_short | 52.3 | 91.9 | 46.4 | 99.0 | |
| ACE | ci_v1 | 55.3 | 81.7 | 48.8 | 100.0 | |
| ACE | ci_v2 | 60.4 | 80.7 | 28.0 | 100.0 | |
| 0.2 | TCE | – | 6.6 | 0.0 | 0.0 | 100.0 |
| ACE | ci_short | 51.3 | 86.3 | 45.8 | 99.0 |
| Method | Prompt | Counterfact | Dispute | Outdated | Counterfact | |
|---|---|---|---|---|---|---|
| (two-sided) | ||||||
| 0.1 | TCE | – | 3.5 | 7.0 | 5.9 | 0.5 |
| ACE | ci_short | 86.5 | 83.7 | 88.2 | 20.0 | |
| ACE | ci_v1 | 92.5 | 95.3 | 100.0 | 27.5 | |
| ACE | ci_v2 | 93.0 | 90.7 | 94.1 | 28.0 | |
| 0.2 | TCE | – | 4.5 | 4.7 | 5.9 | 1.5 |
| Method | Prompt | Recall | Recognition | Continuation | Retention | |
|---|---|---|---|---|---|---|
| 0.1 | TCE | – | 4.6 | 2.0 | 1.2 | 100.0 |
| ACE | ci_short | 40.1 | 96.4 | 9.5 | 100.0 | |
| ACE | ci_v1 | 35.5 | 95.4 | 13.7 | 100.0 | |
| ACE | ci_v2 | 38.1 | 94.4 | 5.4 | 100.0 | |
| 0.2 | TCE | – | 4.1 | 0.5 | 0.6 | 100.0 |
| ACE | ci_short | 37.1 | 86.8 | 8.3 | 100.0 |
| Method | Prompt | Counterfact | Dispute | Outdated | Counterfact | |
|---|---|---|---|---|---|---|
| (two-sided) | ||||||
| 0.1 | TCE | – | 14.0 | 11.6 | 10.0 | 6.0 |
| ACE | ci_short | 94.0 | 95.3 | 100.0 | 29.0 | |
| ACE | ci_v1 | 94.5 | 95.3 | 100.0 | 30.5 | |
| ACE | ci_v2 | 95.0 | 97.7 | 100.0 | 30.5 | |
| 0.2 | TCE | – | 15.0 | 11.6 | 10.0 | 10.0 |
| Method | Prompt | Recall | Recognition | Continuation | Retention | |
|---|---|---|---|---|---|---|
| 0.1 | TCE | – | 1.5 | 0.0 | 0.0 | 100.0 |
| ACE | ci_short | 75.6 | 98.0 | 20.8 | 100.0 | |
| ACE | ci_v1 | 39.1 | 58.4 | 11.9 | 100.0 | |
| ACE | ci_v2 | 45.2 | 50.8 | 2.4 | 100.0 | |
| 0.2 | TCE | – | 2.0 | 0.0 | 0.0 | 100.0 |
| ACE | ci_short | 71.6 | 83.8 | 0.6 | 100.0 |
| Method | Prompt | Counterfact | Dispute | Outdated | Counterfact | |
|---|---|---|---|---|---|---|
| (two-sided) | ||||||
| 0.1 | TCE | – | 11.0 | 18.6 | 54.5 | 8.0 |
| ACE | ci_short | 96.0 | 97.7 | 97.0 | 36.5 | |
| ACE | ci_v1 | 93.0 | 88.4 | 100.0 | 29.0 | |
| ACE | ci_v2 | 92.0 | 93.0 | 97.0 | 31.5 | |
| 0.2 | TCE | – | 41.0 | 18.6 | 54.5 | 36.0 |
| LLM | Method | Prompt | |||
|---|---|---|---|---|---|
| Qwen3.5-4B | TCE | – | 0.0 | 0.0 | 0.0 |
| ACE | ci_short | 50.0 | 48.2 | 38.1 | |
| ACE | ci_v1 | 53.6 | 52.4 | 49.4 | |
| ACE | ci_v2 | 31.5 | 31.0 | 28.6 | |
| Qwen3.5-9B | TCE | – | 1.2 | 0.6 | 0.0 |
| ACE | ci_short | 28.0 | 21.4 | 1.2 |
| LLM | Method | Prompt | Dispute control | Counterfact control | ||||
|---|---|---|---|---|---|---|---|---|
| Qwen3.5-4B | TCE | – | 74.4 | 79.1 | 81.4 | 64.0 | 68.0 | 81.0 |
| ACE | ci_short | 79.1 | 81.4 | 79.1 | 76.5 | 77.0 | 80.0 | |
| ACE | ci_v1 | 81.4 | 81.4 | 79.1 | 76.0 | 77.0 | 81.5 | |
| ACE | ci_v2 | 81.4 | 81.4 | 81.4 | 79.0 | 80.0 | 82.0 | |
| Qwen3.5-9B | TCE | – | 81.4 | 81.4 | 81.4 | 82.5 | 82.5 | 82.5 |
| Updates | Method | Recall | Recognition | NIAH-2 |
|---|---|---|---|---|
| 2 | TCE | 3.0 | 0.0 | 0.0 |
| ACE | 15.2 | 0.0 | 0.0 | |
| 4 | TCE | 1.5 | 1.5 | 0.0 |
| ACE | 45.7 | 62.4 | 1.0 | |
| 8 | TCE | 2.0 | 27.9 | 8.0 |
| ACE | 58.9 | 98.5 | 16.0 |
| Updates | Method | Recall | Recognition | NIAH-2 |
|---|---|---|---|---|
| 2 | TCE | 3.0 | 0.0 | 0.0 |
| ACE | 10.2 | 0.0 | 0.0 | |
| 4 | TCE | 4.1 | 1.0 | 0.0 |
| ACE | 34.0 | 79.2 | 1.0 | |
| 8 | TCE | 0.5 | 70.6 | 5.0 |
| ACE | 44.7 | 99.5 | 8.0 |
| Updates | Method | Recall | Recognition | NIAH-2 |
|---|---|---|---|---|
| 2 | TCE | 0.5 | 0.0 | 0.0 |
| ACE | 12.7 | 0.0 | 0.0 | |
| 4 | TCE | 2.0 | 0.0 | 0.0 |
| ACE | 40.1 | 15.2 | 0.0 | |
| 8 | TCE | 2.0 | 6.6 | 5.0 |
| ACE | 42.6 | 99.0 | 21.0 |
| LLM | Contextual answer | Prior answer ( ACE ) | ||
|---|---|---|---|---|
| TCE | ACE | With invocation | Without invocation | |
| Qwen3.5-4B | 3.5 | 86.5 | 25.5 | 31.5 |
| Qwen3.5-9B | 14.0 | 94.0 | 33.5 | 29.0 |
| Qwen3.5-27B | 11.0 | 96.0 | 39.0 | 35.5 |
| LLM | Method | Recall | Recognition | NIAH-2 |
|---|---|---|---|---|
| Qwen3.5-4B | TCE | 6.1 | 0.5 | 7.0 |
| TCE with generic invocation | 2.0 | 0.0 | 10.0 | |
| ACE | 55.3 | 81.7 | 35.0 | |
| Qwen3.5-9B | TCE | 4.6 | 2.0 | 7.0 |
| TCE with generic invocation | 9.1 | 1.5 | 7.0 | |
| ACE | 35.5 | 95.4 | 17.0 |
| LLM | ACE with shared UID | ACE |
|---|---|---|
| Qwen3.5-4B | 66.0 | 81.7 |
| Qwen3.5-9B | 91.9 | 95.4 |
| Qwen3.5-27B | 47.7 | 58.4 |
| LLM | Method | Recall | Recognition | NIAH-2 |
|---|---|---|---|---|
| Qwen3.5-4B | ACE with alternative wording | 54.3 | 28.9 | 33.0 |
| ACE | 55.3 | 81.7 | 32.0 | |
| Qwen3.5-9B | ACE with alternative wording | 34.5 | 77.7 | 14.0 |
| ACE | 35.5 | 95.4 | 15.0 | |
| Qwen3.5-27B | ACE with alternative wording | 41.6 | 76.1 | 47.0 |
| ACE | 39.1 | 58.4 | 39.0 |
| LLM | Method | Prompt | NIAH-1 | NIAH-2 | NIAH-3 | |
|---|---|---|---|---|---|---|
| Qwen3.5-4B | 0.1 | TCE | – | 98.0 | 7.0 | 0.0 |
| ACE | ci_short | 99.0 | 30.0 | 18.0 | ||
| ACE | ci_v1 | 100.0 | 32.0 | 13.0 | ||
| ACE | ci_v2 | 100.0 | 35.0 | 15.0 | ||
| 0.2 | TCE | – | 100.0 | 8.0 | 0.0 | |
| ACE | ci_short | 99.0 | 26.0 | 19.0 |
| LLM | Method | Prompt | NIAH-1 | NIAH-2 | NIAH-3 | |
|---|---|---|---|---|---|---|
| Qwen3.5-27B | 0.1 | TCE | – | 85.0 | 7.0 | 0.0 |
| ACE | ci_short | 100.0 | 45.0 | 33.0 | ||
| ACE | ci_v1 | 100.0 | 39.0 | 31.0 | ||
| ACE | ci_v2 | 100.0 | 40.0 | 29.0 | ||
| 0.2 | TCE | – | 80.0 | 9.0 | 0.0 | |
| ACE | ci_short | 99.0 | 41.0 | 33.0 |
| LLM | Method | |||
|---|---|---|---|---|
| Qwen3.5-4B | Gold Standard | 20.8 | 20.8 | 20.8 |
| TCE | 7.0 | 8.8 | 8.6 | |
| ACE | 7.8 | 9.0 | 10.0 | |
| Qwen3.5-9B | Gold Standard | 20.3 | 20.3 | 20.3 |
| TCE | 7.4 | 8.2 | 9.2 | |
| ACE | 10.8 | 9.6 | 10.1 |
| Method | Prompt | NIAH-1 | NIAH-2 | NIAH-3 | |
|---|---|---|---|---|---|
| 0.1 | TCE | – | 71.0 | 76.0 | 75.3 |
| ACE | ci_short | 72.3 | 75.8 | 75.3 | |
| ACE | ci_v1 | 72.0 | 73.8 | 73.3 | |
| ACE | ci_v2 | 71.0 | 72.5 | 72.8 | |
| 0.2 | TCE | – | 71.5 | 76.0 | 75.5 |
| ACE | ci_short | 72.8 | 75.5 | 75.0 |
| Method | Prompt | NIAH-1 | NIAH-2 | NIAH-3 | |
|---|---|---|---|---|---|
| 0.1 | TCE | – | 75.5 | 77.0 | 76.5 |
| ACE | ci_short | 67.0 | 74.5 | 73.5 | |
| ACE | ci_v1 | 62.5 | 72.5 | 70.0 | |
| ACE | ci_v2 | 58.8 | 71.0 | 67.5 | |
| 0.2 | TCE | – | 75.8 | 77.3 | 76.8 |
| ACE | ci_short | 68.8 | 74.5 | 74.0 |
| Method | Prompt | NIAH-1 | NIAH-2 | NIAH-3 | |
|---|---|---|---|---|---|
| 0.1 | TCE | – | 79.3 | 80.0 | 80.3 |
| ACE | ci_short | 82.0 | 81.8 | 81.5 | |
| ACE | ci_v1 | 80.8 | 80.8 | 80.8 | |
| ACE | ci_v2 | 81.0 | 80.5 | 79.5 | |
| 0.2 | TCE | – | 79.3 | 80.0 | 80.3 |
| ACE | ci_short | 82.0 | 81.8 | 81.3 |
| Method | Prompt | NIAH-1 | NIAH-2 | NIAH-3 | |
|---|---|---|---|---|---|
| 0.1 | TCE | – | 66.3 | 72.8 | 69.5 |
| ACE | ci_short | 76.5 | 76.0 | 76.0 | |
| ACE | ci_v1 | 75.5 | 75.0 | 75.3 | |
| ACE | ci_v2 | 76.8 | 76.8 | 76.5 | |
| 0.2 | TCE | – | 66.3 | 71.3 | 64.3 |
| ACE | ci_short | 76.5 | 76.0 | 76.3 |
| LLM | Correct UID | Decoy UID |
|---|---|---|
| Qwen3.5-4B | 87.0 | 1.0 |
| Qwen3.5-9B | 84.0 | 8.0 |
| Qwen3.5-27B | 100.0 | 4.0 |
| LLM | Gold Standard | TCE | ACE |
|---|---|---|---|
| Qwen3.5-9B | 100.0 | 30.0 | 80.0 |
| Qwen3.5-27B | 100.0 | 40.0 | 70.0 |
| Muse-Glimmer-30B | 100.0 | 20.0 | 30.0 |
| LLM | NIAH-2 | NIAH-3 | ||||
|---|---|---|---|---|---|---|
| Gold Standard | TCE | ACE | Gold Standard | TCE | ACE | |
| Qwen3.5-4B | 100.0 | 3.3 | 6.7 | 100.0 | 0.0 | 3.3 |
| Qwen3.5-9B | 100.0 | 6.7 | 16.7 | 100.0 | 0.0 | 3.3 |
| Qwen3.5-27B | 100.0 | 3.3 | 20.0 | 100.0 | 0.0 | 13.3 |
| Muse-Glimmer-30B | 100.0 | 10.0 | 16.7 | 100.0 | 3.3 | 20.0 |
| Dataset | Method | Encoding | Steps | Throughput | Response | Output |
|---|---|---|---|---|---|---|
| time (s) | per chunk | (tokens/s) | latency (s) | tokens | ||
| Sandbox | Full context | – | – | – | 0.64 | 11 |
| TCE | 1.10 | 6.0 | 15 | 4.74 | 123 | |
| ACE | 1.34 | 7.0 | 13 | 0.88 | 17 | |
| RULER NIAH-1 | Full context | – | – | – | 0.63 | 9 |
| TCE | 10.08 | 40.0 | 82 | 4.89 | 128 |
| Dataset | Method | Encoding | Steps | Throughput | Response | Output |
|---|---|---|---|---|---|---|
| time (s) | per chunk | (tokens/s) | latency (s) | tokens | ||
| Sandbox | Full context | – | – | – | 0.68 | 11 |
| TCE | 0.98 | 5.0 | 17 | 3.63 | 90 | |
| ACE | 1.18 | 6.0 | 14 | 2.85 | 72 | |
| RULER NIAH-1 | Full context | – | – | – | 0.66 | 9 |
| TCE | 7.31 | 28.0 | 113 | 4.98 | 128 |
| Dataset | Method | Encoding | Steps | Throughput | Response | Output |
|---|---|---|---|---|---|---|
| time (s) | per chunk | (tokens/s) | latency (s) | tokens | ||
| Sandbox | Full context | – | – | – | 1.11 | 11 |
| TCE | 1.92 | 5.0 | 9 | 6.82 | 87 | |
| ACE | 2.44 | 6.0 | 7 | 5.95 | 73 | |
| RULER NIAH-1 | Full context | – | – | – | 1.25 | 9 |
| TCE | 11.97 | 21.0 | 69 | 9.72 | 128 |
| Dataset | Method | Encoding | Steps | Throughput | Response | Output |
|---|---|---|---|---|---|---|
| time (s) | per chunk | (tokens/s) | latency (s) | tokens | ||
| RULER NIAH-1 | Full context | – | – | – | 0.57 | 5 |
| TCE | 3.36 | 10.0 | 235 | 0.14 | 1 | |
| ACE | 9.56 | 15.0 | 82 | 7.15 | 128 | |
| LongBench | Full context | – | – | – | 5.55 | 64 |
| TCE | 5.87 | 1.7 | 1009 | 3.87 | 64 |
| LLM | Dataset | Encoding | Inference | |||
| TCE | ACE | Full context | TCE | ACE | ||
| Qwen3.5-4B | Sandbox | 1.5 | 13.7 | 0.4 | 1.22 | 0.83 |
| RULER NIAH-1 | 336.5 | 926.4 | 6.6 | 1.43 | 1.94 | |
| LongBench | 326.1 | 929.6 | 44.9 | 0.75 | 2.26 | |
| LongBench v2 | 1003.6 | 2522.3 | 131.9 | 2.07 | 6.05 | |
| Qwen3.5-9B | Sandbox | 2.4 | 22.1 | 0.8 | 1.79 | 2.47 |
| LLM | Dataset | Method | KV cache (MiB) |
|---|---|---|---|
| Qwen3.5-4B | Sandbox | Full context | 1.4 |
| TCE | 0.8 | ||
| ACE | 3.0 | ||
| RULER NIAH-1 | Full context | 28.2 | |
| TCE | 1.6 | ||
| ACE | 3.8 |
| LLM | Dataset | Method | KV cache (MiB) |
|---|---|---|---|
| Qwen3.5-27B | Sandbox | Full context | 2.8 |
| TCE | 1.7 | ||
| ACE | 6.1 | ||
| RULER NIAH-1 | Full context | 56.5 | |
| TCE | 3.1 | ||
| ACE | 7.6 |
LLM Context Management
Large language model context management studies how to select, compress, retrieve, and organize information within bounded model inputs.
See all 246 papers