Data processing method, electronic device, readable storage medium, and program product

By adjusting the neighbor relationships and quantized encoding storage of nodes in the graph index, the problem of inaccurate query results caused by inappropriate node distribution in the graph index was solved, resulting in more efficient query results and faster calculation speed.

WO2025227864A1PCT designated stage Publication Date: 2025-11-06HUAWEI TECH CO LTD

Patent Information

Application Number
PCT/CN2025/075296
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2024-04-29
Filing Date
2025-01-26
Publication Date
2025-11-06

AI Technical Summary

Technical Problem

In existing graph indexes, the spatial distribution of a node's neighbors is inappropriate, which affects the accuracy of query results and makes it easy to get trapped in local optima.

Method used

By detecting whether a node's neighboring nodes meet angle thresholds, distance thresholds, or neighboring node quantity thresholds, the neighbor relationships are adjusted. Quantized encoding is used to store nodes, and the storage and calculation of quantized encoding are optimized in the AVX-512 or AVX-1024 instruction set environment to improve query speed.

Benefits of technology

It improves the accuracy of query results, avoids local optima, reduces the waste of computing resources, and improves query efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025075296_06112025_PF_FP_ABST
    Figure CN2025075296_06112025_PF_FP_ABST
Patent Text Reader

Abstract

The present application relates to the field of information retrieval, and in particular relates to a data processing method, an electronic device, a readable storage medium, and a program product. In the method, when a query result of a query vector needs to be searched in a constructed graph index, neighbor nodes of at least some nodes among multiple nodes included in the graph index satisfy at least one of the following: the included angle between two vectors obtained by subtracting a node from any two neighbor nodes of the node is greater than or equal to a first angle threshold value, the distance between any two neighbor nodes of the node is greater than or equal to a first distance threshold value, and the number of neighbor nodes of the node within a preset space range is smaller than a first number. Thus, the neighbor nodes of the nodes in the constructed graph index are relatively dispersed in space, and the problem that a query result falls into a local optimum due to being unable to find nodes at a certain portion of space during a node-based neighbor node search process, because the nodes are densely distributed at a certain position, is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Data processing method, electronic device, readable storage medium and program product

[0001] The present application claims priority to the Chinese patent application No. 202410533951.9, filed on April 29, 2024, entitled “Data processing method, electronic device, readable storage medium and program product”, the whole content of which is incorporated herein by reference. TECHNICAL FIELD

[0002] The present application relates to the field of information retrieval, and in particular to a data processing method, an electronic device, a readable storage medium and a program product. BACKGROUND

[0003] In the current “Internet of Everything, comprehensive perception” data era, how to effectively search for the corresponding target data from massive high-dimensional data is a hot research issue in the field of information retrieval. For example, in massive data, it is necessary to efficiently search for desired image, text, audio and video data.

[0004] In the prior art, traditional nearest neighbor search (NNS) algorithm and approximate nearest neighbor search (ANNS) algorithm can be used, wherein the NNS algorithm method can obtain ideal search accuracy, but the query efficiency is relatively low due to the influence of data size, and may not meet the actual application requirements. The ANNS algorithm can effectively balance the search accuracy and efficiency, and has received extensive attention from researchers.

[0005] At present, the ANNS algorithm can be based on different search strategies: hash coding, tree index, graph index, dimensionality reduction quantization, etc., and is subdivided into different types. Among them, the ANNS algorithm based on graph index has achieved relatively optimal query efficiency under a given search accuracy. So-called graph index, that is, each high-dimensional vector data is regarded as a node, and the neighbor relationship between nodes is constructed according to the vector similarity. When searching specifically, the query can be performed according to the neighbor relationship between nodes. For example, a node G1 is used to find the neighbor of the node G1, that is, the node G2, and then the neighbor of the node G2, that is, the node G3, is found.

[0006] However, when constructing the graph index, only the distance between nodes is considered, and the neighbor relationship is determined according to the distance between nodes, for example, nodes with a distance less than a preset distance from a node are all regarded as neighbor nodes of the node. In the graph index determined in the above manner, if the number of nodes in a sub-space region of the high-dimensional space is large, the node distribution in the sub-space region can have an "aggregation" phenomenon, so that some nodes in the sub-space region are associated with nodes (for example, nodes including at least one layer of neighbor nodes) distributed densely. Since the number of neighbor nodes of each node is limited, the neighbor nodes of the nodes can all be nodes in the sub-space region, and if the retrieval is performed based on the nodes as an entry, it is equivalent to searching for the result in the above-mentioned densely distributed sub-space region, and a locally optimal query result is obtained, which affects the accuracy of the query result. SUMMARY

[0007] The present application provides a data processing method, an electronic device, a readable storage medium and a program product, in order to solve the problem that the accuracy of the query result is affected due to the inappropriate distribution of the neighbors of the nodes in the constructed graph index.

[0008] In a first aspect, an embodiment of the present application provides a data processing method applied to an electronic device, the method comprising: detecting a query request, the query request being used to request to find a query result of a first query vector in a first graph index, wherein the first graph index comprises a plurality of nodes, and neighbor nodes of at least part of the plurality of nodes satisfy a first condition, the first condition comprising at least one of the following: an included angle between two vectors obtained by subtracting the node from any two neighbor nodes of the node is greater than or equal to a first angle threshold, a distance between any two neighbor nodes of the node is greater than or equal to a first distance threshold, and a number of neighbor nodes of the node within a preset space range is less than a first number; from the plurality of nodes, finding at least one target node corresponding to the first query vector; and taking content corresponding to the at least one target node as the query result of the first query vector.

[0009] It can be understood that the first graph index can be a following approximate K-Nearest Neighbor graph, a satellite graph or a quantized satellite graph. A plurality of nodes are included in the first graph index, and a neighbor relationship can exist between the plurality of nodes, that is, a certain node can be a neighbor node of another node, and in the process of querying based on the first graph index, the target node corresponding to the first query vector will be searched based on the neighbor nodes of each node. When the neighbor nodes of at least part of the plurality of nodes satisfy the first condition, the first condition includes at least one of the following: the included angle between two vectors obtained by subtracting the node from any two neighbor nodes of the node is greater than or equal to a first angle threshold, the distance between any two neighbor nodes of the node is greater than or equal to a first distance threshold, and the number of neighbor nodes of the node within a predetermined spatial range is less than a first number. At this time, the neighbor nodes of the node will not be too close, so that the nodes available for querying in the first graph index will be dispersed in space, that is, there will be more possible routes to nodes at different spatial positions, thereby avoiding the problem that the query result falls into local optimization due to the dense distribution of nodes at a certain place, and the nodes at a certain part of the space cannot be found in the process of searching based on the neighbor nodes of the node.

[0010] In a possible implementation of the first aspect, the method further includes: obtaining the neighbor nodes satisfying the first condition by: determining a plurality of first nodes from the plurality of nodes, the plurality of first nodes having a distance to the node less than a second distance threshold; and taking as the neighbor nodes the nodes in the plurality of first nodes satisfying the first condition.

[0011] It can be understood that when establishing the neighbor relationship, a plurality of first nodes are determined from the plurality of nodes, the plurality of first nodes having a distance to the node less than a second distance threshold; and the nodes in the plurality of first nodes satisfying the first condition are taken as the neighbor nodes, so that the distance between the obtained neighbor nodes and the node satisfies a second distance range, and this method is reasonable and scientific.

[0012] In a possible implementation of the first aspect, the number of neighbor nodes of the node is less than a second number.

[0013] It can be understood that controlling the number of neighbor nodes of the node to be within the second number can improve the speed of searching the query result corresponding to the first query vector. For example, the second number can be an out-degree threshold.

[0014] In a possible implementation of the first aspect, the first condition further includes: the distance between a first neighbor node in the neighbor nodes of the node and a second neighbor node in the neighbor nodes of the node is greater than the sum of the distance between the first neighbor node and the node and the distance between the second neighbor node and the node, wherein the second neighbor node is a neighbor node of the first neighbor node.

[0015] It can be understood that when the distance between the first neighbor node in the neighbor nodes of the node and the second neighbor node in the neighbor nodes of the node is greater than the sum of the distance between the first neighbor node and the node and the distance between the second neighbor node and the node, where the second neighbor node is a neighbor node of the first neighbor node, the second neighbor node can be avoided to be searched for a long time.

[0016] In a possible implementation of the first aspect, the node in the first graph index is quantized encoding of the corresponding content.

[0017] It can be understood that the node can be quantized, for example, by using product quantization (PQ) or optimizing product quantization (OPQ) to obtain quantized encoding corresponding to each subsegment of the node, and the node is stored in quantized encoding with smaller data volume. The node in the first graph index is quantized encoding of the corresponding content. This way, it is beneficial to save storage space.

[0018] In a possible implementation of the first aspect, the at least one target node corresponding to the first query vector is searched from the plurality of nodes, including: determining the at least one target node corresponding to the first query vector based on the quantized distance between the first query vector and the quantized encoding of the neighbor node of the at least one node in the plurality of nodes.

[0019] It can be understood that the node can be quantized, and the at least one target node corresponding to the first query vector can be quickly found by calculating the quantized distance between the first query vector and the quantized encoding of the neighbor node of the at least one node in the plurality of nodes.

[0020] In a possible implementation of the first aspect, the node is divided into T subsegments, each subsegment corresponding to a quantized encoding; and the quantized encoding is represented by 4-bit data, T is a positive integer, and T is less than or equal to the vector dimension corresponding to the node; and in an environment using the AVX-512 instruction set, the quantized encoding of the neighbor node of the node is stored in the following manner: the quantized encoding of the same subsegment of each 32 neighbor nodes is stored by 16 consecutive bytes, and the quantized encoding of the T subsegments of the 32 neighbor nodes is stored by 16xT consecutive bytes.

[0021] It can be understood that in an environment using the AVX-512 instruction set, each register has 512 bits of space available, and in this case, 32 neighbor nodes are stored as a group, so in the environment of the AVX-512 instruction set, the register can directly load the quantized encoding of 4 subsegments of 32 neighbor nodes at a time, a total of 512 bits, avoiding 50% of the register space waste.

[0022] In a possible implementation of the first aspect, the quantized codes of the same sub-segment of 32 neighbor nodes are stored by 16 consecutive bytes, including: the lower four bits of the 2Lth byte of the 16 bytes store the quantized code of the Lth neighbor node of the 32 neighbor nodes, and the upper four bits of the 2Lth byte of the 16 bytes store the quantized code of the L+16th neighbor node, where L is an integer greater than or equal to 0 and less than or equal to 7; the lower four bits of the 2L+1th byte of the 16 bytes store the quantized code of the L+8th neighbor node of the 32 neighbor nodes, and the upper four bits of the 2L+1th byte of the 16 bytes store the quantized code of the L+24th neighbor node.

[0023] It can be understood that, since the numbers of the 2 neighbor nodes stored in each byte differ by 16, i.e., the 0th to 15th neighbor nodes of the 32 neighbors are stored in the lower 4 bits of each byte, and the 16th to 31st neighbor nodes of the 32 neighbors are stored in the upper 4 bits of each byte, it is convenient to store the quantized codes corresponding to the 0-15th neighbor nodes of the sub-segment as a byte in a register and the quantized codes corresponding to the 16-31st neighbor nodes of the sub-segment as a byte in another register by reading the upper and lower bits of each byte, respectively, to facilitate subsequent obtaining of the quantized distances of the neighbor nodes corresponding to the quantized codes of the byte size. Moreover, when L is the same, the numbers of the neighbor nodes stored in the 2L+1th byte are 8 greater than the numbers of the neighbor nodes stored in the 2Lth byte. As L increases, the numbers of the neighbor nodes stored in each 2 bytes also increase in turn, which facilitates subsequent obtaining of the quantized distances of the neighbor nodes in the order of small to large numbers with respect to the 16-bit quantized distance of the first query vector by only simple shifting and addition / subtraction, thereby reducing the use of extension instructions and improving the calculation speed.

[0024] In a possible implementation of the first aspect, the quantized distances between the first query vector and the quantized codes of the consecutive 4 sub-segments of the neighbor nodes of the second node in the at least one node are determined based on the following manner: loading the quantized codes of the consecutive 4 sub-segments of the 32 neighbor nodes of the second node from the first memory to the first register at a time; and obtaining the quantized distances between the first query vector and the quantized codes of the consecutive 4 sub-segments of the 32 neighbor nodes based on the data in the first register.

[0025] It can be understood that the quantized codes of the consecutive 4 sub-segments of the 32 neighbor nodes of the second node are loaded from the first memory to the first register at a time, and the waste of register space is avoided.

[0026] In a possible implementation of the first aspect, based on the data in the first register, the quantization distances between the first query vector and the quantization encodings of the continuous 4 sub-segments of the 32 neighbor nodes are obtained by: storing the lower 4 bits of each byte of the data in the first register as a byte to obtain first encoded data, and storing the higher 4 bits of each byte of the data in the first register as a byte to obtain second encoded data; obtaining first distance data from the first distance matrix lookup table based on the first encoded data, and obtaining second distance data from the first distance matrix lookup table based on the second encoded data, wherein the first distance data includes the quantization distances between the first query vector and the continuous 4 sub-segments of the 0th neighbor node to the 15th neighbor node, and each 2L byte of every 16 bytes stores the quantization distance between the Lth neighbor sub-segment and the first query vector, and each 2L+1 byte of every 16 bytes stores the quantization distance between the L+8th neighbor sub-segment and the first query vector, and the second distance data U1 includes the quantization distances between the first query vector and the continuous 4 sub-segments of the 16th neighbor node to the 31st neighbor node, and each 2L byte of every 16 bytes stores the quantization distance between the L+16th neighbor sub-segment and the first query vector, and each 2L+1 byte of every 16 bytes stores the quantization distance between the L+24th neighbor sub-segment and the first query vector; moving each 16-bit data of the first distance data by 8 bits in the low bit direction to obtain 64 bytes of third distance data, and each 16 bytes of the third distance data includes 8 2L bytes, which are the quantization distances between the first query vector and one sub-segment of the 8th neighbor node to the 15th neighbor node, respectively; subtracting the fourth distance data from the first distance data according to each 16-bit data to obtain fifth distance data, wherein the fourth distance data is obtained by moving each 16-bit data of the third distance data by 8 bits in the high bit direction, and the fifth distance data includes the quantization distances between the first query vector and the 4 sub-segments of the 0th neighbor node to the 7th neighbor node; moving each 16-bit data of the second distance data by 8 bits in the low bit direction to obtain 64 bytes of sixth distance data, and each 16 bytes of the sixth distance data includes 8 2L bytes, which are the quantization distances between the first query vector and one sub-segment of the 24th neighbor node to the 31st neighbor node, respectively; subtracting the seventh distance data from the second distance data according to each 16-bit data to obtain eighth distance data, wherein the seventh distance data is obtained by moving each 16-bit data of the sixth distance data by 8 bits in the high bit direction, and the eighth distance data includes the quantization distances between the first query vector and the 4 sub-segments of the 16th neighbor node to the 23rd neighbor node.

[0027] It can be understood that, at this time, according to the above processing manner, the quantized distances of the continuous 4 sub-segments of the 0th to 31st neighbor nodes and the first query vector of the 16-bit size can be obtained only by simple shift and addition and subtraction operations, and the order of the obtained quantized distances is consistent with the numbering order of the 0th to 31st neighbor nodes, thereby reducing the use of extension instructions and improving the calculation speed.

[0028] In a possible implementation of the first aspect, the nodes are divided into T sub-segments, each sub-segment corresponding to a quantized code; and the quantized code is represented by 4-bit data, T is a positive integer, and T is less than or equal to the vector dimension corresponding to the nodes; and in the environment using the AVX-1024 instruction set, the quantized codes of the neighbor nodes of the nodes are stored in the following manner: the quantized codes of the same sub-segment of each 64 neighbor nodes are stored by consecutive 32 bytes, and the quantized codes of the T sub-segments of the 64 neighbor nodes are stored by consecutive 32xT bytes.

[0029] It can be understood that, in the environment using the AVX-1024 instruction set, each register has 1024-bit space available, and at this time, the storage is in groups of 64 neighbor nodes, so in the environment using the AVX-1024 instruction set, the register can directly load the quantized codes of 4 sub-segments of 64 neighbor nodes at a time, a total of 1024 bits, avoiding waste of register space.

[0030] In a possible implementation of the first aspect, the quantized codes of the same sub-segment of each 64 neighbor nodes are stored by consecutive 32 bytes, including: storing the quantized code of the Lth neighbor node of the 64 neighbor nodes in the lower four bits of the 2Lth byte of the 32 bytes, and storing the quantized code of the L+32th neighbor node in the higher 4 bits of the 2Lth byte of the 32 bytes, where L is an integer greater than or equal to 0 and less than or equal to 15; storing the quantized code of the L+16th neighbor node of the 64 neighbor nodes in the lower four bits of the 2L+1th byte of the 32 bytes, and storing the quantized code of the L+48th neighbor node in the higher 4 bits of the 2L+1th byte of the 32 bytes.

[0031] It can be understood that, since the number of each byte stored 2 neighbor nodes is different by 32 when storing, i.e. the 0th neighbor node to the 31st neighbor node of the 64 neighbors is stored in the low 4 bits of each byte, and the 32nd neighbor node to the 63rd neighbor node of the 64 neighbors is stored in the high 4 bits of each byte, it is convenient to store the quantization code corresponding to the 0-31th neighbor node subsegment as a byte in a register by reading the high and low bits of each byte, and store the quantization code corresponding to the 32-63th neighbor node subsegment as a byte in another register, so as to facilitate subsequent quantization distance corresponding to each neighbor node based on byte size quantization code. And when L is the same, the number of neighbor nodes stored in each four bits in the 2L+1th byte is greater than the number of neighbor nodes stored in the corresponding four bits in the 2Lth byte. 16. With the increase of L, the number of neighbor nodes stored in each 2 bytes also increases in turn, which facilitates subsequent obtaining of the 16-bit quantization distance of each neighbor node according to the small-to-large number order with respect to the first query vector only by simple shifting and addition and subtraction, thereby reducing the use of extension instructions and improving the calculation speed.

