Retrieval Is the Memory
LongMem’s cache becomes useful only when a current token can find the right part of it and the model can decide how much that retrieved past should matter. This chapter follows that path from a token query to contiguous chunks, back to token-level key-value pairs, and then through two attention results mixed by a learned gate. The point is practical: an external bank does not provide long-term memory by its size alone; retrieval granularity, fusion, and capacity determine what the model can actually use.
From a token query to a chunk of memory
LongMem does not treat the cache as an unstructured archive in which every token is searched independently. It groups cached key-value pairs into contiguous chunks. For each chunk, the key vectors are mean-pooled across the chunk dimension to create a compact key for indexing. A query from the current token is compared with these pooled chunk keys, and the highest-scoring chunks are selected. The selected chunks are then expanded back into their token-level key-value pairs before they enter the memory-augmented layer.
This is a deliberate compromise between retrieval precision and context integrity. Searching individual cached tokens could offer fine granularity, but it would make the retrieval index larger and could return scattered pieces that no longer preserve the local structure of the original text. Searching chunks reduces the number of index entries and returns neighboring tokens together. The model gives up some freedom to select an isolated token in exchange for a retrieval unit that carries a small amount of surrounding context.
The process for one current token has several distinct transitions. First, the current hidden state produces a query. Second, that query addresses the index of mean-pooled chunk keys using an inner-product similarity. Third, the index returns the highest-scoring chunks rather than the final token-level records. Fourth, LongMem expands those chunks so the memory-augmented layer receives the original key-value pairs within each selected span. Only then can the current token attend to the retrieved memory at token level.
The distinction between index representation and retrieved representation matters. The mean-pooled key is a search aid; it is not the complete memory content that the SideNet consumes. A chunk can be selected because its pooled key resembles the current query, while the individual keys and values inside the chunk provide the finer information used for fusion. Retrieval therefore has two possible mismatch points: the pooled key may rank the wrong chunk, or a correctly selected chunk may contain more or less detail than the current token needs.
The choice of contiguous chunks also preserves a limited form of local meaning. A demonstration example, a sentence, or a short passage often depends on neighboring tokens. Returning the entire surrounding span can help the reader use that relationship instead of seeing an isolated label or fragment. But the same choice can return distractors. Chunking does not solve relevance; it defines the unit at which relevance is judged and the amount of context that arrives after a match.
Chunk size is consequently a workload parameter.