Hamming vector retrieval method and device for relational database, medium and terminal

By constructing a Hamming vector database and using the hmcode data type and hash index table, the problem of existing databases being unable to efficiently store and retrieve high-dimensional Hamming vectors is solved, achieving efficient Hamming vector storage and retrieval.

CN115374104BActive Publication Date: 2025-11-21SHENZHEN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210783496.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-05
Publication Date
2025-11-21
Estimated Expiration
2042-07-05

AI Technical Summary

Technical Problem

Existing database systems cannot efficiently support the storage and retrieval of high-dimensional Hamming vectors, especially in disk-based database systems where traditional algorithms are inefficient.

Method used

A Hamming vector database is constructed. The high-dimensional Hamming vector is divided into low-dimensional sub-vectors using the hmcode data type and a hash index table. Candidate vector IDs are quickly queried through the hash table. The nearest neighbor vector is selected and returned based on the comparison between the number of candidate vector IDs and a preset value.

Benefits of technology

It achieves efficient high-dimensional Hamming vector retrieval, reduces storage space usage, and improves retrieval efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115374104B_ABST
    Figure CN115374104B_ABST
Patent Text Reader

Abstract

The application discloses a Hamming vector retrieval method and device of a relational database, a medium and a terminal. The method comprises the following steps: inputting a Hamming vector to be queried and a required number into a preset database; dividing the Hamming vector to obtain a plurality of sub-vectors, and generating a candidate set based on the plurality of sub-vectors; performing a hash table query on each candidate sub-vector in the candidate set to obtain a candidate vector ID, and counting the number of the candidate vector ID; comparing the number of the candidate vector ID with a preset value to obtain a comparison result, and selecting the required number of vectors with the nearest neighbors to be returned according to the comparison result. The application realizes efficient retrieval of high-dimensional Hamming vectors by using the above method, and realizes storage and calculation of high-dimensional Hamming vectors by constructing a Hamming vector database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of relational database retrieval, and more particularly to a Hamming vector retrieval method, apparatus, medium, and terminal for relational databases. Background Technology

[0002] Database systems are widely used in production environments due to their transactional, disaster recovery, and backup capabilities. Relational databases, in particular, use a relational model to organize data, storing it in rows and columns for user convenience. These rows and columns are called tables, and a set of tables constitutes a database. Users retrieve data from the database through queries, which are executable codes that limit access to specific areas within the database. The relational model can be simply understood as a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and the relationships between them.

[0003] Hamming vectors are widely used in a range of applications such as image retrieval and webpage deduplication due to their low storage and computational overhead. The features of existing multimedia files are usually represented by Hamming vectors, and the similarity between objects in multiple multimedia files can be determined by the distance between Hamming vectors. However, existing databases cannot support the retrieval of high-dimensional Hamming vectors. Summary of the Invention

[0004] In view of the shortcomings of the prior art, the purpose of this application is to provide a Hamming vector retrieval method, apparatus, medium and terminal for relational databases, aiming to solve the problem that existing databases cannot support high-dimensional Hamming vector retrieval.

[0005] To address the aforementioned technical problems, the first aspect of this application provides a Hamming vector retrieval method for relational databases, the method comprising:

[0006] Enter the Hamming vector to be queried and the required number into the preset database;

[0007] The Hamming vector is divided into several sub-vectors, and a candidate set is generated based on the several sub-vectors;

[0008] Perform a hash table lookup for each candidate subvector in the candidate set to obtain the candidate vector ID, and count the number of candidate vector IDs;

[0009] The number of candidate vector IDs is compared with a preset value to obtain a comparison result. Based on the comparison result, the required number of vectors that are the nearest neighbors are selected and returned.

[0010] As a further improvement to the technical solution, the step of inputting the Hamming vector to be queried and the required quantity into the preset database includes:

[0011] Construct a Hamming vector database, and use the constructed Hamming vector database as the preset database;

[0012] Input the Hamming vector to be queried and the required quantity into the preset database.

[0013] As a further improved technical solution, the construction of the Hamming vector database, using the completed Hamming vector database as the preset database, includes:

[0014] Define the database data type as hmcode. hmcode is used to efficiently support the storage and operation of Hamming vectors within the database.

