explodinggradients / ragas

Evaluation framework for your Retrieval Augmented Generation (RAG) pipelines
https://docs.ragas.io
Apache License 2.0
6.58k stars 646 forks source link

How to detect and measure hallucinations? #732

Closed aldrinjenson closed 6 months ago

aldrinjenson commented 6 months ago

Hi, thanks for building Ragas!

Is there a straightforward way to detect or measure hallucination?

Will equating it with faithfulness score be a good metric? For eg: can we say that the RAG system is hallucinating if faitfullness < 0.4 or some arbitrary number ?

TruLens does this using the concept of RAG Triad which seems a bit vague to me.

Is there a similar metric (maybe by combining values of faithfullness, context/answer relevancy etc..) that we can also use from Ragas to measure the amount of hallucination in the system?

I've also noticed Hallucination Evaluation Model by Vectara where it seems like they are taking only groundedness as the metric to measure hallucination.

Please do share your thoughts. Thanks!

shahules786 commented 6 months ago

Hey, @aldrinjenson Bro isn't the same as the idea of faithfulness?

Is there anything deeper than this you're looking for?

aldrinjenson commented 6 months ago

Hi @shahules786

isn't the same as the idea of faithfulness?

I think it comes down to what exactly one means by hallucination from a RAG perspective.

Based on majority of sources on the internet, hallucination means when a model makes up things, mostly incorrect but assumes confidently that it is right.

eg:

Google’s Bard chatbot incorrectly claiming that the James Webb Space Telescope had captured the world’s first images of a planet outside our solar system

Let's say in the case of my RAG system, I have some chunks saying person X worked in company Google; and if I asked the model "Is person x working in a great company?". If the model responds with saying yes, person x is in good company because Google is known for it's greatness etc, technically it's not hallucinating, but it's talking from data outside it's context - using it's worldly knowledge to answer. I tried questions like this in my system(temperature = 0, model = gpt 3.5 turbo 16k). I got faithfulness score as 1 even though nowhere in my context chunks is it mentioned that the company is great. Ideally the model should have answered saying that there is not enough context to answer weather the person is in a great company.

So I am trying to know if faithfulness/groundedness can really be directly equated with hallucination. Additionally, nowhere in the faithfulness page is anything about hallucination mentioned as well.

Personally I feel like groundedness comes as a subsection of hallucination and hence can't directly be equated. Maybe I am missing something.

What are your thoughts.

shahules786 commented 6 months ago

@aldrinjenson , I've understood your question now. Responding to your query:

Is there a straightforward way to detect or measure hallucination?

No, there isn't. This is due not only to technical challenges but also to the nature of truth itself. For example,

"Is person x working at a great company?"

There are subjective and objective realities; a company being "great" falls into the subjective category. Who are we to say whether it is or isn't? Many statements we accept as truth are, in fact, mostly subjective. It's challenging to distinguish between what is true and what is false in these cases. It does not make sense to do so because it's something that exists only in the shared imagination of people.

Regarding my RAG system, we define groundedness/faithfulness as the ability of an LLM to stay true to the given context. We assume that the provided content contains the ultimate truth and hence measure the faithfulness of the answer against it.

Feel free to close the issue if you feel your query has been answered.

aldrinjenson commented 6 months ago

Okay. Makes sense.

In conclusion, I'm realising that while hallucination could be a model making up things and confidently assuming it's true; in real life RAG systems, what we can measure is weather the model is speaking out of a given context. Hence we measure and present this metric as groundedness/faithfulness and not directly equate it as hallucination per se.

Thank You @shahules786