Nearest Neighbor Speculative Decoding for LLM Generation and Attribution

Minghan Li, Xilun Chen, Ari Holtzman, Beidi Chen, Jimmy Lin +2 more
2/3/2026

No official code found. Best implementation: facebookresearch/NEST (12 stars, last commit 2025-05-08).

Abstract

Large language models (LLMs) often hallucinate and lack the ability to provide attribution for their generations. Semi-parametric LMs, such as kNN-LM, approach these limitations by refining the output of an LM for a given prompt using its nearest neighbor matches in a non-parametric data store. However, these models often exhibit slow inference speeds and produce non-fluent texts. In this paper, we introduce Nearest Neighbor Speculative Decoding (NEST), a novel semi-parametric language modeling approach that is capable of incorporating real-world text spans of arbitrary length into the LM generations and providing attribution to their sources. NEST performs token-level retrieval at each inference step to compute a semi-parametric mixture distribution and identify promising span continuations in a corpus. It then uses an approximate speculative decoding procedure that accepts a prefix of the retrieved span or generates a new token. NEST significantly enhances the generation quality and attribution rate of the base LM across a variety of knowledge-intensive tasks, surpassing the conventional kNN-LM method and performing competitively with in-context retrieval augmentation. In addition, NEST substantially improves the generation speed, achieving a 1.8x speedup in inference time when applied to Llama-2-Chat 70B. Code will be released at https://github.com/facebookresearch/NEST/tree/main.

View on arXivView PDF

Code Implementations(1)

This the official implementation of Nearest Neighbor Speculative Decoding (https://arxiv.org/abs/2405.19325), an inference-time revision approach to enhance LLM factuality and generation attribution.

121Shell, PythonJul 23, 20241 years agoNOASSERTION

Similar Papers

Cite this paper

@article{li2026nearest,
  title  = {Nearest Neighbor Speculative Decoding for LLM Generation and Attribution},
  author = {Minghan Li and Xilun Chen and Ari Holtzman and Beidi Chen and Jimmy Lin and Wen-tau Yih and Xi Victoria Lin},
  year   = {2026},
  eprint = {2405.19325},
  archivePrefix = {arXiv},
  doi    = {10.48550/arXiv.2405.19325},
  url    = {https://arxiv.org/abs/2405.19325},
  journal = {NEURIPS 2024 2024}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2405.19325.svg)](https://codeofpaper.com/paper/2405.19325)

Discussion