[0015] Create several hash index tables to divide the high-dimensional Hamming vector into several low-dimensional sub-Hamming vectors. Insert the sub-Hamming vectors into the corresponding hash index tables. The first column of each hash index table is the value of the sub-Hamming vector, and the second column is the ID value of the high-dimensional Hamming vector.

[0016] As a further improved technical solution, the step of dividing the Hamming vector into several sub-vectors and generating a candidate set based on the several sub-vectors includes:

[0017] The Hamming vector is divided into several sub-vectors;

[0018] For each of the sub-vectors, a candidate vector is generated based on a preset Hamming distance. A candidate set is generated based on several of the sub-vectors, wherein all vectors with a preset Hamming distance are used as candidate vectors. The preset Hamming distance is t-1, and t is the number of times candidate vectors are generated.

[0019] As a further improved technical solution, the step of performing a hash table lookup on each candidate subvector in the candidate set to obtain the candidate vector ID, and counting the number of candidate vector IDs, includes:

[0020] For each candidate subvector in the candidate set, query the corresponding hash index table to obtain the candidate vector ID;

[0021] Count the number of all candidate vector IDs retrieved.

[0022] As a further improved technical solution, the step of comparing the number of candidate vector IDs with a preset value to obtain a comparison result, and selecting the required number of vectors to return as nearest neighbors based on the comparison result, includes:

[0023] The number of candidate vector IDs is compared with a preset value to obtain a comparison result where the number of candidate vector IDs is greater than or equal to the preset value or less than the preset value. If the number of candidate vector IDs is greater than the preset value, the corresponding candidate vector is found based on the candidate vector ID. The actual Hamming distance between the candidate vector and the Hamming vector to be queried is calculated. The candidate vectors are sorted according to the actual Hamming distance, and the nearest neighbor vector is returned based on the required number. The preset value is proportional to the number of vectors in the database.

[0024] As a further improved technical solution, after obtaining the comparison result that the number of candidate vector IDs is less than a preset value, the process of generating candidate vectors based on Hamming distance from the sub-vectors, generating a candidate set based on several sub-vectors, and comparing the number of candidate vector IDs with the preset value is repeated. For each candidate sub-vector in the candidate set, a hash table query is performed to obtain the candidate vector ID, and the number of candidate vector IDs is counted. The number of candidate vector IDs is then compared with the preset value.

[0025] A second aspect of this application provides a Hamming vector retrieval device for a relational database, comprising:

[0026] The data input module is used to input the Hamming vector to be queried and the required quantity into the preset database;

[0027] A partitioning module is used to partition the Hamming vector to obtain several sub-vectors, and generate a candidate set based on the several sub-vectors;

[0028] The query module is used to perform a hash table query on each candidate subvector in the candidate set to obtain the candidate vector ID and count the number of candidate vector IDs;

[0029] The comparison module is used to compare the number of candidate vector IDs with a preset value to obtain a comparison result, and select and return the required number of nearest neighbor vectors based on the comparison result.

[0030] A third aspect of this application provides a computer-readable storage medium storing one or more programs that can be executed by one or more processors to implement the steps in the Hamming vector retrieval method for relational databases as described above.

[0031] A fourth aspect of this application provides a terminal device, which includes: a processor, a memory, and a communication bus; the memory stores a computer-readable program that can be executed by the processor;

[0032] The communication bus enables communication between the processor and the memory;

[0033] When the processor executes the computer-readable program, it implements the steps in the Hamming vector retrieval method for relational databases as described above.

[0034] Beneficial effects: Compared with the prior art, the Hamming vector retrieval method of the relational database of the present invention includes: inputting the Hamming vector to be queried and the required number into a preset database; dividing the Hamming vector to obtain several sub-vectors, and generating a candidate set based on the several sub-vectors; performing a hash table query on each candidate sub-vector in the candidate set to obtain the candidate vector ID, and counting the number of candidate vector IDs; comparing the number of candidate vector IDs with a preset value to obtain a comparison result, and selecting and returning the nearest neighbor vectors of the required number based on the comparison result. The present invention achieves efficient retrieval of high-dimensional Hamming vectors by adopting the above method, and realizes the storage and calculation of high-dimensional Hamming vectors by constructing a Hamming vector database. Attached Figure Description

