Skip to content

cannot import name 'context_relevancy' from 'ragas.metrics' Β #1210

@zabih1

Description

@zabih1

from ragas.metrics.critique import harmfulness
from ragas import evaluate

from ragas.metrics import (
    answer_relevancy,
    faithfulness,
    context_recall,
    context_precision,
    context_relevancy,
    answer_correctness,
    answer_similarity
)



def create_ragas_dataset(rag_pipeline, eval_dataset):
  rag_dataset = []
  for row in tqdm(eval_dataset):
    answer = rag_pipeline.invoke({"question" : row["question"]})
    rag_dataset.append(
        {"question" : row["question"],
         "answer" : answer["response"].content,
         "contexts" : [context.page_content for context in answer["context"]],
         "ground_truths" : [row["ground_truth"]]
         }
    )
  rag_df = pd.DataFrame(rag_dataset)
  rag_eval_dataset = Dataset.from_pandas(rag_df)
  return rag_eval_dataset

def evaluate_ragas_dataset(ragas_dataset):
  result = evaluate(
    ragas_dataset,
    metrics=[
        context_precision,
        faithfulness,
        answer_relevancy,
        context_recall,
        context_relevancy,
        answer_correctness,
        answer_similarity
    ],
  )
  return result
  

When i run the above code I give me this error.

ImportError: cannot import name 'context_relevancy' from 'ragas.metrics' (c:\Users\khan\anaconda3\Lib\site-packages\ragas\metrics_init_.py)

Metadata

Metadata

Assignees

No one assigned

    Labels

    answeredπŸ€– The question has been answered. Will be closed automatically if no new commentsbugSomething isn't workingmodule-metricsthis is part of metrics modulequestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions