## Language models can correct factual drift before generating bad words

URL: https://theprimary.com/ai-tech/2026-11-29/retrieval-augmented-decoding-hallucinations
Published: 2026-11-29T19:36:09.495Z
Updated: 2026-11-29T19:36:11.383Z
Category: AI-Tech

A lightweight technique steers next-token probabilities using a compact library of truthful snippets, reducing hallucinations during text generation without costly retraining.

When an automated language model generates an answer to an open query, it does not consult an encyclopaedia of solid beliefs. It produces text by predicting one token after another, choosing each fragment based on the statistical probabilities suggested by the prompt and every word produced so far. If an earlier token points toward a popular folklore tale or a common internet rumour, the model routinely follows that trail, fabricating plausible details with complete stylistic confidence. In machine learning research, this persistent tendency to drift into plausible falsehoods is known as hallucination, and it complicates the deployment of generative software in high-stakes fields such as law, medicine, and research.

The standard remedies for this vulnerability demand immense engineering effort. Computer scientists frequently retrain massive models using reinforcement learning with human feedback, or fine-tune them on curated datasets of verified facts. Yet large-scale training runs require vast computational budgets, and models fine-tuned on narrow factual subjects frequently overfit, losing their flexibility or failing when confronted with unfamiliar tasks. Other systems append lengthy factual passages into the user prompt through in-context learning or retrieval-augmented generation pipelines. While retrieving whole documents can anchor a response, it expands the prompt window, slows down generation, and introduces new risks when retrieved passages contain noise or conflicting claims.

In a paper posted to the arXiv server, computer scientists Manh Nguyen, Sunil Gupta, and Hung Le at the Applied Artificial Intelligence Initiative at Deakin University in Geelong, Australia, propose an alternative way to steer text generation. Instead of retraining the underlying model or flooding the prompt with raw text passages, their approach intervenes directly at the point of token selection. Termed Retrieval-Augmented Decoding, or RAD, the technique compares the active fragment of text against a small library of verified factual examples and gently alters the probability distribution of upcoming tokens to favor factual truthfulness.

## Why do language models slip into factual errors?

Large language models select upcoming tokens through a mathematical progression that links context to probability. First, the neural network processes the entire preceding sequence of words, transforming the text into internal numerical vectors. Second, the final layer of the network converts these vectors into a long array of unnormalised scores, known as logits, with one numerical score assigned to every individual word or sub-word in the system's vocabulary. Third, these raw scores are passed through an exponentiation and normalization function, which converts the numbers into percentage likelihoods across the dictionary. Finally, the decoding algorithm selects the next token, typically choosing the item with the highest probability score.

This step-by-step chain reveals why falsehoods take hold. When a model begins generating an answer, a single ambiguous phrase can alter the numerical vectors computed for subsequent steps. As those internal vectors shift, the unnormalised scores tilt toward misleading associations found across noisy training data. Once an incorrect token is chosen and printed, it becomes part of the permanent context for all subsequent steps. The model then generates text that remains statistically consistent with its own initial blunder, compounding the factual error with each new phrase.

To arrest that sequence before an errant token emerges, Nguyen, Gupta, and Le construct what they call a reference grounding space. This compact reference library pairs short snippets of text with the exact logit distributions produced by a trusted model when answering truthfully. Rather than storing millions of web documents or complex intermediate neural activations, the reference space records how a base language model should score candidate words when it is on the right track.

## How can external reference examples guide active generation?

Retrieval-Augmented Decoding operates by checking the local context of an answer as it is being written and retrieving relevant reference patterns in real time. To construct the initial grounding space, the authors take verified question-and-answer pairs and slide a moving window of eight consecutive tokens across the text. Each eight-token chunk is converted into a compact mathematical representation using an independent sentence embedding model, which is an external neural network designed to measure semantic meaning. Simultaneously, the base language model calculates the full vector of vocabulary logits that immediately follow that eight-token chunk. The system archives these paired representations, matching the semantic embedding key to its corresponding next-token logit values.