[0032] In a possible implementation of the first aspect, the quantization distance between the first query vector and the quantization code of the continuous 4 subsegments of the neighbor nodes of the second node in the at least one node is determined based on the following manner: loading the quantization code of the continuous 4 subsegments of the 64 neighbor nodes of the second node from the second memory to the second register at a time; based on the data in the second register, obtaining the quantization distance between the first query vector and the quantization code of the continuous 4 subsegments of the 64 neighbor nodes.

[0033] It can be understood that, at a time, the quantization code of the continuous 4 subsegments of the 64 neighbor nodes of the second node is loaded from the second memory to the first register, and the register space is avoided to be wasted.

[0034] In a possible implementation of the first aspect, based on the data in the second register, the quantization distances between the first query vector and the quantization encoding of the continuous 4 sub-segments of the 64 neighbor nodes are obtained, including: storing the low 4 bits of each byte of the data in the second register as a byte to obtain third encoded data, and storing the high 4 bits of each byte of the data in the second register as a byte to obtain fourth encoded data; obtaining ninth distance data from the second distance matrix lookup table based on the third encoded data, and obtaining tenth distance data from the second distance matrix lookup table based on the fourth encoded data, wherein the ninth distance data includes the quantization distances between the first query vector and the continuous 4 sub-segments of the 0th neighbor node to the 31st neighbor node, and each 2L byte in every 32 bytes stores the quantization distance between the Lth neighbor sub-segment and the first query vector, and the 2L+1 byte stores the quantization distance between the L+16th neighbor sub-segment and the first query vector, and the tenth distance data includes the quantization distances between the first query vector and the continuous 4 sub-segments of the 32nd neighbor node to the 63rd neighbor node, and each 2L byte in every 32 bytes stores the quantization distance between the L+32th neighbor sub-segment and the first query vector, and the 2L+1 byte stores the quantization distance between the L+48th neighbor sub-segment and the first query vector; moving each 16-bit data of the ninth distance data by 8 bits in the low bit direction to obtain 128 bytes of eleventh distance data, and in each 32 bytes of the eleventh distance data, 16 2L bytes are respectively the quantization distances between one sub-segment of the 16th neighbor node to the 31st neighbor node and the first query vector; subtracting the twelfth distance data from the ninth distance data according to each 16-bit data to obtain thirteenth distance data, wherein the twelfth distance data is the data obtained by moving each 16-bit data of the eleventh distance data by 8 bits in the high bit direction, and the thirteenth distance data includes the quantization distances between the 4 sub-segments of the 0th neighbor node to the 15th neighbor node and the first query vector; moving each 16-bit data of the tenth distance data by 8 bits in the low bit direction to obtain 128 bytes of fourteenth distance data, and in each 32 bytes of the fourteenth distance data, 16 2L bytes are respectively the quantization distances between one sub-segment of the 48th neighbor node to the 63rd neighbor node and the first query vector; subtracting the fifteenth distance data from the tenth distance data according to each 16-bit data to obtain sixteenth distance data, wherein the fifteenth distance data is the data obtained by moving each 16-bit data of the fourteenth distance data by 8 bits in the high bit direction, and the sixteenth distance data includes the quantization distances between the 4 sub-segments of the 32nd neighbor node to the 47th neighbor node and the first query vector.

[0035] It can be understood that, at this time, according to the processing mode as above, only through simple shift and addition and subtraction operations, the quantized distances of the continuous 4 sub-segments of the 0th neighbor node to the 64th neighbor node and the first query vector of the 16-bit size can be obtained, and the order of the obtained quantized distances is consistent with the numbering order of the 0th neighbor node to the 64th neighbor node, thereby reducing the use of the extension instruction and improving the calculation speed.

[0036] In a second aspect, an embodiment of the present application provides an application to an electronic device, and a method includes: obtaining a plurality of nodes to be constructed in a graph index; determining first candidate neighbor nodes of each node based on distances between the plurality of nodes; taking the first candidate neighbor nodes satisfying a first condition as second candidate neighbor nodes of the node, wherein the first condition includes at least one of: an included angle between two vectors obtained by subtracting the node from any two second candidate neighbor nodes of the node being greater than or equal to a first angle threshold, a distance between any two second candidate neighbor nodes of the node being greater than or equal to a first distance threshold, and a number of the second candidate neighbor nodes of the node within a preset spatial range being less than a first number; obtaining neighbor nodes of each node based on the second candidate neighbor nodes of each node; and obtaining a first graph index based on each node and the neighbor nodes of each node.

[0037] It can be understood that the first graph index can be an approximate K-nearest neighbor graph, a satellite graph, or a quantized satellite graph. When constructing the first graph index, a training set including a plurality of nodes can be obtained, and at this time, constructing the first graph index is essentially constructing the neighbor relationship between the nodes, i.e., determining the neighbor nodes of each node. When determining the neighbor nodes of each node, first candidate neighbor nodes of each node are determined based on distances between the plurality of nodes, and then the first candidate neighbor nodes satisfying a first condition are taken as second candidate neighbor nodes of the node, wherein the first condition includes at least one of: an included angle between two vectors obtained by subtracting the node from any two second candidate neighbor nodes of the node being greater than or equal to a first angle threshold, a distance between any two second candidate neighbor nodes of the node being greater than or equal to a first distance threshold, and a number of the second candidate neighbor nodes of the node within a preset spatial range being less than a first number, which can ensure that the determined second candidate neighbor nodes are dispersed in space. At this time, neighbor nodes of each node are obtained based on the second candidate neighbor nodes of each node. Thus, the determined neighbor nodes are not too close to each other, and the nodes available for query in the first graph index are dispersed in space, thereby avoiding the problem that the query result falls into a local optimum due to the dense distribution of nodes in a certain place, which makes it impossible to find nodes in a certain part of the space in the process of searching based on the neighbor nodes of the nodes.

[0038] In a possible implementation of the second aspect, the neighbor nodes of each node are obtained based on the second candidate neighbor nodes of each node, including: adjusting the second candidate neighbor nodes of the node in at least one of the following manners, and taking the adjusted second candidate neighbor nodes as the neighbor nodes of the node: in response to the number of the second candidate neighbor nodes of the node being greater than or equal to the second number, reducing the number of the second candidate neighbor nodes to be less than the second number; in response to the number of nodes taking the node as a neighbor node being less than the third number, taking the node as at least part of the neighbor nodes of the node; in response to the distance between a first node in the second candidate neighbor nodes of the node and a second node in the second candidate neighbor nodes of the node being less than the sum of the distance between the first node and the node and the distance between the second node and the node, deleting the second node from the second candidate neighbor nodes of the node, where the second node is a neighbor node of the first node.

[0039] For example, the second number is the out-degree threshold value below, and the third number is the in-degree threshold value below.

[0040] It can be understood that, after obtaining the second candidate neighbor nodes of each node, the second candidate neighbor nodes can be directly taken as the neighbor nodes, or the second candidate neighbor nodes of the node can be fine-tuned, in response to the number of the second candidate neighbor nodes of the node being greater than or equal to the second number, reducing the number of the second candidate neighbor nodes to be less than the second number; in response to the number of nodes taking the node as a neighbor node being less than the third number, taking the node as at least part of the neighbor nodes of the node; in response to the distance between a first node in the second candidate neighbor nodes of the node and a second node in the second candidate neighbor nodes of the node being less than the sum of the distance between the first node and the node and the distance between the second node and the node, deleting the second node from the second candidate neighbor nodes of the node, where the second node is a neighbor node of the first node, so as to adapt to more changes.

[0041] In a possible implementation of the second aspect, the first graph index is obtained based on the nodes and the neighbor nodes of the nodes, including: dividing the nodes into T sub-segments, each sub-segment corresponding to a quantization code; and the quantization code is represented by 4-bit data, T is a positive integer, and T is less than or equal to the vector dimension corresponding to the nodes; in response to an environment using an AVX-512 instruction set, the quantization codes of the neighbor nodes of the nodes are stored in the following manner: the quantization codes of the same sub-segment of each 32 neighbor nodes are stored by 16 consecutive bytes, and the quantization codes of the T sub-segments of the 32 neighbor nodes are stored by 16×T consecutive bytes.

[0042] In a possible implementation of the second aspect, the quantized encoding of the same sub-segment of each 32 neighbor nodes is stored by consecutive 16 bytes, including: storing the quantized encoding of the Lth neighbor node in the 32 neighbor nodes in the lower 4 bits of the 2Lth byte in the 16 bytes; storing the quantized encoding of the L+16th neighbor node in the higher 4 bits of the 2Lth byte in the 16 bytes, where L is an integer greater than or equal to 0 and less than or equal to 7; storing the quantized encoding of the L+8th neighbor node in the 32 neighbor nodes in the lower 4 bits of the 2L+1th byte in the 16 bytes; and storing the quantized encoding of the L+24th neighbor node in the higher 4 bits of the 2L+1th byte in the 16 bytes.

[0043] In a possible implementation of the second aspect, the first graph index is obtained based on each node and neighbor nodes of each node, including: dividing the nodes into T sub-segments, each of which corresponds to a quantized encoding; and the quantized encoding is represented by 4-bit data, T is a positive integer, and T is less than or equal to the dimension of the vector corresponding to the node; and in an environment using the AVX-1024 instruction set, the quantized encoding of the neighbor nodes of the node is stored in the following manner: the quantized encoding of the same sub-segment of each 64 neighbor nodes is stored by consecutive 32 bytes, and the quantized encoding of the T sub-segments of the 64 neighbor nodes is stored by consecutive 32xT bytes.

[0044] In a possible implementation of the second aspect, the quantized encoding of the same sub-segment of each 64 neighbor nodes is stored by consecutive 32 bytes, including: storing the quantized encoding of the Lth neighbor node in the 64 neighbor nodes in the lower 4 bits of the 2Lth byte in the 32 bytes; storing the quantized encoding of the L+32th neighbor node in the higher 4 bits of the 2Lth byte in the 32 bytes, where L is an integer greater than or equal to 0 and less than or equal to 15; storing the quantized encoding of the L+16th neighbor node in the 64 neighbor nodes in the lower 4 bits of the 2L+1th byte in the 32 bytes; and storing the quantized encoding of the L+48th neighbor node in the higher 4 bits of the 2L+1th byte in the 32 bytes.

[0045] In a third aspect, the embodiments of the present application provide a data processing method applied to an electronic device, the method comprising: detecting a query request, the query request being used to request a query result of a first query vector in a first graph index, wherein the first graph index comprises a plurality of nodes, and neighbor nodes of the plurality of nodes are stored in a first storage according to a first storage manner; from the plurality of nodes, finding at least one target node corresponding to the first query vector; and taking content corresponding to the at least one target node as the query result of the first query vector, wherein the first storage manner comprises: the nodes are divided into T sub-segments, each sub-segment corresponds to a quantized code, and the quantized code is represented by 4-bit data, T is a positive integer, and T is less than or equal to a vector dimension corresponding to the node; in an environment using an AVX-512 instruction set, the quantized codes of the same sub-segment of every 32 neighbor nodes are stored by using 16 consecutive bytes, and the quantized codes of T sub-segments of 32 neighbor nodes are stored by using 16×T consecutive bytes; in an environment using an AVX-1024 instruction set, the quantized codes of the same sub-segment of every 64 neighbor nodes are stored by using 32 consecutive bytes, and the quantized codes of T sub-segments of 64 neighbor nodes are stored by using 32×T consecutive bytes.

[0046] It can be understood that, in the query process, if the environment using the AVX-512 instruction set, each register has 512-bit space available, at this time, 32 neighbor nodes are stored as a group, so in the environment using the AVX-512 instruction set, the register can directly load the quantized codes of 4 sub-segments of 32 neighbor nodes at a time, a total of 512 bits, avoiding 50% of the register space waste. Similarly, in the environment using the AVX-1024 instruction set, each register has 1024-bit space available, at this time, 64 neighbor nodes are stored as a group, so in the environment using the AVX-1024 instruction set, the register can directly load the quantized codes of 4 sub-segments of 64 neighbor nodes at a time, a total of 1024 bits, avoiding register space waste.

[0047] In a possible implementation of the third aspect, the quantized codes of the same sub-segment of every 32 neighbor nodes are stored by using 16 consecutive bytes, comprising: storing the quantized code of an Lth neighbor node in the 32 neighbor nodes in a lower four bits of a 2Lth byte in the 16 bytes, and storing the quantized code of an L+16th neighbor node in a higher 4 bits of the 2Lth byte in the 16 bytes, wherein L is an integer greater than or equal to 0 and less than or equal to 7; storing the quantized code of an L+8th neighbor node in the 32 neighbor nodes in a lower four bits of a 2L+1th byte in the 16 bytes, and storing the quantized code of an L+24th neighbor node in a higher 4 bits of the 2L+1th byte in the 16 bytes.

[0048] In a possible implementation of the third aspect, the quantized codes of the same sub-segment of 64 neighbor nodes are stored by 32 consecutive bytes, including: the low four bits in the 2Lth byte of the 32 bytes store the quantized code of the Lth neighbor node of the 64 neighbor nodes, the high four bits in the 2Lth byte of the 16 bytes store the quantized code of the L+32th neighbor node, where L is an integer greater than or equal to 0 and less than or equal to 15; the low four bits in the 2L+1th byte of the 32 bytes store the quantized code of the L+16th neighbor node of the 64 neighbor nodes, and the high four bits in the 2L+1th byte of the 32 bytes store the quantized code of the L+48th neighbor node.

[0049] In a possible implementation of the third aspect, the method further includes: the neighbor nodes of at least some of the plurality of nodes satisfy a first condition, the first condition including at least one of: an included angle between two vectors obtained by subtracting the node from any two neighbor nodes of the node being greater than or equal to a first angle threshold, a distance between any two neighbor nodes of the node being greater than or equal to a first distance threshold, and a number of the neighbor nodes of the node within a preset spatial range being less than a first number; from the plurality of nodes, finding at least one target node corresponding to the first query vector; and taking content corresponding to the at least one target node as a query result of the first query vector.

[0050] In a fourth aspect, an embodiment of the present application provides an electronic device, including: a memory configured to store instructions, and one or more processors, the instructions being executed by the one or more processors to perform the data processing method in the first aspect and any one of the various implementations of the first aspect, the data processing method in the second aspect and any one of the various implementations of the second aspect, or the data processing method in the third aspect and any one of the various implementations of the third aspect.

[0051] In a fifth aspect, an embodiment of the present application provides a computer-readable storage medium, the computer-readable storage medium storing instructions, the instructions being executed by an electronic device to perform the data processing method in the first aspect and any one of the various implementations of the first aspect, the data processing method in the second aspect and any one of the various implementations of the second aspect, or the data processing method in the third aspect and any one of the various implementations of the third aspect.

[0052] In a sixth aspect, an embodiment of the present application provides a computer program product, which comprises computer program codes, when the computer program codes are run on a computer, the computer program codes cause the computer to execute the data processing method in the first aspect and any one of the implementations of the first aspect, the data processing method in the second aspect and any one of the implementations of the second aspect, or the data processing method in the third aspect and any one of the implementations of the third aspect.

[0053] The beneficial effects of the fourth aspect to the sixth aspect can refer to the beneficial effects of the first aspect, the second aspect and the third aspect, which will not be repeated here. BRIEF DESCRIPTION OF DRAWINGS

[0054] FIG. 1 shows a specific retrieval scenario related to images, texts and audio / video respectively according to some embodiments of the present application;

[0055] FIG. 2A shows a retrieval scenario of searching images by texts according to some embodiments of the present application;

[0056] FIG. 2B shows a retrieval scenario of searching images by texts according to some embodiments of the present application;

[0057] FIG. 3A shows a graph index structure according to some embodiments of the present application;

[0058] FIG. 3B shows a product quantization process according to some embodiments of the present application;

[0059] FIG. 3C shows a node neighbor quantization encoding table arrangement according to some embodiments of the present application;

[0060] FIG. 3D shows an optimized product quantization process according to some embodiments of the present application;

[0061] FIG. 4 shows a process of constructing a quantized graph index and retrieving based on the constructed graph index according to some embodiments of the present application;

[0062] FIG. 5A shows a distribution of neighbor nodes of a node L0 in space according to some embodiments of the present application;

[0063] FIG. 5B shows a neighbor relationship among multiple nodes according to some embodiments of the present application;

[0064] FIG. 6A shows another distribution of neighbor nodes of a node L0 in space according to some embodiments of the present application;

[0065] FIG. 6B illustrates a schematic diagram of neighbor relationships of a node, according to some embodiments of the present disclosure;

[0066] FIG. 6C illustrates a schematic diagram of neighbor relationships of another node, according to some embodiments of the present disclosure;

[0067] FIG. 7A illustrates a schematic diagram of a process of obtaining intermediate data W3, according to some embodiments of the present disclosure;

[0068] FIG. 7B illustrates a schematic diagram of a process of obtaining accumulated data M2, according to some embodiments of the present disclosure;

[0069] FIG. 8A illustrates a schematic diagram of a quantized encoding arrangement of node neighbors, according to some embodiments of the present disclosure;

[0070] FIG. 8B illustrates a schematic diagram of a process of obtaining first encoding data E1 and second encoding data E2, according to some embodiments of the present disclosure;

[0071] FIG. 8C illustrates a schematic diagram of a process of obtaining third distance data P1, according to some embodiments of the present disclosure;

[0072] FIG. 8D illustrates a schematic diagram of a process of obtaining fifth distance data P3, according to some embodiments of the present disclosure;

[0073] FIG. 8E illustrates a schematic diagram of another quantized encoding arrangement of node neighbors, according to some embodiments of the present disclosure;

[0074] FIG. 9A illustrates a schematic diagram of a flowchart of constructing a quantized satellite graph, according to some embodiments of the present disclosure;

[0075] FIG. 9B illustrates a schematic diagram of a process of constructing a quantized satellite graph and performing a query based on the quantized satellite graph, according to some embodiments of the present disclosure;

[0076] FIG. 9C illustrates a schematic diagram of a triangle inequality strategy, according to some embodiments of the present disclosure;

[0077] FIG. 9D illustrates a schematic diagram of quantizing a query vector and calculating a quantized distance, according to some embodiments of the present disclosure;

[0078] FIG. 10A illustrates a schematic diagram of a flowchart of an index construction process involved in a data processing method, according to some embodiments of the present disclosure;

[0079] FIG. 10B illustrates a schematic diagram of a process of performing a query based on a constructed index in a data processing method, according to some embodiments of the present disclosure;

