Home
WorkBlogTalksPapersAbout
Nikita Kozodoi

Blog

29Posts
Nikita Kozodoi

Detect Hallucinations for RAG-Based Systems

  1. Home
  2. Blog
  3. Detect Hallucinations for RAG-Based Systems
Nikita KozodoiMay 202514 min read

Four ways to check an answer against the context it came from

GenAILLMsRAGEvaluationResponsible AI
Read the full post on AWS Blog

RAG reduces hallucinations, but it doesn't remove them. A system can retrieve exactly the right passage and still answer with something that passage never said, and from the outside that answer looks the same as a correct one. Most detection methods work from the prompt and the response alone, while RAG applications have something extra to check against: the context the system actually retrieved. Comparing an answer to the passage it came from is a narrower question than comparing it to the world, which is why detection gets easier here.

We implement four detectors and compare them on accuracy, precision, recall, latency and cost: an LLM prompt-based detector scoring each sentence from 0 to 1 against the context, semantic similarity between the answer and the passage, a BERT stochastic checker, and token similarity. None of them are state of the art, and that's deliberate. They are simple enough to add to an existing pipeline in an afternoon, which counts for more when the alternative is no detection at all.

Two implementation details matter more than the choice of method. First, give the judge its own model, memory and parameters, because a judge sharing chat history with the model that produced the answer ends up grading its own reasoning and tends to agree with itself. Second, tune the cut-off between grounded and hallucinated on your own data, since that boundary shifts by domain and a threshold borrowed from a benchmark will sit in the wrong place.

Nikita Kozodoi

Written by Nikita Kozodoi

Senior Scientist on the AWS FDE team. I publish applied AI research and embed with engineering teams to build custom AI systems, from scoping and experimentation to fine-tuning and production deployment.

See my workGet in touch

Related content

Blog

Improve LLM Responses in RAG Use Cases by Interacting with the User

2023
Talk

Building Chatbots That Know All About Your Business: Retrieval Augmented Generation

2024
Talk

Five Techniques for Improving RAG Chatbots

2024

Pages

  • Work
  • Blog
  • Talks
  • Papers
  • About

Social

  • LinkedIn
  • GitHub
  • Google Scholar
  • X / Twitter
  • Instagram

Contact

  • n.kozodoi@icloud.com
  • Buy me a coffee
  • Download CV
  • RSS feed
  • Berlin, Germany

© 2026 Nikita Kozodoi. All opinions are my own.