Abstract
Modern approaches to enhancing Large Language Models' factual accuracy and knowledge utilization face a fundamental trade-off: non-parametric retrieval-augmented generation (RAG) provides flexible access to external knowledge but suffers from high inference latency and shallow integration, while parametric fine-tuning methods like LoRA risk catastrophic forgetting and degraded general capabilities. In this work, we propose MLP Memory, a lightweight parametric module that learns to internalize retrieval patterns without explicit document access. By pretraining an MLP to imitate a $k$NN retriever's behavior on the entire pretraining dataset, we create a differentiable memory component that captures the benefits of retrieval-based knowledge access in a fully parametric form. Our architecture integrates this pretrained MLP Memory with Transformer decoders through simple probability interpolation, yielding 17.5% and 24.1% scaling gains on WikiText-103 and Web datasets, respectively. It further achieves 12.3% relative improvement on five question-answering benchmarks and 5.2 points absolute gain across nine general NLP tasks, while reducing hallucinations by up to 10 points on HaluEval. Moreover, MLP Memory delivers 2.5$\times$ faster inference than RAG with superior accuracy. Our findings show that learning retrieval patterns parametrically bridges the gap between efficient inference and effective knowledge access, offering a practical alternative to both RAG and fine-tuning approaches.
Introduction
Large Language Models (LLMs) currently struggle with a "knowledge trade-off." To improve factual accuracy, researchers typically rely on either non-parametric retrieval (RAG) or parametric fine-tuning (e.g., LoRA). RAG offers flexibility but introduces high latency due to expensive vector searches and often results in "shallow" integration where the retrieved text is not deeply fused with the model's internal logic. Conversely, parametric fine-tuning is fast at inference but risks "catastrophic forgetting," where the model loses general reasoning abilities while attempting to memorize new facts.
This paper introduces MLP Memory, a differentiable, parametric module that captures the benefits of retrieval in a compact, high-speed format. By internalizing the behavior of a retrieval system, MLP Memory allows LLMs to access vast external knowledge without the performance bottlenecks of traditional RAG.
Methodology: The MLP Memory Module
The core innovation is an 8-layer Multi-Layer Perceptron (MLP) module, typically comprising approximately 1 billion parameters, designed to act as a proxy for a retriever.
Retriever Imitation
Instead of training on raw text, the MLP is pretrained using a $k$-nearest neighbor ($k$NN) retriever as a "teacher." The module learns to map the LLM’s internal hidden states to the same vocabulary distribution that a $k$NN retriever would produce. This process allows the MLP to learn richer contextual relationships than standard fine-tuning, which often focuses on surface-level string memorization.
Integration and Training
The training objective utilizes a hybrid loss function combining KL Divergence (to match the sparse, "spiky" probability distribution of the $k$NN retriever) and Cross-Entropy (to maintain ground-truth token prediction). During inference, the LLM's prediction is mathematically interpolated with the output from the MLP Memory. Notably, the authors found that the module performs best when integrated approximately 70% of the way through the LLM's layers.
Experimental Results
Accuracy and Knowledge Retention
Evaluations across five major question-answering benchmarks (NQ, WebQA, TriviaQA, TruthfulQA, and HotpotQA) demonstrated a 12.3% relative improvement over the Mistral-7B backbone. On the WebQA dataset specifically, performance increased from 29.28% to 37.45%.
Beyond QA, the model showed a 5.2-point absolute gain across nine general NLP tasks and a significant reduction in hallucinations. On the HaluEval benchmark, MLP Memory achieved up to a 10-point absolute gain in accuracy, indicating a superior ability to distinguish factual information from inconsistencies compared to standard fine-tuned models.
Inference Efficiency
A critical advantage of MLP Memory is its efficiency. Unlike RAG, where search time scales with the size of the external database, MLP Memory's inference speed remains constant. The module delivers 2.5$\times$ faster time-to-first-token than RAG and is 5.6$\times$ faster than $k$NN-LM.
Conclusion
MLP Memory bridges the gap between retrieval-based and parametric knowledge storage. By acting as a "highly compressible memory," it can store the patterns of a 40TB datastore within a 4GB module. While the module currently requires a computationally intensive offline pre-computation phase and is less flexible than RAG for real-time knowledge updates, it offers a powerful new paradigm for efficient, knowledge-intensive language modeling. Future work will focus on more efficient architectures and methods for dynamic updates without full retraining.
Summary updated