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:
@@ -4,6 +4,7 @@ This module provides the RAGEngine class that handles knowledge document
|
||||
storage and retrieval using ChromaDB and sentence-transformers embeddings.
|
||||
"""
|
||||
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
import chromadb
|
||||
@@ -28,6 +29,11 @@ class RAGEngine:
|
||||
"""Initialize RAG engine with ChromaDB and embedding model."""
|
||||
settings = get_settings()
|
||||
|
||||
# Set HuggingFace mirror if configured
|
||||
if settings.HF_ENDPOINT:
|
||||
os.environ['HF_ENDPOINT'] = settings.HF_ENDPOINT
|
||||
logger.info(f"Using HuggingFace mirror: {settings.HF_ENDPOINT}")
|
||||
|
||||
# Initialize ChromaDB persistent client
|
||||
logger.info(f"Initializing ChromaDB at: {settings.CHROMA_DB_PATH}")
|
||||
self.chroma_client = chromadb.PersistentClient(
|
||||
|
||||
Reference in New Issue
Block a user