Chúng tôi không thể tìm thấy kết nối internet
Đang cố gắng kết nối lại
Có lỗi xảy ra!
Hãy kiên nhẫn trong khi chúng tôi khắc phục sự cố
Milvus Nhập Dữ Liệu | Tạo Cơ Sở Dữ Liệu, Chỉ Mục, Lược Đồ, Bộ Sưu Tập trong Milvus | Full Code RAG | GenAI
0:04 [Music]
0:07 hello everyone welcome back to my
0:09 YouTube channel in this particular video
0:12 we'll be looking into how we can ingest
0:15 data into a vector database here
0:19 specifically in this particular video we
0:20 are going to use milver Vector database
0:24 into which we are going to feed some
0:25 sort of data the data will be in the
0:28 form of a PDF let me show you that
0:31 particular PDF I'll simply provide you
0:33 the link to that particular PDF in the
0:36 description box so here is the PDF you
0:39 can see the PDF is of around six pages
0:43 first part contains the photosynthesis
0:46 process with the chemical reactions and
0:49 also the different theories behind it
0:52 the second part of the PDF contains
0:54 about the human nervous system in all I
0:56 tried to involve all the different kinds
0:59 of markdown
1:00 stuffs that a PDF can contain and we'll
1:03 be seeing how we can simply feed this
1:06 particular data into the vector DBS so
1:08 without further delay let's start I am
1:11 here inside the VSS code here I have
1:15 simply created a data injection. iynb
1:19 file inside this file we'll be writing
1:21 some sort of code need to make sure that
1:24 whatever libraries we are going to use
1:26 in this particular code all must be
1:29 installed and you know how to install it
1:32 and if you facing any trouble installing
1:34 that you can simply ask me in the
1:35 comment section now since our data is in
1:39 the form of PDF we'll have to first
1:41 extract the content in that particular
1:44 from that particular PDF so that we can
1:46 create chunks out of it and we can
1:47 simply put it in the vector DB so for
1:50 that particular thing I'm using Lang
1:53 chains P PDF
1:56 loader you can use your own custom
1:59 document
2:01 loader but for now our goal is just to
2:04 have a look at how we can simply push
2:07 the data into the vector DBS so that is
2:10 why I'm using the Lang Chain by PDF
2:13 loader so for that I'm simply going to
2:15 write from Lang chain do document
2:20 loaders we'll simply import the P
2:25 PDF loader
2:31 so let's create an instance of this
2:33 particular Pi PDF
2:36 loader inside this you just have to pass
2:38 in the path to your PDF
2:43 file and then we'll simply load this
2:46 particular loader so let's do that
2:50 loader dot load and let's try to print
2:54 the document variable and have a look at
2:57 here that it loads the content page wise
3:01 see page 1 page two page three and so on
3:05 and also there is an advantage that here
3:07 the P PDF loader will automatically
3:09 convert the content into a document
3:12 object now if you want to know about
3:14 document object you will have to have a
3:16 look at the chunking strategies that I
3:19 have explained earlier in this
3:21 particular generative AI playlist so I
3:23 would recommend you to First have a look
3:25 at it now in this document object you
3:27 can see with the page content we also
3:30 have the metadata now over here inside
3:33 the metadata we can clearly see we have
3:35 the source and the page source is what
3:38 you put inside the path in the P PDF
3:40 loader and the page is the by default
3:43 the page numbers that are present inside
3:46 our PDF now out of the chunking
3:48 strategies I'm going to use the
3:51 recursive character text splitter
3:53 strategy in this particular video so let
3:56 me write the code for
3:57 it from Lang chain dot text splitter
4:03 we'll simply import the recursive
4:06 character text
4:09 splitter and then we'll create an
4:11 instance of it so text
4:17 splitter recursive character text
4:19 spitter and inside this we'll simply
4:21 pass in
4:23 the parameters that is the chunk
4:27 size let's keep it 1,000 and then the
4:31 chunk
4:35 overlap let's keep it
4:38 200 now it is recommended that your
4:41 chunk overlap should be at least
4:45 20% to your chunk size but you can play
4:48 with the values as per your use case now
4:51 once we create the object we'll simply
4:53 create
4:55 chunks so let's define the variable
4:57 chunks and inside this we'll use the
5:00 instance text splitter dot split
5:03 documents now over here we are using the
5:05 split documents function because we
5:07 already have all our data in the
5:10 document object inside this we'll pass
5:14 the document variable inside which we
5:17 have the entire
5:19 data so this is just for displaying
5:22 purpose for Chunk in
5:26 chunks I'll simply print each chunk so
5:29 that you can clearly see how it has got
5:33 created and then I'll simply put a
5:35 separator over here so let's execute
5:38 this and here you can see that we have
5:41 got our
5:42 chunks here you can see that this is our
5:47 very first chunk this is the page
5:49 content and this is the metadata of
5:52 it similarly we have similarly we have
5:57 the other chunks
5:59 so I'll simply open the text editor over
6:02 here and here you can see the different
6:05 chunks that has got created so now that
6:07 we have got our chunks now the next step
6:09 is to convert this chunks that is the
6:12 textual data into the embedding data now
6:16 we can simply do that with the help of
6:17 an embedding model we are going to use
6:20 an open- Source embedding model from
6:23 hugging face the model that we are going
6:25 to use is the is from Alibaba NLP the
6:29 name of the model is GTE large using
6:32 that model we'll simply write this
6:33 particular code from sentence
6:37 Transformers
6:39 input sentence
6:42 Transformer now we'll create an instance
6:45 of our embedding model that is the
6:47 variable embedding inside which we'll
6:50 call this particular module sentence
6:52 Transformer here you need to pass in the
6:55 model name here the model that I'm using
6:58 it is this
7:00 so I have just pasted the path to that
7:02 particular
7:03 model that I have got from hugging face
7:06 I'll simply put in the link in the
7:07 description box just passing the second
7:10 parameter that is trust remote code
7:13 equals true and you can simply execute
7:16 this particular cell and your embedding
7:19 model will get loaded for the very first
7:21 time if you are executing this cell it
7:23 will take some time so have some
7:25 patience now that our model is loaded
7:28 we'll simply test it so we will try to
7:31 create embedding of one sentence so
7:34 we'll use the encode function inside the
7:37 embedding object and inside this we pass
7:40 in some
7:42 text so I'll write my name is Yash and
7:46 I'll simply execute
7:52 this so here you can see we have gotten
7:56 the embeddings of this particular text
8:00 let me check the length of the embedding
8:03 that is
8:06 created here you can see the dimensions
8:08 are
8:10 1024 so it captures the semantics nicely
8:14 so now that we are ready with our
8:17 embedding model as well as we are ready
8:19 with the chunks that we are going to
8:21 feed into the vector DB let's now
8:24 connect to our Vector database and write
8:26 the piece of code to push this
8:28 particular data into the vector
8:32 DB so as I said I'm going to use milus
8:36 Vector DB so make sure your Milas is in
8:39 running state if you have used if you're
8:41 using Milas using Docker then make sure
8:43 the instance is running and to have a
8:45 look at the insights of milw you can
8:46 simply use this ATU UI if you want the
8:49 setup of ATU as well as milers then you
8:51 can simply have a look at it from the
8:53 generative AI playlist I have explained
8:56 there step by step how you can set up a
8:59 two as well as Milas onto your local
9:02 system so now that we are connected to
9:04 our database we will now push the data
9:07 into the mils DB now you store data in
9:10 mils in the form of documents they are
9:13 also termed as chunks now the chunks are
9:17 stored inside the
9:20 collection you can just imagine a
9:22 collection as a table inside the SQL
9:26 database and this particular collection
9:29 inside the milus is stored in a database
9:33 you can imagine the hierarchy first
9:35 comes the database then comes the
9:37 collection inside it and inside the
9:39 collection you can have multiple
9:41 documents now the collection has a
9:45 particular
9:46 schema that is what all Fields it
9:50 includes there is one single compulsory
9:52 field that is the vector
9:55 embeddings and that is why this Vector
9:58 DBS are termed as Vector DBS and not
10:01 only DBS because there is a special
10:04 field called as Vector embeddings inside
10:06 it so that one field is
10:09 compulsory apart from that we can have
10:11 multiple other
10:13 fields we'll have a look at it once we
10:16 push the data inside it so as for the
10:18 hierarchy that I have told you first
10:20 comes the database so very first thing
10:23 that we have to do is to create a
10:24 database first so for creating a
10:27 database we'll first have to utilize the
10:30 pus Library so I'll simply write the
10:32 code from
10:35 pus we will simply import the
10:41 connections then we'll also import the
10:43 BB and then we'll also import the
10:48 utility so first we'll create connection
10:51 with the help of the
10:53 connections so we'll write connections
10:56 do connect and inside this we'll simply
10:59 pass on the host and the port onto which
11:01 our milver instance is running so the
11:04 host is the Local Host we can simply
11:07 write Local Host here and then the port
11:11 is the default Port of milis that is
11:16 19530 so over here you can see the
11:18 connection has got established because
11:20 our milis instance is running
11:23 successfully now we will check the
11:25 available databases so I can simply
11:28 write DB do
11:29 list
11:31 database and execute this so over here
11:34 you can see there is one single default
11:36 database now we'll be creating one
11:38 database and to create a database you
11:41 have this particular simple function
11:43 called as create database so let's
11:46 write
11:48 db. create
11:50 database and inside this we'll simply
11:53 specify the name of the
11:54 database so let's say the database name
11:57 is first
12:02 DB and we can simply execute this so our
12:06 database has got created now again if we
12:09 try to run this particular db. list
12:12 database command we'll be getting the
12:15 database first
12:17 DB also you can have a look at the atto
12:20 interface so I'll simply log out from
12:22 here and I'll simply login again and you
12:25 can now see we have the first DB
12:28 database that is created whatever
12:30 changes or whatever data we are going to
12:32 push in the vector database we are going
12:34 to do it inside the first DB only so
12:38 that is why we'll simply point the first
12:40 DB as the current database so for doing
12:43 that we'll write DB dot using database
12:49 and inside this we'll simply specify the
12:51 name of the first DB database that we
12:54 want to be used currently let's execute
12:58 this now to check the list of
13:00 collections inside this particular first
13:02 DB database we can simply use the
13:05 utility dot list collections
13:10 function and with this you can get the
13:12 list of collections currently our first
13:15 DB database is empty that is why there
13:18 are no collections inside it there is a
13:20 procedure to create a collection because
13:23 collection contains certain specific
13:25 schema we'll have to define the schema
13:28 fields we'll have to define the
13:30 parameters every single field should
13:34 contain and then we can simply create
13:37 the collection so let's have a look at
13:39 it now now we'll be creating our schema
13:42 now as I said that schema is the
13:44 structure of our collection it defines
13:48 the different fields that it involves as
13:51 well as types of the each field is
13:55 specified at the time of creation of it
13:57 so we are going to create a schema now
14:00 now taking a look at the data that we
14:02 have over here you can see we have three
14:05 things to store the very first is the
14:07 page content that is by default what we
14:09 have to store we are going to store the
14:11 embeddings of these page
14:14 contents next thing that we want to
14:16 store is the source of this
14:19 particular document the source is
14:22 nothing but the path from which this
14:24 particular document has got retrieved
14:27 and then the page
14:29 that is nothing but an integer value at
14:31 what page it is exactly
14:35 located so now that we know that we have
14:38 to store three different things we'll
14:40 simply specify three different
14:42 variables so our very first field will
14:45 be the source
14:48 field so let's write Source
14:53 field and to create and to create fields
14:56 we have the inbuilt functionalities
14:59 inside the P milers that is nothing but
15:02 field
15:04 schema so we'll simply import from P
15:07 milver I'm simply adding on
15:11 this field schema then we'll also use
15:15 the data type and then we'll use the
15:19 collection as well as
15:21 the collection
15:23 schema let's run this
15:27 again and now we can simply use the
15:30 field schema field schema attribute is
15:32 used to create a field it is used to
15:36 define the structure of the field so
15:39 inside this we'll pass on
15:42 the different parameters first is the
15:47 name so name of this field will be
15:51 Source whatever you specify here the
15:54 same will be reflected into the Milas
15:57 collection next thing
16:00 is the D type that is the data type here
16:03 we are going to use the data
16:06 type string because our source is
16:10 nothing but the path and a path is
16:13 always a
16:14 string so we can specify the max length
16:18 parameter and let's set this to
16:22 255 then we can also specify the
16:24 description of this particular Source
16:26 field but for now I don't want to
16:28 specify it so I won't so I won't use it
16:32 then I will also write the is primary
16:37 field I'll set it to
16:42 false because I don't want this Source
16:45 field to be a primary key similarly
16:47 we'll be specifying two more such Fields
16:50 the second field that we are going to
16:52 specify over here is the Page
16:57 Field now the name would be
17:01 page the data type would be integer with
17:06 64 bit I don't want to specify these
17:10 parameters now we'll specify the main
17:12 field that is embedding
17:17 field let's name this as embeddings the
17:20 data type would be float
17:23 Vector here we have to specify the
17:26 dimensions so we can specify it with the
17:28 help of the parameter dim and we will
17:31 specify 1024 as the dimensions because
17:34 our embedding model generates the
17:36 embeddings with the dimension of
17:39 1024 now with this embedding field if
17:42 you want to store the original data in
17:45 the form of text that is the page
17:46 content then you can also specify one
17:48 more field of storing the actual textual
17:52 data that is the
17:54 content so we'll specify the field
17:57 content field
18:01 in we will name this as the
18:04 content we'll keep the data type as
18:07 string because the content is in the
18:10 form of string and then we can specify
18:13 the max length over here let's specify
18:17 it
18:19 as 2048 you can specify as per your
18:25 wish so now we have defined all the
18:28 variables into which we have defined the
18:31 schema of every single field now to
18:35 create one single structure we'll use
18:37 the collection schema now over here
18:41 let's Define a variable
18:43 schema and here I'm going to call the
18:45 collection schema from pus inside which
18:49 we'll have to specify
18:51 fields in a
18:54 list inside this list I'll be specifying
18:57 all the fields that I have created ated
18:59 earlier that is the source field then
19:02 the peach
19:04 field then comes the embedding
19:08 field and lastly comes the content
19:13 field now make sure about the
19:17 order here as a second parameter I can
19:20 also specify description but for now I'm
19:23 keeping it empty now let's try to
19:25 execute
19:26 this okay so we have got one exception
19:29 that is primary key exception we haven't
19:32 specified any primary key field if you
19:35 know every single collection should have
19:37 a primary key field to uniquely identify
19:40 a particular row so we haven't specified
19:42 that yet so let's do that first so here
19:45 we'll specify an ID field which will act
19:49 as a primary key so let's name it as ID
19:53 field the name of the feied will be ID
19:57 the data type will be
19:59 integer 64
20:03 bits let's keep it is primary as true
20:08 and then we will set it as Auto ID
20:11 equals to true now this Auto ID equals
20:13 to True will create an ID according to
20:17 the data type that we have specified
20:21 automatically and then we'll also store
20:24 this particular ID field in the fields
20:27 list inside the collection
20:29 schema now it should work let's try to
20:32 execute
20:33 this so over here you can see we have
20:37 successfully created our schema
20:39 object let's Define a variable
20:41 collection and we'll use the collection
20:44 class inside the pus we'll specify the
20:48 name of the collection as SS and then
20:52 we'll set the schema of this particular
20:54 collection with the schema variable
20:57 inside which we have defined our schema
21:01 of our collection let's try to execute
21:03 this okay we have got an error saying
21:06 that string data type not yet supported
21:09 please use whereare type instead okay so
21:13 here instead of using string data type
21:16 we'll simply use the
21:21 whereare so let's execute this cell
21:24 again to create the
21:25 schema and after that we'll simply
21:27 execute this cell of creating
21:30 collection now you can see that our
21:32 collection has got created now just to
21:35 check whether it has got created
21:36 successfully we can simply check this
21:38 using this particular function that is
21:42 utility. list
21:46 collections you can see our science
21:48 collection has got created successfully
21:52 collection. load let's execute this okay
21:56 so after executing this we are getting
21:59 exception stating that index is not
22:01 found now what is an index now inside a
22:05 vector
22:06 database it stores the document in a
22:08 particular format it stores it in a
22:11 particular structure so that whenever we
22:14 try to retrieve it or we are try to
22:16 perform query search operation it will
22:19 optimally search for that particular
22:21 relevant
22:23 documents which is the closest to that
22:25 particular query we have already closely
22:27 seen how an index works I have already
22:31 explained what are indexes in Vector DBS
22:34 as well as what exactly are the
22:37 different types of indexes I have also
22:39 explained you the mathematical intution
22:41 behind the working of hnsw and the other
22:45 types of indexing in the generative AI
22:48 playlist you can have a look at it so
22:51 inside a vector DB you will have to
22:53 create an index and that is why whenever
22:55 I'm trying to load the collection it is
22:58 throwing me this particular exception so
23:00 first we'll have to create an index we
23:02 are going to create an index with the
23:04 help of hnsw
23:06 algorithm so you don't have to worry
23:08 about it everything is inbuilt in here
23:11 we just have to call it and set the
23:14 parameters so for creating an index
23:17 we'll have to first set the index
23:22 parameters so I'll be creating a
23:25 dictionary inside which
23:29 inside which I will put all the
23:32 necessary parameters so first I will set
23:36 the metric
23:38 type so matric type is a parameter which
23:42 tells on what basis you want to perform
23:45 the query search on the basis of
23:47 similarity or on the basis of distance I
23:50 will use the ukian distance that is L2
23:54 for more different types of metrics you
23:57 can have a look at it in the official
23:59 documentation of Milas I will simply
24:02 post the link to that documentation in
24:04 the description box then we'll
24:07 specify the index
24:10 type now I'm specifying
24:12 hnsw that is hierarchical navigable
24:15 small world next I will
24:17 include a subd
24:20 dictionary inside this dictionary which
24:23 will state the parameters to this
24:25 particular index
24:27 type so so the key will be params and
24:30 the value will be a
24:32 dictionary inside this I
24:34 will state the M value that is the
24:39 number of neighboring links I will set
24:41 this to 16 and then the next parameter
24:44 is EF
24:47 construction I will set this to 200 now
24:50 we are done with specifying the index
24:52 params now we'll execute this now we'll
24:55 simply create an index so we will write
24:59 collection do create index now this
25:03 collection variable contains the
25:04 collection that we have created earlier
25:07 which contains the specified
25:09 schema now we'll create an index inside
25:12 this we'll simply specify the field name
25:16 onto which we have to apply this
25:18 particular index the field name is
25:23 embeddings next inside this we'll pass
25:25 on the index params as the index
25:30 parameters that we have defined in a
25:32 dictionary so we'll specify it now let's
25:35 try to execute this
25:38 cell so here you can see we have
25:40 successfully created our index to this
25:43 particular field
25:45 edings now let's try to load this
25:47 particular
25:52 collection now you can see our
25:54 collection has got loaded successfully
25:57 now let's go into the at two interface
25:59 and have a look at whether our
26:01 collection is getting reflected or not
26:04 so now you can see over here inside the
26:06 first DB database you can simply see the
26:10 collection signs that has got created
26:13 now if you look inside this particular
26:14 collection you can
26:17 see that this is the specified schema
26:20 the ID it is the type it is of the type
26:24 integer 64bit we have the source we have
26:27 the page we have embeddings we have the
26:30 content we have all this and you can see
26:33 clearly that the field embeddings has
26:36 the index type as
26:38 hnsw the metric type is L2 that we
26:41 specified in the index params the M
26:44 value is 16 and the EF construction
26:47 value is 200 if you look at the data tab
26:51 over here particular collection is empty
26:54 now we'll try to push the chunks that we
26:57 have created in into this particular
26:59 collection you need to make sure that
27:01 whenever you are going to push the
27:02 content into the collection the data
27:06 that you going to push it should be in
27:08 the same order it should be of the same
27:12 type as well as it should be of the same
27:14 format that is specified while creating
27:17 the fields of the collection we have our
27:20 data in the variable
27:23 chunks from this what we want we want
27:26 Source we want page number we want the
27:29 page content as well as we also have to
27:31 create the embeddings of this page
27:34 content so we'll require four variables
27:36 so let's create all the four variables
27:39 so the first is
27:41 source so what we can do is we can
27:43 simply create a list of all the sources
27:47 that we have in this particular order
27:50 from all the
27:51 chunks so I will write using the list
27:54 comprehension for Chunk in chunks now
27:58 what I want from each chunk I want the
28:03 chunk do metadata because this source is
28:07 present inside the metadata
28:09 field and inside this I want only
28:13 the source
28:15 attribute so I will get list of all the
28:20 sources in the same order in which these
28:23 chunks are
28:25 present similarly I'll fetch the Pages
28:29 or I would say the page
28:31 numbers so what I want for Chunk in
28:33 chunks what I want chunk. metad data and
28:37 inside which I want the page so I'll
28:40 specify it over here next what I
28:44 want I want the page
28:49 contents so I will name it as page
28:55 contents and for junk in junks
28:59 I can simply fetch the page content like
29:02 this Dot Page content I'll get the page
29:06 contents of all the chunks in the form
29:09 of a list next what I want is the
29:15 embeddings so I'll specify content
29:18 embeddings here I'll have to create
29:20 embeddings of every single page content
29:23 so how to create an embedding we already
29:25 have loaded the embedding model in the
29:27 variable embedding we can use the we can
29:30 use the encode function and we can pass
29:33 in this particular page
29:35 content inside the inside that encode
29:38 function to get the
29:41 embeddings so we will write embedding
29:44 dot the encode function inside it and
29:47 we'll pass on the chunk. page content
29:51 inside this encode
29:54 function this will make sure that the
29:56 embeddings will be created on of each
29:58 page
29:59 content in one
30:01 dimension and it will be stored in this
30:04 list now let's try to execute this
30:07 particular
30:08 cell it will take some time because our
30:10 embeddings are getting created so you
30:13 can see now this particular cell has got
30:15 executed successfully now let's check
30:18 whether we have got the same thing what
30:19 we have
30:22 expected so over here we have got the
30:25 page contents correctly
30:30 then let's try to check the content
30:36 embeddings yes here we have got an here
30:39 we have got a list of arrays of one
30:42 Dimensions that is nothing but
30:44 embeddings of each and every page
30:46 content let's try to check for the
30:51 pages yes we have got the page numbers
30:53 and let's try to check for the sources
30:56 also
30:59 yes we have got the sources now that we
31:02 are ready with these variables in which
31:04 the data that has to be pushed is ready
31:07 now let's try to write the code with the
31:10 help of which we can simply push this
31:11 data into the milver database now for
31:15 inserting we have a function named
31:18 insert inside the collection object that
31:20 we have
31:21 created so collection do insert now
31:24 inside this we will have to pass on the
31:27 list of variables inside which we have
31:30 the
31:31 data in a list format and make sure it
31:35 is in the same order in which you have
31:37 specified the fields of the collection
31:41 so over here you can see that first we
31:43 have specified The Source field then the
31:46 Page Field then the embedding field and
31:48 then the content field so let's do that
31:52 so first we'll push the
31:54 sources next we'll push the pages which
31:58 contains the page number next we'll push
32:01 the embeddings because our third field
32:04 is
32:05 embeddings and next we'll push the page
32:08 contents which contains the textual data
32:11 of the
32:13 embeddings so let's try to execute this
32:15 particular
32:17 cell here you can see it has got
32:19 successfully executed here the insert
32:22 count is shown that is 10 chunks or I
32:25 would say 10 documents has got inserted
32:28 then here the success count is also
32:30 shown that is 10 all the 10 documents
32:33 has got successfully inserted now let's
32:36 try to check using the at2 interface so
32:38 over here you can see that our data has
32:41 got successfully
32:43 pushed you can see the ID which was an
32:47 autogenerated
32:49 field it has got successfully created
32:51 for each and every
32:53 document then comes the source field
32:56 here whatever path we have specified is
33:00 now successfully over
33:03 here then the Page Field which contains
33:05 the page numbers the embeddings field
33:08 which contains the embeddings of each
33:10 and every document then the page content
33:13 field which contains the content of
33:16 every single embedding over here every
33:19 single thing has got inserted
33:22 successfully so I hope every single
33:24 thing that I have explained you in this
33:26 particular video is crystal clear to you
33:28 all if you guys have any single doubt
33:31 then you can straight away put it in the
33:32 comment section I'll be happy to solve
33:34 it for more such videos do like share
33:37 and subscribe to my channel also hit the
33:39 Bell icon and don't forget to follow me
33:41 on Instagram please join me on telegram
33:44 thanks for watching have a good day
33:46 ahead
33:54 [Music]
0:07 Xin chào mọi người, chào mừng các bạn trở lại với kênh YouTube của mình. Trong video này, chúng ta sẽ cùng tìm hiểu cách đưa dữ liệu vào cơ sở dữ liệu vector.
0:19 Cụ thể, trong video này, chúng ta sẽ sử dụng cơ sở dữ liệu Milvus Vector để đưa dữ liệu vào. Dữ liệu sẽ ở định dạng PDF. Để mình cho các bạn xem file PDF đó nhé. Mình sẽ để link tải file PDF này ở phần mô tả.
0:36 Đây là file PDF. Các bạn có thể thấy nó có khoảng sáu trang. Phần đầu tiên nói về quá trình quang hợp với các phản ứng hóa học và các lý thuyết liên quan.
0:52 Phần thứ hai của file PDF nói về hệ thần kinh của con người. Nói chung, mình đã cố gắng đưa vào tất cả các loại định dạng văn bản khác nhau mà một file PDF có thể có, và chúng ta sẽ xem cách đưa dữ liệu này vào cơ sở dữ liệu vector.
1:08 Không chần chừ nữa, chúng ta bắt đầu thôi. Mình đang ở trong VS Code. Ở đây, mình đã tạo một file "data injection.ipynb". Trong file này, chúng ta sẽ viết code. Các bạn nhớ đảm bảo rằng tất cả các thư viện cần thiết đều đã được cài đặt nhé.
1:32 Nếu các bạn gặp khó khăn trong việc cài đặt, cứ hỏi mình ở phần bình luận. Vì dữ liệu của chúng ta ở dạng PDF, trước tiên chúng ta cần trích xuất nội dung từ file PDF đó để tạo thành các đoạn văn, sau đó mới có thể đưa vào cơ sở dữ liệu vector.
1:50 Để làm việc này, mình sẽ sử dụng PDF loader của Langchain. Các bạn có thể sử dụng trình tải tài liệu tùy chỉnh của riêng mình, nhưng hiện tại, mục tiêu của chúng ta là xem cách đưa dữ liệu vào cơ sở dữ liệu vector, vì vậy mình sẽ sử dụng PDF loader của Langchain.
2:13 Để làm điều đó, mình sẽ viết "from Langchain do document loaders, chúng ta sẽ đơn giản nhập P PDF loader."
2:31 Bây giờ, hãy tạo một phiên bản của PDF loader này. Bên trong, chúng ta sẽ truyền đường dẫn đến file PDF, sau đó tải nó.
2:46 Vậy, hãy làm như sau: "loader dot load" và thử in biến "documents" để xem nó tải nội dung theo từng trang như thế nào.
3:01 Các bạn thấy đấy, trang 1, trang 2, trang 3, v.v. Một ưu điểm nữa là PDF loader sẽ tự động chuyển đổi nội dung thành đối tượng tài liệu.
3:12 Nếu bạn muốn tìm hiểu thêm về đối tượng tài liệu, bạn nên xem các chiến lược phân đoạn mà mình đã giải thích trong danh sách phát AI tạo sinh này. Mình khuyên các bạn nên xem nó trước.
3:25 Trong đối tượng tài liệu này, các bạn có thể thấy, cùng với nội dung trang, chúng ta còn có siêu dữ liệu. Trong siêu dữ liệu này, chúng ta có thể thấy rõ ràng nguồn và nguồn trang là đường dẫn bạn đã đặt trong PDF loader, và trang là số trang mặc định trong file PDF của chúng ta.
3:46 Trong các chiến lược phân đoạn, mình sẽ sử dụng chiến lược phân tách văn bản ký tự đệ quy trong video này.
3:56 Để mình viết code cho nó: "from Langchain dot text splitter, chúng ta sẽ đơn giản nhập trình phân tách văn bản ký tự đệ quy" và sau đó tạo một phiên bản của nó.
4:11 "Trình phân tách văn bản ký tự đệ quy trình phân tách văn bản" và bên trong, chúng ta sẽ truyền các tham số như kích thước đoạn, mình sẽ để là 1000, và đoạn chồng chéo, mình sẽ để là 200.
4:38 Các bạn nên để đoạn chồng chéo ít nhất 20% so với kích thước đoạn, nhưng có thể điều chỉnh các giá trị này tùy theo trường hợp sử dụng của bạn.
4:51 Sau khi tạo đối tượng, chúng ta sẽ tạo các đoạn. Vậy, hãy xác định biến "các đoạn" và bên trong, chúng ta sẽ sử dụng phiên bản "trình phân tách văn bản dot split documents".
5:03 Ở đây, chúng ta sử dụng hàm "split documents" vì chúng ta đã có tất cả dữ liệu trong đối tượng tài liệu. Bên trong, chúng ta sẽ truyền biến "documents" chứa toàn bộ dữ liệu.
5:19 Để hiển thị các đoạn, mình sẽ in từng đoạn để các bạn thấy rõ cách nó được tạo, sau đó mình sẽ đặt một dấu phân cách ở đây.
5:38 Hãy chạy đoạn code này, và các bạn có thể thấy chúng ta đã có các đoạn của mình. Đây là đoạn đầu tiên, đây là nội dung trang và đây là siêu dữ liệu của nó. Tương tự, chúng ta có các đoạn khác.
5:59 Mình sẽ mở trình soạn thảo văn bản ở đây, và các bạn có thể thấy các đoạn khác nhau đã được tạo. Bây giờ chúng ta đã có các đoạn, bước tiếp theo là chuyển đổi các đoạn này, tức là dữ liệu văn bản, thành dữ liệu nhúng.
6:16 Chúng ta có thể làm điều này với sự trợ giúp của một mô hình nhúng. Chúng ta sẽ sử dụng một mô hình nhúng mã nguồn mở từ Hugging Face.
6:23 Mô hình mà chúng ta sẽ sử dụng là từ Alibaba NLP. Tên của mô hình là GTE large. Sử dụng mô hình đó, chúng ta sẽ viết đoạn code này "from sentence Transformers".
6:42 "câu đầu vào Transformer". Bây giờ, chúng ta sẽ tạo một phiên bản của mô hình nhúng, đó là biến "nhúng" bên trong đó chúng ta sẽ gọi mô-đun Transformer câu này.
6:52 Ở đây, bạn cần truyền tên mô hình. Mô hình mà mình đang sử dụng là cái này, vì vậy mình vừa dán đường dẫn đến mô hình đó mà mình đã lấy từ Hugging Face.
7:06 Mình sẽ để link trong phần mô tả. Chỉ cần truyền tham số thứ hai là "trust remote code bằng true" và bạn có thể chạy ô này, mô hình nhúng của bạn sẽ được tải.
7:21 Lần đầu tiên chạy, có thể sẽ mất một chút thời gian, các bạn hãy kiên nhẫn nhé. Bây giờ mô hình của chúng ta đã được tải, chúng ta sẽ kiểm tra nó.
7:28 Chúng ta sẽ thử tạo nhúng của một câu. Chúng ta sẽ sử dụng hàm "encode" bên trong đối tượng "nhúng" và bên trong, chúng ta truyền một đoạn văn bản.
7:42 Mình sẽ viết tên mình là Yash và chạy nó.
7:52 Các bạn có thể thấy chúng ta đã nhận được các nhúng của văn bản này. Để mình kiểm tra độ dài của nhúng được tạo.
8:06 Các bạn có thể thấy kích thước là 1024, vậy là nó nắm bắt ngữ nghĩa khá tốt.
8:14 Bây giờ chúng ta đã sẵn sàng với mô hình nhúng, cũng như các đoạn văn bản mà chúng ta sẽ đưa vào cơ sở dữ liệu vector. Hãy kết nối với cơ sở dữ liệu vector và viết code để đẩy dữ liệu này vào.
8:32 Như mình đã nói, mình sẽ sử dụng Milvus Vector DB, vì vậy hãy đảm bảo Milvus của bạn đang chạy. Nếu bạn đang sử dụng Milvus bằng Docker, hãy đảm bảo phiên bản đang chạy.
8:43 Để xem chi tiết về Milvus, bạn có thể sử dụng giao diện ATU UI. Nếu bạn muốn thiết lập ATU và Milvus, bạn có thể xem hướng dẫn từng bước trong danh sách phát AI tạo sinh của mình.
9:02 Bây giờ chúng ta đã kết nối với cơ sở dữ liệu, chúng ta sẽ đẩy dữ liệu vào Milvus DB. Dữ liệu trong Milvus được lưu trữ dưới dạng tài liệu, hay còn gọi là các đoạn.
9:13 Các đoạn này được lưu trữ bên trong một bộ sưu tập. Bạn có thể hình dung bộ sưu tập như một bảng trong cơ sở dữ liệu SQL. Các bộ sưu tập trong Milvus được lưu trữ trong một cơ sở dữ liệu.
9:33 Bạn có thể hình dung hệ thống phân cấp như sau: Đầu tiên là cơ sở dữ liệu, sau đó là bộ sưu tập bên trong, và bên trong bộ sưu tập, bạn có thể có nhiều tài liệu.
9:41 Mỗi bộ sưu tập có một lược đồ cụ thể, bao gồm tất cả các trường. Có một trường bắt buộc duy nhất là nhúng vector. Đó là lý do tại sao Vector DB được gọi là Vector DB chứ không chỉ là DB, vì có một trường đặc biệt là nhúng vector.
10:06 Trường này là bắt buộc. Ngoài ra, chúng ta có thể có nhiều trường khác. Chúng ta sẽ xem xét chúng sau khi đẩy dữ liệu vào.
10:18 Theo hệ thống phân cấp mình vừa nói, đầu tiên là cơ sở dữ liệu. Vì vậy, việc đầu tiên chúng ta cần làm là tạo một cơ sở dữ liệu.
10:24 Để tạo cơ sở dữ liệu, chúng ta sẽ sử dụng thư viện pymilvus. Mình sẽ viết "from pymilvus". Chúng ta sẽ nhập "connections", sau đó "db" và "utility".
10:48 Đầu tiên, chúng ta sẽ tạo kết nối bằng "connections.connect". Bên trong, chúng ta sẽ truyền máy chủ và cổng mà phiên bản Milvus đang chạy.
11:04 Máy chủ là "localhost". Chúng ta có thể viết "localhost" ở đây, và cổng là cổng mặc định của Milvus, 19530.
11:16 Các bạn có thể thấy kết nối đã được thiết lập vì phiên bản Milvus đang chạy thành công. Bây giờ chúng ta sẽ kiểm tra các cơ sở dữ liệu hiện có.
11:25 Mình sẽ viết "db.list_database()" và chạy nó. Các bạn có thể thấy chỉ có một cơ sở dữ liệu mặc định.
11:36 Bây giờ chúng ta sẽ tạo một cơ sở dữ liệu. Để tạo, chúng ta có hàm "create_database".
11:46 Mình sẽ viết "db.create_database()" và bên trong, chúng ta sẽ chỉ định tên của cơ sở dữ liệu. Ví dụ, tên cơ sở dữ liệu là "first_db".
12:06 Cơ sở dữ liệu của chúng ta đã được tạo. Bây giờ, nếu chúng ta chạy lại lệnh "db.list_database()", chúng ta sẽ thấy cơ sở dữ liệu "first_db".
12:17 Bạn cũng có thể xem trên giao diện ATU. Mình sẽ đăng xuất và đăng nhập lại, và các bạn có thể thấy cơ sở dữ liệu "first_db" đã được tạo.
12:28 Bất kỳ thay đổi hoặc dữ liệu nào chúng ta đẩy vào cơ sở dữ liệu vector, chúng ta sẽ thực hiện bên trong "first_db". Vì vậy, chúng ta sẽ chỉ định "first_db" là cơ sở dữ liệu hiện tại.
12:43 Để làm điều đó, chúng ta sẽ viết "db.using_database()" và bên trong, chúng ta sẽ chỉ định tên cơ sở dữ liệu "first_db" mà chúng ta muốn sử dụng.
12:58 Để kiểm tra danh sách các bộ sưu tập bên trong cơ sở dữ liệu "first_db", chúng ta có thể sử dụng hàm "utility.list_collections()".
13:15 Hiện tại, cơ sở dữ liệu "first_db" của chúng ta trống, vì vậy không có bộ sưu tập nào bên trong. Để tạo một bộ sưu tập, chúng ta cần xác định các trường lược đồ và các tham số của từng trường.
13:25 Chúng ta sẽ phải xác định các trường lược đồ, các tham số mà mọi trường nên chứa, và sau đó chúng ta có thể tạo bộ sưu tập. Chúng ta hãy xem ngay bây giờ.
13:39 Bây giờ chúng ta sẽ tạo lược đồ. Lược đồ là cấu trúc của bộ sưu tập. Nó xác định các trường khác nhau và kiểu dữ liệu của từng trường.
13:55 Kiểu dữ liệu được chỉ định tại thời điểm tạo. Chúng ta sẽ tạo lược đồ ngay bây giờ.
14:00 Xem xét dữ liệu chúng ta có ở đây, chúng ta cần lưu trữ ba thứ: nội dung trang (là thứ chúng ta phải lưu trữ), các nhúng của nội dung trang, nguồn của tài liệu (là đường dẫn từ đó tài liệu được truy xuất), và số trang.
14:35 Vì vậy, chúng ta sẽ chỉ định ba biến khác nhau. Trường đầu tiên là trường nguồn.
14:53 Mình sẽ viết "trường Nguồn". Để tạo các trường, chúng ta có các hàm tích hợp trong pymilvus, đó là "FieldSchema".
15:04 Mình sẽ nhập "FieldSchema", "DataType", "Collection" và "Schema". Chạy lại đoạn code này, và bây giờ chúng ta có thể sử dụng "FieldSchema".
15:32 Thuộc tính "FieldSchema" được sử dụng để tạo một trường và xác định cấu trúc của nó. Bên trong, chúng ta sẽ truyền các tham số khác nhau.
15:47 Đầu tiên là "name", tên của trường này sẽ là "Nguồn". Bất cứ điều gì bạn chỉ định ở đây sẽ được phản ánh trong bộ sưu tập Milvus.
15:57 Tiếp theo là "dtype", kiểu dữ liệu. Ở đây, chúng ta sẽ sử dụng kiểu dữ liệu chuỗi vì nguồn là đường dẫn, và đường dẫn luôn là một chuỗi.
16:14 Chúng ta có thể chỉ định tham số "max_length" và đặt nó thành 255. Chúng ta cũng có thể chỉ định mô tả cho trường "Nguồn", nhưng mình không muốn làm điều đó.
16:32 Mình cũng sẽ viết "is_primary", và đặt nó thành "False" vì mình không muốn trường "Nguồn" là khóa chính. Tương tự, chúng ta sẽ chỉ định thêm hai trường như vậy.
16:50 Trường thứ hai là trường "Trang". Tên sẽ là "trang". Kiểu dữ liệu sẽ là số nguyên 64 bit. Mình không muốn chỉ định các tham số khác.
17:10 Bây giờ chúng ta sẽ chỉ định trường chính, đó là trường "nhúng". Hãy đặt tên là "nhúng". Kiểu dữ liệu sẽ là Vector dấu phẩy động.
17:23 Ở đây, chúng ta phải chỉ định kích thước. Chúng ta có thể chỉ định nó bằng tham số "dim" và đặt là 1024, vì mô hình nhúng của chúng ta tạo ra các nhúng với kích thước 1024.
17:41 Nếu bạn muốn lưu trữ dữ liệu gốc ở dạng văn bản (tức là nội dung trang), bạn có thể chỉ định thêm một trường để lưu trữ dữ liệu văn bản thực tế, đó là "nội dung".
17:54 Chúng ta sẽ chỉ định trường "nội dung" và đặt tên là "nội dung". Kiểu dữ liệu sẽ là chuỗi vì nội dung ở dạng chuỗi, và chúng ta có thể chỉ định độ dài tối đa ở đây.
18:17 Hãy đặt nó là 2048. Bạn có thể chỉ định tùy ý. Bây giờ chúng ta đã xác định tất cả các biến và lược đồ của mọi trường.
18:31 Để tạo một cấu trúc duy nhất, chúng ta sẽ sử dụng "CollectionSchema". Hãy xác định một biến "schema" và gọi "CollectionSchema" từ pymilvus. Bên trong, chúng ta sẽ chỉ định các trường trong một danh sách.
18:54 Bên trong danh sách này, mình sẽ chỉ định tất cả các trường đã tạo trước đó: "trường nguồn", "trường trang", "trường nhúng" và "trường nội dung".
19:13 Hãy chú ý đến thứ tự ở đây. Mình cũng có thể chỉ định mô tả, nhưng hiện tại mình để trống. Hãy thử chạy đoạn code này.
19:26 Chúng ta gặp một ngoại lệ: "ngoại lệ khóa chính". Chúng ta chưa chỉ định bất kỳ trường khóa chính nào. Mọi bộ sưu tập nên có một trường khóa chính để xác định duy nhất một hàng.
19:42 Vì vậy, hãy làm điều đó trước. Chúng ta sẽ chỉ định một trường ID, đóng vai trò là khóa chính. Hãy đặt tên là "trường ID". Tên của trường sẽ là "ID". Kiểu dữ liệu sẽ là số nguyên 64 bit.
20:03 Hãy đặt "is_primary" là "True" và "auto_id" là "True". "auto_id" bằng "True" sẽ tự động tạo một ID theo kiểu dữ liệu đã chỉ định. Chúng ta cũng sẽ lưu trữ trường ID này trong danh sách các trường bên trong "CollectionSchema".
20:29 Bây giờ nó sẽ hoạt động. Hãy thử chạy lại. Các bạn có thể thấy chúng ta đã tạo thành công đối tượng lược đồ.
20:39 Hãy xác định một biến "collection" và sử dụng lớp "Collection" bên trong pymilvus. Chúng ta sẽ chỉ định tên của bộ sưu tập là "SS" và đặt lược đồ của bộ sưu tập này bằng biến "schema", nơi chúng ta đã xác định lược đồ của bộ sưu tập.
21:01 Hãy thử chạy. Chúng ta gặp một lỗi: "Kiểu dữ liệu chuỗi chưa được hỗ trợ. Vui lòng sử dụng VarChar thay thế."
21:13 Thay vì sử dụng kiểu dữ liệu chuỗi, chúng ta sẽ sử dụng "VarChar". Hãy chạy lại ô này để tạo lược đồ, sau đó
21:27 chạy ô này để tạo bộ sưu tập. Bây giờ bạn có thể thấy bộ sưu tập của chúng ta đã được tạo. Để kiểm tra xem nó đã được tạo thành công hay chưa, chúng ta có thể sử dụng hàm "utility.list_collections()".
21:46 Bạn có thể thấy bộ sưu tập "science" của chúng ta đã được tạo thành công. "collection.load()". Hãy chạy nó. Sau khi chạy, chúng ta nhận được ngoại lệ: "Không tìm thấy chỉ mục".
22:01 Chỉ mục là gì? Bên trong một cơ sở dữ liệu vector, tài liệu được lưu trữ ở một định dạng cụ thể, trong một cấu trúc cụ thể. Khi chúng ta cố gắng truy xuất hoặc thực hiện thao tác tìm kiếm, nó sẽ tìm kiếm tối ưu các tài liệu liên quan gần nhất với truy vấn.
22:25 Mình đã xem xét kỹ cách một chỉ mục hoạt động và giải thích về chỉ mục trong Vector DB, cũng như các loại chỉ mục khác nhau. Mình cũng đã giải thích trực giác toán học đằng sau hoạt động của HNSW và các loại lập chỉ mục khác trong danh sách phát AI tạo sinh.
22:51 Các bạn có thể xem nó. Bên trong một DB vector, bạn phải tạo một chỉ mục. Đó là lý do tại sao khi mình cố gắng tải bộ sưu tập, nó báo lỗi.
23:00 Chúng ta sẽ tạo một chỉ mục bằng thuật toán HNSW. Mọi thứ đều được tích hợp ở đây. Chúng ta chỉ cần gọi nó và đặt các tham số.
23:14 Để tạo một chỉ mục, chúng ta sẽ đặt các tham số chỉ mục. Mình sẽ tạo một từ điển và đặt tất cả các tham số cần thiết.
23:32 Đầu tiên, mình sẽ đặt "metric_type". "metric_type" là một tham số cho biết bạn muốn thực hiện tìm kiếm truy vấn dựa trên cơ sở tương tự hoặc khoảng cách.
23:50 Mình sẽ sử dụng khoảng cách Euclidean, đó là L2. Để biết thêm các loại metric khác nhau, bạn có thể xem trong tài liệu chính thức của Milvus. Mình sẽ để link trong phần mô tả.
24:04 Sau đó, chúng ta sẽ chỉ định "index_type". Mình sẽ chỉ định HNSW, Hierarchical Navigable Small World.
24:17 Tiếp theo, mình sẽ bao gồm một từ điển phụ, nêu các tham số cho loại chỉ mục này.
24:27 Khóa sẽ là "params" và giá trị sẽ là một từ điển. Bên trong, mình sẽ nêu giá trị "M", số lượng liên kết lân cận. Mình sẽ đặt nó thành 16, và tham số tiếp theo là "efConstruction".
24:50 Mình sẽ đặt nó thành 200. Bây giờ chúng ta đã hoàn thành việc chỉ định các tham số chỉ mục. Chúng ta sẽ chạy nó. Bây giờ chúng ta sẽ tạo một chỉ mục.
24:55 Mình sẽ viết "collection.create_index()". Biến "collection" này chứa bộ sưu tập mà chúng ta đã tạo trước đó, chứa lược đồ đã chỉ định.
25:09 Chúng ta sẽ tạo một chỉ mục. Bên trong, mình sẽ chỉ định tên trường mà chúng ta phải áp dụng chỉ mục này. Tên trường là "nhúng".
25:23 Tiếp theo, mình sẽ truyền các tham số chỉ mục, là các tham số mà chúng ta đã xác định trong một từ điển.
25:38 Các bạn có thể thấy chúng ta đã tạo thành công chỉ mục cho trường "embeddings". Bây giờ hãy thử tải bộ sưu tập này.
25:52 Bây giờ bạn có thể thấy bộ sưu tập của chúng ta đã được tải thành công. Hãy vào giao diện ATU và xem bộ sưu tập của chúng ta có được hiển thị hay không.
26:04 Bên trong cơ sở dữ liệu "first_db", bạn có thể thấy bộ sưu tập đã được tạo. Nếu bạn nhìn vào bên trong bộ sưu tập này, bạn có thể thấy đây là lược đồ đã chỉ định.
26:20 ID có kiểu số nguyên 64 bit. Chúng ta có nguồn, trang, nhúng và nội dung. Các bạn có thể thấy trường nhúng có loại chỉ mục là HNSW.
26:41 Loại metric là L2, như chúng ta đã chỉ định trong các tham số chỉ mục. Giá trị M là 16 và giá trị efConstruction là 200. Nếu bạn nhìn vào tab dữ liệu, bộ sưu tập này đang trống.
26:54 Bây giờ chúng ta sẽ đẩy các đoạn đã tạo vào bộ sưu tập này. Các bạn cần đảm bảo rằng dữ liệu bạn đẩy vào bộ sưu tập phải theo đúng thứ tự.
27:08 Nó phải có cùng kiểu và định dạng như khi tạo các trường của bộ sưu tập. Chúng ta có dữ liệu trong biến "các đoạn".
27:23 Từ đây, chúng ta muốn gì? Chúng ta muốn nguồn, số trang, nội dung trang và các nhúng của nội dung trang. Vậy, chúng ta cần bốn biến. Hãy tạo chúng.
27:39 Đầu tiên là nguồn. Chúng ta có thể tạo một danh sách tất cả các nguồn theo thứ tự từ tất cả các đoạn.
27:51 Mình sẽ viết bằng cách sử dụng list comprehension: "for Chunk in các đoạn". Mình muốn "Chunk.metadata" vì nguồn nằm trong trường siêu dữ liệu, và mình chỉ muốn nguồn.
28:15 Chúng ta sẽ có các nguồn theo cùng thứ tự với các đoạn. Tương tự, mình sẽ lấy các trang, hay số trang.
28:31 "for Chunk in các đoạn, mình muốn Chunk.metadata và bên trong đó mình muốn trang."
28:40 Tiếp theo, mình muốn nội dung trang. Mình sẽ đặt tên là "nội dung trang" và "for Chunk in các đoạn, mình có thể lấy nội dung trang bằng Chunk.page_content."
29:02 Mình sẽ nhận được nội dung trang của tất cả các đoạn dưới dạng danh sách. Tiếp theo, mình muốn các nhúng.
29:15 Mình sẽ chỉ định "nội dung nhúng". Ở đây, mình sẽ phải tạo các nhúng của mọi nội dung trang.
29:23 Làm thế nào để tạo nhúng? Chúng ta đã tải mô hình nhúng trong biến "nhúng". Chúng ta có thể sử dụng hàm "encode" và truyền nội dung trang vào hàm "encode" đó để nhận các nhúng.
29:41 Mình sẽ viết "nhúng.encode()" và truyền "Chunk.page_content" vào hàm "encode".
29:54 Điều này sẽ đảm bảo rằng các nhúng sẽ được tạo trên mỗi nội dung trang và được lưu trữ trong danh sách. Hãy chạy đoạn code này.
30:08 Sẽ mất một chút thời gian vì các nhúng đang được tạo. Đoạn code này đã được thực thi thành công.
30:15 Bây giờ, hãy kiểm tra xem chúng ta đã nhận được những gì mình mong đợi hay chưa. Chúng ta đã nhận được nội dung trang một cách chính xác.
30:30 Hãy kiểm tra nội dung nhúng. Chúng ta đã nhận được một danh sách các mảng một chiều, đó là các nhúng của từng nội dung trang.
30:46 Hãy kiểm tra các trang. Chúng ta đã nhận được số trang. Kiểm tra các nguồn. Chúng ta đã nhận được các nguồn.
31:00 Bây giờ chúng ta đã sẵn sàng với các biến này, nơi dữ liệu cần đẩy đã sẵn sàng. Hãy viết code để đẩy dữ liệu này vào cơ sở dữ liệu Milvus.
31:15 Để chèn, chúng ta có hàm "insert" bên trong đối tượng bộ sưu tập. "collection.insert()".
31:24 Bên trong, chúng ta sẽ truyền danh sách các biến chứa dữ liệu ở định dạng danh sách, và đảm bảo nó theo đúng thứ tự mà bạn đã chỉ định các trường của bộ sưu tập.
31:41 Chúng ta đã chỉ định "Trường Nguồn", "Trường Trang", "Trường Nhúng" và "Trường Nội dung".
31:52 Đầu tiên, chúng ta sẽ đẩy các nguồn. Tiếp theo, chúng ta sẽ đẩy các trang chứa số trang. Tiếp theo, chúng ta sẽ đẩy các nhúng, và cuối cùng, chúng ta sẽ đẩy nội dung trang chứa dữ liệu văn bản của các nhúng.
32:13 Hãy chạy đoạn code này. Nó đã được thực thi thành công. Số lượng chèn là 10 đoạn, hay 10 tài liệu đã được chèn.
32:28 Số lượng thành công cũng là 10. Tất cả 10 tài liệu đã được chèn thành công. Hãy kiểm tra bằng giao diện ATU.
32:38 Dữ liệu của chúng ta đã được đẩy thành công. ID là một trường tự động tạo. Nó đã được tạo thành công cho từng tài liệu.
32:53 Trường nguồn đã thành công. Trường trang chứa số trang, trường nhúng chứa các nhúng của từng tài liệu.
33:10 Trường nội dung trang chứa nội dung của mọi nhúng. Mọi thứ đã được chèn thành công.
33:22 Mình hy vọng mọi thứ mình đã giải thích trong video này đều rõ ràng với các bạn. Nếu các bạn có bất kỳ nghi ngờ nào, hãy đặt câu hỏi ở phần bình luận. Mình rất vui được giải đáp.
33:34 Để xem thêm các video như vậy, hãy thích, chia sẻ và đăng ký kênh của mình. Nhấn vào biểu tượng Chuông và đừng quên theo dõi mình trên Instagram. Tham gia với mình trên Telegram.
33:44 Cảm ơn đã xem. Chúc các bạn một ngày tốt lành.
33:54 [Âm nhạc]
Dịch Vào Lúc: 2025-03-03T01:02:38Z
Phiên bản Dịch: 3.1 Improved translation step with full context