[0080] FIG. 11 illustrates a schematic diagram of a data processing apparatus 1100, according to some embodiments of the present disclosure;

[0081] FIG. 12 shows another device schematic diagram, according to some embodiments of the present application;

[0082] FIG. 13 shows an algorithm comparison effect schematic diagram, according to some embodiments of the present application;

[0083] FIG. 14 shows a general search schematic diagram, according to some embodiments of the present application;

[0084] FIG. 15 shows a device schematic diagram, according to some embodiments of the present application. DETAILED DESCRIPTION

[0085] The illustrative embodiments of the present application include but are not limited to a data processing method, an electronic device, a readable storage medium, and a program product.

[0086] The embodiments of the present application are described below with reference to the accompanying drawings.

[0087] It can be understood that with the continuous maturity of artificial intelligence technologies such as computer vision and natural language processing, multi-modal data such as video / images, text, and audio can be vectorized and encoded based on representation learning to achieve heterogeneous data feature encoding. The data processing method provided by the present application can not only be widely applied in traditional application scenarios such as web search, text search, image / video search, but also can be widely applied in diversified cross-modal intelligent search application scenarios such as image search by text, song recognition, product recommendation, and intelligent question answering, and is an important technology to achieve general search of large-scale heterogeneous data. It can be understood that when searching, the content (or the features corresponding to the content) to be searched, such as pictures, texts, audio / videos, can be stored as nodes to obtain query results according to query inputs.

[0088] For example, FIG. 1 shows some specific search scenarios related to images, texts, and audio / videos, respectively. Referring to FIG. 1, regarding images, there are image search, face recognition, and advertisement push; regarding texts, there are intelligent question answering, full-text search, and image search by text; and regarding audio / videos, there are song recognition, video search, and live broadcast recommendation.

[0089] FIGS. 2A and 2B show an image search by text search scenario, according to some embodiments of the present application. As shown in FIG. 2A, a user KA inputs a “flower” text in a search box 001A of a webpage of a terminal 100, and then selects a “picture” control 001B. At this time, a plurality of “flower” pictures shown in a box 002 in FIG. 2B can be searched based on a graph index established by a large amount of data as nodes.

[0090] As described in the background, the retrieval process can be performed using the ANNS algorithm, and the ANNS algorithm can be based on different retrieval strategies: hash coding, tree indexing, graph indexing, dimensionality reduction quantization, etc., thereby being subdivided into different types.

[0091] For the convenience of description, some technical terms in the embodiments of the present application are introduced first. In the embodiments of the present application, a node can be substantially regarded as a vector, and the description of the node and the vector is not specifically distinguished.

[0092] K-neighbor graph: A K-neighbor graph is a directed graph that connects a node vi with its K-nearest neighbor nodes. For example, referring to FIG. 3A, the node vi points to four neighbor nodes L1, L2, L3, and L4. Each of the neighbor nodes L1, L2, L3, and L4 has its corresponding neighbor. For example, the node L3 also points to the neighbor node L4, etc. For a node, the “arrow” in the graph is from one node to another neighbor node, the in-degree is the number of edges or arrows pointing to the node, and the out-degree is the number of edges from the node pointing to other nodes. As shown in FIG. 3A, the out-degree of the node vi is 4, and the in-degree is 0.

[0093] Approximate K-neighbor graph: A graph indexing structure for vector retrieval, which is constructed based on the K-neighbor graph, simplifies the traditional K-neighbor graph, improves the construction speed of the graph index, but does not strictly guarantee the K-neighbor property, i.e., does not strictly guarantee that each node has a neighbor relationship with the K nodes closest to itself in the global.

[0094] Satellite graph: A graph indexing structure for vector retrieval, which is constructed based on the approximate K-neighbor graph, limits the out-degree and in-degree of the nodes of the approximate K-neighbor graph, and the number of neighbors of the nodes and the path length between the nodes and the neighbors are moderate compared with the approximate K-neighbor graph.

[0095] Quantized satellite graph: A graph indexing structure for vector retrieval, which is constructed based on the satellite graph, quantizes the nodes in the satellite graph, such as product quantization (PQ) or optimizing product quantization (OPQ), to obtain the encoded representation of each node after quantization. Compared with the satellite graph, the speed of node distance calculation is greatly improved.

[0096] Product quantization (PQ) is a kind of vector quantization algorithm. The original vector space can be decomposed into a plurality of low-dimensional subspaces, and the original vector is represented by a short code composed of the quantization indicators of the subspaces of the subspaces. Then, the quantization distance between the query vector and the cluster center is used to approximate the real distance between the query vector and the target vector, so as to realize the effective retrieval of the target vector.

[0097] The specific process of PQ quantization is introduced as follows: referring to FIG. 3B, N M-dimensional vectors are divided into T equal-length subsegments, and the subsegments at the same position correspond to the same subspace, that is, subspace 0,..., subspace (T-1) are obtained, each of which is N m-dimensional vectors, that is, N*m in the figure. Each subspace is clustered, and for example, 16 clusters are clustered in the figure, so that T*16 cluster centers are obtained. The distance of each subsegment to all cluster centers in the subspace is calculated, and the cluster center number closest to the distance is taken as the quantization code of the subsegment. The quantization codes of the subsegments are concatenated, that is, the node quantization code of the entire vector is obtained. For example, referring to the node quantization code shown in block 003 of FIG. 3B, it is N*T-dimensional data, and for each cluster center in each subspace, 16 cluster centers are represented by numbers 0-15.

[0098] For convenience of description, hereinafter, the cluster center numbered i (i is an integer from 0 to 15) is represented as cluster center i, for example, the first number 15 in the node quantization code shown in block 003 of FIG. 3B corresponds to the cluster center 15, which is the quantization code of an m-dimensional subsegment in subspace 0.

[0099] The node quantization codes of the neighbor nodes corresponding to each node are stored in the memory according to a preset arrangement method corresponding to the node neighbor quantization code table. Specifically, the quantization codes of all neighbor nodes of a node can be arranged compactly, so as to be loaded from the memory by using the SIMD register for operation, thereby realizing high-speed quantization distance calculation.

[0100] The arrangement method is specifically described below in combination with the node neighbor quantization code table shown in FIG. 3C. It is assumed that each node has at most 128 neighbor nodes, and the number of divided subspaces is 64, that is, N is 128 and T is 64 in FIG. 3B. The quantization code set of subspace j is represented by quantizer_j, that is, according to T=64, the value range of j is 0-63. And 16 neighbors are stored as a group. The use of each table and quantizer shown in FIG. 3C is only for the convenience of describing the principle. According to the fact that each node has at most 128 neighbors, the quantization codes of all neighbors of each node can be represented by tables 1-8 at most.

[0101] In FIG. 3C, each quantizer_j stores the quantized codes of the 16 neighbors of the current node. In the actual storage space, the cluster center number of each stored neighbor node subsegment is represented by 4 bits, i.e., the range of the quantized code of the neighbor node is from 0000 to 1111. It needs to be explained that in FIG. 3C, the 0, 1, …, k, …, 127 corresponding to the bit positions 0-3 and the bit positions 4-7 in the table are used to represent 128 neighbor nodes, i.e., the 128 neighbor nodes are recorded as the 0th-127th neighbor nodes. That is, the storage order of the quantized codes of the neighbor node subsegments. With reference to FIG. 3C, the two consecutive rows vertically aligned in each quantizer_j are stored continuously in the memory, and each byte occupies 8 bits. The specific storage order is shown by the arrows in FIG. 3C (only the storage order of the cluster center numbers corresponding to the subsegments of 2 groups of 16 neighbors is shown in the figure). It can be understood that the actual data stored in the bit positions 0-3 and the bit positions 4-7 in each byte is the quantized code (i.e., the cluster center number) of the neighbor node subsegment. For example, assuming that the quantized code of the neighbor 0 subsegment in the quantizer_0 is 8, the stored data is represented by 4 bits as 0111.

[0102] For convenience of description, the following will refer to the u-th neighbor of the node as neighbor_u (u starts from 0). For example, the bit positions 0-3 in the quantizer_0 in FIG. 3C respectively store the cluster center numbers corresponding to the subsegments of the neighbor 0, the neighbor 2, the neighbor 4, …, and the neighbor 14.

[0103] It can be understood that in the vector retrieval process, the distance between the query vector and the cluster center can be calculated in advance to obtain a distance matrix look up table (LUT), and the distance stored in the LUT can be used to approximate the real distance between the query vector and the target vector, thereby achieving effective retrieval of the target vector. Therefore, in the vector retrieval process, the cluster center number can be determined based on the quantized code set, and then the cluster center number is looked up in the LUT.

[0104] Distance matrix look up table (LUT): a LUT storing the distances from all sub-vectors of a query vector to all cluster centers of each subspace. Specifically, first, the query vector is divided into equal-length subsegments to obtain query sub-vectors, and the distances from the query sub-vectors to all cluster centers of the corresponding subspace are calculated in each subspace to obtain the LUT corresponding to each subspace.

[0105] For example, referring to FIG. 3B, assuming that the LUTs of the distances from a query vector q to all 16 cluster centers of each of T subspaces are D0, D1, …, D(T-2), D(T-1).

[0106] Assuming the quantization encoding of neighbor 0 is "15, 1, …, 6, 7" as shown in the first row of box 003 in FIG. 3B, at this time, the following formula (I) shows the distance between the query vector q and neighbor 0:

[0107] D(q, V0) = D0

[0015] + D1

[0001] + … + D(T-1)

[0007] Formula (I)

[0108] Wherein, V0 represents neighbor 0, D0

[0015] represents the distance between the query vector q and the cluster center numbered 15 in subspace 0, "15" in "D0

[0015] " is the cluster center number corresponding to the subsegment belonging to subspace 0 in neighbor 0, which can be specifically referred to the first number "15" in the first row of box 003 in FIG. 3B; D1

[0001] represents the distance between the query vector q and the cluster center numbered 1 in subspace 1, "01" in "D1

[0001] " is the cluster center number corresponding to the subsegment belonging to subspace 1 in neighbor 0, which can be specifically referred to the second number "1" in the first row of box 003 in FIG. 3B, and other details are not described here.

[0109] It can be understood that when performing quantization search on the constructed quantization graph, the distance matrix lookup table can be combined with the above-mentioned node neighbor quantization encoding table to calculate the quantization distance between the query vector and all neighbors of each node in the routing process.

[0110] Optimizing product quantization (OPQ) is an improvement based on PQ quantization. Specifically, referring to FIG. 3D, OPQ quantization first uses an orthogonal matrix R to multiply the original vector (i.e., the node to be quantized), thereby rotating the original vector to obtain a rotated vector, and then divides each M-dimensional vector after rotation into T m-dimensional sub-vectors, that is, subsequent operations are performed according to the manner of PQ quantization, and the quantization encoding of all nodes is obtained, thereby obtaining a node quantization encoding table. Box 004 in FIG. 3D is shown as a node quantization encoding table.

[0111] In some embodiments, an efficient ANNS algorithm can be constructed based on graph indexing, combined with the contents of vantage point tree (VP-Tree) and product quantization (PQ).

[0112] FIG. 4 shows a process diagram for constructing a quantized graph index and searching based on the constructed graph index according to some embodiments of the present application. The execution subject of the process can be a database system, which can be executed by an electronic device or multiple electronic devices in cooperation. The specific construction process is as follows:

[0113] S101: Incrementally initialize the graph tree hybrid index.

[0114] In some implementations, a dataset for constructing a graph index is obtained, which results in a large amount of high-dimensional vector data. The high-dimensional vector data is regarded as nodes, and the nodes are inserted into an initialized graph tree hybrid index one by one to implement incremental construction of the graph tree hybrid index. The tree index can be a VP-Tree, and the graph index can be an initial approximate K-Nearest Neighbor graph.

[0115] S102: Obtain first candidate neighbor nodes of each node.

[0116] In some implementations, the first candidate neighbor node set is obtained according to an existing ANNS on the initial approximate K-Nearest Neighbor graph. For example, the first candidate neighbor node set can be obtained by using the NN-expansion method.

[0117] S103: Determine second candidate neighbor nodes from the first candidate neighbor nodes of each node according to distances.

[0118] In some implementations, neighbors can be further determined from the first candidate neighbor nodes according to distances, and directed edges between nodes are constructed to generate an approximate K-Nearest Neighbor graph.

[0119] For example, the first candidate neighbor nodes are sorted in ascending order of vector distances from the node, and the first K1 neighbors are taken as the second candidate neighbor nodes.

[0120] S104: Perform degree adjustment and path adjustment to obtain neighbor nodes of each node.

[0121] In some implementations, after the generated approximate K-Nearest Neighbor graph is constructed, degree adjustment and path adjustment are performed on the constructed approximate K-Nearest Neighbor graph to obtain an adjusted approximate K-Nearest Neighbor graph. Specifically, degree adjustment and path adjustment can be performed based on the relationship between each node and the corresponding second candidate neighbor node to obtain neighbor nodes of each node. For example, the out-degree and in-degree of a node can be adjusted by adjusting the direction of the directed edge between the nodes, and path adjustment can be implemented based on the connection relationship between the second candidate neighbor nodes of the node.

[0122] S105: Node quantization and construction of a quantized graph.

[0123] In some implementations, the PQ quantization is performed based on the node neighbor relationship in the adjusted approximate K-Nearest Neighbor graph to obtain node quantization codes, and a quantized node data structure is constructed according to the neighbor relationship between nodes and the arrangement mode corresponding to the node neighbor quantization code table to generate a quantized approximate K-Nearest Neighbor graph, hereinafter referred to as a "quantized graph". For the node quantization, reference can be made to the description of FIG. 3B above, and for the neighbor arrangement mode corresponding to the node neighbor quantization code table, reference can be made to the description of FIG. 3C above.

[0124] It can be understood that the above steps S101-S105 are a simple description of constructing a graph index. The following steps S106 and S107 describe the process of searching based on the constructed graph index:

[0125] S106: Obtain a seed node using the tree index.

[0126] It can be understood that the tree index can be used to obtain a rough search result, and then a fine search is performed in the graph index according to the rough search result, thereby reducing the search time.

[0127] In some implementations, the number K' of neighbors to be searched and the query vector q are obtained, and one or more nodes with a smaller distance from the query vector q are roughly searched in the tree index, such as a VP-Tree, as seed nodes for searching in the graph index.

[0128] S107: Search in the quantized graph from the seed node as a starting node.

[0129] In some implementations, the obtained seed node is used as an entry node of the graph index, and a search algorithm is performed in the quantized graph to obtain K' nearest neighbor query results corresponding to the query vector q. Specifically, for a query vector, the same as the node quantization process described above, the query vector is first divided into equal-length sub-segments, and the distance of each sub-segment to all cluster centers in each subspace is calculated to obtain the LUT described above. The LUT stores the distance of all sub-vectors of the query vector to all cluster centers in each subspace. When performing quantized search on the constructed quantized graph, the quantized distance between the query vector and all neighbors of each node in the routing process is calculated according to the LUT, K' candidate results are obtained based on the quantized distance according to the routing rule, and then the first K' nearest nodes are selected as the query results according to the actual distance between vectors in the K' nodes, thereby accelerating the search speed.

[0130] In some implementations, the candidate result set can be initialized according to the entry nodes, the number of the storable nodes in the candidate result set is limited to KM, and then the distances between the neighbor nodes of the nodes in the candidate result set and the query vector q are calculated. The neighbor nodes satisfying the distance condition are inserted into the candidate result set according to the quantized distance size, that is, the nodes in the candidate result set are updated, wherein the distance condition can be that the quantized distance between the neighbor node and the query vector q is less than (1+ε) times the distance of the K'th node in the current candidate result set, and ε is a quantization expansion coefficient, which is a non-negative number. When the number of the storable nodes KM is exceeded, the nodes with a far distance in the candidate result set are deleted. The nodes in the candidate result set whose neighbor nodes have been calculated are marked, and the nodes are not operated subsequently. Then, the neighbor nodes of the other nodes in the candidate result set are calculated in turn according to the distance from small to large, the candidate result set is dynamically updated, until all the nodes in the candidate result set are accessed and the candidate result set does not need to be updated, and the process stops. It can be understood that after the KM nodes are obtained, K' final query results can be obtained from the KM nodes. It can be understood that other ways can also be used to find the K' final query results, which are not required here.

[0131] For example, taking K' as 10 and ε as 1 as an example, the initial to-be-accessed set includes multiple entry nodes, and the nodes are sequentially sorted from near to far as node W1, node W2, node W3,..., node Wn. The storage number KM is limited to 100. The neighbor nodes of each node are calculated in turn according to the order, and it is assumed that the first 80 neighbor nodes W1, W2,..., W80 of the 100 neighbor nodes of node W1 satisfy the distance condition, that is, the quantized distance between the neighbor node and the query vector q is less than 2 times the distance of the 10th node in the current candidate result set, and then the neighbor nodes W1, W2,..., W80 are inserted into the candidate result set, and the nodes in the candidate result set are still sorted according to the quantized distance from small to large. It is assumed that the nodes in the candidate result set are node W1, node W2, W3,..., W80, node W81,..., W100, and the node W1 whose neighbor nodes have been calculated is marked. The neighbor nodes of node W2 are continuously calculated, and the previous operation is repeated. Finally, 100 nodes are obtained. Then, the 10 nodes closest to the query vector q are selected based on the actual distance. 18 1_1 1_80 1_1 1_80 1_1 1_80 18

[0132] ​​​​​​​​In the retrieval process, the method for calculating the quantized distance between the query vector and each neighbor of the node in the routing process according to the LUT is as follows: the cluster head number to which each sub-vector of the node neighbor belongs can be obtained by using the node neighbor quantization code table. When calculating the distance between a certain vector and the query vector, the cluster head to which each sub-section belongs in the node neighbor quantization code table and the distance corresponding to the query vector are directly taken from the LUT. The sum of the distances of these sub-sections is the distance between the query vector and the vector, which is specifically described in the above description of the distance between the query vector and the neighbor 0 of the node in FIG. 3B, and will not be repeated here.