[0035] Figure 1 This is a flowchart of the Hamming vector retrieval method for relational databases according to the present invention.

[0036] Figure 2 This is a structural schematic diagram of the terminal device provided by the present invention.

[0037] Figure 3 This is a structural block diagram of the device provided by the present invention.

[0038] Figure 4 This is a retrieval diagram in the Hamming vector retrieval method for relational databases of the present invention.

[0039] Figure 5 This is a flowchart of the retrieval process in the Hamming vector retrieval method for relational databases of the present invention.

[0040] Figure 6 This is a diagram illustrating the index construction process in the Hamming vector retrieval method for relational databases of the present invention.

[0041] Figure 7 This is a schematic diagram illustrating the specific space occupancy of the Hamming vector using hmcode in the Hamming vector retrieval method for relational databases of the present invention.

[0042] Figure 8 This is a schematic diagram of the batch enumeration of subvectors in the Hamming vector retrieval method for relational databases of the present invention.

[0043] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0044] To facilitate understanding of this application, a more complete description will be provided below with reference to the accompanying drawings. Preferred embodiments of this application are shown in the drawings. However, this application can be implemented in many different forms and is not limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the disclosure of this application.

[0045] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs. The terminology used herein in the specification of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application.

[0046] The inventors discovered through research that the existing technology has the following problems:

[0047] (1) Database systems are widely used in production environments due to their transactional, disaster recovery, and backup capabilities. However, most databases cannot efficiently support the storage, computation, and querying of high-dimensional Hamming vectors. Hamming vectors are widely used in applications such as image retrieval and webpage deduplication due to their low storage and computational overhead. However, the time cost of exhaustive retrieval in Hamming vector datasets is relatively high. Efficient KNN retrieval algorithms have been proposed, but most of these algorithms are memory-based and not suitable for database systems where data is stored on disk.

[0048] like Figure 1 As shown in the embodiment of this application, a Hamming vector retrieval method for a relational database includes the following steps:

[0049] S1, input the Hamming vector to be queried and the required quantity into the preset database;

[0050] Specifically, during the retrieval process, the Hamming vector to be queried and the required number of nearest neighbor vectors are first input into the preset database, and the preset database obtains the Hamming vector to be queried and the required number.

[0051] The step of inputting the Hamming vector to be queried and the required quantity into the preset database includes the following steps:

[0052] S101, Construct a Hamming vector database and use the constructed Hamming vector database as the preset database;

[0053] S102, input the Hamming vector to be queried and the required quantity into the preset database.

[0054] The construction of the Hamming vector database, and the use of the completed Hamming vector database as the preset database, includes the following steps:

[0055] S1011 defines the data type of the database as hmcode. hmcode is used to efficiently support the storage and operation of Hamming vectors within the database.

[0056] S1012, Create several hash index tables, divide the high-dimensional Hamming vector into several low-dimensional sub-Hamming vectors, and insert the sub-Hamming vectors into the corresponding hash index tables. The first column of each hash index table is the value of the sub-Hamming vector, and the second column is the ID value of the high-dimensional Hamming vector.

[0057] Specifically, such as Figure 7 The above is a schematic diagram illustrating the space usage of a 128-dimensional Hamming vector with a length of 16 bytes using hmcode. Most databases often cannot efficiently store high-dimensional Hamming vectors. For example, a 128-dimensional Hamming vector often needs to be represented using a string type (such as '0000111010101') or an array type (such as a 4-dimensional uint32 array). However, such representations are not flexible in dimension definition, and the space overhead in the database is also relatively large. Therefore, the database data type is defined as hmcode. hmcode is used to efficiently support the storage and operation of Hamming vectors within the database. hmcode reallocates the storage method of variable-length data structures. The storage method of hmcode is as follows: a fixed header space of 4 bytes, a 2-byte variable to represent the dimension of hmcode, a 2-byte variable to store the length of the hmcode data part, and the remaining space is used to store the actual data part. This data structure definition allows for flexible definition of the length of the Hamming vector, reduces storage space usage, and facilitates calculation and retrieval, achieving the technical effect of storing Hamming vector data on disk.

