MCPcopy Create free account
hub / github.com/AQ-MedAI/MedMemoryBench / compute

Method compute

metrics/string_match.py:43–76  ·  view source on GitHub ↗
(
        self,
        query_id: str,
        query_type: str,
        model_output: str,
        expected_answers: List[str],
        question: str = "",
        **kwargs
    )

Source from the content-addressed store, hash-verified

41 NAME = "string_contain"
42
43 def compute(
44 self,
45 query_id: str,
46 query_type: str,
47 model_output: str,
48 expected_answers: List[str],
49 question: str = "",
50 **kwargs
51 ) -> MetricResult:
52 model_normalized = normalize_text(model_output)
53
54 matched = []
55 for answer in expected_answers:
56 answer_normalized = normalize_text(answer)
57 if answer_normalized and answer_normalized in model_normalized:
58 matched.append(answer)
59
60 is_correct = len(matched) == len(expected_answers) and len(expected_answers) > 0
61
62 return MetricResult(
63 query_id=query_id,
64 query_type=query_type,
65 score=1.0 if is_correct else 0.0,
66 is_correct=is_correct,
67 model_output=model_output,
68 expected_answer=", ".join(expected_answers),
69 question=question,
70 details={
71 "matched_answers": matched,
72 "total_expected": len(expected_answers),
73 "total_matched": len(matched),
74 "metric": self.NAME,
75 }
76 )
77
78
79class ExactMatchMetric(BaseMetric):

Callers

nothing calls this directly

Calls 3

normalize_textFunction · 0.85
MetricResultClass · 0.85
joinMethod · 0.45

Tested by

no test coverage detected