以下是 ConversationalRetrievalQA 结构体定义和初始化方法:
// ConversationalRetrievalQA chain builds on RetrievalQA to provide a chat history component.
type ConversationalRetrievalQA struct {
// Retriever used to retrieve the relevant documents.
Retriever schema.Retriever
// Memory that remembers previous conversational back and forths directly.
Memory schema.Memory
// CombineDocumentsChain The chain used to combine any retrieved documents.
CombineDocumentsChain Chain
// CondenseQuestionChain The chain the documents and query is given to.
// The chain used to generate a new question for the sake of retrieval.
// This chain will take in the current question (with variable `question`)
// and any chat history (with variable `chat_history`) and will produce
// a new standalone question to be used later on.
CondenseQuestionChain Chain
// OutputKey The output key to return the final answer of this chain in.
OutputKey string
// RephraseQuestion Whether to pass the new generated question to the CombineDocumentsChain.
// If true, will pass the new generated question along.
// If false, will only use the new generated question for retrieval and pass the
// original question along to the CombineDocumentsChain.
RephraseQuestion bool
// ReturnGeneratedQuestion Return the generated question as part of the final result.
ReturnGeneratedQuestion bool
// InputKey The input key to get the query from, by default "query".
InputKey string
// ReturnSourceDocuments Return the retrieved source documents as part of the final result.
ReturnSourceDocuments bool
}
var _ Chain = ConversationalRetrievalQA{}
// NewConversationalRetrievalQA creates a new NewConversationalRetrievalQA.
func NewConversationalRetrievalQA(
combineDocumentsChain Chain,
condenseQuestionChain Chain,
retriever schema.Retriever,
memory schema.Memory,
) ConversationalRetrievalQA {
return ConversationalRetrievalQA{
Memory: memory,
Retriever: retriever,
CombineDocumentsChain: combineDocumentsChain,
CondenseQuestionChain: condenseQuestionChain,
InputKey: _conversationalRetrievalQADefaultInputKey,
OutputKey: _llmChainDefaultOutputKey,
RephraseQuestion: true,
ReturnGeneratedQuestion: false,
ReturnSourceDocuments: false,
}
}
ConversationalRetrievalQA 包括了几个不同的 LLMChain,他们的执行顺序是怎样的?