fix: better gard nan value from numpy for issue #11827 (#11864)

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
This commit is contained in:
yihong 2024-12-20 09:28:32 +08:00 committed by GitHub
commit 463fbe2680
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 18 additions and 4 deletions

View file

@ -116,6 +116,8 @@ class CacheEmbedding(Embeddings):
embedding_results = embedding_result.embeddings[0]
embedding_results = (embedding_results / np.linalg.norm(embedding_results)).tolist()
if np.isnan(embedding_results).any():
raise ValueError("Normalized embedding is nan please try again")
except Exception as ex:
if dify_config.DEBUG:
logging.exception(f"Failed to embed query text '{text[:10]}...({len(text)} chars)'")