I’m trying to build a document-based question-answering system using LangChain with a Pinecone vector store as the retriever and a local Llama model for the LLM. However, I’m encountering a ValidationError when trying to create the RetrievalQA chain. Here’s a simplified version of my code:
from langchain.chains import RetrievalQA
from langchain_community.vectorstores import Pinecone
from langchain_pinecone import PineconeVectorStore
from langchain.llms import CTransformers
pc = Pinecone(api_key=pinecone_api_key)
index_name = "medical-chatbot" # change if desired
index = pc.Index(index_name)
vector_store = PineconeVectorStore(index=index, embedding=embeddings)
docsearch = vector_store.from_texts([t.page_content for t in text_chunks], embeddings, index_name = index_name)
query = "What are the main parts of a human eye"
docs = vector_store.similarity_search(query, k=3)
# Assuming the setup code above like loading PDF, splitting text, etc. is correct
# Initialize Pinecone
vector_store = PineconeVectorStore(index=index, embedding=embeddings)
# LLM model setup
model = r"C:pathtoyourmodelllama-2-7b-chat.ggmlv3.q4_0.bin"
llm = CTransformers(model=model, model_type="llama", config={'max_new_tokens': 512, 'temperature': 0.8})
# Prompt template
prompt_template = """
Use the following pieces of information to answer the user's question.
If you don't know the answer, just say that you don't know, please don't try and make up answers.
Context: {context}
Question: {question}
Only return the helpful answer below and nothing else.
Helpful answer:
"""
PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
# Setup RetrievalQA: The main Error lies here!!
qa = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=docsearch.as_retriever(search_kwargs={"k": 2}),
return_source_documents=True,
chain_type_kwargs={"prompt": PROMPT}
)
while True:
user_input = input("Input Prompt:")
result = qa({"query": user_input})
print("Response: ", result["result"])
Error:
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)
Context:
- I’m using Pinecone as the vector store, with LangChain to handle the document search and retrieval process.
- The error seems to be related to the BaseRetriever class when instantiating the RetrievalQA chain.
How can I resolve this ValidationError and properly instantiate the RetrievalQA chain using Pinecone as the retriever? What might be causing this issue and how to debug it?
Nothing015 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.