1
00:00:03,740 --> 00:00:05,120
How do we build?

2
00:00:06,210 --> 00:00:11,490
Rack applications using the new Long Chain Expression Language.

3
00:00:11,880 --> 00:00:21,480
In this exercise, we are going to see a comparison between the old way of building rack applications

4
00:00:21,480 --> 00:00:26,070
with long chain and the new way using the long chain expression language.

5
00:00:26,100 --> 00:00:36,390
Remember that long chain recently launched this new way of, uh, building applications?

6
00:00:36,390 --> 00:00:44,040
The long chain expression language that right now is as valid as the classic way.

7
00:00:44,040 --> 00:00:48,750
So you can choose what is the way that works better for you.

8
00:00:49,020 --> 00:00:54,870
Long chain is recommending the the second approach, the long chain, the new launching expression language,

9
00:00:54,870 --> 00:01:03,270
because it says that it is more simple to use and it is easier to integrate with other applications,

10
00:01:03,270 --> 00:01:05,610
like for example, Lamb-smith.

11
00:01:05,610 --> 00:01:12,390
It is important for you to become familiar with this new approach, because it seems that a long chain

12
00:01:12,390 --> 00:01:18,210
is going to, uh, focus on this new way of doing things in the future.

13
00:01:18,210 --> 00:01:25,680
So it's important for us to be aware of it and to see how a, the, the, the methodology is evolving.

14
00:01:26,130 --> 00:01:34,830
So in the first part of the code you have in the right side of the screen, we are creating a typical

15
00:01:34,830 --> 00:01:36,750
very simple drag application.

16
00:01:36,750 --> 00:01:43,080
So first we are connecting with the dot m file where we have the credentials in order to communicate

17
00:01:43,080 --> 00:01:45,120
with the open AI API.

18
00:01:45,120 --> 00:01:47,970
And then we build our drag application.

19
00:01:47,970 --> 00:01:50,460
We instantiate the LM model.

20
00:01:50,460 --> 00:01:53,730
We are loading our private file.

21
00:01:53,730 --> 00:01:55,650
In this case it's a text file.

22
00:01:55,650 --> 00:02:01,230
And we have this text file in a in a folder uh called data.

23
00:02:01,350 --> 00:02:03,360
So we load this document.

24
00:02:03,360 --> 00:02:08,580
We split this document in a small chunks with the text splitter.

25
00:02:08,699 --> 00:02:16,170
Then we convert the chunks of text into numbers with open AI embeddings.

26
00:02:16,170 --> 00:02:23,400
And once we have it, we load this embeddings into a face vector database.

27
00:02:23,490 --> 00:02:29,010
So this store embeddings is the name of our vector database.

28
00:02:29,010 --> 00:02:38,010
And now using the retrieval QA chain that lang chains provides, we can create a chain that will be

29
00:02:38,010 --> 00:02:40,530
able to, uh, respond.

30
00:02:40,530 --> 00:02:49,020
Questions about our private document, one, uh, little note, uh, pay attention to this last element

31
00:02:49,020 --> 00:02:57,000
of the chain, the retriever element, because this is something we are going to see again in the new

32
00:02:57,000 --> 00:02:57,840
way of doing things.

33
00:02:57,840 --> 00:03:04,980
So here we see that the retriever element is the name of the database store embeddings.

34
00:03:04,980 --> 00:03:10,380
Remember, store embeddings is the name of our vector database dot as retriever.

35
00:03:10,860 --> 00:03:18,210
So we are telling the chain that we want to use this vector database as the retriever one.

36
00:03:18,210 --> 00:03:20,880
Uh, small thing, a small detail.

37
00:03:20,880 --> 00:03:29,400
Remember that in the classic way we use the dot run in order to execute our question in the in the chain.

38
00:03:29,520 --> 00:03:36,090
So in the new way, with the Lang chain expression language, a couple of things change.

39
00:03:36,480 --> 00:03:46,050
Remember that we are going to create the chain with a pipes a in this case, uh, in order for this

40
00:03:46,050 --> 00:03:53,880
chain to be able to respond, questions about our, uh, our private document, take a look at the prompt

41
00:03:53,880 --> 00:03:54,360
template.

42
00:03:54,360 --> 00:04:01,830
So in our prompt template, what we are saying is answer the question based only on the following context.

43
00:04:02,100 --> 00:04:06,180
So this context is going to be our private document.

44
00:04:06,180 --> 00:04:11,970
We know our private document is stored in the vector database okay.

45
00:04:11,970 --> 00:04:18,329
So context is going to store our vector database as retriever.

46
00:04:18,570 --> 00:04:22,680
So you see here the context has the retriever.

47
00:04:22,680 --> 00:04:23,850
What is the retriever.

48
00:04:23,850 --> 00:04:27,750
The retriever is our vector database as retriever.

49
00:04:28,530 --> 00:04:36,690
The second thing we see here in the prompt template is that the question is going to be a variable that

50
00:04:36,690 --> 00:04:38,610
the user is going to input.

51
00:04:38,610 --> 00:04:38,970
Okay.

52
00:04:38,970 --> 00:04:48,600
So this question is the user the the the variable that a a the user is going to input.

53
00:04:48,600 --> 00:04:49,110
Okay.

54
00:04:49,110 --> 00:04:56,280
So here in the in the new way of uh defining the chain here you have this variable question.

55
00:04:56,280 --> 00:05:02,160
And now we are passing the runnable pass through module okay.

56
00:05:02,160 --> 00:05:05,340
This is what allows us to execute.

57
00:05:05,580 --> 00:05:13,680
This chain now within vogue, not with run and to include here directly the content of the question

58
00:05:13,680 --> 00:05:14,370
variable.

59
00:05:14,370 --> 00:05:18,210
Okay, so this is the question we are going to make to this chain.

60
00:05:18,210 --> 00:05:20,310
And this is the answer we get.

61
00:05:20,640 --> 00:05:31,800
So as you can see more concise a but something you need to be used to this new way of working with a

62
00:05:31,800 --> 00:05:32,370
long chain.

63
00:05:32,370 --> 00:05:40,020
Remember that in the long chain documentation you can find more information, cases and details for

64
00:05:40,020 --> 00:05:45,240
creating a drug application with a new long chain expression language.

65
00:05:45,240 --> 00:05:54,270
And probably you will find many other approaches that are more, uh, are more suitable to your different

66
00:05:54,270 --> 00:05:55,440
use cases.

