@@ -77,25 +77,9 @@ class LLMRAGAnswerRelevancy(BaseOpenAI):
7777 }}
7878 Output: """
7979
80- # 默认的embedding模型
81- embedding_model = None
82-
8380 # 配置参数
8481 strictness = 3 # 生成的问题数量
8582
86- @classmethod
87- def init_embedding_model (cls , model_name : str = "text-embedding-3-large" ):
88- """初始化embedding模型"""
89- # 确保LLM客户端已经创建
90- if not hasattr (cls , 'client' ) or cls .client is None :
91- cls .create_client ()
92-
93- # 直接使用OpenAI的Embedding API
94- cls .embedding_model = {
95- 'model_name' : model_name ,
96- 'client' : cls .client
97- }
98-
9983 @classmethod
10084 def build_messages (cls , input_data : Data ) -> List :
10185 """构建LLM输入消息"""
@@ -162,8 +146,14 @@ def process_question_response(cls, response: str) -> Dict[str, Any]:
162146 @classmethod
163147 def calculate_similarity (cls , question : str , generated_questions : List [str ]) -> np .ndarray :
164148 """计算原始问题与生成问题的相似度"""
149+ # 检查 Embedding 模型是否已初始化
165150 if cls .embedding_model is None :
166- cls .init_embedding_model ()
151+ raise ValueError (
152+ "Embedding model not initialized. Please configure 'embedding_config' in your LLM config with:\n "
153+ " - model: embedding model name (e.g., 'BAAI/bge-m3')\n "
154+ " - api_url: embedding service URL\n "
155+ " - key: API key (optional for local services)"
156+ )
167157
168158 # 检查生成的问题是否为空列表或全为空字符串
169159 if not generated_questions or all (q == "" for q in generated_questions ):
@@ -229,9 +219,6 @@ def calculate_score(cls, answers: List[Dict[str, Any]], original_question: str)
229219 @classmethod
230220 def eval (cls , input_data : Data ) -> EvalDetail :
231221 """评估答案相关性"""
232- # 初始化embedding模型(如果尚未初始化)
233- if cls .embedding_model is None :
234- cls .init_embedding_model ()
235222 raw_data = getattr (input_data , 'raw_data' , {})
236223 # 提取原始问题
237224 original_question = input_data .prompt or raw_data .get ("question" , "" )
@@ -245,7 +232,6 @@ def eval(cls, input_data: Data) -> EvalDetail:
245232 cls .dynamic_config .parameters ['temperature' ] = 0.7
246233 else :
247234 # 如果没有parameters,创建一个包含temperature的parameters
248- from dingo .config .input_args import EvaluatorLLMArgs
249235 current_params = cls .dynamic_config .parameters or {}
250236 current_params ['temperature' ] = 0.7
251237 cls .dynamic_config .parameters = current_params
@@ -267,11 +253,6 @@ def eval(cls, input_data: Data) -> EvalDetail:
267253 # 检查是否有自定义的strictness参数
268254 cls .strictness = cls .dynamic_config .parameters .get ('strictness' , 3 )
269255
270- # 检查是否有自定义的embedding模型
271- embedding_model_name = cls .dynamic_config .parameters .get ('embedding_model' , None )
272- if embedding_model_name :
273- cls .init_embedding_model (embedding_model_name )
274-
275256 # 构建详细的reason文本
276257 all_reasons = []
277258 for detail in details :
0 commit comments