1
00:00:00,000 --> 00:00:00,000
Hello guys.

2
00:00:00,000 --> 00:00:03,000
So we are going to continue the discussion with respect to Lang Chen.

3
00:00:03,000 --> 00:00:04,000
Already.

4
00:00:04,000 --> 00:00:09,000
We had uh, in our previous module, we had discussed about building chat bots with, uh, you know,

5
00:00:09,000 --> 00:00:11,000
uh, chat message history.

6
00:00:11,000 --> 00:00:15,000
Also now in this video we are going to discuss about vector stores and retrievers.

7
00:00:16,000 --> 00:00:21,000
And uh, in this video tutorial we will familiarize you with the Lang and vector store and retriever

8
00:00:21,000 --> 00:00:22,000
abstraction.

9
00:00:22,000 --> 00:00:28,000
These abstraction are designed to support retrieval of data from vector databases and other sources

10
00:00:28,000 --> 00:00:30,000
for integration with LLM workflows.

11
00:00:30,000 --> 00:00:37,000
They are important for application that fetch data to be reasoned over as part of model inference already.

12
00:00:37,000 --> 00:00:41,000
Uh, if you remember in previously also we have discussed about vector stores and retrieval, but here

13
00:00:41,000 --> 00:00:45,000
I really want to add more features and even play with, uh, chat message history.

14
00:00:45,000 --> 00:00:50,000
Okay, so first of all, what we are basically going to do over here is that we will quickly go ahead

15
00:00:50,000 --> 00:00:56,000
and install this important libraries like pip install Lang Chin, uh, along with the Lang Chin, we

16
00:00:56,000 --> 00:01:00,000
will also go ahead and install pip install Lang Chin Chroma.

17
00:01:00,000 --> 00:01:05,000
I hope we have done all this installation beforehand in our same virtual environment.

18
00:01:05,000 --> 00:01:13,000
And then along with this you have also done the installation of pip install lang chin slash crock.

19
00:01:13,000 --> 00:01:17,000
Okay, so all these installation you have specifically done I guess so because you may.

20
00:01:17,000 --> 00:01:18,000
Sure.

21
00:01:18,000 --> 00:01:22,000
You should also have written this in your requirement dot txt okay.

22
00:01:22,000 --> 00:01:24,000
So here you can see requirement is already satisfied.

23
00:01:24,000 --> 00:01:27,000
So I will just go ahead and make this right okay.

24
00:01:27,000 --> 00:01:32,000
But just understand that I've done this all uh installation with respect to the libraries that I require

25
00:01:32,000 --> 00:01:33,000
okay.

26
00:01:33,000 --> 00:01:36,000
So please make sure that you update all these things in requirement dot txt.

27
00:01:36,000 --> 00:01:42,000
Now the next thing that we are basically going to do is that I will take one example that is even given

28
00:01:42,000 --> 00:01:44,000
in the documentation page of Lang Chain.

29
00:01:44,000 --> 00:01:48,000
So how to probably go ahead and create a document okay.

30
00:01:48,000 --> 00:01:52,000
So you need to understand what exactly this document is.

31
00:01:52,000 --> 00:01:59,000
So here I'm going to write some information about the document so that you will be able to get get this

32
00:01:59,000 --> 00:02:01,000
and even be able to refer this.

33
00:02:01,000 --> 00:02:04,000
So I will quickly add some comments over here.

34
00:02:04,000 --> 00:02:07,000
Um, let's say this is my page content.

35
00:02:07,000 --> 00:02:10,000
Okay I will go ahead and add over here page content.

36
00:02:10,000 --> 00:02:12,000
This will basically be my metadata okay.

37
00:02:12,000 --> 00:02:15,000
And then we will read it and we'll try to see it okay.

38
00:02:15,000 --> 00:02:21,000
So here you can see Lang Chen implements a document abstraction which is intended to represent a unit

39
00:02:21,000 --> 00:02:23,000
of text and associated metadata.

40
00:02:23,000 --> 00:02:27,000
It has two attributes uh page content a string representing the content.

41
00:02:27,000 --> 00:02:31,000
And it has metadata where a dictionary is containing arbitrary metadata.

42
00:02:31,000 --> 00:02:36,000
The metadata attribute can capture information about the source of the document, its relationship to

43
00:02:36,000 --> 00:02:38,000
other document, and other information.

44
00:02:38,000 --> 00:02:43,000
Okay, uh, note that an individual document object often represents a chunk of a large document.

45
00:02:43,000 --> 00:02:44,000
Okay.

46
00:02:44,000 --> 00:02:49,000
So let's say, uh, here, in order to work with this specific document, I will go ahead and import

47
00:02:49,000 --> 00:02:51,000
from long chain underscore dot documents.

48
00:02:51,000 --> 00:02:53,000
I will be importing this document class.

49
00:02:53,000 --> 00:02:59,000
Now in order to define my documents, I will be using a list of documents which I'm actually creating.

50
00:02:59,000 --> 00:02:59,000
This right.

51
00:02:59,000 --> 00:03:04,000
As said documents has two important, uh, properties, right.

52
00:03:04,000 --> 00:03:05,000
Two important attributes.

53
00:03:05,000 --> 00:03:09,000
One is the page content and the other one is the metadata.

54
00:03:09,000 --> 00:03:14,000
So metadata over here will be a dictionary containing arbitrary metadata.

55
00:03:14,000 --> 00:03:17,000
The metadata attributes can capture information about the source of the documents, right?

56
00:03:17,000 --> 00:03:20,000
So here you can see that the source is nothing but this specific doc.

57
00:03:20,000 --> 00:03:21,000
Okay.

58
00:03:21,000 --> 00:03:23,000
We have just written it over here in this way.

59
00:03:23,000 --> 00:03:28,000
So this will basically become my one document second document third document fourth document.

60
00:03:28,000 --> 00:03:28,000
Right.

61
00:03:28,000 --> 00:03:33,000
And remember this document can be a part of a large document.

62
00:03:33,000 --> 00:03:34,000
It can represent a chunk of a large document.

