How do we build?
Rack applications using the new Long Chain Expression Language.
In this exercise, we are going to see a comparison between the old way of building rack applications
with long chain and the new way using the long chain expression language.
Remember that long chain recently launched this new way of, uh, building applications?
The long chain expression language that right now is as valid as the classic way.
So you can choose what is the way that works better for you.
Long chain is recommending the the second approach, the long chain, the new launching expression language,
because it says that it is more simple to use and it is easier to integrate with other applications,
like for example, Lamb-smith.
It is important for you to become familiar with this new approach, because it seems that a long chain
is going to, uh, focus on this new way of doing things in the future.
So it's important for us to be aware of it and to see how a, the, the, the methodology is evolving.
So in the first part of the code you have in the right side of the screen, we are creating a typical
very simple drag application.
So first we are connecting with the dot m file where we have the credentials in order to communicate
with the open AI API.
And then we build our drag application.
We instantiate the LM model.
We are loading our private file.
In this case it's a text file.
And we have this text file in a in a folder uh called data.
So we load this document.
We split this document in a small chunks with the text splitter.
Then we convert the chunks of text into numbers with open AI embeddings.
And once we have it, we load this embeddings into a face vector database.
So this store embeddings is the name of our vector database.
And now using the retrieval QA chain that lang chains provides, we can create a chain that will be
able to, uh, respond.
Questions about our private document, one, uh, little note, uh, pay attention to this last element
of the chain, the retriever element, because this is something we are going to see again in the new
way of doing things.
So here we see that the retriever element is the name of the database store embeddings.
Remember, store embeddings is the name of our vector database dot as retriever.
So we are telling the chain that we want to use this vector database as the retriever one.
Uh, small thing, a small detail.
Remember that in the classic way we use the dot run in order to execute our question in the in the chain.
So in the new way, with the Lang chain expression language, a couple of things change.
Remember that we are going to create the chain with a pipes a in this case, uh, in order for this
chain to be able to respond, questions about our, uh, our private document, take a look at the prompt
template.
So in our prompt template, what we are saying is answer the question based only on the following context.
So this context is going to be our private document.
We know our private document is stored in the vector database okay.
So context is going to store our vector database as retriever.
So you see here the context has the retriever.
What is the retriever.
The retriever is our vector database as retriever.
The second thing we see here in the prompt template is that the question is going to be a variable that
the user is going to input.
Okay.
So this question is the user the the the variable that a a the user is going to input.
Okay.
So here in the in the new way of uh defining the chain here you have this variable question.
And now we are passing the runnable pass through module okay.
This is what allows us to execute.
This chain now within vogue, not with run and to include here directly the content of the question
variable.
Okay, so this is the question we are going to make to this chain.
And this is the answer we get.
So as you can see more concise a but something you need to be used to this new way of working with a
long chain.
Remember that in the long chain documentation you can find more information, cases and details for
creating a drug application with a new long chain expression language.
And probably you will find many other approaches that are more, uh, are more suitable to your different
use cases.