[0058] Unlike traditional multi-index algorithms that use inverted index tables to find subvectors, we use hash tables in the database for fast subvector lookup. First, we create m hash index tables, where the first column of each table is the subvector value, and the second column is the ID value of the high-dimensional vector in the dataset. Then, we insert data, dividing the high-dimensional Hamming vector in the dataset into m low-dimensional sub-Hamming vectors and inserting them into the corresponding hash index tables. Simultaneously, we create a hash index in the first column to facilitate fast subvector lookup. By constructing m hash index tables, we can quickly retrieve the candidate vector ID values ​​in the database based on the candidate subvectors enumerated from the query subvector.

[0059] After the Hamming vector database is constructed, the Hamming vector to be queried and the number K of the nearest neighbor vectors to be found need to be input into the Hamming vector database. The required number K is the number of nearest neighbor vectors to be found. K is manually set when performing Hamming vector retrieval. K can be a value such as 2, 3, 4, 5, etc., and generally K is greater than 1.

[0060] Among them, the Multi-index algorithm is a memory-based, efficient Hamming vector KNN retrieval algorithm. The Multi-index algorithm stores high-dimensional vectors in multiple inverted index tables for similarity queries. Due to its efficiency and high recall rate, the Multi-index algorithm is widely used for approximate queries on Hamming distance. However, as a memory-based algorithm, it cannot be well applied to database systems where data resides on disk, and its efficiency is also insufficient. Therefore, it cannot efficiently meet the needs of storing Hamming vectors and performing similarity retrieval within a database system.

[0061] S2, the Hamming vector is divided into several sub-vectors, and a candidate set is generated based on the several sub-vectors;

[0062] Specifically, the Hamming vector database constructs a partitioning process for the input high-dimensional Hamming vectors, resulting in several low-dimensional sub-vectors. Then, it performs batch enumeration on each sub-vector to generate a candidate set.

[0063] The step of dividing the Hamming vector into several sub-vectors and generating a candidate set based on the several sub-vectors includes the following steps:

[0064] S201, Divide the Hamming vector to obtain several sub-vectors;

[0065] S202, generate candidate vectors for each sub-vector based on a preset Hamming distance, and generate a candidate set based on several sub-vectors, wherein all vectors with a preset Hamming distance are used as candidate vectors, the preset Hamming distance is t-1, and t is the number of times candidate vectors are generated.

[0066] Specifically, the input high-dimensional Hamming vector is divided into n sub-vectors, where n is a pre-set value. Assuming the dimension of the high-dimensional Hamming vector is d, then the dimension of each sub-vector is d / n. For example, if a 20-dimensional Hamming vector is divided into 4 sub-vectors q1, q2, q3, and q4, then each sub-vector has a dimension of 5. By dividing the high-dimensional Hamming vector into several low-dimensional Hamming vectors with the same dimension, the retrieval of the high-dimensional Hamming vector is achieved.

[0067] Then, as Figure 8As shown, t represents the number of times candidate vectors are generated. The number of times candidate vectors are generated is equal to the number of times step S202 is performed. For each sub-vector, candidate sub-vectors with a Hamming distance of t-1 are enumerated in batches. Unlike the traditional multi-index algorithm, t represents the number of times candidate vectors are generated. When candidate vectors are generated for the first time, t-1 = 0, and the enumerated candidate vector is only itself. When candidate vectors are generated for the second time, t is 2 and t-1 = 1. When candidate vectors are generated for the third time, t is 3 and t-1 = 2, and so on. Each time step S202 is repeated, t = t+1.

[0068] S3, perform a hash table lookup for each candidate subvector in the candidate set to obtain the candidate vector ID, and count the number of candidate vector IDs;

[0069] Specifically, the Hamming vector database performs a hash table lookup for each candidate subvector in the candidate set. The hash table is the pre-created hash index table mentioned above. Several candidate vector IDs are obtained through the lookup. The total number of candidate vector IDs is counted. The candidate vector ID is the position of the candidate vector in the database and can uniquely identify the vector, similar to a person's ID number. The candidate vector can be found by the candidate vector ID. The candidate vector ID can reduce storage space while facilitating fast retrieval.