[0133] However, in determining the neighbors of the node, the graph index is mainly constructed according to the distance between the nodes. If some nodes are densely distributed in a certain region in space, since the number of neighbor nodes of each node is limited, the neighbor nodes of the node may all be distributed in a certain or some dense space region in the process of generating the neighbor nodes of the node. At this time, the determined neighbor nodes are likely to not include the node to be queried. When searching from the entry node, the search may be performed only in some space regions at this time, thereby easily leading to local optimization of the search, so that the query result is not accurate enough.

[0134] For example, the neighbor nodes of the node L0 are determined, and the number of neighbor nodes of each node is limited to no more than 50. The 50 nodes with the shortest distance to the node L0 among other nodes are taken as the neighbor nodes. If the 50 neighbor nodes are densely distributed in a certain space region. For example, referring to the distribution of the neighbor nodes of the node L0 in space shown in FIG. 5A, since the number of neighbor nodes of each node is limited in the process of determining the neighbor nodes of each node, the determined neighbor nodes may not include the node to be queried, so that the subsequently accessed nodes may not include the node to be queried. For example, referring to the neighbor relationship between a plurality of nodes shown in FIG. 5B. It is assumed that the node D1 is the node most similar to the query vector q. Taking the determination of the neighbor nodes of the node L0 as an example, since the number of neighbor nodes of the node L0 is limited, and the node L03 is far away from the node L0, the node L03 is not taken as the neighbor node of the node L0. As can be seen from FIG. 5B, the node D1 can be accessed through the node L03. At this time, when the neighbor nodes of the node L0 need to be accessed, since the node L03 is not taken as the neighbor node of the node L0, the subsequently accessed nodes may not include the node D1 to be queried. Since the nodes close to the node L0, such as the node L01 and the node L02, are taken as the neighbor nodes, the subsequent node access may be performed within the range of the circle 005 at this time, thereby leading to the query result not being accurate enough.

[0135] Therefore, in order to solve the above problems, the present application provides a data processing method, in the process of constructing a graph index, when determining the second candidate neighbor node of a node X, not only the distance between each node and the node X is considered, but also the spatial distribution of the determined second candidate neighbor nodes is considered, so as to avoid the second candidate neighbor nodes being densely distributed in a subspace within a preset range. Specifically, the second candidate neighbor node of the node X is determined to be a node whose distance from the node X is less than a preset distance threshold Y0, and the second candidate neighbor node of the node X also satisfies at least one of the following distribution conditions:

[0136] The included angle between two vectors obtained by subtracting the node X from any two second candidate neighbor nodes (hereinafter referred to as "neighbor node included angle") is greater than or equal to a preset angle threshold Y1;

[0137] The distance between any two second candidate neighbor nodes is greater than or equal to a preset distance threshold Y2;

[0138] The number of second candidate neighbor nodes within a preset spatial range is less than a preset number Y3.

[0139] After obtaining the second candidate neighbor nodes of each node, the neighbor nodes of each node can be obtained based on the second candidate neighbor nodes of each node.

[0140] In some embodiments, the second candidate neighbor nodes of each node can be directly used as the neighbor nodes of each node.

[0141] In other embodiments, the number of second candidate neighbor nodes can be increased or decreased according to the out-degree and in-degree of the current node and the relationship between the second candidate neighbor nodes. For details, reference can be made to the description in step S204 in FIG. 9B, which will not be repeated here.

[0142] It can be understood that, since the number of second candidate neighbor nodes of each node is limited, the second candidate neighbor nodes of the node X determined in the approximate K-neighbor graph based on the above method will not be too close to each other, so that the neighbor nodes of the node are dispersed in space, i.e., there will be more possibilities to route to the nodes at different spatial positions, thereby avoiding the problem that the nodes are densely distributed at a certain position, so that in the process of node searching, the nodes at a certain part of the space cannot be found, and the query result is trapped in a local optimum. For example, as shown in FIG. 6A, the neighbor nodes of the node L0 are relatively dispersed in space, such as the nodes L01', L02', and L03' are relatively dispersed, and the node L03' in the neighbor nodes points to the optimal node D1, so that the node D1 can be found through the node L03'. Since the neighbor nodes of each node are dispersed in space, the probability of finding the nodes distributed at various positions in space is improved, thereby improving the accuracy of the query result.

[0143] In some embodiments, the first candidate neighbor node can be determined to be the second candidate neighbor node in turn according to the distance between the first candidate neighbor node and the node X. And the first candidate neighbor node can be determined to be the second candidate neighbor node based on whether the angle between the first candidate neighbor node and the node determined to be the second candidate neighbor node is greater than or equal to a preset angle threshold Y1. If the angle between the first candidate neighbor node and the node determined to be the second candidate neighbor node does not satisfy the preset angle threshold Y1, the first candidate neighbor node is not the second candidate neighbor node; otherwise, the first candidate neighbor node is the second candidate neighbor node.

[0144] For example, when considering the angle of the neighbor node in the graph index construction, referring to FIG. 6B, for node V1, it is assumed that there are currently four first candidate neighbor nodes, and the vector distance from node V1 in turn from small to large is: node C11, node C12, node C13 and node C14. And the threshold of the angle of the neighbor node is α. The first candidate neighbor node can be determined to be the second candidate neighbor node in turn according to the vector distance from node V1. Since the vector distance between node C11 and node V1 is the smallest, node C11 is determined to be the second candidate neighbor node. The angle between node C12 and node C11 and node V1 is greater than α, so node C12 is the second candidate neighbor node. For node C13, the angles between node C13 and node C11 and node C12 are calculated respectively. Since the angle between node C13 and node C11 is smaller, node C13 is discarded. For node C14, the angles between node C14 and node C11 and node C12 are both greater than α, so node C14 is the second candidate neighbor node.

[0145] It can be understood that since some part of the nodes with dense distribution are discarded, more vacancies of the second candidate neighbor nodes can be left for other nodes at this time, so that the obtained neighbor nodes of node V1 will not be too close to each other, and the neighbor nodes are uniformly distributed in space. Therefore, by taking the size of the angle of the neighbor node as a condition for selecting the second candidate neighbor node, the second candidate neighbor nodes can be dispersed in space, avoiding the problem that the query result falls into local optimization. In addition, when querying based on the second candidate neighbor node, the second candidate neighbor nodes in different directions can be queried, which can also avoid the problem that incorrect query results are obtained due to the direction of the node queried in the query process, and improve the query efficiency.

[0146] In some embodiments, when judging whether the current first candidate neighbor node is the second candidate neighbor node in order according to the distance between the current first candidate neighbor node and node X, the distance between the current first candidate neighbor node and the node determined as the second candidate neighbor node can be used to judge whether the current first candidate neighbor node is the second candidate neighbor node. If the distance between the current first candidate neighbor node and the node determined as the second candidate neighbor node is less than the preset distance P2, the current first candidate neighbor node is not the second candidate neighbor node; otherwise, the current first candidate neighbor node is the second candidate neighbor node. Thus, the distance between any two second candidate neighbor nodes exceeds a certain distance.

[0147] For example, when considering the distance between neighbor nodes in the construction of the graph index, referring to FIG. 6C, for node V2, it is assumed that there are currently four first candidate neighbor nodes, and the vector distance from node V2 in ascending order is node C21, node C22, node C23 and node C24. The preset distance threshold Y2 between neighbor nodes is θ. The vector distance from node V2 can be used to judge whether each first candidate neighbor node is the second candidate neighbor node in order. Since the vector distance from node C21 to node V2 is the smallest, node C21 is first determined as the second candidate neighbor node. The distance between node C22 and node C21 is greater than θ, so node C22 is the second candidate neighbor node. The distance between node C23 and node C21 is less than θ, but since the vector distance from node C21 to node V2 is smaller than the vector distance from node C23 to node V2, node C23 is discarded. For node C24, the distance between node C24 and node C21, and the distance between node C24 and node C22 are both greater than θ, so node C24 is the second candidate neighbor node. Thus, the neighbor nodes of node V2 obtained will not be too close to each other, so that the neighbor nodes are distributed more dispersedly in space.

[0148] In addition, in some embodiments, when the distance matrix lookup table is used for distance calculation based on the node quantization coding table, the distance between the query vector and multiple neighbor nodes can be calculated simultaneously to realize parallel calculation. Currently, in the case of using the AVX-512 instruction set, the memory is addressed by byte.

[0149] The above takes the specific arrangement of the node neighbor quantization coding table shown in FIG. 3C as an example. Next, in the AVX-512 instruction set, the process of obtaining the quantization distance from the LUT table based on the coding arrangement shown in FIG. 3C to realize parallel calculation is simply described in combination with FIG. 7A. It can be understood that in other examples, the node quantization can also be divided into more subspaces, and more neighbor nodes are involved, which will not be described here.

[0150] As the previous elaboration of the node neighbor quantization coding table shown in FIG. 3C. Limiting each node to have at most 128 neighbor nodes, the number of subspaces to be split is 64, i.e. N is 128 and T is 64 in FIG. 3B. In actual storage space, the cluster center numbers corresponding to each neighbor node subsegment are stored in memory, and are stored continuously in memory.

[0151] (1) In combination with the previous rules using AVX-256 instruction set, the register loads the quantization coding of 4 subsegments of 16 node neighbors at a time, a total of 256 bits, i.e. taking out the data of 4 quantizers (i.e. the cluster center numbers corresponding to the first 4 subspaces of the neighbors) at a time. Since the current AVX-512 instruction set is used, the register can load 512 bits of data at a time. At this time, the extension instruction _mm512_cvtepu8_epi16 is used to expand 8 bits to 16 bits to meet the requirement that the data of 4 quantizers taken out can occupy 512 bits. Specifically, the register loads the quantization coding of 4 subsegments of 16 node neighbors at a time, a total of 256 bits, and stores it as 512 bits in the bit expansion mode, thereby obtaining the intermediate data W0, wherein the intermediate data W0 corresponds to a register.

[0152] For example, FIG. 7A shows a schematic diagram of loading data corresponding to the first 4 subspaces of 16 neighbors at a time and performing bit expansion, represented by Table ① to Table ②. Among them, the intermediate data W0_1, the intermediate data W0_2, the intermediate data W0_3, and the intermediate data W0_4 in Table ② correspond to different subsegments of the node, and are only for easy understanding. At this time, the order of storage in memory according to byte is that byte 0: the subsegment of neighbor 0 corresponding to space 0, the subsegment of neighbor 1 corresponding to space 0; byte 1: empty byte; byte 2: the subsegment of neighbor 2 corresponding to space 0, the subsegment of neighbor 3 corresponding to space 0......, i.e. sequentially stored according to the order of the arrows in the table (only the order of 2 subspaces is shown in the figure).

[0153] (2) Taking out the low 4 bits in the non-empty byte and expanding it to 16 bits to obtain the intermediate data W1, and taking out the high 4 bits in the non-empty byte and expanding it to 16 bits to obtain the intermediate data W2. Perform or operation on the expanded intermediate data W1 and the intermediate data W2 to obtain the intermediate data W3. It can be understood that since the addressing is according to byte addressing, and the cluster center number is stored according to 4 bits, when the data loaded from the memory into the register is operated, the data loaded from the memory into the register needs to be reorganized to facilitate distance lookup in the LUT.

[0154] For example, as shown in FIG. 7A, the change from Table ② to Table ③ represents that the low 4-bit data is expanded to 16 bits, and the change from Table ② to Table ④ represents that the high 4-bit data is expanded to 16 bits. The intermediate data W3 shown in Table ⑤ is obtained by performing an OR operation on the data in Table ③ and Table ④. At this time, the cluster center number corresponding to each neighbor subsegment occupies one byte, i.e., 8 bits.

[0155] (3) Then, according to the intermediate data W3, the quantization distance corresponding to the quantization code (i.e., the cluster center number) of each node is found from the LUT and stored to obtain distance data. For example, as shown in Table ① in FIG. 7B, the quantization distance corresponding to each neighbor node subsegment is obtained, and the value of each quantization distance occupies 8 bits. The numbers "0, 1,..., 15" in Table ① represent the quantization distance corresponding to the subsegment of the neighbor node.

[0156] (4) The quantization distances of the subsegments belonging to the same neighbor node are added to obtain the quantization distance of the 4 subsegments of the query vector and the corresponding neighbor node.

[0157] For example, referring to Table ② and Table ③ shown in FIG. 7B, in the addition process, the quantization distances of each 2 subsegments are first added to obtain accumulated data M1, and then the parts in the accumulated data M1 are added. For example, the same neighbor nodes in distance data_1 and distance data_2 are added, and the same neighbor nodes in distance data_3 and distance data_4 are added to obtain accumulated data M1_1 and accumulated data M1_2, respectively. Then, the accumulated data M1_1 and the accumulated data M1_2 are added to obtain accumulated data M2, which can be used for subsequent continuous addition.

[0158] In order to avoid overflow in addition, for example, the addition of 2 8-bit data will overflow, so it is necessary to use the time-consuming _mm512_cvtepu8_epi16 instruction to expand each quantization distance in the accumulated data M1 from 8-bit storage to 16-bit storage, and a relatively complex bit expansion instruction is required, and each quantization distance in the accumulated data M2 is configured as 32 bits.

[0159] It can be understood that the above shows the quantization distance corresponding to the first 4 subsegments of neighbors 0-15, and the subsequent registers can be operated in a loop in this way to obtain the quantization distance of the query vector and neighbors 0-128 in sequence.

[0160] However, in the case of using the AVX-512 instruction set, a larger data width can be supported, and since the above method only extracts 256 bits of quantized encoding of node neighbors at a time, i.e., 16 neighbors in 4 subspaces, the cluster center number is not full of the existing 512-bit register, for example, in the 3rd and 4th rows of the table "②" in FIG. 7A, both are empty, so 50% of the register will be wasted in the environment using the AVX-512 instruction set. And in the process of distance calculation, more time-consuming instructions with longer clock cycle numbers are needed, such as the extension instruction _mm512_cvtepu8_epi16 that expands 8 bits to 16 bits, which increases the time cost of calculation.

[0161] Therefore, in order to improve the utilization rate of the register during quantized distance calculation and reduce the use of time-consuming extension instructions, the present application further provides a data processing method, in which: in the quantization process, the node is divided into T (T is less than or equal to the vector dimension corresponding to the node) subspaces, each subspace includes n (1 < n ≤ 16) clusters, and the cluster center of each cluster is represented by 4-bit data. In the environment using the AVX-512 instruction set, the quantized encoding of the neighbor nodes of any node is stored in the following manner: the quantized encoding of every 32 neighbors (denoted as the 0th-31st neighbors) in a subspace is stored by 16 consecutive bytes (denoted as the 0th-15th bytes), and the quantized encoding of the 32 neighbor nodes in T subspaces is stored by 16xT consecutive bytes, wherein:

[0162] the 2Lth (L = 0, 1, 2, …, 7) byte (hereinafter referred to as "byte 2L") of the 16 bytes stores the quantized encoding of the Lth neighbor of the 32 neighbors in the lower four bits and the quantized encoding of the L+16th neighbor in the upper four bits;

[0163] the 2L+1th (L = 0, 1, 2, …, 7) byte (hereinafter referred to as "byte 2L+1") of the 16 bytes stores the quantized encoding of the L+8th neighbor of the 32 neighbors in the lower four bits and the quantized encoding of the L+24th neighbor in the upper four bits.

[0164] For example, as shown in FIG. 8A, the sub-section of every 32 nodes is a large group, for each quantizer, the lower 4 bits of byte 0 store the quantized encoding (i.e., the cluster center number) of the sub-section of neighbor 0, and the upper 4 bits of byte 0 store the quantized encoding of the sub-section of neighbor 16; the lower 4 bits of byte 1 store the quantized encoding of the sub-section of neighbor 8, and the upper 4 bits of byte 1 store the quantized encoding of the sub-section of neighbor 24; …; the upper 4 bits of byte 15 store the quantized encoding of the sub-section of neighbor 31, which can be referred to the arrow shown in FIG. 8A.

[0165] It can be understood that, since storage is in groups of 32 nodes, the quantization code of 4 sub-segments of 32 nodes can be directly loaded into the register in the context of the AVX-512 instruction set, which is a total of 512 bits, avoiding 50% of the available register space. And since each byte stores the number of 2 neighbors with a difference of 16 when stored, i.e. neighbors 0-15 in 32 neighbors are stored in the low 4 bits, and neighbors 16-31 in 32 neighbors are stored in the high 4 bits, it is convenient to store the quantization code (i.e. cluster center number) corresponding to the sub-segment of neighbors 0-15 as a byte in a register, and the quantization code corresponding to the sub-segment of neighbors 16-31 as a byte in another register, for lookup in the LUT, and each register occupies 512 bits in the register unit, making full use of the register space. And since from byte 0, every 2 bytes in a large group is a sub-group, for each sub-group, the neighbor number of every 4 bits of data in the next byte is 8 greater than the neighbor number of every 4 bits of data in the previous byte. The neighbor number corresponding to every 4 bits of data in the next sub-group is 1 greater than the neighbor number corresponding to every 4 bits of data in the corresponding position in the previous sub-group. Therefore, after storing the cluster center number stored by byte in the register, it is convenient to obtain the 16-bit quantization distance by simply shifting and adding, for calculating the result, and restoring to the normal order of 0-31. Thus, the use of extension instructions is reduced, and the calculation speed is improved.

[0166] The process of restoring the distance calculation result to the normal order of 0-31 by simple shifting and adding based on the above storage method is introduced below.

[0167] (1) The register loads the quantization code of 4 sub-segments of 32 node neighbors from the memory at a time, a total of 512 bits, i.e. 4 quantizers are taken out from the memory at a time, i.e. the quantization code of the neighbor node corresponding to the first 4 sub-spaces, to obtain the encoding data E0. Since the AVX-512 instruction set is currently used, the register can load 512 bits of data at a time. At this time, the 512 bits in the register will be completely used, avoiding 50% of the available register space. For example, referring to Table ① shown in FIG. 8B, the storage order of the encoding data E0 in the register relative to the original storage order in the memory has not changed.

