在 LangChain 中 ,ConversationalRetrievalQA 包括几个 LLMChain,他们的调用顺序是怎样的?

以下是 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,他们的执行顺序是怎样的?

在LangChain的ConversationalRetrievalQA中,包含了一个或多个LLMChain。这些LLMChain被按照指定的顺序进行调用。一般来说,调用的顺序是按照它们在ConversationalRetrievalQA代码中的顺序进行的。例如,如果ConversationalRetrievalQA有两个LLMChain,那么第一个LLMChain会在第二个LLMChain之前进行调用。调用的顺序可以根据需要进行更改,以满足特定的需求。