|
@@ -5,6 +5,7 @@ from typing import Optional, cast
|
|
|
import numpy as np
|
|
|
from sqlalchemy.exc import IntegrityError
|
|
|
|
|
|
+from configs import dify_config
|
|
|
from core.embedding.embedding_constant import EmbeddingInputType
|
|
|
from core.model_manager import ModelInstance
|
|
|
from core.model_runtime.entities.model_entities import ModelPropertyKey
|
|
@@ -110,6 +111,8 @@ class CacheEmbedding(Embeddings):
|
|
|
embedding_results = embedding_result.embeddings[0]
|
|
|
embedding_results = (embedding_results / np.linalg.norm(embedding_results)).tolist()
|
|
|
except Exception as ex:
|
|
|
+ if dify_config.DEBUG:
|
|
|
+ logging.exception(f"Failed to embed query text: {ex}")
|
|
|
raise ex
|
|
|
|
|
|
try:
|
|
@@ -122,6 +125,8 @@ class CacheEmbedding(Embeddings):
|
|
|
encoded_str = encoded_vector.decode("utf-8")
|
|
|
redis_client.setex(embedding_cache_key, 600, encoded_str)
|
|
|
except Exception as ex:
|
|
|
- logging.exception("Failed to add embedding to redis %s", ex)
|
|
|
+ if dify_config.DEBUG:
|
|
|
+ logging.exception("Failed to add embedding to redis %s", ex)
|
|
|
+ raise ex
|
|
|
|
|
|
return embedding_results
|