63
00:03:34,000 --> 00:03:39,000
Let's say if I have one PDF where I have eight pages, this can probably be my first page.

64
00:03:39,000 --> 00:03:40,000
This can be my second page.

65
00:03:40,000 --> 00:03:42,000
This can be my third page.

66
00:03:42,000 --> 00:03:44,000
So that kind of information will have right.

67
00:03:44,000 --> 00:03:46,000
So this is what a document is.

68
00:03:46,000 --> 00:03:49,000
So let me just go ahead and execute this.

69
00:03:49,000 --> 00:03:54,000
Now if I go ahead and print this particular document I will be able to see this documents over here.

70
00:03:54,000 --> 00:03:55,000
Right.

71
00:03:55,000 --> 00:03:58,000
And again the type will be specifically document itself okay.

72
00:03:59,000 --> 00:04:02,000
Now let's go ahead and work with Vector Store.

73
00:04:02,000 --> 00:04:08,000
Now already I have told you what is the main importance of Vector Store is that we will be able to convert

74
00:04:08,000 --> 00:04:12,000
this text into embeddings, right into word vectors, into vectors.

75
00:04:12,000 --> 00:04:18,000
We basically say, and then we can store all those vectors inside our vector store db.

76
00:04:18,000 --> 00:04:18,000
Right.

77
00:04:18,000 --> 00:04:21,000
So in this case I will take an example of chroma.

78
00:04:21,000 --> 00:04:29,000
So I will go ahead and write lang chain underscore uh lang chain underscore chroma I'm going to import

79
00:04:29,000 --> 00:04:30,000
my chroma DB.

80
00:04:30,000 --> 00:04:31,000
Okay.

81
00:04:31,000 --> 00:04:37,000
Now what I'm actually going to do over here is that quickly, um, will do one thing over here.

82
00:04:37,000 --> 00:04:40,000
I will use completely open source libraries.

83
00:04:40,000 --> 00:04:40,000
Okay.

84
00:04:40,000 --> 00:04:44,000
Open source, LM model, open source, uh, embedding techniques and all.

85
00:04:44,000 --> 00:04:48,000
Now, you know, in our env file we have also used this HDF underscore token.

86
00:04:48,000 --> 00:04:48,000
Right.

87
00:04:48,000 --> 00:04:55,000
This token is specifically coming from hugging face now with the help of this particular token, I can

88
00:04:55,000 --> 00:05:01,000
call open source libraries that are available with respect to embedding or even, uh, LM models.

89
00:05:01,000 --> 00:05:01,000
Right.

90
00:05:01,000 --> 00:05:07,000
So in this case, first of all, what I will do is that, uh, I will just make a new cell over here.

91
00:05:07,000 --> 00:05:09,000
I will go ahead and write import OS.

92
00:05:09,000 --> 00:05:16,000
And along with this I will say from uh, from dot env dot env.

93
00:05:16,000 --> 00:05:19,000
Sorry from dot env.

94
00:05:19,000 --> 00:05:22,000
Import load underscore dot env.

95
00:05:22,000 --> 00:05:23,000
Right.

96
00:05:23,000 --> 00:05:27,000
Uh I will go ahead and initialize this load underscore dot env because I really want the environment

97
00:05:27,000 --> 00:05:28,000
variable.

98
00:05:28,000 --> 00:05:33,000
Now I will go ahead and first of all take my grok underscore API key because I will be able to refer

99
00:05:33,000 --> 00:05:40,000
my um, I will be able to usually use the open source model that are present in the grok AI infrastructure.

100
00:05:40,000 --> 00:05:41,000
Okay.

101
00:05:41,000 --> 00:05:43,000
so here I will go ahead and write OS dot get env.

102
00:05:43,000 --> 00:05:47,000
And here I'm just going to give my grok API key.

103
00:05:47,000 --> 00:05:51,000
Please make sure that you have created that in your environment variable.

104
00:05:51,000 --> 00:05:51,000
Okay.

105
00:05:51,000 --> 00:05:54,000
The next thing that I'm going to set is OS dot environ.

106
00:05:54,000 --> 00:05:58,000
I will just going to call this particular HDF underscore token.

107
00:05:58,000 --> 00:06:01,000
So let me just go ahead and call this HDF underscore token.

108
00:06:01,000 --> 00:06:03,000
I hope the spelling is right.

109
00:06:03,000 --> 00:06:04,000
It should be capital.

110
00:06:04,000 --> 00:06:07,000
So here you have my f underscore token.

111
00:06:07,000 --> 00:06:12,000
And I'm going to initialize this value to os dot get env.

112
00:06:12,000 --> 00:06:16,000
And inside this I'm just going to use this same f underscore token.

113
00:06:16,000 --> 00:06:16,000
Right.

114
00:06:16,000 --> 00:06:20,000
So this is quite simple quite easy till now okay.

115
00:06:20,000 --> 00:06:21,000
We have set up all the environment variable.

116
00:06:21,000 --> 00:06:25,000
Now let me just go ahead and call my uh LM model.

117
00:06:25,000 --> 00:06:33,000
So here for using the LM model I also have to import from long chain underscore grok.

118
00:06:34,000 --> 00:06:39,000
Import grok itself for Chad grok right.

119
00:06:39,000 --> 00:06:40,000
So this will be the Chad grok.

120
00:06:40,000 --> 00:06:44,000
And with the help of this API key we will try to access all the models.

121
00:06:44,000 --> 00:06:51,000
So this time for this particular uh for this particular problem statement, I'm going to take my different

122
00:06:51,000 --> 00:06:52,000
model name over here.

123
00:06:52,000 --> 00:06:58,000
So over here, first of all I will go ahead and apply my grok API key which will be equal to my grok

124
00:06:58,000 --> 00:06:59,000
API key itself.

125
00:06:59,000 --> 00:07:00,000
Okay.

126
00:07:00,000 --> 00:07:02,000
This will be my first parameter.

127
00:07:02,000 --> 00:07:04,000
And the second parameter will basically be my model.

