mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-05-20 01:28:36 +08:00
chore: add abstract decorator and output log when query embedding fails (#9264)
This commit is contained in:
parent
ea6734f550
commit
d97d3ff5fc
@ -5,6 +5,7 @@ from typing import Optional, cast
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from sqlalchemy.exc import IntegrityError
|
from sqlalchemy.exc import IntegrityError
|
||||||
|
|
||||||
|
from configs import dify_config
|
||||||
from core.embedding.embedding_constant import EmbeddingInputType
|
from core.embedding.embedding_constant import EmbeddingInputType
|
||||||
from core.model_manager import ModelInstance
|
from core.model_manager import ModelInstance
|
||||||
from core.model_runtime.entities.model_entities import ModelPropertyKey
|
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_result.embeddings[0]
|
||||||
embedding_results = (embedding_results / np.linalg.norm(embedding_results)).tolist()
|
embedding_results = (embedding_results / np.linalg.norm(embedding_results)).tolist()
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
if dify_config.DEBUG:
|
||||||
|
logging.exception(f"Failed to embed query text: {ex}")
|
||||||
raise ex
|
raise ex
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -122,6 +125,8 @@ class CacheEmbedding(Embeddings):
|
|||||||
encoded_str = encoded_vector.decode("utf-8")
|
encoded_str = encoded_vector.decode("utf-8")
|
||||||
redis_client.setex(embedding_cache_key, 600, encoded_str)
|
redis_client.setex(embedding_cache_key, 600, encoded_str)
|
||||||
except Exception as ex:
|
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
|
return embedding_results
|
||||||
|
@ -27,9 +27,11 @@ class BaseKeyword(ABC):
|
|||||||
def delete_by_ids(self, ids: list[str]) -> None:
|
def delete_by_ids(self, ids: list[str]) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def delete(self) -> None:
|
def delete(self) -> None:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@abstractmethod
|
||||||
def search(self, query: str, **kwargs: Any) -> list[Document]:
|
def search(self, query: str, **kwargs: Any) -> list[Document]:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class ElasticSearchVector(BaseVector):
|
|||||||
raise ValueError("Elasticsearch vector database version must be greater than 8.0.0")
|
raise ValueError("Elasticsearch vector database version must be greater than 8.0.0")
|
||||||
|
|
||||||
def get_type(self) -> str:
|
def get_type(self) -> str:
|
||||||
return "elasticsearch"
|
return VectorType.ELASTICSEARCH
|
||||||
|
|
||||||
def add_texts(self, documents: list[Document], embeddings: list[list[float]], **kwargs):
|
def add_texts(self, documents: list[Document], embeddings: list[list[float]], **kwargs):
|
||||||
uuids = self._get_uuids(documents)
|
uuids = self._get_uuids(documents)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user