Temporal Context Reinstatement Drives Episodic-Like Order Memory in Long-Context Language Models
Abstract
Human episodic memory supports the retrieval of experiences that unfold over extended timescales, yet the computational mechanisms underlying this ability remain debated due to the limited mechanistic accessibility in long-term memory experiments in humans. Long-context LLMs may offer promising ways to reveal plausible computational mechanisms that drive this type of retrieval. Here, we investigate whether and how LLMs capture the core behavioral signatures of episodic memory via a temporal order memory task. Using a new dataset of human behavior based on memory of a full-length novel, we show that models exhibit the same characteristic distance effect observed in humans on this task. We next apply long-context mechanistic interpretability analyses to uncover how models solve this task, and find that model performance relies on a one-dimensional temporal code that is reinstated during retrieval by a single time-reinstatement attention head. These findings support temporal context reinstatement as an important mechanism for episodic-like temporal-order memory in LLMs, offering new insights into how temporal aspects of long-term episodic memory may be instantiated in both artificial and biological systems.
Lay Summary
When we recall a past experience, we remember not just what happened but its place in time, which events came before others. This sense of temporal order is a core feature of episodic memory and fundamental to human thought, yet how the brain reconstructs the order of past events remains poorly understood, partly because we cannot easily watch the brain in the act of remembering. In this work, we use large language models (LLMs) as a transparent model system for this question. Unlike the brain, the internal computation in an LLM can be inspected and directly altered. We recruited people who had recently finished a full-length novel and asked them to judge which of two passages appeared earlier in the book, then gave the same test to LLMs. Both reproduced a striking signature of human memory: people and models alike were far more accurate when the two passages were widely separated in the story than when they sat close together. Looking inside the models, we found that this ability hinges on a single internal component that builds a simple internal "timeline" of the text as it reads and replays that timeline when asked about order. The component isn't leaning on the plot: when we scrambled the narrative while leaving the words intact, performance held up. This shows the models rely on a sense of position laid down as they read, not on reconstructing order from the story's logic. Disabling this one component pushes the models' order judgments back toward guessing, while strengthening it improves them. Our results point to a concrete mechanism — reinstating a stored sense of time during recall — that may help explain how temporal order is represented in both artificial and biological memory systems. Along the way, we release the first dataset of human memory for the temporal order of events in a full-length book, together with an open-source toolkit for studying long-context memory in LLMs.