I'm not going to lie, at this point you have every reason to be impatient with me.
We've been yammering away for ages about raga, and you've not actually had a chance to use rag yet.
We've just talked about vectors.
We've talked about prompts and context and cheap versions of Rag.
Finally, it's time for the real deal.
Today, it's time that we put a rag pipeline into action.
And it's going to be stupid.
Easy.
Just you wait.
So what's going to happen today?
We're going to create a conversation chain in long chain, which is where long chain comes together
to put the different pieces glued together to give you a conversation with retrieval with Rag.
We're going to ask questions and get answers that demonstrate an expert understanding and will build
ultimately a knowledge worker assistant with a chat UI.
And because of all the wonderful things that you've already learned, you're going to see that it's
going to be incredibly easy, of course.
So first of all, just to give you a briefing, there are some abstractions in long chain, some some
concepts that long chain has defined that make things easier.
And here are the three of them that we will be using today.
First of all, there's an abstraction around an LLM.
An LLM is just represents, in our case, OpenAI.
But it could represent others.
And Liangcheng gives you that one object that represents your abstraction around a model.
Then there is an abstraction called a retriever.
And that is a sort of interface onto something like a vector store.
In our case, it will be Cromer, which will be used for Rag retrieval.
So that is a retriever interface around something that can take vectors and can enrich your prompt.
And then the third abstraction is memory.
And that represents some kind of a of a history of a discussion with a chatbot in some way, some memory.
So this in practice, what we're used to here is that list of dicts, that list that comprises of a
sort of a system message at the top, and then user assistant, user assistant.
But that has been abstracted away into a concept called memory for long chain, which behind under the
covers it will handle that list or whatever other kind of format different models might need.
So these are the three key, uh, wrappers around more functionality that you get from long Chain.
And with that in mind, take a look at how simple it's going to be to put together a rag pipeline.
It's going to be done with four lines of code.
And here are the four lines of code in front of you right now.
And this is the brilliance that is in the first line.
LM is chat open AI that is creating a lang chain ln object.
LM object for open AI.
And you can imagine there's similar objects that you could create for anything else.
That's the first line, the first abstraction.
LM the second line.
The second abstraction.
Memory.
You create a lang chain object called a conversation buffered memory.
You have to provide this a couple of things.
The key is just the the how it will organize, what it will, what you can use to look up that memory
and chat history is what it has to be, because that's what's going to be expected later and return
messages is telling Lang that you're going to want this to be stored in a way that what comes back are
going to be a series of messages, not just a big block of text representing the conversation.
So you just need to know that these are what you have to use for this kind of chat application.
The next line is quite simply saying we have a vector store that we've created its chroma, and we're
going to call this this this method as retriever.
And it's going to wrap that in an interface object called a retriever.
And that is the the kind of, uh, object that Lang chain is expecting in order to be able to, to have
a Rag workflow.
So those are our three abstractions the LM, the memory and the retriever.
They've all been created.
And now that last line puts it together into something called a conversation chain.
Uh, and that is something which is a conversation retrieval chain that you create, uh, and you call,
you create it by calling that, that, um, uh, method from LM, and you just pass in three things
the LM, the retriever and the memory, the three things we just created.
And so it's as simple as that.
With that fourth line of code, we have just created a Rag pipeline.
You don't believe me?
Let's go over to JupyterLab and give it a try ourselves.