Skip to content

Commit 24425ac

Browse files
authored
Fix: reference key error in LLMContextPrecisionWithoutReference (#1570)
fix to #1567
1 parent 38d09dc commit 24425ac

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/ragas/metrics/_context_precision.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class LLMContextPrecisionWithReference(MetricWithLLM, SingleTurnMetric):
104104
max_retries: int = 1
105105
_reproducibility: int = 1
106106

107+
def _get_row_attributes(self, row: t.Dict) -> t.Tuple[str, t.List[str], t.Any]:
108+
return row["user_input"], row["retrieved_contexts"], row["reference"]
109+
107110
@property
108111
def reproducibility(self):
109112
return self._reproducibility
@@ -153,14 +156,15 @@ async def _ascore(
153156
) -> float:
154157
assert self.llm is not None, "LLM is not set"
155158

159+
user_input, retrieved_contexts, reference = self._get_row_attributes(row)
156160
responses = []
157-
for context in row["retrieved_contexts"]:
161+
for context in retrieved_contexts:
158162
verdicts: t.List[Verification] = (
159163
await self.context_precision_prompt.generate_multiple(
160164
data=QAC(
161-
question=row["user_input"],
165+
question=user_input,
162166
context=context,
163-
answer=row["reference"],
167+
answer=reference,
164168
),
165169
n=self.reproducibility,
166170
llm=self.llm,

0 commit comments

Comments
 (0)