[0070] The step of performing a hash table lookup on each candidate subvector in the candidate set to obtain the candidate vector ID, and counting the number of candidate vector IDs, includes the following steps:

[0071] S301, query the corresponding hash index table for each candidate subvector in the candidate set to obtain the candidate vector ID;

[0072] S302, count the number of all candidate vector IDs retrieved.

[0073] Specifically, for each candidate subvector in the candidate set, a query is performed in the corresponding hash index table to obtain several candidate vector IDs. The number of candidate vectors found is then counted. If a candidate subvector is matched with a corresponding candidate vector ID in the hash index table, that candidate vector ID is marked. Finally, the total number of marked candidate vector IDs is counted, and this total number is taken as the total number of candidate vector IDs found. The specific query process is as follows: for each candidate subvector, the corresponding hash index table is queried. Each candidate subvector is compared with the first column of the corresponding hash index table. If the value of the subvector in the first column of the hash index table corresponds to a candidate subvector, then the ID value of the high-dimensional vector corresponding to that subvector's value is the candidate vector ID. This high-dimensional vector ID value is marked. The total number of marked high-dimensional vector ID values ​​is counted, and this total number is taken as the total number of candidate vector IDs found.

[0074] S4, compare the number of candidate vector IDs with a preset value to obtain a comparison result, and select the required number of vectors that are the nearest neighbors to return based on the comparison result.

[0075] Specifically, the Hamming vector database compares the number of candidate vector IDs with a preset value and obtains two comparison results. The first comparison result is that the number of candidate vector IDs is greater than or equal to the preset value, and the second comparison result is that the number of candidate vector IDs is less than the preset value. The preset value is proportional to the number of vectors in the database. If the first comparison result is obtained, the K nearest neighbor vectors are returned. The number of nearest neighbor vectors K is the number of vectors input into the Hamming vector database in step S1.

[0076] The step of comparing the number of candidate vector IDs with a preset value to obtain a comparison result, and selecting the required number of vectors to return as nearest neighbors based on the comparison result, includes:

[0077] The number of candidate vector IDs is compared with a preset value to obtain a comparison result where the number of candidate vector IDs is greater than or equal to the preset value or less than the preset value. If the number of candidate vector IDs is greater than the preset value, the corresponding candidate vector is found based on the candidate vector ID. The actual Hamming distance between the candidate vector and the Hamming vector to be queried is calculated. The candidate vectors are sorted according to the actual Hamming distance, and the nearest neighbor vector is returned based on the required number. The preset value is proportional to the number of vectors in the database.

[0078] After obtaining the comparison result that the number of candidate vector IDs is less than a preset value, the process of generating candidate vectors based on Hamming distance from the sub-vectors, generating a candidate set based on several sub-vectors, and comparing the number of candidate vector IDs with the preset value is repeated. For each candidate sub-vector in the candidate set, a hash table query is performed to obtain the candidate vector ID, and the number of candidate vector IDs is counted. The process of comparing the number of candidate vector IDs with the preset value is then repeated.

[0079] Specifically, the preset value is the total number of vectors in the Hamming vector database multiplied by α, where α is pre-set and is typically 0.01. If the number of candidate vector IDs is less than the total number of vectors in the Hamming vector database multiplied by α, then steps S202, S3, and S4 are repeated. That is, candidate vectors are generated for each sub-vector based on the preset Hamming distance, and a candidate set is generated based on several sub-vectors. A hash table query is performed on each candidate sub-vector in the candidate set to obtain the candidate vector ID, and the number of candidate vector IDs is counted. The number of candidate vector IDs is compared with the preset value to obtain a comparison result. Based on the comparison result, the required number of nearest neighbor vectors are selected and returned. The repetition stops when the number of candidate vector IDs is greater than or equal to the preset value comparison result, and the K nearest Hamming vectors are returned.

