MemLLM: Finetuning LLMs to Use Explicit Read-Write Memory

Ali Modarressi, Abdullatif Köksal, Ayyoob Imani, Mohsen Fayyaz, Hinrich SchuetzeNFAM @ ICLR 2025

Abstract

While current large language models (LLMs) perform well on many knowledge-related tasks, they are limited by relying on their parameters as an implicit storage mechanism. As a result, they struggle with memorizing rare events and with updating their memory as facts change over time. In addition, the uninterpretable nature of parametric memory makes it challenging to prevent hallucination. Model editing and augmenting LLMs with parameters specialized for memory are only partial solutions. In this paper, we introduce MemLLM, a novel method of enhancing LLMs by integrating a structured and explicit read-and-write memory module. MemLLM tackles the aforementioned challenges by enabling dynamic interaction with the memory and improving the LLM's capabilities in using stored knowledge. Our experiments indicate that MemLLM enhances the LLM's performance and interpretability, in language modeling in general and knowledge-intensive tasks in particular. We see MemLLM as an important step towards making LLMs more grounded and factual through memory augmentation.

Introduction

Standard Large Language Models (LLMs) store knowledge within their internal weights, a phenomenon known as "parametric memory." This approach suffers from three primary flaws: staticity, where updating facts requires expensive retraining; opacity, making it difficult to interpret hallucinations; and tail-end weakness, where models struggle with rare entities. While Retrieval-Augmented Generation (RAG) offers a partial solution by storing unstructured text, it often leads to redundant storage and difficulty in resolving conflicting facts.

MemLLM addresses these issues by finetuning LLMs to interact with an explicit, structured, and human-readable database. This framework allows the model to treat external knowledge as a read-write memory, significantly improving factual accuracy and updatability while requiring 80% less storage than traditional RAG systems.

System Architecture

MemLLM (specifically implemented using Mistral-7B) is designed to interact with a Structured Read-Write Memory through a dedicated API.

Memory Structure

Knowledge is organized as relational triples (Subject-Relation-Object). These triples are indexed using vector embeddings (via Contriever) to facilitate fuzzy, similarity-based searching rather than relying on strict keyword matching. This structured approach is highly efficient; storing 111 million facts as triples uses less than 20% of the memory required by a RAG system storing the same facts as full sentences.

The structured memory schema, illustrating the relationship between Entities, Relations, and the Triple Memory (Main) table.

Interaction API

The model is trained to generate special tokens to interact with this memory module:

  • MEM_WRITE: During processing, the model extracts facts from input text and writes them to the database.
  • MEM_READ: During generation, the model can pause, initiate a query (e.g., "Who is the performer of this song?"), and incorporate the retrieved results into its subsequent tokens.
Visualization of the MEM_READ process, where the LLM generates a query token, retrieves a fact from memory, and incorporates it into the final output.

Training and Data Pipeline

The researchers utilized LoRA (Low-Rank Adaptation) to teach the model these new interaction skills. A novel data generation pipeline was developed to convert annotated corpora, such as Wikipedia, into training examples of API calls. Key datasets included:

  • Re-DocRED: Used for training relation extraction and retrieval.
  • Distant Supervised DocRED: A large-scale dataset cleaned using a "reasoning-based" filtering method with another LLM to ensure high-quality training examples.
  • ZsRE (Zero-Shot Relation Extraction): Used to evaluate knowledge editing capabilities.
  • Counterfactual Re-DocRED: A dataset of "fake" facts designed to train the model to prioritize its external memory over internal pre-trained biases.

Experimental Results

MemLLM demonstrates significant improvements across several benchmarks:

  • Language Modeling: The model achieved a lower perplexity (PPL) on Wikipedia text compared to baselines. On target entities specifically, it reached 2.986 PPL versus 3.550 for the baseline.
  • Knowledge Editing: On the ZsRE benchmark, MemLLM outperformed state-of-the-art editing methods like GRACE and WISE.
  • Locality: The system achieved a Locality score of 0.97, indicating that updating a specific fact in memory causes almost zero "collateral damage" to unrelated knowledge.

Discussion and Future Work

MemLLM represents a shift toward active participation in retrieval, where the model decides when and what to look up. Because the memory is structured, it remains human-inspectable and easily editable.

However, current limitations include a schema constrained to 96 Wikidata relations and added computational latency during inference. Future work will focus on moving toward an "open-schema" for arbitrary relations and enabling "multi-hop" reasoning within the structured memory.

Summary updated

BibTeX
@inproceedings{modarressi2025memllm,
  author = {Ali Modarressi and Abdullatif Köksal and Ayyoob Imani and Mohsen Fayyaz and Hinrich Schuetze},
  title = {{MemLLM: Finetuning LLMs to Use Explicit Read-Write Memory}},
  booktitle = {NFAM @ ICLR},
  year = {2025},
  url = {https://openreview.net/forum?id=i2vIIGIm2C},
}
Figure