mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 18:29:04 +08:00
Duplicate embedding cache check (#3134)
Co-authored-by: jyong <jyong@dify.ai>
This commit is contained in:
parent
ef80b3711e
commit
ab9fcbdfb9
@ -60,14 +60,17 @@ class CacheEmbedding(Embeddings):
|
|||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.exception('Failed transform embedding: ', e)
|
logging.exception('Failed transform embedding: ', e)
|
||||||
|
cache_embeddings = []
|
||||||
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])
|
||||||
embedding_cache = Embedding(model_name=self._model_instance.model,
|
if hash not in cache_embeddings:
|
||||||
hash=hash,
|
embedding_cache = Embedding(model_name=self._model_instance.model,
|
||||||
provider_name=self._model_instance.provider)
|
hash=hash,
|
||||||
embedding_cache.set_embedding(embedding)
|
provider_name=self._model_instance.provider)
|
||||||
db.session.add(embedding_cache)
|
embedding_cache.set_embedding(embedding)
|
||||||
|
db.session.add(embedding_cache)
|
||||||
|
cache_embeddings.append(hash)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user