[0080] Specifically, the number of times candidate vectors are generated during the first repetition of step S201 is 2, so t-1 = 1. That is, candidate subvectors with a Hamming distance of 1 are enumerated in batches for each subvector. The number of times candidate vectors are generated during the second repetition of step S201 is 3, and so on, until the number of candidate vector IDs is greater than or equal to the total number of vectors in the Hamming vector database multiplied by α. If the number of candidate vector IDs is greater than or equal to the total number of vectors in the Hamming vector database multiplied by α, then the corresponding candidate vector is found according to each candidate vector ID, and the actual Hamming distance between the Hamming vector to be queried and the candidate vectors is calculated. Then, they are sorted in ascending order according to the Hamming distance over time, and the top K vectors with the smallest Hamming distance are returned. The number of nearest neighbor vectors K required is the input to the Hamming vector database in step S1. Thus, the KNN retrieval of high-dimensional Hamming vectors in the Hamming vector database is realized.

[0081] like Figure 3 As shown, based on the above-described Hamming vector retrieval method for relational databases, this embodiment provides a Hamming vector retrieval device for relational databases, including:

[0082] Data input module 1 is used to input the Hamming vector to be queried and the required quantity into the preset database;

[0083] The partitioning module 2 is used to partition the Hamming vector to obtain several sub-vectors, and generate a candidate set based on the several sub-vectors;

[0084] The query module 3 is used to perform a hash table query on each candidate subvector in the candidate set to obtain the candidate vector ID and count the number of candidate vector IDs;

[0085] The comparison module 4 is used to compare the number of candidate vector IDs with a preset value to obtain a comparison result, and select the required number of vectors that are the nearest neighbors to return based on the comparison result.

[0086] Furthermore, it is worth noting that the working process of the Hamming vector retrieval device based on a relational database provided in this embodiment is the same as that of the Hamming vector retrieval method for relational databases described above. For details, please refer to the working process of the Hamming vector retrieval method for relational databases, which will not be repeated here.

[0087] Based on the Hamming vector retrieval method for relational databases described above, this embodiment provides a computer-readable storage medium storing one or more programs that can be executed by one or more processors to implement the steps in the Hamming vector retrieval method for relational databases as described in the above embodiment.

[0088] like Figure 2 As shown, based on the Hamming vector retrieval method for relational databases described above, this application also provides a terminal device, which includes at least one processor 20; a display screen 21; and a memory 22, and may further include a communications interface 23 and a bus 24. The processor 20, display screen 21, memory 22, and communications interface 23 can communicate with each other via the bus 24. The display screen 21 is configured to display a preset user guide interface in the initial setup mode. The communications interface 23 can transmit information. The processor 20 can call logical instructions in the memory 22 to execute the methods described in the above embodiments.

[0089] Furthermore, the logical instructions in the aforementioned memory 22 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium.

[0090] The memory 22, as a computer-readable storage medium, can be configured to store software programs, computer-executable programs, such as program instructions or modules corresponding to the methods in the embodiments of this disclosure. The processor 20 executes functional applications and data processing by running the software programs, instructions, or modules stored in the memory 22, thereby implementing the methods in the above embodiments.

[0091] The memory 22 may include a program storage area and a data storage area. The program storage area may store the operating system and application programs required for at least one function; the data storage area may store data created based on the use of the terminal device. Furthermore, the memory 22 may include high-speed random access memory (RAM) and non-volatile memory. Examples include various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks, as well as transient storage media.

[0092] Compared to existing technologies, the Hamming vector retrieval method for relational databases of the present invention includes: inputting the Hamming vector to be queried and the required quantity into a preset database; dividing the Hamming vector into several sub-vectors, and generating a candidate set based on the several sub-vectors; performing a hash table query on each candidate sub-vector in the candidate set to obtain a candidate vector ID, and counting the number of candidate vector IDs; comparing the number of candidate vector IDs with a preset value to obtain a comparison result, and selecting and returning the required number of nearest neighbors based on the comparison result. The present invention achieves efficient retrieval of high-dimensional Hamming vectors by employing the above method, and realizes the storage and computation of high-dimensional Hamming vectors by constructing a Hamming vector database.

[0093] It should be understood that the application of the present invention is not limited to the examples above. Those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the protection scope of the appended claims.

Claims

