1
00:00:00,000 --> 00:00:03,000
So guys, now let's continue the discussion with respect to this particular project.

2
00:00:03,000 --> 00:00:05,000
Now what we are going to implement over here.

3
00:00:05,000 --> 00:00:09,000
So here you will be able to see that I have a research paper folder okay.

4
00:00:09,000 --> 00:00:12,000
And inside this folder I have this two amazing research paper.

5
00:00:12,000 --> 00:00:16,000
That is attention is all you need and overview of large language models.

6
00:00:16,000 --> 00:00:20,000
So I have kept all both these PDFs inside this folder.

7
00:00:21,000 --> 00:00:24,000
And we will consider this as an external data source.

8
00:00:24,000 --> 00:00:26,000
And we will try to ask any question.

9
00:00:26,000 --> 00:00:30,000
And probably we should be able to get the response from this particular research paper through this

10
00:00:30,000 --> 00:00:31,000
document.

11
00:00:31,000 --> 00:00:32,000
Q&A okay.

12
00:00:32,000 --> 00:00:38,000
So how we will be executing this again over here we are going to be specifically use this chat grok

13
00:00:38,000 --> 00:00:38,000
okay.

14
00:00:38,000 --> 00:00:45,000
And uh, along with this you'll also be seeing that, uh, we will go ahead and uh, you know, uh,

15
00:00:45,000 --> 00:00:49,000
implement open source LM model instead of just using open AI.

16
00:00:49,000 --> 00:00:49,000
Okay.

17
00:00:50,000 --> 00:00:53,000
Uh, so that you will also everybody will be able to execute this, Okay.

18
00:00:53,000 --> 00:00:56,000
So quickly, let's go ahead and do this now.

19
00:00:56,000 --> 00:01:04,000
First thing first I will go ahead and write from dot env import load underscore dot env okay.

20
00:01:04,000 --> 00:01:12,000
And then uh we will now just go ahead and execute this load underscore dot env.

21
00:01:12,000 --> 00:01:16,000
Now this is specifically used to load all the environment variables.

22
00:01:16,000 --> 00:01:21,000
Right now I'm going to load the grok grok API.

23
00:01:22,000 --> 00:01:24,000
And this will be very much important.

24
00:01:24,000 --> 00:01:28,000
And for some number of hits grok completely provides you free API itself.

25
00:01:28,000 --> 00:01:32,000
So anybody can probably go ahead and create your account okay.

26
00:01:32,000 --> 00:01:34,000
You have to go ahead and create your account.

27
00:01:34,000 --> 00:01:37,000
And based on that you can actually go ahead and create your keys.

28
00:01:37,000 --> 00:01:43,000
Now here I will go ahead and write OS dot environment dot environ.

29
00:01:43,000 --> 00:01:46,000
And here I'm going to use my grok API key.

30
00:01:46,000 --> 00:01:50,000
So I'll go ahead and copy this I'll go ahead and paste it over here.

31
00:01:50,000 --> 00:01:51,000
Okay.

32
00:01:51,000 --> 00:01:56,000
Along with this what I will specifically do is that I will just go ahead and write is equal to OS dot

33
00:01:56,000 --> 00:01:57,000
get env.

34
00:01:57,000 --> 00:01:57,000
Okay.

35
00:01:58,000 --> 00:02:07,000
Once I do this I will quickly go ahead and write my open uh sorry grok grok API key itself.

36
00:02:07,000 --> 00:02:12,000
Okay, so once I get this grok API key then I will be able to interact with any model that I want okay.

37
00:02:12,000 --> 00:02:18,000
Now uh, once we are setting this up, I can also make sure that I can get the direct key from here.

38
00:02:18,000 --> 00:02:19,000
Okay.

39
00:02:19,000 --> 00:02:22,000
Um, so let's go to the next step.

40
00:02:22,000 --> 00:02:24,000
And here, uh, let me just go ahead and write.

41
00:02:24,000 --> 00:02:28,000
This is my grok API underscore key, which is nothing.

42
00:02:28,000 --> 00:02:34,000
But if I just go ahead and write os dot get env, it is just going to get it from the environment variable.

43
00:02:34,000 --> 00:02:34,000
Okay.

44
00:02:34,000 --> 00:02:36,000
So this way also you can actually get your API key.

45
00:02:36,000 --> 00:02:40,000
Now is the most important step is creating your LM model.

46
00:02:40,000 --> 00:02:42,000
For this we will be using this Chad Grok.

47
00:02:42,000 --> 00:02:50,000
And here we have to first of all provide our grok API key which will be equal to nothing, but it will

48
00:02:50,000 --> 00:02:52,000
be equal to this grok API key.

49
00:02:52,000 --> 00:02:52,000
Right.

50
00:02:52,000 --> 00:02:55,000
So this is the first parameter that is required over here.

51
00:02:55,000 --> 00:02:57,000
And the second parameter is nothing but my model name.

52
00:02:58,000 --> 00:03:03,000
So in order to provide the model name I will go back to my website of grok.

