SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2510.18866 · ICLR · 2025

LightMem: Lightweight and Efficient Memory-Augmented Generation

Ningyu Zhang, Shumin Deng, Huajun Chen, Yunzhi Yao, Mengru Wang, Shuofei Qiao, Ziwen Xu, Ziyan Jiang, Haoming Xu, Jizhan Fang, Xinle Deng, Yuqi Tang

arXiv · PDF · Open in the Atlas

Code that ran

5 of 7 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 3 failures of our instrument; 2 no recorded run), measured 2026-11-23; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2510.18866.json · badge: /api/ran/2510.18866.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
zjunlp/LightMem canonical (classifier label)
classifier basis: census
5 ran · 2 no recorded run
FunctionStatusWhere it lives
assign_sequence_numbers_with_timestamps Ran
ran; our contract draft was wrong, not the code
zjunlp/LightMem/src/lightmem/memory/utils.py
code served (permissive licence) · get_code("678788a945dfe814")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re
from datetime import datetime, timedelta
from collections import defaultdict

# Create sample message objects with required fields
def create_message(session_time, speaker_id, speaker_name, weekday):
    return {
        'session_time': session_time,
        'speaker_id': speaker_id,
        'speaker_name': speaker_name,
        'weekday': weekday
    }

# Build extract_list structure: list of api_call_segments, 
# where each api_call_segment is a list of topic_segments,
# where each topic_segment is a list of messages
extract_list = [
    [
        [
            create_message('2024-01-15 10:30:45', 'speaker_1', 'Alice', 'Monday'),
            create_message('2024-01-15 10:30:45', 'speaker_2', 'Bob', 'Monday'),
        ],
        [
            create_message('2024-01-15 11:00:00', 'speaker_3', 'Charlie', 'Monday'),
        ],
    ],
    [
        [
            create_message('2024-01-16 09:15:30', 'speaker_1', 'Alice', 'Tuesday'),
            create_message('2024-01-16 09:15:30', 'speaker_4', 'Diana', 'Tuesday'),
            create_message('2024-01-16 09:15:30', 'speaker_2', 'Bob', 'Tuesday'),
        ],
    ],
]

# topic_id_mapping: for each api_call_segment, a list of topic IDs
# API call 0 has 2 topic segments, API call 1 has 1 topic segment
topic_id_mapping = [
    [101, 102],
    [201],
]

