ragas icon indicating copy to clipboard operation
ragas copied to clipboard

cannot import name 'context_precision' from 'ragas.metrics'

Open dividor opened this issue 1 year ago • 1 comments

[X ] I have checked the documentation and related resources and couldn't resolve my bug.

Describe the bug I am trying to follow this documentation, but it doesn't work because context_precision seems to be missing.

Ragas version: ragas-0.1.14 Python version: 3.11.4

Code to Reproduce The code from Ragas' documentation ...

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

Error trace

Cell In[52], [line 1](vscode-notebook-cell:?execution_count=52&line=1)
----> [1](vscode-notebook-cell:?execution_count=52&line=1) from ragas.metrics import (
      [2](vscode-notebook-cell:?execution_count=52&line=2)     faithfulness,
      [3](vscode-notebook-cell:?execution_count=52&line=3)     answer_relevancy,
      [4](vscode-notebook-cell:?execution_count=52&line=4)     context_precision,
      [5](vscode-notebook-cell:?execution_count=52&line=5)     context_recall,
      [6](vscode-notebook-cell:?execution_count=52&line=6) )

ImportError: cannot import name 'context_precision' from 'ragas.metrics' (/Users/ME/opt/miniconda3/envs/eval_demo/lib/python3.11/site-packages/ragas/metrics/__init__.py)

Expected behavior The documented code should work.

Additional context RAGAs is great, thanks!

dividor avatar Aug 20 '24 00:08 dividor

Hey @dividor! 👋 I'm here to help you out with any bugs or questions you have. I'm a bot that can assist with problem-solving and answering queries while you wait for a human maintainer.

The ImportError occurs because context_precision is not defined as a module-level variable in ragas.metrics. Instead, it is defined within src/ragas/metrics/_context_precision.py.

To resolve this issue, you can import context_precision directly from ragas.metrics._context_precision:

from ragas.metrics._context_precision import context_precision

Alternatively, you can import it directly from ragas.metrics as it is included in the __all__ list in the src/ragas/metrics/__init__.py file:

from ragas.metrics import context_precision

This should resolve the ImportError you are encountering [1][2].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Aug 20 '24 00:08 dosubot[bot]