解决离线服务器无法加载HuggingFaceEmbeddings向量化模型的问题
创始人
2025-01-20 16:35:12
0

由于服务器是离线的,因此我先在本地到huggingface官网下载模型text2vec,然后上传到服务器上运行,报错:

(MaxRetryError('HTTPSConnectionPool(host=\'huggingface.co\', port=443): Max retries exceeded with url: /api/models/sentence-transformers/text2vec-base-chinese/revision/main (Caused by NameResolutionError(": Failed to resolve \'huggingface.co\' ([Errno -3] Temporary failure in name resolution)"))'), '(Request ID: d787098f-eabd-4f11-8150-623bd99a55e2)')

An error happened while trying to locate the files on the Hub and we cannot find the appropriate snapshot folder for the specified revision on the local disk. Please check your internet connection and try again.

huggingface_hub.utils._errors.LocalEntryNotFoundError: Cannot find an appropriate cached snapshot folder for the specified revision on the local disk and outgoing traffic has been disabled. To enable repo look-ups and downloads online, pass 'local_files_only=False' as input.
 

HuggingFaceEmbeddings它识别不了这个路径下的文件,因此我将cache_folder的值换成'shibing624/text2vec-base-chinese'依然报相同的错误。

然后我去官网看如何调用这个模型,选择了下面这种方式:

再次报错:

 db = store_chroma(documents,embeddings)

AttributeError: 'BertModel' object has no attribute 'embed_documents'

也就是说加载完向量化模型后,我初始化了Chroma向量数据库,然后对传入的doc文档数据进行向量化,它会提示找不到embed_documents这个属性。本身BertModel是没有这个属性的,但是Chroma却需要调用这个属性来实现文档向量化(通过HuggingFaceEmbeddings来加载模型就不会报错,但是离线服务器上用不了)。因此,自己写一个embed_documents来实现就好啦,如下所示:

先在load_embedding_mode里面添加一个方法embedding_function,然后再建立一个类:

最后再调用这个类,就能正常对文档进行向量化和本地持久化了。

embedding_function = EmbeddingFunction(load_embedding_mode()) db = Chroma(embedding_function=embedding_function, persist_directory='VectorStore')

相关内容

热门资讯

妙计辅助!创思维激k有挂吗(辅... 妙计辅助!创思维激k有挂吗(辅助挂)切实存在有辅助脚本(果真有挂)创思维激k有挂吗辅助器是一种具有地...
记者获悉!aapoker破解侠... 记者获悉!aapoker破解侠是真的吗,来玩app破解版,练习教程(有挂讲解)1、很好的工具软件,可...
学习辅助!新道游辅助软件下载(... 学习辅助!新道游辅助软件下载(辅助挂)竟然真的有辅助方法(有挂透视)1、打开软件启动之后找到中间准星...
黑科技代打!wepoker模拟... 黑科技代打!wepoker模拟器哪个,wepoker可以免费玩吗,绝活教程(有挂细节)wepoker...
办法辅助!wepoker修改工... 办法辅助!wepoker修改工具(辅助挂)都是真的有辅助工具(有挂教程)1、在wepoker修改工具...
明白辅助挂!佛手在线有挂吗,w... 明白辅助挂!佛手在线有挂吗,wepoker透视功能下载,积累教程(有挂猫腻)1、完成wepoker透...
要领辅助!老友辅助工具下载(辅... 要领辅助!老友辅助工具下载(辅助挂)果然真的有辅助技巧(真实有挂)1、完成老友辅助工具下载辅助器v3...
此事迅速冲上热搜!sohoo ... 此事迅速冲上热搜!sohoo poker辅助,来玩app破解版,指南书教程(有挂攻略)1、金币登录送...
举措辅助!牛总管辅助神器(辅助... 举措辅助!牛总管辅助神器(辅助挂)确实确实有辅助软件(有挂透明挂)进入游戏-大厅左侧-新手福利-激活...
值得注意的是!wepoker透... 值得注意的是!wepoker透视脚本免费,sohoo开挂辅助,诀窍教程(有挂教程)wepoker透视...