ARGS = {
    'extract_list': extract_list,
    'offset_ms': 500,
    'topic_id_mapping': topic_id_mapping,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
clean_response Ran
ran, honoured the contract we drafted
zjunlp/LightMem/src/lightmem/memory/utils.py
code served (permissive licence) · get_code("9b74125509be5828")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned list, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re
import json
from typing import List, Dict, Any

def clean_response(response: str) -> List[Dict[str, Any]]:
    """
    Cleans the model response by:
    1. Removing enclosing code block markers (```[language] ... ```).
    2. Parsing the JSON content safely.
    3. Returning the value of the "data" key if present, otherwise trying to return the parsed list/dict.
    """
    pattern = '```(?:json)?\\s*([\\s\\S]*?)\\s*```'
    match = re.search(pattern, response.strip())
    cleaned = match.group(1).strip() if match else response.strip()
    try:
        parsed = json.loads(cleaned)
    except json.JSONDecodeError as e:
        print(f'JSON decoding error: {str(e)}')
        return []
    if isinstance(parsed, dict) and 'data' in parsed and isinstance(parsed['data'], list):
        return parsed['data']
    if isinstance(parsed, list):
        return parsed
    return []


# Test case 1: response with code block markers and data key
response_1 = """```json
{
  "data": [
    {"id": 1, "name": "Alice"},
    {"id": 2, "name": "Bob"}
  ]
}
"""

# Test case 2: response with code block markers but no data key (direct list)
response_2 = """```json
[
  {"id": 1, "name": "Charlie"},
  {"id": 2, "name": "Diana"}
]
"""

# Test case 3: response without code block markers
response_3 = '[{"id": 1, "name": "Eve"}]'

ARGS = {
    "response": response_1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_anscheck_prompt Ran
ran; our contract draft was wrong, not the code
zjunlp/LightMem/experiments/longmemeval/run_lightmem_gpt.py
code served (permissive licence) · get_code("8e4f7c8ecedd17fa")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Sonnet 4.5, prompt python_fixture_v1) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

ARGS = {
    'task': 'single-session-user',
    'question': 'What is the capital of France?',
    'answer': 'Paris',
    'response': 'The capital of France is Paris.',
    'abstention': False
}
Setup block drafted by
a language model, Claude Sonnet 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
make_attr_patch Ran
ran; our contract draft was wrong, not the code
zjunlp/LightMem/src/lightmem/memory_toolkits/monkey_patch.py
code served (permissive licence) · get_code("71ac5d11bf237b07")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned tuple, ndim 1, dtype family float; no output shape is stated. The image it ran in was not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn
from pydantic import BaseModel
from typing import Callable, Any

torch.manual_seed(0)

# Create a simple class with an attribute to patch
class SimpleClass:
    def original_method(self, x: int) -> int:
        return x * 2

# Create a simple BaseModel with an attribute
class SimpleModel(BaseModel):
    value: int = 0
    
    def original_method(self, x: int) -> int:
        return x + 1

# Test objects
test_obj_regular = SimpleClass()
test_obj_basemodel = SimpleModel()

# For the regular class case
ARGS = {
    "obj": test_obj_regular,
    "attr": "original_method"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
pydantic, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple, ndim 1, dtype family float — a tuple output has no array shape of its own; none is stated
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
true_or_false Ran
ran, violated the contract we drafted
zjunlp/LightMem/experiments/longmemeval/run_lightmem_gpt.py
code served (permissive licence) · get_code("c799cf59bf6b0ace")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned bool, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

# Analyzing the function true_or_false
# It takes a single parameter 'response' which can be None or a string-like object
# The function checks the content of the response to determine True/False

# Test case 1: response that starts with 'yes'
response_yes = "yes, this is correct"

# Test case 2: response that is None
response_none = None

# Test case 3: response that starts with 'no'
response_no = "no, this is not right"

# Test case 4: response that contains 'yes' but doesn't start with it
response_contains_yes = "maybe yes"

# Test case 5: response that is empty
response_empty = ""

# Test case 6: response with whitespace
response_whitespace = "  y  "

ARGS = {
    "response": "yes, this is the answer"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type bool, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_tokenizer_for_model Not yet run
unverified (harvested, no recorded run)
zjunlp/LightMem/src/lightmem/memory_toolkits/token_monitor.py
code served (permissive licence) · get_code("b528422968655fae")
How it ran

no invocation recorded.

save_memory_entries Not yet run
unverified (harvested, no recorded run)
zjunlp/LightMem/src/lightmem/memory/utils.py
code served (permissive licence) · get_code("dcc248d6e996daf9")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 6 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
get_anscheck_prompt 3 other papers
2 dated earlier, 1 later
2410.10813 (2024-10)
LongMemEval: Benchmarking Chat Assistants on Long-Term Interactive Memory
2506.09944 (2025-06)
Query-Focused Retrieval Heads Improve Long-Context Reasoning and Re-ranking
2601.01280 (2026-01)
Does Memory Need Graphs? A Unified Framework and Empirical Analysis for Long-Term Dialog Memory

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Despite their remarkable capabilities, Large Language Models (LLMs) struggle to effectively leverage historical interaction information in dynamic and complex environments. Memory systems enable LLMs to move beyond stateless interactions by introducing persistent information storage, retrieval, and utilization mechanisms. However, existing memory systems often introduce substantial time and computational overhead. To this end, we introduce a new memory system called LightMem, which strikes a balance between the performance and efficiency of memory systems. Inspired by the Atkinson-Shiffrin model of human memory, LightMem organizes memory into three complementary stages. First, cognition-inspired sensory memory rapidly filters irrelevant information through lightweight compression and groups information according to their topics. Next, topic-aware short-term memory consolidates these topic-based groups, organizing and summarizing content for more structured access. Finally, long-term memory with sleep-time update employs an offline procedure that decouples consolidation from online inference. On LONGMEMEVAL and LOCOMO, using GPT and Qwen backbones, LightMem consistently surpasses strong baselines, improving QA accuracy by up to 7.7% / 29.3%, reducing total token usage by up to 38× / 20.9× and API calls by up to 30× / 55.5×, while purely online test-time costs are even lower, achieving up to 106× / 117× token reduction and 159× / 310× fewer API calls. The code is available at https://github.com/zjunlp/LightMem.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2510.18866")
get_code_for_paper("2510.18866")
have("2510.18866")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2510.18866.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2510.18866.svg)](https://syntology.ai/paper/2510.18866)

Connect an agent — have() is free.