Large Language Models (LLMs) are state-of-the-art today, and generally perform well for simple and low-interaction tasks, such as single-turn conversations, and command-and-response systems. However, their direct use is generally limited in the case of applications with complex and high-interaction tasks, such as multi-turn dialogue systems, and enterprise-grade chatbots. Most real-world applications are complex, and are characterized by the interaction (or integration) of multiple systems. This necessitates LLMs to be combined with information (computations) produced by multiple sources – but most LLMs are not natively built for this. This is where technologies like LangChain can play an important role.
LangChain is an open-source framework that enables LLMs to combine with other LLMs/models and artifacts for building complex conversational applications. It offers several modules – the main ones are mentioned below.
- LLM module, the most fundamental building block that can be used to generate predictions from language models.
- PromptTemplate module for prompt engineering
- Chain module that combines PromptTemplates and LLMs (or even other Chains) that can be executed in multi-step workflows
- Agent module to dynamically determine the actions that are needed, and in the required order
- Memory module that captures the memory from previous interactions by adding state to Chains and Agents
Some features, like the Memory module, have a lot of practical value. For instance, this module helps to address a problem often encountered in enterprise chatbots and dialogue systems – how to address longer conversations better. Moreover, this memory can be captured in multiple forms – ConversationBufferMemory, ConversationSummaryMemory, ConversationBufferWindowMemory, and ConversationSummaryBufferMemory – which helps to manage different memory requirement scenarios. This memory capture is a form of context management that LangChain achieves in three ways:
- Buffering, by using the last ‘n’ interactions as the contextual reference
- Summarization of the conversations (i.e., by compressing the contextual information from the verbatim dialogues)
- Hybrid of buffering and summarization – which often produces better results than the preceding two approaches
Another prominent feature of LangChain is Data Augmented Generation which enables specific/contextual data to be leveraged for generating text in addition to the generic data on which the LLMs were trained. It is particularly useful in building conversational systems that are domain-specific, or rely on specific data sources.
Google Search, Hugging Face, OpenAI, and other LLM ecosystems can be used with LangChain. The next steps for this technology are to mature the existing features, and add new ones, such as enabling Multi-task Learning, and supporting non-textual data.