53
00:03:03,000 --> 00:03:07,000
And here you'll be able to see if I go to the first home page.

54
00:03:07,000 --> 00:03:11,000
Here are different different models that you can specifically use right.

55
00:03:11,000 --> 00:03:15,000
So you can provide this llama three 8,000,000,008 192.

56
00:03:15,000 --> 00:03:18,000
You can provide llama three 7,000,000,008 192 gamma seven.

57
00:03:18,000 --> 00:03:19,000
Be it.

58
00:03:19,000 --> 00:03:23,000
So let's go ahead and select this I will go ahead and write like this on itself.

59
00:03:23,000 --> 00:03:27,000
Gamma dash seven B dash it okay.

60
00:03:27,000 --> 00:03:29,000
So I will just go ahead and write in the same way.

61
00:03:29,000 --> 00:03:33,000
So here you have this gamma.

62
00:03:35,000 --> 00:03:38,000
7BIT okay.

63
00:03:38,000 --> 00:03:41,000
So we are basically going to use this LLM model like this.

64
00:03:41,000 --> 00:03:44,000
You can also go ahead and specify your llama three model if you want.

65
00:03:44,000 --> 00:03:47,000
So let's say I want to go ahead and use llama three model.

66
00:03:47,000 --> 00:03:48,000
I can go ahead and specify like this.

67
00:03:48,000 --> 00:03:52,000
So let's continue with llama three so that uh it's okay.

68
00:03:52,000 --> 00:03:53,000
You can use any of the open source models.

69
00:03:53,000 --> 00:03:54,000
It is up to you.

70
00:03:54,000 --> 00:03:58,000
Now I'll go ahead and define my chat prompt template.

71
00:03:58,000 --> 00:03:58,000
Okay.

72
00:03:58,000 --> 00:04:03,000
Now inside this chat prompt template I'm just going to use dot from underscore template.

73
00:04:04,000 --> 00:04:06,000
Now is the most important thing.

74
00:04:06,000 --> 00:04:09,000
Like see the previous ways how we used to create chat prompt template.

75
00:04:09,000 --> 00:04:14,000
Now this will be a little bit different because here we need to provide some context information also.

76
00:04:14,000 --> 00:04:19,000
So here I'm just going to say hey um I'll go ahead and write it over here.

77
00:04:19,000 --> 00:04:32,000
I'll say, hey, answer the questions based on the provided context only Okay.

78
00:04:32,000 --> 00:04:35,000
And then I will say next sentence.

79
00:04:35,000 --> 00:04:43,000
Please provide the most accurate response.

80
00:04:43,000 --> 00:04:48,000
Response based on the question.

81
00:04:48,000 --> 00:04:48,000
Right.

82
00:04:48,000 --> 00:04:52,000
And here I will just go ahead and define my context.

83
00:04:52,000 --> 00:04:54,000
This will basically be my context.

84
00:04:54,000 --> 00:04:55,000
Here I will give a placeholder.

85
00:04:55,000 --> 00:04:58,000
Now now why I am just using this keyword.

86
00:04:58,000 --> 00:05:02,000
We will try to understand okay, because this is important.

87
00:05:02,000 --> 00:05:07,000
The libraries that we have used this create stuff document chain and create retrieval chain.

88
00:05:07,000 --> 00:05:12,000
This has a separate meaning for this kind of context message that is seen in the prompt template.

89
00:05:12,000 --> 00:05:14,000
Okay we'll discuss more about it.

90
00:05:14,000 --> 00:05:17,000
And then here I will just go ahead and write my question.

91
00:05:17,000 --> 00:05:20,000
This question will basically have my input.

92
00:05:20,000 --> 00:05:21,000
Okay.

93
00:05:22,000 --> 00:05:24,000
Now here is my prompt.

94
00:05:24,000 --> 00:05:27,000
So here in this prompt it is just like a document Q&A.

95
00:05:27,000 --> 00:05:30,000
In case of document Q&A I need to provide a context over here.

96
00:05:30,000 --> 00:05:33,000
What this context will be replaced with.

97
00:05:33,000 --> 00:05:35,000
I will just discuss about it once we proceed.

98
00:05:35,000 --> 00:05:36,000
Okay.

99
00:05:36,000 --> 00:05:39,000
So this is my prompt, a simple prompt that I have actually written.

100
00:05:40,000 --> 00:05:45,000
Now the first thing, as you know, I have to create my vectors, right?

101
00:05:45,000 --> 00:05:47,000
Create my vectors.

102
00:05:47,000 --> 00:05:49,000
And this time I'll be creating my vectors.

103
00:05:49,000 --> 00:05:51,000
I'll say vector embeddings.

104
00:05:51,000 --> 00:05:52,000
Okay.

105
00:05:52,000 --> 00:05:59,000
Now inside this function, my main aim will be that I should be able to read all the documents from

106
00:05:59,000 --> 00:05:59,000
here.

107
00:05:59,000 --> 00:06:04,000
After reading the documents, I should be able to read the content inside this.

