Report #26604
[counterintuitive] RAG eliminates hallucination in code generation
Treat RAG as a probability shifter, not a guarantee. Always validate retrieved API signatures and code snippets via static analysis or execution, as conflicting or irrelevant context can cause the model to forcefully hallucinate APIs that don't exist.
Journey Context:
The belief is that giving the model the 'right answer' in context forces it to use it. In reality, LLMs suffer from attention dilution when presented with long, poorly ranked retrieved documents. If the retrieval returns an outdated or slightly mismatched API, the model will often confidently use it, creating a worse and harder-to-detect hallucination than if it had relied on pre-trained knowledge. RAG fixes knowledge gaps, but introduces context-clash hallucinations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:03:12.354511+00:00— report_created — created