128
00:07:04,000 --> 00:07:10,000
Now this time if you go ahead and see the documentation page of grok, this time I'm going to take another

129
00:07:10,000 --> 00:07:11,000
model.

130
00:07:11,000 --> 00:07:19,000
Previously we used uh, gamma two, but now I'm going to use llama three and eight B and 8192.

131
00:07:19,000 --> 00:07:20,000
Okay.

132
00:07:20,000 --> 00:07:24,000
So from where I'm actually getting this let me just open the browser and show it to you.

133
00:07:24,000 --> 00:07:28,000
So this is my browser I will go to google.com.

134
00:07:28,000 --> 00:07:30,000
And here I've already logged in.

135
00:07:30,000 --> 00:07:36,000
So you can see I'm using this meta lambda 317 billion sorry 8,000,000,008 192.

136
00:07:36,000 --> 00:07:37,000
So this is my uh model.

137
00:07:37,000 --> 00:07:43,000
It is 8 billion parameter version of meta llama model delivers compelling performance at best in class

138
00:07:43,000 --> 00:07:44,000
speed and price.

139
00:07:44,000 --> 00:07:47,000
Okay, so we will be specifically using this okay.

140
00:07:47,000 --> 00:07:50,000
So let's quickly go ahead and use that.

141
00:07:50,000 --> 00:07:52,000
So over here I've actually used this.

142
00:07:52,000 --> 00:07:55,000
And now I will go ahead and execute my LM model okay.

143
00:07:55,000 --> 00:07:56,000
Now this is fine.

144
00:07:56,000 --> 00:07:58,000
Now as you all know why do we use chroma.

145
00:07:58,000 --> 00:08:00,000
Chroma is a kind of vector store.

146
00:08:00,000 --> 00:08:04,000
And in order to use chroma, first of all we need to convert our text into vectors.

147
00:08:04,000 --> 00:08:06,000
Now how do we convert a text into vectors?

148
00:08:06,000 --> 00:08:10,000
Obviously they are embedding techniques we have seen about different different embedding techniques

149
00:08:10,000 --> 00:08:12,000
like OpenAI embedding llama embedding.

150
00:08:12,000 --> 00:08:13,000
Right?

151
00:08:13,000 --> 00:08:17,000
In this video I will be showing you one embedding technique, which we have used with respect to hugging

152
00:08:17,000 --> 00:08:18,000
face because it is open source.

153
00:08:18,000 --> 00:08:19,000
Okay.

154
00:08:19,000 --> 00:08:25,000
So with respect to hugging face, what we are actually going to do is that first of all, uh, I have

155
00:08:25,000 --> 00:08:29,000
set up this h f underscore token with respect to the environment.

156
00:08:29,000 --> 00:08:36,000
Now I will quickly go ahead and install one library which is called as pip install lang chain huggingface.

157
00:08:36,000 --> 00:08:39,000
But I hope we have done this before also.

158
00:08:39,000 --> 00:08:42,000
So let me just go ahead and write Huggingface.

159
00:08:42,000 --> 00:08:45,000
And uh, we are just going to install this particular library.

160
00:08:45,000 --> 00:08:51,000
So here you can see that this library is basically getting installed and it shows requirement already

161
00:08:51,000 --> 00:08:51,000
satisfied.

162
00:08:51,000 --> 00:08:52,000
We have already done this installation.

163
00:08:52,000 --> 00:08:54,000
So I'm just doing it in front of you.

164
00:08:54,000 --> 00:08:58,000
If you have not done it, please make sure that after you do the installation, write this in your requirement

165
00:08:58,000 --> 00:09:00,000
dot txt to keep a track of it.

166
00:09:00,000 --> 00:09:02,000
Okay, now what I'm actually going to do.

167
00:09:02,000 --> 00:09:06,000
I'll go ahead and write from Lang Chen from Lang Chen.

168
00:09:06,000 --> 00:09:11,000
Um Lang Chen underscore hugging face.

169
00:09:11,000 --> 00:09:16,000
Okay I'm going to import hugging face embeddings okay.

170
00:09:16,000 --> 00:09:18,000
So this hugging face embedding.

171
00:09:18,000 --> 00:09:22,000
So it actually helps us to download the embedding techniques uh embedding model.

172
00:09:22,000 --> 00:09:25,000
Uh with respect to the different kind of models that are available over there.

173
00:09:25,000 --> 00:09:27,000
So I'm just going to go ahead and create my embeddings.

174
00:09:27,000 --> 00:09:28,000
So I'll go ahead and write.

175
00:09:28,000 --> 00:09:30,000
Embeddings is equal to hugging face embedding.

176
00:09:30,000 --> 00:09:36,000
And here my I'm going to give my model name the model name that I'm actually going to specify.

177
00:09:36,000 --> 00:09:36,000
Okay.

178
00:09:36,000 --> 00:09:40,000
Now let's go ahead and open my hugging face okay.

179
00:09:40,000 --> 00:09:44,000
So here I will go ahead and open my hugging face.

180
00:09:44,000 --> 00:09:45,000
Dot Co okay.

181
00:09:45,000 --> 00:09:50,000
Now please make sure that you create an account in this uh c for embedding.

182
00:09:50,000 --> 00:09:52,000
We have a lot of different different models okay.

183
00:09:52,000 --> 00:09:57,000
So if I go ahead and search for embeddings or let's say that I'll go ahead and click on models over

184
00:09:57,000 --> 00:09:57,000
here.

185
00:09:58,000 --> 00:10:03,000
So once I click on models uh you'll be able to see computer vision natural language processing, audio

186
00:10:03,000 --> 00:10:03,000
tabular.

187
00:10:03,000 --> 00:10:08,000
Different different models are basically there for our work use case.

188
00:10:08,000 --> 00:10:12,000
I have searched for one model which is called as all mini LM.

189
00:10:12,000 --> 00:10:17,000
Okay, so this will basically help us in doing the.

190
00:10:17,000 --> 00:10:20,000
So here you can see all mini uh all mini over here.

