Skip to content

KeyError: 'correctness' when running evaluate in giskard.rag #2111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
kunjanshah0811 opened this issue Feb 17, 2025 · 3 comments
Open

KeyError: 'correctness' when running evaluate in giskard.rag #2111

kunjanshah0811 opened this issue Feb 17, 2025 · 3 comments
Assignees

Comments

@kunjanshah0811
Copy link

kunjanshah0811 commented Feb 17, 2025

When running evaluate from giskard.rag with the specified metrics ragas_context_recall and ragas_context_precision, the following error occurs

from giskard.rag import evaluate, RAGReport, AgentAnswer
from giskard.rag.metrics.ragas_metrics import ragas_context_recall, ragas_context_precision

def answer_fn(question, history=None):

    answer = chat_engine.chat(question, chat_history=[])

    return AgentAnswer(
        message=answer.response,
        documents=[source.content for source in answer.sources]
    )

report = evaluate(answer_fn, 
                testset=testset, 
                knowledge_base=knowledge_base,
                metrics=[ragas_context_recall, ragas_context_precision])
report.save("test_report")

ERROR

KeyError                                  Traceback (most recent call last)
File c:\Users\KUNJAN SHAH\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\base.py:3805, in Index.get_loc(self, key)
   3804 try:
-> 3805     return self._engine.get_loc(casted_key)
   3806 except KeyError as err:

File index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()

File index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()

File pandas\\_libs\\hashtable_class_helper.pxi:7081, in pandas._libs.hashtable.PyObjectHashTable.get_item()

File pandas\\_libs\\hashtable_class_helper.pxi:7089, in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'correctness'```
@alexcombessie
Copy link
Member

Hey @henchaves - is this a known issue?

@henchaves
Copy link
Member

Hello @kunjanshah0811, thanks for reporting this issue.

Could you confirm that you only get this error when calling report.save method? I've just tried to call this method and it's working fine here, so I think I'll need more information about your specs so I can try to simulate your env. Could you share what is you OS, Python version and pip list?

Just so you know, we constrained the version of some external libs (such as ragas and langchain) which were causing incompatibilities with generate_testset and evaluate methods. You can try to use this giskard version while it's not released yet: #2122.

@henchaves henchaves self-assigned this Mar 18, 2025
@GTimothee
Copy link
Contributor

GTimothee commented Apr 6, 2025

Something that could be happening:

  1. We always compute correctness, even if here only ragas_context_recall and ragas_context_precision are passed. So it explains why correctness is involved in the error.

  2. Now we are using a LLM to generate JSON, and here the error seems to be KeyError: 'correctness', which may mean that the LLM that has been used just failed to generate the correctness key.

So it may just be an error in the evaluate function and a LLM problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants
@alexcombessie @GTimothee @henchaves @kunjanshah0811 and others