UserWarning: `ChatVectorDBChain` is deprecated

#2
by gimborgo - opened

Hi there,
thank you for this example. Using the cli_app.py file I'm getting the error UserWarning: ChatVectorDBChain is deprecated.

As described in this blog post (https://blog.langchain.dev/retrieval/) the ChatVectorDBChain is now ConversationalRetrievalChain so I understand the warning and I swapped it in query_data.py. But now I get the following error:

pydantic.error_wrappers.ValidationError: 2 validation errors for ConversationalRetrievalChain
retriever
  instance of BaseRetriever expected (type=type_error.arbitrary_type; expected_arbitrary_type=BaseRetriever)
qa_prompt
  extra fields not permitted (type=value_error.extra)

And I cannot investigate further, any hint to go beyond?

Thank you.

Version: langchain-0.0.154
OpenAI key provided.

I've been able to overcome the problem replacing pickle with FAISS in cli_app.py and rephrasing the files like this.

I still don't know how to pass the qa_prompt correctly.

Obviously the State of the Union file must be ingested in a FAISS vector.

# cli_app.py

from langchain.vectorstores import FAISS
from query_data import get_chain
from langchain.embeddings.openai import OpenAIEmbeddings

faiss_directory = './db_faiss' # this is the vector db

if __name__ == "__main__":
    vectorstore = FAISS.load_local(faiss_directory, OpenAIEmbeddings())
    qa_chain = get_chain(vectorstore)
    chat_history = []
    print("Chat with your docs!")
    while True:
        print("Human:")
        question = input()
        result = qa_chain({"question": question, "chat_history": chat_history})
        chat_history.append((question, result["answer"]))
        print("AI:")
        print(result["answer"])
# query_data.py
from langchain.prompts.prompt import PromptTemplate
from langchain.llms import OpenAI
from langchain.chains import ConversationalRetrievalChain

_template = """Given the following conversation and a follow up question, rephrase the follow up question to be a standalone question.
You can assume the question about the most recent state of the union address.

Chat History:
{chat_history}
Follow Up Input: {question}
Standalone question:"""
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_template)

# template = """You are an AI assistant for answering questions about the most recent state of the union address.
# 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 the most recent state of the union, politely inform them that you are tuned to only answer questions about the most recent state of the union.
# Question: {question}
# =========
# {context}
# =========
# Answer in Markdown:"""
# QA_PROMPT = PromptTemplate(template=template, input_variables=["question", "context"])


def get_chain(vectorstore):
    llm = OpenAI(temperature=0)
    # qa_chain = ChatVectorDBChain.from_llm(
    qa_chain = ConversationalRetrievalChain.from_llm(
        llm,
        retriever=vectorstore.as_retriever(),   # See https://blog.langchain.dev/retrieval/
        # qa_prompt=QA_PROMPT,
        condense_question_prompt=CONDENSE_QUESTION_PROMPT,
        verbose=True,
    )
    return qa_chain

I followed suggestion above but now get the error "AttributeError: 'OpenAIEmbeddings' object has no attribute 'deployment".
Any insight out there?

Sign up or log in to comment