191
00:10:20,000 --> 00:10:21,000
Right.

192
00:10:21,000 --> 00:10:22,000
Uh it is L6 v2 right.

193
00:10:22,000 --> 00:10:26,000
The same model, uh, we can basically use and from different different companies.

194
00:10:26,000 --> 00:10:29,000
Also, it is provided they have made some kind of changes and all.

195
00:10:29,000 --> 00:10:34,000
but if you understand this is a kind of a sentence transformer, but I'm going to just use this sentence

196
00:10:34,000 --> 00:10:35,000
transformer over here.

197
00:10:35,000 --> 00:10:37,000
Now what this model is all about.

198
00:10:37,000 --> 00:10:39,000
This is a sentence transformer model.

199
00:10:39,000 --> 00:10:45,000
It maps sentence and paragraph to a 384 dimension dense vector space, and can be used for tasks like

200
00:10:45,000 --> 00:10:47,000
clustering or semantic search.

201
00:10:47,000 --> 00:10:53,000
Okay, so whatever words it basically takes, it basically converts into a 384 dimensional vector space.

202
00:10:53,000 --> 00:10:53,000
Okay.

203
00:10:53,000 --> 00:10:56,000
So we will try to use this over here okay.

204
00:10:56,000 --> 00:10:59,000
And based on this uh, we will try to use this specific model.

205
00:10:59,000 --> 00:11:05,000
Now in order to call this model what we need to do is that in the model name I will just go and write

206
00:11:05,000 --> 00:11:08,000
and paste this all mini LM six v2.

207
00:11:08,000 --> 00:11:09,000
Okay.

208
00:11:09,000 --> 00:11:14,000
So once I go ahead and execute this, this will basically be my embeddings that I'm actually going to

209
00:11:14,000 --> 00:11:14,000
use.

210
00:11:14,000 --> 00:11:15,000
Okay.

211
00:11:15,000 --> 00:11:21,000
This will take some time because it is just going to download it from the hugging face and it is downloading

212
00:11:21,000 --> 00:11:22,000
it in your local machine, okay.

213
00:11:23,000 --> 00:11:25,000
So that it can be used at any point of time.

214
00:11:25,000 --> 00:11:28,000
And uh, again.

215
00:11:28,000 --> 00:11:30,000
So now you can see that it has got downloaded.

216
00:11:30,000 --> 00:11:30,000
Okay.

217
00:11:30,000 --> 00:11:31,000
Now it's time.

218
00:11:31,000 --> 00:11:34,000
We will go ahead and use this embedding techniques.

219
00:11:34,000 --> 00:11:34,000
Okay.

220
00:11:34,000 --> 00:11:38,000
Along with our uh, where we will be converting our text into vectors.

221
00:11:38,000 --> 00:11:41,000
So we will be using this chroma vector store.

222
00:11:41,000 --> 00:11:43,000
Now let me just go ahead and create my vector store.

223
00:11:43,000 --> 00:11:49,000
In this vector store I will just go ahead and write chroma dot uh from documents.

224
00:11:49,000 --> 00:11:49,000
Okay.

225
00:11:49,000 --> 00:11:53,000
And inside this from documents we will be giving our documents.

226
00:11:53,000 --> 00:11:54,000
Okay.

227
00:11:54,000 --> 00:11:56,000
And we are going to give our embedding techniques.

228
00:11:56,000 --> 00:11:59,000
So embedding is equal to nothing but embeddings.

229
00:11:59,000 --> 00:12:04,000
And this embeddings is nothing but uh, the same embeddings that we have basically used called as hugging

230
00:12:04,000 --> 00:12:04,000
face embeddings.

231
00:12:05,000 --> 00:12:08,000
Now, what exactly is happening over here?

232
00:12:08,000 --> 00:12:13,000
When I write chroma dot from documents with respect to documents, and embedding is equal to embedding,

233
00:12:13,000 --> 00:12:19,000
first of all, all these documents is going to get converted into vectors, okay, into vectors by using

234
00:12:19,000 --> 00:12:20,000
this embedding technique.

235
00:12:20,000 --> 00:12:23,000
And then it is going to get stored in this chroma DB.

236
00:12:23,000 --> 00:12:26,000
So that is what is basically happening inside this particular line of code.

237
00:12:26,000 --> 00:12:27,000
Okay.

238
00:12:27,000 --> 00:12:33,000
So uh, this was, uh, most of the thing that we really want.

239
00:12:33,000 --> 00:12:33,000
Okay.

240
00:12:33,000 --> 00:12:36,000
And, uh, now let's go ahead and execute it.

241
00:12:36,000 --> 00:12:40,000
And if I go, just go ahead and, uh, see the vector store.

242
00:12:40,000 --> 00:12:43,000
So this it will show it to me that it is a chroma vector store.

243
00:12:43,000 --> 00:12:44,000
Okay.

244
00:12:44,000 --> 00:12:48,000
And, uh, already in my previous video, I've shown you how to store this vector store in your local

245
00:12:48,000 --> 00:12:49,000
if you really want.

246
00:12:49,000 --> 00:12:53,000
Okay, so but this is just like a chroma DB, which is storing the specific information in the form

247
00:12:53,000 --> 00:12:54,000
of vectors okay.

248
00:12:54,000 --> 00:12:56,000
Now this is fine.

249
00:12:56,000 --> 00:13:02,000
Now with the help of these vectors, what exactly we can do with the help of this vector store I can

250
00:13:02,000 --> 00:13:04,000
apply something called a similarity search.

251
00:13:04,000 --> 00:13:06,000
I can go ahead and apply this.

252
00:13:06,000 --> 00:13:10,000
And let's say if I'm going and searching with respect to Cat, I will be getting all the sentences which

253
00:13:10,000 --> 00:13:14,000
has cat information over here which are similar to this particular cat word.

254
00:13:14,000 --> 00:13:15,000
Okay.

255
00:13:15,000 --> 00:13:17,000
So any word that you write you will be able to do this.

