Spaces:
Sleeping
Sleeping
yjhuang
commited on
Commit
·
5ebc995
1
Parent(s):
31bbc21
correct HuggingFaceEmbeddings and Chroma vector store initialization
Browse files- function.py +18 -1
function.py
CHANGED
|
@@ -132,12 +132,29 @@ def retrieve_resume_info(query: str):
|
|
| 132 |
|
| 133 |
print('!! retrieve_resume_info() is called !!')
|
| 134 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 135 |
# Initialize embedding function
|
| 136 |
cv_path = "./CV.docx"
|
| 137 |
vector_dir = "./vector"
|
| 138 |
model_name = "BAAI/bge-large-zh-v1.5"
|
| 139 |
|
| 140 |
-
embeddings = HuggingFaceEmbeddings(model_name=model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
# Check if the vector database already exists
|
| 143 |
if os.path.exists(vector_dir):
|
|
|
|
| 132 |
|
| 133 |
print('!! retrieve_resume_info() is called !!')
|
| 134 |
|
| 135 |
+
import os
|
| 136 |
+
os.environ["HF_HOME"] = "/tmp/huggingface"
|
| 137 |
+
os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
|
| 138 |
+
|
| 139 |
+
|
| 140 |
# Initialize embedding function
|
| 141 |
cv_path = "./CV.docx"
|
| 142 |
vector_dir = "./vector"
|
| 143 |
model_name = "BAAI/bge-large-zh-v1.5"
|
| 144 |
|
| 145 |
+
#embeddings = HuggingFaceEmbeddings(model_name=model_name)
|
| 146 |
+
# 設置模型參數
|
| 147 |
+
model_kwargs = {'device': 'cpu'} # 如果有 GPU,改成 'cuda'
|
| 148 |
+
encode_kwargs = {'normalize_embeddings': False} # 是否標準化向量
|
| 149 |
+
|
| 150 |
+
# 初始化 Hugging Face Embeddings
|
| 151 |
+
embeddings = HuggingFaceEmbeddings(
|
| 152 |
+
model_name=model_name,
|
| 153 |
+
model_kwargs=model_kwargs,
|
| 154 |
+
encode_kwargs=encode_kwargs
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
|
| 159 |
# Check if the vector database already exists
|
| 160 |
if os.path.exists(vector_dir):
|