CN114896240A - Data retrieval method and device, storage medium and electronic device - Google Patents
Data retrieval method and device, storage medium and electronic device Download PDFInfo
- Publication number
- CN114896240A CN114896240A CN202210340324.4A CN202210340324A CN114896240A CN 114896240 A CN114896240 A CN 114896240A CN 202210340324 A CN202210340324 A CN 202210340324A CN 114896240 A CN114896240 A CN 114896240A
- Authority
- CN
- China
- Prior art keywords
- target
- data
- database
- retrieval
- characteristic data
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 48
- 238000004422 calculation algorithm Methods 0.000 claims abstract description 55
- 238000012545 processing Methods 0.000 claims abstract description 39
- 238000012512 characterization method Methods 0.000 claims abstract description 31
- 238000004590 computer program Methods 0.000 claims description 16
- 238000005259 measurement Methods 0.000 claims description 8
- 238000013500 data storage Methods 0.000 abstract description 2
- 238000013139 quantization Methods 0.000 description 71
- 102100030148 Integrator complex subunit 8 Human genes 0.000 description 42
- 101710092891 Integrator complex subunit 8 Proteins 0.000 description 42
- 239000013598 vector Substances 0.000 description 32
- 238000004364 calculation method Methods 0.000 description 12
- 238000007906 compression Methods 0.000 description 10
- 230000006835 compression Effects 0.000 description 10
- 238000013144 data compression Methods 0.000 description 10
- 230000008569 process Effects 0.000 description 10
- 230000008901 benefit Effects 0.000 description 8
- 230000005540 biological transmission Effects 0.000 description 6
- 238000013135 deep learning Methods 0.000 description 5
- 230000001133 acceleration Effects 0.000 description 4
- 230000000694 effects Effects 0.000 description 4
- 238000001514 detection method Methods 0.000 description 3
- 238000010586 diagram Methods 0.000 description 3
- 238000007667 floating Methods 0.000 description 3
- 238000004891 communication Methods 0.000 description 2
- 238000005516 engineering process Methods 0.000 description 2
- 230000006870 function Effects 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000011002 quantification Methods 0.000 description 2
- 238000012163 sequencing technique Methods 0.000 description 2
- 238000011524 similarity measure Methods 0.000 description 2
- 238000012360 testing method Methods 0.000 description 2
- 101100481876 Danio rerio pbk gene Proteins 0.000 description 1
- 101100481878 Mus musculus Pbk gene Proteins 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000003203 everyday effect Effects 0.000 description 1
- 230000006872 improvement Effects 0.000 description 1
- 238000000691 measurement method Methods 0.000 description 1
- 238000010295 mobile communication Methods 0.000 description 1
- 238000010606 normalization Methods 0.000 description 1
- 238000011160 research Methods 0.000 description 1
- 230000001131 transforming effect Effects 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2237—Vectors, bitmaps or matrices
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/242—Query formulation
- G06F16/2433—Query languages
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
- G06F16/24553—Query execution of query operations
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/248—Presentation of query results
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/22—Matching criteria, e.g. proximity measures
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- Data Mining & Analysis (AREA)
- General Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Computational Linguistics (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Evolutionary Computation (AREA)
- Evolutionary Biology (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Bioinformatics & Computational Biology (AREA)
- Artificial Intelligence (AREA)
- Life Sciences & Earth Sciences (AREA)
- Mathematical Physics (AREA)
- Software Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The embodiment of the invention provides a data retrieval method, a data retrieval device, a storage medium and an electronic device, wherein target data is obtained and used for retrieval in a target database, the target database comprises a first-level target database and a second-level target database, a preset algorithm is adopted to perform characterization processing on the target data to obtain a target characteristic data set, the target characteristic data set comprises first target characteristic data and second target characteristic data, a first retrieval operation is executed in the first-level target database based on the first target characteristic data to obtain a first retrieval result, a second retrieval operation is executed in the second-level target database based on the second target characteristic data and the first retrieval result to obtain a second retrieval result, and the retrieval precision and speed are improved, and reduces data storage costs.
Description
Technical Field
The embodiment of the invention relates to the field of data processing, in particular to a data retrieval method, a data retrieval device, a storage medium and an electronic device.
Background
In the current age of high informatization, media such as a video platform, a social network, an online shopping platform and the like generate massive information such as videos and images every day, and the scale of the media can even be hundreds of billions. The video platform can recommend similar videos according to the watching habits of users, the social network can recommend users who can know according to the relationship network of the users, and the online shopping users hope to search similar commodities according to pictures. In these application scenarios, similar data is retrieved from massive data, thereby leading to two basic problems: how to structurally describe the data and retrieve similar results from massive base database data.
With the development of deep learning in recent years, there has been extensive research on how to structurally describe data generated by the internet, and a large amount of data is used to train a depth model for spatial embedding (embedding) of an image into a high-dimensional feature, and a high-dimensional spatial feature vector is used to represent a picture, which also becomes a common practice of current image retrieval technologies, that is, inputting a picture into a depth model to obtain a characteristic vector with a distinguishing fixed dimension as a structural description of the picture.
The vector retrieval is based on vector data description, and K vectors (K-Nearest Neighbor, KNN) similar to the query vector are retrieved in a given vector data set according to some metric method, and are usually obtained by first calculating similarity and then using a topK sorting algorithm. However, because KNN is too computationally intensive, an Approximate Nearest Neighbor (ANN) method is usually used, but the ANN-based method causes a loss of the retrieval accuracy.
Taking the 512-dimensional vector X as an example, when floating-point data is stored, a storage space of 2KB is occupied, the storage efficiency is about 52.2 ten thousand/GB, for a data set exceeding one hundred million levels, a full memory system cannot be used, and a data compression technology is required to reduce storage overhead at this time. In the past, such as Product Quantization (PQ), the idea of ANN and clustering algorithm is also based on the compression of data, but the data precision is obviously lost at a high compression rate.
As can be seen from the above, on one hand, the ANN method causes a loss of the retrieval accuracy, and on the other hand, the vector data stored in floating point numbers occupy a large amount of storage space, which limits the capacity of the retrieval system, and the existing compression method causes a significant loss of the data accuracy under a high compression rate, thereby affecting the retrieval accuracy.
Therefore, how to effectively improve the storage amount of the data on the premise of not damaging the precision of the data and effectively improve the retrieval precision is a problem which needs to be mainly solved at present.
Disclosure of Invention
The present invention is mainly advantageous in that it provides a data retrieval method, apparatus, storage medium, and electronic apparatus, which improve the accuracy of retrieval by executing the first retrieval operation and the second retrieval operation in the target database.
Another advantage of the present invention is to provide a data retrieval method, apparatus, storage medium, and electronic apparatus, which improve data storage capacity while maintaining data accuracy by performing two-stage quantization operations, i.e., Bit quantization operation and Int8 quantization operation, on the target data and the target database, respectively.
Another advantage of the present invention is to provide a data retrieval method, apparatus, storage medium, and electronic apparatus, which integrate the advantages of two quantization modes by performing two-level quantization operations, i.e., Bit quantization operation and Int8 quantization operation, on the target data and the target database, respectively, thereby effectively improving the retrieval speed.
According to an embodiment of the present invention, a method for data retrieval is provided, including:
acquiring target data, wherein the target data is used for retrieval in a target database, and the target database comprises a first-level target database and a second-level target database;
performing characterization processing on the target data by adopting a preset algorithm to obtain a target characteristic data set, wherein the target characteristic data set comprises first target characteristic data and second target characteristic data;
executing a first retrieval operation in the first-level target database based on the first target characteristic data to obtain a first retrieval result;
and executing a second retrieval operation in the second-level target database based on the second target characteristic data and the first retrieval result to obtain a second retrieval result.
According to an exemplary embodiment of the present invention, the first-stage target database is a database obtained by performing a Bit quantization on an original database, and the second-stage target database is a database obtained by performing an Int8 quantization on the original database.
According to an exemplary embodiment of the present invention, the preset algorithm includes a first algorithm and a second algorithm;
the method for characterizing the target data by adopting a preset algorithm to obtain a target characteristic data set, wherein the target characteristic data set comprises first target characteristic data and second target characteristic data, and comprises the following steps:
performing first characterization processing on the target data by adopting the first algorithm to obtain first target characteristic data;
and performing second characterization processing on the target data by adopting the second algorithm to obtain second target characteristic data.
According to an exemplary embodiment of the invention, the first retrieving operation is a data similarity measurement in hamming distance.
According to an exemplary embodiment of the present invention, based on the second target feature data and the first search result, performing a second search operation in the second-level target database to obtain a second search result, including:
acquiring an index value corresponding to the first retrieval result in the second-level target database based on the first retrieval result to obtain a target index value;
based on the second target feature data and the target index value, executing the second retrieval operation in the second target database according to the cosine distance to obtain a second retrieval result
According to another embodiment of the present invention, a data retrieval apparatus is provided, including:
the system comprises an acquisition module, a search module and a search module, wherein the acquisition module is used for acquiring target data, and the target data is used for searching in a target database, wherein the target database comprises a first-level target database and a second-level target database;
the characteristic processing module is used for performing characteristic processing on the target data by adopting a preset algorithm to obtain a target characteristic data group, wherein the target characteristic data group comprises first target characteristic data and second target characteristic data;
the first retrieval module is used for executing a first retrieval operation in the first-level target database based on the first target characteristic data to obtain a first retrieval result;
and the second retrieval module is used for executing second retrieval operation in the second-level target database based on the second target characteristic data and the first retrieval result to obtain a second retrieval result.
According to an exemplary embodiment of the present invention, the first-stage target database is a database obtained by performing a Bit quantization on an original database, and the second-stage target database is a database obtained by performing an Int8 quantization on the original database.
According to an exemplary embodiment of the present invention, the preset algorithm includes a first algorithm and a second algorithm;
wherein the characterization processing module further comprises:
the first characterization processing unit is used for performing first characterization processing on the target data by adopting the first algorithm to obtain first target characteristic data;
and the second characterization processing unit is used for performing second characterization processing on the target data by adopting the second algorithm to obtain second target characteristic data.
According to a further embodiment of the present invention, there is also provided a computer-readable storage medium having a computer program stored thereon, wherein the computer program is arranged to perform the steps of any of the above method embodiments when executed.
According to yet another embodiment of the present invention, there is also provided an electronic device, including a memory in which a computer program is stored and a processor configured to execute the computer program to perform the steps in any of the above method embodiments.
Drawings
Fig. 1 is a block diagram of a hardware configuration of a mobile terminal of a data retrieval method according to an embodiment of the present invention;
FIG. 2 is a flow chart of a method of data retrieval according to an embodiment of the present invention;
fig. 3 is a block diagram of a data retrieval apparatus according to an embodiment of the present invention.
Detailed Description
Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings in conjunction with the embodiments.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order.
The method embodiments provided in the embodiments of the present application may be executed in a mobile terminal, a computer terminal, or a similar computing device. Taking an example of the present invention running on a mobile terminal, fig. 1 is a block diagram of a hardware structure of the mobile terminal according to a detection method of the present invention. As shown in fig. 1, the mobile terminal may include one or more (only one shown in fig. 1) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), and a memory 104 for storing data, wherein the mobile terminal may further include a transmission device 106 for communication functions and an input-output device 108. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration, and does not limit the structure of the mobile terminal. For example, the mobile terminal may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 may be used to store a computer program, for example, a software program and a module of application software, such as a computer program corresponding to a detection method in the embodiment of the present invention, and the processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, so as to implement the method described above. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the mobile terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used for receiving or transmitting data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a Network adapter (NIC), which can be connected to other Network devices through a base station so as to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used for communicating with the internet in a wireless manner.
In order to better solve the technical problems mentioned in the background art, the invention discloses a data retrieval method, a data retrieval device, a storage medium and an electronic device, and the following embodiments are described in detail one by one.
Referring to fig. 2, fig. 2 is a flowchart illustrating a data retrieval method according to an embodiment of the present disclosure, which specifically includes the following steps:
s202, acquiring target data, wherein the target data are used for retrieval in a target database, and the target database comprises a first-level target database and a second-level target database;
according to an embodiment of the present invention, the target data may be image data, voice data, and text data, and the image data is data that needs to be retrieved in the target database.
It should be noted that the embodiments provided by the present invention are mainly described by taking an application scenario of image retrieval as an example.
According to an embodiment of the present invention, the first-level target database is a database obtained by quantizing an original database by Bit, and the second-level target database is a database obtained by quantizing the original database by Int 8.
According to an embodiment of the present invention, in particular, Bit quantization refers to compressing each Bit of original data into a binary Bit representation, as follows:
after Bit quantization, the floating point numerical value which originally needs to be represented by 4 bytes only needs to be represented by 1/8 bytes, the data compression rate reaches 32, and the storage space occupation is greatly reduced.
And transforming each floating point number of the original data in the original database into a binary Bit representation by using the Bit quantization formula, wherein the compression ratio of the whole data set reaches 32, and the first-stage target database is formed.
According to an embodiment of the invention, specifically, before quantizing the data represented by the original float32, Int8 normalizes the original data in a l2 norm, then counts the value distribution of the normalized data, selects a proper quantization parameter α, makes the quantized data distribution fall between-127 and 128, and performs Int8 quantization on the original data in the original database by using α to obtain the second-level target database even if the precision loss of the quantized value is minimum.
It is worth mentioning that while the Int8 quantization is performed on the original database, vector calculation can be performed by a Single Instruction Multiple Data (SIMD) Instruction of hardware to achieve calculation acceleration.
S204, performing characterization processing on the target data by adopting a preset algorithm to obtain a target characteristic data group, wherein the target characteristic data group comprises first target characteristic data and second target characteristic data;
according to an embodiment of the present invention, the preset algorithm includes a first algorithm and a second algorithm.
According to an embodiment of the present invention, the characterization processing mainly converts the original data into vector data with a feature describing the data structuring through the preset algorithm, that is, converts the original data into the target feature data through the preset algorithm. The result obtained in the characterization processing process is the target feature data, the target feature data is feature vector data with distinguishing fixed dimensions, and the feature vector data can be used as structural description data of the image.
According to an embodiment of the present invention, the step S204 further includes:
s2041, performing first characterization processing on the target data by adopting the first algorithm to obtain first target characteristic data;
according to an embodiment of the present invention, in step S2041, specifically, Bit quantization is performed on the target data by using a first algorithm to obtain the first target feature data, where the first target feature data is used to perform a first search operation in a first-stage target database, that is, the first target feature data is used to perform the first search operation in a database after Bit quantization, where a process of Bit quantization is the same as a process of Bit quantization performed on the target database, and is not described herein again. The first algorithm is a deep learning network model and is used for carrying out Bit quantification on the target data.
S2042, performing second characterization processing on the target data by adopting the second algorithm to obtain second target characteristic data.
According to an embodiment of the present invention, in step S2042, specifically, Int8 quantization is performed on the target data by using a second algorithm to obtain second target feature data, where the second target feature data is used to perform a second retrieval operation in a second-level target database, that is, the second target feature data is used to perform the second retrieval operation in a database after Int8 quantization, where the Int8 quantization process is the same as the Int8 quantization process performed on the target database, and details are not repeated here. Wherein the second algorithm is a deep learning network model for Int8 quantization of the target data.
S206, based on the first target characteristic data, executing a first retrieval operation in the first-level target database to obtain a first retrieval result;
according to an embodiment of the invention, the first retrieving operation is a data similarity measurement in terms of hamming distance.
Wherein the similarity measure refers to calculating similarity distance between different vectors by using a measurement algorithm. In the embodiment of the present invention, hamming distance is used for similarity measurement, i.e. for calculating the similarity distance between the first target feature data and the data contained in the first-level target database.
Wherein the Hamming distance calculation formula is as follows:
wherein x and y represent data vectors, n represents vector dimension, and ∈ represents exclusive or.
Specifically, in step S206, based on the first target feature data, similarity distances between the first target feature data and data included in the first-level target database are calculated according to hamming distances, and the search results are top N sorted according to the similarity distances to obtain the first search result, where the first search result is used as a candidate space subset, and N represents a larger number of candidate space subsets.
It is worth mentioning that, in the step S206, the first target feature data and the first-level target database are both structured description data quantized by Bit.
According to an embodiment of the present invention, when ordering top N, it is preferable that a top N ordering with larger size N be performed to ensure that more target results are included in the first-level search result.
S208, based on the second target feature data and the first retrieval result, executing a second retrieval operation in the second-level target database to obtain a second retrieval result.
According to an embodiment of the present invention, the step S208 includes:
s2081, based on the first retrieval result, obtaining an index value corresponding to the first retrieval result in the second-level target database to obtain a target index value;
s2082, based on the second target feature data and the target index value, executing the second retrieval operation in the second target database according to the cosine distance to obtain the second retrieval result.
According to an embodiment of the present invention, in step S2081, based on the N search results in step S206, index values of the N search results corresponding to the second-level target database are obtained, and N index data values, that is, the target index values, are obtained.
According to an embodiment of the present invention, in step S2082, the cosine distance is a similarity measurement method, wherein the cosine distance calculation formula is:
where x, y represent data vectors and theta represents the angle between the vectors.
Specifically, in step S2082, based on the second target feature data and the target index value, the similarity distance between the second target feature data and the data included in the second-level target database is calculated according to the cosine distance, and the search results are subjected to top K sorting according to the similarity distance to obtain the second search result, where K represents the final number of search results.
It is worth mentioning that in the step S208, the second target feature data and the second-level target database are both structured description data quantified by Int 8.
According to an embodiment of the present invention, in step S2082, when the second search operation is performed in the second target database according to the cosine distance based on the second target feature data and the target index value, the inner product of the two vectors after l2 normalization, that is, the second target feature data and the second-level target database, can be directly calculated according to the cosine distance formula, that is, the cosine similarity between the two vectors is obtained, and since the quantization of Int8 is multiplied by the quantization parameter α, the result needs to be divided by 2 powers of α when calculating the similarity, according to the above steps, the cosine similarity or the cosine distance between the second target feature data and the data included in the second-level target database is obtained.
It is worth mentioning that, through the above steps, using Int8 quantization space search (i.e. searching the target data quantized by Int8 in the target search database quantized by Int 8), it is possible to obtain 4 times of data compression ratio and acceleration effect according to SIMD calculation, and at the same time, it is possible to ensure that there is no loss of search precision. Using the Bit quantization space search (i.e. using the target data after Bit quantization to search in the target search database after Bit quantization), a data compression ratio of 32 times can be obtained and more efficient hamming distance calculation is used, but the search accuracy is slightly reduced. In the embodiment provided by the patent, a two-stage retrieval idea is designed, and the advantages of two quantization modes are integrated, firstly, retrieval is performed in a Bit quantization space, and a top N ordering with a larger N is executed to ensure that more target results are contained in a first-stage retrieval result. And then, searching in an Int8 quantization space, using N search results in the Bit quantization space to correspond to indexes in an Int8 space, and using the N data as a search base library of an Int8 quantization space, thereby greatly reducing the calculation amount of the Int8 quantization space, and finally obtaining cosine similarity in an inner product mode and sequencing top K to obtain a final search result.
It should be noted that in the embodiment provided by the present disclosure, a two-stage search scheme based on the Int8 quantization space and the Bit quantization space is used, where the Int8 quantization compression ratio is relatively low, the precision is not substantially lost, and the Bit quantization compression ratio is high, and the precision is slightly reduced. According to the embodiment provided by the patent, the Bit quantized data is used as the first-level retrieval space, and the Int8 quantized data is used as the second-level retrieval space, so that a high-speed and high-precision two-level retrieval scheme is realized.
It should be noted that, from the perspective of storage compression, table 1 shows the number of vector data (referenced to 2048-dimensional vectors) that can be stored per GB storage space in different data format representations.
Table 1:
as can be seen from table 1, the storage efficiency of the data compressed by Int8 is 4 times that of float32, and the storage efficiency of the data compressed by Bit is 32 times that of float32, so that it can be seen that in this patent embodiment, the storage cost can be greatly reduced by the data compression based on two-stage retrieval of Int8 and Bit.
In order to demonstrate the advantages of the two-level search proposed by an embodiment of the data search method in the present patent in terms of search speed and search accuracy, Index data (the number of base libraries is 76.2 ten thousand) in the google landsearch V2 data set is used as test data, and brute force search and IVF search (Inverted File Index) implemented in the source vector search library faiss are used as comparison results, which are shown in table 2.
Table 2:
as shown in Table 2, the number of test pools was 76.2 ten thousand, the vector length was 2048, and R4@ mAP represents the average accuracy under rank 4. The accuracy is highest under the violent Faiss search, but the speed is very slow. The parameters of the faiss IVF (the number of clusters is 2048, and the number of retrieval blocks np is 100) are set, so that the retrieval precision of the method is basically consistent with that of the second-level retrieval, and the speed of the second-level retrieval is 6 times that of the IVF method under the condition that the retrieval precision is reduced little compared with that of the brute force retrieval, and the comprehensive performance of the second-level retrieval is better.
In summary, the data retrieval method based on the two-level retrieval scheme provided by the embodiment of the present invention has good effects in data compression (and storage), retrieval speed, retrieval accuracy and other aspects, and particularly has obvious advantages under the comprehensive consideration of the three indexes.
The method according to the above embodiments can be implemented by software plus necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
In this embodiment, a data detection apparatus is further provided, and the apparatus is used to implement the foregoing embodiments and preferred embodiments, and the description already made is omitted. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
According to another embodiment of the present invention, referring to fig. 3, there is provided a data retrieval apparatus including:
an obtaining module 30, configured to obtain target data, where the target data is used for retrieval in a target database, where the target database includes a first-level target database and a second-level target database;
according to an embodiment of the present invention, the first-stage target database is a database obtained by performing a Bit quantization on an original database, and the second-stage target database is a database obtained by performing an Int8 quantization on the original database.
It is worth mentioning that while the Int8 quantization is performed on the original database, vector calculation can be performed by a Single Instruction Multiple Data (SIMD) Instruction of hardware to achieve calculation acceleration.
The characterization processing module 40 is configured to perform characterization processing on the target data by using a preset algorithm to obtain a target feature data set, where the target feature data set includes first target feature data and second target feature data;
according to an embodiment of the present invention, the preset algorithm includes a first algorithm and a second algorithm.
According to an embodiment of the present invention, the characterization processing mainly converts the original data into vector data with a feature describing the data structuring through the preset algorithm, that is, converts the original data into the target feature data through the preset algorithm. The result obtained in the characterization processing process is the target feature data, the target feature data is feature vector data with distinguishing fixed dimensions, and the feature vector data can be used as structural description data of the image.
According to an embodiment of the present invention, the characterization processing module 40 further includes:
a first characterizing unit 41, configured to perform first characterizing processing on the target data by using the first algorithm to obtain first target characteristic data;
according to an embodiment of the present invention, the first characterization processing unit 41 may be specifically configured to perform Bit quantization on the target data by using the first algorithm to obtain the first target feature data, where the first target feature data is used to perform a first search operation in a first-stage target database, that is, the first target feature data is used to perform the first search operation in a database after Bit quantization, where a process of Bit quantization is the same as a process of Bit quantization performed on the target database, and is not described herein again. The first algorithm is a deep learning network model and is used for carrying out Bit quantification on the target data.
And the second characterization processing unit 42 is configured to perform second characterization processing on the target data by using the second algorithm to obtain second target characteristic data.
According to an embodiment of the present invention, the second characterization processing unit 42 may be specifically configured to perform Int8 quantization on the target data by using a second algorithm to obtain the second target feature data, where the second target feature data is used to perform a second search operation in a second-level target database, that is, the second target feature data is used to perform the second search operation in the database after Int8 quantization, where a process of Int8 quantization is the same as a process of performing Int8 quantization on the target database, and is not described herein again. Wherein the second algorithm is a deep learning network model for Int8 quantization of the target data.
A first retrieval module 50, configured to execute a first retrieval operation in the first-level target database based on the first target feature data to obtain a first retrieval result;
according to an embodiment of the present invention, the first retrieving operation is a data similarity measurement according to a hamming distance.
Wherein the similarity measure refers to calculating similarity distance between different vectors by using a measurement algorithm. In the embodiment of the present invention, hamming distance is used for similarity measurement, that is, for calculating the similarity distance between the first target feature data and the data contained in the first-level target database.
Specifically, the first retrieval module 50 may be specifically configured to, based on the first target feature data, calculate a similarity distance between the first target feature data and data included in the first-level target database according to a hamming distance, and perform top N sorting on the retrieval results according to the similarity distance to obtain the first retrieval result, where the first retrieval result is used as a candidate space subset, and N represents a larger number of candidate space subsets.
It is worth mentioning that both the first target feature data and the first-level target database are structured description data quantized by Bit.
According to an embodiment of the present invention, when ordering top N, it is preferable that a top N ordering with larger size N be performed to ensure that more target results are included in the first-level search result.
And a second retrieving module 60, configured to execute a second retrieving operation in the second-level target database based on the second target feature data and the first retrieving result, so as to obtain a second retrieving result.
According to an embodiment of the present invention, the second retrieving module 60 further includes:
an index obtaining unit 61, configured to obtain, based on the first search result, an index value corresponding to the first search result in the second-level target database, to obtain a target index value;
the second search result obtaining unit 62 executes the second search operation in the second target database according to the cosine distance based on the second target feature data and the target index value, so as to obtain the second search result.
According to an embodiment of the present invention, based on the N search results, index values corresponding to the N search results in the second-level target database are obtained, so as to obtain N index data values, that is, the target index values.
Specifically, the second search result obtaining unit 62 may be specifically configured to calculate, based on the second target feature data and the target index value, a similarity distance between the second target feature data and data included in the second-level target database by a cosine distance, and perform top K sorting on the search results according to the similarity distance to obtain the second search result, where K represents the number of final search results.
It is worth mentioning that both the second target feature data and the second level target database are structured description data quantified by Int 8.
According to an embodiment of the present invention, when the second retrieval operation is performed in the second target database according to the cosine distance based on the second target feature data and the target index value, for two vectors normalized by l2, that is, the second target feature data and the second-level target database, the cosine distance formula shows that the inner product of the two vectors can be directly calculated, that is, the cosine similarity between the two vectors is obtained, and since the Int8 multiplies the quantization parameter α during quantization, the result needs to be divided by the power of 2 of α during similarity calculation, and according to the above steps, the cosine similarity or the cosine distance between the second target feature data and the data included in the second-level target database is obtained.
It is worth mentioning that, as can be seen from the above embodiments, using Int8 quantization space retrieval (i.e. retrieving the target data quantized with Int8 in the target retrieval database quantized with Int 8), it is possible to obtain 4 times of data compression ratio and acceleration effect of computation per SIMD, while ensuring that there is no loss of retrieval accuracy. Using the Bit quantization space search (i.e. using the target data after Bit quantization to search in the target search database after Bit quantization), a data compression ratio of 32 times can be obtained and more efficient hamming distance calculation is used, but the search accuracy is slightly reduced. In the embodiment provided by the patent, a two-stage retrieval idea is designed, and the advantages of two quantization modes are integrated, firstly, retrieval is performed in a Bit quantization space, and a top N ordering with a larger N is executed to ensure that more target results are contained in a first-stage retrieval result. And then, searching in an Int8 quantization space, using N search results in the Bit quantization space to correspond to indexes in an Int8 space, and using the N data as a search base library of an Int8 quantization space, thereby greatly reducing the calculation amount of the Int8 quantization space, and finally obtaining cosine similarity in an inner product mode and sequencing top K to obtain a final search result.
It should be noted that in the embodiment provided by the present disclosure, a two-stage search scheme based on the Int8 quantization space and the Bit quantization space is used, where the Int8 quantization compression ratio is relatively low, the precision is not substantially lost, and the Bit quantization compression ratio is high, and the precision is slightly reduced. According to the embodiment provided by the patent, the Bit quantized data is used as the first-level retrieval space, and the Int8 quantized data is used as the second-level retrieval space, so that a high-speed and high-precision two-level retrieval scheme is realized. And in the patent embodiment, the storage cost can be greatly reduced by data compression based on two-level retrieval of Int8 and Bit.
To sum up, the data retrieval device based on the two-level retrieval scheme provided by the embodiment of the patent obtains better effects in the aspects of data compression (and storage), retrieval speed, retrieval accuracy and the like, and has obvious advantages particularly under the comprehensive consideration of the three indexes.
Embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program is arranged to perform the steps of any of the above-mentioned method embodiments when executed.
In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to: various media capable of storing computer programs, such as a usb disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk.
Embodiments of the present invention also provide an electronic device comprising a memory having a computer program stored therein and a processor arranged to run the computer program to perform the steps of any of the above method embodiments.
In an exemplary embodiment, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
For specific examples in this embodiment, reference may be made to the examples described in the foregoing embodiments and exemplary implementations, and details of this embodiment are not repeated herein.
It will be apparent to those skilled in the art that the various modules or steps of the invention described above may be implemented using a general purpose computing device, they may be centralized on a single computing device or distributed across a network of computing devices, and they may be implemented using program code executable by the computing devices, such that they may be stored in a memory device and executed by the computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into various integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the principle of the present invention should be included in the protection scope of the present invention.
Claims (10)
1. A method of data retrieval, comprising:
acquiring target data, wherein the target data is used for retrieval in a target database, and the target database comprises a first-level target database and a second-level target database;
performing characterization processing on the target data by adopting a preset algorithm to obtain a target characteristic data set, wherein the target characteristic data set comprises first target characteristic data and second target characteristic data;
executing a first retrieval operation in the first-level target database based on the first target characteristic data to obtain a first retrieval result;
and executing a second retrieval operation in the second-level target database based on the second target characteristic data and the first retrieval result to obtain a second retrieval result.
2. The method of claim 1, wherein the first level target database is a database obtained by quantizing a raw database in Bit, and wherein the second level target database is a database obtained by quantizing the raw database in Int 8.
3. The method of claim 1, wherein the preset algorithm comprises a first algorithm and a second algorithm;
the method for characterizing the target data by adopting a preset algorithm to obtain a target characteristic data set, wherein the target characteristic data set comprises first target characteristic data and second target characteristic data, and comprises the following steps:
performing first characterization processing on the target data by adopting the first algorithm to obtain first target characteristic data;
and performing second characterization processing on the target data by adopting the second algorithm to obtain second target characteristic data.
4. The method of claim 1, wherein the first retrieving operation is a data similarity measurement in hamming distance.
5. The method of claim 1, wherein performing a second search operation in the second-level target database based on the second target feature data and the first search result to obtain a second search result comprises:
acquiring an index value corresponding to the first retrieval result in the second-level target database based on the first retrieval result to obtain a target index value;
and executing the second retrieval operation in the second target database according to the cosine distance based on the second target feature data and the target index value to obtain a second retrieval result.
6. A data retrieval device, comprising:
the system comprises an acquisition module, a search module and a search module, wherein the acquisition module is used for acquiring target data, and the target data is used for searching in a target database, wherein the target database comprises a first-level target database and a second-level target database;
the characteristic processing module is used for carrying out characteristic processing on the target data by adopting a preset algorithm to obtain a target characteristic data set, wherein the target characteristic data set comprises first target characteristic data and second target characteristic data;
the first retrieval module is used for executing a first retrieval operation in the first-level target database based on the first target characteristic data to obtain a first retrieval result;
and the second retrieval module is used for executing second retrieval operation in the second-level target database based on the second target characteristic data and the first retrieval result to obtain a second retrieval result.
7. The apparatus of claim 6, wherein the first level target database is a database obtained by quantizing a raw database in Bit, and wherein the second level target database is a database obtained by quantizing the raw database in Int 8.
8. The apparatus of claim 7, wherein the preset algorithm comprises a first algorithm and a second algorithm;
wherein the characterization processing module further comprises:
the first characterization processing unit is used for performing first characterization processing on the target data by adopting the first algorithm to obtain first target characteristic data;
and the second characterization processing unit is used for performing second characterization processing on the target data by adopting the second algorithm to obtain second target characteristic data.
9. A computer-readable storage medium, in which a computer program is stored, wherein the computer program is arranged to perform the method of any of claims 1 to 5 when executed.
10. An electronic device comprising a memory and a processor, wherein the memory has stored therein a computer program, and wherein the processor is arranged to execute the computer program to perform the method of any of claims 1 to 5.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210340324.4A CN114896240A (en) | 2022-04-02 | 2022-04-02 | Data retrieval method and device, storage medium and electronic device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202210340324.4A CN114896240A (en) | 2022-04-02 | 2022-04-02 | Data retrieval method and device, storage medium and electronic device |
Publications (1)
Publication Number | Publication Date |
---|---|
CN114896240A true CN114896240A (en) | 2022-08-12 |
Family
ID=82714583
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202210340324.4A Pending CN114896240A (en) | 2022-04-02 | 2022-04-02 | Data retrieval method and device, storage medium and electronic device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN114896240A (en) |
Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111767419A (en) * | 2019-05-22 | 2020-10-13 | 北京京东尚科信息技术有限公司 | Picture searching method, device, equipment and computer readable storage medium |
-
2022
- 2022-04-02 CN CN202210340324.4A patent/CN114896240A/en active Pending
Patent Citations (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111767419A (en) * | 2019-05-22 | 2020-10-13 | 北京京东尚科信息技术有限公司 | Picture searching method, device, equipment and computer readable storage medium |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112199375B (en) | Cross-modal data processing method and device, storage medium and electronic device | |
CN105912611B (en) | A kind of fast image retrieval method based on CNN | |
Duan et al. | Overview of the MPEG-CDVS standard | |
US9256693B2 (en) | Recommendation system with metric transformation | |
US9256617B2 (en) | Apparatus and method for performing visual search | |
KR101565265B1 (en) | Coding of feature location information | |
CN111368133B (en) | Method and device for establishing index table of video library, server and storage medium | |
CN111177438B (en) | Image characteristic value searching method and device, electronic equipment and storage medium | |
US20140310314A1 (en) | Matching performance and compression efficiency with descriptor code segment collision probability optimization | |
US20200118033A1 (en) | Method for approximate k-nearest-neighbor search on parallel hardware accelerators | |
KR20220092776A (en) | Apparatus and method for quantizing neural network models | |
CN113869420B (en) | Text recommendation method and related equipment based on contrast learning | |
Zhang et al. | OMCBIR: Offline mobile content-based image retrieval with lightweight CNN optimization | |
CN114238329A (en) | Vector similarity calculation method, device, equipment and storage medium | |
CN111309946B (en) | Established file optimization method and device | |
CN110825902B (en) | Method and device for realizing feature similarity search, electronic equipment and storage medium | |
CN110442749B (en) | Video frame processing method and device | |
CN117648495B (en) | Data pushing method and system based on cloud primary vector data | |
CN113157962B (en) | Image retrieval method, electronic device, and storage medium | |
CN113590898A (en) | Data retrieval method and device, electronic equipment, storage medium and computer product | |
CN114049463A (en) | Binary tree data gridding and grid point data obtaining method and device | |
CN111767419A (en) | Picture searching method, device, equipment and computer readable storage medium | |
CN111767421A (en) | Method, device, electronic equipment and computer readable medium for retrieving image | |
CN115881211B (en) | Protein sequence alignment method, protein sequence alignment device, computer equipment and storage medium | |
CN114398883B (en) | Presentation generation method and device, computer readable storage medium and server |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |