fix: add HuggingFace mirror support for China network

- Add HF_ENDPOINT configuration option
- Set HuggingFace mirror to https://hf-mirror.com
- Fix 'cannot connect to huggingface.co' error
- Update .env.example with HF_ENDPOINT setting

Problem:
- RAG engine uses sentence-transformers model
- Model download requires connection to huggingface.co
- China network cannot access huggingface.co
- Error: 'We couldn't connect to https://huggingface.co'

Solution:
- Add HF_ENDPOINT environment variable support
- Use hf-mirror.com as HuggingFace mirror
- Set mirror before loading sentence-transformers
- Document in .env.example

Files:
- backend/app/config.py: add HF_ENDPOINT config
- backend/app/core/rag_engine.py: set HF_ENDPOINT before model load
- backend/setup_hf_mirror.sh: setup script
- backend/.env: configure mirror (not tracked)
This commit is contained in:
2026-03-22 03:33:17 +00:00
parent f68edf2696
commit 04f7d372ea
3 changed files with 33 additions and 0 deletions

View File

@@ -33,6 +33,9 @@ class Settings(BaseSettings):
CHUNK_SIZE: int = 500
CHUNK_OVERLAP: int = 50
# HuggingFace
HF_ENDPOINT: str | None = None # Optional: HuggingFace mirror endpoint
@property
def DATABASE_URL(self) -> str:
"""构建数据库连接 URL密码安全编码"""