The choice of an eight-token window was deliberate. In response to questions from Primary about why shorter or longer token spans were abandoned, Manh said, "Our core assumption is that similar local contexts lead to similar next-token predictions." Manh explained that with four tokens, "that assumption breaks" because a short chunk "matches many unrelated facts, so the retrieved signal becomes noisy." Conversely, when the window expands to 16 tokens or an entire prefix, "each match is more reliable, but exact-enough matches become rare, so retrieval rarely fires." According to Manh, eight tokens proved to be the empirical "balance point."

During active generation, the system repeats this comparison at every individual step. As the language model prepares to select its next token, the software isolates the eight most recent tokens of the running response and converts them into a query embedding using the same sentence model. It then measures the cosine similarity between this query and every stored embedding in the reference space. Cosine similarity evaluates the directional alignment of two vectors on a scale from minus one to one, allowing the algorithm to detect whether the active context resembles a known factual pattern.

To ensure that irrelevant reference passages do not distort generation, the system applies a strict similarity threshold, considering only reference chunks whose similarity score exceeds 0.70. If no stored context reaches this bar, the system takes no action, and the model relies entirely on its standard logits. When one or more reference chunks cross the threshold, the system normalizes their similarity scores into relative importance weights and calculates a weighted average of their saved next-token logits.

This 0.70 cutoff prevents misleading examples from corrupting the generation. Manh told Primary that when the threshold is relaxed, "weakly related neighbors leak in and dilute the signal." Under that scenario, "informativeness goes up slightly but truthfulness goes down," meaning the model sounds convincing while adopting inaccurate details. If the cutoff is raised near 0.90 or 1.0, Manh noted that the filter removes nearly every reference, causing the system to fall back to unassisted greedy decoding.

The final intervention combines the base model's raw logits with this retrieved aggregate signal through a straightforward addition. The retrieved logit vector is scaled by an interpolation parameter, denoted as alpha, and added directly to the base model's current logits. This gentle mathematical nudge elevates the scores of truthful continuations while depressing the rank of erroneous tokens. The model then selects the highest-scoring token from this modified distribution and advances to the next step.

In the study, the researchers fixed the interpolation weighting at 0.5 across all evaluation models. Manh said the team tested values including 0, 0.1, 0.2, 0.5, and 1 on a single representative model, finding that gains grew steadily up to 0.5. At an alpha of 1, however, "performance drops below greedy" because retrieved values overpower the model's native reasoning. Manh noted that a drop in informativeness at that level indicates that "outputs get less natural when retrieval dominates."

The authors illustrate this dynamic using an open query about scientific discoveries: when asked to name a cryptid that scientists proved to be real, standard greedy decoding causes the model to generate Yeti. In the author demonstration, the base scores for Yeti and the correct answer coelacanth are closely matched, with Yeti slightly ahead. By retrieving reference contexts sharing similar eight-token phrasing, the system adds a positive grounding signal to the prefix for coelacanth, pushing it into the top position and producing a factually accurate response without requiring external human intervention.

## What did the experimental evaluations reveal?

The researchers evaluated Retrieval-Augmented Decoding across four standard open-ended text benchmarks: TruthfulQA, which tests susceptibility to popular misconceptions; WikiQA, an open-domain retrieval corpus drawn from Wikipedia; Alpaca, which probes general instruction-following and reasoning; and HaluEval, a benchmark focused on dialogue and summarization errors. The experiments assessed performance across four separate large language models to determine whether the decoding mechanism could generalize across differing model architectures.

To measure performance, the authors evaluated generations using external language model scoring pipelines, tracking truthfulness percentages and informativeness percentages alongside their mathematical product. The authors reported that Retrieval-Augmented Decoding consistently outperformed standard decoding methods, such as greedy decoding, contrastive decoding, and layer-contrasting techniques like DoLa, while maintaining strong informativeness scores across test tasks.

