Repository: explodinggradients/ragas
Issue: Context type issue - "contexts" should be of type Sequence[string] 
Root cause: Documentation Deficiency

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<head>

<meta name=Generator content="Microsoft Excel">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
x\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--.font0
	{color:#ABB2BF;
	font-size:9.0pt;
	font-family:Calibri;
	font-weight:400;
	font-style:normal;
	text-decoration:none;}
.font1
	{color:#98C379;
	font-size:9.0pt;
	font-family:Calibri;
	font-weight:400;
	font-style:normal;
	text-decoration:none;}
.font2
	{color:#000000;
	font-size:11.0pt;
	font-family:Calibri;
	font-weight:400;
	font-style:normal;
	text-decoration:none;}
br
	{mso-data-placement:same-cell;}
td
	{padding-top:1px;
	padding-left:1px;
	padding-right:1px;
	mso-ignore:padding;
	color:#000000;
	font-size:11.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:Calibri;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-protection:locked visible;}
.et2
	{color:#98C379;
	font-size:9.0pt;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	white-space:normal;}
-->
</style>
</head>
<body>
<!--StartFragment-->


question | answer | context
-- | -- | --
what is your return policy | Our return policy allows you to return the product at the time of delivery if you are not satisfied with the quality or freshness. We will take the returned product back and issue a credit note for the value of the return products. For more details, you can check our FAQs section on the app. | ["The first superbowl was held on January 15, 1967", "The New England Patriots have won the Super Bowl a record six times"]


<!--EndFragment-->
</body>

</html>

Above is a sample row from my dataset, despite passing the context as a list of strings, I'm hitting the ValueError: Dataset feature "contexts" should be of type Sequence[string]

Dataset({
    features: ['question', 'answer', 'contexts'],
    num_rows: 4
})

When trying to run the 'result' - 

```
result = evaluate(
    dataset_llm,
    metrics=[faithfulness, answer_relevancy, context_precision, harmfulness],
)
result
```

Consistency hitting the ValueError -  ValueError: Dataset feature "contexts" should be of type Sequence[string], got <class 'datasets.features.features.Value'>

Please help.
Regards
Lohith






































































Hey @lohith-slanglabs, thanks for raising the issue.  please ensure that your dataset is prepared as shown [here](https://docs.ragas.io/en/latest/howtos/applications/data_preparation.html) 

If the issue persists, please share 
1.  ragas version you're using.
2.  couple of samples as a .json/ csv file so that I can try and reproduce the issue.



@shahules786 thank you for the quick reply. 

Attaching the notebook and the sample dataframe that I'm using [here](https://drive.google.com/drive/folders/1vgeN72BSckd5OR86-UXm5V6jhxIDFH22?usp=sharing).

I'm currently using ragas v0.0.16.

Please LMK if i need to make any corrections or changes.

Hey @lohith-slanglabs , the issue was when exporting dataframe to dict.  The context column was automatically converted to string by pandas. 
You can fix it by replacing code with 
```
from datasets import Dataset
dataset_dict_updated = {
    "question": df_sample["question"].tolist(),
    "answer": df_sample["answer"].tolist(),
    "contexts": [eval(item) for item in df_sample["context"].tolist()], ## made change here
}

dataset_llm = Dataset.from_dict(dataset_dict_updated)
```

Feel free to close the issue if it's working for you. 

Hey @shahules786, ingesting data through CSV was quite ambiguous. I went ahead and fed the data in JSON format, which resolved my issues.

Thank you for your help. 

I have the problem as well，but "contexts": [eval(item) for item in df_sample["context"].tolist()], ## made change here don't solve my problem