256
00:13:17,000 --> 00:13:23,000
Now along with this in the vector store we can also go ahead and hit with Sync query okay.

257
00:13:23,000 --> 00:13:28,000
So a sync query also functionality is supported by this particular vector store.

258
00:13:28,000 --> 00:13:30,000
So let me just go ahead and write.

259
00:13:30,000 --> 00:13:35,000
In order to implement this a sync I will just go ahead and hit or I'll use this await keyword.

260
00:13:35,000 --> 00:13:41,000
And then I will be using the same thing that is called as vector store similarity search by cat.

261
00:13:41,000 --> 00:13:48,000
Now here you will be able to see that, um, a weight uh object list cannot be used in a weight expression.

262
00:13:48,000 --> 00:13:49,000
Okay.

263
00:13:49,000 --> 00:13:50,000
Let's see.

264
00:13:50,000 --> 00:13:50,000
Okay.

265
00:13:50,000 --> 00:13:55,000
Instead of using this similarity search there is another function which is called as a similarity search.

266
00:13:55,000 --> 00:13:56,000
Okay.

267
00:13:56,000 --> 00:14:00,000
So now if I go ahead and hit this here you will be able to get this particular information.

268
00:14:00,000 --> 00:14:06,000
But this entire query will be uh, hitting with respect to using it will not be um, like, uh, it

269
00:14:06,000 --> 00:14:09,000
need not wait till the response is probably coming back.

270
00:14:09,000 --> 00:14:11,000
It will just use this async method.

271
00:14:11,000 --> 00:14:11,000
Okay.

272
00:14:11,000 --> 00:14:12,000
Over here.

273
00:14:13,000 --> 00:14:19,000
Now this, uh, resource, uh, see this information that we are specifically getting here, we are

274
00:14:19,000 --> 00:14:21,000
only getting the page content sometime.

275
00:14:21,000 --> 00:14:24,000
I would also like to get the scores like how much match is basically happening.

276
00:14:24,000 --> 00:14:27,000
So what we can do is that I will just go ahead and use this.

277
00:14:27,000 --> 00:14:34,000
And instead of using just similarity search, I will say, hey, use similarity search with score.

278
00:14:34,000 --> 00:14:36,000
And again they are with vectors.

279
00:14:36,000 --> 00:14:38,000
Also you can convert into vectors and you can also do it.

280
00:14:38,000 --> 00:14:41,000
So here you will be able to see that I'll be getting okay.

281
00:14:41,000 --> 00:14:43,000
This is this much score.

282
00:14:43,000 --> 00:14:45,000
And this is over here 1.571.5.

283
00:14:45,000 --> 00:14:47,000
Name whichever is the nearest.

284
00:14:47,000 --> 00:14:54,000
I think it uses a distance metric to calculate the sentence and the words okay, whichever is the nearest.

285
00:14:54,000 --> 00:14:57,000
So .93 is the nearest, then 1.57.

286
00:14:57,000 --> 00:14:59,000
After that you are able to get this.

287
00:14:59,000 --> 00:15:01,000
Then 1.591.66 okay.

288
00:15:01,000 --> 00:15:05,000
So in short this is about vector stores where you are able to do it.

289
00:15:05,000 --> 00:15:12,000
Now let's do one thing and let's talk about one very important thing which is called as retrievers.

290
00:15:13,000 --> 00:15:13,000
Okay.

291
00:15:14,000 --> 00:15:17,000
Now let's worry about this retriever topic.

292
00:15:17,000 --> 00:15:21,000
And I'm just going to put a description over here.

293
00:15:21,000 --> 00:15:22,000
Okay.

294
00:15:22,000 --> 00:15:25,000
So that you have this for the reference.

295
00:15:25,000 --> 00:15:26,000
Let's read this okay.

296
00:15:26,000 --> 00:15:28,000
And then we'll try to understand it.

297
00:15:28,000 --> 00:15:29,000
Lankan vector store object.

298
00:15:29,000 --> 00:15:36,000
Do not subclass runnable and so cannot immediately be integrated into the Lankan expression uh language

299
00:15:36,000 --> 00:15:38,000
chains like LCL right.

300
00:15:38,000 --> 00:15:40,000
RIT Lankan retrievers are runnable.

301
00:15:40,000 --> 00:15:46,000
So they implement a standard set of methods synchronous and asynchronous invoke and batch operation,

302
00:15:46,000 --> 00:15:50,000
and are designed to be incorporated LCL chains.

303
00:15:50,000 --> 00:15:55,000
So vector store, you can see that it cannot be integrated with your entire chain.

304
00:15:55,000 --> 00:15:58,000
That is what this sentence basically say.

305
00:15:58,000 --> 00:16:04,000
The reason is very simple because it is not a subclass of runnable, whereas in the case of retrievers

306
00:16:04,000 --> 00:16:05,000
they are runnables.

307
00:16:05,000 --> 00:16:05,000
Okay.

308
00:16:05,000 --> 00:16:11,000
And this can specifically be integrated right or incorporated with the LCL chain.

309
00:16:11,000 --> 00:16:12,000
LCL chain.

310
00:16:12,000 --> 00:16:15,000
Now what exactly is this long chain retrieval?

311
00:16:15,000 --> 00:16:16,000
It is.

312
00:16:16,000 --> 00:16:20,000
Uh, you can just say it is a standard set of methods which will be able to perform synchronous and

313
00:16:20,000 --> 00:16:22,000
asynchronous invoke and batch operations.

314
00:16:22,000 --> 00:16:30,000
Okay, so if Vector store is not a subclass of runnable, we cannot integrate with long chain.

315
00:16:30,000 --> 00:16:33,000
We cannot integrate with chains by using LCL.

316
00:16:33,000 --> 00:16:39,000
So what do we do is that we have a way, how we can basically convert this vector store into a retriever,

317
00:16:39,000 --> 00:16:43,000
which is a runnable, so that it can be integrated to the LCL chain.

318
00:16:43,000 --> 00:16:44,000
Right.

319
00:16:44,000 --> 00:16:44,000
How to do it?

