# MemCode: Discrete Semantic Representations for Long-Term Agent Memory

*Xin Li, Liang Hu, Duoqian Miao, Ming Peng, Qi Zhang*

[NeurIPS page](https://neurips.cc/virtual/2026/poster/152904) · [OpenReview](https://openreview.net/forum?id=PYZcd99axs) · [Open on the map](../papers.html#p152904)

Category: [LLM Reasoning, Memory & RAG](../pcat/19.md) › [Reasoning Trace Memory Systems](../pgroup/31.md) · Type: new method · Keywords: discrete semantic memory, atomic memory units, learnable codebook, isomorphic semantic quantization, dual retrieval, LLM agent memory

Areas: [Memory](../areas/memory.md) › Agent Memory Systems › Agent Memory; [Long Context](../areas/longcontext.md) › Long-context mechanisms › Agent memory representations; [AI Agents](../areas/agents.md) › Agent Capabilities › LLM Agent Memory

## Summary
MemCode introduces a discrete semantic memory framework that rewrites dialogue into atomic memory units, maps them into a learnable codebook with isomorphic semantic quantization, and uses codebook co-occurrence topology as an additional retrieval path, achieving higher accuracy and faster memory construction for LLM agents.

## Explained to a 5-year-old
A robot friend talks with you over many days and needs to remember what you said. It breaks those talks into tiny, self-contained pieces. It stores the pieces in a special box that groups similar pieces together. When it wants to remember something, it looks both at the box and at similar pieces to find the right memory. This makes the robot remember faster and more reliably, and it also writes new pieces right away and later organizes them.

## Explained to a 5-year-old, longer
A robot friend talks with you over many days and needs to remember what you said. It stores those talks in a memory bank so it can bring up old conversations later. The old way of storing memories works like a fuzzy picture that can change a little each time. This fuzzy picture sometimes makes it hard to find the right memory, especially when the words are different but the meaning is the same. The new idea breaks each conversation into tiny, self-contained pieces, like small story blocks. Each block contains everything needed to understand that piece of the conversation on its own. These blocks are placed into a special box that groups similar blocks together. The box works like a codebook: similar blocks are stored near each other, making them easy to find. When the robot wants to remember something, it looks both at the box and at the similar blocks to locate the right memory. This dual search helps it find memories that are logically related even if they use different words. The robot also writes new blocks right away and later organizes the whole box to keep it tidy. Because of these improvements, the robot can recall memories faster, more reliably, and with less effort.

## For a technical reader
MemCode is a memory framework for LLM agents that stores dialogue as discrete atomic units rather than continuous embeddings. It maps these units into a learnable codebook using isomorphic semantic quantization and adds a retrieval path based on codebook co-occurrence topology. The design separates online writes from offline consolidation, allowing fast per-dialogue memory construction while improving accuracy and retrieval speed.

## Problem
Long-term memory for LLM agents suffers from unstable access units and difficulty retrieving logically related but lexically distant evidence.

## Method
The approach rewrites dialogue into self-contained atomic memory units, maps these units into a learnable codebook using isomorphic semantic quantization, and leverages codebook co-occurrence topology as an additional retrieval path alongside vector search. It also separates online atomic writes from asynchronous offline consolidation for long-term storage.

## Results
The approach achieves the best overall accuracy on LongMemEval-S and LoCoMo while constructing per-dialogue memory in roughly 40-130 seconds, making it 3-21× faster than LightMem and over an order of magnitude faster than A-MEM and MemoryOS.

## Contributions
It introduces discrete atomic memory units and a learnable codebook with isomorphic semantic quantization, adds a dual retrieval mechanism based on codebook topology and vector search, and separates online writes from offline consolidation for scalable long-term memory.

## Research questions this paper is counted under

- [How can LLM agents effectively store, retrieve, and reuse past experiences while preserving fidelity, provenance, and adaptability over long interaction histories?](../q/14.md)

This page was written by language models from the title and abstract of each paper, and the answers were checked by two other models. It can be wrong: check the paper itself. [Suggest a correction](../feedback/?on=p/152904)
