Repository: explodinggradients/ragas
Issue: answer_correctness : too many values to unpack (expected 3)
Root cause: Algorithmic Error

**Describe the bug**
I'm trying to use the AnswerCorrectness with bedrock (both embeddings and llm). When i launc answer similarity it works, but when i launch answer correctness this error occurs:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[29], line 1
----> 1 res_similar=answer_correctness.score(df_ev)

File /opt/conda/lib/python3.10/site-packages/ragas/metrics/base.py:76, in Metric.score(self, dataset, callbacks)
     74 with trace_as_chain_group(f"ragas_{self.name}", callback_manager=cm) as group:
     75     for batch in tqdm(self.get_batches(len(dataset))):
---> 76         score = self._score_batch(dataset.select(batch), callbacks=group)
     77         scores.extend(score)
     79 return dataset.add_column(f"{self.name}", scores)

File /opt/conda/lib/python3.10/site-packages/ragas/metrics/_answer_correctness.py:129, in AnswerCorrectness._score_batch(self, dataset, callbacks, callback_group_name)
    123 if prediction:
    124     prediction = [
    125         item.get(key_map[k], np.nan)
    126         for item in prediction
    127         for k in key_map.keys()
    128     ]
--> 129     tp, fp, fn = [
    130         len(item) if isinstance(item, list) else np.nan
    131         for item in prediction
    132     ]
    133     score = tp / (tp + 0.5 * (fp + fn))
    134 else:

ValueError: too many values to unpack (expected 3)

**Ragas version**: 0.0.22
**Python version**: 3.10.6

**Code to Reproduce**
max_tokens_to_sample = 400
temperature = 0.1
top_k = 250
top_p = 1
from langchain.llms.bedrock import Bedrock

claude_llm = Bedrock(model_id="anthropic.claude-instant-v1", model_kwargs={
        "temperature": float(temperature),
        "max_tokens_to_sample": int(max_tokens_to_sample),
        "top_p": float(top_p),
        "top_k": int(top_k),         
    },client=bedrock_runtime,streaming=True)

bedrock_embeddings = BedrockEmbeddings(client=bedrock_runtime)
ragas_bedrock_model = LangchainLLM(claude_llm)

from ragas.metrics import AnswerCorrectness, AnswerSimilarity
answer_similarity = AnswerSimilarity(llm=ragas_bedrock_model,embeddings= bedrock_embeddings)
answer_correctness = AnswerCorrectness(llm=ragas_bedrock_model, weights=[0.4,0.6], answer_similarity=AnswerSimilarity(llm=ragas_bedrock_model,embeddings= bedrock_embeddings))

res_similar=answer_similarity .score(df_ev) **--> It works!**
res_correct = answer_correctness .score(df_ev) --> It gives this error:
 

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[29], line 1
----> 1 res_similar=answer_correctness.score(df_ev)

File /opt/conda/lib/python3.10/site-packages/ragas/metrics/base.py:76, in Metric.score(self, dataset, callbacks)
     74 with trace_as_chain_group(f"ragas_{self.name}", callback_manager=cm) as group:
     75     for batch in tqdm(self.get_batches(len(dataset))):
---> 76         score = self._score_batch(dataset.select(batch), callbacks=group)
     77         scores.extend(score)
     79 return dataset.add_column(f"{self.name}", scores)

File /opt/conda/lib/python3.10/site-packages/ragas/metrics/_answer_correctness.py:129, in AnswerCorrectness._score_batch(self, dataset, callbacks, callback_group_name)
    123 if prediction:
    124     prediction = [
    125         item.get(key_map[k], np.nan)
    126         for item in prediction
    127         for k in key_map.keys()
    128     ]
--> 129     tp, fp, fn = [
    130         len(item) if isinstance(item, list) else np.nan
    131         for item in prediction
    132     ]
    133     score = tp / (tp + 0.5 * (fp + fn))
    134 else:

ValueError: too many values to unpack (expected 3)
**Error trace**
ValueError: too many values to unpack (expected 3)
**Expected behavior**
The answer correcntess to give right scores

![error_ragas](https://github.com/explodinggradients/ragas/assets/90828168/45c25ced-c7b5-4f6f-b789-479d37f808f2)


Same issue

I "solved" the problem giving the single observation (and not entire database) to the metric. It seems it is linked to the length of the database (still it's a problem!)

I have the same issue.

Digging deeper, it looks like the code assumes that there's going to be 3 values to unpack (tp, fp, fn) when we're finding the tp, fp, fn **per item in prediction**. To solve this, we need to **account for the fact that prediction is not always a length-1 list.**

Does anyone know why "prediction" (which is a single element from the array generated from `self.llm.generate(...).generations`) is not length-1? I'm hoping that can help illuminate what's going on.

I suspect @jjmachan can help!

Hey guys @samialsheikh @AnnamariaGalante @xxSpencer Sorry for the late reply but can you please install the newest version and try again? `pip install ragas==0.1.0rc1`
Make sure you follow the instructions from https://docs.ragas.io/en/latest/index.html , there are some changes in the code. 

I believe that this issue was addressed and fixed in the v0.1 release. Feel free to reopen if needed. 

Same issue for me also! I tried both pip install ragas==0.1.0rc1 and pip install ragas==0.1 but they are not working.

Hey @gulsumbudakoglu just do `pip install -U ragas` nd it should solve your issue.