In the documentation, I ve seen two patterns of construction and I m a bit confused about the difference between both. I don t know if there s any actual difference or if just the same thing in different approach.
Example 1 (using .from_llm):
model = ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.3)
embeddings = OpenAIEmbeddings()
vectordb = Chroma(embedding_function=embeddings, persist_directory=directory)
memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
qa = ConversationalRetrievalChain.from_llm(
model,
vectordb.as_retriever(),
condense_question_prompt=CUSTOM_QUESTION_PROMPT,
memory=memory
)
query = "What did the president say about Ketanji Brown Jackson"
result = qa({"question": query})
Example 2 (no method, with LLMChain):
llm = OpenAI(temperature=0)
question_generator = LLMChain(llm=llm, prompt=CONDENSE_QUESTION_PROMPT)
doc_chain = load_qa_with_sources_chain(llm, chain_type="map_reduce")
chain = ConversationalRetrievalChain(
retriever=vectorstore.as_retriever(),
question_generator=question_generator,
combine_docs_chain=doc_chain,
)
chat_history = []
query = "What did the president say about Ketanji Brown Jackson"
result = chain({"question": query, "chat_history": chat_history})
I can see that in the second example I m defining the model and prompt separately as a question_generator that I pass as an argument in the chain aftwerwards. Thus, I m passing a doc_chain.
But I ve some abstract doubts, such as what s underneath, what are the consequences, when should I use one or another, if it s the same output etc. Mostly, is the first simple example somehow using a question_generator or a doc_chain which are omitted in the code?