108
00:06:04,000 --> 00:06:10,000
I mean, read this research paper, read the content inside this and after reading it make sure apply

109
00:06:10,000 --> 00:06:14,000
recursive character text splitter along with that, split all this particular documents and just by

110
00:06:14,000 --> 00:06:22,000
using files, we can proceed further and we can go ahead and probably store them in some kind of vector

111
00:06:22,000 --> 00:06:22,000
database.

112
00:06:22,000 --> 00:06:23,000
Okay.

113
00:06:23,000 --> 00:06:29,000
So here what I will do, I will quickly go ahead and use uh, define this function which is called as

114
00:06:29,000 --> 00:06:30,000
create vector embedding.

115
00:06:30,000 --> 00:06:35,000
But here since my vector store will be used in some other, uh, code.

116
00:06:35,000 --> 00:06:39,000
Also, what I will do is that I will try to use session state over here.

117
00:06:39,000 --> 00:06:45,000
Session states actually helps you to remember uh, your vector store DB specifically this is for vector

118
00:06:45,000 --> 00:06:45,000
store DB.

119
00:06:45,000 --> 00:06:48,000
That is the reason I'm trying to create some session state.

120
00:06:48,000 --> 00:06:52,000
This session state variables will be able to access in other functions also whenever it is required.

121
00:06:52,000 --> 00:06:58,000
Okay, this is just to make sure that your entire application has some kind of memory with respect to

122
00:06:58,000 --> 00:06:59,000
this particular chatbot.

123
00:06:59,000 --> 00:07:09,000
Okay, so here I will say if my vector's not in s t dot session state, I'm just going to try to create

124
00:07:09,000 --> 00:07:14,000
a vectors variable, which will be my session state variable.

125
00:07:14,000 --> 00:07:17,000
So I'll say TX dot session underscore state.

126
00:07:18,000 --> 00:07:19,000
Okay.

127
00:07:19,000 --> 00:07:27,000
Then I will just go ahead and write it over here, and I will just go ahead and say TT dot session underscore

128
00:07:27,000 --> 00:07:28,000
state.

129
00:07:28,000 --> 00:07:31,000
First of all, I will go ahead and create my embeddings.

130
00:07:31,000 --> 00:07:36,000
Now in this case my embeddings that I'm actually going to use is nothing but my embeddings.

131
00:07:36,000 --> 00:07:36,000
Okay.

132
00:07:36,000 --> 00:07:42,000
Now whatever embedding I'm basically using, I will also keep this in the session state variable right.

133
00:07:42,000 --> 00:07:45,000
Specifically in this particular session state.

134
00:07:45,000 --> 00:07:49,000
Then we will quickly go ahead and write SD dot session state.

135
00:07:49,000 --> 00:07:52,000
Another session state we will go ahead and create.

136
00:07:53,000 --> 00:07:56,000
And inside this I will go ahead and write a loader.

137
00:07:56,000 --> 00:07:57,000
Right.

138
00:07:57,000 --> 00:08:00,000
This loader will be my data ingestion step right now.

139
00:08:00,000 --> 00:08:06,000
In this case I'm going to use this pi pdf directory loader okay pi pdf directory loader.

140
00:08:06,000 --> 00:08:11,000
And inside this I'm going to give my folder name.

141
00:08:11,000 --> 00:08:12,000
What is the folder name that you have?

142
00:08:12,000 --> 00:08:16,000
It is nothing but research underscore paper right.

143
00:08:16,000 --> 00:08:20,000
So this is the folder name that we will be giving over here okay.

144
00:08:20,000 --> 00:08:21,000
So let's go ahead and give this.

145
00:08:21,000 --> 00:08:26,000
So here you can see this is my research research papers papers I should right okay.

146
00:08:27,000 --> 00:08:32,000
Now this is nothing but this is my data ingestion step.

147
00:08:33,000 --> 00:08:33,000
Perfect.

148
00:08:33,000 --> 00:08:36,000
We are loading something, loading some information.

149
00:08:36,000 --> 00:08:37,000
This can also come from Streamlit directly.

150
00:08:37,000 --> 00:08:39,000
It is up to you right?

151
00:08:39,000 --> 00:08:39,000
How?

152
00:08:39,000 --> 00:08:41,000
You basically want to go ahead and upload this.

153
00:08:42,000 --> 00:08:42,000
Now.

154
00:08:42,000 --> 00:08:49,000
After this I will just go ahead and say st dot session, underscore state dot documents.

155
00:08:49,000 --> 00:08:53,000
And uh from this loader I'm going to load all the documents.

156
00:08:53,000 --> 00:09:00,000
So for that again I have to call this st dot session state dot loader dot load.

157
00:09:01,000 --> 00:09:03,000
I will load all the documents over here.

158
00:09:03,000 --> 00:09:09,000
And uh this will basically be my complete document loading.

159
00:09:09,000 --> 00:09:12,000
I'll just write this comment so that you'll be able to understand it okay.

160
00:09:12,000 --> 00:09:18,000
Then uh, what we are going to do is that I'll go ahead and write s t dot session underscore state dot