[0168] (2) Then, from the loaded 512-bit data, the low 4 bits of each byte are stored in a register as a byte (8 bits) respectively, to obtain the first encoded data El, in which, for every 16 bytes, the 2Lth byte stores the quantized code of the Lth neighbor (i.e. neighbor L), and the 2L+1th byte stores the quantized code of the L+8th neighbor (i.e. neighbor L+8); the high 4 bits of each byte of the loaded 512-bit data are stored in another register as a byte (8 bits) respectively, to obtain the second encoded data E2, in which, for every 16 bytes, the 2Lth byte stores the quantized code of the L+16th neighbor (i.e. neighbor L+16), and the 2L+1th byte stores the quantized code of the L+24th neighbor (i.e. neighbor L+24). At this time, each register occupies 512 bits. And, since byte addressing is required, and each cluster center number occupies a byte, it is convenient to look up in the LUT. It can be understood that, since, when stored in advance, in every 16 bytes, the neighbors 0-15 of the 32 neighbors are stored in the low 4 bits, and the neighbors 16-31 of the 32 neighbors are stored in the high 4 bits, it is convenient to store the quantized codes corresponding to the sub-segments of neighbors 0-15 in one register, and to store the quantized codes corresponding to the sub-segments of neighbors 16-31 in another register, and each register occupies 512 bits, fully utilizing the register space.

[0169] For example, referring to Table 2 shown in FIG. 8B, the quantized codes of the 4 sub-segments of neighbors 0-15 are stored in one register. Referring to Table 3 shown in FIG. 8B, the quantized codes of the 4 sub-segments of neighbors 16-31 are stored in one register. And in Table 2 shown in FIG. 8B, at this time, the quantized codes of the sub-segments of each neighbor are stored in the order as in the table. The order of "0, 8, 1, 9...7, 15" in each sub-table in Table 2 respectively represents the arrangement order of the quantized codes of the sub-segments of neighbor 0, the quantized codes of the sub-segments of neighbor 8,..., the quantized codes of the sub-segments of neighbor 15. In Table 3 shown in FIG. 8B, at this time, the quantized codes of the sub-segments of each neighbor are stored in the order as in the table. The order of "16, 24, 17, 25...23, 31" in each sub-table in Table 3 respectively represents the arrangement order of the quantized codes of the sub-segments of neighbor 16, the quantized codes of the sub-segments of neighbor 24,..., the quantized codes of the sub-segments of neighbor 31.

[0170] (3) According to the first encoding data El and the second encoding data E2 respectively, the first distance data U0 and the second distance data U1 are obtained by searching in the LUT. In each 16 bytes of the first distance data U0, the 2Lth byte stores the quantized distance of the Lth neighbor (i.e. neighbor L), and the 2L+1th byte stores the quantized distance of the L+8th neighbor (i.e. neighbor L+8). In the second distance data U1, the 2Lth byte stores the quantized distance of the L+16th neighbor (i.e. neighbor L+16), and the 2L+1th byte stores the quantized distance of the L+24th neighbor (i.e. neighbor L+24). For example, Table 1 in FIG. 8C shows the first distance data U0, which obtains the quantized distance corresponding to the sub-segment of each neighbor node. Each quantized distance has a value of 8 bits. It can be understood that the obtained quantized distance in the first distance data U0 corresponds to the number of each neighbor. The numbers "0, 16, 8,..., 31" in Table 1 represent the quantized distance of the neighbor sub-segment corresponding to the number. The storage order is the same as the order of the neighbor number in the first encoding data El, which will not be described here.

[0171] (4) The data in each 16 bits of the first distance data U0 is right shifted (i.e. moved to the low bit direction) by 8 bits, i.e. the data in the high 8 bits is stored to the low 8 bits, to obtain the third distance data P1. In each 16 bytes of the third distance data P1, the 2Lth byte stores the quantized distance of the L+8th neighbor (i.e. neighbor L+8), and the 2L+1th byte stores empty. The third distance data P1 stores the quantized distance of the sub-segment of the neighbor 8-15 in order, and each quantized distance is 16-bit data. The data in each 16 bits of the third distance data P1 is left shifted (i.e. moved to the high bit direction) by 8 bits to obtain the fourth distance data P2. Then, the first distance data U0 is subtracted from the data in each 16 bits of the fourth distance data P2 to obtain the fifth distance data P3. The fifth distance data P3 stores the quantized distance of the sub-segment of the neighbor 0-7 in order, and each quantized distance is 16-bit data. For example, referring to FIG. 8C, the first distance data U0 shown in Table 1 in FIG. 8C is right shifted by 8 bits per 16 bits to become the third distance data P1 shown in Table 2. For example, referring to FIG. 8D, the first distance data U0 shown in Table 1 in FIG. 8D is subtracted from the fourth distance data P2 shown in Table 2 to obtain the fifth distance data P3 shown in Table 3. It can be understood that the third distance data P1 and the fifth distance data P3 are essentially the 16-bit quantized distance corresponding to the sub-segment of the neighbor 0-15.

[0172] Similarly, the 16-bit quantized distances corresponding to the sub-segments of the 16th to 31st neighbor nodes can be obtained from the second distance data U1 in the same way, and are stored in another two registers. Specifically, the 8th bit of each 16-bit data of the second distance data U1 is moved to the low bit direction to obtain the 64-byte sixth distance data Q1, and in each 16-byte of the sixth distance data Q1, the 8th 2L byte is the quantized distance corresponding to a sub-segment of the 24th to 31st neighbor nodes, respectively. The second distance data U1 is subtracted by the seventh distance data Q2 according to each 16-bit data to obtain the eighth distance data Q3, and the seventh distance data Q2 is the data obtained by moving the 8th bit of each 16-bit data of the sixth distance data Q1 to the high bit direction, and the eighth distance data Q3 includes the quantized distances corresponding to the 16th to 23rd neighbor nodes.

[0173] It can be understood that in this process, the bit extension instruction is not used, and the 16-bit quantized distances of the nodes 0-31 in order can be obtained, thereby avoiding the problem of overflow.

[0174] (5) The quantized distances of the sub-segments belonging to the same neighbor node are added to obtain the quantized distances of the 4 sub-segments of the query vector and the corresponding neighbor node. Thus, according to the quantized codes of the 4 sub-segments of each neighbor node loaded into the register multiple times, the quantized distances of the query vector and the corresponding neighbor node are obtained.

[0175] In addition, corresponding to the environment using the AVX-1024 instruction set, the quantized codes of the neighbor nodes of any one node are stored in the following manner: the quantized codes of each 64 neighbor nodes (denoted as the 0th to 63rd neighbor nodes) in a subspace are stored by 32 consecutive bytes (denoted as the 0th to 31st bytes), and the quantized codes of the 64 neighbor nodes in the T subspace are stored by 32xT consecutive bytes, wherein:

[0176] The 2L (L=0, 1, 2, …, 15)th byte in the 32 bytes, the low four bits store the quantized code of the Lth neighbor node in the 64 neighbor nodes, and the high four bits store the quantized code of the L+32th neighbor node;

[0177] The 2L+1 (L=0, 1, 2, …, 15)th byte in the 32 bytes, the low four bits store the quantized code of the L+16th neighbor node in the 64 neighbor nodes, and the high four bits store the quantized code of the L+48th neighbor node.

[0178] For example, as shown in FIG. 8E, each 64-node sub-section is a large group, for each quantizer_j, the low 4 bits of byte 0 store the quantization code of the sub-section of neighbor 0 (i.e. cluster center number), the high 4 bits of byte 0 store the quantization code of the sub-section of neighbor 32; the low 4 bits of byte 1 store the quantization code of the sub-section of neighbor 16, the high 4 bits of byte 1 store the quantization code of the sub-section of neighbor 48;... the low 4 bits of byte 31 store the quantization code of the sub-section of neighbor 31, the high 4 bits of byte 31 store the quantization code of the sub-section of neighbor 63.

[0179] It can be understood that at this time, in the environment of AVX-1024 instruction set, since storage is in groups of 64 nodes, the register operation unit in the environment of AVX-1024 instruction set can directly read the quantization codes of 4 sub-sections of 64 nodes, at this time, a total of 1024 bits, avoiding 50% of the waste of register space. Similarly, in the same way as the reading process in the environment of AVX-512 instruction set described above, the utilization rate of registers during quantization distance calculation is improved, and the use of time-consuming extension instructions is reduced.

[0180] Specifically, (1) the register loads the quantization codes of 4 sub-sections of 64 neighbor nodes at a time, a total of 1024 bits, i.e. 4 quantizer data from the memory at a time, i.e. the quantization codes of the first 4 sub-spaces of the neighbor nodes, to obtain the first encoding data E0'.

[0181] (2) Then, from the loaded 1024-bit data, the low 4 bits of each byte are stored in a register as a byte (8 bits) respectively, to obtain the third encoding data E1', in every 32 bytes of the third encoding data E1', the 2Lth byte stores the quantization code of the Lth neighbor (i.e. neighbor L), and in every 32 bytes of the third encoding data E1', the 2L+1th byte stores the quantization code of the L+16th neighbor (i.e. neighbor L+16); from the loaded 1024-bit data, the high 4 bits of each byte are stored in another register as a byte (8 bits) respectively, to obtain the fourth encoding data E2', in every 32 bytes of the fourth encoding data E2', the 2Lth byte stores the quantization code of the L+32th neighbor (i.e. neighbor L+32), and in the fourth encoding data E2', the 2L+1th byte stores the quantization code of the L+48th neighbor (i.e. neighbor L+48).

[0182] (3) According to the third encoding data E1' and the fourth encoding data E2', respectively, look up in the LUT to obtain the ninth distance data U0' and the tenth distance data U1'. In every 32 bytes of the ninth distance data U0', the 2Lth byte stores the quantized distance corresponding to the sub-segment of the Lth neighbor (i.e. neighbor L), in every 32 bytes of the ninth distance data U0', the 2L+1th byte stores the quantized distance corresponding to the sub-segment of the L+16th neighbor (i.e. neighbor L+16), in every 32 bytes of the tenth distance data U1', the 2Lth byte stores the quantized distance corresponding to the sub-segment of the L+32th neighbor (i.e. neighbor L+32), in every 32 bytes of the tenth distance data U1', the 2L+1th byte stores the quantized distance corresponding to the sub-segment of the L+48th neighbor (i.e. neighbor L+48).

[0183] (4) Shift every 16 bits of data in the ninth distance data U0' to the right by 8 bits, i.e. store the data in the high 8 bits to the low 8 bits, to obtain the eleventh distance data P1', in every 32 bytes of the eleventh distance data P1', the 2Lth byte stores the quantized distance corresponding to the sub-segment of the L+16th neighbor (i.e. neighbor L+16), the 2L+1th byte in the eleventh distance data P1' is stored as empty. The eleventh distance data P1' stores the quantized distances corresponding to the sub-segments of the neighbors 16-31 in order, each quantized distance being 16 bits of data. Shift the eleventh distance data P1' to the left by 8 bits to obtain the twelfth distance data P2', then subtract every 16 bits of data in the ninth distance data U0' and the twelfth distance data P2' to obtain the thirteenth distance data P3'. The thirteenth distance data P3' stores the quantized distances of the sub-segments of the neighbors 0-15 in order, each quantized distance being 16 bits of data. Similarly, for the tenth distance data U1', the same method can be used to obtain the 16-bit quantized distances corresponding to the sub-segments of the neighbors 32-64, and store them in another two registers respectively. Shift every 16 bits of data in the tenth distance data U1' to the low bit direction by 8 bits to obtain the 128-byte fourteenth distance data Q1', in every 32 bytes of the fourteenth distance data Q1', 16 2Lth bytes are respectively the quantized distances corresponding to the sub-segments of the 48th neighbor node to the 63rd neighbor node; shift every 16 bits of data in the fourteenth distance data Q1' to the high bit direction by 8 bits to obtain the fifteenth distance data Q2', subtract the fifteenth distance data Q2' from the tenth distance data U1' according to every 16 bits of data to obtain the sixteenth distance data Q3', the sixteenth distance data Q3' includes the quantized distances of the 4 sub-segments of the 32nd neighbor node to the 47th neighbor node and the query vector. It can be understood that in this process, the carry instruction is not used, and the 16-bit quantized distance can be obtained, avoiding the problem of overflow.

[0184] (5) adding the quantized distances of each sub-segment belonging to the same neighbor node to obtain the quantized distance between the query vector and the four sub-segments of the corresponding neighbor node and the query vector.

[0185] It can be understood that the data processing method provided by the embodiments of the present application can be applied to any electronic device, which can include but is not limited to a mobile phone, a tablet computer, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a server, a server cluster, and the like, without limitation.

[0186] It can be understood that in some embodiments, the graph index constructed in the data processing method provided by the embodiments of the present application can be a direct approximate K-neighbor graph, that is, after obtaining the second candidate neighbor nodes of each node and the second candidate neighbor nodes of each node satisfy the distribution condition, the second candidate neighbor nodes of each node are no longer adjusted, and each node is no longer quantized, and a query is directly performed based on the constructed approximate K-neighbor graph. In other embodiments, the graph index constructed in the data processing method provided by the embodiments of the present application can be a satellite graph based on an approximate K-neighbor graph including degree adjustment or path adjustment, that is, after degree adjustment and path adjustment based on the second candidate neighbor nodes of each node, each node is no longer quantized, and a query operation is directly performed based on the constructed satellite graph. In addition, in some embodiments, when constructing the graph index in the data processing method provided by the embodiments of the present application, after obtaining the satellite graph based on the approximate K-neighbor graph including degree adjustment or path adjustment, the satellite graph is quantized to obtain a quantized satellite graph, that is, after adjusting the second candidate neighbor nodes of each node, each node is quantized, and a query operation is performed based on the constructed quantized satellite graph, so as to improve the query speed.

[0187] Hereinafter, a quantized satellite graph is constructed and a query is performed based on the quantized satellite graph as an example.

[0188] It can be understood that FIG. 9A illustrates a simplified flowchart of constructing a quantized satellite graph according to the embodiments of the present application. As shown in FIG. 9A, the database system can use the prepared data set for training, then construct an approximate K-neighbor graph (AKNNG), then perform degree adjustment and path adjustment on the approximate K-neighbor graph to obtain a satellite graph (SG), and then perform quantization on the satellite graph to obtain a quantized satellite graph (QSG). Then, a retrieval is performed based on the quantized satellite graph and a query vector.

[0189] Specifically, FIG. 9B shows a process of constructing a quantified satellite graph and querying based on the quantified satellite graph according to an embodiment of the present application. The execution subject of the process can be a database system, which can be executed by an electronic device or multiple electronic devices in cooperation. The specific process is as follows:

[0190] S201: Initialize the graph tree hybrid index according to the data set. It can be understood that the initialized graph tree hybrid index includes a tree index and an initial graph index.

[0191] In some embodiments, the training set original vector data is read in batches, the VP-Tree tree index is constructed in batches, and the initial neighbor set of each node is obtained according to the distance between vectors.

[0192] In some implementations, the training set vectors are read in batches, and a preset number (for example, 500) of vectors are read in each batch. The i-th batch of vectors is denoted as V i , and the j-th vector in V i is denoted as v ij . After each batch of vectors is read in, the initialized graph index and the tree index are updated according to the newly read vectors. Thus, the VP-Tree tree index is constructed based on the read vector data. In the process of initializing the graph index, for a vector v ij , a greedy search is performed in the current initial graph index obtained based on the previously read vector data to calculate the RangeA vectors closest to it in terms of vector distance. Furthermore, the RangeA vectors closest to it in terms of vector distance and the vectors before v ij in the current batch are taken as the initial neighbor set A of the vector v ij .

[0193] For example, taking RangeA as 100, for the 3rd batch of 500 vectors, for the 9th vector v 39 in the 3rd batch, the 100 vectors closest to it in terms of vector distance can be filtered out from the initial neighbor set of all vectors before v 39 , and then the filtered 100 vectors and the first 8 vectors in the 3rd batch are taken as the initial neighbor set A of the vector v 39 .

[0194] The following formulas (2) and (3) respectively show the expressions of two kinds of vector distances. Specifically, for any two vectors a and b, formula (2) shows the vector distance D E (a, b) based on the Euclidean distance metric; and formula (3) shows the vector distance D A (a, b) based on the angular distance metric, which are respectively expressed as

[0195] where n is the vector dimension.

[0196] S202: Determine a first candidate neighbor node set of each node.

[0197] In some embodiments, the first candidate neighbor node set is obtained using a NN-expansion method.

[0198] In some implementations, according to the principle of the NN-expansion method, the initial neighbor set A of the node v ij and the initial neighbor set corresponding to the initial neighbor node in the initial neighbor set A jointly constitute the first candidate neighbor node set B of the node v ij . The nodes in the first candidate neighbor node set B are sorted in ascending order of the vector distance from the node v ij to obtain an ordered first candidate neighbor node set C.

[0199] For example, the initial neighbor set A of the node v 39 has 108 nodes, each of which has its own corresponding initial neighbor set. The 108 nodes and the nodes in the initial neighbor set corresponding to each node jointly constitute the first candidate neighbor node set B of the node v 39 . Then the nodes in the first candidate neighbor node set B and the node v 39 are sorted in ascending order of the vector distance to obtain an ordered first candidate neighbor node set C.

[0200] S203: Determine a second candidate neighbor node set of each node according to a space adjustment strategy, and generate an approximate K-neighbor graph.

[0201] In some embodiments, the space adjustment strategy includes: when determining the second candidate neighbor node of the node, not only the distance between the nodes and the node X is considered, but also at least one of the following distribution conditions is satisfied: the neighbor node angle of any two second candidate neighbor nodes is greater than or equal to a preset angle threshold Y1; the distance between any two second candidate neighbor nodes is greater than or equal to a preset distance threshold Y2; the number of second candidate neighbor nodes in a preset space range is less than a preset number Y3. So that in the case of satisfying the foregoing space adjustment strategy, the second candidate neighbor node set of each node is determined from the ordered first candidate neighbor node set of each node, and the approximate K-neighbor graph is generated.

[0202] Specifically, the second candidate neighbor node set satisfying the above space adjustment strategy can be obtained in the following manner.

[0203] In some implementations, it can be determined whether the current first candidate neighbor node is the second candidate neighbor node based on whether the angle between the current first candidate neighbor node and the node that has been determined as the second candidate neighbor node is greater than or equal to a preset angle threshold Y1. If the angle between the current first candidate neighbor node and the node that has been determined as the second candidate neighbor node does not meet the preset angle threshold Y1, then it is not considered as the second candidate neighbor node; otherwise, it is considered as the second candidate neighbor node.

