0

When I am trying to build a RetrievalQA.from_chain_type with my local llm and PineCone VectorDataBase. However, it is not able to create a retriever owing to the error of not being able to instantiate abstract class of BaseRetriever.

The error is a Validation Error as shown below:

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)

I tried to create my own class retriever and check the documentation of the PineCone API, however was not able to get the output chain as desired. My docsearch instance is basically a PineCone object and is of the type :

<langchain_pinecone.vectorstores.PineconeVectorStore at 0x147954250>

This is how I created my docsearch object :

from langchain_pinecone import PineconeVectorStore as PC

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

Kindly let me know how to proceed ahead with this. My options are either this or using ChromaDB as a last resort. However, since I have memory constraints I would prefer to solve this via PineConeDB itself.

2
  • was it working properly when used with chroma DB? Commented Apr 16, 2024 at 3:28
  • @MubashirAhmedSiddiqui yes it was. I mean not this particular code, but I have used the RetrievalQA.from_chain_type with a ChromaDB vector space and it worked fine. Commented Apr 17, 2024 at 1:54

2 Answers 2

0

How is chain_type_kwargs defined? From API doc >

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]) –

For example

qa_chain = RetrievalQA.from_chain_type(
        llm=llm,
        retriever=vectordb.as_retriever(),
        chain_type="stuff",
        chain_type_kwargs={"prompt": prompt},
        return_source_documents=True)
Sign up to request clarification or add additional context in comments.

1 Comment

The chain_type_kwargs is defined as follows : Prompt = PromptTemplate(template=prompt_template,input_variables=["context", "question"]) chain_type_kwargs = {'prompt':Prompt} It is exactly the same as the example stated above.
0

Try upgrading Langchain and all other packages versions. Langchain version should be over 0.1.0 and after upgrading restart kerner and run again. This helped me, also make sure all the dependencies are compatible with each other.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.