320
00:16:44,000 --> 00:16:46,000
I will be talking about that.

321
00:16:46,000 --> 00:16:46,000
Okay.

322
00:16:46,000 --> 00:16:53,000
So first of all, what I will do over here is that and then uh, you can see we, we, we can create

323
00:16:53,000 --> 00:16:56,000
a simple version of this ourself without subclassing retriever.

324
00:16:56,000 --> 00:17:00,000
If we choose what we wish to use to retrieve documents, we can create a runnable easily.

325
00:17:00,000 --> 00:17:02,000
Okay, let me just show you.

326
00:17:02,000 --> 00:17:04,000
I know I have spoken about many things over here.

327
00:17:04,000 --> 00:17:10,000
So first of all I'm going and I'll import this from typing import list.

328
00:17:10,000 --> 00:17:10,000
Okay.

329
00:17:10,000 --> 00:17:16,000
This list we will be specifically using this is uh see the list functionality is almost different,

330
00:17:16,000 --> 00:17:18,000
but this is a kind of a different list.

331
00:17:19,000 --> 00:17:21,000
Uh, when compared to the data structure list that we are using.

332
00:17:21,000 --> 00:17:21,000
Okay.

333
00:17:21,000 --> 00:17:31,000
So now I'm going to import from lang chain dot core underscore core dot document import document okay.

334
00:17:31,000 --> 00:17:38,000
So we are going to just import this document lang chain okay.

335
00:17:38,000 --> 00:17:46,000
Then I'm going to go ahead and right from lang chain underscore core dot runnables.

336
00:17:46,000 --> 00:17:53,000
We are just going to import runnable lambda okay.

337
00:17:53,000 --> 00:17:55,000
Runnable lambda.

338
00:17:56,000 --> 00:17:59,000
Now what exactly is this runnable lambda.

339
00:17:59,000 --> 00:17:59,000
Everything.

340
00:17:59,000 --> 00:18:01,000
We will be talking about it okay.

341
00:18:01,000 --> 00:18:09,000
Now see this here we will try to create retriever by two ways one by using this runnable lambda okay.

342
00:18:09,000 --> 00:18:15,000
So here I will go ahead and write retriever is equal to runnable lambda okay.

343
00:18:15,000 --> 00:18:21,000
And here what we can do we can basically go ahead and write vector store dot similarity search okay.

344
00:18:21,000 --> 00:18:25,000
And here we can just say dot bind and give the top top result.

345
00:18:25,000 --> 00:18:28,000
Whichever result you are able to get okay.

346
00:18:28,000 --> 00:18:30,000
Select the top result k is equal to one.

347
00:18:31,000 --> 00:18:33,000
Now I will just go ahead and call this retriever.

348
00:18:33,000 --> 00:18:36,000
I will explain you right what exactly is happening.

349
00:18:36,000 --> 00:18:41,000
Dot batch okay I'll be using a batch function in the retriever okay.

350
00:18:41,000 --> 00:18:43,000
And this is I feel this way.

351
00:18:43,000 --> 00:18:48,000
You should not do it because, uh, the next method that we, uh, I will be talking about how you can

352
00:18:48,000 --> 00:18:50,000
retrieve the data from the vector store.

353
00:18:50,000 --> 00:18:51,000
That will be the best way.

354
00:18:51,000 --> 00:18:54,000
Let's say inside this batch, I give two words.

355
00:18:54,000 --> 00:18:58,000
One is cat and one is shark or dog.

356
00:18:58,000 --> 00:19:00,000
Let's say I'll go ahead and pick dog.

357
00:19:00,000 --> 00:19:04,000
Okay, now what this is going to basically do please see to this.

358
00:19:04,000 --> 00:19:04,000
Okay.

359
00:19:04,000 --> 00:19:06,000
So here I am creating.

360
00:19:06,000 --> 00:19:09,000
This is just like a runnable lambda function okay.

361
00:19:09,000 --> 00:19:15,000
And this function is going to get applied to all the parameters that we are giving inside this particular

362
00:19:15,000 --> 00:19:16,000
batch okay.

363
00:19:16,000 --> 00:19:18,000
Let's say if we give cat over here.

364
00:19:18,000 --> 00:19:18,000
Right.

365
00:19:18,000 --> 00:19:21,000
So first of all it is going to do the vector similarity search on cat.

366
00:19:22,000 --> 00:19:25,000
And whichever will be the topmost result I will get that particular value and it will get displayed.

367
00:19:25,000 --> 00:19:26,000
Then.

368
00:19:26,000 --> 00:19:32,000
Since this is a runnable lambda that basically means a lambda function to execute this runnables then

369
00:19:32,000 --> 00:19:33,000
I will be passing this particular.

370
00:19:33,000 --> 00:19:35,000
This dog parameter will get passed.

371
00:19:35,000 --> 00:19:40,000
Again, the similarity search will be done and based on the similarity search, whichever will be the

372
00:19:40,000 --> 00:19:40,000
top result.

373
00:19:40,000 --> 00:19:41,000
I will be getting that.

374
00:19:41,000 --> 00:19:44,000
Okay, That is what is basically going to happen over here.

375
00:19:44,000 --> 00:19:49,000
Now if I go ahead and execute it here, you can see cats are independent and they often this and this

376
00:19:49,000 --> 00:19:50,000
is my related to dog.

377
00:19:50,000 --> 00:19:54,000
So two content are we have been able to retrieve from the vector store.

378
00:19:54,000 --> 00:19:56,000
So vector store is a DB right.

379
00:19:56,000 --> 00:20:02,000
And we are able to convert this into retrievers just by using this runnable lambda okay.

380
00:20:02,000 --> 00:20:07,000
And what is the mean name of this runnable lambda based on the method that I'm calling, whether it

381
00:20:07,000 --> 00:20:08,000
is invoke or batch.

382
00:20:08,000 --> 00:20:11,000
In batch I can probably call multiple parameters multiple inputs.

383
00:20:11,000 --> 00:20:14,000
It will get executed with respect to the similarity search that we are doing.

