mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
Compatible with unique index conflicts (#3183)
This commit is contained in:
parent
ca3e2e6cc0
commit
2e4dec365d
|
@ -41,7 +41,8 @@ class CacheEmbedding(Embeddings):
|
||||||
embedding_queue_embeddings = []
|
embedding_queue_embeddings = []
|
||||||
try:
|
try:
|
||||||
model_type_instance = cast(TextEmbeddingModel, self._model_instance.model_type_instance)
|
model_type_instance = cast(TextEmbeddingModel, self._model_instance.model_type_instance)
|
||||||
model_schema = model_type_instance.get_model_schema(self._model_instance.model, self._model_instance.credentials)
|
model_schema = model_type_instance.get_model_schema(self._model_instance.model,
|
||||||
|
self._model_instance.credentials)
|
||||||
max_chunks = model_schema.model_properties[ModelPropertyKey.MAX_CHUNKS] \
|
max_chunks = model_schema.model_properties[ModelPropertyKey.MAX_CHUNKS] \
|
||||||
if model_schema and ModelPropertyKey.MAX_CHUNKS in model_schema.model_properties else 1
|
if model_schema and ModelPropertyKey.MAX_CHUNKS in model_schema.model_properties else 1
|
||||||
for i in range(0, len(embedding_queue_texts), max_chunks):
|
for i in range(0, len(embedding_queue_texts), max_chunks):
|
||||||
|
@ -61,6 +62,7 @@ class CacheEmbedding(Embeddings):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception('Failed transform embedding: ', e)
|
logging.exception('Failed transform embedding: ', e)
|
||||||
cache_embeddings = []
|
cache_embeddings = []
|
||||||
|
try:
|
||||||
for i, embedding in zip(embedding_queue_indices, embedding_queue_embeddings):
|
for i, embedding in zip(embedding_queue_indices, embedding_queue_embeddings):
|
||||||
text_embeddings[i] = embedding
|
text_embeddings[i] = embedding
|
||||||
hash = helper.generate_text_hash(texts[i])
|
hash = helper.generate_text_hash(texts[i])
|
||||||
|
@ -72,6 +74,8 @@ class CacheEmbedding(Embeddings):
|
||||||
db.session.add(embedding_cache)
|
db.session.add(embedding_cache)
|
||||||
cache_embeddings.append(hash)
|
cache_embeddings.append(hash)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
except IntegrityError:
|
||||||
|
db.session.rollback()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
logger.error('Failed to embed documents: ', ex)
|
logger.error('Failed to embed documents: ', ex)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user