RetrievalQA.from_chain_type 显示无法实例化抽象的验证错误

问题描述 投票:0回答:1

当我尝试使用本地 llm 和 PineCone VectorDataBase 构建 RetrievalQA.from_chain_type 时。但是,由于无法实例化 BaseRetriever 抽象类的错误,因此无法创建检索器。

该错误是验证错误,如下所示:

ValidationError                           Traceback (most recent call last)
/Users/dhruv/Desktop/Machine_Learning/Projects/Medical_ChatBot_Application/preprocessing/Experiment.ipynb Cell 28 line 1
----> 1 qa=RetrievalQA.from_chain_type(
      2     llm=llm, 
      3     chain_type="stuff", 
      4     retriever=docsearch.as_retriever(search_kwargs={'k': 2}),
      5     return_source_documents=True, 
      6     chain_type_kwargs=chain_type_kwargs)

File ~/anaconda3/envs/mchatbot/lib/python3.9/site-packages/langchain/chains/retrieval_qa/base.py:95, in BaseRetrievalQA.from_chain_type(cls, llm, chain_type, chain_type_kwargs, **kwargs)
     91 _chain_type_kwargs = chain_type_kwargs or {}
     92 combine_documents_chain = load_qa_chain(
     93     llm, chain_type=chain_type, **_chain_type_kwargs
     94 )
---> 95 return cls(combine_documents_chain=combine_documents_chain, **kwargs)

File ~/anaconda3/envs/mchatbot/lib/python3.9/site-packages/langchain/load/serializable.py:74, in Serializable.__init__(self, **kwargs)
     73 def __init__(self, **kwargs: Any) -> None:
---> 74     super().__init__(**kwargs)
     75     self._lc_kwargs = kwargs

File ~/anaconda3/envs/mchatbot/lib/python3.9/site-packages/pydantic/main.py:341, in pydantic.main.BaseModel.__init__()

ValidationError: 1 validation error for RetrievalQA
retriever
  Can't instantiate abstract class BaseRetriever with abstract methods _aget_relevant_documents, _get_relevant_documents (type=type_error)

我尝试创建自己的类检索器并检查 PineCone API 的文档,但是无法获得所需的输出链。我的 docsearch 实例基本上是一个 PineCone 对象,并且类型为:

<langchain_pinecone.vectorstores.PineconeVectorStore at 0x147954250>

这就是我创建文档搜索对象的方式:

from langchain_pinecone import PineconeVectorStore as PC

docsearch = PC.from_texts([t.page_content for t in text_chunks],
        embeddings,
        index_name = index_name)

请让我知道如何继续进行此操作。我的选择是要么使用 ChromaDB,要么使用 ChromaDB 作为最后的手段。但是,由于我有内存限制,我更愿意通过 PineConeDB 本身来解决这个问题。

python abstract-class langchain llama pinecone
1个回答
0
投票

chain_type_kwargs
如何定义?来自 API 文档 >

https://api.python.langchain.com/en/latest/chains/langchain.chains.retrieval_qa.base.BaseRetrievalQA.html#langchain.chains.retrieval_qa.base.BaseRetrievalQA

chain_type_kwargs (Optional[dict]) –

例如

qa_chain = RetrievalQA.from_chain_type(
        llm=llm,
        retriever=vectordb.as_retriever(),
        chain_type="stuff",
        chain_type_kwargs={"prompt": prompt},
        return_source_documents=True)
© www.soinside.com 2019 - 2024. All rights reserved.