1. A Hamming vector retrieval method for relational databases, characterized in that, The method includes: Enter the Hamming vector to be queried and the required number into the preset database; The Hamming vector is divided into several sub-vectors, and a candidate set is generated based on the several sub-vectors; Perform a hash table lookup for each candidate subvector in the candidate set to obtain the candidate vector ID, and count the number of candidate vector IDs; The number of candidate vector IDs is compared with a preset value to obtain a comparison result. Based on the comparison result, the required number of vectors that are the nearest neighbors are selected and returned. The step of inputting the Hamming vector to be queried and the required quantity into the preset database includes: Construct a Hamming vector database, and use the constructed Hamming vector database as the preset database; Input the Hamming vector to be queried and the required quantity into the preset database; The construction of the Hamming vector database, and the use of the completed Hamming vector database as the preset database, includes: Define the database data type as hmcode. hmcode is used to efficiently support the storage and operation of Hamming vectors within the database. Create several hash index tables to divide the high-dimensional Hamming vector into several low-dimensional sub-Hamming vectors. Insert the sub-Hamming vectors into the corresponding hash index tables. The first column of each hash index table is the value of the sub-Hamming vector, and the second column is the ID value of the high-dimensional Hamming vector.

2. The Hamming vector retrieval method for a relational database according to claim 1, characterized in that, The step of dividing the Hamming vector into several sub-vectors and generating a candidate set based on the several sub-vectors includes: The Hamming vector is divided into several sub-vectors; For each of the sub-vectors, a candidate vector is generated based on a preset Hamming distance. A candidate set is generated based on several of the sub-vectors, wherein all vectors with a preset Hamming distance are used as candidate vectors. The preset Hamming distance is t-1, and t is the number of times candidate vectors are generated.

3. The Hamming vector retrieval method for a relational database according to claim 2, characterized in that, The step of performing a hash table lookup on each candidate subvector in the candidate set to obtain the candidate vector ID, and counting the number of candidate vector IDs, includes: For each candidate subvector in the candidate set, query the corresponding hash index table to obtain the candidate vector ID; Count the number of all candidate vector IDs retrieved.

4. The Hamming vector retrieval method for a relational database according to claim 3, characterized in that, The step of comparing the number of candidate vector IDs with a preset value to obtain a comparison result, and selecting the required number of vectors to return as nearest neighbors based on the comparison result, includes: The number of candidate vector IDs is compared with a preset value to obtain a comparison result where the number of candidate vector IDs is greater than or equal to the preset value or less than the preset value. If the number of candidate vector IDs is greater than the preset value, the corresponding candidate vector is found based on the candidate vector ID. The actual Hamming distance between the candidate vector and the Hamming vector to be queried is calculated. The candidate vectors are sorted according to the actual Hamming distance, and the nearest neighbor vector is returned based on the required number. The preset value is proportional to the number of vectors in the database.

5. The Hamming vector retrieval method for a relational database according to claim 3, characterized in that, After obtaining the comparison result that the number of candidate vector IDs is less than a preset value, the process of generating candidate vectors based on Hamming distance from the sub-vectors, generating a candidate set based on several sub-vectors, and comparing the number of candidate vector IDs with the preset value is repeated. For each candidate sub-vector in the candidate set, a hash table query is performed to obtain the candidate vector ID, and the number of candidate vector IDs is counted. The process of comparing the number of candidate vector IDs with the preset value is then repeated.

6. A Hamming vector retrieval device for a relational database, used to implement the Hamming vector retrieval method for a relational database as described in any one of claims 1-5, characterized in that, include: The data input module is used to input the Hamming vector to be queried and the required quantity into the preset database; A partitioning module is used to partition the Hamming vector to obtain several sub-vectors, and generate a candidate set based on the several sub-vectors; The query module is used to perform a hash table query on each candidate subvector in the candidate set to obtain the candidate vector ID and count the number of candidate vector IDs; The comparison module is used to compare the number of candidate vector IDs with a preset value to obtain a comparison result, and select and return the required number of nearest neighbor vectors based on the comparison result.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores one or more programs, which can be executed by one or more processors to implement the steps in the Hamming vector retrieval method for relational databases as described in any one of claims 1-5.

8. A terminal device, characterized in that, include: Processor, memory, and communication bus; The memory stores a computer-readable program that can be executed by the processor; The communication bus enables communication between the processor and the memory; When the processor executes the computer-readable program, it implements the steps in the Hamming vector retrieval method for relational databases as described in any one of claims 1-5.