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.

fix: float values are not json for nan value close #11827 (#11840)

yihong5a8a90156022
diff --git a/api/core/rag/embedding/cached_embedding.py b/api/core/rag/embedding/cached_embedding.py
index fc8e0440c33..652f7e145fd 100644
--- a/api/core/rag/embedding/cached_embedding.py
+++ b/api/core/rag/embedding/cached_embedding.py
@@ -65,6 +65,11 @@ class CacheEmbedding(Embeddings):
for vector in embedding_result.embeddings:
try:
normalized_embedding = (vector / np.linalg.norm(vector)).tolist()
+ # stackoverflow best way: https://stackoverflow.com/questions/20319813/how-to-check-list-containing-nan
+ if np.isnan(normalized_embedding).any():
+ # for issue #11827 float values are not json compliant
+ logger.warning(f"Normalized embedding is nan: {normalized_embedding}")
+ continue
embedding_queue_embeddings.append(normalized_embedding)
except IntegrityError:
db.session.rollback()