@@ -308,24 +308,26 @@ def select_training_by_question(session: SessionDep, question: str, oid: int, da
308308 _list .append (DataTraining (id = row .id , question = row .question ))
309309
310310 if settings .EMBEDDING_ENABLED :
311- try :
312- model = EmbeddingModelCache .get_model ()
313-
314- embedding = model .embed_query (question )
315-
316- if advanced_application_id is not None :
317- results = session .execute (text (embedding_sql_in_advanced_application ),
318- {'embedding_array' : str (embedding ), 'oid' : oid ,
319- 'advanced_application' : advanced_application_id })
320- else :
321- results = session .execute (text (embedding_sql ),
322- {'embedding_array' : str (embedding ), 'oid' : oid , 'datasource' : datasource })
323-
324- for row in results :
325- _list .append (DataTraining (id = row .id , question = row .question ))
326-
327- except Exception :
328- traceback .print_exc ()
311+ with session .begin_nested ():
312+ try :
313+ model = EmbeddingModelCache .get_model ()
314+
315+ embedding = model .embed_query (question )
316+
317+ if advanced_application_id is not None :
318+ results = session .execute (text (embedding_sql_in_advanced_application ),
319+ {'embedding_array' : str (embedding ), 'oid' : oid ,
320+ 'advanced_application' : advanced_application_id })
321+ else :
322+ results = session .execute (text (embedding_sql ),
323+ {'embedding_array' : str (embedding ), 'oid' : oid , 'datasource' : datasource })
324+
325+ for row in results :
326+ _list .append (DataTraining (id = row .id , question = row .question ))
327+
328+ except Exception :
329+ traceback .print_exc ()
330+ session .rollback ()
329331
330332 _map : dict = {}
331333 _ids : list [int ] = []
0 commit comments