Closed whosyourdadds closed 6 months ago
langchain对reranker的支持不如llamaindex,所以集成进langchain的reranker接口由BCEmbedding这个python包提供,解决方案: 1、你需要安装本repository:pip install BCEmbedding==0.1.3 2、按照这个样例来调用:https://github.com/netease-youdao/BCEmbedding?tab=readme-ov-file#1-used-in-langchain
langchain对reranker的支持不如llamaindex,所以集成进langchain的reranker接口由BCEmbedding这个python包提供,解决方案: 1、你需要安装本存储库:pip install BCEmbedding==0.1.3 2、按照这个样例来调用:https://github.com/netease-youdao/BCEmbedding?tab=readme-ov-file#1-used-in-langchain
我使用的就是这段样例,同时也安装了相关的依赖包. 似乎是我的环境导致的,前一天还没报错
代码: reranker = BCERerank(model="./bce-reranker-base_v1", top_n=5, device='cuda:0')
错误信息:
ValueError Traceback (most recent call last) Cell In[6], line 39 31 embed_model = HuggingFaceEmbeddings( 32 model_name=embedding_model_name, 33 model_kwargs=embedding_model_kwargs, 34 encode_kwargs=embedding_encode_kwargs 35 ) 36 # 创建一个reranker模型 37 # reranker_args = {'model': './bce-reranker-base_v1', 'top_n': 5, 'device': 'cuda:0'} 38 # reranker = BCERerank() ---> 39 reranker = BCERerank(model="./bce-reranker-base_v1", top_n=5, device='cuda:0')
File /mnt/workspace/BCEmbedding/BCEmbedding/tools/langchain/bce_rerank.py:55, in BCERerank.init(self, top_n, model, device, kwargs) 50 except ImportError: 51 raise ImportError( 52 "Cannot import
BCEmbedding
package,", 53 "pleasepip install BCEmbedding>=0.1.2
", 54 ) ---> 55 self._model = RerankerModel(model_name_or_path=model, device=device, kwargs) 56 super().init(top_n=top_n, model=model)File /opt/conda/lib/python3.10/site-packages/pydantic/v1/main.py:357, in BaseModel.setattr(self, name, value) 354 return object_setattr(self, name, value) 356 if self.config.extra is not Extra.allow and name not in self.fields: --> 357 raise ValueError(f'"{self.class.name}" object has no field "{name}"') 358 elif not self.config.allow_mutation or self.config.frozen: 359 raise TypeError(f'"{self.class.name}" is immutable and does not support item assignment')
ValueError: "BCERerank" object has no field "_model"