Skip to content

Commit 330724b

Browse files
committed
2 parents 00ab7bc + f95b647 commit 330724b

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

infrastructure/ai/local_embedding_service.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def __init__(self, model_name: str = None, use_gpu: bool = True):
8080
else:
8181
model_path = model_name
8282

83+
# 判断是否为 HuggingFace 模型 ID(如 "BAAI/bge-small-zh-v1.5")
84+
_original_model_name = model_path
85+
_is_hf_model_id = "/" in model_path and not Path(model_path).is_absolute()
86+
8387
# 将路径转为绝对路径(相对路径基于项目根目录)
8488
_resolved = Path(model_path)
8589
if not _resolved.is_absolute():
@@ -95,6 +99,10 @@ def __init__(self, model_name: str = None, use_gpu: bool = True):
9599
if _fallback.exists():
96100
model_name = str(_fallback)
97101
logger.info(f"Using local model path (auto-resolved): {model_name}")
102+
elif _is_hf_model_id:
103+
# 看起来像 HuggingFace 模型 ID,保留原始值让 SentenceTransformer 从缓存加载
104+
model_name = _original_model_name
105+
logger.info(f"Using HuggingFace model ID (cached): {model_name}")
98106
else:
99107
raise FileNotFoundError(
100108
f"Local model not found at '{_resolved}' or '{_fallback}'.\n\n"

0 commit comments

Comments
 (0)