ragas icon indicating copy to clipboard operation
ragas copied to clipboard

How do I put ragas outputs into a clean JSON, like the JSON that I can get from the dashboard?

Open AmirPoursaberi opened this issue 8 months ago • 1 comments

Hi. I want to extract the output results from the Ragas result object on my local machine. How do I do that?

AmirPoursaberi avatar Apr 09 '25 07:04 AmirPoursaberi

Hi @AmirPoursaberi, you can convert the evaluation result to pandas then can convert them to dict.

from ragas.dataset_schema import EvaluationDataset
from ragas import evaluate 
from ragas.dataset_schema import SingleTurnSample
from ragas.metrics import AnswerAccuracy

from langchain_openai import ChatOpenAI
from ragas.llms import LangchainLLMWrapper

sample = SingleTurnSample(
    user_input="When was Einstein born?",
    response="Albert Einstein was born in 1879.",
    reference="Albert Einstein was born in 1879."
)

dataset = EvaluationDataset(samples=[sample])

llm = ChatOpenAI(model="gpt-4o-mini")
evaluator_llm = LangchainLLMWrapper(langchain_llm=llm)

result = evaluate(dataset=dataset, metrics=[AnswerAccuracy(llm=evaluator_llm)])
result.to_pandas().to_dict()

sahusiddharth avatar Apr 13 '25 09:04 sahusiddharth

It seems the issue was answered, closing this now.

github-actions[bot] avatar Nov 18 '25 09:11 github-actions[bot]