Introduction
As the demand for high-quality training data for Large Language Models (LLMs) outpaces supply, researchers have turned to non-parametric approaches. The $k$-nearest neighbor language model ($k$NN-LM) is a prominent solution, allowing a smaller base model to access a massive external datastore during inference. While this approach significantly improves perplexity—the model's ability to predict the next token—this paper investigates whether such "memory" translates into actual reasoning capabilities.
The $k$NN-LM Mechanism
The $k$NN-LM operates by augmenting a standard language model with a retrieval step. First, a datastore is constructed by saving the hidden state representations of every token in a large corpus. During inference, for each generated token, the model performs a $k$-nearest neighbor search in this vector space. The final output probability is an interpolation between the base LM's prediction and the distribution of tokens found in the datastore.
Experimental Setup
The authors evaluated three state-of-the-art open-source models: Llama-2-7b, Llama-3-8B, and Mistral-7B. They constructed two specialized datastores:
- Wiki: A 2.2GB collection of 610 million tokens from Wikipedia and other general sources.
- Math: A 0.6GB collection of 200 million tokens from nearly 4,000 mathematical textbooks.
Performance was measured across 22 datasets, split between memory-intensive tasks (like sentiment analysis) and reasoning-intensive tasks (like multi-hop QA and logic).
Key Findings: The Perplexity Paradox
A central finding of the study is that lower perplexity is a "decoy" for reasoning ability. While $k$NN-LMs excel at predicting the next word based on local syntactic patterns, they often fail to grasp the underlying logic of a query.
The Multi-Hop Wall and Semantic Sensitivity
$k$NN-LMs struggle significantly with tasks requiring the integration of multiple facts. The retrieval mechanism is highly sensitive to phrasing (syntax) but often ignores meaning (semantics). It frequently retrieves high-frequency entities that appear in similar-looking sentences but are factually incorrect for the specific context. Furthermore, "Oracle" experiments showed that even when the correct answer is present among the retrieved neighbors, the base model often lacks the reasoning capacity to select it.
Results: Memory vs. Reasoning
The empirical results highlight a sharp divide between memory and reasoning. On memory-intensive tasks, the $k$NN-LM improved performance in 8 out of 11 cases. However, the story changes for reasoning-intensive benchmarks.
As shown in the data, adding the Wiki datastore to Llama-3-8B actually decreased its accuracy on HotpotQA from 25.14% to 24.48%. Similarly, despite the inclusion of a specialized Math datastore, mathematical reasoning saw no significant benefit; Llama-2-7b's performance on GSM8K dropped from 14.83% to 13.48% with retrieval enabled.
Conclusion and Future Directions
The study concludes that while $k$NN-LMs provide a powerful patch for memorization, they are not a substitute for the deep reasoning capabilities developed during pre-training. The "shallow" nature of token-level retrieval introduces noise that can distract the model during complex tasks. Future work may find more success in Retrieval-Augmented Generation (RAG), which retrieves entire document chunks to provide the model with broader context, rather than individual token-level neighbors.
Summary updated