Duplicate embedding cache check (#3134)

Co-authored-by: jyong <jyong@dify.ai>
This commit is contained in:
Jyong 2024-04-07 15:20:58 +08:00 committed by GitHub
parent ef80b3711e
commit ab9fcbdfb9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -60,14 +60,17 @@ class CacheEmbedding(Embeddings):
db.session.rollback()
except Exception as e:
logging.exception('Failed transform embedding: ', e)
cache_embeddings = []
for i, embedding in zip(embedding_queue_indices, embedding_queue_embeddings):
text_embeddings[i] = embedding
hash = helper.generate_text_hash(texts[i])
if hash not in cache_embeddings:
embedding_cache = Embedding(model_name=self._model_instance.model,
hash=hash,
provider_name=self._model_instance.provider)
embedding_cache.set_embedding(embedding)
db.session.add(embedding_cache)
cache_embeddings.append(hash)
db.session.commit()
except Exception as ex:
db.session.rollback()