384
00:20:14,000 --> 00:20:15,000
Okay.

385
00:20:15,000 --> 00:20:25,000
Now, the second technique that we are going to use over here is something called as vector store implement

386
00:20:25,000 --> 00:20:26,000
as retrieval method.

387
00:20:26,000 --> 00:20:30,000
This will generate a retriever, specifically a vector store retrieval.

388
00:20:30,000 --> 00:20:35,000
This retrieval includes specific search type and search queries.

389
00:20:35,000 --> 00:20:41,000
Arguments attributes that identify what method of the underlying vector to call okay and how to parameterize

390
00:20:41,000 --> 00:20:41,000
them.

391
00:20:41,000 --> 00:20:47,000
Now, this is probably the best way how you can go ahead and query from a vector store, right?

392
00:20:47,000 --> 00:20:49,000
We really need to convert this into a retrieval.

393
00:20:49,000 --> 00:20:54,000
So I will go ahead and write vector store dot as retriever.

394
00:20:54,000 --> 00:20:54,000
Okay.

395
00:20:54,000 --> 00:21:01,000
Now this retriever acts as an interface right to pass or to take any information from the vector store

396
00:21:01,000 --> 00:21:02,000
and give it as a response.

397
00:21:02,000 --> 00:21:02,000
Okay.

398
00:21:02,000 --> 00:21:07,000
So here I will go ahead and give my parameter.

399
00:21:07,000 --> 00:21:08,000
The first parameter will be my search type.

400
00:21:08,000 --> 00:21:12,000
So here you have the functionality of search type and the search type.

401
00:21:12,000 --> 00:21:15,000
Over here I can go ahead and write similarity okay.

402
00:21:15,000 --> 00:21:21,000
Then the search argument search search underscore k w a args.

403
00:21:21,000 --> 00:21:22,000
Okay.

404
00:21:22,000 --> 00:21:27,000
Now this argument specifically I will be mentioning with k colon one.

405
00:21:27,000 --> 00:21:29,000
So this I'm saying hey give the top first result.

406
00:21:29,000 --> 00:21:33,000
See here we have written dot bind with k is equal to one.

407
00:21:33,000 --> 00:21:34,000
Again we are using similarity search.

408
00:21:34,000 --> 00:21:36,000
Here we are giving two parameters over here.

409
00:21:36,000 --> 00:21:40,000
One is search type and one is search underscore k w a args okay.

410
00:21:40,000 --> 00:21:44,000
And finally here you'll be able to see that once I create this retriever.

411
00:21:45,000 --> 00:21:45,000
Okay.

412
00:21:45,000 --> 00:21:49,000
Let's go ahead and create this retriever.

413
00:21:49,000 --> 00:21:53,000
R e t r e v e r is equal to this.

414
00:21:53,000 --> 00:21:58,000
Okay I'm just going to go ahead and write retriever dot batch.

415
00:21:58,000 --> 00:22:01,000
And now I will give the same two words that I've actually given.

416
00:22:01,000 --> 00:22:03,000
One is cat and one is dog.

417
00:22:03,000 --> 00:22:06,000
So this is the next way.

418
00:22:06,000 --> 00:22:09,000
And here is all the information that I am able to get.

419
00:22:09,000 --> 00:22:16,000
Okay, so this is how you can go ahead and probably use any of this with respect to, uh, you know,

420
00:22:16,000 --> 00:22:17,000
implementing things.

421
00:22:17,000 --> 00:22:18,000
Okay.

422
00:22:18,000 --> 00:22:21,000
And this is how you can actually go ahead and work with it.

423
00:22:21,000 --> 00:22:21,000
Right.

424
00:22:21,000 --> 00:22:23,000
So here we have store.

425
00:22:23,000 --> 00:22:27,000
We have basically what we have actually done is that we have taken a document content.

426
00:22:27,000 --> 00:22:29,000
This may be coming from a PDF.

427
00:22:29,000 --> 00:22:31,000
It may be coming from any website and all.

428
00:22:31,000 --> 00:22:33,000
We have converted this into a vector store.

429
00:22:33,000 --> 00:22:36,000
And finally, with the help of retriever we are able to get the response.

430
00:22:36,000 --> 00:22:42,000
Okay, so uh, this was mostly about all the things that we have actually discussed till here, right

431
00:22:42,000 --> 00:22:42,000
now.

432
00:22:43,000 --> 00:22:46,000
Um, I hope you were able to understand this.

433
00:22:46,000 --> 00:22:47,000
Okay.

434
00:22:47,000 --> 00:22:53,000
Now, one final thing that I really want to show you is that how we can integrate this retriever along

435
00:22:53,000 --> 00:22:53,000
with the chain.

436
00:22:53,000 --> 00:22:55,000
Okay, So guys let's go ahead.

437
00:22:55,000 --> 00:22:58,000
And here I will be putting up some information.

438
00:22:58,000 --> 00:23:02,000
Let's say this is my chat prompt template.

439
00:23:02,000 --> 00:23:04,000
And this is my runnable pass through.

440
00:23:04,000 --> 00:23:08,000
This is the basic uh, prompt that I'm actually trying to create.

441
00:23:08,000 --> 00:23:11,000
Answer this question using the provided context only.

442
00:23:11,000 --> 00:23:11,000
Right.

443
00:23:11,000 --> 00:23:15,000
And this particular context, uh, needs to be filled by the vector store.

444
00:23:15,000 --> 00:23:16,000
Right.

445
00:23:16,000 --> 00:23:18,000
And this is the question that what user is going to give.

446
00:23:18,000 --> 00:23:19,000
Okay.

447
00:23:19,000 --> 00:23:23,000
So here what I will do I will go ahead and create my prompt quickly.

448
00:23:23,000 --> 00:23:24,000
So this will basically be my prompt.

449
00:23:24,000 --> 00:23:26,000
And we have discussed all these things earlier also.

450
00:23:26,000 --> 00:23:26,000
Right.

451
00:23:26,000 --> 00:23:31,000
So chat prompt template dot from message and human message I'm giving the message whatever message we

