from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import FAISS
import torch
# 配置模型
model_config = {
"model_name": "/path/to/local/bge-large-zh-v1.5", # 本地模型路径
"model_kwargs": {
"device": "cuda" if torch.cuda.is_available() else "cpu",
},
"encode_kwargs": {
"normalize_embeddings": True,
"batch_size": 32,
"show_progress_bar": True
}
}
# 初始化 embedding 模型
embeddings = HuggingFaceEmbeddings(**model_config)
# 测试模型
texts = ["这是一个测试句子", "这是另一个句子"]
embedded = embeddings.embed_documents(texts)
print(f"嵌入维度: {len(embedded[0])}")
试一下这样,注意你的显卡要好哦,否则可能会很慢