From f8761b8e3c79dd88b268fa0ec6273d36583ccb74 Mon Sep 17 00:00:00 2001 From: yihong Date: Thu, 19 Dec 2024 20:50:20 +0800 Subject: [PATCH] fix: float values are not json for nan value close #11827 (#11840) 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()