A notable finding of the investigation is the extreme sample efficiency of the grounding space. Nguyen, Gupta, and Le established that an effective reference library can be built from as few as 10 annotated reference samples, with stable performance observed across collections ranging from 10 to 100 samples. Manh explained to Primary that this efficiency stems from the sliding window: standard prompting methods treat 10 samples as 10 discrete examples, whereas sliding a window converts 10 full answers into "about 30 times more reference points." For highly specialized subjects like medicine or long-tail facts, Manh noted that fewer chunks match, leading the software to fall back cleanly to the base model rather than causing harm.

Furthermore, the grounding space demonstrated cross-task generalization: a compact library derived from TruthfulQA reference examples improved factual accuracy when the model answered queries from WikiQA, and reference material constructed from WikiQA similarly enhanced truthfulness on TruthfulQA tasks. Manh credited this transfer to strict thresholding: because the eight-token segments reflect natural factual phrasing rather than rigid task formats, out-of-domain banks contribute when phrasing matches and fall silent when it does not.

Because the technique operates purely on output logits and uses a model-agnostic sentence embedding tool, it avoids the heavy computational burden associated with other decoding interventions. Contrastive decoding methods require parallel forward passes through separate expert and amateur networks, while self-consistency approaches generate multiple full candidate continuations and aggregate them. The authors reported that Retrieval-Augmented Decoding executes in a single autoregressive generation pass, avoiding repeated sampling passes or invasive tracking of internal transformer layer weights.

## What are the boundaries of this decoding approach?

The experimental results reflect controlled benchmark environments rather than guaranteed universal performance in live consumer software. The reported evaluations are computational simulations on academic question-answering sets, and they do not prove that an eight-token window will prevent hallucinations across complex technical domains such as clinical medicine or statutory legal analysis. The method assumes that local semantic phrasing reliably mirrors factual sentence structures, an assumption that can break down when a query involves rare technical nomenclature, highly nested logic, or novel linguistic constructions.

Manh pointed out that because the approach relies on local patterns, it struggles when factual correctness depends on broader reasoning chains. Prompts involving multi-step arithmetic, explicit negation, or counterfactual scenarios expose this vulnerability. In particular, Manh cautioned that when different facts share identical phrasing, such as a phrase stating that an event went into effect on a specific calendar date, retrieval can fetch a matching context describing an unrelated event and inject an erroneous year. In such cases, the system matches surface phrasing rather than factual meaning.

Additionally, the research paper by Nguyen, Gupta, and Le is published, and the version on the arXiv repository is now exactly the ECML PKDD 2026 proceedings version. The arXiv version is identical to the proceedings of ECML PKDD 2026, including the results and benchmark comparisons. The technique also requires the base language model to expose its unnormalised output logits, making the method incompatible with closed commercial interfaces that return only raw text completions.

## Where does decoding-time intervention lead next?

The findings from Deakin University point toward a middle ground between static prompt engineering and expensive model retraining. By demonstrating that a reference library constructed from just 10 verified examples can steer model probability distributions during generation, the study suggests that factual alignment can be treated as a lightweight search problem at the vocabulary layer. For machine learning engineers, this creates the possibility of deploying domain-specific factual filters that can be swapped or updated instantly without modifying core neural network weights.

The next practical step for researchers will be determining how Retrieval-Augmented Decoding handles dynamic knowledge bases that change daily, such as breaking news or financial ledgers. Engineers will also need to test whether the 0.70 similarity threshold and the eight-token context window remain effective when scaled to larger models containing hundreds of billions of parameters. For now, the technique demonstrates that language models can be kept closer to the truth simply by showing their final mathematical layers what honest text looks like.

This piece was prepared from the arXiv paper and public records together with answers from Manh to six questions from the Primary news team, completed September 2026.
