Validation error for ConversationalRetrievalChain retriever

i am trying to execute the code mentioned in lesson 7 of this course build-your-own-rag-bot.
i get stuck with following code

qa_chain = ConversationalRetrievalChain(
i get the following error
“Can’t instantiate abstract class BaseRetriever with abstract methods _aget_relevant_documents, _get_relevant_documents (type=type_error)”

i am using AzureChatOpenAI and AzureOpenAIEmbeddings LLMS, but reusing the same code given in lesson 7.

any reference to code where this is solved ?


I suspect you’re using some incompatible versions of some of the tools or packages.

Kindly share a screenshot of the error you are encountering

here is the code snippet and error information that i get

import openai
import chromadb
from unstructured_client import UnstructuredClient
from unstructured_client.models import shared
from unstructured.chunking.title import chunk_by_title
from import partition_md
#from unstructured.partition.pptx import partition_pptx
from unstructured.staging.base import dict_to_elements
from langchain_community.vectorstores import Chroma
from langchain_core.documents import Document

from langchain_openai import AzureOpenAIEmbeddings
from langchain.chat_models import AzureChatOpenAI
from openai import AzureOpenAI
from langchain.prompts.prompt import PromptTemplate
from langchain.chains import ConversationalRetrievalChain, LLMChain
from langchain.chains.qa_with_sources import load_qa_with_sources_chain

llm = AzureChatOpenAI(deployment_name=“XXXX”,
temperature=0, openai_api_version=“2024-02-15-preview”,
openai_api_key =“XXXX”,
openai_api_base = “XXXX”)

embeddings = AzureOpenAIEmbeddings(openai_api_key =“XXX”,
azure_endpoint = “XXX”,azure_deployment=“ada-002”)

template = “”"You are an AI assistant for answering questions about the Donut document understanding model.
You are given the following extracted parts of a long document and a question. Provide a conversational answer.
If you don’t know the answer, just say “Hmm, I’m not sure.” Don’t try to make up an answer.
If the question is not about Donut, politely inform them that you are tuned to only answer questions about Donut.
Question: {question}


Answer in Markdown:“”"

prompt = PromptTemplate(template=template, input_variables=[“question”, “context”])

vectorstore = Chroma.from_documents(documents, embeddings)

retriever = vectorstore.as_retriever(
search_kwargs={“k”: 6}

doc_chain = load_qa_with_sources_chain(llm, chain_type=“map_reduce”)
question_generator_chain = LLMChain(llm=llm, prompt=prompt)

qa_chain = ConversationalRetrievalChain(


ValidationError Traceback (most recent call last)
Input In [22], in <cell line: 1>()
----> 1 qa_chain = ConversationalRetrievalChain(
2 retriever=retriever,
3 question_generator=question_generator_chain,
4 combine_docs_chain=doc_chain,
5 )

File ~\AppData\Roaming\Python\Python39\site-packages\langchain\load\, in Serializable.init(self, **kwargs)
73 def init(self, **kwargs: Any) → None:
—> 74 super().init(**kwargs)
75 self._lc_kwargs = kwargs

File ~\AppData\Roaming\Python\Python39\site-packages\pydantic\, in pydantic.main.BaseModel.init()

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

Hello @grandhes

Although you are using the openai azure, to run or practice this model on your local environment, you would require all the necessary (metadata) files such as

Which I suppose you don’t have utils files access? Or there might be a mismatch in the way you have recalled and how the course programmer must have recalled.

One such issue also was due to the version mismatch of pydantic.

Kindly let us know do have access to the basemodel file?


Thanks a lot for your suggestion, yes it was issue with Pydantic version. after i upgraded the version, it worked well.


1 Like