Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ragas/integrations/langchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def evaluate_run(
if example.outputs is None or "ground_truth" not in example.outputs:
raise ValueError("expected `ground_truth` in example outputs.")
chain_eval["ground_truth"] = example.outputs["ground_truth"]
eval_output = self(chain_eval, include_run_info=True)
eval_output = self.invoke(chain_eval, include_run_info=True)

evaluation_result = EvaluationResult(
key=self.metric.name, score=eval_output[self.metric.name]
Expand Down
34 changes: 28 additions & 6 deletions src/ragas/metrics/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
C - contexts: context used for generation
G - ground_truth: ground truth answer
"""

from __future__ import annotations

import asyncio
Expand All @@ -25,17 +26,37 @@
EvaluationMode = Enum("EvaluationMode", "qac qa qc gc ga qga qcg")


def get_required_columns(
eval_mod: EvaluationMode, ignore_columns: t.Optional[t.List[str]] = None
) -> t.List[str]:
if eval_mod == EvaluationMode.qac:
keys = ["question", "answer", "contexts"]
elif eval_mod == EvaluationMode.qa:
keys = ["question", "answer"]
elif eval_mod == EvaluationMode.qc:
keys = ["question", "contexts"]
elif eval_mod == EvaluationMode.gc:
keys = ["contexts", "ground_truth"]
elif eval_mod == EvaluationMode.ga:
keys = ["answer", "ground_truth"]
elif eval_mod == EvaluationMode.qga:
keys = ["question", "contexts", "answer", "ground_truth"]
elif eval_mod == EvaluationMode.qcg:
keys = ["question", "contexts", "ground_truth"]
ignore_columns = ignore_columns or []

return [k for k in keys if k not in ignore_columns]


@dataclass
class Metric(ABC):
@property
@abstractmethod
def name(self) -> str:
...
def name(self) -> str: ...

@property
@abstractmethod
def evaluation_mode(self) -> EvaluationMode:
...
def evaluation_mode(self) -> EvaluationMode: ...

@abstractmethod
def init(self, run_config: RunConfig):
Expand Down Expand Up @@ -97,8 +118,9 @@ async def ascore(
return score

@abstractmethod
async def _ascore(self, row: t.Dict, callbacks: Callbacks, is_async: bool) -> float:
...
async def _ascore(
self, row: t.Dict, callbacks: Callbacks, is_async: bool
) -> float: ...


@dataclass
Expand Down