#3040·ragas

answer_relevancy 通过同步的 embed_query/embed_documents 封锁整个事件循环,导致 evaluate() 处理的无关并发任务停滞不前

作者: ecalogero创建于 2026年9月27日更新于 2026年9月27日
标签bug

ragas/metrics/_answer_relevance.py (ragas 0.4.3): Python def calculate_similarity(self, question: str, generated_questions: list[str]): ... question_vec = np.asarray(self.embeddings.embed_query(question)).reshape(1, -1) # line 100 gen_question_vec = np.asarray( self.embeddings.embed_documents(generated_questions) ).reshape(len(generated_questions), -1) called from: Python def _calculate_score(self, answers, row) -> float: ... cosine_sim = self.calculate_similarity(question, gen_questions) # line 126 — sync call, not awaited async def _ascore(self, row, callbacks) -> float: ... responses = await self.question_generation.generate_multiple(...) # correctly async return self._calculate_score(responses, row) # line 141 — the blocking call happens here ragas/metrics/base.py shows the correct pattern is already used elsewhere in the codebase (checking hasattr(embedding_model, "embed_query") and falling back to await ...aembed_query(text) when available), so this looks like an oversight specific to _answer_relevance.py rather than a deliberate design choice. Reproduction ragas==0.4.3, LangChain-core==0.3.86, LangChain-google-vertexai==2.1.2, Python 3.12 evaluate(dataset=..., metrics=[faithfulness, answer_relevancy, context_precision, context_recall], run_config=RunConfig(timeout=700, max_workers=16)) over a 22-row dataset, embeddings backed by VertexAIEmbeddings (a real network-backed embeddings provider, not a local/instant one) Traced the run with a Langfuse callback handler passed via callbacks= Observed behavior Multiple faithfulness and context_precision tasks raised TimeoutError() from ragas.executor despite their own underlying ChatVertexAI generation calls (visible in the trace) completing in roughly 1–1.5 minutes each. In the traces, the wrapping metric span consistently ran far longer than the single LLM generation nested inside it — e.g. one context_precision sub-step showed a 10m09s wrapper

内容来源: vibrantlabsai/ragas