Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error message for missing embeddings in Answer Relevancy Metric #1877

Merged
merged 8 commits into from
Jan 24, 2025
4 changes: 3 additions & 1 deletion src/ragas/metrics/_answer_relevance.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ class ResponseRelevancy(MetricWithLLM, MetricWithEmbeddings, SingleTurnMetric):
strictness: int = 3

def calculate_similarity(self, question: str, generated_questions: list[str]):
assert self.embeddings is not None
assert (
self.embeddings is not None
), f"Error: '{self.name}' requires embeddings to be set."
question_vec = np.asarray(self.embeddings.embed_query(question)).reshape(1, -1)
gen_question_vec = np.asarray(
self.embeddings.embed_documents(generated_questions)
Expand Down
4 changes: 3 additions & 1 deletion src/ragas/metrics/_answer_similarity.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ async def _single_turn_ascore(
return await self._ascore(row, callbacks)

async def _ascore(self, row: t.Dict, callbacks: Callbacks) -> float:
assert self.embeddings is not None, "embeddings must be set"
assert (
self.embeddings is not None
), f"Error: '{self.name}' requires embeddings to be set."

ground_truth = t.cast(str, row["reference"])
answer = t.cast(str, row["response"])
Expand Down
Loading