Skip to content

Commit

Permalink
fix(metrics): avoid getting none in context_recall (#355)
Browse files Browse the repository at this point in the history
Maybe this isssue #352
is talking about the same thing.

---------

Co-authored-by: Dash <[email protected]>
  • Loading branch information
yuukidach and Dash authored Dec 7, 2023
1 parent 68c7ed6 commit af55f18
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ rich
ruff
isort
black[jupyter]
pyright
pyright==1.1.338
llama_index
notebook
sphinx-autobuild
Expand Down
10 changes: 7 additions & 3 deletions src/ragas/metrics/_context_recall.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,14 @@ def _score_batch(
for response in responses:
response = load_as_json(response[0])
if response:
response = [
int(item.get("Attributed", "").lower() == "yes")
if item.get("Attributed")
else np.nan
for item in response
]
denom = len(response)
numerator = sum(
item.get("Attributed").lower() == "yes" for item in response
)
numerator = sum(response)
scores.append(numerator / denom)
else:
scores.append(np.nan)
Expand Down

0 comments on commit af55f18

Please sign in to comment.