Back to Index

When Should You Use LangChain?


Chapters

0:0 When to use LangChain
0:52 Do I need a framework?
4:3 LangChain for Learning
6:3 Moving on from LangChain
7:46 Should you use Langchain?

Transcript

Okay, so the first chapter of the course, we're going to focus on when should we actually use LangChain and when should we use something else. Now, through this chapter, we're not really going to focus too much on the code. Every other chapter is very code focused, but this one is a little more just theoretical.

What is LangChain? Where does it fit in? When should I use it? When should I not? So I want to just start by framing this. LangChain is one of, if not the most popular open source framework within the Python ecosystem, at least for AI. It works pretty well for a lot of things and also works terribly for a lot of things as well, to be completely honest.

There are massive pros, massive cons to using LangChain. Here, we're just going to discuss a few of those and see how LangChain maybe compares a little bit against other frameworks. So the very first question we should be asking ourselves is, do we even need a framework? Is a framework actually needed when we can just hit an API, you have the OpenAI API, other APIs, Mistral, so on, and we can get a response from an LLM in five lines of code on average for those.

It is incredibly, incredibly simple. However, that can change very quickly when we start talking about agents or retrieval augmented generation, research assistance, all this sort of stuff, those use cases, those methods can suddenly get quite complicated when we're outside of frameworks. And that's not necessarily a bad thing, right?

It can be incredibly useful to be able to just understand everything that is going on and build it yourself. But the problem is that to do that, you need time. Like you need to learn all the intricacies of building these things, the intricacies of these methods themselves, like what, you know, how do they even work?

And that kind of runs in the opposite direction of what we see with AI at the moment, which is AI is being integrated into the world at an incredibly fast rate. And because of this, most engineers coming into the space are not from a machine learning or AI background.

Most people don't necessarily have any experience with the system. A lot of engineers coming in that could be DevOps engineers, generic backend Python engineers, even frontend engineers coming in and building all these things, which is great, but they don't necessarily have the experience. And that, you know, that might be you as well.

And that's not a bad thing because the idea is that obviously you're going to learn and you're going to pick up a lot of these things. And in this scenario, there's quite a good argument for using a framework because a framework means that you can get started faster and a framework like LangChain, it abstracts away a lot of stuff.

And that's a big complaint that a lot of people will have with LangChain, but that abstracting away of many things is also what makes LangChain popular because it means that you can come in not really knowing, okay, what, you know, RAG is, for example, and you can implement a RAG pipeline, get the benefits of it without really needing to understand it.

And yes, there's an argument against that as well, just implementing something without really understanding it. But as we'll see throughout the course, it is possible to work with LangChain in a way, as we will in this course, where you can implement these things in an abstract way and then break them apart and start understanding the intricacies at least a little bit.

So that can actually be pretty good. However, again, circling back to what we said at the start, if the idea or your application is just a very simple, you know, you need to generate some text based on some basic input, maybe you should just use an API that's completely valid as well.

Now, we just said, okay, a lot of people coming to LangChain might not be from an AI background. So another question for a lot of these engineers might be, okay, if I want to learn about, you know, RAG, agents, all of these things, should I skip LangChain and just try and build it from scratch myself?

Well, LangChain can help a lot with that learning journey. So you can start very abstract. And as you gradually begin to understand the framework better, you can strip away more and more of those abstractions and get more into the details. And in my opinion, this gradual shift towards more explicit code with less abstraction is a really nice feature.

And it's also what we focus on, right? Throughout this course, that's what we're going to be doing. Going to sign abstract, stripping away the abstractions and getting more explicit with what we're building. So for example, building an agent in LangChain, there's in this very simple and incredibly abstract create tools agent method that we can use.

And like it creates a tool agent for you. It's, it doesn't tell you anything. So you can, you can use that, right? And we will use that initially in the course, but then you can actually go from that to defining your full agent execution logic, which is basically a tools call to open AI.

You're going to be getting that tool information back, but then you've got to figure out, okay, how am I going to execute that? How am I going to store this information? And then how am I going to iterate through this? So we're going to be seeing that stripping away abstractions as we work through, as we build agents, as we do, as we build like our streaming use case, among the many other things, even chat memory, we'll see there as well.

So LangChain can act as the on-ramp to your AI learning experience. Then what you might find, and I do think this is quite true for most people, is that if you, if you're really serious about AI engineering and that's what you want to do, like that's your focus, right?

Which isn't for everyone, for certain. A lot of people just want to understand a bit of AI and they want to continue doing what they're doing and just integrate AI here and there. And maybe those, you know, if that's your focus, you might stick with LangChain. You know, there's not necessarily a reason to move on.

But in the other scenario where you're thinking, okay, I want to get really good at this. I want to just learn as much as I can. And I'm going to dedicate basically my, you know, my short term future of my career on becoming AI engineer. Then LangChain might be the on-ramp.

It might be your initial learning curve, but then after you've become competent with LangChain, you might actually find that you want to move on to other frameworks. And that doesn't necessarily mean that you're going to have wasted your time with LangChain. Because one, LangChain is a thing helping you learn.

And two, one of the main frameworks that I recommend a lot of people to move on to is actually LangGraph, which is still within the LangChain ecosystem. And it still uses a lot of LangChain objects and methods, and of course, concepts as well. So even if you do move on from LangChain, you may move on to something like LangGraph, which you can't know LangChain for anyway.

And let's say you do move on to another framework instead. In that scenario, the concepts that you learn from LangChain are still pretty important. So to just finish up this chapter, I just want to summarize on that question of should you be using LangChain? What's important to remember is that LangChain does abstract a lot.

Now, this abstraction of LangChain is both a strength and a weakness. With more experience, those abstractions can feel like a limitation. And that is why we sort of go with the idea that LangChain is really good to get started with. But as the project grows in complexity or the engineers get more experience, they might move on something like LangGraph, which in any case, is going to be using LangChain to some degree.

So in either one of those scenarios, LangChain is going to be a core tool in an AI engineered toolkit. So it's worth learning in our opinion. But of course, it comes with its, you know, it comes with its weaknesses. And it's just good to be aware of that it's not a perfect framework.

But for the most part, you will learn a lot from it, and you will be able to build a lot with it. So with all of that, we'll move on to our first sort of hands-on chapter with LangChain, where we'll just introduce LangChain, some of the essential concepts. We're not going to dive too much into the syntax, but we'll see you understand a little bit of what we can do with it.

LangChain, some of the most important concepts. We're not going to dive too much into the