Data processing method and device
By generating codewords and codebooks with dense matrix structures, the data in the original base library is compressed and encoded, which solves the problem of low retrieval efficiency in large library searches, and achieves efficient data retrieval and calculation speed improvement.
Patent Information
- Application Number
- CN202411275854.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-21
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2043-07-21
AI Technical Summary
In large database search, the retrieval efficiency is low due to the large amount of data stored in the database. Especially when performing search tasks on the acceleration card, all the information data in the database needs to be loaded into the video memory, resulting in low computing efficiency.
Generate an initial codebook, and compress and encode the object data of candidate objects stored in the original base library to generate codebooks and codewords. The codeword structure is a dense matrix, and the retrieval efficiency is improved by using the high computing speed of the dense matrix and the access to continuous memory blocks.
By retrieving the codewords and codebooks after compression and encoding, the search efficiency and computing speed are significantly improved, the data storage needs are reduced, and the memory access speed is improved.
Smart Images

Figure CN119415724B_ABST
Abstract
Description
[0001] This application is a divisional application. The application number of the original application is 202310910436.3, and the original application date is July 21, 2023. The entire content of the original application is incorporated into this application by reference. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to a data processing method and device. Background Art
[0003] The continuous development of computer technology has generated a vast amount of information data. Large-scale database retrieval is the process of retrieving the required data from this vast amount of information data. The process involves obtaining the object data of the query object, searching the information database for information data similar to the query object data, and returning the found information data as the search results.
[0004] A typical problem with large database retrieval is the sheer volume of data stored in the database. For example, a facial feature database can store the facial features of a large number of sample objects. Each sample object corresponds to a high-dimensional facial feature. For example, a sample object's facial features may be 256-dimensional, resulting in a database with a data volume in the billions.
[0005] Large database retrieval is a data-intensive task that generally runs on the accelerator card of the computing device. When performing the retrieval task, the accelerator card needs to load all the information data in the database into the video memory. Due to the large amount of data in the database, the retrieval efficiency is low. Summary of the Invention
[0006] The present application provides a data processing method and device to improve retrieval efficiency.
[0007] In a first aspect, an embodiment of the present application provides a data processing method, which can be specifically executed by a computing device or by a chip inside the computing device, or by a processor in the computing device (exemplarily, the processor can be a central processing unit, an accelerator card, etc.). Taking the execution of a computing device as an example, the method includes: the computing device generates an initial codebook; wherein the structure of the initial codebook is a d*m matrix, the initial codebook includes multiple initial sub-codebooks, the structure of each initial sub-codebook is a d*p matrix, and m is greater than p, p is greater than 1, and d is greater than 1; the computing device generates a codebook for compressing and encoding the object data of the candidate object stored in the original base library according to each initial sub-codebook in the initial codebook, and a codeword after compression encoding; wherein the structure of the codeword is a matrix including multiple codeword blocks, the codeword block includes a first element, and the other positions in the matrix except the multiple codeword blocks are second elements, and each column in the matrix corresponds to a codeword block.
[0008] Through the above design, the computing device generates a codebook and codeword corresponding to the object data corresponding to multiple candidates stored in the original base library based on the initial codebook. Since the codeword is obtained by compressing and encoding the object data of the candidate objects stored in the original base library, the data volume of the codeword is much smaller than the data volume of the object data corresponding to multiple candidates stored in the original base library. During retrieval, retrieval can be performed based on the codeword and codebook obtained by compression encoding, thereby improving retrieval efficiency. In addition, the structure of the codeword is a matrix including multiple codeword blocks. For example, non-zero elements can be concentrated in the codeword blocks, and the codeword block structure is a dense matrix. In this way, when the computing device reads the codeword and performs calculation processing, the calculation speed of the dense matrix is much higher than other calculation forms; and each column in the codeword matrix corresponds to a codeword block, that is, each column in the codeword matrix only includes an area with non-zero elements. Therefore, based on this codeword structure, data can be stored in continuous memory blocks, and continuous memory block access can greatly improve the memory access speed of the computing device.
[0009] In one possible design, when generating the initial codebook, the computing device selects object data of m sample objects from the object data of candidate objects stored in the original base library to form multiple sample sets, where each sample set includes object data of p sample objects; and generates each initial sub-codebook included in the initial codebook based on the object data of the sample objects included in each sample set.
[0010] Through the above design, the computing device generates an initial codebook based on the object data of the sample objects selected from the original base library. This initial codebook generation method makes the obtained initial codebook more accurate.
[0011] In one possible design, when determining the initial sub-codebook corresponding to each sample set, the computing device performs, for any sample set, orthogonal basis initialization on a matrix composed of object data of sample objects included in the sample set to generate the initial sub-codebook corresponding to the sample set.
[0012] Through the above design, the initial sub-codebook obtained by performing an orthogonal basis initialization on the matrix composed of the object data of the sample object can better meet the requirements related to the codebook and improve the accuracy of the generated codebook.
[0013] In one possible design, a computing device determines, based on a subspace distance between object data of each sample object and each initial sub-codebook, a sample object dataset corresponding to each initial sub-codebook; for any initial sub-codebook, generates, based on the sample object dataset corresponding to the initial sub-codebook, an updated sub-codebook and a corresponding codeword block corresponding to the initial sub-codebook; generates a codebook based on the updated sub-codebook corresponding to each initial sub-codebook; and generates a codeword based on the codeword block corresponding to each initial sub-codebook.
[0014] Through the above design, when determining the codebook and codeword, the computing device first determines the sample object data set corresponding to the initial sub-codebook based on the subspace distance between the object data included in the sample set and the initial sub-codebook, so that the object data with high similarity to the initial sub-codebook can be used as a sample object data set, and a new sub-codebook and corresponding codeword blocks are generated by processing the sample object set. In this way, the object data of the candidate objects corresponding to the sub-codebook and the codeword blocks are data with high similarity. Therefore, the codebook and codewords generated in this manner can improve the retrieval efficiency in the subsequent retrieval process.
[0015] In one possible design, the computing device determines, for object data of any sample object, an initial sub-codebook corresponding to the object data of the sample object from multiple initial sub-codebooks based on a subspace distance between the object data of the sample object and each initial sub-codebook; and determines, based on a correspondence between the object data of the sample object and the initial sub-codebooks, a sample object dataset corresponding to each initial sub-codebook, where the sample object dataset includes the object data of the sample object corresponding to the initial sub-codebook.
[0016] Through the above design, the sample object data set corresponding to each initial sub-codebook determined by the computing device includes object data of relatively similar candidate objects. Based on this method, codebooks and codewords are generated, which can improve retrieval efficiency in subsequent retrieval processes.
[0017] In one possible design, when generating a codeword based on the codeword blocks corresponding to each initial sub-codebook, the computing device divides the codeword blocks corresponding to each initial sub-codebook into reference codewords, quantizes the reference codewords, and adjusts elements in the quantized reference codewords to generate the codewords. Exemplarily, the computing device adjusts the elements in the quantized reference codewords such that the structure of the adjusted codeword is a matrix including multiple codeword blocks, where each column in the matrix corresponds to a codeword block.
[0018] Through the above design, the computing device quantizes the reference codewords composed of each codeword block, which can achieve a higher compression rate. In addition, by adjusting the elements in the reference codeword, each column in the adjusted codeword corresponds to a codeword block. The adjusted codeword is a dense matrix, which can improve the computing speed when the computing device calls the codeword.
[0019] In one possible design, the codeword is structured as a block diagonal matrix.
[0020] In one possible design, after receiving a query request, the computing device determines a query vector corresponding to the query request; and retrieves a target object that matches the query request from multiple candidate objects stored in the original database based on the query vector, codeword, and codebook.
[0021] Through the above design, after obtaining the query vector, the computing device searches based on the codeword obtained after compressing and encoding the original object data. The codeword structure is specially designed so that the codeword structure includes multiple block matrices, and each column in the matrix corresponds to a block. The codeword structure is a dense matrix. Since the operation speed of a dense matrix is much higher than other operation forms, the computing device can significantly increase the operation speed during the retrieval process based on this dense codeword matrix, thereby improving the retrieval efficiency. In addition, since each column in the codeword matrix corresponds to a block, that is, each column in the codeword matrix only includes one area with non-zero elements, based on this codeword structure, data can be stored in continuous memory blocks. Continuous memory block access can greatly increase the memory access speed of the computing device, thereby further improving the retrieval efficiency.
[0022] In a possible design, each codeword in the codeword is divided into blocks and stored in different storage areas.
[0023] Through the above design, each codeword block in the codeword structure represents data with high similarity. By storing each codeword block in a different storage area, it is possible to centrally store data with high similarity, facilitating data retrieval in subsequent processes.
[0024] In one possible design, the computing device determines a target storage area based on a query vector and a codebook; and retrieves a target object matching the query request from multiple candidate objects based on codeword blocks stored in the target storage area.
[0025] With this design, when executing the search process, the computing device first determines the target storage area for storing the codeword blocks based on the query vector and the codebook. It then searches within the target storage area for target objects that match the query. This query method significantly improves search efficiency compared to searching across all codeword blocks.
[0026] In one possible design, the codebook includes multiple sub-codebooks, each sub-codebook corresponding to a codeword block; when determining the target storage area, the computing device determines, based on the query vector and the codebook, first similarity information between the query vector and each sub-codebook in the codebook, where the first similarity information is used to represent a degree of similarity between the query vector and the sub-codebook; the computing device determines a target sub-codebook from the multiple sub-codebooks included in the codebook based on the first similarity information between the query vector and each sub-codebook in the codebook; the computing device determines, based on the correspondence between the sub-codebooks and the codeword blocks, a target codeword block corresponding to the target sub-codebook, and uses the storage area storing the target codeword block as the target storage area.
[0027] With the above design, when determining a target storage area from multiple storage areas, the computing device calculates the first similarity information between the query vector and each sub-codebook in the codebook to determine a target sub-codebook with a high similarity to the query vector. Then, based on the correspondence between the sub-codebooks and the codeword blocks, the computing device can determine the storage area storing the codeword blocks corresponding to the target sub-codebook as the target storage area. This design allows the codeword blocks stored in the target storage area to be determined to be most similar to the query vector from among the multiple storage areas, thereby simplifying the retrieval process.
[0028] In one possible design, a computing device determines a product of a query vector and a codebook to obtain an intermediate vector; divides the intermediate vector into sub-intermediate vectors corresponding to each sub-codebook; and determines first similarity information between the query vector and each sub-codebook in the codebook based on the sub-intermediate vectors corresponding to each sub-codebook.
[0029] Through the above design, a solution is provided for accurately determining the first similarity information between the query vector and each sub-codebook in the codebook. Based on this design, the first similarity information between the query vector and each sub-codebook in the codebook can be accurately determined.
[0030] In one possible design, the computing device determines, based on the sub-intermediate vector corresponding to the target sub-codebook and the codeword blocks stored in the target storage area, second similarity information between the query vector and each candidate object corresponding to the codeword block stored in the target storage area, where the second similarity information is used to characterize the degree of similarity between the query vector and the candidate objects corresponding to the codeword blocks stored in the target storage area. The computing device then determines the target object from the candidate objects corresponding to the target sub-codebook based on the second similarity information.
[0031] Through the above design, after determining the target storage area, the computing device calculates the second similarity information between the query vector and the codeword blocks stored in the target storage area, and retrieves the target object that matches the query vector from the candidate objects corresponding to the target storage area; based on the second similarity information, the target object can be accurately retrieved.
[0032] In a second aspect, embodiments of the present application provide a data processing apparatus having the functionality to implement the method described in the first aspect or any possible implementation of the first aspect. The apparatus may be a computing device or a processor included in a computing device. The functionality of the data processing apparatus may be implemented via hardware or via hardware executing corresponding software. The hardware or software may include one or more modules, units, or means corresponding to the functionality described above.
[0033] In one possible implementation, in one possible design, the structure of the device includes an initialization unit and a processing unit. These units can perform the corresponding functions of the computing device in the above-mentioned first aspect method example. For details, please refer to the detailed description in the method example, which is not repeated here.
[0034] In another possible implementation, the apparatus includes a processor and may also include a memory. The processor is coupled to the memory and can be configured to execute computer program instructions stored in the memory, causing the apparatus to perform the method described in the first aspect or any possible implementation of the first aspect. Optionally, the apparatus further includes a communication interface, with the processor coupled to the communication interface. When the apparatus is a computing device, the communication interface may be a transceiver or an input / output interface.
[0035] In a third aspect, an embodiment of the present application provides a computer-readable storage medium having a computer program or instruction stored thereon. When the computer program or instruction is executed, the computer executes the method in the above-mentioned first aspect or any possible implementation of the first aspect.
[0036] In a fourth aspect, an embodiment of the present application provides a computer program product. When a computer reads and executes the computer program product, the computer executes the method in the above-mentioned first aspect or any possible implementation of the first aspect.
[0037] The technical effects that can be achieved in any of the second to fourth aspects mentioned above can refer to the description of the beneficial effects in the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 A schematic diagram of an image retrieval scenario provided in an embodiment of the present application;
[0039] Figure 2A schematic diagram of a base storage structure provided in an embodiment of the present application;
[0040] Figure 3 A schematic diagram of a product recommendation scenario provided in an embodiment of the present application;
[0041] Figure 4 A schematic diagram of a system architecture provided in an embodiment of the present application;
[0042] Figure 5 A schematic diagram of a process for establishing a compressed database provided in an embodiment of the present application;
[0043] Figure 6 A schematic diagram of a sample set partitioning method provided in an embodiment of the present application;
[0044] Figure 7 A schematic diagram of determining subspace distance provided in an embodiment of the present application;
[0045] Figure 8 A schematic diagram of performing PCA dimensionality reduction on a matrix provided in an embodiment of the present application;
[0046] Figure 9 A codeword structure provided in an embodiment of the present application;
[0047] Figure 10 Another codeword structure provided in an embodiment of the present application;
[0048] Figure 11 A schematic diagram of the relationship between an original base library, a codebook, and codewords provided in an embodiment of the present application;
[0049] Figure 12 A schematic diagram of partition storage provided in an embodiment of the present application;
[0050] Figure 13 A search flow chart provided in an embodiment of the present application;
[0051] Figure 14 A schematic diagram of determining a target storage area provided in an embodiment of the present application;
[0052] Figure 15 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application;
[0053] Figure 16 A schematic diagram of the structure of a data processing device provided in an embodiment of the present application;
[0054] Figure 17 A schematic diagram of the structure of a computing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] First, some terms in this application are explained to facilitate understanding by those skilled in the art.
[0056] 1. Database Compression: Database compression compresses stored data to reduce storage space and improve database performance and efficiency. The primary goals of database compression are to optimize storage resource utilization, improve query performance, and reduce storage costs. Compressing a database reduces storage space usage, thereby lowering storage costs. Furthermore, a compressed database improves read and write efficiency due to the reduced data volume, accelerating query and transaction processing.
[0057] 2. Vector retrieval technology: In a given vector data set, vectors similar to the query vector are retrieved according to a certain measurement method.
[0058] 3. The k-means clustering algorithm is an iterative clustering analysis algorithm. Specifically, given the number of clusters, k, the entire dataset is clustered. The objective function is to minimize the sum of the distances from all samples to the cluster centers. The objective function is iteratively calculated and optimized to obtain k cluster centers and the category to which each sample belongs.
[0059] 4. Principal component analysis (PCA) dimensionality reduction is a common data analysis method that uses orthogonal transformation to convert data represented by possibly correlated variables into data represented by a small number of linearly uncorrelated variables. Linearly uncorrelated variables are called principal components. The number of principal components is usually smaller than the number of original variables, so principal component analysis is often used to reduce the dimensionality of high-dimensional data and extract the main characteristic components of the data. Common methods of PCA dimensionality reduction include the covariance matrix method and the eigenvalue decomposition method. Among them, the covariance matrix method uses the covariance matrix to solve the eigenvalue and eigenvector, and then obtains the reduced-dimensional data; the eigenvalue decomposition method can use the singular value decomposition method to solve, thereby obtaining the reduced-dimensional data.
[0060] 5. The base database is a database or data structure used to store extracted feature vectors. It is commonly used in tasks such as face recognition, image retrieval, and speech recognition to facilitate similarity matching or comparison. When building the base database, features must be extracted for each sample object and stored in the base database. For example, the base database can use a matrix structure to store data, with each column representing a feature vector for a sample object.
[0061] Figure 1The following is a schematic diagram of an image retrieval scenario. First, a picture set including a large number of sample pictures is obtained, where the sample pictures are pictures including sample objects. Object recognition is performed on each sample picture in the picture set. The object data (also called object features) of the sample object in each sample picture can be extracted through a feature extraction model, and the extracted object data of each sample object is stored to form a base database. Figure 2 The schematic diagram of the base database structure shown in the figure can be a d*n matrix, where n represents the object data of n sample objects stored in the base database, and d represents the dimension of the object data of each sample object. After receiving a query request, the query request may include an image to be queried, and the object features of the query object in the image to be queried are extracted to obtain a query vector; a search is performed in the base database based on the query vector to retrieve object data that meets the similarity requirement with the query vector; it is determined from which target images these object data that meet the similarity requirement were extracted, and the determined target images are returned as search results. For example, in an Internet application, based on the product image to be queried input by the user, images containing products with similar appearance to the product image input by the user are retrieved from the base database.
[0062] Figure 3 A schematic diagram of a product recommendation scenario is shown. First, a large number of product samples are obtained, and the product features of each product are extracted through a feature extraction model (for example, feature extraction can be performed on pictures including product appearance, product description information, etc.), and the extracted product features of each product are stored to form a base database. When recommending products to users, the query request obtained includes a user identifier, and the user features of the user are extracted through a feature extraction model (in implementation, feature extraction can be performed on the user's historical behavior data, user portrait, etc. to extract user features), and the user features are used as query vectors; according to the query vector, a search is performed in the base database to retrieve product features that meet the similarity requirements with the query vector; it is determined from which target products these product features that meet the similarity requirements are extracted, and the determined target products are returned as search results.
[0063] During implementation, a query request can be received by a computing device. The computing device then retrieves object data from a database that meets the required similarity with the query vector based on the query vector corresponding to the query request, and uses the candidate objects of the object data that meet the required similarity with the query vector as the retrieval result. Since retrieval from the database is a data-intensive task, it can be run on the accelerator card of the computing device. When executing the retrieval task, the computing device loads the object data in the database into the video memory, so that object data that matches the query vector can be found from the large amount of object data in the database, thereby obtaining the retrieval result. When the amount of object data stored in the database is large, searching from all the object data stored in the database will result in low retrieval efficiency.
[0064] Based on the above problems, an embodiment of the present application provides a data processing method, which compresses and encodes the object data of multiple candidate objects through a codebook to obtain codewords. The compressed and encoded codewords can be stored in a base database. When performing a retrieval task, the retrieval results can be quickly obtained based on the query vector, codebook and codewords.
[0065] The following describes the system architecture applicable to the embodiments of this application. Figure 4 As shown, the system includes a terminal device 40, a computing device 41, and a storage device 42. The computing device 41 can receive a query request sent by the terminal device 40 and determine a query vector corresponding to the query request; the storage device 42 stores codewords obtained by compressing and encoding object data of multiple candidate objects, as well as a codebook corresponding to the codewords.
[0066] Illustratively, the query request may include a picture to be queried, and the computing device 41 may extract object data of the query object included in the picture to be queried, and use the extracted object data of the query object as a query vector.
[0067] The computing device 41 obtains the codebook and codeword from the storage device 42 and, based on the query vector, codeword, and codebook, retrieves a target object that matches the query request from multiple candidate objects. In implementation, when the computing device 41 performs a retrieval task, the retrieval task can be performed by a processor in the computing device 41 or by an accelerator card. If the retrieval task is performed by the processor, the processor loads the codebook and codeword from the storage device 42 into the memory. If the retrieval task is performed by the accelerator card, the processor loads the codebook and codeword from the storage device 42 into the video memory.
[0068] After obtaining the query vector, the computing device 41 searches from the compressed and encoded base library. The base library stores codewords obtained after compression encoding of the original object data, and the codeword structure is specially designed so that the codeword structure includes a matrix of multiple blocks, and each column in the matrix corresponds to a codeword block. Each codeword block obtained in the codeword structure is a dense matrix. Since the operation speed of the dense matrix is much higher than other operation forms, the processor or acceleration card of the computing device 41 can significantly improve the operation speed based on the dense codeword matrix during the retrieval process, thereby improving the retrieval efficiency; in addition, since each column in the codeword matrix corresponds to a block, that is, each column in the codeword matrix only includes an area with non-zero elements, based on this codeword structure, data can be stored in continuous memory blocks. Continuous memory block access can greatly improve the memory access speed, thereby further improving the retrieval efficiency.
[0069] It should be noted that Figure 4 The system architecture shown is only an example. The embodiments of the present application do not limit the specific form of the system architecture. The system architecture applicable to the embodiments of the present application may have more Figure 4 More or fewer devices than shown.
[0070] Based on the above Figure 4 The system architecture shown in FIG. This embodiment of the present application provides a data processing solution. The implementation process of this solution can be divided into two phases: the first phase is the database construction phase, and the second phase is the retrieval phase. In the database construction phase, object data based on multiple candidate objects is compressed and encoded to obtain a compressed base database. In the retrieval phase, target objects that match the query request are retrieved from the compressed base database based on the query vector corresponding to the query request. The following describes these two phases separately.
[0071] 1. Database construction stage.
[0072] In the database building phase, the database building process can be executed by a computing device; wherein the computing device executing the database building process is Figure 4 The computing devices that execute the retrieval process can be different computing devices.
[0073] During the database building phase, embodiments of the present application can collect a large number of samples; the computing device can extract object data for multiple candidate objects from the samples. For example, the samples can be images, and the object data for the candidate objects can be feature data for objects in the images, including but not limited to people, goods, buildings, animals, and plants.
[0074] The computing device can construct an original database based on the object data of the extracted candidate objects. The original database can be structured in a matrix format, with each column representing the object data of a candidate object. Because the number of candidate objects collected during the database construction phase is large, and the object data of each candidate object is high-dimensional, the original database will be very large.
[0075] In implementation, the computing device can extract object data of the candidate object from each collected sample based on the trained feature extraction model. The embodiment of the present application does not limit the type of feature extraction model used.
[0076] The following is combined with Figure 5 The following describes the database building process performed by the computing device in the embodiment of the present application.
[0077] like Figure 5 The schematic diagram of the process of establishing a compressed database shown in FIG. 1 may specifically include the following steps:
[0078] Step 501: The computing device generates an initial codebook;
[0079] The initial codebook includes multiple initial sub-codebooks; optionally, the structure of the initial sub-codebook is a d*p matrix, and the structure of the initial codebook composed of the multiple initial sub-codebooks is a d*m matrix, where m is greater than p, p is greater than 1, and d is greater than 1. Optionally, the value of m can be an integer multiple of p, and the value of p can be a preset subspace size.
[0080] When a computing device generates an initial codebook, it can be implemented in a variety of different ways:
[0081] One possible implementation is to select object data of m sample objects from the object data of candidate objects stored in the original base database to form multiple sample sets; and generate an initial sub-codebook according to the object data of the sample objects included in each sample set.
[0082] During implementation, the computing device may select object data of m sample objects from the original base database, and organize the object data of the m sample objects into multiple sample sets based on the value of p, with each sample set including object data of p sample objects. The value of m is the number of columns corresponding to the codebook in the embodiment of this application, and the value of m is much smaller than the number of candidate objects stored in the original base database.
[0083] Assuming that the value of m is 9 and the preset subspace size is 3, the object data of 9 sample objects are selected from the original base library and divided into three groups. The grouping method can be as follows: Figure 6As shown, the object data of sample objects m1, m2, and m3 are combined into sample set 1, the object data of sample objects m4, m5, and m6 are combined into sample set 2, and the object data of sample objects m7, m8, and m9 are combined into sample set 3.
[0084] In implementation, the computing device may randomly select object data of m sample objects from the original base database. For example, the original base database stores uncompressed object data of multiple candidate objects, such as the data structure stored in the original base database is as follows: Figure 2 As shown, the computing device can randomly select m sample objects from n candidate objects, where the value of m is much smaller than the value of n.
[0085] When generating the initial sub-codebook, the computing device may, for any sample set, perform orthogonal basis initialization on a matrix composed of object data of sample objects included in the sample set to obtain an initial sub-codebook; wherein the number of columns of the obtained initial sub-codebook is p.
[0086] In implementation, for each sample set, the object data of the sample objects included in the sample set are combined into a matrix, and the matrix is initialized with an orthogonal basis to obtain an initial sub-codebook corresponding to the sample set. For example, Figure 6 As shown, the object data of the sample objects m1, m2, and m3 included in sample set 1 are initialized with an orthogonal basis to obtain the initial subcodebook corresponding to sample set 1; the object data of the sample objects m4, m5, and m6 included in sample set 2 are initialized with an orthogonal basis to obtain the initial subcodebook corresponding to sample set 2; the object data of the sample objects m7, m8, and m9 included in sample set 3 are initialized with an orthogonal basis to obtain the initial subcodebook corresponding to sample set 3.
[0087] When the computing device of the embodiment of the present application performs orthogonal basis initialization on the matrix composed of the object data included in the sample set, the orthogonal basis of the matrix can be obtained in a variety of different ways, the obtained orthogonal basis is used as the initialization matrix of the matrix, and the obtained initialization matrix is used as the initial sub-codebook corresponding to the sample set.
[0088] The orthogonal basis can be initialized using QR decomposition. The principle of QR decomposition is that, for a given matrix A, it can be decomposed into the product of an orthogonal matrix Q and an upper triangular matrix R, i.e., A = QR. The orthogonal matrix Q can be used as the orthogonal basis to initialize the matrix. Alternatively, the orthogonal basis can be initialized using diagonalization. The principle of diagonalization is that, for certain special types of matrices (such as symmetric matrices or positive definite matrices), an orthogonal basis can be obtained through diagonalization. The eigenvectors of the symmetric matrix form an orthogonal basis to initialize the matrix.
[0089] When the computing device generates the initial codebook, another possible implementation method is to pre-set multiple sample data (the sample data may not be the object data in the original base library), divide the multiple sample data into sample sets, and randomly initialize the matrix composed of the sample data in the sample set to obtain each initial sub-codebook; and each obtained initial sub-codebook is combined into an initial codebook.
[0090] Step 502: The computing device generates a codebook for compressing and encoding the object data of the candidate object stored in the original base library, and a codeword after the compression encoding, based on each initial sub-codebook in the initial codebook.
[0091] In one possible implementation, the computing device determines, based on the subspace distance between the object data of each sample object and each initial sub-codebook, a sample object dataset corresponding to each initial sub-codebook; for any initial sub-codebook, generating, based on the sample object dataset corresponding to the initial sub-codebook, an updated sub-codebook and a corresponding codeword block corresponding to the initial sub-codebook; generating a codebook based on the updated sub-codebook corresponding to each initial sub-codebook; and generating a codeword based on the codeword block corresponding to each initial sub-codebook.
[0092] The following describes a process in which the computing device determines, based on the subspace distance between the object data included in each sample set and each initial subcodebook, a sample object data set corresponding to each initial subcodebook.
[0093] Step 1a: The computing device determines the subspace distance between the object data of each sample object in each sample set and each initial sub-codebook;
[0094] Here, we take the example of selecting object data of m sample objects from the original database and dividing the sample sets; Figure 7 The object data of m candidate samples and m / p initial sub-codebooks are shown, where the dimension of the initial sub-codebook is d*p. The subspace distance between the object data of each sample object and each initial sub-codebook is determined respectively. An optional way to determine the subspace distance is to determine the subspace distance based on the product between the vector (dimension is 1*d) composed of the object data of a sample object and an initial sub-codebook; as shown in FIG. Figure 7 As shown, the product of a 1*d vector composed of object data of a sample object and the d*p initial sub-codebook is a 1*p vector. The computing device can calculate the L2 norm of the 1*p vector to obtain the subspace distance.
[0095] Step 2a: The computing device determines, from the multiple initial sub-codebooks, an initial sub-codebook corresponding to the object data of the sample object based on the subspace distance between the object data of the sample object and each initial sub-codebook;
[0096] For object data of any sample object, the subspace distance between the object data of the sample object and each initial subcodebook is determined in step 1. In one possible implementation, the initial subcodebook with the smallest subspace distance is bound to the sample object, thereby obtaining an initial subcodebook corresponding to the object data of the sample object.
[0097] Step 3a: The computing device determines, based on the correspondence between the object data of the sample objects and the initial sub-codebook, a sample object data set corresponding to each initial sub-codebook, where the sample object data set includes the object data of the sample objects corresponding to the initial sub-codebook.
[0098] Based on the initial sub-codebook corresponding to the object data of each sample object obtained in step 2a, a correspondence between the object data of the sample object and the initial sub-codebook can be generated. Based on the generated correspondence between the object data of the sample object and the initial sub-codebook, a sample object dataset corresponding to each initial sub-codebook can be obtained.
[0099] Exemplarily, assuming that the value of m is 9, the number of initial sub-codebooks obtained based on the object data of 9 sample objects is 3; if the correspondence between the object data of the sample objects generated based on step 2a and the initial sub-codebook is as shown in Table 1, then the sample object data set corresponding to the initial sub-codebook 1 includes the object data of the sample object 1, the object data of the sample object 3, and the object data of the sample object 7; the sample object data set corresponding to the initial sub-codebook 2 includes the object data of the sample object 2, the object data of the sample object 5, and the object data of the sample object 9; and the sample object data set corresponding to the initial sub-codebook 3 includes the object data of the sample object 4, the object data of the sample object 6, and the object data of the sample object 8.
[0100] Object data of sample object 1 Initial subcodebook 1 Object data of sample object 2 Initial subcodebook 2 Object data of sample object 3 Initial subcodebook 1 Object data for sample object 4 Initial subcodebook 3 Object data of sample object 5 Initial subcodebook 2 Object data for sample object 6 Initial subcodebook 3 Object data of sample object 7 Initial subcodebook 1 Object data for sample object 8 Initial subcodebook 3 Object data of sample object 9 Initial subcodebook 2
[0101] Table 1
[0102] After determining the sample object data set corresponding to each initial sub-codebook, the computing device generates, for any initial sub-codebook, an updated sub-codebook corresponding to the initial sub-codebook and a corresponding codeword block according to the sample object data set corresponding to the initial sub-codebook.
[0103] Optionally, the computing device may perform PCA dimensionality reduction processing on the sample object data set corresponding to the initial sub-codebook to generate an updated sub-codebook corresponding to the initial sub-codebook and corresponding codeword blocks.
[0104] During implementation, when performing PCA dimensionality reduction processing on the sample object dataset corresponding to the initial sub-codebook, the computing device combines the sample object dataset corresponding to the initial sub-codebook into a matrix, performs PCA dimensionality reduction processing on the combined matrix, and obtains an updated sub-codebook and codeword blocks corresponding to the initial sub-codebook. The updated sub-codebook corresponds to a preset subspace size, the number of rows in the updated sub-codebook is the dimension d of the object data, and the number of columns in the updated sub-codebook is the preset subspace size p. The number of rows in the obtained codeword blocks is the preset subspace size p, and the number of columns in the codeword blocks is the number of sample objects included in the sample object dataset.
[0105] Exemplarily, assuming that the sample object data set corresponding to the initial sub-codebook includes object data of x sample objects, the sample object data set corresponding to the initial sub-codebook forms a matrix of d*x. Figure 8 The process of performing PCA dimensionality reduction processing on the matrix composed of the sample object data set corresponding to the initial sub-codebook is shown, and the d*x matrix is reduced to a d*p sub-codebook and a p*x codeword block.
[0106] It should be noted that after obtaining the updated sub-codebook and codeword block, the computing device of the embodiment of the present application can repeatedly execute the above-mentioned process of updating the sub-codebook and the corresponding codeword block according to the sample object data set based on the updated sub-codebook, and continuously update the sub-codebook and codeword block until the determined sub-codebook and codeword block meet the conditions.
[0107] The computing device of the embodiment of the present application may determine whether each updated sub-codebook and codeword block meets the conditions based on the loss function by minimizing the least squares reconstruction loss function;
[0108] The minimized least squares reconstruction loss function in the embodiment of the present application can be defined as follows:
[0109]
[0110] Wherein, C is a dense codebook matrix, whose dimension can be d*m; B is a structured block sparse codeword matrix, whose dimension can be m*n; A is a matrix composed of object data of multiple candidate objects in the original base database; Represents a Frobenius norm operation. B includes multiple codebook blocks, and codebook blocks may include non-zero elements. Positions outside of the codebook blocks in B are zero, and each column of B corresponds to a codebook block (i.e., each column of B has only one contiguous region with non-zero elements). Optionally, the positions of non-zero elements in different columns of B are either identical or completely different, and the union of the positions of non-zero elements in different columns covers all dimensions.
[0111] After the computing device generates the updated sub-codebooks and the corresponding codeword blocks corresponding to the initial sub-codebooks, a codebook is generated according to the updated sub-codebooks corresponding to each initial sub-codebook; and a codeword is generated according to the codeword blocks corresponding to each initial sub-codebook.
[0112] When a computing device generates a codeword, one possible implementation method is that the computing device divides each codeword into blocks to form a reference codeword, quantizes the reference codeword, and adjusts elements in the quantized reference codeword to generate the codeword.
[0113] During implementation, the computing device may use standard int 8 quantization to quantize the reference codeword; or may use lower bit quantization to quantize the reference codeword, thereby achieving a higher compression rate.
[0114] Optionally, the structure of the codeword generated by the computing device in the embodiment of the present application is a matrix including multiple codebook blocks, the codebook blocks include first elements, and other positions in the matrix except for the multiple blocks are second elements, and each column in the matrix corresponds to a block.
[0115] Exemplarily, the first element is a non-zero element, and the second element is a 0 element. Since the codeword structure only contains non-zero elements in the codebook blocks, and the rest of the codeword contains 0 elements, the non-zero elements in the codeword are concentrated in each codebook block, and each codebook block in the codebook is a dense matrix.
[0116] When adjusting the elements in the reference codeword after quantization processing, the computing device may rearrange each column of the reference codeword according to a non-zero element pattern, thereby generating a codeword.
[0117] like Figure 9 The codeword structure obtained in the embodiment of the present application shown is a matrix including multiple codeword blocks, and each column in the matrix corresponds to a codeword block, and the positions of different codeword blocks in the column can be exactly the same. Or as Figure 10 The codeword structure obtained in the embodiment of the present application shown in FIG. 1 is a matrix including multiple codeword blocks, and each column in the matrix corresponds to a codeword block, and the positions of different codeword blocks in the column are completely different; Figure 10 The codeword structure shown is a block diagonal matrix.
[0118] Correspondingly, based on the rearrangement of the reference codewords, the elements in each column of the original base database storing the object data of multiple candidate objects can also be rearranged in the same way, so that the matrix corresponding to the original base database is approximately equal to the product of the generated codebook and the codeword. Figure 11As shown, the matrix A (whose dimension is d*n) corresponding to the original base library is approximately equal to the product of the codebook C (whose dimension is d*m) and the codeword B, where the codeword B is a block diagonal matrix, and the codebook C includes multiple sub-codebooks. The number of columns of each sub-codebook is the preset subspace size p, and the number of rows of each codeword block of the codeword B is the preset subspace size p. Each codeword block of the codeword B corresponds one-to-one to each sub-codebook in the codebook C.
[0119] After the computing device of the embodiment of the present application obtains the codebook and codeword corresponding to the object data of multiple candidate objects in the original base based on the above process, the codeword can be stored in the compressed base, and the base stores data in the form of a matrix. Since the object data of multiple candidate objects can be approximately equal to the product of the codebook and the codeword, when other devices read the codewords stored in the target database, the object data of multiple candidate objects can be restored based on the codebook. As can be seen from the above introduction, the codeword structure of the embodiment of the present application is a matrix including multiple codeword blocks, and only the first element (exemplarily, the first element is a non-zero element) is included in the codeword block, and the second element (exemplarily, the second element is a 0 element) is included in the other positions of the matrix, thereby greatly reducing the amount of data stored in the target database.
[0120] When storing codewords in a base database, the base database may be divided into multiple storage areas. Optionally, the storage areas in the embodiment of the present application may be buckets, where a bucket stores data with a high degree of similarity.
[0121] In implementation, after the computing device obtains the codebooks and codewords corresponding to the object data of multiple candidate objects, when storing the codewords in the base database, one possible implementation method is that each storage area in the multiple storage areas is used to store a codeword block in the codeword. Figure 12 As shown, each codeword in the codeword structure is divided into blocks and stored in different storage areas in sequence.
[0122] In the database building process provided by the embodiment of the present application, the original base of the storage object data is subjected to database compression processing, and the object data of multiple candidate objects are compressed and encoded into code words, and the structure of the code word is a matrix including multiple code word blocks. Since the non-zero elements in the code words of the embodiment of the present application are concentrated in the code word blocks, the various code word blocks in the code word are dense matrices, so that when the computing device reads the code word and performs arithmetic processing, the computing speed of the dense matrix is much higher than other computing forms; in addition, since each column in the code word matrix corresponds to a code word block, that is, each column in the code word matrix only includes an area with non-zero elements, based on this code word structure, data can be stored in continuous memory blocks, and continuous memory block access can greatly improve the memory access speed of the computing device. In summary, the code word structure of the embodiment of the present application can greatly improve the computing speed and memory access speed of the computing device.
[0123] 2. Retrieval stage.
[0124] During the retrieval phase, the retrieval process may be executed by a computing device; wherein the computing device executing the retrieval process and the computing device executing the database building process during the database building phase may be different computing devices.
[0125] The following is combined with Figure 13 The following describes the retrieval process performed by the computing device in the embodiment of the present application.
[0126] Step 1301: The computing device receives a query request and determines a query vector corresponding to the query request.
[0127] After receiving a query request, the computing device determines a query vector based on the query content. Optionally, the computing device may extract features from the query content based on a feature extraction model to generate the query vector. For example, if the query request is for products similar to a product in a query image, and the query content obtained by the computing device is an image, the computing device extracts product features from the image to generate the query vector.
[0128] Step 1302: The computing device retrieves a target object that matches the query request from a plurality of candidate objects stored in the original database according to the query vector, the codeword, and the codebook.
[0129] The codewords used by the computing device in step 1302 are obtained by compressing and encoding the object data of multiple candidate objects through a codebook. The codebook and codewords may be those generated in the database building phase.
[0130] Since the embodiment of the present application stores each codeword block in multiple storage areas of the base database, when the computing device searches for a target object that matches a query request, it first determines the target storage area from the multiple storage areas, and then searches for the target object that matches the query request based on the codeword blocks stored in the target storage area.
[0131] In one possible implementation, the computing device determines a target storage area from multiple storage areas based on a query vector and a codebook; and retrieves a target object matching the query request from multiple candidate objects based on codeword blocks stored in the target storage area.
[0132] The following describes the process of the computing device determining the target storage area and the process of retrieving the target object based on the codeword blocks stored in the target storage area.
[0133] 1. The computing device determines a target storage area from multiple storage areas in the target database according to the query vector and the codebook.
[0134] The codebook of the embodiment of the present application includes multiple sub-codebooks, wherein the size of the sub-codebook is determined according to a preset subspace size. For example, if the preset subspace size is p, then one sub-codebook corresponds to p candidate objects, that is, the dimension of the matrix corresponding to one sub-codebook is d*p, where d is the feature dimension of the object data of the candidate object.
[0135] In one possible implementation, the computing device may determine the target storage area according to the following method:
[0136] Step 1b: The computing device determines, based on the query vector and the codebook, a subspace distance between the query vector and each sub-codebook in the codebook.
[0137] Optionally, the computing device may determine the first similarity information between the query vector and the sub-codebook according to the following formula:
[0138] The first similarity information is used to represent the similarity between the query vector and the sub-codebook.
[0139] In implementation, the computing device may determine the first similarity information between the query vector and the sub-codebook in a variety of different ways:
[0140] Method 1: A computing device determines a product of a query vector and a codebook to obtain an intermediate vector; divides the intermediate vector into sub-intermediate vectors corresponding to each sub-codebook; and determines first similarity information between the query vector and each sub-codebook in the codebook based on the sub-intermediate vector corresponding to each sub-codebook.
[0141] In this manner, a larger value of the first similarity information determined by the computing device indicates a higher similarity between the query vector and the sub-codebook.
[0142] For example, if the feature dimension of the query vector is d, the query vector can be represented as a 1*d matrix, and the codebook structure is a d*m matrix. Then, the query vector and the codebook are multiplied to obtain an intermediate vector of a 1*m matrix. Based on the size of the sub-codebook, the intermediate vector is divided into multiple sub-intermediate vectors, and the divided sub-intermediate vectors can be a 1*p matrix. When the computing device determines the first similarity information between the query vector and each sub-codebook in the codebook based on the sub-intermediate vector corresponding to each sub-codebook, the L2 norm of the 1*p matrix can be used as the first similarity information.
[0143] In approach 2, the computing device determines a subspace distance between the query vector and each sub-codebook in the codebook, and uses the subspace distance as first similarity information between the query vector and each sub-codebook in the codebook.
[0144] Optionally, the computing device may calculate the subspace distance between the query vector and the sub-codebook according to the following formula:
[0145]
[0146] Where D is the subspace distance between the query vector and the subcodebook, q is the query vector (feature dimension is d), A k is the matrix corresponding to the sub-codebook (its dimension is d*p).
[0147] In this manner, the smaller the value of the first similarity information determined by the computing device is, the higher the similarity between the query vector and the sub-codebook is.
[0148] Step 2b: The computing device determines a target sub-codebook from the multiple sub-codebooks included in the codebook according to the first similarity information between the query vector and each sub-codebook in the codebook.
[0149] If, in step 2b, the computing device uses approach 1 to determine the first similarity information between the query vector and each sub-codebook in the codebook, the computing device selects k0 sub-codebooks with large first similarity information values from the multiple sub-codebooks included in the codebook as target sub-codebooks. If, in step 2b, the computing device uses approach 2 to use the subspace distance between the query vector and each sub-codebook in the codebook as the first similarity information, the computing device selects k0 sub-codebooks with small subspace distances from the multiple sub-codebooks included in the codebook as target sub-codebooks.
[0150] Step 3b: The computing device determines the target codeword block corresponding to the target subcodebook according to the correspondence between the subcodebook and the codeword block, and uses the storage area storing the codeword block corresponding to the target codeword block as the target storage area.
[0151] After the computing device determines the target sub-codebook from the codebook, since the sub-codebooks correspond one-to-one to the codeword blocks in the codeword structure, the computing device determines the target codeword block in the codeword structure that corresponds to the target sub-codebook. Furthermore, since each storage area in the target database stores a codeword block, the storage area storing the target codeword block is determined as the target storage area.
[0152] like Figure 14 As shown, after the computing device determines the first similarity information between the query vector and each sub-codebook in the codebook, it sorts the multiple storage areas of the target database according to the first similarity information. In implementation, if the first similarity information is determined using method 1 above, the storage areas are sorted in descending order based on the values of the first similarity information; if the first similarity information is determined using method 2 above, the storage areas are sorted in ascending order based on the values of the first similarity information. The top k0 storage areas in the sorting order are selected from the multiple storage areas as the target storage areas.
[0153] 2. The computing device retrieves a target object that matches the query request from multiple candidate objects based on the codeword blocks stored in the target storage area.
[0154] In one possible implementation, the computing device determines, based on the sub-intermediate vector corresponding to the target sub-codebook and the codeword blocks stored in the target storage area, second similarity information between the query vector and each candidate object corresponding to the codeword block stored in the target storage area, where the second similarity information is used to characterize the degree of similarity between the query vector and each candidate object corresponding to the codeword block stored in the target storage area; and the computing device determines the target object from the candidate objects corresponding to the target sub-codebook based on the second similarity information.
[0155] In implementation, the computing device may determine the second similarity information in a variety of different ways:
[0156] Method 1: The computing device determines the product of the sub-intermediate vector corresponding to the target sub-codebook and the codeword block stored in the target storage area, and determines, based on the product, second similarity information between the query vector and each candidate object corresponding to the codeword block stored in the target storage area.
[0157] For example, assuming that the target sub-codebook is a d*p matrix and the codeword blocks stored in the target storage area are a p*x matrix, the product of the target sub-codebook and the codeword blocks stored in the target storage area is a d*x matrix; each column in the d*x matrix corresponds to a candidate object. Optionally, the computing device can determine the L2 norm for each column of the d*x matrix to obtain second similarity information between the query vector and each candidate object corresponding to the codeword block stored in the target storage area.
[0158] After the computing device obtains the second similarity information between the query vector and each candidate object corresponding to the codeword block stored in the target storage area based on the above-mentioned method 1, it selects k1 candidate objects with the largest second similarity information values from the candidate objects corresponding to the codeword blocks stored in the target storage area as target objects based on the second similarity information.
[0159] Method 2: The computing device determines, based on the codeword blocks stored in the target storage area, an adjustment weight for each candidate object corresponding to the codeword blocks stored in the target storage area; and determines a product of a sub-intermediate vector corresponding to the target sub-codebook and the codeword blocks stored in the target storage area, and determines, based on the product and each adjustment weight, second similarity information between the query vector and each candidate object corresponding to the codeword blocks stored in the target storage area.
[0160] The following is a detailed description of the method 2 for determining the second similarity information.
[0161] Step 1c: The computing device determines, based on the codeword blocks stored in the target storage area, an adjustment weight for each candidate object corresponding to the codeword blocks stored in the target storage area;
[0162] During implementation, the computing device determines the L2 norm of each column of the codeword block stored in the target storage area; determines the adjustment weight of the candidate object based on the calculation result of the L2 norm; illustratively, if the codeword block stored in the target storage area is a p*x matrix, then for each column of the matrix, the L2 norm is determined, thereby obtaining x adjustment weights; optionally, assuming that the L2 norm of each column of the codeword block is y, 0.5*y is added. 2 The adjusted weight of the candidate object corresponding to this column.
[0163] Step 2c: The computing device determines the product of the sub-intermediate vector corresponding to the target sub-codebook and the codeword block stored in the target storage area;
[0164] Exemplarily, assuming that the target sub-codebook is a d*p matrix and the codeword blocks stored in the target storage area are a p*x matrix, the product of the target sub-codebook and the codeword blocks stored in the target storage area is a d*x matrix.
[0165] Step 3c: The computing device determines, based on the product and each adjusted weight, second similarity information between the query vector and each candidate object corresponding to the codeword block stored in the target storage area;
[0166] If the product obtained in step 2c is a d*x matrix, the computing device determines the L2 norm of each column of the matrix and uses the L2 norm of each column as the similarity corresponding to the column; the computing device negates the similarity and uses the sum of the similarity after negation and the corresponding adjustment parameter as the second similarity information.
[0167] After the computing device obtains the second similarity information between the query vector and each candidate object corresponding to the codeword block stored in the target storage area based on the above-mentioned method 2, it selects k1 candidate objects with the smallest second similarity information values from the candidate objects corresponding to the codeword blocks stored in the target storage area as target objects based on the second similarity information.
[0168] After the computing device in the embodiment of the present application determines the target object that matches the query request from multiple candidate objects, it can use the identification information of the target object as the retrieval result.
[0169] The retrieval method provided by the embodiment of the present application is that when the computing device obtains the query vector and retrieves the retrieval results matching the query vector from the database, the computing device searches from the target database after compression coding; and the target database of the embodiment of the present application stores the codeword obtained after compression coding of the original object data, and the codeword structure is specially designed so that the structure of the codeword includes a matrix of multiple codeword blocks, and each column in the matrix corresponds to a codeword block. The non-zero elements in the codeword of the embodiment of the present application are concentrated in the codeword blocks, and each codeword block in the codeword is a dense matrix. Since the operation speed of the dense matrix is much higher than other operation forms, the computing device can significantly improve the operation speed based on the dense codeword matrix during the retrieval process, thereby improving the retrieval efficiency; in addition, since each column in the codeword matrix corresponds to a codeword block, that is, each column in the codeword matrix only includes an area with non-zero elements, based on this codeword structure, data can be stored in continuous memory blocks, and continuous memory block access can greatly improve the memory access speed of the computing device, thereby further improving the retrieval efficiency.
[0170] Based on the above content and the same technical concept, the embodiment of the present application provides a data processing device 1500, such as Figure 15 As shown, the data processing device 1500 includes an initialization unit 1501 and a processing unit 1502 .
[0171] Initialization unit 1501 is configured to generate an initial codebook, wherein the structure of the initial codebook is a d*m matrix, the initial codebook includes multiple initial sub-codebooks, the structure of each initial sub-codebook is a d*p matrix, where m is greater than p, p is greater than 1, and d is greater than 1;
[0172] A processing unit 1502 is configured to generate, based on each initial sub-codebook in the initial codebook, a codebook for compressing and encoding object data of candidate objects stored in an original base library, and a codeword after the compression encoding; wherein the structure of the codeword is a matrix including a plurality of codeword blocks, the codeword blocks including first elements, positions other than the plurality of codeword blocks in the matrix as second elements, and each column in the matrix corresponding to a codeword block.
[0173] In a possible implementation, the initialization unit 1501 is specifically configured to:
[0174] Selecting m sample objects' object data from the object data of the candidate objects stored in the original database to form multiple sample sets, where each sample set includes p sample objects' object data;
[0175] Each initial sub-codebook included in the initial codebook is generated according to object data of the sample object included in each sample set.
[0176] In a possible implementation, the processing unit 1502 is specifically configured to:
[0177] Determine, according to the subspace distance between the object data of each sample object and each initial subcodebook, the sample object data set corresponding to each initial subcodebook;
[0178] For any initial sub-codebook, generating an updated sub-codebook and corresponding codeword blocks corresponding to the initial sub-codebook according to the sample object data set corresponding to the initial sub-codebook;
[0179] Generating the codebook according to the updated sub-codebook corresponding to each initial sub-codebook; and generating the codeword according to the codeword block corresponding to each initial sub-codebook.
[0180] In a possible implementation, the processing unit 1502 is specifically configured to:
[0181] For object data of any sample object, determining an initial subcodebook corresponding to the object data of the sample object from a plurality of initial subcodebooks according to a subspace distance between the object data of the sample object and each initial subcodebook;
[0182] According to the correspondence between the object data of the sample objects and the initial sub-codebook, a sample object data set corresponding to each initial sub-codebook is determined respectively, where the sample object data set includes the object data of the sample objects corresponding to the initial sub-codebook.
[0183] In a possible implementation, the processing unit 1502 is specifically configured to:
[0184] Divide the codewords corresponding to each initial sub-codebook into blocks to form reference codewords;
[0185] The reference codeword is quantized, and elements in the quantized reference codeword are adjusted to generate the codeword.
[0186] In a possible implementation, the structure of the codeword is a block diagonal matrix.
[0187] In a possible implementation, the present application embodiment further provides a data processing device 1600, such as Figure 16 As shown, the data processing device 1600 includes a receiving unit 1601 and a retrieval unit 1602; wherein, the data processing device 1600 and the Figure 15 The data processing apparatus 1500 shown can be deployed on a device, or the data processing apparatus can be deployed with a device such as Figure 15 The data processing devices shown may be deployed separately.
[0188] The receiving unit 1601 is configured to receive a query request and determine a query vector corresponding to the query request;
[0189] The retrieval unit 1602 is configured to retrieve a target object matching the query request from a plurality of candidate objects stored in the original database according to the query vector, the codeword, and the codebook.
[0190] In a possible implementation, each codeword in the codeword is divided into blocks and stored in different storage areas.
[0191] In a possible implementation, the retrieval unit 1602 is specifically configured to:
[0192] determining a target storage area according to the query vector and the codebook;
[0193] According to the codeword blocks stored in the target storage area, a target object matching the query request is retrieved from the multiple candidate objects.
[0194] In a possible implementation, the codebook includes multiple sub-codebooks, each sub-codebook corresponds to a codeword block;
[0195] The retrieval unit 1602 is specifically configured to:
[0196] determining, based on the query vector and the codebook, first similarity information between the query vector and each sub-codebook in the codebook, wherein the first similarity information is used to represent a degree of similarity between the query vector and the sub-codebook;
[0197] determining a target subcodebook from a plurality of subcodebooks included in the codebook according to first similarity information between the query vector and each subcodebook in the codebook;
[0198] According to the correspondence between the sub-codebook and the block, the target codeword block corresponding to the target sub-codebook is determined, and the storage area storing the target codeword block is used as the target storage area.
[0199] In a possible implementation, the retrieval unit 1602 is specifically configured to:
[0200] Determine a product of the query vector and the codebook to obtain an intermediate vector;
[0201] Dividing the intermediate vector into sub-intermediate vectors corresponding to each sub-codebook respectively;
[0202] Determine, according to the sub-intermediate vector corresponding to each sub-codebook, first similarity information between the query vector and each sub-codebook in the codebook.
[0203] In a possible implementation, the retrieval unit 1602 is specifically configured to:
[0204] determining, based on the sub-intermediate vector corresponding to the target sub-codebook and the codeword blocks stored in the target storage area, second similarity information between the query vector and each candidate object corresponding to the codeword blocks stored in the target storage area, wherein the second similarity information is used to represent a degree of similarity between the query vector and the candidate objects corresponding to the codeword blocks stored in the target storage area;
[0205] The target object is determined from candidate objects corresponding to the target sub-codebook according to the second similarity information.
[0206] Figure 17 This is a schematic diagram of the structure of a computing device provided in an embodiment of the present application. The computing device is used to perform the above Figure 5 、 Figure 13 The method executed by the computing device in the method embodiment. The computing device 1700 includes a processor 1701, a memory 1702, and a communication interface 1703. The processor 1701, the memory 1702, and the communication interface 1703 may be connected via a bus 1704.
[0207] The processor 1701 is used to execute instructions stored in the memory 1702 so that the data processing device 1400 or the data processing device 1500 executes the data processing method provided in this application. The processor 1701 can be, but is not limited to, any one or more of: a central processing unit (CPU), a data processing unit (DPU), a system on chip (SOC), a field programmable gate array (FPGA), a graphics processing unit (GPU), an application specific integrated circuit (ASIC), or an accelerator card.
[0208] Memory 1702 is used to store computer instructions and data, such as memory 1702 storing computer instructions and data required to implement the data processing method provided in this application. Memory 1702 includes volatile memory (volatile memory), such as random access memory (RAM), dynamic random access memory (DRAM), etc. It can also be non-volatile memory (non-volatile memory), such as read-only memory (ROM), storage-class memory (SCM), flash memory, hard disk drive (HDD) or solid state drive (SSD).
[0209] The memory 1702 stores executable program code, and the processor 1701 executes the executable program code to implement the aforementioned data processing functions. The memory 1702 stores instructions for the data processing device 1500 and / or the data processing device 1600 to execute the data processing method provided in this application.
[0210] The communication interface 1703 is used to communicate with internal or external devices, such as obtaining read requests / write requests sent by a process, or communicating with a storage device to complete data access. For example, the communication interface 1703 can be a network card.
[0211] The bus 1704 may be a Peripheral Component Interconnect Express (PCIe) bus, a Double Data Rate (DDR) bus, a Serial Advanced Technology Attachment (SATA) bus, a Serial Attached SCSI (SAS) bus, a Controller Area Network (CAN) bus, an Extended Industry Standard Architecture (EISA) bus, a Unified Bus (UBus or UB), a Compute Express Link (CXL), a Cache Coherent Interconnect for Accelerators (CCIX), etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 17 The bus 1704 may include a path for transmitting information between each component of the data processing device 1700 (eg, the memory 1702, the processor 1701, and the communication interface 1703).
[0212] The present application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions that can be run on a computing device or stored in any available medium. When the computer program product is run on at least one computing device, the at least one computing device executes the above-mentioned Figure 5 or Figure 13 The data processing method executed by the computing device in the embodiment is shown in FIG. Figure 5 or Figure 13 The description of each step is not repeated here.
[0213] The present application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that can be stored by a computing device or a data storage device such as a data center that contains one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions that instruct the computing device to execute the above Figure 5 or Figure 13The data processing method executed by the computing device in the embodiment is shown in FIG. Figure 5 or Figure 13 The description of each step is not repeated here.
[0214] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When software is used for implementation, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, computer, server or data center to another website, computer, server or data center via a wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) method. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrations. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
[0215] The various illustrative logic units and circuits described in the embodiments of the present application can be implemented or operated by a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic, a discrete hardware component, or the design of any combination thereof. The general-purpose processor can be a microprocessor, alternatively, the general-purpose processor can also be any traditional processor, controller, microcontroller or state machine. The processor can also be implemented by a combination of computing devices, such as a digital signal processor and a microprocessor, a plurality of microprocessors, one or more microprocessors in conjunction with a digital signal processor core, or any other similar configuration to implement.
[0216] The steps of the methods or algorithms described in the embodiments of the present application can be directly embedded in hardware, software units executed by a processor, or a combination of the two. The software units can be stored in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, removable disk, CD-ROM, or other storage media in any form known in the art. Exemplarily, the storage medium can be connected to the processor so that the processor can read information from the storage medium and write information to the storage medium. Alternatively, the storage medium can also be integrated into the processor. The processor and storage medium can be arranged in an ASIC.
[0217] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0218] Although the present application has been described with reference to specific features and embodiments thereof, it is apparent that various modifications and combinations may be made thereto without departing from the spirit and scope of the present application. Accordingly, this specification and the drawings are merely illustrative of the present application as defined by the appended claims and are deemed to cover any and all modifications, variations, combinations or equivalents within the scope of the present application. Obviously, those skilled in the art may make various modifications and variations to the present application without departing from the scope of the present application. Thus, the present application is intended to include such modifications and variations if they fall within the scope of the claims of the present application and their equivalents.
Claims
1. A data processing method, characterized in that: The method comprises: Generate an initial codebook; wherein the structure of the initial codebook is a d*m matrix, the initial codebook includes multiple initial sub-codebooks, the structure of each initial sub-codebook is a d*p matrix, the m is greater than p, the p is greater than 1, and the d is greater than 1; A codebook for compressing and encoding object data of a candidate object stored in an original base database, and a codeword after the compression encoding are generated based on each of the multiple initial sub-codebooks; wherein the structure of the codeword is a matrix including a plurality of codeword blocks, each column in the matrix corresponds to a codeword block, and the codeword block is a dense matrix.
2. The method according to claim 1, wherein The generating of the initial codebook comprises: Selecting m sample objects' object data from the object data of the candidate objects stored in the original database to form multiple sample sets, where each sample set includes p sample objects' object data; Each initial sub-codebook included in the initial codebook is generated according to object data of the sample object included in each sample set.
3. The method according to claim 2, wherein The step of generating, based on each initial sub-codebook in the initial codebook, a codebook for compressing and encoding the object data of the candidate object stored in the original base database, and a codeword after the compression encoding, includes: Determine, according to the subspace distance between the object data of each sample object and each initial subcodebook, the sample object data set corresponding to each initial subcodebook; For any initial sub-codebook, generating an updated sub-codebook and corresponding codeword blocks corresponding to the initial sub-codebook according to the sample object data set corresponding to the initial sub-codebook; Generating the codebook according to the updated sub-codebook corresponding to each initial sub-codebook; and generating the codeword according to the codeword block corresponding to each initial sub-codebook.
4. The method according to claim 3, wherein The step of determining, based on the subspace distance between the object data of each sample object and each initial subcodebook, a sample object data set corresponding to each initial subcodebook, includes: For object data of any sample object, determining an initial subcodebook corresponding to the object data of the sample object from a plurality of initial subcodebooks according to a subspace distance between the object data of the sample object and each initial subcodebook; According to the correspondence between the object data of the sample objects and the initial sub-codebook, a sample object data set corresponding to each initial sub-codebook is determined respectively, where the sample object data set includes the object data of the sample objects corresponding to the initial sub-codebook.
5. The method according to claim 3, wherein The generating the codeword according to the codeword blocks corresponding to each initial sub-codebook includes: Divide the codewords corresponding to each initial sub-codebook into blocks to form reference codewords; The reference codeword is quantized, and elements in the quantized reference codeword are adjusted to generate the codeword.
6. The method according to any one of claims 1 to 5, wherein: The structure of the codeword is a block diagonal matrix.
7. The method according to any one of claims 1 to 5, wherein: The method further comprises: receiving a query request and determining a query vector corresponding to the query request; According to the query vector, the codeword, and the codebook, a target object matching the query request is retrieved from a plurality of candidate objects stored in the original database.
8. The method according to claim 7, wherein Each codeword in the codeword is divided into blocks and stored in different storage areas.
9. The method according to claim 8, wherein The retrieving a target object matching the query request from a plurality of candidate objects stored in the original database according to the query vector, the codeword, and the codebook includes: determining a target storage area according to the query vector and the codebook; According to the codeword blocks stored in the target storage area, a target object matching the query request is retrieved from the multiple candidate objects.
10. The method according to claim 9, wherein The codebook includes multiple sub-codebooks, each sub-codebook corresponds to a codeword block; The determining a target storage area according to the query vector and the codebook includes: determining, based on the query vector and the codebook, first similarity information between the query vector and each sub-codebook in the codebook, wherein the first similarity information is used to represent a degree of similarity between the query vector and the sub-codebook; determining a target subcodebook from a plurality of subcodebooks included in the codebook according to first similarity information between the query vector and each subcodebook in the codebook; According to the correspondence between the sub-codebook and the codeword block, the target codeword block corresponding to the target sub-codebook is determined, and the storage area storing the target codeword block is used as the target storage area.
11. The method according to claim 10, wherein The determining, according to the query vector and the codebook, first similarity information between the query vector and each sub-codebook in the codebook includes: Determine a product of the query vector and the codebook to obtain an intermediate vector; Dividing the intermediate vector into sub-intermediate vectors corresponding to each sub-codebook respectively; Determine, according to the sub-intermediate vector corresponding to each sub-codebook, first similarity information between the query vector and each sub-codebook in the codebook.
12. The method according to claim 11, wherein The determining, based on the codeword blocks stored in the target storage area, a target object matching the query request from the plurality of candidate objects comprises: determining, based on the sub-intermediate vector corresponding to the target sub-codebook and the codeword blocks stored in the target storage area, second similarity information between the query vector and each candidate object corresponding to the codeword blocks stored in the target storage area, wherein the second similarity information is used to represent a degree of similarity between the query vector and the candidate objects corresponding to the codeword blocks stored in the target storage area; The target object is determined from candidate objects corresponding to the target sub-codebook according to the second similarity information.
13. A data processing device, characterized in that: The device comprises: An initialization unit, configured to generate an initial codebook, wherein the structure of the initial codebook is a d*m matrix, the initial codebook includes multiple initial sub-codebooks, the structure of each initial sub-codebook is a d*p matrix, the m is greater than p, the p is greater than 1, and the d is greater than 1; A processing unit is configured to generate, based on each of the multiple initial sub-codebooks, a codebook for compressing and encoding object data of a candidate object stored in an original base library, and a codeword after the compression encoding; wherein the structure of the codeword is a matrix including a plurality of codeword blocks, each column in the matrix corresponds to a codeword block, and the codeword block is a dense matrix.
14. A computing device, characterized in that The computing device comprises a memory and at least one processor, wherein the memory is configured to store a set of computer program instructions. When the processor executes the set of program instructions, the method according to any one of claims 1 to 12 is performed.
15. A computer-readable storage medium, characterized in that When the computer-readable storage medium is executed by a storage device, the storage device executes the method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Fast database search systems and methods
CN110168525A