Intro to 🦜🔗 LangChains

·

4 min read

Introduction...

So, you should’ve heard about LangChains, it’s a buzzword these days. But do you know what it is and how does it work? Well, if you don't know, no problem. In this blog, I’ll explain to you what are langchains and what are its different components which make it so powerful.

What are LLMs?

First of all, we’ll define LangChain. To understand LangChain, firstly you should know what large language models(LLMs) are. I’ll explain these in detail in some other blog but in simple terms, the models that use deep learning algorithms to process and understand natural language are known as large language models (LLMs). One of the most famous examples of LLM is GPT-3 (you have heard about this if you are active in this field).

So, this is a little bit about LLMs but what does this have to do with LangChain. Well, LangChain is an open-source framework that helps combine large language models like GPT-3 or models from hugging face with external sources of computation and data.

A Disadvantage(kinda) of LLM...

Let’s take ChatGPT for example (you’ve probably heard of this right? If not then please go on Google and search ChatGPT) which uses an LLM, if you ask some generic question to ChatGPT, it can answer it pretty well but what if you ask it some specific question it won’t be able to answer. So how about you can give a LLM your data and then ask it to answer questions based on that data or suppose you want to ask a LLM to perform some action? Well, for these things, langchains come in handy. You can give 4-5 documents as data and then ask questions based on that data.

LangChain provides access to external resources such as Wikipedia and Google APIs.

Main Components Of LangChain...

Now, what are the main components of langchains. Well, according to the official documentation of langchain (you can check it out here), there are 6 main components namely models, prompts, indexes, memory, chains, and agents. Below is a little explanation of all these components, but if you want to learn about them in detail you can check out the official documentation.

  1. Models - This component contains all the models that we can use in langchain. There are 3 types of models available. First, LLMs in which text input gives text output, the Second type is the chat model, which takes a list of chat messages and returns a chat messenger and the third one are text embeddings by which we can convert out text input into vectors.

  2. Prompts - Now we want some way to interact with our model right? This is where prompts come in. Prompts are like the inputs to our model. Langchain gives things such as Prompt templates, chat templates, etc. to interact with models.

  3. Indexes - Indexes help in structuring the document which we give as input. It has various sub-components such as a document loader, text splitter, vector store, and retrievers.

  4. Memory - By default, each input is treated independently but we can make our application remember previous conversations using the memory concept. This feature is particularly important in applications such as chatbots, where retaining memory of previous conversations is essential.

  5. Chains - Giving a simple input prompt is fine but sometimes we want to give our model a series of actions to perform. This is where the concept of chains comes in handy. Different actions can be chained together so that the output of the first will go as an input inside the next call. Some of the chains available in langchain are simple sequential chains, sequential chains, summarization chains, etc.

  6. Agents - The concept of agents is a bit tricky to explain so first we’ll see the official langchain definition of agents-

“Some applications will require not just a predetermined chain of calls to LLMs/other tools, but potentially an unknown chain that depends on the user’s input. In these types of chains, there is an “agent” which has access to a suite of tools. Depending on the user input, the agent can then decide which, if any, of these tools to call.”

So, agents have access to certain tools, and based on the user’s inputs agents decide which tools to call and in what order.

Resources...

First of all, Thank you so much for reading to the end and I hope you got a pretty good understanding of LangChain and its various components. If you want to learn more about it, below are some of the resources you can follow -

Final Notes...

I want to keep this blog short so I think this will be enough. I'm still learning about LangChains so hopefully I’ll share the whole process of how these work in the future but for now, we’ll be implementing this in the next blog. Stay tuned for that!

Â