RelevanceModel.predict:v4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import weave
from ragas.dataset_schema import SingleTurnSample
@weave.op()
async def predict(self, question: str, documents: list[str], response: str):
sample = SingleTurnSample(
user_input=question,
response=response,
retrieved_contexts=documents,
)
score = await self._relevance_scorer.single_turn_ascore(sample)
if score >= self.threshold:
return {"flagged": False, "extras": {"score": score}}
return {"flagged": True, "extras": {"score": score}}