From 6325f796705193a9788b9dd37df8b93bb41cf7d4 Mon Sep 17 00:00:00 2001 From: yihong0618 Date: Thu, 19 Dec 2024 18:04:01 +0800 Subject: [PATCH] fix: float values are not json for nan value close #11827 Signed-off-by: yihong0618 --- api/core/rag/embedding/cached_embedding.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/core/rag/embedding/cached_embedding.py b/api/core/rag/embedding/cached_embedding.py index fc8e0440c332c3..652f7e145fd94d 100644 --- a/api/core/rag/embedding/cached_embedding.py +++ b/api/core/rag/embedding/cached_embedding.py @@ -65,6 +65,11 @@ def embed_documents(self, texts: list[str]) -> list[list[float]]: 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()