161
00:09:18,000 --> 00:09:19,000
text splitter.

162
00:09:19,000 --> 00:09:21,000
I have to use some kind of text splitter over here.

163
00:09:21,000 --> 00:09:27,000
And this text splitter will be nothing, but it will be assigned to a recursive character text splitter,

164
00:09:27,000 --> 00:09:29,000
which we have already discussed.

165
00:09:29,000 --> 00:09:33,000
Inside this there will be a chunk size of 1000, let's say.

166
00:09:34,000 --> 00:09:36,000
And then I'm going to use a chunk.

167
00:09:39,000 --> 00:09:42,000
Overlap of 200 okay.

168
00:09:43,000 --> 00:09:47,000
I'm just going to use this chunk uh, with respect to this okay.

169
00:09:47,000 --> 00:09:47,000
Okay.

170
00:09:47,000 --> 00:09:48,000
Perfect.

171
00:09:48,000 --> 00:09:51,000
Uh, so this is my recursive character text splitter, which I'm actually doing it.

172
00:09:51,000 --> 00:09:59,000
And then finally it is just dot session underscore state dot final underscore documents.

173
00:09:59,000 --> 00:10:04,000
This will be my final documents because I have to apply this text splitting technique again I will go

174
00:10:04,000 --> 00:10:06,000
ahead and save everything in the session.

175
00:10:06,000 --> 00:10:10,000
That is what I'm actually doing, so that my entire application has some kind of memory whenever it

176
00:10:10,000 --> 00:10:12,000
has to refer to.

177
00:10:12,000 --> 00:10:17,000
Okay, now I will be using this session state dot text splitter.

178
00:10:19,000 --> 00:10:21,000
And I will use this split text splitter.

179
00:10:21,000 --> 00:10:23,000
Dot split documents.

180
00:10:23,000 --> 00:10:27,000
It is called as split documents.

181
00:10:27,000 --> 00:10:31,000
This way we are actually splitting all our documents right.

182
00:10:31,000 --> 00:10:35,000
So for this I will again where my documents is basically present.

183
00:10:35,000 --> 00:10:36,000
It is present over here.

184
00:10:36,000 --> 00:10:37,000
Okay.

185
00:10:37,000 --> 00:10:43,000
Just to make sure that this will not take much time, I will just take, uh, this documents and I'll

186
00:10:43,000 --> 00:10:46,000
say, hey, starting 50 documents, just go ahead and do it right.

187
00:10:46,000 --> 00:10:51,000
You can also do the remaining one so that it will not take much time for doing this entire processing.

188
00:10:51,000 --> 00:10:51,000
Okay.

189
00:10:51,000 --> 00:10:53,000
That is the reason I have just given top 50.

190
00:10:53,000 --> 00:11:00,000
Uh, now I will go ahead and write s t dot session underscore state dot vectors.

191
00:11:00,000 --> 00:11:03,000
And here we are going to basically use for this.

192
00:11:04,000 --> 00:11:08,000
See this last step is all about converting your final documents.

193
00:11:08,000 --> 00:11:11,000
First of all converting that into vectors.

194
00:11:11,000 --> 00:11:16,000
And after you convert everything into vectors, all the text or documents into vector, then you try

195
00:11:16,000 --> 00:11:18,000
to store it in some kind of vector database.

196
00:11:18,000 --> 00:11:19,000
Okay.

197
00:11:19,000 --> 00:11:25,000
And this vectors that you are seeing SD dot session dot vectors sessions underscore state dot vectors.

198
00:11:25,000 --> 00:11:27,000
This is your vector database.

199
00:11:27,000 --> 00:11:31,000
So I will go ahead and write files dot from underscore documents.

200
00:11:32,000 --> 00:11:39,000
And here you have SD dot session state dot final underscore documents.

201
00:11:40,000 --> 00:11:44,000
It is final underscore documents.

202
00:11:44,000 --> 00:11:49,000
And here I'm also going to the second parameter we need to give is our embedding technique.

203
00:11:49,000 --> 00:11:50,000
Right.

204
00:11:50,000 --> 00:11:57,000
So if I go ahead and write SD dot session underscore state dot embedding whatever embedding techniques

205
00:11:57,000 --> 00:11:59,000
I have actually used.

206
00:11:59,000 --> 00:12:00,000
Right.

207
00:12:00,000 --> 00:12:01,000
That's it.

208
00:12:01,000 --> 00:12:02,000
You know.

209
00:12:02,000 --> 00:12:07,000
So finally after executing all these things, you'll be seeing that you're converting this into vectors.

210
00:12:07,000 --> 00:12:12,000
You don't even have to return this vectors because already we are saving this in the session state.

211
00:12:12,000 --> 00:12:12,000
Perfect.

212
00:12:12,000 --> 00:12:15,000
Now quickly, let's go ahead and do this.

213
00:12:15,000 --> 00:12:17,000
I will go ahead and create my prompt.

214
00:12:17,000 --> 00:12:22,000
And here I will write SD dot text underscore input okay.