[0204] Specifically, for any node v whose second candidate neighbor node is to be determined... i We can determine whether a node is a second candidate neighbor node by sequentially judging the order of the first candidate neighbor nodes in the first candidate neighbor node set C. Specifically, we can determine whether node v is a second candidate neighbor node. i The first vector c1 in the ordered first candidate neighbor set C is automatically used as node v i The second candidate neighbor node is node v. i The second candidate neighbor node is represented by N ij Let j represent the current order in which nodes are identified as the second candidate neighbor. Traverse the vector c in the first candidate neighbor set C. i Calculate its relationship with node v respectively i , and N, which has been identified as the second candidate neighbor node. ij The included angle formed (with node v) i The cosine value of (where the vertex is) is used to obtain the vector c. i With each of the identified second candidate neighbor nodes N ij The included angle between neighboring nodes. If for the second candidate neighbor node N... ij The cosine values ​​are all less than the threshold T. α That is, if the included angle between neighboring nodes is determined to be greater than a preset angle threshold Y1, then vector c will be... i As node v i The second candidate neighbor node. It's understandable that the neighbor relationship is unidirectional; if c... i It is v i The second candidate neighbor node can be represented as a v in the graph index. i Point to c i The directed edges. Specific examples can be found in Figure 6B above, and will not be repeated here.

[0205] Formula (iv) below shows the calculation of vector c. i Its relationship with node v i The determined second candidate neighbor node N ij The included angle (with node v) i The expression for the cosine value of (where the vertex is):

[0206] wherein N ij represents the determined jth second candidate neighbor node of node v i , ||*|| represents the modulus of a vector, and c i represents the current first candidate neighbor node to be determined.

[0207] In some implementations, it is determined whether the current first candidate neighbor node is a second candidate neighbor node based on whether the distance between the current first candidate neighbor node and the node determined as a second candidate neighbor node is greater than or equal to a preset distance threshold Y2. If the distance between the current first candidate neighbor node and the node determined as a second candidate neighbor node is less than the preset distance threshold Y2, the current first candidate neighbor node is not determined as a second candidate neighbor node. Otherwise, the current first candidate neighbor node is determined as a second candidate neighbor node. Thus, it is ensured that the distance between any two second candidate neighbor nodes exceeds a certain distance. It can be understood that the above formula (two) or formula (three) can be used to calculate the distance between the first candidate neighbor node and each second candidate neighbor node. For specific examples, reference can be made to the description in FIG. 6C above, which will not be repeated here.

[0208] In addition, in some implementations, a spatial sub-range to which the current first candidate neighbor node belongs can also be calculated, and it is determined whether there are a preset number Y3 of second candidate neighbor nodes in the spatial sub-range. If there are, the current first candidate neighbor node is discarded. If there are not, the current first candidate neighbor node is determined as a second candidate neighbor node.

[0209] It can be understood that for each batch of vectors V i , the second candidate neighbor node set of each node in the batch of vectors is determined in order. After the second candidate neighbor node set of each node in the batch of vectors V i is determined, the batch of vectors V i+1 is read, and the above steps are performed until all vectors in the training set are processed, and the construction of the approximate K-Nearest Neighbor graph is completed.

[0210] S204: Degree adjustment and path adjustment are performed on the approximate K-Nearest Neighbor graph to obtain the neighbor nodes of each node, and a satellite graph is generated.

[0211] In some embodiments, when the second candidate neighbor nodes of each node are obtained, the neighbor nodes of each node can be obtained based on the second candidate neighbor nodes of each node.

[0212] Understandably, each node has an out-degree and an in-degree. For a node, the in-degree refers to the number of edges or arrows pointing to that node, which is the number of nodes that node is a neighbor of other nodes. The out-degree refers to the number of edges originating from that node and pointing to other nodes, which is the number of nodes that node is a neighbor of. Refer to Figure 3A above for details. Specifically, the second candidate neighbor node of a node can be adjusted in at least one of the following ways, and the adjusted second candidate neighbor node becomes the node's neighbor node: corresponding to node v i If the number of second candidate neighbor nodes is greater than or equal to the out-degree threshold G0, reduce the number of second candidate neighbor nodes to less than the out-degree threshold G0; if the number of times a node has been a neighbor node is less than the in-degree threshold G1, move node v to the next neighbor node. i As node v i At least some of the neighboring nodes of the neighboring nodes; corresponding to node v i Node A and node v in the second candidate neighbor nodes i The distance between node B in the second candidate neighbor node, and the distance between node A and node v i The sum of the distances between nodes B and v is less than the sum of the distances between nodes B and v. i The distance between them determines whether node B is considered node v. i The neighboring nodes of node A, where node B is a neighboring node of node A.

[0213] In some implementations, an upper limit for the out-degree and a lower limit for the in-degree of each node can be set, new nodes can be added as neighbor nodes of a node, or some second-candidate neighbor nodes can be deleted from the second-candidate neighbor nodes to generate an initial satellite image; based on the initial satellite image, the "shortcut edges" can be reduced using the triangle inequality to generate the satellite image.

[0214] For example, for any node v i All of its second candidate neighbor nodes have been selected according to node v. i The vector distances are sorted in ascending order. At this point, node density adjustment is performed based on an approximate K-nearest neighbor graph. This involves traversing all nodes in the graph index and adjusting the density for each node v. i If its out-degree f0 (e.g., out-degree value of 188) is greater than the out-degree threshold G0 (e.g., threshold of 128), then the redundant second candidate neighbor node is deleted; if its in-degree f1 (e.g., in-degree value of 60) is less than the in-degree threshold G1 (e.g., threshold of 70), then reverse edges are added to its second candidate neighbor nodes in order of distance, until its in-degree f1 equals the in-degree threshold G1 or all neighbors have had reverse edges added. After performing node density adjustment on all nodes in the approximate K-nearest neighbor graph, the initial satellite image is obtained.

[0215] According to the triangle inequality strategy, the shortcut path adjustment is performed on all nodes in the initialized satellite graph. For example, referring to FIG. 9C, for a node v i There is a neighbor n2, and the node v i The neighbor n2 can be directly pointed to through one edge, or the neighbor n2 can be pointed to through the neighbor n1 first, and then the neighbor n1 is pointed to through the neighbor n2, that is, there is a neighbor n2, if there is a path v i ->n1->n2. It is detected whether the condition shown in the following formula (five) is met, if yes, the node n2 is deleted from the neighbor set of the node v i After the shortcut path adjustment is performed on all nodes in the initialized satellite graph, the satellite graph is obtained. max{D(v i ,n1), D(n1,n2)} < D(v i ,n2) formula (five)

[0216] wherein, for any two vectors a, b, D(a, b) represents the vector distance between the vectors a, b.

[0217] S205: node quantization, using the optimized neighbor storage mode, a quantized satellite graph is constructed.

[0218] In some embodiments, the nodes in the satellite graph are dimensionally reduced and quantized to obtain node quantization codes, so as to obtain a node neighbor quantization code table corresponding to the neighbor storage mode of each node. The neighbor nodes are stored according to the corresponding mode of the node quantization code table, and a quantized satellite graph is generated.

[0219] In some implementations, based on the satellite graph, a product quantization (PQ) or optimizing product quantization (OPQ) method is used to generate node quantization codes; based on the neighbor relationship of the nodes in the satellite graph, the node quantization codes are rearranged according to a preset neighbor node arrangement mode to generate a node neighbor quantization code table; and based on the node neighbor quantization code table, a quantized node data structure is constructed to generate a quantized satellite graph.

[0220] For example, S1 vectors are randomly selected in the training set, the cluster centers of each subspace of the nodes are trained according to the OPQ method, and the orthogonal matrix R is calculated, and then the OPQ dimension reduction quantization is performed on all nodes in the satellite graph. For example, the original vector can be first multiplied by the orthogonal matrix R to obtain a rotated vector. Then each rotated vector is segmented, and then each subspace obtained after segmentation is clustered respectively, and the quantization code of all vectors is obtained according to the cluster center after clustering. For example, as shown in FIG. 3D, N M-dimensional vectors are rotated, and each M-dimensional vector after selection is segmented into T m-dimensional sub-vectors. Then each subspace is clustered respectively to obtain the quantization code of all vectors. For details, reference can be made to the description of product quantization and optimized product quantization in technical terms, which will not be repeated here.

[0221] It can be understood that based on the quantization code of all vectors, all neighbors of each node in the satellite graph are stored in the quantization code set. For example, when the cluster center number (the value is between 0 and 15) of the cluster to which each subspace belongs is stored, for each 32 neighbor nodes, each subspace can be stored according to the node neighbor quantization code set as shown in FIG. 8A. For details of the storage method, reference can be made to the description of FIG. 8A, which will not be repeated here. After the above-mentioned quantization code rearrangement is performed on all nodes in the satellite graph, a quantized satellite graph is obtained.

[0222] S206: determining an entry node based on the query vector.

[0223] In some embodiments, the VP-Tree tree index is used to obtain the similar nodes of the query vector as the entry node of the graph index according to the query vector.

[0224] In some implementations, dimension reduction quantization is performed on a given query vector to obtain a quantized query vector. Based on the query vector, the VP-Tree tree index is routed to calculate the vectors similar to the query vector as the entry node of the graph index.

[0225] S207: starting from the entry node, searching in the quantized satellite graph.

[0226] In some embodiments, a search algorithm is performed in the quantized satellite graph by quantization distance to obtain a candidate result set with KM candidate results; then the nodes in the candidate result set are screened according to the real distance between the query vector and the KM candidate results to obtain K' formal results, thereby obtaining the query result.

[0227] In some implementations, the query vector is dimensionally reduced and quantized, and the LUT is generated by calculating the distance between the original sub-vector of the query vector and the vector of each subspace cluster center. Starting from the entry node, the quantized search is performed on the quantized satellite graph, the quantized distance between the query vector and all neighbors of each node in the routing process is calculated, the neighbor nodes that meet the distance condition are inserted into the candidate result set according to the quantized distance, and the candidate result set is updated according to the updating method in step S107 above, until the nodes in the candidate result set are no longer updated. Then, the real distance between each candidate result and the query vector is calculated, for example, the distance value D E or D A The K' nodes with the smallest distance are taken as the query results.

[0228] For example, referring to FIG. 9D, when the quantized satellite graph is quantized based on the OPQ method, for a query vector q, the OPQ method is used to obtain the quantized code of the query vector q, the query vector q is divided into T equal-length sub-vectors, the distance between each sub-vector and all 16 cluster centers in each subspace is calculated, and the LUT is generated, where the LUT is a T*16 matrix. Using the node neighbor quantization code table, the cluster number to which each sub-vector of the node neighbor belongs can be obtained, and the distance between the cluster center of the cluster number in the LUT and the corresponding sub-vector of the node neighbor can be obtained by looking up the LUT, so as to approximate the distance between the query vector sub-vector and the corresponding sub-vector of the node neighbor. The distances of the sub-vectors are accumulated to obtain the quantized distance between the query vector and the neighbor of the node. The specific calculation process can be referred to the description of formula (I) above, and will not be described here. It can be understood that when the data is stored in the manner shown in FIG. 8A, the data can be read and calculated in the manner shown in FIG. 8B to FIG. 8D. The specific process is described above and will not be described here.

[0229] FIG. 10A shows a flowchart of an index construction process involved in a data processing method according to an embodiment of the present application. The execution subject of this step can be any electronic device used for the index construction process in the database system. The specific steps are as follows:

[0230] S301, determining the first candidate neighbor node of each node.

[0231] It can be understood that the pictures, texts, audio / video contents (or the features corresponding to the part of the contents) that need to be retrieved can be stored as nodes, so that the query results can be obtained according to the query input.

[0232] In some embodiments, the approximate K-Nearest Neighbor graph is built as the graph index. At this time, the first candidate neighbor node of each node can be determined based on the existing manner of building the approximate K-Nearest Neighbor graph. The specific process can refer to steps S201 and S202 shown in FIG. 9B, and the specific process is not described here.

[0233] S302, determining the nodes satisfying the distribution condition from the first candidate neighbor nodes of each node as the second candidate neighbor nodes of each node.

[0234] It can be understood that the distribution condition can be any one of the following three conditions: (1) the neighbor node included angle of any two second candidate neighbor nodes is greater than or equal to a preset angle threshold Y1; (2) the distance between any two second candidate neighbor nodes is greater than or equal to a preset distance threshold Y2; (3) the number of second candidate neighbor nodes in a preset space range is less than a preset number Y3. At this time, when the second candidate neighbor nodes of each node satisfy the above distribution condition, since each neighbor is dispersed in space, the distribution is more uniform, and the probability of finding the nodes distributed in each position in space is improved, thereby improving the retrieval accuracy.

[0235] In some embodiments, the nodes satisfying the distribution condition can be selected as the second candidate neighbor nodes of each node in the following manner.

[0236] In some implementations, whether the current first candidate neighbor node is the second candidate neighbor node can be determined based on whether the neighbor node included angle between the current first candidate neighbor node and the node determined as the second candidate neighbor node is greater than or equal to the preset angle threshold Y1. If the neighbor node included angle between the current first candidate neighbor node and the node determined as the second candidate neighbor node does not satisfy the preset angle threshold Y1, the current first candidate neighbor node is not used as the second candidate neighbor node.

[0237] In other implementations, whether the current first candidate neighbor node is the second candidate neighbor node can be determined based on whether the distance between the current first candidate neighbor node and the node determined as the second candidate neighbor node is greater than or equal to the preset distance P2. If the distance between the current candidate neighbor node and the node determined as the second candidate neighbor node is less than the preset distance threshold Y2, the current first candidate neighbor node is not used as the second candidate neighbor node.

[0238] In addition, in some implementations, the space sub-range to which the current first candidate neighbor node belongs can also be calculated, and it is judged whether there are a preset number Y3 of second candidate neighbor nodes in the space sub-range. If there are, the current first candidate neighbor node is discarded. If not, the current first candidate neighbor node is used as the second candidate neighbor node.

[0239] It can be understood that the specific determination of the second candidate neighbor node of each node can refer to step S203 in FIG. 9B, which will not be described here.

[0240] S303, based on the second candidate neighbor node of each node, obtaining the neighbor node of each node, and generating a quantized satellite graph.

[0241] In some embodiments, based on the relationship between each node and the second candidate neighbor node of each node, degree adjustment and path adjustment are performed to obtain the neighbor node of each node, and a satellite graph is generated. The nodes in the satellite graph are quantized, and based on the quantized encoding of each node and the neighbor relationship between each node, a quantized satellite graph is generated.

[0242] In the process of generating a quantized satellite graph based on the quantized encoding of each node and the neighbor relationship between each node, when the cluster center corresponding to the node encoding is represented by 4-bit data, and the neighbor node quantized encoding of each node needs to be arranged using the AVX-512 instruction set, the original storage mode can be used for data storage, for example, the storage mode corresponding to the node neighbor quantized encoding table shown in FIG. 3C is stored. The storage mode proposed in the present application can also be used for storage, that is, the quantized encoding of each of the 32 neighbors in a subspace is stored by 16 consecutive bytes, and the quantized encoding of the 32 neighbor nodes in T subspaces is stored by 16xT consecutive bytes, wherein: the 2L (L=0, 1, 2, …, 7) bytes in the 16 bytes store the quantized encoding of the Lth neighbor in the 32 neighbors, and the high 4 bits store the quantized encoding of the L+16th neighbor; the 2L+1 (L=0, 1, 2, …, 7) bytes in the 16 bytes store the quantized encoding of the L+8th neighbor in the 32 neighbors, and the high 4 bits store the quantized encoding of the L+24th neighbor. For example, the storage mode corresponding to the node neighbor quantized encoding table shown in FIG. 8A can be stored. The specific description can refer to the description of FIG. 3C and FIG. 8A above, which will not be described here.

[0243] It can be understood that the specific process of generating a quantized satellite graph based on the second candidate neighbor node of each node can also refer to the description of steps S204 and S205 above, which will not be described here.

[0244] It can be understood that when the electronic device is searching, if the function of supporting the query itself, the query can be based on the device itself. For example, the device stores quantized satellite map data, and the computing power can support it. At this time, the query can be directly based on the stored quantized satellite map. If the electronic device itself does not support the query function, the content to be queried can be sent to other devices to call the query function of other devices to obtain the query result. For example, the device does not store quantized satellite map data, at this time, it can be connected with other devices supporting query in quantized satellite map to obtain query result based on other devices. For the convenience of understanding, FIG. 10B shows a process diagram for querying based on the constructed index in a data processing method according to an embodiment of the present application. The process is introduced by taking the device 101 obtaining the query result through the device 102 as an example. The specific steps are as follows:

[0245] S401, the device 101 obtains and sends the query vector to the device 102.

[0246] In some embodiments, in various retrieval fields, such as the above-mentioned image retrieval, face recognition, advertisement pushing, etc.; regarding the text, there are intelligent question and answer, full-text retrieval, text-to-image search, etc.; regarding audio / video, there are song recognition, video retrieval, live broadcast recommendation, etc. When the device 101 obtains the query vector, the query vector can be sent to the device 102. It can be understood that the query vector can be generated based on the user input query content, can be automatically generated based on the user's behavior habits, and can be obtained in other ways, which is not required here.

[0247] S402, the device 102 queries KM candidate results from the quantized satellite map according to the query vector, wherein the second candidate neighbor nodes of each node in the approximate K-neighbor graph corresponding to the quantized satellite map satisfy the distribution condition.

[0248] In some embodiments, after receiving the query vector, the device 102 calculates the quantized distance between the query vector and the nodes to be queried based on the quantized satellite graph, so as to quickly determine the KM candidate results. It can be understood that, since the second candidate neighbor nodes of each node in the approximate K-neighbor graph corresponding to the quantized satellite graph used for query satisfy the distribution condition, wherein the distribution condition is any one of the following three: (1) the angle between any two second candidate neighbor nodes is greater than or equal to a preset angle threshold Y1; (2) the distance between any two second candidate neighbor nodes is greater than or equal to a preset distance threshold Y2; (3) the number of second candidate neighbor nodes in a preset space range is less than a preset number Y3. At this time, the nodes to be queried in the quantized satellite graph are dispersed in space, and the probability of finding the nodes to be queried in each position in space is improved, thereby avoiding finding only in the range where the nodes are dense, and failing to find better query results outside the range where the nodes are dense. The specific finding process can be referred to the description in steps S206 and S207 in FIG. 9B, and will not be repeated here.

