Index construction method, device, vector search method and retrieval system
By introducing the second representative point into the retrieval system, the problem of low retrieval accuracy caused by only considering the center point in the existing technology is solved. By calculating the distance between the query vector and the first and second representative points, the accuracy of the retrieval is improved.
Patent Information
- Application Number
- CN202210406518.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-18
- Publication Date
- 2025-09-30
- Estimated Expiration
- 2042-04-18
AI Technical Summary
When constructing an inverted index, existing retrieval systems only consider the central representative point of the cluster set, resulting in low accuracy of retrieval results and failure to find target vectors of edge points far from the center point.
During the index construction process, the first cluster set where the target vector is located is determined, and at least one second representative point that meets the preset conditions is determined for it. An index association is established between the target vector and the first and second representative points, and a more accurate target vector is obtained by calculating the distance between the query vector and these representative points.
This improves the accuracy of retrieval, avoids the problem of inaccurate retrieval results caused by only considering the center point and missing the edge points, and ensures that the target vector corresponding to the query vector can be obtained more accurately.
Smart Images

Figure CN114791966B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data retrieval technology, and in particular to an index construction method, device, vector search method and retrieval system. Background Art
[0002] With the rapid growth of data, data retrieval is widely used in fields such as image, video, speech, and protein molecular structure retrieval. Since various data, such as image data, can be abstracted as high-dimensional feature vectors, the similarity between data can be quantified as the distance between feature vectors in vector space. For example, the closer the distance between two feature vectors, the higher the similarity between the original data corresponding to the two feature vectors. Therefore, data retrieval can be transformed into a vector search in vector space, that is, the process of searching for several data similar to the query data in the database is transformed into the process of searching for several feature vectors in the database that are closest to the query vector corresponding to the query data.
[0003] At present, some retrieval systems will construct an inverted index for the database to facilitate user retrieval. Among them, the method of constructing the inverted index is to first cluster the feature vectors corresponding to each data in the database, such as through k-means clustering, to divide the entire vector space into several cluster sets, each cluster set has a corresponding representative point, and each feature vector is classified into the cluster set corresponding to the representative point closest to itself. In this way, when searching for a query vector, the system will determine the representative point closest to the query vector based on the distance between the query vector and multiple representative points, and search all the feature vectors in the cluster set where the representative point is located. It can be understood that searching all feature vectors is to obtain the distance between each feature vector and the query vector. Then, several feature vectors in the cluster set that are closer to the query vector are used as search results.
[0004] However, since the retrieval system determines the representative point closest to the query vector, and then only uses several feature vectors in the cluster set where this representative point is located that are closer to the query vector as search results, there may be a situation where there are several feature vectors in the cluster set where other representative points are located that are closer to the query vector, resulting in the failure to obtain a more accurate target vector of the query vector, resulting in lower accuracy of the retrieval results. Summary of the Invention
[0005] To solve the problem of low accuracy of retrieval results of vector retrieval methods, embodiments of the present application provide an index construction method, device, vector search method, and retrieval system.
[0006] In a first aspect, an embodiment of the present application provides an index construction method, comprising:
[0007] Determine a target vector and a first cluster set in which the target vector is located, wherein the first cluster set has a corresponding first representative point;
[0008] Determining at least one second representative point that meets a preset condition for the first cluster set;
[0009] An index association is established between the target vector and the first representative point and the second representative point respectively.
[0010] It can be understood that the index construction method provided in the embodiment of the present application can determine at least one second representative point that is farther away from the first representative point of each cluster set, that is, an edge point, in addition to determining the first representative point. In this way, during the retrieval process, the distance between the query vector and the first representative point and the second representative point can be compared, that is, the distance between the edge point farther away from the center point and the query vector is taken into account, thereby avoiding the problem in the prior art that the target vector is an edge point, while the prior art center only considers the distance to the center point, resulting in a more accurate target vector not being found. That is, during the query process, the distance between the first representative point and the second representative point and the query vector is calculated respectively to query the corresponding target cluster set, so that the target vector corresponding to the query vector can be obtained more accurately, which can effectively avoid the problem of low search accuracy caused by the aforementioned representative point of the cluster set not being able to fully represent all the feature vectors in the cluster set, thereby effectively improving the search accuracy.
[0011] It can be understood that the target vector in the first cluster set mentioned in the embodiment of the present application can be any vector in the first cluster set.
[0012] It can be understood that the above-mentioned edge point may be an edge feature vector in the first cluster set, that is, a feature vector that is far away from the first representative point of the first cluster set.
[0013] In a possible implementation of the first aspect, determining at least one second representative point that meets a preset condition for the first cluster set includes:
[0014] Determining a first distance between each feature vector in the first cluster set and the first representative point;
[0015] A first sequence is determined from the eigenvectors according to the first distance, and a preset number of eigenvectors in the first sequence are used as the second representative points.
[0016] It can be understood that in an embodiment of the present application, the second representative point can be determined based on the distance between each feature vector in the first cluster set and the first representative point, so that the feature vector farther away from the first representative point can be used as the second representative point, making the selection of the second representative point more accurate.
[0017] In a possible implementation of the first aspect, determining a first sequence from the feature vectors based on the distance, and using a preset number of feature vectors in the first sequence as the second representative points includes:
[0018] sorting the eigenvectors from largest to smallest according to the first distance to obtain the first sequence;
[0019] The first preset number of feature vectors in the first sequence are used as the second representative points.
[0020] It is understood that in the embodiments of the present application, the eigenvectors in the first cluster set can be sorted from farthest to closest based on the distance between each eigenvector and the first representative point, according to their proximity to the first representative point. This can facilitate the selection of corresponding second representative points based on a set number. For example, if the set number of second representative points is five, the first five eigenvectors in the sorted first sequence can be directly used as the second representative points.
[0021] In a possible implementation of the first aspect, determining a first sequence from the feature vectors based on the first distance, and using a preset number of feature vectors in the first sequence as the second representative points includes:
[0022] Taking the feature vectors whose first distance is greater than the set distance as a first sequence;
[0023] using a preset number of feature vectors in the first sequence as the second representative points;
[0024] Alternatively, the eigenvectors in the first sequence are sorted from far to near according to the first distance, and a preset number of eigenvectors before the sorting are determined as the second representative points.
[0025] It is understood that in the embodiments of the present application, the first sequence can be obtained based on feature vectors in the first cluster set whose distance from the first representative point is greater than a set distance. That is, the feature vectors in the first sequence are vectors that are farther from the first representative point and greater than the set distance. This can make the method for selecting the second cluster set more standardized and simple. For example, the second representative point can be obtained by simply setting a corresponding distance threshold parameter in the algorithm for selecting the second representative point.
[0026] In a possible implementation of the first aspect, determining at least one second representative point that meets a preset condition for the first cluster set includes:
[0027] determining at least one second cluster set adjacent to the first cluster set among other cluster sets except the first cluster set;
[0028] Obtaining a first distance between each feature vector in the first cluster set and a first representative point of the first cluster set; and a second distance between each feature vector and a first representative point of each second cluster set;
[0029] For each of the feature vectors, the first sequence corresponding to each second cluster set is obtained according to the first distance and the second distance, and a preset number of feature vectors in the first sequence are used as the second representative points.
[0030] It can be understood that the greater the distance between each eigenvector in each first cluster set and the first representative point of each first cluster set, the farther the eigenvector is from the center of the first cluster set, and the more likely it is to become an edge point of the center of the first cluster; the second cluster set is a cluster set closer to the first cluster set, and the second distance to at least one adjacent second cluster set is obtained. When the second distance is smaller, it means that the eigenvector is closer to the second cluster set, that is, closer to the edge of the first cluster set, so the second representative point can be determined more accurately and reasonably based on the first distance and the second distance.
[0031] In a possible implementation of the first aspect, for each feature vector, obtaining the first sequence corresponding to each second cluster set according to the first distance and the second distance, and using a preset number of feature vectors in the first sequence as second representative points includes:
[0032] The eigenvectors are sorted from large to small according to the sum of the first distance and the second distance to obtain a first sequence, and a preset number of eigenvectors in the first sequence are used as second representative points.
[0033] It can be understood that the first sequence is obtained by sorting the sum of the first distance and the second distance from large to small. The feature vector with the larger sum of the distance in the obtained first sequence is the feature vector that is farther from the first representative point of the first cluster set and also farther from the first representative point of the second cluster set. That is, the feature vector may be located at the edge point in the opposite direction from the first representative point of the first representative point to the second representative point. When the first sequence corresponding to the second cluster set in each direction of the first cluster set is obtained, the edge points in each direction of the first cluster set can be obtained. In this way, using the edge points in each direction of the first cluster set as the second representative point can effectively improve the search accuracy.
[0034] In a possible implementation of the first aspect, determining at least one second representative point that meets a preset condition for the first cluster set includes:
[0035] determining at least one second cluster set adjacent to the first cluster set among other cluster sets except the first cluster set;
[0036] Obtaining a second distance between each feature vector in the first cluster set and the first representative point of each second cluster set;
[0037] For each of the feature vectors, a first sequence corresponding to each second cluster set is obtained according to the second distance, and a preset number of feature vectors in the first sequence are used as second representative points.
[0038] It can be understood that the smaller the second distance is, the closer the feature vector is to the second cluster set, that is, the closer it is to the edge of the first cluster set, so the second representative point, that is, the edge point of the first cluster set, can be determined more accurately according to the second distance.
[0039] In a possible implementation of the first aspect, obtaining, for each of the feature vectors according to the second distance, the first sequence corresponding to each second cluster set, and using a preset number of feature vectors in the first sequence as second representative points includes:
[0040] The eigenvectors are sorted from small to large according to the second distance, a first sequence corresponding to each second cluster set is obtained, and a first preset number of eigenvectors in the first sequence are used as second representative points.
[0041] In a possible implementation of the first aspect, determining at least one second cluster set adjacent to the first cluster set among cluster sets other than the first cluster set includes:
[0042] Obtaining the distance between the representative points corresponding to each of the other cluster sets and the first representative point corresponding to the first cluster set;
[0043] According to the distance, a second sequence is determined from cluster sets other than the first cluster set, and a preset number of cluster sets in the second sequence are determined as second cluster sets.
[0044] In a possible implementation of the first aspect, determining the first cluster set in which the target vector belongs includes:
[0045] Obtaining the distance between the target vector and the first representative points corresponding to all cluster sets;
[0046] Among all cluster sets, the cluster set with the shortest distance between the corresponding first representative point and the target vector is used as the first cluster set where the target vector is located.
[0047] It can be understood that in the embodiment of the present application, based on the distance between the target vector and the first representative point corresponding to all cluster sets, the cluster set with the closest distance between the target vector and the representative point corresponding to the cluster set is used as the first cluster set where the target vector is located, so as to more conveniently determine the cluster set where the target vector is located based on the distance between the representative point and the query vector, thereby finding the target vector more efficiently.
[0048] In a possible implementation of the first aspect above, the distance includes at least one of the following: Euclidean distance, inner product distance, and Hamming distance.
[0049] It can be understood that the distance in the embodiment of the present application includes Euclidean distance and inner product distance, which is just a description of the distance and can also be represented by any other feasible distance.
[0050] In a second aspect, an embodiment of the present application provides an index construction device, comprising:
[0051] A first determining unit is configured to determine a target vector and a first cluster set in which the target vector is located, wherein the first cluster set has a corresponding first representative point;
[0052] The second determining unit is configured to determine at least one second representative point that meets a preset condition for the first cluster set.
[0053] An association unit is used to establish index associations between the target vector and the first representative point and the second representative point respectively.
[0054] In a third aspect, an embodiment of the present application provides a vector search method, comprising:
[0055] Get the query vector;
[0056] Obtaining a first distance between the query vector and a first representative point and a second representative point corresponding to each cluster set in the database;
[0057] determining, based on the first distance, at least one representative point corresponding to the query vector, and taking the cluster set corresponding to the at least one representative point as a target cluster set;
[0058] Obtaining a second distance between each feature vector in the target cluster set and the query vector;
[0059] A target vector corresponding to the query vector is determined according to the second distance.
[0060] The vector search method provided in the embodiments of the present application can compare the distance between the query vector and both the first representative point and the second representative point during the retrieval process. This means that the distance between the query vector and edge points that are farther from the center point is taken into account, thereby avoiding the problem in the prior art where the target vector is an edge point, while the prior art only considers the distance to the center point, resulting in a failure to find a more accurate target vector. Specifically, during the query process, the edge points are used as second representative points, and the distances between them and the query vector are calculated in combination with the first representative points to query the corresponding target cluster set. This allows for more accurate acquisition of the target vector corresponding to the query vector, effectively avoiding the aforementioned problem of low search accuracy caused by the representative points of the cluster set not being able to fully represent all the feature vectors in the cluster set, thereby effectively improving search accuracy.
[0061] In a possible implementation of the third aspect, the method further includes: determining a target vector corresponding to the query vector based on the distance; including:
[0062] The feature vector whose distance is within the set range is used as the target vector corresponding to the query vector.
[0063] It can be understood that using a feature vector whose distance between the query vector and a feature vector in the target cluster set is within a set range as the target vector corresponding to the query vector can ensure the similarity between the target vector and the query vector.
[0064] In a fourth aspect, an embodiment of the present application provides a search device, applied to a database, comprising:
[0065] A first acquisition unit, configured to acquire a query vector;
[0066] A second acquiring unit, configured to acquire a distance between the query vector and a first representative point and a second representative point corresponding to each cluster set in the database;
[0067] A first determining unit is configured to determine a representative point closest to the query vector, and use a cluster set corresponding to the representative point closest to the query vector as a target cluster set;
[0068] A third acquiring unit is configured to acquire a distance between each feature vector in the target cluster set and the query vector;
[0069] The second determining unit is configured to determine a target vector corresponding to the query vector according to the distance.
[0070] In a fifth aspect, an embodiment of the present application provides a retrieval system, comprising the above-mentioned index construction device and / or the above-mentioned search device.
[0071] In a sixth aspect, an embodiment of the present application provides an index structure comprising a representative point item and an inverted file item; the representative point item comprises a first representative point and at least one second representative point corresponding to each cluster set in a database, and the inverted file item comprises each inverted file corresponding to each cluster set;
[0072] The inverted file includes each feature vector in the cluster set corresponding to the inverted file.
[0073] In the seventh aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing instructions executed by one or more processors of the electronic device, and a processor, which is one of the one or more processors of the electronic device, for executing the index construction method described in any one of the first aspects of the claim or the vector search method described in any one of the third aspects.
[0074] In an eighth aspect, an embodiment of the present application provides a readable medium, characterized in that instructions are stored on the readable medium, which, when executed on an electronic device, enables the machine to execute the index construction method described in any one of the first aspects or the vector search method described in any one of the third aspects.
[0075] In a ninth aspect, an embodiment of the present application provides a computer program product, comprising instructions, wherein the instructions are used to implement the index construction method described in any one of the first aspects or the vector search method described in any one of the third aspects.
[0076] Based on the above solution, this application has the following beneficial effects:
[0077] The index construction method provided by the present application provides multiple ways to accurately select the second representative point, and can realize the selection of edge points in each direction of the first cluster set as the second representative point, and establish an index association between each feature vector and the corresponding first representative point and the second representative point. During the retrieval process, the distance between the query vector and the first representative point and the second representative point can be compared, and the target cluster set can be determined based on the comparison result. In this way, the target vector corresponding to the query vector can be obtained more accurately, which can avoid searching only the cluster set to which the first representative point that is closer to the query vector belongs, and omitting the target vector in the cluster set to which the first representative point that is farther away from the query vector belongs, thereby effectively improving the search accuracy. BRIEF DESCRIPTION OF THE DRAWINGS
[0078] Figure 1a According to some embodiments of the present application, a schematic diagram of an image database S is shown;
[0079] Figure 1b According to some embodiments of the present application, a schematic diagram of constructing an inverted index for an image database S is shown;
[0080] Figure 2 According to some embodiments of the present application, a schematic diagram of determining a second cluster set of cluster set S1 is shown;
[0081] Figure 3a According to some embodiments of the present application, a schematic diagram of obtaining a distance between a feature vector X1 and a first representative point of a second cluster set is shown;
[0082] Figure 3b According to some embodiments of the present application, a schematic diagram of obtaining a distance between a feature vector X1 and a first representative point of a second cluster set is shown;
[0083] Figure 4 According to some embodiments of the present application, a schematic diagram of determining a second cluster set of cluster set S1 is shown;
[0084] Figure 5a According to some embodiments of the present application, a schematic diagram of representative points of a database S is shown;
[0085] Figure 5b According to some embodiments of the present application, a schematic diagram of an index structure corresponding to a database S is shown;
[0086] Figure 6a According to some embodiments of the present application, a schematic diagram of querying representative points in a database S is shown;
[0087] Figure 6bAccording to some embodiments of the present application, a schematic diagram of obtaining a target feature vector in a database S is shown;
[0088] Figure 7 According to some embodiments of the present application, a flowchart of an index construction method is shown;
[0089] Figure 8 According to some embodiments of the present application, a flowchart of a search method is shown;
[0090] Figure 9 According to some embodiments of the present application, a schematic diagram of an index construction device is shown;
[0091] Figure 10 According to some embodiments of the present application, a schematic diagram of a search device is shown;
[0092] Figure 11 According to some embodiments of the present application, a schematic diagram of a retrieval system is shown;
[0093] Figure 12 According to some embodiments of the present application, a block diagram of an electronic device is shown. DETAILED DESCRIPTION
[0094] The illustrative embodiments of the present application include, but are not limited to, an index building method, apparatus, data system, and search method.
[0095] As mentioned above, the accuracy of the search results obtained by constructing an inverted index in the current database is relatively low.
[0096] For example, Figure 1a FIG. 1 is a schematic diagram of an image database S in a retrieval system, where the database S includes feature vectors corresponding to each image. Figure 1b The diagram in Figure 1 is a schematic diagram of constructing an inverted index for the image database S. Figure 1b As shown, first, each feature vector in the database S is distributed into four cluster sets through clustering processing, namely cluster set S1, cluster set S2, cluster set S3 and cluster set S4, among which cluster set S1 has a corresponding representative point C1, cluster set S2 has a corresponding representative point C2, cluster set S3 has a corresponding representative point C3, and cluster set S4 has a corresponding representative point C4.
[0097] It is understood that the representative point mentioned in the embodiments of the present application can be the center point of the cluster set, that is, the arithmetic mean of each point (each eigenvector) in the cluster set. Alternatively, the center point can be a point whose distance difference from each point in the cluster set is within a preset range; or it can be a point determined based on other rules.
[0098] When performing vector retrieval on the query vector A corresponding to the query image based on the above database S, the retrieval system will determine the distance between each representative point and the query vector A, for example, Figure 1b As shown, the retrieval system determines that the distance between representative point C1 and query vector A is d1, the distance between representative point C2 and query vector A is d2, the distance between representative point C3 and query vector A is d3, and the distance between representative point C4 and query vector A is d4. Assuming that d4>d3>d1>d2, the system determines that the representative point closest to query vector A among the four representative points is representative point C2. It then searches each feature vector in cluster set S2 where representative point C2 resides. It can be understood that searching each feature vector is to obtain the distance between each feature vector and query vector A. Feature vectors Y1 and Y2 in cluster set S2 that are closer to query vector A or within a set distance range are used as target vectors for query vector A. The original image data corresponding to the target vectors is then output to the client.
[0099] However, if Figure 1b As shown, in fact, the feature vector X1 in the cluster set S1 is the feature vector closest to the query vector A in the database S. However, since the representative point C1 of the cluster set S1 is not the closest to the query vector, the system does not search the feature vectors in the cluster set S1, resulting in the failure to obtain the accurate target vector of the query vector A, resulting in the omission of the most accurate retrieval result, affecting the accuracy of the retrieval.
[0100] To solve the above problems, an embodiment of the present application provides an index construction method, which specifically includes: obtaining the feature vectors corresponding to each data in the database to be indexed; clustering the feature vectors to obtain multiple cluster sets, each cluster set has a corresponding first representative point; assigning each feature vector to a first cluster set corresponding to the first representative point closest to each feature vector; determining at least one second representative point that meets preset conditions for the first cluster set; for each target vector in the cluster set, establishing an index association between the target vector and the first representative point and the second representative point in the cluster set.
[0101] It can be understood that the first representative point may be the center point of the corresponding cluster set, and the second representative point may be a point in the cluster set that is farther from the center point, or an edge point in the cluster set.
[0102] It is understood that the above clustering processing method can be a clustering method such as K-means. Among them, the K-means clustering method can first preset an arbitrary number of cluster sets and the first representative points corresponding to the cluster sets, then obtain the distance between each feature vector in the database and the first representative point corresponding to each cluster set; and assign each feature vector to the cluster set corresponding to the first representative point with the closest distance.
[0103] For any cluster set, such as the first cluster set, there are multiple ways to determine at least one second representative point that meets the preset conditions. The following examples introduce several of them:
[0104] In the first feasible scheme, the method for determining at least one second representative point that meets the preset conditions can be: obtaining the first distance between the first representative point of the first cluster set and all the feature vectors in the first cluster set; sorting the feature vectors from far to near according to the first distance to obtain the first sequence corresponding to the first cluster set; determining the first preset number of feature vectors in the first sequence as the second representative points in the cluster set.
[0105] It can be understood that in an embodiment of the present application, the second representative point can be determined based on the distance between each feature vector in the first cluster set and the first representative point, so that the feature vector farther away from the first representative point can be used as the second representative point, making the selection of the second representative point more accurate.
[0106] In the embodiment of the present application, the eigenvectors in the first cluster set are sorted from farthest to closest based on the distance between each eigenvector and the first representative point, that is, based on how close each eigenvector is to the first representative point. This makes it easier to select the corresponding second representative points based on the set number. For example, if the set number of second representative points is five, the first five eigenvectors in the sorted first sequence can be directly used as the second representative points.
[0107] In a second feasible scheme, the method for determining at least one second representative point that meets the preset conditions can be: obtaining the first distance between the first representative point of the first cluster set and all the feature vectors in the first cluster set; taking the feature vectors whose first distance is greater than the set distance as the feature vectors in the first sequence, and then taking a preset number of feature vectors in the first sequence as the second representative points, or sorting the feature vectors in the first sequence from far to near according to the first distance, and taking the first preset number of feature vectors in the sorting as the second representative points.
[0108] It is understood that in the embodiments of the present application, the first sequence can be obtained based on feature vectors in the first cluster set whose distance from the first representative point is greater than a set distance. That is, the feature vectors in the first sequence are vectors that are farther from the first representative point and greater than the set distance. This can make the method for selecting the second cluster set more standardized and simple. For example, the second representative point can be obtained by simply setting a corresponding distance threshold parameter in the algorithm for selecting the second representative point.
[0109] In a third feasible scheme, the method for determining at least one second representative point that meets the preset conditions can be: determining at least one second cluster set adjacent to the first cluster set in cluster sets other than the first cluster set; obtaining the distance between each feature vector in the first cluster set and the first representative point of each second cluster set; sorting the feature vectors from near to far according to the distance, and obtaining the first sequence corresponding to each second cluster set; and taking the first set number of feature vectors in the first sequence as the second representative points.
[0110] It can be understood that the smaller the second distance is, the closer the feature vector is to the second cluster set, that is, the closer it is to the edge of the first cluster set. Therefore, the above method of obtaining the second representative point by the distance between each feature vector in the first cluster combination and each adjacent second cluster set is convenient for obtaining the edge points of the first cluster set in various directions, and taking the edge points of the first cluster set in various directions as the second representative points. It is convenient for determining the representative point closest to the query vector based on the distance between the second representative point and the first representative point and the query vector during retrieval, and searching the cluster set corresponding to the representative point. For query vectors that are far away from the first representative point of each cluster set but close to the second representative point, that is, the edge point, the probability of the target vector being found can be increased during the query process, effectively improving the search accuracy.
[0111] Among them, the method for obtaining at least one second cluster set adjacent to the first cluster set can be: sorting each cluster set in the above-mentioned multiple cluster sets except the first cluster set from near to far according to the distance between the first representative point of each cluster set and the first representative point of the first cluster set, and obtaining the second sequence corresponding to the first cluster set; and taking the first preset number of cluster sets in the second sequence as the second cluster set adjacent to the first cluster set.
[0112] The following is the aforementioned Figure 1b Taking the first cluster set S1 in the example, the method of obtaining the second representative point in the first cluster set S1 is introduced:
[0113] First, at least one second cluster set adjacent to the first cluster set S1 can be obtained. The method of obtaining at least one second cluster set adjacent to the first cluster set S1 can be: obtaining the distance between the first representative points of the other three cluster sets except the cluster set S1 and the first representative point C1 of the first cluster set S1. For example, Figure 2 As shown, the distance d5 between the first representative point C2 of cluster set S2 and the first representative point C1 of the first cluster set S1 can be obtained, the distance d6 between the first representative point C3 of cluster set S3 and the first representative point C1 of the first cluster set S1 can be obtained, and the distance d7 between the first representative point C4 of cluster set S4 and the first representative point C1 of the first cluster set S1 can be obtained. Then, according to the distance between the first representative point of each of the three cluster sets and the first representative point C1 of the first cluster set S1, the three cluster sets are sorted from near to far to obtain the second sequence corresponding to the first representative point C1. Assuming that d7 < d5 < d6, the second sequence corresponding to the first representative point C1 is cluster set S4 - cluster set S2 - cluster set S3. At this time, the first representative point C1 is indexed and associated with the first preset number of cluster sets in the second sequence. Assuming that the preset number is 2, cluster set S2 and cluster set S4 can be regarded as the adjacent second cluster sets of the first cluster set S1.
[0114] Then, the distance between each feature vector in the first cluster set S1 and the first representative point C2 of the second cluster set S2, and the distance between each feature vector in the first cluster set S1 and the first representative point C4 of the second cluster set S4 are obtained. Figure 3a As shown in , for the feature vector X1, the distance d2_1 between the feature vector X1 in the first cluster set S1 and the first representative point C2 of the second cluster set S2 is obtained, and the distances between other feature vectors and the first representative point C2 are not repeated here; according to the distance between each feature vector and the first representative point C2, each feature vector is sorted from near to far. Assuming that the first sequence obtained by sorting the 16 feature vectors in the first cluster set S1 from far to near according to the distance is X1-X3-X5-......-X16. Assuming that the preset number of second representative points of the corresponding cluster set obtained according to each neighboring set is one, the first feature vector in the first sequence corresponding to the second cluster set S2, that is, the feature vector X1, can be used as the second representative point. At the same time, the distance between each feature vector in the first cluster set S1 and the first representative point C4 of the second cluster set S4 is obtained, as shown Figure 3aAs shown in , for feature vector X1, the distance d4_1 between feature vector X1 in the first cluster set S1 and the first representative point C4 of the second cluster set S4 is obtained. The distances between other feature vectors and the first representative point C4 are not repeated here. According to the distance between each feature vector and the first representative point C4, each feature vector is sorted from near to far. Assuming that the first sequence obtained by sorting the 16 feature vectors in the first cluster set S1 from near to far according to the distance is X7-X8-X1-......-X14. Assuming that the preset number of second representative points of the corresponding cluster set obtained according to each neighboring set is one, the first feature vector in the first sequence corresponding to the fourth cluster set S4, that is, feature vector X7, can be used as the second representative point.
[0115] It is understood that the above method of obtaining the adjacent cluster sets of the first cluster set, i.e., the second cluster set, by sorting the representative points of each cluster set according to the distance between the first representative point of the first cluster set is merely illustrative. Alternatively, the embodiment of the present application may use other methods to obtain the adjacent cluster sets of the first cluster set, i.e., the second cluster set.
[0116] Among them, the method for obtaining the second cluster set can also be: the cluster sets in the second sequence are composed of cluster sets whose distances between the first representative points of each cluster set except the first cluster set in the above-mentioned multiple cluster sets and the first representative point of the first cluster set are less than the set distance; and then any preset number of cluster sets in the second sequence are used as the second cluster set, or the distances between the first representative points of each cluster set in the second sequence and the first representative point of the first cluster set are sorted from near to far, and the first preset number of cluster sets in the sorting are used as the second cluster set.
[0117] For example, Figure 2As shown, a method for determining a second cluster set adjacent to cluster set S1 may be: first, obtain the distances between the first representative points of cluster sets other than cluster set S1 and the first representative point of cluster set S1. For example, the distance between the first representative point C2 of cluster set S2 and the first representative point C1 of the first cluster set S1 is d5, the distance between the first representative point C3 of cluster set S3 and the first representative point C1 of the first cluster set S1 is d6, and the distance between the first representative point C4 of cluster set S4 and the first representative point C1 of the first cluster set S1 is d7. Then, d5, d6, and d7 are compared with the set distance D. If d5 and d7 are less than the set distance D, cluster sets S2 and cluster set S4 form the cluster sets in the second sequence. Then, the distances d5 and d7 between the first representative points of cluster sets S2 and cluster set S4 in the second sequence and the first representative point of cluster set S1 are sorted from closest to farthest. If d7 is less than d5, the sorting is cluster set S4 - cluster set S2. If the preset number of second cluster sets is one, cluster set S4 is used as the second cluster set.
[0118] For another example, the method for obtaining the second cluster set can also be: estimating the approximate radius distance of each cluster set except the first cluster set where the first representative point of the first cluster set itself is located, obtaining the difference between the distance between the first representative point of each cluster set and the first representative point of the first cluster set and the approximate radius distance, and according to the difference, sorting each cluster set from near to far to obtain a second sequence, and taking the first preset number of cluster sets in the second sequence as the second cluster set.
[0119] It can be understood that in some embodiments, the above-mentioned method of estimating the approximate radius distance of each cluster set except the first cluster set where the target feature vector itself is located can be: obtaining the distance between all feature vectors in each cluster set and the representative points in each cluster set, and taking the maximum distance between all feature vectors and the representative points as the approximate radius distance of each cluster set.
[0120] For example, Figure 3bAs shown, the method for determining the second cluster set adjacent to the cluster set S1 can be as follows: First, determine each cluster set S2, S3, and S4 except the cluster set S1. Take the maximum distance between each feature vector in the cluster set S2 and the first representative point C2 of the cluster set S2 as the approximate radius distance of the cluster set S2. Assume the maximum distance is the distance r1 between the feature vector Y3 and the first representative point C2 of the cluster set S2, then take r1 as the approximate radius distance of the cluster set S2. Take the maximum distance between each feature vector in the cluster set S3 and the first center point C3 as the approximate radius distance of the cluster set S2. Assume the maximum distance is the distance r2 between the feature vector Z1 and the first representative point C3 of the cluster set S3, then take r2 as the approximate radius distance of the cluster set S3. Take the maximum distance between each feature vector in the cluster set S4 and the first center point C4 as the approximate radius distance of the cluster set S4. Assume the maximum distance is the distance r3 between the feature vector W5 and the first representative point C4 of the cluster set S4, then take r3 as the approximate radius distance r3 of the cluster set S4.
[0121] Then, determine the difference between the distance d5 between the first representative point C2 of the cluster set S2 and the first representative point C1 of the cluster set S1 and the radius distance r1 of the cluster set S2 as d5 - r1, the difference between the distance d6 between the first representative point C3 of the cluster set S3 and the first representative point C1 of the cluster set S1 and the radius distance r2 of the cluster set S3 as d6 - r2, and the difference between the distance d7 between the first representative point C4 of the cluster set S4 and the first representative point C1 of the cluster set S1 and the radius distance r3 of the cluster set S4 as d7 - r3. According to the differences, sort the cluster sets S2, S3, and S4 from near to far to obtain the second sequence. Assume d5 - r1 < d7 - r3 < d6 - r2, then the second sequence is the cluster set S1 - the cluster set S4 - the cluster set S3. Take the first preset number of cluster sets in the second sequence as the second cluster set. Assume taking the first 1 number of cluster sets in the second sequence as the second cluster set, then the second cluster set is the cluster set S1.
[0122] In some embodiments, the method for estimating the approximate radius of each cluster set can also be any other feasible method, such as estimating through a neural network model or related algorithms, etc.
[0123] It can be understood that the difference between the distance between the representative point of any cluster set and the first representative point of the first cluster set and the approximate radius can approximately represent the distance between the marginal feature vector in this cluster set and the first representative point of the first cluster set. When the distance between the marginal feature vector and the first representative point of the first cluster set is relatively close, it is possible that the cluster set where this marginal feature vector is located is the adjacent set of the first cluster set.
[0124] In a fourth feasible solution, the method for determining at least one second representative point that meets the preset conditions can be: determining at least one second cluster set adjacent to the first cluster set in cluster sets other than the first cluster set; obtaining the first distance between each feature vector in the first cluster set and the first representative point of the first cluster set, and the second distance between each feature vector in the first cluster set and the first representative point of each second cluster set, and based on the sum of the first distance and the second distance; sorting each feature vector from far to near according to the sum of the distances, obtaining the first sequence corresponding to each second cluster set; and using the first set number of feature vectors in the first sequence as the second representative points. It can be understood that the method for obtaining at least one second cluster set adjacent to the first cluster set in the fourth solution is the same as the method for obtaining the second cluster set described in the third solution, and will not be repeated here.
[0125] It can be understood that the first sequence is obtained by sorting the sum of the first distance and the second distance from large to small. The feature vector with the larger sum of the distance in the obtained first sequence is the feature vector that is farther from the first representative point of the first cluster set and also farther from the first representative point of the second cluster set. That is, the feature vector may be located at the edge point in the opposite direction from the first representative point of the first representative point to the second representative point. When the first sequence corresponding to the second cluster set in each direction of the first cluster set is obtained, the edge points in each direction of the first cluster set can be obtained. In this way, using the edge points in each direction of the first cluster set as the second representative point can effectively improve the search accuracy.
[0126] Get the following Figure 4 Taking at least one second representative point of the cluster set S1 as an example, the method of obtaining the second representative point in the fourth implementation scheme in the embodiment of the present application is described:
[0127] like Figure 4 As shown in , it is assumed that the second cluster set adjacent to the first cluster set S1 is the aforementioned Figure 3a According to the second cluster set S2 adjacent to the first cluster set S1 determined above, the sum of the first distance between each feature vector in the first cluster set S1 and the first representative point C1 of the first cluster set S1 and the second distance between each feature vector in the first cluster set S1 and the first representative point C2 of the second cluster set S2 is obtained.
[0128] For example, Figure 4As shown in the figure, the sum of the first distance d1_1 between the eigenvector X1 in the first cluster set S1 and the first representative point C1 and the second distance d2_1 to the first representative point C2 is d_s2. The way to obtain the sum of distances for the other 15 eigenvectors is the same and will not be repeated here. Assuming that the first sequence corresponding to the cluster set S2 obtained by sorting the 16 eigenvectors in the first cluster set S1 from far to near according to the sum of distances is X2-X3-X1-......-X14, and assuming that the preset number of second representative points of the corresponding cluster set obtained according to each neighboring set is one, the first eigenvector in the first sequence corresponding to the second cluster set S2, that is, the eigenvector X2, can be used as the second representative point.
[0129] At the same time, according to the adjacent second cluster set S4 of the first cluster set S1 determined above, the sum of the first distance between each feature vector in the first cluster set S1 and the first representative point C1 of the first cluster set S1 and the second distance between each feature vector in the first cluster set S1 and the first representative point C4 of the second cluster set S4 is obtained, for example, Figure 4 In the figure, the sum of the distances d_s4 between the first distance d1_1 between the eigenvector X1 in the first cluster set S1 and the first representative point C1 and the second distance d4_1 between the first representative point C4 and the other 15 eigenvectors is obtained in the same way and will not be repeated here; assuming that the first sequence obtained by sorting the 16 eigenvectors in the first cluster set S1 from far to near according to the sum of the distances is X4-X1-X3-......-X15, assuming that the number of preset second representative points of the corresponding cluster set obtained according to each neighboring set is one, the first eigenvector in the first sequence corresponding to the fourth cluster set S4, that is, the eigenvector X4, can be used as the second representative point.
[0130] Based on the index construction method of the present application, each feature vector in each cluster set can establish an index association with the first representative point and the second representative point of the cluster set. In this way, when querying, the distance between the query vector and the first representative point of the first cluster set, that is, the center point, can be obtained, and the distance between the query vector and the second representative point of the first cluster set, that is, the edge point, can also be obtained. In this way, during the retrieval process, the distance between the query vector and the first representative point and the second representative point can be compared, that is, the distance between the edge point farther from the center point and the query vector is taken into account, avoiding the problem in the prior art that the target vector is an edge point, and the prior art center only considers the distance to the center point, resulting in a more accurate target vector not being found. That is, during the query process, the edge point is used as the second representative point, combined with the first representative point, and the distance between the edge point and the query vector is calculated respectively to query the corresponding target cluster set, so that the target vector corresponding to the query vector can be obtained more accurately, which can effectively avoid the problem of low search accuracy caused by the aforementioned representative point of the cluster set not being able to fully represent all the feature vectors in the cluster set, thereby effectively improving the search accuracy.
[0131] It is understood that when obtaining the second representative points of each cluster set in the entire database, the preset number of second representative points of each cluster set can be determined according to the following method:
[0132] In a first feasible solution, the method for determining the preset number of second representative points of each cluster set is as follows: according to the preset total number of second representative points in the database, according to the number or radius of the feature vectors in each cluster set, the preset number of second representative points of each cluster set is determined according to the ratio of the preset total number of second representative points and the number or radius of the feature vectors in each cluster set; it is understood that in some embodiments, when the calculated preset number of second representative points of any cluster set is not an integer, the final preset number can be obtained according to a rounding rule. For example, the rounding rule can be to add 1 to the integer digit of the value corresponding to the current number and discard the decimal part to obtain the value obtained as the value corresponding to the final preset number.
[0133] For example, the preset total number of the second representative points is 4. Figure 1bIn the cluster set corresponding to the database S shown, there are 16 feature vectors in cluster set S1, 14 feature vectors in cluster set S2, 10 feature vectors in cluster set S3, and 17 feature vectors in cluster set S4. The ratio of the number of second representative points to be determined in cluster set S1, cluster set S2, cluster set S3, and cluster set S4 is 16:14:10:17. Based on the preset total number of second representative points and the ratio of the number of second representative points of 16:14:10:17, it can be determined that the number of second representative points to be determined in cluster set S1, cluster set S2, cluster set S3, and cluster set S4 is 1.1, 0.9, 0.7, and 1.7. According to the above rounding rule, it can be concluded that the preset number of second representative points to be determined in cluster set S1, cluster set S2, cluster set S3, and cluster set S4 is 2, 1, 1, and 2, respectively.
[0134] It can be understood that the above-mentioned method of determining the preset number of second representative points for each cluster set based on the preset total number of second representative points and the number of feature vectors or the ratio of radius in each cluster set can make the distribution of the second representative points more uniform, avoiding the problem that some cluster sets are very small but still determine a large number of second representative points, resulting in waste of resources, while other larger cluster sets determine fewer second representative points, making it difficult for the representative points determined in the larger cluster set to fully represent the corresponding cluster set, resulting in a decrease in search accuracy.
[0135] In the second feasible scheme, the method for determining the preset number of second representative points of each cluster set is: according to the preset total number of second representative points in the database, sort from large to small according to the number or radius of feature vectors in each cluster set, and select a set number of second representative points from each cluster set until the preset total number is selected.
[0136] For example, the preset total number of the second representative points is 4. Figure 1b In the cluster sets corresponding to the database S shown, the number of feature vectors in each cluster set is determined. There are 16 feature vectors in cluster set S1, 14 feature vectors in cluster set S2, 10 feature vectors in cluster set S3, and 17 feature vectors in cluster set S4. Then, the order obtained by arranging the feature vectors in each cluster set from large to small is cluster set S4 - cluster set S1 - cluster set S2 - cluster set S3.
[0137] When the set number of second representative points selected in each cluster set is 2, in the order of cluster set S4, cluster set S1, cluster set S2, and cluster set S3, the preset number of second representative points to be determined in cluster set S4 and cluster set S1 is two. This is because the preset total number of second representative points has been reached. No second representative points will be selected for subsequent cluster sets S2 and S3. That is, the number of second representative points in cluster sets S2 and S3 following cluster set S1 is zero.
[0138] It can be understood that the above method of sorting the cluster sets according to the number of feature vectors or radius in each cluster set from large to small based on the preset total number of second representative points and selecting a set number of second representative points from each cluster set can determine a smaller number of second representative points in smaller cluster sets, and determine more second representative points in other larger cluster sets, so that the determined representative points can fully represent the corresponding cluster sets, effectively improving the search accuracy.
[0139] It can be understood that after obtaining the second representative point of each cluster set, for each feature vector in the cluster set, an index association is established between the feature vector and the first representative point and the second representative point in the cluster set.
[0140] For example, Figure 5a Shown for Figure 1a The first representative point and the second representative point corresponding to the database S shown in Figure 5b A schematic diagram of the corresponding index structure is shown. Figure 5a As shown, the representative points of the database S are cluster set S1 with the corresponding first representative point C1, second representative points X1, X7, cluster set S2 with the corresponding first representative point C2, second representative point Y1 and second representative point Y2, cluster set S3 with the corresponding first representative point C3, second representative point Z1, and cluster set S4 with the corresponding first representative point C4, second representative points W1, W2, W3 and W4. Figure 5b As shown, the index structure of the database S includes representative point items and inverted file items. The representative point items include cluster set S1 with corresponding first representative point C1, second representative points X1, X7, cluster set S2 with corresponding first representative point C2, second representative point Y1, and second representative point Y2, cluster set S3 with corresponding first representative point C3, second representative point Z1, and cluster set S4 with corresponding first representative point C4, second representative points W1, W2, W3, and W4.
[0141] The first representative point C1 and the second representative points X1 and X7 corresponding to the cluster set S1 have a corresponding inverted file D1, and the inverted file D1 includes each feature vector in the cluster set S1 corresponding to the corresponding representative point C1.
[0142] The first representative point C2, the second representative point Y1 and the second representative point Y2 corresponding to the cluster set S2 have a corresponding inverted file D2, and the inverted file D2 includes each feature vector in the cluster set S2 corresponding to the corresponding representative point C2.
[0143] The inverted file D3 corresponding to the first representative point C3 and the second representative point Z1 of the cluster set S3 includes each feature vector in the cluster set S3 corresponding to the corresponding representative point C3.
[0144] The first representative point C4 and the second representative points W1, W2, W3 and W4 corresponding to the cluster set S4 have a corresponding inverted file D4, and the inverted file D4 includes each feature vector in the cluster set S4 corresponding to the corresponding representative point C4.
[0145] Corresponding to the above vector index construction method, when searching for such a vector, the retrieval system can first obtain the query vector; obtain the distance between the query vector and the first representative point and the second representative point corresponding to each cluster set in the database; determine the first preset number of representative points closest to the query vector, and use the cluster set corresponding to the first preset number of representative points closest to the query vector as the target cluster set; obtain the distance between each feature vector in the target cluster set and the query vector; and determine the target vector corresponding to the query vector based on the distance.
[0146] It can be understood that when the determined target cluster set has duplicate cluster sets, only one of the duplicate cluster sets may be retained.
[0147] It can be understood that the index construction method provided in the embodiment of the present application can determine at least one second representative point that is relatively far from the first representative point of each cluster set. In this way, during the retrieval process, the distance between the query vector and the first representative point and the second representative point can be compared to obtain the first preset number of representative points closest to the query vector. In this way, the method of using edge points as representative points when constructing the index can make it possible to take into account the distance between edge points that are far from the center point and the query vector during retrieval, thereby avoiding the problem in the prior art that the target vector is an edge point, while the prior art center only considers the distance to the center point, resulting in a more accurate target vector not being found. During the query process, the distance between the first representative point and the second representative point of each cluster set and the query vector is obtained for comparison with the query vector to query the corresponding target cluster set, so that the target vector closest to the query vector can be obtained more accurately, which can effectively avoid the problem of low search accuracy caused by the aforementioned representative points of the cluster set not being able to fully represent all the feature vectors in the cluster set, thereby effectively improving the search accuracy.
[0148] For example, the index is constructed for the image database S shown in FIG1. The system first distributes each feature vector in the database S into four cluster sets through the above k-means clustering process, and obtains the following Figure 1a The four cluster sets shown are cluster set S1, cluster set S2, cluster set S3 and cluster set S4, wherein each of the four cluster sets has a corresponding first representative point and a second representative point, and the second representative point corresponding to each cluster set is determined according to one of the above methods of determining at least one second representative point of each cluster set that meets the preset conditions. For example, Figure 5a As shown, cluster set S1 has corresponding first representative point C1, second representative point X1, X7, cluster set S2 has corresponding first representative point C2, second representative point Y1 and second representative point Y2, cluster set S3 has corresponding first representative point C3, second representative point Z1, and cluster set S4 has corresponding first representative point C4, second representative point W1, W2, W3 and W4. At this time, based on the first representative point and second representative point of each cluster set and the feature vectors of the cluster set to which each center point belongs, the above-mentioned inverted file method is established. Figure 5b The index structure shown.
[0149] Based on the above-mentioned Figure 5b When the database S performs vector retrieval on the query vector A, the retrieval system determines the distance between the first representative point and the second representative point of each cluster set in the database S and the query vector A, for example, Figure 6aAs shown, the retrieval system will determine the distances between the 13 representative points, namely the first representative point C1, the second representative point X1, and the second representative point X7 of the cluster set S1, the first representative point C2, the second representative point Y1, and the second representative point Y2 of the cluster set S2, the first representative point C3, the second representative point Z1 of the cluster set S3, and the first representative point C4, the second representative points W1, W2, W3, and W4 of the cluster set S4, and the query vector A, and determine the first two representative points among the 13 representative points that are closest to the query vector A, namely the second representative point X1 of the cluster set S1 and the second representative point Y1 of the cluster set S2, and then search each feature vector in the cluster set S1 where the representative point X1 is located and each feature vector in the cluster set S2 where the representative point Y1 is located according to the index structure, that is, obtain the distance between each feature vector in the cluster set S1 and the cluster set S2 and the query vector.
[0150] In some embodiments, a feature vector whose distance from the query vector A is less than a set value can be used as a target vector. Assume that the distance between the feature vector X1 in cluster set S1 and the feature vectors Y1 and Y2 in cluster set S2 and the query vector A is less than a set value, such as Figure 6b As shown, the eigenvector X1 and the eigenvectors Y1 and Y2 are used as target vectors.
[0151] In other embodiments, the feature vectors in each target cluster set can be sorted from near to far according to the distance, and the first set number of features in the sorting are selected as the target vectors of the query vector. Assume that the feature vector X1 in cluster set S1 and the feature vectors Y1 and Y2 in cluster set S2 are the first three feature vectors in the sorting. Then Figure 6b As shown, the eigenvector X1 and the eigenvectors Y1 and Y2 are used as target vectors.
[0152] It can be understood that the application of the index construction method to the index construction in the above-mentioned image database in the embodiment of the present application is only an example. The index construction method provided in the embodiment of the present application can be applied to various video, voice, protein molecular structure and other databases, that is, the index construction method provided in the embodiment of the present application can be widely used in image, video, voice, protein molecular structure retrieval and other fields.
[0153] It is understood that the retrieval system mentioned in the embodiments of the present application may include at least one database, for example, the aforementioned image database, as well as a video database, a document database, etc. The image database includes feature vectors corresponding to multiple original image data, the video database includes feature vectors corresponding to multiple original video data, and the document database includes feature vectors corresponding to multiple original document data. It is practicable that each database may construct an index using the aforementioned index construction method.
[0154] The index construction method provided in the embodiment of the present application is described in detail below. It is understood that the index construction method provided in the embodiment of the present application can be executed by the retrieval system or by other electronic devices, that is, the other electronic devices will construct an index for the database and then deploy the indexed database to the retrieval system.
[0155] The index construction method provided in the embodiment of the present application is described in detail below by taking the index construction method executed by the retrieval system as an example. Figure 7 A flow chart of an index construction method according to an embodiment of the present application is shown.
[0156] like Figure 7 As shown, the index construction method in the embodiment of the present application may include:
[0157] 701: Obtain the feature vector corresponding to each data in the database for which the index is to be created.
[0158] It is understood that the database may include one or more data structures such as various images, videos, audio, and protein molecular structures. Since various data can be converted into high-dimensional feature vectors, the retrieval system can first convert each raw data in the database into a corresponding feature vector. It is understood that each raw data converted into a corresponding feature vector is a target vector. It is understood that each raw data in the database may also be retained and stored in the database.
[0159] For example, for the above-mentioned image database, the retrieval system may first convert each image data in the image database into a corresponding feature vector.
[0160] 702: Perform clustering processing on each feature vector to obtain multiple cluster sets, each cluster set having a corresponding first representative point.
[0161] It can be understood that the first representative point may be the center point of the corresponding cluster set.
[0162] It is understood that in the embodiment of the present application, the method for clustering each feature vector may be a k-means clustering method, wherein the k-means clustering method specifically includes:
[0163] Obtain K initial cluster representative points and k pre-set cluster sets, each corresponding to an initial first representative point. It should be understood that at this point, the cluster set has not yet been assigned a feature vector and is merely a virtual set with corresponding initial representative points. The value of K, i.e., the number of cluster sets, can be set manually based on actual needs.
[0164] Obtain the distance between each feature vector in the database and the first representative point corresponding to each cluster. Assign each feature vector to the cluster corresponding to the first representative point closest to it. Then, calculate a loss function based on each feature vector obtained from each cluster. Repeat this process until the loss function reaches a preset threshold.
[0165] It can be understood that the distance mentioned in the embodiments of the present application can be other distances such as Euclidean distance, inner product distance and Hamming distance.
[0166] In other embodiments, the first representative point in each cluster set may be re-determined, for example, the average vector of all feature vectors in the cluster set may be used as the first representative point.
[0167] For example, for any target vector, the distance between the target vector and the first representative point of each cluster set may be obtained, and the target vector may be assigned to the first cluster set corresponding to the first representative point with the shortest distance.
[0168] It can be understood that the above-mentioned method of clustering the feature vectors may also be other clustering methods.
[0169] 703: Determine a preset number of second representative points that meet preset conditions for each of the above cluster sets.
[0170] It can be understood that the preset number of second representative points corresponding to each cluster set is determined based on the preset total number of second representative points in the database. When the preset total number of second representative points is small, there may be some cluster sets whose preset number of second representative points is 0. At this time, there is no need to determine the second representative points of the cluster sets with a preset number of 0.
[0171] It can be understood that the second representative point can be an edge point of the corresponding cluster set.
[0172] The following describes the method of determining the second representative point in the embodiment of the present application by taking the example of determining at least one second representative point that meets the preset conditions in the first cluster set where any target vector is located.
[0173] In some implementations, the method for determining at least one second representative point that meets the preset conditions can be: obtaining the distance between the first representative point of each first cluster set and all feature vectors in the cluster center; sorting the feature vectors from far to near according to the first distance to obtain a first sequence corresponding to each first cluster set; and determining the first preset number of feature vectors in the first sequence as the second representative points in the cluster set.
[0174] In an embodiment of the present application, the second representative point is determined based on the distance between each feature vector in the first cluster set and the first representative point, so that the feature vector farther away from the first representative point can be used as the second representative point, making the selection of the second representative point more accurate.
[0175] In the embodiment of the present application, the eigenvectors in the first cluster set are sorted from farthest to closest based on the distance between each eigenvector and the first representative point, i.e., based on how close each eigenvector is to the first representative point. This facilitates the selection of corresponding second representative points based on a set number of points. For example, if the set number of second representative points is five, the first five eigenvectors in the sorted first sequence can be directly used as the second representative points.
[0176] In some implementations, the method for determining at least one second representative point that meets the preset conditions can be: obtaining the distance between the first representative point of each first cluster set and all feature vectors in the cluster center; taking the feature vector whose first distance is greater than the set distance as the feature vector in the first sequence, and then taking all the feature vectors in the first sequence as the second representative point, or sorting the feature vectors in the first sequence from far to near according to the first distance, and taking the feature vector at the front of the set order in the sorting as the second representative point.
[0177] In the embodiment of the present application, the first sequence is obtained based on feature vectors in the first cluster set whose distance from the first representative point is greater than a set distance. That is, the feature vectors in the first sequence are vectors that are farther from the first representative point and greater than the set distance. This can make the method for selecting the second cluster set more standardized and simple. For example, the second representative point can be obtained by simply setting a corresponding distance threshold parameter in the algorithm for selecting the second representative point.
[0178] In some implementations, the method for determining at least one second representative point that meets the preset conditions can be: determining at least one second cluster set that is adjacent to the first cluster set in cluster sets other than the first cluster set; obtaining the distance between each feature vector in the first cluster set and the first representative point of each second cluster set; sorting the feature vectors from near to far according to the distance, and obtaining the first sequence corresponding to each second cluster set; and using the first set number of feature vectors in the first sequence as the second representative points.
[0179] In the embodiment of the present application, the second representative point is determined based on the distance between each feature vector in each first cluster set and at least one adjacent second cluster set. It is understandable that the smaller the distance between a feature vector and an adjacent second cluster set, the closer the feature vector is to the second cluster set, that is, the closer it is to the edge of the first cluster set. Therefore, the second representative point can be determined more accurately based on the distance between the feature vector and the adjacent second cluster set.
[0180] The method of obtaining at least one second cluster set adjacent to the first cluster set may be:
[0181] The cluster sets other than the first cluster set in the above-mentioned multiple cluster sets are sorted from near to far according to the distance between the first representative point of each cluster set and the first representative point of the first cluster set to obtain a second sequence corresponding to the first cluster set; the first preset number of cluster sets in the second sequence are used as the second cluster set.
[0182] For example, for the aforementioned Figure 2 For each cluster set shown, taking the first cluster set S1 as an example, the distances d5, d6, and d7 between the first center point of the first cluster set S1 and the first center points of the other cluster sets C2, C3, and C4 are obtained, and the clusters are sorted from closest to farthest based on the distances. Assuming that d7 < d5 < d6, the first sequence corresponding to the first representative point C1 is cluster set S4 - cluster set S2 - cluster set S3. In this case, the first representative point C1 is indexed and associated with the first preset number of cluster sets in the second sequence. Assuming the preset number is two, cluster set S2 and cluster set S4 can be regarded as the second cluster set adjacent to the first cluster set S1.
[0183] After determining the second set of clusters, e.g. Figure 3aAs shown, for any vector in the first cluster set, taking the eigenvector X1 as an example, the distance d2_1 between the eigenvector X1 in the first cluster set S1 and the first representative point C2 of the second cluster set S2 is obtained, and the distances between other eigenvectors and the first representative point C2 are not repeated here; according to the distance between each eigenvector and the first representative point C2, each eigenvector is sorted from near to far. It is assumed that according to the distance, the first sequence obtained by sorting the 16 eigenvectors in the first cluster set S1 from far to near is X1-X3-X5-......-X16, and the preset number is 1, then the second representative point corresponding to the second cluster set S2 is X1. At the same time, the distance between each eigenvector in the first cluster set S1 and the first representative point C4 of the second cluster set S4 is obtained. For the eigenvector X1, the distance d4_1 between the eigenvector X1 in the first cluster set S1 and the first representative point C4 of the second cluster set S4 is obtained. The distances between other eigenvectors and the first representative point C4 are not repeated here. According to the distance between each eigenvector and the first representative point C4, each eigenvector is sorted from near to far. Assuming that the first sequence obtained by sorting the 16 eigenvectors in the first cluster set S1 from near to far according to the distance is X7-X8-X1-......-X14, and the preset number is 1, then the second representative point corresponding to the second cluster set S4 is X7.
[0184] It is understood that the above method of obtaining the adjacent cluster sets of the first cluster set, i.e., the second cluster set, by sorting the representative points of each cluster set according to the distance between the first representative point of the first cluster set is merely an example. Alternatively, the method of obtaining the second cluster set in the embodiment of the present application may be other methods.
[0185] For example, the method for obtaining the second cluster set can also be: the cluster sets in the second sequence are composed of cluster sets whose distances between the first representative points of each cluster set except the first cluster set in the above-mentioned multiple cluster sets and the first representative point of the first cluster set are less than the set distance; and then any preset number of cluster sets in the second sequence are used as the second cluster set, or the distances between the first representative points of each cluster set in the second sequence and the first representative point of the first cluster set are sorted from near to far, and the cluster set that is at the front of the set order in the sorting is used as the second cluster set.
[0186] For example, Figure 2As shown, a method for determining a second cluster set adjacent to cluster set S1 may be: first, obtain the distances between the first representative points of cluster sets other than cluster set S1 and the first representative point of cluster set S1. For example, the distance between the first representative point C2 of cluster set S2 and the first representative point C1 of the first cluster set S1 is d5, the distance between the first representative point C3 of cluster set S3 and the first representative point C1 of the first cluster set S1 is d6, and the distance between the first representative point C4 of cluster set S4 and the first representative point C1 of the first cluster set S1 is d7. Then, d5, d6, and d7 are compared with the set distance D. If d5 and d7 are less than the set distance D, cluster sets S2 and cluster set S4 form the cluster sets in the second sequence. Then, the distances d5 and d7 between the first representative points of cluster sets S2 and cluster set S4 in the second sequence and the first representative point of cluster set S1 are sorted from closest to farthest. If d7 is less than d5, the sorting is cluster set S4 - cluster set S2. If the preset number of second cluster sets is one, cluster set S4 is used as the second cluster set.
[0187] For another example, the method for obtaining the second cluster set can also be: estimating the approximate radius distance of each cluster set except the first cluster set where the first representative point of the first cluster set itself is located, obtaining the difference between the distance between the first representative point of each cluster set and the first representative point of the first cluster set and the approximate radius distance to which they belong, and sorting each cluster set from near to far according to the difference distance to obtain a second sequence, and taking the first preset number of cluster sets in the second sequence as the second cluster set.
[0188] It can be understood that in some embodiments, the above-mentioned method of estimating the approximate radius distance of each cluster set except the first cluster set where the target feature vector itself is located can be: obtaining the distance between all feature vectors in each cluster set and the representative points in each cluster set, and taking the maximum distance between all feature vectors and the representative points as the approximate radius distance of each cluster set.
[0189] For example, as mentioned above Figure 3bAs shown in [figure number], the method for determining the second cluster set adjacent to the cluster set S1 can be as follows: First, determine each cluster set S2, S3, and S4 other than the cluster set S1. Take the maximum distance between each feature vector in the cluster set S2 and the first representative point C2 of the cluster set S2 as the approximate radius distance of the cluster set S2. Assume that the maximum distance is the distance r1 between the feature vector Y3 and the first representative point C2 of the cluster set S2, then take r1 as the approximate radius distance of the cluster set S2. Take the maximum distance between each feature vector in the cluster set S3 and the first center point C3 as the approximate radius distance of the cluster set S2. Assume that the maximum distance is the distance r2 between the feature vector Z1 and the first representative point C3 of the cluster set S3, then take r2 as the approximate radius distance of the cluster set S3. Take the maximum distance between each feature vector in the cluster set S4 and the first center point C4 as the approximate radius distance of the cluster set S4. Assume that the maximum distance is the distance r3 between the feature vector W5 and the first representative point C4 of the cluster set S4, then take r3 as the approximate radius distance r3 of the cluster set S4.
[0190] Then, determine the difference between the distance d5 between the first representative point C2 of the cluster set S2 and the first representative point C1 of the cluster set S1 and the radius distance r1 of the cluster set S2 as d5 - r1, the difference between the distance d6 between the first representative point C3 of the cluster set S3 and the first representative point C1 of the cluster set S1 and the radius distance r2 of the cluster set S3 as d6 - r2, and the difference between the distance d7 between the first representative point C4 of the cluster set S4 and the first representative point C1 of the cluster set S1 and the radius distance r3 of the cluster set S4 as d7 - r3. According to the differences, sort the cluster sets S2, S3, and S4 from near to far to obtain the second sequence. Assume that d5 - r1 < d7 - r3 < d6 - r2, then the second sequence is the cluster set S1 - the cluster set S4 - the cluster set S3. Take the first preset number of cluster sets in the second sequence as the second cluster set. Assume that the first 1 number of cluster sets in the second sequence is taken as the second cluster set, then the second cluster set is the cluster set S1.
[0191] In some embodiments, the method for estimating the approximate radius of each cluster set can also be any other implementable method, such as estimating through a neural network model or related algorithms, etc.
[0192] In other implementations, the method for determining at least one second representative point that meets the preset conditions can be: determining at least one second cluster set that is adjacent to the first cluster set in cluster sets other than the first cluster set; obtaining the first distance between each feature vector in the first cluster set and the first representative point of the first cluster set, and the second distance between each feature vector in the first cluster set and the first representative point of each second cluster set, and based on the sum of the first distance and the second distance; sorting each feature vector from far to near according to the sum of the distances, and obtaining the first sequence corresponding to each second cluster set; and taking the first set number of feature vectors in the first sequence as the second representative points.
[0193] It can be understood that the method of obtaining at least one second cluster set adjacent to the first cluster set in the fourth solution is the same as the method of obtaining the second cluster set described in the third solution, and will not be repeated here.
[0194] It can be understood that a feature vector with a larger sum of the first distance and the second distance is a feature vector that is farther from the first representative point of the first cluster set and also farther from the first representative point of the second cluster set. In other words, this feature vector is likely located at an edge point in the opposite direction from the first representative point to the second representative point of the first representative point. Once the first sequence corresponding to the second cluster set in each direction of the first cluster set is obtained, the edge points in each direction of the first cluster set can be obtained. In this way, using the edge points in each direction of the first cluster set as the second representative points can effectively improve search accuracy.
[0195] As mentioned above Figure 4 As shown in , in the fourth embodiment of the present application, the method for obtaining the second representative point of the cluster set S1 may be:
[0196] Assume that the second cluster set adjacent to the first cluster set S1 is the aforementioned Figure 3a According to the second cluster set S2 adjacent to the first cluster set S1 determined above, the sum of the first distance between each feature vector in the first cluster set S1 and the first representative point C1 of the first cluster set S1 and the second distance between each feature vector in the first cluster set S1 and the first representative point C2 of the second cluster set S2 is obtained.
[0197] For example, Figure 4As shown in , the sum of the first distance d1_1 between the feature vector X1 in the first cluster set S1 and the first representative point C1 and the second distance d2_1 with the first representative point C2 is d_s2. The way to obtain the sum of the distances of the other 15 feature vectors is the same and will not be repeated here. Assuming that the first sequence corresponding to the cluster set S2 obtained by sorting the 16 feature vectors in the first cluster set S1 from far to near according to the sum of the distances is X2-X3-X1-......-X14, assuming that the number of preset second representative points of the corresponding cluster set obtained according to each neighboring set is one, the first feature vector in the first sequence corresponding to the second cluster set S2, that is, the feature vector X2, can be used as the second representative point. At the same time, according to the second cluster set S4 adjacent to the first cluster set S1 determined above, the sum of the first distance between each feature vector in the first cluster set S1 and the first representative point C1 of the first cluster set S1 and the second distance between each feature vector in the first cluster set S4 and the first representative point C4 of the second cluster set S4 is obtained. For example, Figure 4 In the example, the sum d_s4 of the first distance d1_1 between feature vector X1 in first cluster set S1 and the first representative point C1, and the second distance d4_1 between the first representative point C4, is obtained. The distance sums for the other 15 feature vectors are obtained in the same manner and are not further described here. Assuming that the first sequence obtained by sorting the 16 feature vectors in first cluster set S1 from farthest to closest based on the distance sums is X4-X1-X3-...-X15, and assuming that the number of second representative points for each corresponding cluster set obtained from each neighboring set is one, the first feature vector in the first sequence corresponding to the fourth cluster set S4, namely feature vector X4, can be used as the second representative point.
[0198] It is understood that when obtaining the second representative points of each cluster set in the entire database, the preset number of second representative points of each cluster set can be determined according to the following method:
[0199] In a first feasible solution, the method for determining the preset number of second representative points of each cluster set is as follows: according to the preset total number of second representative points in the database, according to the number or radius of the feature vectors in each cluster set, the preset number of second representative points of each cluster set is determined according to the ratio of the preset total number of second representative points and the number or radius of the feature vectors in each cluster set; it is understood that in some embodiments, when the calculated preset number of second representative points of any cluster set is not an integer, the final preset number can be obtained according to a rounding rule. For example, the rounding rule can be to add 1 to the integer digit of the value corresponding to the current number and discard the decimal part to obtain the value obtained as the value corresponding to the final preset number.
[0200] For example, the preset total number of the second representative points is 4. Figure 1b In the cluster set corresponding to the database S shown, there are 16 feature vectors in cluster set S1, 14 feature vectors in cluster set S2, 10 feature vectors in cluster set S3, and 17 feature vectors in cluster set S4. The ratio of the number of second representative points to be determined in cluster set S1, cluster set S2, cluster set S3, and cluster set S4 is 16:14:10:17. Based on the preset total number of second representative points and the ratio of the number of second representative points of 16:14:10:17, it can be determined that the number of second representative points to be determined in cluster set S1, cluster set S2, cluster set S3, and cluster set S4 is 1.1, 0.9, 0.7, and 1.7. According to the above rounding rule, it can be concluded that the preset number of second representative points to be determined in cluster set S1, cluster set S2, cluster set S3, and cluster set S4 is 2, 1, 1, and 2, respectively.
[0201] It can be understood that the above-mentioned method of determining the preset number of second representative points for each cluster set based on the preset total number of second representative points and the number of feature vectors or the ratio of radius in each cluster set can make the distribution of the second representative points more uniform, avoiding the problem that some cluster sets are very small but still determine a large number of second representative points, resulting in waste of resources, while other larger cluster sets determine fewer second representative points, making it difficult for the representative points determined in the larger cluster set to fully represent the corresponding cluster set, resulting in a decrease in search accuracy.
[0202] In the second feasible scheme, the method for determining the preset number of second representative points of each cluster set is: according to the preset total number of second representative points in the database, sort from large to small according to the number or radius of feature vectors in each cluster set, and select a set number of second representative points from each cluster set until the preset total number is selected.
[0203] For example, the preset total number of the second representative points is 4. Figure 1b In the cluster sets corresponding to the database S shown, the number of feature vectors in each cluster set is determined. There are 16 feature vectors in cluster set S1, 14 feature vectors in cluster set S2, 10 feature vectors in cluster set S3, and 17 feature vectors in cluster set S4. Then, the order obtained by arranging the feature vectors in each cluster set from large to small is cluster set S4 - cluster set S1 - cluster set S2 - cluster set S3.
[0204] When the set number of second representative points selected in each cluster set is 2, in the order of cluster set S4, cluster set S1, cluster set S2, and cluster set S3, the preset number of second representative points to be determined in cluster set S4 and cluster set S1 is two. This is because the preset total number of second representative points has been reached. No second representative points will be selected for subsequent cluster sets S2 and S3. That is, the number of second representative points in cluster sets S2 and S3 following cluster set S1 is zero.
[0205] It can be understood that the above method of sorting the cluster sets according to the number of feature vectors or radius in each cluster set from large to small based on the preset total number of second representative points and selecting a set number of second representative points from each cluster set can determine a smaller number of second representative points in smaller cluster sets, and determine more second representative points in other larger cluster sets, so that the determined representative points can fully represent the corresponding cluster sets, effectively improving the search accuracy.
[0206] 704: Establish an index association between each feature vector in each cluster set and the first representative point and the second representative point of the corresponding cluster set.
[0207] Each feature vector in each first cluster set is index-associated with the first representative point and the second representative point in the cluster set, wherein each feature vector in each first cluster set is the target vector. In the embodiment of the present application, after determining that the first cluster set has at least one second representative point that meets the preset conditions, an index association can be established between the target vector in each first cluster set and the first representative point and the second representative point of the first cluster set, respectively.
[0208] It can be understood that the index construction method provided in the embodiment of the present application can determine at least one second representative point, i.e., an edge point, that is farther away from the first representative point of each cluster set in addition to determining the first representative point. In this way, during the retrieval process, the distance between the query vector and the first representative point and the second representative point can be compared, i.e., the distance between the edge point farther away from the center point and the query vector is taken into account, thereby avoiding the problem in the prior art that the target vector is an edge point, while the prior art center only considers the distance from the center point, resulting in a more accurate target vector not being found. That is, during the query process, the edge point is used as the second representative point, combined with the first representative point, and the distance between the edge point and the query vector is calculated to query the corresponding target cluster set. The target vector corresponding to the query vector can be obtained more accurately, which can effectively avoid the problem of low search accuracy caused by the aforementioned representative point of the cluster set not being able to fully represent all the feature vectors in the cluster set, thereby effectively improving the search accuracy.
[0209] The following describes the index structure constructed by the above-mentioned index construction method in the embodiment of the present application. The index association may include two parts, namely, a representative point item and an inverted file item. The representative point item may include the first representative point and the second representative point corresponding to each cluster set, and the inverted file item includes the inverted file corresponding to each representative point. Each inverted file includes the information of each feature vector in the cluster set corresponding to each representative point in the corresponding representative point item. It can be understood that since the first representative point and the second representative point belonging to the same cluster set correspond to the same feature vector, the inverted file content corresponding to the first representative point and the second representative point belonging to the same cluster set is the same.
[0210] For example, Figure 5a Shown for Figure 1a The representative points corresponding to the database S shown in Figure 5b A schematic diagram of the index structure is shown. Figure 5a As shown, the representative points of the database S are cluster set S1 with the corresponding first representative point C1, second representative points X1, X7, cluster set S2 with the corresponding first representative point C2, second representative point Y1 and second representative point Y2, cluster set S3 with the corresponding first representative point C3, second representative point Z1, and cluster set S4 with the corresponding first representative point C4, second representative points W1, W2, W3 and W4. Figure 5b As shown, the index structure of the database S includes representative point items and inverted file items. The representative point items include cluster set S1 with corresponding first representative point C1, second representative points X1, X7, cluster set S2 with corresponding first representative point C2, second representative point Y1, and second representative point Y2, cluster set S3 with corresponding first representative point C3, second representative point Z1, and cluster set S4 with corresponding first representative point C4, second representative points W1, W2, W3, and W4.
[0211] The first representative point C1 and the second representative points X1 and X7 corresponding to the cluster set S1 have a corresponding inverted file D1, and the inverted file D1 includes each feature vector in the cluster set S1 corresponding to the corresponding representative point C1.
[0212] The first representative point C2, the second representative point Y1 and the second representative point Y2 corresponding to the cluster set S2 have a corresponding inverted file D2, and the inverted file D2 includes each feature vector in the cluster set S2 corresponding to the corresponding representative point C2.
[0213] The inverted file D3 corresponding to the first representative point C3 and the second representative point Z1 of the cluster set S3 includes each feature vector in the cluster set S3 corresponding to the corresponding representative point C3.
[0214] The first representative point C4 and the second representative points W1, W2, W3 and W4 corresponding to the cluster set S4 have a corresponding inverted file D4, and the inverted file D4 includes each feature vector in the cluster set S4 corresponding to the corresponding representative point C4.
[0215] An embodiment of the present application also includes a database, which uses the above-mentioned index construction method to construct an index, and the database includes: multiple cluster sets, each cluster set has at least one feature vector; wherein each cluster set has a corresponding first representative point or second representative point; the feature vector in each cluster set has an index association with the first representative point or second representative point of the cluster set in which it is located.
[0216] Figure 8 The flowchart of a search method in an embodiment of the present application is shown. The search method can be used in various databases including the above-mentioned index structure, and the search method can be executed by a retrieval system including the above-mentioned database. Figure 8 As shown, the search method in the embodiment of the present application may include:
[0217] 801: Get query vector;
[0218] It is understood that when a user searches for information, they can enter corresponding query data in the search window or search box of the search system. After obtaining the query data, the search system can convert the query data into a corresponding query vector. It is understood that the query data entered by the user can be in any format.
[0219] For example, the query data input by the user may be in the format of an image. After the retrieval system obtains the image, it may convert the image into a corresponding query vector.
[0220] For example, the query data input by the user may be in text format. After the retrieval system obtains the text, it may convert the text into a corresponding query vector.
[0221] For example, the query data input by the user may be in a video format. After the retrieval system obtains the video, it may convert the video into a corresponding query vector.
[0222] 802: Obtain a first distance between the query vector and the first representative point and the second representative point corresponding to each cluster set in the database.
[0223] It can be understood that in the embodiment of the present application, the above-mentioned first distance can be Euclidean distance or inner product distance, etc.
[0224] In some implementations, after obtaining the query vector, the retrieval system determines a first distance between the query vector and a first representative point and a second representative point of each cluster set in the database.
[0225] For example, Figure 6a As shown, the retrieval system will determine the first distances between the 13 representative points and the query vector A, including the first representative point C1, the second representative point X1, and X7 of the cluster set S1, the first representative point C2, the second representative point Y1, and the second representative point Y2 of the cluster set S2, the first representative point C3, the second representative point Z1 of the cluster set S3, and the first representative point C4, the second representative point W1, W2, W3, and W4 of the cluster set S4.
[0226] 803: Determine at least one representative point corresponding to the query vector based on the first distance obtained above, and use the cluster set corresponding to the at least one representative point as the target cluster set.
[0227] It is understandable that the specific number of representative points in the at least one representative point corresponding to the query vector can be determined by the user according to the needs, or it can be set according to the total number of feature vectors corresponding to the database or the number of cluster sets after the database completes clustering. For example, based on the range of the total number of feature vectors in the database, assuming that the total number of feature vectors in the database is 0-1000, the number of representative points determined can be set to 2. Assuming that the total number of feature vectors in the database is 1000-100000, the number of representative points determined can be set to 10. It is understandable that the above method of setting the number of representative points is only a distance description, and the present application is not limited to any other feasible method.
[0228] In some implementations, clusters corresponding to representative points whose distances from the query vector A are less than a set value may be combined as a target cluster set.
[0229] In other embodiments, the first distance may be used to sort the features from near to far, and a predetermined number of features before the sorting are selected as the target cluster set of the query vector.
[0230] For example, with the set number of target vectors being two, the representative points are sorted according to the first distance between the 13 representative points and the query vector A in the above step. If the first two representative points in the sorting are the second representative point X1 of cluster set S1 and the second representative point Y1 of cluster set S2, cluster set S1 and cluster set S2 are selected as target cluster sets for retrieval.
[0231] 804: Obtain a second distance between each feature vector in the target cluster set and the query vector.
[0232] In some implementations, a second distance between each feature vector in the target cluster set and the query vector is obtained based on the established index association.
[0233] For example, the second distance between each feature vector in cluster set S1 and cluster set S2 and the query vector A may be obtained.
[0234] 805: Determine a target vector corresponding to the query vector according to the second distance.
[0235] It can be understood that in the embodiment of the present application, the above-mentioned second distance can be Euclidean distance or inner product distance, etc.
[0236] In some implementations, a feature vector whose second distance from the query vector A is less than a set value may be used as a target vector.
[0237] For example, suppose the distance between the feature vector X1 in cluster set S1 and the feature vectors Y1 and Y2 in cluster set S2 and the query vector A satisfies the feature vector that is less than the set value, such as Figure 6b As shown, the eigenvector X1 and the eigenvectors Y1 and Y2 are used as target vectors.
[0238] In some other embodiments, the feature vectors may be sorted according to the second distance, and a predetermined number of feature vectors before the sorting are selected as target vectors of the query vector.
[0239] For example, the preset number is 3, and after obtaining the distance between the query vector A and each feature vector in the cluster set S1 and the cluster set S2, each feature vector is sorted from near to far according to the distance. Figure 6b As shown, assuming that the feature vector Y1, feature vector Y2 in cluster set S2 and feature vector X1 in distance cluster set S are the first three feature vectors in the sorting, the feature vector Y1, feature vector Y2 in cluster set S2 and feature vector X1 in distance cluster set S are used as the target vector corresponding to the query vector.
[0240] It can be understood that the index construction method provided in the embodiment of the present application can determine at least one second representative point that is relatively far from the first representative point of each cluster set. In this way, during the retrieval process, the distance between the query vector and the first representative point and the second representative point can be compared to obtain the first preset number of representative points closest to the query vector. In this way, the method of using edge points as representative points when constructing the index can make it possible to take into account the distance between edge points that are far from the center point and the query vector during retrieval, thereby avoiding the problem in the prior art that the target vector is an edge point, while the prior art center only considers the distance to the center point, resulting in a more accurate target vector not being found. During the query process, the distance between the first representative point and the second representative point of each cluster set and the query vector is obtained for comparison with the query vector to query the corresponding target cluster set, so that the target vector closest to the query vector can be obtained more accurately, which can effectively avoid the problem of low search accuracy caused by the aforementioned representative points of the cluster set not being able to fully represent all the feature vectors in the cluster set, thereby effectively improving the search accuracy.
[0241] It can be understood that in the embodiment of the present application, after the retrieval system obtains the target vector, the original data corresponding to the target vector can be output to the client.
[0242] For example, when the database is an image database, the retrieval system may output the original image data corresponding to the target vector to the client.
[0243] It can be understood that the above search method can be used to search one database in the retrieval system, and can also be used to search multiple databases in the retrieval system.
[0244] For example, when the retrieval system includes only one database, when the search method is used to search the database in the retrieval system, the retrieval system can perform a search on the database according to the query vector. Figure 8 The search method shown in is used to obtain the search result output corresponding to the database. It can be understood that the search result can be the original data corresponding to the target vector of the query vector retrieved from the database.
[0245] When the retrieval system includes multiple databases, the retrieval system can perform the above-mentioned search on each of the multiple databases based on the query vector. Figure 8 The search method shown in is used to obtain a search result corresponding to each database, and then all search results are output.
[0246] It is understood that the formats of the input data acquired by the retrieval system and the output data determined by the retrieval system may be the same or different. The output data format is related to the data format contained in the searched database. For example, if the data format in the searched database includes text format, image format, or video format, the output data format may be text format, image format, or video format.
[0247] For example, when the format of the input data is a picture, the retrieval system includes a database, and the data format in the database is all pictures, the output data format is also a picture format.
[0248] For example, when the retrieval system includes a database, and the data format in the database includes text format, picture format or video format, the data format output by the retrieval system may be text format, picture format or video format.
[0249] For example, when the retrieval system includes a first database, a second database and a third database, the data format in the first database includes a text format, the data format in the second database includes a picture format, and the data format in the third database includes a video format, then the data format output by the retrieval system may be a text format, a picture format or a video format.
[0250] Figure 9 A schematic diagram of an index construction device according to an embodiment of the present application is shown. Figure 9 As shown, the index building device includes:
[0251] A first determining unit is configured to determine a target vector and a first cluster set in which the target vector is located, wherein the first cluster set has a corresponding first representative point;
[0252] A second determining unit, configured to determine at least one second representative point meeting a preset condition for the first cluster set;
[0253] The association unit is used to establish index associations between the target vector and the first representative point and the second representative point respectively.
[0254] Figure 10 A schematic diagram of a search device according to an embodiment of the present application is shown. Figure 10 As shown, the search device includes:
[0255] A first acquisition unit, configured to acquire a query vector;
[0256] a second acquiring unit, configured to acquire a first distance between the query vector and a first representative point and a second representative point corresponding to each cluster set in the database;
[0257] a first determining unit, configured to determine, based on the first distance, at least one representative point corresponding to the query vector, and use the cluster set corresponding to the at least one representative point as a target cluster set;
[0258] A third acquiring unit, configured to acquire a second distance between each feature vector in the target cluster set and the query vector;
[0259] A second determining unit is configured to determine a target vector corresponding to the query vector according to the second distance.
[0260] The embodiment of the present application also includes a retrieval system, which may include the above-mentioned index construction device, and / or at least one database and / or search device. Figure 11 A schematic diagram of a retrieval system according to an embodiment of the present application is shown. Figure 11 The retrieval system shown in includes an index building device, a database and a search device.
[0261] Figure 12 A block diagram of an electronic device according to an embodiment of the present application is shown. In one embodiment, the electronic device 1400 may include one or more processors 1404, system control logic 1408 connected to at least one of the processors 1404, system memory 1412 connected to the system control logic 1408, non-volatile memory (NVM) 1416 connected to the system control logic 1408, and a network interface 1420 connected to the system control logic 1408.
[0262] In some embodiments, the processor 1404 may include one or more single-core or multi-core processors. In some embodiments, the processor 1404 may include any combination of general-purpose processors and specialized processors (e.g., graphics processors, application processors, baseband processors, etc.). In embodiments where the electronic device 1400 employs an eNB (Evolved Node B) 101 or a RAN (Radio Access Network) controller 102, the processor 1404 may be configured to execute various embodiments, for example, one or more of the multiple embodiments shown in FIG7 or FIG8.
[0263] In some embodiments, system control logic 1408 may include any suitable interface controller to provide any suitable interface to at least one of processors 1404 and / or any suitable device or component in communication with system control logic 1408 .
[0264] In some embodiments, the system control logic 1408 may include one or more memory controllers to provide an interface to the system memory 1412. The system memory 1412 may be used to load and store data and / or instructions. In some embodiments, the memory 1412 of the electronic device 1400 may include any suitable volatile memory, such as a suitable dynamic random access memory (DRAM).
[0265] NVM / memory 1416 may include one or more tangible, non-transitory computer-readable media for storing data and / or instructions. In some embodiments, NVM / memory 1416 may include any suitable non-volatile memory such as flash memory and / or any suitable non-volatile storage device, such as at least one of an HDD (Hard Disk Drive), a CD (Compact Disc) drive, and a DVD (Digital Versatile Disc) drive.
[0266] NVM / storage 1416 may include a portion of storage resources on the device on which electronic device 1400 is installed, or it may be accessible to the device but not necessarily part of the device. For example, NVM / storage 1416 may be accessed over a network via network interface 1420.
[0267] In particular, system memory 1412 and NVM / storage 1416 may include, respectively, a temporary copy and a permanent copy of instructions 1424. Instructions 1424 may include instructions that, when executed by at least one of processors 1404, cause electronic device 1400 to perform the following operations: Figure 3a In some embodiments, the instructions 1424, hardware, firmware, and / or software components thereof may additionally or alternatively be located in the system control logic 1408, the network interface 1420, and / or the processor 1404.
[0268] The network interface 1420 may include a transceiver for providing a radio interface for the electronic device 1400, thereby communicating with any other suitable devices (such as a front-end module, an antenna, etc.) through one or more networks. In some embodiments, the network interface 1420 may be integrated with other components of the electronic device 1400. For example, the network interface 1420 may be integrated with at least one of the processor 1404, the system memory 1412, the NVM / storage 1416, and a firmware device (not shown) having instructions. When at least one of the processors 1404 executes the instructions, the electronic device 1400 implements the following. Figure 7 Or the method shown in 8.
[0269] The network interface 1420 may further include any suitable hardware and / or firmware to provide a multiple-input multiple-output radio interface. For example, the network interface 1420 may be a network adapter, a wireless network adapter, a telephone modem, and / or a wireless modem.
[0270] In one embodiment, at least one of the processors 1404 may be packaged together with logic for one or more controllers of the system control logic 1408 to form a system-in-package (SiP). In one embodiment, at least one of the processors 1404 may be integrated on the same die with logic for one or more controllers of the system control logic 1408 to form a system-on-chip (SoC).
[0271] Electronic device 1400 may further include an input / output (I / O) device 1432. I / O device 1432 may include a user interface that enables a user to interact with electronic device 1400; peripheral component interfaces may also be designed to enable peripheral components to interact with electronic device 1400. In some embodiments, electronic device 1400 may further include a sensor for determining at least one of environmental conditions and location information related to electronic device 1400.
[0272] In some embodiments, the user interface may include, but is not limited to, a display (e.g., an LCD display, a touch screen display, etc.), a speaker, a microphone, one or more cameras (e.g., a still image camera and / or a video camera), a flashlight (e.g., an LED flash), and a keyboard.
[0273] In some embodiments, the peripheral component interface may include, but is not limited to, a non-volatile memory port, an audio jack, and a power interface.
[0274] In some embodiments, the sensors may include, but are not limited to, a gyroscope sensor, an accelerometer, a proximity sensor, an ambient light sensor, and a positioning unit. The positioning unit may also be part of or interact with the network interface 1420 to communicate with components of a positioning network (e.g., Global Positioning System (GPS) satellites).
[0275] The various embodiments of the mechanisms disclosed in this application can be implemented in hardware, software, firmware, or a combination of these implementation methods. The embodiments of the present application can be implemented as a computer program or program code executed on a programmable system, which includes at least one processor, a storage system (including volatile and non-volatile memory and / or storage elements), at least one input device, and at least one output device.
[0276] Program code can be applied to input instructions to perform the functions described herein and generate output information. The output information can be applied to one or more output devices in a known manner. For purposes of this application, a processing system includes any system having a processor such as, for example, a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.
[0277] Program code can be implemented with a high-level programming language or an object-oriented programming language to communicate with the processing system. Where necessary, program code can also be implemented in assembly language or machine language. In fact, the mechanism described in this application is not limited to the scope of any particular programming language. In either case, the language can be a compiled language or an interpreted language.
[0278] In some cases, the disclosed embodiments may be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments may also be implemented as instructions carried or stored on one or more temporary or non-temporary machine-readable (e.g., computer-readable) storage media, which may be read and executed by one or more processors. For example, the instructions may be distributed over a network or through other computer-readable media. Therefore, a machine-readable medium may include any mechanism for storing or transmitting information in a form readable by a machine (e.g., a computer), including but not limited to floppy disks, optical disks, optical discs, read-only memories (CD-ROMs), magneto-optical disks, read-only memories (ROMs), random access memories (RAMs), erasable programmable read-only memories (EPROMs), electrically erasable programmable read-only memories (EEPROMs), magnetic or optical cards, flash memory, or a tangible machine-readable memory for transmitting information (e.g., carrier waves, infrared signals, digital signals, etc.) using the Internet in electrical, optical, acoustic, or other forms of propagation signals. Therefore, a machine-readable medium includes any type of machine-readable medium suitable for storing or transmitting electronic instructions or information in a form readable by a machine (e.g., a computer).
[0279] An embodiment of the present application provides a computer program product, including instructions, which are used to implement the above-mentioned index construction method or the above-mentioned vector search method.
[0280] In the accompanying drawings, some structural or method features may be shown in a particular arrangement and / or order. However, it should be understood that such a particular arrangement and / or order may not be required. Rather, in some embodiments, these features may be arranged in a manner and / or order different from that shown in the accompanying drawings. In addition, the inclusion of a structural or method feature in a particular figure does not imply that such a feature is required in all embodiments, and in some embodiments, such features may not be included or may be combined with other features.
[0281] It should be noted that the units / modules mentioned in the various device embodiments of the present application are all logical units / modules. Physically, a logical unit / module can be a physical unit / module, or a part of a physical unit / module, or can be implemented as a combination of multiple physical units / modules. The physical implementation of these logical units / modules themselves is not the most important. The combination of functions implemented by these logical units / modules is the key to solving the technical problems raised by this application. In addition, in order to highlight the innovative part of this application, the above-mentioned device embodiments of this application do not introduce units / modules that are not closely related to solving the technical problems raised by this application. This does not mean that other units / modules do not exist in the above-mentioned device embodiments.
[0282] It should be noted that in the examples and description of this patent, relational terms such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "including a" does not exclude the presence of other identical elements in the process, method, article or device that includes the element.
[0283] While the present application has been shown and described with reference to certain preferred embodiments thereof, it will be understood by those skilled in the art that various changes in form and details may be made therein without departing from the scope of the present application.
Claims
1. A vector search method, characterized in that: include: Determine a target vector and a first cluster set in which the target vector is located, wherein the first cluster set has a corresponding first representative point, the first representative point corresponding to the first cluster set is the center point of the first cluster set, and the target vector is a feature vector corresponding to the data in the database; Determining at least one second representative point that meets a preset condition for the first cluster set, where the second representative point corresponding to the first cluster set is an edge point of the first cluster set; establishing index associations between the target vector and a first representative point of the first cluster set and a second representative point of the first cluster set respectively; Get the query vector; Obtaining a first distance between the query vector and a first representative point corresponding to each cluster set in the database and a second representative point corresponding to each cluster set, where the first representative point corresponding to each cluster set is the center point of the corresponding cluster set, and the second representative point corresponding to each cluster set is the edge point of the corresponding cluster set; determining, based on the first distance, at least one representative point corresponding to the query vector, and taking the cluster set corresponding to the at least one representative point as a target cluster set; Obtaining a second distance between each feature vector in the target cluster set and the query vector; A feature vector corresponding to the query vector is determined according to the second distance.
2. The vector search method according to claim 1, characterized in that: in, Determining at least one second representative point that meets a preset condition for the first cluster set includes: Determining a first distance between each feature vector in the first cluster set and the first representative point; A first sequence is determined from the eigenvectors according to the first distance, and a preset number of eigenvectors in the first sequence are used as the second representative points.
3. The vector search method according to claim 2, characterized in that: in, The step of determining a first sequence from the eigenvectors according to the first distance, and using a preset number of eigenvectors in the first sequence as the second representative points includes: sorting the eigenvectors from largest to smallest according to the first distance to obtain the first sequence; The first preset number of feature vectors in the first sequence are used as the second representative points.
4. The vector search method according to claim 2, characterized in that: in, Determining a first sequence from the eigenvectors according to the first distance, and using a preset number of eigenvectors in the first sequence as the second representative points includes: Taking the feature vectors whose first distance is greater than the set distance as a first sequence; using a preset number of feature vectors in the first sequence as the second representative points; Alternatively, the feature vectors in the first sequence are sorted from far to near according to the first distance, and a preset number of feature vectors before the sorting are determined as the second representative points.
5. The vector search method according to claim 1, characterized in that: in, Determining at least one second representative point that meets a preset condition for the first cluster set includes: determining at least one second cluster set adjacent to the first cluster set among other cluster sets except the first cluster set; Obtaining a first distance between each eigenvector in the first cluster set and a first representative point of the first cluster set, and a second distance between each eigenvector and a first representative point of each second cluster set; For each of the feature vectors, a first sequence corresponding to each second cluster set is obtained according to the first distance and the second distance, and a preset number of feature vectors in the first sequence are used as the second representative points.
6. The vector search method according to claim 5, characterized in that: in, For each of the feature vectors, obtaining the first sequence corresponding to each second cluster set according to the first distance and the second distance, and using a preset number of feature vectors in the first sequence as second representative points, including: The eigenvectors are sorted from large to small according to the sum of the first distance and the second distance to obtain a first sequence, and a preset number of eigenvectors in the first sequence are used as the second representative points.
7. The vector search method according to claim 1, characterized in that: in, Determining at least one second representative point that meets a preset condition for the first cluster set includes: determining at least one second cluster set adjacent to the first cluster set among other cluster sets except the first cluster set; Obtaining a second distance between each feature vector in the first cluster set and the first representative point of each second cluster set; For each of the feature vectors, a first sequence corresponding to each second cluster set is obtained according to the second distance, and a preset number of feature vectors in the first sequence are used as the second representative points.
8. The vector search method according to claim 7, characterized in that: in, For each of the feature vectors, obtaining the first sequence corresponding to each second cluster set according to the second distance, and using a preset number of feature vectors in the first sequence as second representative points, including: The eigenvectors are sorted from small to large according to the second distance to obtain a first sequence corresponding to each second cluster set, and the first preset number of eigenvectors in the first sequence are used as the second representative points.
9. The vector search method according to any one of claims 5 to 8, characterized in that: in, Determining at least one second cluster set adjacent to the first cluster set among other cluster sets except the first cluster set includes: Get the first generation of representative points corresponding to the other cluster sets and the first cluster set The distance between the table points; According to the distance, a second sequence is determined from cluster sets other than the first cluster set, and a preset number of cluster sets in the second sequence are determined as the second cluster set.
10. The vector search method according to claim 1, characterized in that: Determining a first cluster set where the target vector is located includes: Obtaining the distance between the target vector and the first representative points corresponding to all cluster sets; Among all cluster sets, the cluster set with the shortest distance between the corresponding first representative point and the target vector is used as the first cluster set where the target vector is located.
11. The vector search method according to claim 10, characterized in that: The distance includes at least one of the following: Euclidean distance, inner product distance and Hamming distance.
12. The vector search method according to claim 1, characterized in that: The step of determining a feature vector corresponding to the query vector according to the second distance includes: The feature vector whose second distance is within the set range is used as the feature vector corresponding to the query vector.
13. A vector search device, characterized in that: Applied to database: including: a first determining unit, configured to determine a target vector and a first cluster set to which the target vector belongs, wherein the first cluster set has a corresponding first representative point, the first representative point corresponding to the first cluster set is a center point of the first cluster set, and the target vector is a feature vector corresponding to the data in the database; A second determining unit is configured to determine at least one second representative point that meets a preset condition for the first cluster set, wherein the second representative point corresponding to the first cluster set is an edge point of the first cluster set; an association unit, configured to establish index associations between the target vector and a first representative point corresponding to the first cluster set and a second representative point corresponding to the first cluster set; A first acquisition unit, configured to acquire a query vector; The second acquisition unit is used to obtain the query vector corresponding to each cluster set in the database. a first distance between the first representative point and the second representative point corresponding to each cluster set, wherein the first representative point corresponding to each cluster set is the center point of the corresponding cluster set, and the second representative point corresponding to each cluster set is the edge point of the corresponding cluster set; a first determining unit, configured to determine, based on the first distance, at least one representative point corresponding to the query vector, and use the cluster set corresponding to the at least one representative point as a target cluster set; A third acquiring unit, configured to acquire a second distance between each feature vector in the target cluster set and the query vector; The second determining unit is configured to determine a feature vector corresponding to the query vector according to the second distance.
14. A retrieval system, characterized in that: Including the vector search device as claimed in claim 13.
15. A database, characterized in that comprising an index structure, the index structure being used to implement the vector search method according to any one of claims 1 to 12, the index structure comprising a representative point item and an inverted file item; The representative point item includes a first representative point and at least one second representative point corresponding to each cluster set in the database, and the inverted file item includes each inverted file corresponding to each cluster set, wherein the first representative point is the center point of the corresponding cluster set, and the second representative point is the edge point of the corresponding cluster set; The inverted file includes each feature vector in the cluster set corresponding to the inverted file, and each feature vector is a feature vector corresponding to data in a database.
16. An electronic device, characterized in that: include: A memory for storing instructions executed by one or more processors of an electronic device, and a processor, which is one of the one or more processors of the electronic device, for executing the vector search method according to any one of claims 1 to 12.
17. A readable medium, characterized in that The readable medium stores instructions, which, when executed on an electronic device, enable the machine to execute the vector search method according to any one of claims 1 to 12.
18. A computer program product, characterized in that The method comprises instructions for implementing the vector search method according to any one of claims 1 to 12.
Citation Information
Patent Citations
Balanced image clustering method based on hierarchical clustering
CN103049514A
High-dimensional vector quantity search method combining clustering and double key values
CN103500165A