215
00:12:22,000 --> 00:12:30,000
And here we are going to basically use enter your enter your query okay.

216
00:12:30,000 --> 00:12:34,000
From the documents or from the research paper I'll say okay.

217
00:12:36,000 --> 00:12:39,000
And then finally, uh, I will go ahead and do this.

218
00:12:39,000 --> 00:12:44,000
I'll go ahead and just write if s t dot button, okay?

219
00:12:44,000 --> 00:12:50,000
And I'll say, hey, document embedding and I'll just create a button, okay.

220
00:12:50,000 --> 00:12:50,000
Over there.

221
00:12:51,000 --> 00:12:55,000
This button will be responsible in running this particular function and creating our vector store.

222
00:12:55,000 --> 00:12:56,000
Okay.

223
00:12:56,000 --> 00:13:00,000
So as soon as we run this this is basically going to read all the research papers.

224
00:13:00,000 --> 00:13:02,000
It is going to probably convert that into documents.

225
00:13:02,000 --> 00:13:05,000
And then it is finally going to convert into a vectors.

226
00:13:05,000 --> 00:13:05,000
Okay.

227
00:13:05,000 --> 00:13:11,000
So here, uh, what I will do is that I'll just go ahead and call this and I'll say hey go ahead and

228
00:13:11,000 --> 00:13:13,000
call this create vector embedding.

229
00:13:13,000 --> 00:13:18,000
And after doing that, if once it is successful I'll go ahead and say read dot write.

230
00:13:19,000 --> 00:13:22,000
Your vector database is ready okay.

231
00:13:22,000 --> 00:13:25,000
So that you will be able to query from it okay.

232
00:13:25,000 --> 00:13:29,000
Now it's time to check the Power of Grok API.

233
00:13:29,000 --> 00:13:35,000
Okay, so once your vector database is ready, uh, the next step will be that, uh, we will go ahead

234
00:13:35,000 --> 00:13:42,000
and check our, uh, you know, the specifically we'll check, uh, that how powerful is the grok API?

235
00:13:42,000 --> 00:13:43,000
So that is the reason I'm importing time.

236
00:13:43,000 --> 00:13:47,000
So here, uh, I will just go ahead and rename this to user underscore prompt.

237
00:13:47,000 --> 00:13:48,000
Okay.

238
00:13:48,000 --> 00:13:53,000
So finally if I give this user underscore prompt if user is giving any prompt okay.

239
00:13:54,000 --> 00:13:56,000
Now is the most important step.

240
00:13:56,000 --> 00:13:58,000
What should basically happen.

241
00:13:58,000 --> 00:14:05,000
You know that my vectors this is t dot session state dot vectors has my vector db vector store db right

242
00:14:05,000 --> 00:14:08,000
now when as soon as my user prompt.

243
00:14:08,000 --> 00:14:13,000
Basically user is writing some input and pressing some enter or pressing enter right?

244
00:14:13,000 --> 00:14:16,000
It should first of all create this stuff document chain.

245
00:14:16,000 --> 00:14:18,000
And now let's discuss about this stuff.

246
00:14:18,000 --> 00:14:19,000
Document change what it is.

247
00:14:19,000 --> 00:14:22,000
Here we are going to give two important parameters.

248
00:14:22,000 --> 00:14:27,000
One is LM model and the second one is nothing but our prompt okay.

249
00:14:27,000 --> 00:14:29,000
So this should be the prompt.

250
00:14:29,000 --> 00:14:33,000
Now let me just go ahead and define this variable document underscore chain.

251
00:14:33,000 --> 00:14:36,000
Now see what this exactly does.

252
00:14:36,000 --> 00:14:38,000
Create stuff underscore document chain.

253
00:14:38,000 --> 00:14:42,000
It creates a chain for passing a list of documents to the model.

254
00:14:42,000 --> 00:14:42,000
Okay.

255
00:14:42,000 --> 00:14:47,000
What it is basically doing, it creates a chain for passing a list of documents to the model.

256
00:14:47,000 --> 00:14:51,000
And here the two important parameters are LM and prompt.

257
00:14:52,000 --> 00:14:56,000
As soon as I give this here, you'll be able to see that in the prompt you have this variable called

258
00:14:56,000 --> 00:14:57,000
as context.

259
00:14:57,000 --> 00:15:03,000
Right inside this context, all that list of documents will specifically go and whatever specific input

260
00:15:03,000 --> 00:15:06,000
you are giving it will go over here, right how it will go.

261
00:15:06,000 --> 00:15:11,000
I will just combine it further with one more important retrieval chain, which will discuss about okay,

262
00:15:11,000 --> 00:15:16,000
but in short, this is providing a list of documents in specifically in this particular context.

263
00:15:16,000 --> 00:15:17,000
Like it will get appended over here.

264
00:15:17,000 --> 00:15:21,000
And this entire chat prompt template will be created from here itself.

265
00:15:21,000 --> 00:15:22,000
Okay.

266
00:15:22,000 --> 00:15:26,000
Now further, we will not keep quiet with this document chain here.

