mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
fix mem leak for local reranker (#1295)
### What problem does this PR solve? #1288 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -39,6 +39,7 @@ class Base(ABC):
|
|||||||
class DefaultRerank(Base):
|
class DefaultRerank(Base):
|
||||||
_model = None
|
_model = None
|
||||||
_model_lock = threading.Lock()
|
_model_lock = threading.Lock()
|
||||||
|
|
||||||
def __init__(self, key, model_name, **kwargs):
|
def __init__(self, key, model_name, **kwargs):
|
||||||
"""
|
"""
|
||||||
If you have trouble downloading HuggingFace models, -_^ this might help!!
|
If you have trouble downloading HuggingFace models, -_^ this might help!!
|
||||||
@ -102,19 +103,24 @@ class JinaRerank(Base):
|
|||||||
|
|
||||||
class YoudaoRerank(DefaultRerank):
|
class YoudaoRerank(DefaultRerank):
|
||||||
_model = None
|
_model = None
|
||||||
|
_model_lock = threading.Lock()
|
||||||
|
|
||||||
def __init__(self, key=None, model_name="maidalun1020/bce-reranker-base_v1", **kwargs):
|
def __init__(self, key=None, model_name="maidalun1020/bce-reranker-base_v1", **kwargs):
|
||||||
from BCEmbedding import RerankerModel
|
from BCEmbedding import RerankerModel
|
||||||
if not YoudaoRerank._model:
|
if not YoudaoRerank._model:
|
||||||
try:
|
with YoudaoRerank._model_lock:
|
||||||
print("LOADING BCE...")
|
if not YoudaoRerank._model:
|
||||||
YoudaoRerank._model = RerankerModel(model_name_or_path=os.path.join(
|
try:
|
||||||
get_home_cache_dir(),
|
print("LOADING BCE...")
|
||||||
re.sub(r"^[a-zA-Z]+/", "", model_name)))
|
YoudaoRerank._model = RerankerModel(model_name_or_path=os.path.join(
|
||||||
except Exception as e:
|
get_home_cache_dir(),
|
||||||
YoudaoRerank._model = RerankerModel(
|
re.sub(r"^[a-zA-Z]+/", "", model_name)))
|
||||||
model_name_or_path=model_name.replace(
|
except Exception as e:
|
||||||
"maidalun1020", "InfiniFlow"))
|
YoudaoRerank._model = RerankerModel(
|
||||||
|
model_name_or_path=model_name.replace(
|
||||||
|
"maidalun1020", "InfiniFlow"))
|
||||||
|
|
||||||
|
self._model = YoudaoRerank._model
|
||||||
|
|
||||||
def similarity(self, query: str, texts: list):
|
def similarity(self, query: str, texts: list):
|
||||||
pairs = [(query, truncate(t, self._model.max_length)) for t in texts]
|
pairs = [(query, truncate(t, self._model.max_length)) for t in texts]
|
||||||
|
|||||||
Reference in New Issue
Block a user