Chain Component
Learn how to use a simple LLM chain and combine multiple chains in your applications.
Types of chains
Chains help in abstracting multistep actions in a simple way. There are many types of chains supported by langchaingo. Here are some of the commonly used chains:
LLM chain: This is the simplest form of a chain that combines a prompt template and an LLM.
ConversationalRetrievalChain: This chain can be used to have a conversational interaction using a document as context or source of information. It takes in a question, fetches the required documents and passes them (along with the conversation) to an LLM for a response.
StuffDocumentsChain: This chain accepts a list of documents, formats them all into a prompt, and then passes it to an LLM. One has to make sure that the final size of the prompt and the document fit within the LLM context window.
MapReduceDocumentsChain: This can be used when the use case requires a lot of documents that need to be processed by LLM in parallel. It groups documents into chunks (less than the LLM context length) and then passes them into the LLM. It accepts the responses and repeats until it can fit the entire context into the final LLM call.
RefineDocumentsChain: This chain works by by generating an initial answer based on the first document and then looping over the remaining documents to refine its answer. Its operations cannot be parallelized since it generates an answer by refining the previous answer.
MapRerankDocumentsChain: This invokes the LLM with each document requesting for confidence score (along with the ...