267
00:15:26,000 --> 00:15:33,000
What I will do is that I will go ahead and write st dot session underscore state okay dot vectors okay.

268
00:15:33,000 --> 00:15:35,000
You know this it is a vectors is basically there.

269
00:15:36,000 --> 00:15:41,000
I will go ahead and write this as as retriever.

270
00:15:41,000 --> 00:15:44,000
Now you know that we need to convert.

271
00:15:44,000 --> 00:15:49,000
Uh, if I want to retrieve any information from my vector db, I need to first of all convert that into

272
00:15:49,000 --> 00:15:50,000
a retriever.

273
00:15:50,000 --> 00:15:51,000
Right.

274
00:15:51,000 --> 00:15:56,000
So if I go ahead and write as retriever, let me just check the spelling.

275
00:15:56,000 --> 00:15:57,000
I hope it is fine.

276
00:16:00,000 --> 00:16:09,000
Okay so just a second as underscore retriever.

277
00:16:09,000 --> 00:16:09,000
Okay.

278
00:16:09,000 --> 00:16:16,000
So I'm just going to convert this into retriever and finally save this particular value in the form

279
00:16:16,000 --> 00:16:18,000
of a retriever variable.

280
00:16:18,000 --> 00:16:24,000
And what this retriever acts as, it acts as an interface to pass to query your vector database.

281
00:16:24,000 --> 00:16:25,000
In short.

282
00:16:25,000 --> 00:16:25,000
Right.

283
00:16:25,000 --> 00:16:27,000
So this is my vectors over here.

284
00:16:27,000 --> 00:16:30,000
I've used this t dot embeddings techniques that I've used over here.

285
00:16:30,000 --> 00:16:31,000
This is perfect.

286
00:16:31,000 --> 00:16:38,000
Now once I get this as a retriever you know what we do is that obviously this retriever is like querying

287
00:16:38,000 --> 00:16:39,000
a specific vector DB.

288
00:16:39,000 --> 00:16:43,000
This document chain has the context of a list of entire documents.

289
00:16:43,000 --> 00:16:49,000
So once we combine both of them, in short we are going to create a retrieval chain that is create retriever

290
00:16:49,000 --> 00:16:49,000
chain.

291
00:16:49,000 --> 00:16:51,000
And here two parameters are basically given.

292
00:16:51,000 --> 00:16:54,000
One is retriever and the second one is document chain.

293
00:16:54,000 --> 00:16:55,000
Okay.

294
00:16:55,000 --> 00:16:59,000
Once we do this we will be able to invoke this entire thing right.

295
00:16:59,000 --> 00:17:02,000
So here I will go ahead and write retrieval underscore chain.

296
00:17:02,000 --> 00:17:02,000
Right.

297
00:17:02,000 --> 00:17:07,000
So this actually is my chain which has document chain which has retrieval combined together.

298
00:17:07,000 --> 00:17:08,000
Okay.

299
00:17:08,000 --> 00:17:10,000
Now let's go ahead and see the power of this grok API.

300
00:17:10,000 --> 00:17:11,000
You'll just understand.

301
00:17:11,000 --> 00:17:19,000
So first of all I will just go ahead and write a start timer over here I'll say time dot process time

302
00:17:19,000 --> 00:17:21,000
process underscore time.

303
00:17:21,000 --> 00:17:25,000
And once we process this you will be able to see my response over here.

304
00:17:25,000 --> 00:17:29,000
And I'll go ahead and write my retrieval chain.

305
00:17:29,000 --> 00:17:29,000
Okay.

306
00:17:29,000 --> 00:17:32,000
Dot invoke okay.

307
00:17:32,000 --> 00:17:34,000
And you know what kind of input I'm actually giving.

308
00:17:34,000 --> 00:17:37,000
It is nothing but input over here.

309
00:17:37,000 --> 00:17:37,000
Right.

310
00:17:37,000 --> 00:17:39,000
This is the same input that we are giving over here.

311
00:17:39,000 --> 00:17:39,000
Right.

312
00:17:39,000 --> 00:17:42,000
The same variable, the same input we are giving over here.

313
00:17:42,000 --> 00:17:46,000
And here we are going to just replace this with user prompt.

314
00:17:47,000 --> 00:17:51,000
Now we will be able to get the answer after this.

315
00:17:51,000 --> 00:17:55,000
But before that we will go ahead and calculate our response time.

316
00:17:55,000 --> 00:17:55,000
Okay.

317
00:17:56,000 --> 00:17:57,000
So let's go ahead and print.

318
00:18:00,000 --> 00:18:02,000
I'll say, hey, uh, I'll use a f string.

319
00:18:02,000 --> 00:18:06,000
I'll say response time is nothing, but it is equal to.

320
00:18:08,000 --> 00:18:10,000
It is equal to.

321
00:18:11,000 --> 00:18:18,000
I will go ahead and write over here time dot process underscore time minus start time.

322
00:18:18,000 --> 00:18:25,000
Okay, once I do this I will be able to get my, uh, the time how much it time how much time it has

