MCPcopy Create free account
hub / github.com/dataease/SQLBot / save_embeddings

Function save_embeddings

backend/apps/data_training/curd/data_training.py:445–470  ·  view source on GitHub ↗
(session_maker, ids: List[int])

Source from the content-addressed store, hash-verified

443
444
445def save_embeddings(session_maker, ids: List[int]):
446 if not settings.EMBEDDING_ENABLED:
447 return
448
449 if not ids or len(ids) == 0:
450 return
451 try:
452 session = session_maker()
453 _list = session.query(DataTraining).filter(and_(DataTraining.id.in_(ids))).all()
454
455 _question_list = [item.question for item in _list]
456
457 model = EmbeddingModelCache.get_model()
458
459 results = model.embed_documents(_question_list)
460
461 for index in range(len(results)):
462 item = results[index]
463 stmt = update(DataTraining).where(and_(DataTraining.id == _list[index].id)).values(embedding=item)
464 session.execute(stmt)
465 session.commit()
466
467 except Exception:
468 traceback.print_exc()
469 finally:
470 session_maker.remove()
471
472
473embedding_sql = f"""

Callers 1

Calls 5

get_modelMethod · 0.80
removeMethod · 0.65
updateFunction · 0.50
filterMethod · 0.45
valuesMethod · 0.45

Tested by

no test coverage detected