[0249] It can be understood that, when the quantized encoding of each node neighbor is stored in the original storage mode, the original reading mode corresponding to the original storage mode is used for reading, and when the quantized encoding of each node neighbor is stored in the storage mode involved in the data processing mode proposed in the present application, the reading mode corresponding to the storage mode involved in the present application is used for reading. For example, the reading process can be referred to the corresponding reading mode in FIGS. 8B to 8D, and will not be repeated here.

[0250] S403, the device 102 determines K' query results based on the actual distance between the query vector and the KM candidate results.

[0251] It can be understood that, in the foregoing process of determining the KM candidate results, the quantized distance between the query vector and each node is used for calculation. Therefore, in order to obtain the actual vector distance between the query vector and the KM candidate results in some embodiments, the device 102 can more accurately determine the K' query results. The process of determining the K' query results based on the actual vector distance between the query vector and the KM candidate results can be referred to the description in step S207 in FIG. 9B, and will not be repeated here.

[0252] S404, the device 102 sends the K' query results to the device 101.

[0253] FIG. 11 illustrates a data processing apparatus 1100 according to an embodiment of the present application. The apparatus 1100 comprises a tree index construction module 1101, an approximate K-NN graph construction module 1102, a satellite graph construction module 1103, a quantized satellite graph construction module 1104, and a vector query module 1105, wherein the vector query module 1105 comprises a tree index query module 1105A and a graph index query module 1105B.

[0254] The tree index construction module 1101 is configured to construct a tree index according to the nodes. The process of constructing the tree index according to the nodes can refer to the description about constructing the tree index in step S201 in FIG. 9B, which will not be repeated here.

[0255] The approximate K-NN graph construction module 1102 is configured to construct the neighbor relationship of each node according to the similarity between high-dimensional vectors, generate a graph index, obtain a first candidate neighbor node set, determine a second candidate neighbor node set using a space adjustment strategy, and generate an approximate K-NN graph. The process of generating the approximate K-NN graph can refer to the process of steps S201 to S203 in FIG. 9B, and steps S301 and S302 in FIG. 10A, which will not be repeated here.

[0256] The satellite graph construction module 1103 is configured to perform degree adjustment and shortcut path adjustment on the approximate K-NN graph to obtain a satellite graph. The process of performing degree adjustment and shortcut path adjustment on the approximate K-NN graph to obtain the satellite graph can refer to the description of step S204 in FIG. 9B and step S303 in FIG. 10A, which will not be repeated here.

[0257] The quantized satellite graph construction module 1104 is configured to perform dimension reduction quantization on each node in the satellite graph, recombine the quantization codes, obtain a node neighbor quantization code table, and further generate a quantized satellite graph. The process of performing dimension reduction quantization on each node in the satellite graph to obtain the quantized satellite graph can refer to the description of step S205 in FIG. 9B and step S303 in FIG. 10A, which will not be repeated here.

[0258] The vector query module 1105 is configured to search in the graph-tree hybrid index based on a query vector to obtain a query result. The tree index query module 1105A is configured to calculate vectors with a distance close to the query vector as an entry node of the graph index in the vector retrieval stage. The graph index query module 1105B is configured to perform dimension reduction quantization on the query vector, calculate a distance matrix LUT, perform routing on the quantized satellite graph, perform high-speed quantized distance parallel calculation based on the distance matrix LUT and the node neighbor quantization code table, and thus accurately and efficiently retrieve a plurality of vectors with a smaller quantized distance from the query vector to form a candidate result set, calculate the real distance between each vector in the candidate result set and the query vector, confirm a formal result set based on the calculation result, and thus realize the query result corresponding to the query vector. The specific process of searching in the graph-tree hybrid index based on a query vector to obtain a query result can be referred to the descriptions of steps S206 and S207 in FIG. 9B and FIG. 10B, which are not described herein again.

[0259] FIG. 12 shows a schematic diagram of an apparatus according to an embodiment of the present application. The apparatus includes a host and an auxiliary memory, for example, a hard disk, which is external to the host. The host includes a main memory and a processor. The main memory can be a memory. The processor can be a central processing unit (CPU). The processor can include an arithmetic logic unit (ALU) and a control unit (CU). It can be understood that the embodiments provided in the present application can be implemented by program codes in the memory. As described above, the embodiments provided in the present application can include two parts of index construction and vector retrieval. Specifically, in some embodiments, for the index construction stage, the processor can load algorithm codes and data sets into the main memory, and then load the algorithm codes and data sets from the main memory into internal registers, and construct an approximate K-neighbor graph (AKNNG), a satellite graph (SG) and a quantized satellite graph (QSG) one by one based on the loaded data. The arithmetic logic unit (ALU) in the processor can be used for distance calculation between nodes. After the graph index construction is completed, the constructed graph index is stored in the auxiliary memory (hard disk). In the vector retrieval stage, the processor loads the graph index from the auxiliary memory into the main memory based on the program, and loads the query vector into the main memory, and then performs the approximate neighbor retrieval process on the graph index. The arithmetic logic unit in the processor can be used for distance calculation between nodes, and finally the vector query result is returned.

[0260] For the convenience of description, the algorithm corresponding to the index construction and query process provided in the embodiments of the present application is recorded as "qsgngt". Through comparison of query efficiency and retrieval accuracy with international leading algorithms of the same type, for example, Table 1 below shows the specific algorithms used for comparison, and the source of the algorithm is indicated. FIG. 13 shows an algorithm comparison effect diagram according to an embodiment of the present application. Referring to FIG. 13, compared with the same type of comparison algorithm, the query efficiency of the qsgngt algorithm indicated by the arrow 006 in the figure has significant superiority under the given retrieval accuracy. Specifically, Table 1 shows six algorithms that can be used for comparison effect, which are faiss-ivfpqfs algorithm, NGT-qg algorithm, vamana(diskann) algorithm, hnsw(nmslib) algorithm, and scann algorithm. As shown in FIG. 13, when the recall time is shorter, the qsgngt algorithm (algorithm of the present application) can query the most query vector data per second. When the same number of query vectors are queried per second, the qsgngt algorithm takes the shortest recall time.

[0261] Table 1

[0262] It can be understood that, on the one hand, the embodiment adopts a space adjustment strategy to ensure that the neighbors of the nodes in the graph index are uniformly distributed in space, improve the quality of the graph index, reduce the probability of the search process falling into local optimum, and achieve higher retrieval accuracy under the same query efficiency; on the other hand, the embodiment adopts a multi-node quantization coding arrangement scheme and a quantization search algorithm, which can improve the parallelism of node quantization distance calculation and achieve higher query efficiency under the same retrieval accuracy.

[0263] Specifically, in some embodiments of the present application, for the index construction phase, all nodes in the data set are traversed, for the current processing node, the first candidate neighbor node set (each first candidate neighbor node in the first candidate neighbor node set is arranged in ascending order according to the distance to the current processing node) is determined according to the distance (Euclidean distance, cosine distance, etc. determined according to the specific business scenario) between the node vectors, then the neighbor node angle size or neighbor node distance size corresponding to each first candidate neighbor node in the first candidate neighbor node set is calculated in turn, and the nodes in the first candidate neighbor node set are screened according to the threshold, so as to ensure that the neighbors of the current processing node are uniformly distributed in space. The above process is performed on all nodes in the data set to complete the construction of the approximate K-Nearest Neighbor Graph (AKNNG).

[0264] In some embodiments of the present application, the node neighbor quantization coding arrangement is improved, so that after the quantized neighbor nodes are stored based on the improved node neighbor quantization coding arrangement, the calculation efficiency of the quantized distance can be improved. Specifically, in the index construction phase, after the construction of the satellite graph is completed, the OPQ dimension reduction quantization or the PQ dimension reduction quantization is performed on all neighbor nodes of each node. After dimension reduction quantization, each node in the satellite graph is constructed as a quantized node. Each quantized node contains two parts, one is the number of all neighbors of the node, and the other is the quantization code of all neighbors of the node (i.e. the cluster center number corresponding to the subsegment of the neighbor).

[0265] It can be understood that the qsgngt algorithm proposed in the embodiments of the present application can be used as a downstream algorithm of general retrieval to provide a basis for constructing a general retrieval algorithm. As shown in FIG. 14, general retrieval can be represented as “vector representation + vector retrieval”. The so-called vector representation is that image, text, video, voice and other multi-modal data can complete high-quality vector representation with the help of a large model and be mapped into a unified vector space. The so-called vector retrieval is that an index structure is constructed according to the vectors in the unified vector space, and for multi-modal queries such as text and image, the queries are mapped into the unified vector space, and high-efficiency and high-quality approximate neighbor vector retrieval is completed through the index structure. The qsgngt algorithm proposed in the embodiments of the present application can be used in the above-mentioned vector retrieval stage, and can realize general retrieval by matching the multi-modal data vector representation technology. In addition, the qsgngt algorithm proposed in the embodiments of the present application achieves the best effect in the current industry on a million-scale data set, and can be expanded to a billion level by using the following two schemes.

[0266] Scheme 1: Combine the qsgngt algorithm with the coarse clustering algorithm in the faiss-ivfpqfs algorithm. Specifically, for the index construction phase, the vectors in the database are clustered (for example, the number of clusters is about 1000), divided into multiple sub-databases (the vector scale in each sub-database is about one million), and the index structure is constructed by using the index construction method of the qsgngt algorithm for each sub-database. In the vector retrieval phase, the distance between the query vector and the cluster center of each sub-database is calculated, the sub-database with a relatively short distance is selected, the approximate neighbor query result is returned in the sub-database by using the vector retrieval module of the qsgngt algorithm, the query results of multiple sub-databases are reordered, and the final query result is obtained.

[0267] Scheme 2: Combine the qsgngt algorithm with the "memory + disk" index architecture in the spann algorithm. For the index construction phase, cluster the vectors in the database (for example, the number of clusters is about one million), divide them into multiple sub-databases (the size of the vectors in each sub-database is about 1000), take the cluster centers (i.e., cluster centers) of each sub-database as nodes, form a million-scale vector set, and use the index construction method of the qsgngt algorithm to construct an index structure on the million-scale vector set and store it in the memory. Each of the one million clusters contains about 1000 original vectors, and after dimension reduction quantization, the original vectors and quantization codes are stored in the disk. In the vector retrieval phase, the vector retrieval module of the qsgngt algorithm is used to perform approximate neighbor search in the above-mentioned million-node-scale graph index, and the cluster center closest to the query vector is returned. According to the cluster number, the original vectors and quantization codes of the corresponding cluster are taken out from the disk, and the quantization distance calculation is performed with the query vector to obtain a candidate result set. The vectors in the candidate result set are used to perform real distance calculation (Euclidean distance or cosine distance, etc.) with the query vector to obtain the final approximate neighbor query result.

[0268] The data processing method proposed in the embodiments of the present application can be deployed in any electronic device, and the electronic device has the following requirements: equipped with an operating system, for example, a Linux / Windows system; has a processor, for example, a CPU, and a memory, wherein the memory is recommended to be at least 8GB.

[0269] As shown in FIG. 15, the apparatus 1500 can include one or more processors 1501, which can also be referred to as processing units, and can implement certain control functions. The processor 1501 can be a general purpose processor or a special purpose processor, etc. For example, it can be a baseband processor or a central processing unit. The baseband processor can be used to process communication protocols and communication data, and the central processing unit can be used to control communication devices such as base stations, baseband chips, terminals, terminal chips, DUs or CUs, execute software programs, and process data of software programs.

[0270] In an alternative design, the processor 1501 can also store instructions and / or data 1503, which can be run by the processor to enable the apparatus 1500 to perform the data processing method described in the above method embodiments.

[0271] In another alternative design, the processor 1501 can include a transceiver unit for implementing the receiving and transmitting functions. For example, the transceiver unit can be a transceiver circuit, or an interface, or an interface circuit. The transceiver circuit, the interface, or the interface circuit for implementing the receiving and transmitting functions can be separate or integrated together. The transceiver circuit, the interface, or the interface circuit described above can be used for reading and writing of codes / data, or the transceiver circuit, the interface, or the interface circuit described above can be used for transmission or transfer of signals.

[0272] In yet another possible design, the apparatus 1500 can include a circuit that can implement the functions of the foregoing method embodiments.

[0273] Optionally, the apparatus 1500 can include one or more memories 1502, which can store instructions / data 1504 that can be run on the processor, so that the apparatus 1500 performs the methods described in the foregoing method embodiments. Optionally, the memories can also store data. Optionally, the processor can also store instructions and / or data. The processor and the memories can be separately arranged or integrated together. For example, the corresponding relationships described in the foregoing method embodiments can be stored in the memories or in the processor.

[0274] Optionally, the apparatus 1500 can further include a transceiver 1505 and / or an antenna 1506. The processor 1501 can be referred to as a processing unit, which controls the apparatus 1500. The transceiver 1505 can be referred to as a transceiving unit, a transceiver, a transceiver circuit, a transceiving device, an interface, an interface circuit, or a transceiving module, etc., which is used to implement the receiving and transmitting functions.

[0275] Optionally, the apparatus 1500 in the embodiments of the present application can be used to execute the data processing method described in the embodiments of the present application.

[0276] According to the method provided in the embodiments of the present application, the present application further provides a computer program product, which includes computer program codes, and when the computer program codes run on a computer, the computer implements the steps performed by the apparatus 1500 in any one of the foregoing embodiments.

[0277] According to the method provided in the embodiments of the present application, the present application further provides a computer readable medium, which stores program codes, and when the program codes run on a computer, the computer implements the steps performed by the apparatus 1500 in any one of the foregoing embodiments.

[0278] Embodiments disclosed herein can be implemented in hardware, software, firmware, or any combination thereof. Embodiments of the application can be implemented as computer programs or program code executing on programmable systems comprising 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.

[0279] 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 known fashion. For purposes of this application, a processing system includes any system that has a processor, such as a digital signal processor (DSP), a microcontroller, an application specific integrated circuit (ASIC), or a microprocessor.

[0280] The program code can be implemented in a high level procedural or object oriented programming language to communicate with a processing system. The program code can be implemented in assembly or machine language, if desired. In fact, the mechanisms described herein are not limited in scope to any particular programming language. In any case, the language can be a compiled or interpreted language.

[0281] In some cases, the disclosed embodiments can be implemented in hardware, firmware, software, or any combination thereof. The disclosed embodiments can be implemented as instructions carried by or stored on one or more transitory or non-transitory machine- readable (e.g., computer-readable) media, which can be read and executed by one or more processors. For example, the instructions can be distributed over the network or by other computer readable media. Thus, a machine-readable medium can include any mechanism for storing or transmitting information in a form readable by a machine (e.g., a computer), including without limitation, floppy diskettes, optical disks, optical fiber, ROMs, RAMs, EPROMs, EEPROMs, magnetic or optical cards, flash memory, or tangible, machine-readable media in other forms. Accordingly, a machine-readable medium includes any medium that is capable of storing or transferring information that is readable by a machine (e.g., a computer).

[0282] In the drawings, some of the structures or method features are shown in certain arrangements and / or orders. It should be understood, however, that such specific arrangements and / or orders can not be required. Instead, in some embodiments, the features can be arranged in a different manner and / or order than shown in the illustrative drawings. Additionally, inclusion of a structure or method feature in a particular figure is not meant to imply that such feature is required in all embodiments, and in some embodiments, the features can not be included or can be combined with other features.

[0283] It should be noted that each unit / module mentioned in the embodiments of the devices in the present application is a logical unit / module, and in the physical world, one logical unit / module can be a physical unit / module, or a part of a physical unit / module, or a combination of multiple physical unit / modules, and the physical implementation of the logical unit / module itself is not the most important, and the combination of the functions implemented by the logical unit / module is the key to solving the technical problems proposed in the present application. In addition, in order to highlight the innovative part of the present application, the above-mentioned embodiments of the devices of the present application do not introduce units / modules that are not closely related to solving the technical problems proposed in the present application, which does not mean that the above-mentioned device embodiments do not have other units / modules.

[0284] It should be noted that in the examples and descriptions of the present patent, the relationship terms such as first and second are only used 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 the entities or operations. Moreover, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "including one" does not exclude the presence of another identical element in the process, method, article or device including the element. Although the present application is illustrated and described with reference to certain preferred embodiments, it should be understood by those skilled in the art that various changes in form and detail can be made without departing from the scope of the present application.

Claims

1. A data processing method, characterized by, The method is applied to an electronic device, and the method comprises: detecting a query request, the query request being used to request a query result of a first query vector in a first graph index, wherein the first graph index comprises a plurality of nodes, and neighbor nodes of at least part of the plurality of nodes satisfy a first condition, the first condition comprising at least one of the following: an included angle between two vectors obtained by subtracting the node from any two neighbor nodes of the node is greater than or equal to a first angle threshold value, a distance between any two neighbor nodes of the node is greater than or equal to a first distance threshold value, and a number of neighbor nodes of the node within a preset spatial range is less than a first number; finding at least one target node corresponding to the first query vector from the plurality of nodes; taking content corresponding to the at least one target node as the query result of the first query vector.

2. The method of claim 1, wherein, The neighbor nodes satisfying the first condition are obtained in the following manner: determining a plurality of first nodes from the plurality of nodes, the plurality of first nodes having a distance to the node less than a second distance threshold value; taking nodes satisfying the first condition from the plurality of first nodes as the neighbor nodes.

3. The method of claim 1, wherein, A number of neighbor nodes of the node is less than a second number.

4. The method according to any one of claims 1-3, characterized in that, The first condition further comprises: a distance between a first neighbor node in the neighbor nodes of the node and a second neighbor node in the neighbor nodes of the node is greater than a distance between the first neighbor node and the node, and a distance between the second neighbor node and the node, wherein the second neighbor node is a neighbor node of the first neighbor node.

5. The method according to any one of claims 1-4, characterized in that, The node in the first graph index is quantization encoded content.

6. The method of claim 5, wherein, The finding of the at least one target node corresponding to the first query vector from the plurality of nodes comprises: determining the at least one target node corresponding to the first query vector based on a quantization distance between the first query vector and the quantization encoding of the neighbor nodes of at least one node in the plurality of nodes.