323
00:18:25,000 --> 00:18:28,000
basically taken for this retrieval chain to get executed.

324
00:18:28,000 --> 00:18:31,000
And then finally we go ahead and write our response.

325
00:18:31,000 --> 00:18:38,000
So I'll go ahead and write TX dot write let's say response off answer okay.

326
00:18:38,000 --> 00:18:39,000
Done.

327
00:18:40,000 --> 00:18:47,000
Finally we will go ahead and write uh, with uh c you also need to know that what kind of response,

328
00:18:47,000 --> 00:18:49,000
what kind of other context we usually get.

329
00:18:49,000 --> 00:18:49,000
Right.

330
00:18:49,000 --> 00:18:52,000
So for that also you can actually go ahead and display it.

331
00:18:52,000 --> 00:18:57,000
So I'll go ahead and write Streamlit with a Streamlit uh expander.

332
00:18:57,000 --> 00:19:02,000
And here I'm just going to write with St Dot expander.

333
00:19:02,000 --> 00:19:02,000
the.

334
00:19:05,000 --> 00:19:10,000
Document similarity search.

335
00:19:12,000 --> 00:19:13,000
Okay.

336
00:19:13,000 --> 00:19:19,000
So I will go ahead and write for I comma doc in enumerate okay.

337
00:19:19,000 --> 00:19:23,000
And we basically take C along with this response of answer no.

338
00:19:23,000 --> 00:19:27,000
There will be another one variable which is called as response of context.

339
00:19:27,000 --> 00:19:32,000
That will actually give you all the relevant context information from that particular documents.

340
00:19:32,000 --> 00:19:32,000
Okay.

341
00:19:32,000 --> 00:19:34,000
We'll go ahead and write this also.

342
00:19:34,000 --> 00:19:42,000
So I'll go ahead and write SD dot write doc dot page underscore content okay.

343
00:19:42,000 --> 00:19:48,000
Now quickly let me just go ahead and uh make sure that right all the other information I'm just displaying

344
00:19:48,000 --> 00:19:51,000
what all other context is basically coming over here.

345
00:19:51,000 --> 00:19:52,000
I'll just give this.

346
00:19:52,000 --> 00:19:56,000
So one final change that I really wanted to do.

347
00:19:56,000 --> 00:19:56,000
Okay.

348
00:19:56,000 --> 00:20:00,000
So after writing this code, see we are using all of my embeddings.

349
00:20:00,000 --> 00:20:04,000
Uh, it is of uh, no worries, you can definitely use it.

350
00:20:04,000 --> 00:20:09,000
But sometimes, you know, since this is running in our local machine, you know, it may definitely

351
00:20:09,000 --> 00:20:17,000
take a lot of time to probably, you know, convert that into, you know, embeddings specifically convert

352
00:20:17,000 --> 00:20:18,000
all the text into vectors.

353
00:20:18,000 --> 00:20:23,000
So that is the reason what I will do is that over here, instead of using my embedding, I will just

354
00:20:23,000 --> 00:20:27,000
go ahead and use OpenAI embedding because OpenAI embedding will be in the form of APIs.

355
00:20:28,000 --> 00:20:33,000
Uh, the reason why I'm doing this is that because see, if I don't do this automatically, it is going

356
00:20:33,000 --> 00:20:37,000
to take a lot of time just to probably, um, uh, convert all our text into vectors.

357
00:20:37,000 --> 00:20:41,000
Along with this, we will go ahead and load our opening AI API key.

358
00:20:41,000 --> 00:20:42,000
Okay.

359
00:20:42,000 --> 00:20:44,000
So please make sure that you do this.

360
00:20:44,000 --> 00:20:46,000
You can go ahead and try with all of my embedding also.

361
00:20:46,000 --> 00:20:51,000
But as soon as you will probably run it, you will be seeing that it will take a lot of time, you know,

362
00:20:51,000 --> 00:20:53,000
and I have already done that.

363
00:20:53,000 --> 00:20:57,000
So that is the reason I'm saying you, uh, but I think with the help of OpenAI embedding, it should

364
00:20:57,000 --> 00:20:58,000
happen very much quickly.

365
00:20:58,000 --> 00:20:59,000
Right.

366
00:20:59,000 --> 00:21:01,000
So let's go ahead and execute now.

367
00:21:01,000 --> 00:21:03,000
So I will just go ahead and clear my screen.

368
00:21:03,000 --> 00:21:07,000
I'll say, hey Streamlit, run App.py.

369
00:21:07,000 --> 00:21:13,000
Okay, so now my entire website is over here.

370
00:21:13,000 --> 00:21:15,000
I will click on Document Embedding.

371
00:21:15,000 --> 00:21:16,000
Let's wait for some time.

372
00:21:16,000 --> 00:21:20,000
Now as soon as I click on Document embedding, see what is happening inside the hood.

373
00:21:20,000 --> 00:21:21,000
Right.

374
00:21:21,000 --> 00:21:22,000
You should really understand this.

375
00:21:22,000 --> 00:21:25,000
So here this function has got created.

