Equals

class opik.evaluation.metrics.Equals(case_sensitive: bool = False, name: str = 'equals_metric')

Bases: BaseMetric

A metric that checks if an output string exactly matches an expected output string.

This metric returns a score of 1.0 if the strings match exactly, and 0.0 otherwise. The comparison can be made case-sensitive or case-insensitive.

Parameters:
  • case_sensitive – Whether the comparison should be case-sensitive. Defaults to False.

  • name – The name of the metric. Defaults to “equals_metric”.

Example

>>> from comet_llm_eval.evaluation.metrics import Equals
>>> equals_metric = Equals(case_sensitive=True)
>>> result = equals_metric.score("Hello, World!", "Hello, World!")
>>> print(result.value)
1.0
>>> result = equals_metric.score("Hello, World!", "hello, world!")
>>> print(result.value)
0.0
score(output: str, reference: str, **ignored_kwargs: Any) ScoreResult

Calculate the score based on whether the output string exactly matches the expected output.

Parameters:
  • output – The output string to check.

  • reference – The expected output string to compare against.

  • **ignored_kwargs – Additional keyword arguments that are ignored.

Returns:

A ScoreResult object with a value of 1.0 if the strings match,

0.0 otherwise.

Return type:

score_result.ScoreResult

async ascore(*args: Any, **kwargs: Any) ScoreResult | List[ScoreResult]

Async public method that can be called independently.