Skip to content

Commit af55f18

Browse files
yuukidachDash
andauthored
fix(metrics): avoid getting none in context_recall (#355)
Maybe this isssue #352 is talking about the same thing. --------- Co-authored-by: Dash <[email protected]>
1 parent 68c7ed6 commit af55f18

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

requirements/dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ rich
22
ruff
33
isort
44
black[jupyter]
5-
pyright
5+
pyright==1.1.338
66
llama_index
77
notebook
88
sphinx-autobuild

src/ragas/metrics/_context_recall.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,14 @@ def _score_batch(
116116
for response in responses:
117117
response = load_as_json(response[0])
118118
if response:
119+
response = [
120+
int(item.get("Attributed", "").lower() == "yes")
121+
if item.get("Attributed")
122+
else np.nan
123+
for item in response
124+
]
119125
denom = len(response)
120-
numerator = sum(
121-
item.get("Attributed").lower() == "yes" for item in response
122-
)
126+
numerator = sum(response)
123127
scores.append(numerator / denom)
124128
else:
125129
scores.append(np.nan)

0 commit comments

Comments
 (0)