376
00:21:25,000 --> 00:21:28,000
Now this session state variable will get created.

377
00:21:28,000 --> 00:21:30,000
We are going to create embeddings.

378
00:21:30,000 --> 00:21:31,000
Then it will become loader.

379
00:21:31,000 --> 00:21:33,000
It will read all the research papers inside this.

380
00:21:33,000 --> 00:21:35,000
Then you have this documents.

381
00:21:35,000 --> 00:21:36,000
Then you have this text splitter.

382
00:21:37,000 --> 00:21:37,000
Similarly.

383
00:21:37,000 --> 00:21:40,000
Finally you will be able to create your vector database.

384
00:21:40,000 --> 00:21:40,000
Right.

385
00:21:40,000 --> 00:21:42,000
And all these things are there.

386
00:21:42,000 --> 00:21:43,000
Perfect.

387
00:21:43,000 --> 00:21:44,000
It looks good enough.

388
00:21:44,000 --> 00:21:47,000
Let's see whether it has got executed or not.

389
00:21:47,000 --> 00:21:51,000
So yes here you can see the vector database is ready.

390
00:21:51,000 --> 00:21:59,000
But if you try to just use uh uh, you know, embedding it is going to take forever because that entire

391
00:21:59,000 --> 00:22:01,000
embedding is going to just happen in a local machine.

392
00:22:01,000 --> 00:22:06,000
So let me just go ahead and ask, what is Transformers?

393
00:22:06,000 --> 00:22:09,000
I'll ask a question, what is a Transformers?

394
00:22:09,000 --> 00:22:11,000
And I will go ahead and press enter.

395
00:22:12,000 --> 00:22:16,000
So here you can see based on the provided context, transformer is a model architecture that relies

396
00:22:16,000 --> 00:22:21,000
entirely on attention mechanism to draw global dependency between input and output.

397
00:22:21,000 --> 00:22:22,000
Right.

398
00:22:22,000 --> 00:22:24,000
And here is your document similarity search.

399
00:22:24,000 --> 00:22:25,000
Right.

400
00:22:25,000 --> 00:22:32,000
So from all this context, it was able to retrieve from the uh research paper, which is amazing right.

401
00:22:32,000 --> 00:22:33,000
This looks quite good.

402
00:22:33,000 --> 00:22:34,000
Right.

403
00:22:34,000 --> 00:22:41,000
Uh, let's say uh what I'll go ahead and write what is a large language model.

404
00:22:41,000 --> 00:22:41,000
Okay.

405
00:22:42,000 --> 00:22:44,000
And I'll go ahead and press enter.

406
00:22:44,000 --> 00:22:46,000
Or based on the context.

407
00:22:46,000 --> 00:22:47,000
So much information is there.

408
00:22:47,000 --> 00:22:49,000
And here you can also see your entire context.

409
00:22:49,000 --> 00:22:51,000
Information is also visible.

410
00:22:51,000 --> 00:22:51,000
Right.

411
00:22:52,000 --> 00:22:53,000
Pretty much nice.

412
00:22:53,000 --> 00:22:56,000
So you're able to see this entire information.

413
00:22:56,000 --> 00:23:01,000
See uh if you want to get more larger context information, uh, more larger information with respect

414
00:23:01,000 --> 00:23:07,000
to this research paper, what you can do is that you can go to the code and you can change, uh, this

415
00:23:07,000 --> 00:23:12,000
things the chunk size, you can keep the chunk size to 10,000, and you can probably keep the overlap

416
00:23:12,000 --> 00:23:14,000
to 500 and keep on doing this.

417
00:23:14,000 --> 00:23:14,000
Right.

418
00:23:14,000 --> 00:23:17,000
But here, uh, in short, we have actually got this.

419
00:23:17,000 --> 00:23:20,000
Uh, again, I'll tell you why I have used OpenAI document embedding.

420
00:23:20,000 --> 00:23:25,000
The open source LM model is specifically used, but other than that, I think everything looks fine.

421
00:23:25,000 --> 00:23:25,000
Okay.

422
00:23:26,000 --> 00:23:28,000
Um, uh, let me just go ahead and write.

423
00:23:28,000 --> 00:23:33,000
What is attention is all you need, okay.

424
00:23:33,000 --> 00:23:37,000
If I want to ask this question, I will just go ahead and press enter.

425
00:23:37,000 --> 00:23:40,000
And this is your entire information, right.

426
00:23:40,000 --> 00:23:43,000
And all the related context information is over here.

427
00:23:43,000 --> 00:23:44,000
See?

428
00:23:45,000 --> 00:23:46,000
Everything is visible.

429
00:23:47,000 --> 00:23:48,000
This is good enough over here.

430
00:23:48,000 --> 00:23:52,000
I think you are able to understand this specific project.

431
00:23:52,000 --> 00:23:54,000
Um, this was it for my side.

432
00:23:55,000 --> 00:23:57,000
I'll see you all in the next video.

433
00:23:57,000 --> 00:23:57,000
Thank you.