452
00:23:31,000 --> 00:23:32,000
are giving it over here okay.

453
00:23:32,000 --> 00:23:39,000
And uh this message uh I'm just specifically saying that hey, uh, what is the information that I really

454
00:23:39,000 --> 00:23:39,000
want to give?

455
00:23:39,000 --> 00:23:46,000
Okay, so after this, you'll be able to see that, uh, I will go ahead and create this prompt.

456
00:23:46,000 --> 00:23:49,000
And after that I will go ahead and create my entire rack chain.

457
00:23:49,000 --> 00:23:53,000
Now, in order to create this rack chain, how do I pass this retriever?

458
00:23:53,000 --> 00:23:54,000
Right.

459
00:23:54,000 --> 00:23:56,000
How do I pass this retriever along with my chain?

460
00:23:56,000 --> 00:23:59,000
Because now retriever is a type of runnable over there.

461
00:23:59,000 --> 00:24:00,000
It is a subclass of runner.

462
00:24:00,000 --> 00:24:01,000
Uh, it is.

463
00:24:01,000 --> 00:24:03,000
You can just see over here, right.

464
00:24:03,000 --> 00:24:04,000
It is a subclass of, uh.

465
00:24:05,000 --> 00:24:07,000
So here, uh, where it went.

466
00:24:07,000 --> 00:24:07,000
Okay.

467
00:24:07,000 --> 00:24:10,000
So retrievers are runnables, right?

468
00:24:10,000 --> 00:24:12,000
So now it has become a subclass of runnable, right?

469
00:24:12,000 --> 00:24:14,000
So how do we integrate it over here?

470
00:24:14,000 --> 00:24:19,000
So first of all, I will just go ahead and replace whatever context I have written over here.

471
00:24:19,000 --> 00:24:25,000
So instead of this context, I should be getting this entire context from retriever okay.

472
00:24:25,000 --> 00:24:27,000
This retriever will be responsible.

473
00:24:27,000 --> 00:24:31,000
The second parameter that I really want is my question.

474
00:24:31,000 --> 00:24:32,000
Right.

475
00:24:32,000 --> 00:24:35,000
And this particular question will again be in the form of key value pairs.

476
00:24:36,000 --> 00:24:36,000
Right.

477
00:24:36,000 --> 00:24:42,000
And this value what we are basically going to pass, we will go ahead and write runnable pass through.

478
00:24:42,000 --> 00:24:46,000
Runnable pass through basically means we are going to get this particular information in the invoke

479
00:24:46,000 --> 00:24:47,000
method.

480
00:24:47,000 --> 00:24:47,000
Okay.

481
00:24:47,000 --> 00:24:49,000
Then you have prompt.

482
00:24:49,000 --> 00:24:52,000
After this I will go ahead and pass through prompt.

483
00:24:52,000 --> 00:24:53,000
Then my LM model okay.

484
00:24:53,000 --> 00:24:58,000
So so this basically becomes my rank, uh, the entire chain itself.

485
00:24:58,000 --> 00:25:04,000
Now in order to execute it, I will go ahead and write a rag underscore chain dot invoke.

486
00:25:04,000 --> 00:25:04,000
Okay.

487
00:25:04,000 --> 00:25:10,000
And let me just say hey tell me about dogs okay?

488
00:25:10,000 --> 00:25:14,000
And once I get this response I will go ahead and print it.

489
00:25:15,000 --> 00:25:20,000
So print response dot content okay.

490
00:25:20,000 --> 00:25:25,000
So here once I execute this according to the provider context, the dog are great companions known for

491
00:25:25,000 --> 00:25:26,000
their loyalty and friendliness.

492
00:25:26,000 --> 00:25:28,000
So from all the documents we are basically getting this.

493
00:25:28,000 --> 00:25:30,000
Now what we have actually implemented.

494
00:25:30,000 --> 00:25:33,000
This is just a basic rag right?

495
00:25:33,000 --> 00:25:36,000
This is rag retrieval augmented generation.

496
00:25:36,000 --> 00:25:36,000
Right.

497
00:25:36,000 --> 00:25:39,000
So here what we have done we have used chat prompt template.

498
00:25:39,000 --> 00:25:40,000
We have used runnable pass through.

499
00:25:40,000 --> 00:25:42,000
We have created our prompt.

500
00:25:42,000 --> 00:25:43,000
Here we have given two inputs.

501
00:25:43,000 --> 00:25:45,000
One is question and one is context.

502
00:25:45,000 --> 00:25:48,000
This context needs to be replaced by our retriever.

503
00:25:48,000 --> 00:25:52,000
So this retriever if I am writing over here this is basically the information from our vector store.

504
00:25:52,000 --> 00:25:55,000
All the documents will get added over here right.

505
00:25:55,000 --> 00:26:00,000
And finally you'll be able to see that I'm able to also integrate this in the rank rag underscore chain.

506
00:26:01,000 --> 00:26:02,000
Your question will be runnable pass through.

507
00:26:02,000 --> 00:26:06,000
That basically is whatever input I'm actually giving over here that is going to get placed over here.

508
00:26:06,000 --> 00:26:10,000
And then we are going to use prompt and LM to create the long chain.

509
00:26:10,000 --> 00:26:11,000
Finally we get the response.

510
00:26:11,000 --> 00:26:16,000
So I hope you are able to understand and get some idea with respect to vector store retrieval.

511
00:26:16,000 --> 00:26:20,000
And this is the entire thing that we really need to learn.

512
00:26:20,000 --> 00:26:21,000
And these are something basics.

513
00:26:21,000 --> 00:26:27,000
Because later on, once we start building projects you will be able to learn more amazing things.

514
00:26:27,000 --> 00:26:28,000
So yes, this was it from my side.

515
00:26:28,000 --> 00:26:29,000
I hope you liked this particular video.

516
00:26:29,000 --> 00:26:30,000
I'll see you all in the next video.

517
00:26:30,000 --> 00:26:31,000
Thank you.

