Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Duplicate embedding cache check (#3134)

Jyongab9fcbdfb961
diff --git a/api/core/embedding/cached_embedding.py b/api/core/embedding/cached_embedding.py
index 11dfe8dc15f..4156368e562 100644
--- a/api/core/embedding/cached_embedding.py
+++ b/api/core/embedding/cached_embedding.py
@@ -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])
- 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)
+ 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()