7. The method of claim 6, wherein, The node is divided into T sub-segments, each sub-segment corresponding to a quantization encoding; and the quantization encoding is represented by 4-bit data, T is a positive integer, and T is less than or equal to a vector dimension corresponding to the node. Corresponding to an environment using an AVX-512 instruction set, the quantization encoding of the neighbor nodes of the node is stored in the following manner: quantization encodings of the same sub-segment of every 32 neighbor nodes are stored by consecutive 16 bytes, and quantization encodings of T sub-segments of the 32 neighbor nodes are stored by consecutive 16xT bytes.

8. The method of claim 7, wherein, The storage of the quantization encodings of the same sub-segment of every 32 neighbor nodes by consecutive 16 bytes comprises: a lower four bits in a 2Lth byte in 16 bytes store quantization encoding of an Lth neighbor node in the 32 neighbor nodes, and a higher 4 bits in the 2Lth byte in the 16 bytes store quantization encoding of an L+16th neighbor node, wherein the L is an integer greater than or equal to 0 and less than or equal to 7. The lower four bits of the 2L+1th byte of the 16 bytes store quantized encoding of the L+8th neighbor node of the 32 neighbor nodes, and the higher four bits of the 2L+1th byte of the 16 bytes store quantized encoding of the L+24th neighbor node.

9. The method of claim 8, wherein, The quantized distance between the first query vector and the quantized encoding of the consecutive 4 sub-segments of the neighbor nodes of a second node of the at least one node is determined based on the following manner: loading the quantized encoding of the consecutive 4 sub-segments of the 32 neighbor nodes of the second node from the first memory to a first register at one time; obtaining the quantized distance between the first query vector and the quantized encoding of the consecutive 4 sub-segments of the 32 neighbor nodes based on the data in the first register.

10. The method of claim 9, wherein, The obtaining the quantized distance between the first query vector and the quantized encoding of the consecutive 4 sub-segments of the 32 neighbor nodes based on the data in the first register comprises: storing the lower four bits of each byte of the data in the first register as a byte respectively to obtain first encoding data, and storing the higher four bits of each byte of the data in the first register as a byte to obtain second encoding data; obtaining first distance data from a first distance matrix lookup table based on the first encoding data, and obtaining second distance data from the first distance matrix lookup table based on the second encoding data, wherein the first distance data comprises quantized distances between the first query vector and the consecutive 4 sub-segments of the 0th neighbor node to the 15th neighbor node, and each 2Lth byte of every 16 bytes stores quantized distances between the first query vector and the sub-segment of the Lth neighbor, and each 2L+1th byte stores quantized distances between the first query vector and the sub-segment of the L+8th neighbor, and the second distance data comprises quantized distances between the first query vector and the consecutive 4 sub-segments of the 16th neighbor node to the 31st neighbor node, and each 2Lth byte of every 16 bytes stores quantized distances between the first query vector and the sub-segment of the L+16th neighbor, and each 2L+1th byte stores quantized distances between the first query vector and the sub-segment of the L+24th neighbor; moving each 16-bit data of the first distance data by 8 bits in the low bit direction to obtain third distance data of 64 bytes, and each 16 bytes of the third distance data comprises 8 2Lth bytes which are respectively quantized distances between the first query vector and one sub-segment of the 8th neighbor node to the 15th neighbor node; subtracting fourth distance data from the first distance data according to each 16-bit data to obtain fifth distance data, wherein the fourth distance data is data obtained by moving each 16-bit data of the third distance data by 8 bits in the high bit direction, and the fifth distance data comprises quantized distances between the first query vector and the 4 sub-segments of the 0th neighbor node to the 7th neighbor node; The second distance data is moved 8 bits to the low bit direction every 16 bits, to obtain 64 bytes of sixth distance data, in each 16 bytes of the sixth distance data, 8 2Lth bytes are respectively the quantized distances between one sub-segment of the 24th to 31st neighbor nodes and the first query vector; The second distance data is subtracted by seventh distance data every 16 bits to obtain eighth distance data, the seventh distance data is the data obtained by moving 8 bits to the high bit direction of the second distance data every 16 bits, and the eighth distance data includes the quantized distances between 4 sub-segments of the 16th to 23rd neighbor nodes and the first query vector.

11. The method of claim 6, wherein, The node is divided into T sub-segments, each sub-segment corresponds to a quantized code, and the quantized code is represented by 4-bit data, T is a positive integer, and T is less than or equal to the vector dimension corresponding to the node; Corresponding to an environment using the AVX-1024 instruction set, the quantized codes of the neighbor nodes of the node are stored in the following manner: The quantized codes of the same sub-segment of every 64 neighbor nodes are stored by 32 consecutive bytes, and the quantized codes of T sub-segments of the 64 neighbor nodes are stored by 32×T consecutive bytes.

12. The method of claim 11, wherein, The storage of the quantized codes of the same sub-segment of every 64 neighbor nodes by 32 consecutive bytes includes: The low four bits of the 2Lth byte in the 32 bytes store the quantized code of the Lth neighbor node in the 64 neighbor nodes, and the high four bits of the 2Lth byte in the 32 bytes store the quantized code of the L+32th neighbor node, wherein L is an integer greater than or equal to 0 and less than or equal to 15; The low four bits of the 2L+1th byte in the 32 bytes store the quantized code of the L+16th neighbor node in the 64 neighbor nodes, and the high four bits of the 2L+1th byte in the 32 bytes store the quantized code of the L+48th neighbor node.

13. The method of claim 12, wherein, The quantized distances between the first query vector and the quantized codes of the consecutive 4 sub-segments of the neighbor nodes of a second node in the at least one node are determined in the following manner: The quantized codes of the consecutive 4 sub-segments of the 64 neighbor nodes of the second node are loaded from the second memory to the second register at a time; Based on the data in the second register, the quantized distances between the first query vector and the quantized codes of the consecutive 4 sub-segments of the 64 neighbor nodes are obtained.

14. The method of claim 13, wherein, The obtaining of the quantized distances between the first query vector and the quantized codes of the consecutive 4 sub-segments of the 64 neighbor nodes based on the data in the second register includes: The low four bits of each byte in the data in the second register are stored as a byte respectively to obtain third encoding data, and the high four bits of each byte in the data in the second register are stored as a byte respectively to obtain fourth encoding data; obtaining ninth distance data from the second distance matrix lookup table based on the third encoded data, and obtaining tenth distance data from the second distance matrix lookup table based on the fourth encoded data, wherein the ninth distance data comprises quantized distances of the first 4 sub-segments of the 0th to 31st neighbor nodes and the first query vector, and each 2Lth byte in every 32 bytes stores a quantized distance of a sub-segment of an Lth neighbor and the first query vector, and each 2L+1th byte stores a quantized distance of a sub-segment of an L+16th neighbor and the first query vector, and the tenth distance data comprises quantized distances of the first 4 sub-segments of the 32nd to 63rd neighbor nodes and the first query vector, and each 2Lth byte in every 32 bytes stores a quantized distance of a sub-segment of an L+32th neighbor and the first query vector, and each 2L+1th byte stores a quantized distance of a sub-segment of an L+48th neighbor and the first query vector; moving each 16-bit data of the ninth distance data to a low bit direction by 8 bits to obtain 128 bytes of eleventh distance data, wherein each 32 bytes of the eleventh distance data comprises 16 2Lth bytes, each of which is a quantized distance of a sub-segment of the 16th to 31st neighbor nodes and the first query vector; subtracting twelfth distance data from the ninth distance data according to each 16-bit data to obtain thirteenth distance data, wherein the twelfth distance data is obtained by moving each 16-bit data of the eleventh distance data to a high bit direction by 8 bits, and the thirteenth distance data comprises quantized distances of 4 sub-segments of the 0th to 15th neighbor nodes and the first query vector; moving each 16-bit data of the tenth distance data to a low bit direction by 8 bits to obtain 128 bytes of fourteenth distance data, wherein each 32 bytes of the fourteenth distance data comprises 16 2Lth bytes, each of which is a quantized distance of a sub-segment of the 48th to 63rd neighbor nodes and the first query vector; subtracting fifteenth distance data P2 from the tenth distance data according to each 16-bit data to obtain sixteenth distance data, wherein the fifteenth distance data is obtained by moving each 16-bit data of the fourteenth distance data to a high bit direction by 8 bits, and the sixteenth distance data comprises quantized distances of 4 sub-segments of the 32nd to 47th neighbor nodes and the first query vector.

15. A data processing method, characterized by, The method is applied to an electronic device, and the method comprises: obtaining a plurality of nodes to be indexed in a graph; determining first candidate neighbor nodes of each node based on distances between the plurality of nodes; taking the first candidate neighbor nodes satisfying a first condition as second candidate neighbor nodes of the node, wherein the first condition comprises at least one of the following: An included angle between two vectors respectively obtained by subtracting the node from any two second candidate neighbor nodes of the node is greater than or equal to a first angle threshold, a distance between any two second candidate neighbor nodes of the node is greater than or equal to a first distance threshold, and a number of second candidate neighbor nodes of the node within a preset spatial range is less than a first number; Based on the second candidate neighbor nodes of each node, neighbor nodes of each node are obtained; Based on each node and the neighbor nodes of each node, a first graph index is obtained.

16. The method of claim 15, wherein, The obtaining of the neighbor nodes of each node based on the second candidate neighbor nodes of each node comprises: The second candidate neighbor nodes of the node are adjusted in at least one of the following manners, and the adjusted second candidate neighbor nodes are taken as the neighbor nodes of the node: Corresponding to a number of second candidate neighbor nodes of the node being greater than or equal to a second number, the number of second candidate neighbor nodes is reduced to be less than the second number; Corresponding to a number of times that the node is taken as a neighbor node being less than a third number, the node is increased to be a neighbor node of at least part of the neighbor nodes of the node; Corresponding to a distance between a first node in the second candidate neighbor nodes of the node and a second node in the second candidate neighbor nodes of the node being less than a sum of distances between the first node and the node and between the second node and the node, the second node is not taken as a neighbor node of the node, wherein the second node is a neighbor node of the first node.

17. The method according to claim 15 or 16, characterized in that, The obtaining of the first graph index based on each node and the neighbor nodes of each node comprises: The node is divided into T sub-segments, each sub-segment corresponding to a quantization code; and the quantization code is represented by 4-bit data, T is a positive integer, and T is less than or equal to a vector dimension corresponding to the node; Corresponding to an environment using an AVX-512 instruction set, the quantization codes of the neighbor nodes of the node are stored in the following manner: The quantization codes of the same sub-segment of every 32 neighbor nodes are stored by means of 16 consecutive bytes, and the quantization codes of T sub-segments of the 32 neighbor nodes are stored by means of 16×T consecutive bytes.

18. The method of claim 17, wherein, The storing of the quantization codes of the same sub-segment of every 32 neighbor nodes by means of 16 consecutive bytes comprises: The quantization code of an Lth neighbor node in the 32 neighbor nodes is stored in a lower four bits of a 2Lth byte in the 16 bytes; The quantization code of an L+16th neighbor node is stored in a higher 4 bits of the 2Lth byte in the 16 bytes, wherein the L is an integer greater than or equal to 0 and less than or equal to 7; The quantization code of an L+8th neighbor node in the 32 neighbor nodes is stored in a lower four bits of a 2L+1th byte in the 16 bytes; The quantization code of an L+24th neighbor node is stored in a higher 4 bits of the 2L+1th byte in the 16 bytes.

19. The method of claim 15 or 16, wherein, The obtaining of the first graph index based on each node and the neighbor nodes of each node comprises: The node is divided into T sub-segments, each sub-segment corresponding to a quantization code; and the quantization code is represented by 4-bit data, T is a positive integer, and T is less than or equal to the vector dimension corresponding to the node; Corresponding to an environment using an AVX-512 instruction set, the quantization codes of the neighbor nodes of the node are stored in the following manner: The quantization codes of the same sub-segment of every 64 neighbor nodes are stored by consecutive 32 bytes, and the quantization codes of T sub-segments of the 64 neighbor nodes are stored by consecutive 32*T bytes.

20. The method of claim 19, wherein, The storing of the quantization codes of the same sub-segment of every 64 neighbor nodes by consecutive 32 bytes comprises: In the low four bits of the 2Lth byte of the 32 bytes, the quantization code of the Lth neighbor node of the 64 neighbor nodes is stored; and in the high 4 bits of the 2Lth byte of the 32 bytes, the quantization code of the L+32th neighbor node is stored, wherein the L is an integer greater than or equal to 0 and less than or equal to 15; In the low four bits of the 2L+1th byte of the 32 bytes, the quantization code of the L+16th neighbor node of the 64 neighbor nodes is stored; In the high 4 bits of the 2L+1th byte of the 32 bytes, the quantization code of the L+48th neighbor node is stored.

21. A data processing method, characterized by, The method is applied to an electronic device, and the method comprises: detecting a query request, the query request being used to request a query result of a first query vector in a first graph index, wherein the first graph index comprises a plurality of nodes, and neighbor nodes of the plurality of nodes are stored in a first storage manner; finding at least one target node corresponding to the first query vector from the plurality of nodes; taking content corresponding to the at least one target node as the query result of the first query vector, wherein the first storage manner comprises: The node is divided into T sub-segments, each sub-segment corresponding to a quantization code; and the quantization code is represented by 4-bit data, T is a positive integer, and T is less than or equal to the vector dimension corresponding to the node; Corresponding to an environment using an AVX-512 instruction set, the quantization codes of the neighbor nodes of the node are stored in the following manner: The quantization codes of the same sub-segment of every 64 neighbor nodes are stored by consecutive 32 bytes, and the quantization codes of T sub-segments of the 64 neighbor nodes are stored by consecutive 32*T bytes.

22. The method of claim 21, wherein, The storing of the quantization codes of the same sub-segment of every 64 neighbor nodes by consecutive 32 bytes comprises: In the low four bits of the 2Lth byte of the 32 bytes, the quantization code of the Lth neighbor node of the 64 neighbor nodes is stored; and in the high 4 bits of the 2Lth byte of the 32 bytes, the quantization code of the L+32th neighbor node is stored, wherein the L is an integer greater than or equal to 0 and less than or equal to 15; In the low four bits of the 2L+1th byte of the 32 bytes, the quantization code of the L+16th neighbor node of the 64 neighbor nodes is stored; In the high 4 bits of the 2L+1th byte of the 32 bytes, the quantization code of the L+48th neighbor node is stored. The method is applied to an electronic device, and the method comprises: detecting a query request, the query request being used to request a query result of a first query vector in a first graph index, wherein the first graph index comprises a plurality of nodes, and neighbor nodes of the plurality of nodes are stored in a first storage manner; finding at least one target node corresponding to the first query vector from the plurality of nodes; taking content corresponding to the at least one target node as the query result of the first query vector, wherein the first storage manner comprises: The node is divided into T sub-segments, each sub-segment corresponding to a quantization code; and the quantization code is represented by 4-bit data, T is a positive integer, and T is less than or equal to the vector dimension corresponding to the node; Corresponding to an environment using an AVX-512 instruction set, the quantization codes of the neighbor nodes of the node are stored in the following manner: The quantization codes of the same sub-segment of every 64 neighbor nodes are stored by consecutive 32 bytes, and the quantization codes of T sub-segments of the 64 neighbor nodes are stored by consecutive 32*T bytes. The storing of the quantization codes of the same sub-segment of every 64 neighbor nodes by consecutive 32 bytes comprises: In the low four bits of the 2Lth byte of the 32 bytes, the quantization code of the Lth neighbor node of the 64 neighbor nodes is stored; and in the high 4 bits of the 2Lth byte of the 32 bytes, the quantization code of the L+32th neighbor node is stored, wherein the L is an integer greater than or equal to 0 and less than or equal to 15; In the low four bits of the 2L+1th byte of the 32 bytes, the quantization code of the L+16th neighbor node of the 64 neighbor nodes is stored; In the high 4 bits of the 2L+1th byte of the 32 bytes, the quantization code of the L+48th neighbor node is stored. The lower four bits of the 2L+1th byte of the 16 bytes store quantized coding of the L+8th neighbor node of the 32 neighbor nodes, and the higher four bits of the 2L+1th byte of the 16 bytes store quantized coding of the L+24th neighbor node.

23. The method of claim 20, wherein, The quantized coding of the same sub-segment of every 64 neighbor nodes is stored by consecutive 32 bytes, including: The lower four bits of the 2Lth byte of the 32 bytes store quantized coding of the Lth neighbor node of the 64 neighbor nodes, and the higher four bits of the 2Lth byte of the 16 bytes store quantized coding of the L+32th neighbor node, wherein the L is an integer greater than or equal to 0 and less than or equal to 15; The lower four bits of the 2L+1th byte of the 32 bytes store quantized coding of the L+16th neighbor node of the 64 neighbor nodes, and the higher four bits of the 2L+1th byte of the 32 bytes store quantized coding of the L+48th neighbor node.

24. The method of any one of claims 21-23, wherein, Further comprising: Neighbor nodes of at least part of the plurality of nodes satisfy a first condition, and the first condition includes at least one of: An included angle between two vectors respectively obtained by subtracting the node from any two neighbor nodes of the node is greater than or equal to a first angle threshold, a distance between any two neighbor nodes of the node is greater than or equal to a first distance threshold, and a number of neighbor nodes of the node within a preset spatial range is less than a first number; From the plurality of nodes, at least one target node corresponding to a first query vector is found; Content corresponding to the at least one target node is taken as a query result of the first query vector.

25. An electronic device, comprising: Including: A memory for storing instructions; A processor for executing the instructions to implement the data processing method of any one of claims 1-14, 15-20, or 21-24.

26. A readable storage medium characterized by, The readable medium stores instructions, and the instructions, when executed on an electronic device, cause the electronic device to execute the data processing method of any one of claims 1-14, 15-20, or 21-24.

27. A computer program product, characterised in that, The computer program product includes computer program code, which, when executed on a computer, causes the computer to execute the data processing method of any one of claims 1-14, 15-19, or 21-24.

Citation Information

Patent Citations

  • To-be-retrieved data processing method, data retrieval method, electronic equipment and medium

    CN114817657A

  • Neighbor graph updating method for approximate nearest neighbor search

    CN117150082A

  • Method for encoding based on mixture of vector quantization and nearest neighbor search using thereof

    US20200226137A1

Cited By

  • Method and system for predicting residual service life of bearing based on vector space retrieval

    CN121542279A

  • Method and system for predicting residual useful life of bearing based on vector space retrieval

    CN121542279B