And welcome to continuing our journey with Hrag.
And today it's time to unveil Liang Chen.
So first, a quick reminder of what you can already do when it comes to Hrag.
So we last time talked about the simple idea behind Hrag.
Just the idea that you could retrieve relevant contexts and include that in the prompt.
And then we talked a bit about vectors and how text can be mapped to a vector that represents its meaning.
And you can use these vectors to try to be more intelligent about how you select relevant context for
the prompt.
So today we're going to talk about Lang chain.
I'm going to describe the framework and its pros and cons.
We're going to use Lang chain to read in our knowledge base and to divide it into chunks of relevant
information, which later will be putting in a vector database and retrieving.
So here is the backstory to Lang Chain.
It's a relatively recent framework.
It was created in late 2022, and its main goal is to allow allow people to build LLM applications quickly,
stitching together different bits of functionality into a sort of chain of processing.
It actually has its own language, its own declarative language called Lang Chain Expression Language.
LCL and we're not going to be using that.
Particularly I am going to show you some of it, but there are simpler ways to use lang chain just by
using Python code.
So what are the pros and cons?
So it does hugely simplify creating applications to do common things like assistance and Rag.
As we will see, it's going to literally be a few lines of code.
So it gives you very quick time to market.
There's nothing particularly magical about something like rag.
We could do it the brute force way, by looking up in a vector database by adding to the prompt.
Lang chain just standardizes and simplifies and makes it all easier and quicker.
It's also a useful wrapper code around common models, so that you can write your code once and then
switch in different models like OpenAI or Claude, and not have to deal with the slight differences
in the API, which you can imagine is just sort of convenient.
You can imagine that we could do that ourselves.
We could write a little wrapper function, much as we did when we were using Gradio to call two different
llms.
And that's essentially what Lang Chain has done.
They've built wrappers around the common APIs.
It has to be said, as the APIs for LMS has matured, as they've become increasingly similar, and as
the sort of code scripts out there for doing this become more and more widespread, there is less of
a need for an underlying framework like Lang Chain than there was perhaps a year ago.
So the need is decreased a bit.
There's a lot of people that are rolling their own in terms of building their own pipelines for things
like Rag, and you'll see how easy it would be to do that too.
But Lang Chain still gives you a tremendous head start.
And so it's very useful framework as you will see today.
So what we're going to do is we're going to use Lang chain to load in our knowledge base.
We're first going to read all of the documents stored in the folders using some some tooling.
We're then going to add metadata to the documents to say what kind of document it is, which is going
to be useful for us later.
And then we're going to use Lang chain to break the documents down into useful chunks, chunks which
represent text that belongs nicely together and will be ready to be vectorized and put in our database.
So with that, let's head back to JupyterLab.