Skip to content

Commit 5ce585c

Browse files
authored
fix tp&fp calc error (#1848)
#1796 Compatibility is being fixed due to different sample trigger points
1 parent b8c6be2 commit 5ce585c

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/ragas/metrics/_factual_correctness.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,10 @@ async def _single_turn_ascore(
257257
else:
258258
response_reference = np.array([])
259259

260+
response_reference = np.array(response_reference, dtype=bool)
260261
tp = sum(reference_response)
261262
fp = sum(~reference_response)
262263
if self.mode != "precision":
263-
response_reference = np.array(response_reference, dtype=bool)
264264
fn = sum(~response_reference)
265265
else:
266266
fn = 0

src/ragas/testset/synthesizers/multi_hop/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ def convert_to_scenario(self, data: t.Dict[str, t.Any]) -> MultiHopScenario:
158158
)
159159

160160
async def _generate_sample(
161-
self, scenario: MultiHopScenario, callbacks: Callbacks
161+
self, scenario: Scenario, callbacks: Callbacks
162162
) -> SingleTurnSample:
163-
163+
if not isinstance(scenario, MultiHopScenario):
164+
raise TypeError('scenario type should be MultiHopScenario')
164165
reference_context = self.make_contexts(scenario)
165166
prompt_input = QueryConditions(
166167
persona=scenario.persona,

src/ragas/testset/synthesizers/single_hop/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ def convert_to_scenario(self, data: t.Dict[str, t.Any]) -> SingleHopScenario:
119119
)
120120

121121
async def _generate_sample(
122-
self, scenario: SingleHopScenario, callbacks: Callbacks
122+
self, scenario: Scenario, callbacks: Callbacks
123123
) -> SingleTurnSample:
124-
124+
if not isinstance(scenario, SingleHopScenario):
125+
raise TypeError('scenario type should be SingleHopScenario')
125126
reference_context = scenario.nodes[0].properties.get("page_content", "")
126127
prompt_input = QueryCondition(
127128
persona=scenario.persona,

0 commit comments

Comments
 (0)