GPU-based graph vector indexing construction method, apparatus, and storage medium
By employing a GPU-based graph vector indexing construction method, and utilizing sharding and pipeline design, the problem of time-consuming graph indexing construction on the CPU is solved, achieving efficient graph indexing construction and improving construction speed and data processing capabilities.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 启元实验室
- Filing Date
- 2026-03-06
- Publication Date
- 2026-06-30
AI Technical Summary
Existing technologies for building high-quality graph indexes on CPUs are too time-consuming and cannot meet the needs of frequent index updates in online services.
A GPU-based graph vector indexing method is adopted. The original dataset is sharded by clustering algorithm, and a local graph vector index is built on the GPU. By using the producer-consumer model and double-buffered pipeline design, the data transmission and computation are overlapped to build a hierarchical global graph vector index.
While maintaining the same recall rate, the graph index construction speed is improved by about 3 to 13 times, which can handle datasets that far exceed the GPU memory capacity, solve the memory wall problem, and shorten the construction time.
Smart Images

Figure CN121807861B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of graph index construction technology, and more specifically, to a GPU-based graph vector index construction method, apparatus, and storage medium. Background Technology
[0002] With the rapid development of artificial intelligence and big data technologies, Approximate Nearest Neighbor Search (ANNS) has become a core supporting technology in fields such as web search, recommender systems, retrieval augmentation (RAG), and large-scale data mining. In these applications, in order to quickly find the nearest neighbor of a query vector in a large-scale, high-dimensional vector dataset, it is usually necessary to build an index structure.
[0003] Among various indexing techniques, graph-based indexes (such as HNSW and NSG) have become the mainstream choice in industry and academia due to their excellent balance between recall and query latency. These methods construct a sparse nearest-neighbor graph, allowing the query process to quickly navigate to the target region in the graph using either greedy search or beam search.
[0004] However, despite the excellent query performance of graph indexes, building high-quality graph indexes (such as NSG) on the CPU is very time-consuming. For example, for a dataset containing 200 million vectors, building an index using only the CPU could take more than 10 hours. This is unacceptable for online services that require frequent index updates (such as daily or even hourly refreshes) to cope with data distribution shifts.
[0005] The content of the background section is merely technology known to the public and does not necessarily represent existing technology in the field. Summary of the Invention
[0006] This application aims to provide a GPU-based graph vector index construction method, apparatus, and storage medium to solve the aforementioned technical problem of time-consuming graph index construction.
[0007] According to one aspect of this application, a GPU-based graph vector index construction method is provided. The method includes: partitioning the original dataset based on a clustering algorithm to obtain a first preset number of partitioned data subsets; sending the i-th partitioned data subset to the GPU, where i is a positive integer; constructing a local graph vector index for the i-th partitioned data subset on the GPU; sending the (i+1)-th partitioned data subset to the GPU until all local graph vector indices are obtained; and constructing a hierarchical global graph vector index based on all local graph vector indices.
[0008] According to some embodiments of this application, constructing a local graph vector index for the i-th data subset on a GPU includes: on the GPU, performing the steps of determining a sequence of candidate neighbor vectors for the current query vector of the i-th data subset; traversing all query vectors of the i-th data subset to determine a sequence of candidate neighbor vectors for all query vectors; on the GPU, pruning the candidate neighbor vectors in the candidate neighbor vector sequence based on a preset pruning rule to obtain an adjacency list corresponding to the current query vector; traversing all query vectors of the i-th data subset to determine an adjacency list corresponding to all query vectors; and on the GPU, inserting reverse edges into the graph structure corresponding to the adjacency list corresponding to all query vectors to construct a local graph vector index for the i-th data subset.
[0009] According to some embodiments of this application, determining the candidate neighbor vector sequence of the current query vector in the i-th data subset includes: expanding the candidate neighbor vectors of the current query vector based on the current graph structure corresponding to the current query vector in the i-th data subset; determining a first distance between the current query vector and the candidate neighbor vectors; sorting the candidate neighbor vectors according to the first distance to determine the first candidate neighbor vector sequence of the current query vector; determining whether the first candidate neighbor vector sequence meets a preset stopping condition; if yes, determining the first candidate neighbor vector sequence as the candidate neighbor vector sequence of the current query vector; if no, performing the step of determining the candidate neighbor vector sequence of the current query vector in the i-th data subset again.
[0010] According to some embodiments of this application, determining the first distance between the current query vector and the candidate neighbor vector includes: converting the current query vector into query data in a preset format, and converting the candidate neighbor vector into candidate data in a preset format; determining an intermediate result of the first distance between the preset format query data and the preset format candidate data; and determining the first distance based on the pre-stored modulus of the current query vector, the modulus of the candidate neighbor vector, and the intermediate result of the first distance.
[0011] According to some embodiments of this application, sorting candidate neighbor vectors based on a first distance to determine the first candidate neighbor vector sequence of the current query vector includes: sorting the candidate neighbor vectors based on a shared memory-based bitonic sort or a shared memory-based radix sort based on the first distance to determine the first candidate neighbor vector sequence of the current query vector.
[0012] According to some embodiments of this application, pruning candidate neighbor vectors in a candidate neighbor vector sequence based on preset pruning rules to obtain an adjacency list corresponding to the current query vector includes: grouping the candidate neighbor vector sequence into a second preset number of candidate matrices; determining a second distance between the candidate matrices and the known neighbors of the current query vector; and pruning candidate neighbor vectors in the candidate neighbor vector sequence according to the second distance based on preset pruning rules to obtain an adjacency list corresponding to the current query vector.
[0013] According to some embodiments of this application, constructing a hierarchical global graph vector index based on all local graph vector indices includes: determining the navigation point of the i-th data subset based on the local graph vector index of the i-th data subset; traversing all local graph vector indices to obtain all navigation points; determining the metagraph corresponding to all local graph vector indices based on all navigation points; and constructing a hierarchical global graph vector index based on all local graph vector indices and metagraphs.
[0014] According to some embodiments of this application, constructing a hierarchical global graph vector index based on all local graph vector indices and metagraphs includes: determining a first preset number of global graph vector indices for fragmented data subsets based on all local graph vector indices and metagraphs; and constructing a hierarchical global graph vector index based on the global graph vector index and all local graph vector indices.
[0015] According to one aspect of this application, a GPU-based graph vector index construction apparatus is provided, the apparatus including an index construction unit. The index construction unit partitions the original dataset based on a clustering algorithm to obtain a first preset number of partitioned data subsets; the index construction unit sends the i-th partitioned data subset to the GPU, where i is a positive integer; the index construction unit constructs a local graph vector index for the i-th partitioned data subset on the GPU, and sends the (i+1)-th partitioned data subset to the GPU, until all local graph vector indices are obtained; the index construction unit constructs a hierarchical global graph vector index based on all local graph vector indices.
[0016] According to another aspect of this application, this application also provides a non-volatile computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is capable of implementing the GPU-based graph vector index construction method as described above.
[0017] The technical solution of this application can segment the original dataset using a clustering algorithm to obtain a first preset number of segmented data subsets. The technical solution of this application can send the i-th segmented data subset to the GPU. The technical solution of this application can construct a local graph vector index for the i-th segmented data subset on the GPU, and simultaneously send the (i+1)-th segmented data subset to the GPU, until all local graph vector indices are obtained. The technical solution of this application can construct a hierarchical global graph vector index using all local graph vector indices.
[0018] The technical solution of this application can build a producer-consumer model pipeline, and the data transfer time of the PCIe bus is completely masked by the computation time of the GPU, eliminating the I / O bottleneck. Under the premise of maintaining the same recall rate, the end-to-end construction speed is improved by about 3 to 13 times (the specific speedup depends on the data dimension of the original dataset; the higher the dimension, the more obvious the speedup). This can effectively shorten the graph index construction time.
[0019] The technical solution of this application adopts a double-buffered pipeline design, which enables the solution to process datasets that far exceed the GPU memory capacity, and the performance hardly decreases with the increase of data volume, thus solving the memory wall problem. Attached Figure Description
[0020] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 A flowchart illustrating method 1000 according to an embodiment of this application is shown;
[0022] Figure 2 A flowchart illustrating step S300 according to an embodiment of this application is shown;
[0023] Figure 3 A flowchart illustrating step S310 according to an embodiment of this application is shown;
[0024] Figure 4 A flowchart illustrating step S312 according to an embodiment of this application is shown;
[0025] Figure 5 A flowchart illustrating step S330 according to an embodiment of this application is shown;
[0026] Figure 6 A flowchart illustrating step S500 according to an embodiment of this application is shown;
[0027] Figure 7 A flowchart illustrating step S540 according to an embodiment of this application is shown;
[0028] Figure 8 A schematic diagram of the structure of a GPU-based graph vector index construction apparatus according to an embodiment of this application is shown.
[0029] Explanation of reference numerals in the attached figures:
[0030] GPU-based graph vector index building device 20; index building unit 21. Detailed Implementation
[0031] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, they are provided so that this application will be thorough and complete, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted.
[0032] The described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a full understanding of embodiments of this disclosure. However, those skilled in the art will recognize that the technical solutions of this disclosure can be practiced without one or more of these specific details, or other methods, components, materials, devices, etc. In these cases, well-known structures, methods, devices, implementations, materials, or operations will not be shown or described in detail.
[0033] Furthermore, the terms “comprising” and “having”, and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the steps or units listed, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to such process, method, product, or apparatus.
[0034] The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order.
[0035] The technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some, not all, of the embodiments of this application. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0036] The English terms used in this application, their full English names, and their corresponding Chinese definitions are as follows:
[0037] CPU, Central Processing Unit;
[0038] GPU, Graphics Processing Unit;
[0039] Faiss-IVF, Facebook AI Similarity Search - Inverted File Index;
[0040] K-means, K-means Clustering, K-means clustering (algorithm).
[0041] SoA, Structure-of-Arrays;
[0042] DMA, Direct Memory Access;
[0043] Pinned memory, page-locked memory;
[0044] CUDA, Compute Unified Device Architecture;
[0045] I / O, Input / Output;
[0046] ID, Identification, identifier;
[0047] GEMM, General Matrix Multiply;
[0048] Tensor Core;
[0049] FP16, 16-bit Floating Point;
[0050] BF16, Brain Floating Point 16, a 16-bit Brain floating-point number;
[0051] FP32, 32-bit Floating Point;
[0052] Warp, thread bundle;
[0053] Top-k, the top k results (the k results with the highest similarity / probability);
[0054] PCIe, Peripheral Component Interconnect Express, is a high-speed peripheral component interconnect bus.
[0055] ANNS, Approximate Nearest Neighbor Search;
[0056] RAG, Retrieval-Augmented Generation;
[0057] HNSW, Hierarchical Navigable Small World;
[0058] NSG, Navigating Spreading-out Graph.
[0059] See Figure 8 The GPU-based graph vector indexing device 20 provided in this application includes an indexing unit 21. The following section discusses... Figure 8 This application describes a GPU-based graph vector index construction method 1000, see [link to relevant documentation]. Figure 1 Method 1000 includes steps S100-S500.
[0060] In step S100, the original dataset is divided into fragments based on a clustering algorithm to obtain a first preset number of fragmented data subsets.
[0061] According to the example embodiment, the original dataset can be an initial, complete set of vector data to be indexed.
[0062] The sharded data subsets can be independent subsets of data after splitting the original dataset. The first preset number can be the number of sharded data subsets. This first preset number can be set according to the GPU's transfer and memory parameters. Sharding processing can be performed on the CPU. Transfer parameters can be the transfer bandwidth from CPU to GPU and from GPU to CPU. Memory parameters can be the GPU's memory size. The first preset number ensures that the total sharding processing time is the maximum of the data transfer time and the computation processing time, thus guaranteeing perfect overlap between computation and transfer. The clustering algorithm can be either the Faisal-IVF coarse quantizer or the K-means algorithm.
[0063] For example, in step S100, the index building unit 21 can divide the original dataset into shards on the CPU based on a clustering algorithm, and divide vectors with similar geometric positions into the same shard data subset to obtain a first preset number of shard data subsets, which can significantly improve the hit rate of the first-level cache or second-level cache in the subsequent graph index building process.
[0064] In step S200, the i-th data fragment subset is sent to the GPU.
[0065] According to the example embodiment, i is a positive integer, and i is less than or equal to a first preset number. The fragmented data subset is organized in host memory as a Structure Array (SoA) format, where the k-th dimension of all vectors is stored contiguously. This layout ensures that memory accesses are merged when data is transferred to the GPU and read by a warp, greatly improving PCIe transfer efficiency and GPU global memory read bandwidth.
[0066] The CPU-side buffer uses pinned memory, which avoids the operating system's paging and swapping of memory. It also allows the GPU's DMA (Direct Memory Access) engine to directly read host memory without CPU involvement, which is a necessary condition for achieving asynchronous transmission and computation overlap.
[0067] For example, in step S200, the index building unit 21 sends the i-th fragment data subset to the GPU.
[0068] In step S300, the local graph vector index of the i-th data subset is constructed on the GPU.
[0069] According to the example implementation, a local graph vector index can be a graph-structured vector index for a subset of sharded data. For example, a local graph vector can be an HNSW, NSG, or similar structure, thereby achieving scalability and parallel query capabilities while ensuring retrieval accuracy.
[0070] For example, in step S300, the index building unit 21 constructs a local graph vector index for the i-th data subset on the GPU. The index building unit 21 can determine the candidate neighbor vector sequence of the current query vector in the i-th data subset, traverse all query vectors in the i-th data subset to determine the candidate neighbor vector sequence of all query vectors, and prune the candidate neighbor vectors in the candidate neighbor vector sequence based on a preset pruning rule to obtain the adjacency list corresponding to the current query vector. It then traverses all query vectors in the i-th data subset to determine the adjacency list corresponding to all query vectors. The index building unit 21 can insert reverse edges into the graph structure corresponding to the adjacency list of all query vectors to construct the local graph vector index for the i-th data subset.
[0071] In step S400, the (i+1)th data fragment subset is sent to the GPU until all local graph vector indices are obtained.
[0072] According to the example embodiment, steps S400 and S300 can be executed synchronously. For example, in step S400, the index building unit 21 can send the (i+1)th fragment data subset to the GPU until all local graph vector indices are obtained.
[0073] Index building unit 21 can allocate two equal GPU buffers, creating two high-priority computation streams S_compute and two copy streams S_copy for data transfer. Index building unit 21 fully processes the i-th data subset in one buffer on the computation stream S_compute within the GPU core. Simultaneously, index building unit 21 asynchronously copies the (i+1)-th data subset from CPU memory to the other buffer via the copy stream S_copy using the DMA engine. Index building unit 21 can also perform finishing work on the (i-1)-th data subset (e.g., counting the number of edges in the local graph vector index) and read back the results (e.g., reading back the local graph vector index) on the CPU, writing the results back to the CPU. Index building unit 21 achieves seamless switching through CUDA event synchronization steps S400 and S300, thereby constructing a double-buffered pipeline for the producer-consumer model. Index building unit 21 can write back the local graph vector index to the CPU.
[0074] In step S500, a hierarchical global graph vector index is constructed based on all local graph vector indices.
[0075] According to the example embodiment, a hierarchical global graph vector index can be the original data and the corresponding global graph vector index, which is combined through hierarchical organization and global graph connections. The hierarchical global graph vector index can be a structure such as HNSW.
[0076] For example, in step S500, the index building unit 21 can construct a hierarchical global graph vector index based on all local graph vector indices. The index building unit 21 can determine the metagraph based on all local graph vector indices, and the index building unit 21 can construct a hierarchical global graph vector index based on the metagraph and all local graph vector indices.
[0077] Through the above embodiments, the technical solution of this application can segment the original dataset using a clustering algorithm to obtain a first preset number of segmented data subsets. The technical solution of this application can send the i-th segmented data subset to the GPU. The technical solution of this application can construct a local graph vector index for the i-th segmented data subset on the GPU, and simultaneously send the (i+1)-th segmented data subset to the GPU, until all local graph vector indices are obtained. The technical solution of this application can construct a hierarchical global graph vector index using all local graph vector indices.
[0078] The technical solution of this application can build a producer-consumer model pipeline, and the data transfer time of the PCIe bus is completely masked by the computation time of the GPU, eliminating the I / O bottleneck. Under the premise of maintaining the same recall rate, the end-to-end construction speed is improved by about 3 to 13 times (the specific speedup depends on the data dimension of the original dataset; the higher the dimension, the more obvious the speedup). This can effectively shorten the graph index construction time.
[0079] The technical solution of this application adopts a double-buffered pipeline design, which enables the solution to process datasets that far exceed the GPU memory capacity, and the performance hardly decreases with the increase of data volume, thus solving the memory wall problem.
[0080] Optionally, see Figure 2 Step S300 may include steps S310-S350.
[0081] In step S310, on the GPU, the step of determining the candidate neighbor vector sequence of the current query vector for the i-th data subset is performed.
[0082] According to the example embodiment, the query vector can be a vector data in the i-th data subset. The current query vector can be a batch of query vectors being processed. The candidate neighbor vector sequence can be a sequence of vector nodes of the candidate neighbors of the current query vector.
[0083] For example, in step S310, the index building unit 21 can perform the step of determining the candidate neighbor vector sequence of the current query vector of the i-th shard data subset on the GPU.
[0084] Optionally, see Figure 3 Step 310 may include steps S311-S316.
[0085] In step S311, the candidate neighbor vectors of the current query vector are expanded according to the current graph structure corresponding to the current query vector in the i-th data subset.
[0086] According to the example embodiment, the current graph structure can be the graph structure corresponding to the current candidate neighbor vector of the current query vector. The candidate neighbor vector can be a set of candidate neighbor vector nodes of the current query vector.
[0087] For example, in step S311, the index building unit 21 can expand the candidate neighbor vectors of the current query vector based on the current graph structure corresponding to the current query vector in the i-th data subset. The index building unit 21 can also expand potential closer neighbor nodes by starting from the known neighbor nodes of the current graph structure corresponding to the current query vector in the i-th data subset.
[0088] The index building unit 21 can record the accessed vector nodes and instantiate a block-level private access record table in shared memory. For the ID range of the i-th data subset that is a small ID range (e.g., the small ID range can be the ID data range that is less than the shared memory divided by the block capacity), a bitmap is used for implementation. For the ID range of the i-th data subset that is a large ID range (e.g., the large ID range can be the ID data range that is greater than or equal to the shared memory divided by the block capacity), a cuckoo hash table is used for implementation. The access record table can transform the originally random global memory writes into low-latency on-chip operations.
[0089] In step S312, the first distance between the current query vector and the candidate neighbor vector is determined.
[0090] According to the example embodiment, the first distance can be the distance between the current query vector and the candidate neighbor vectors. For example, the first distance can be the Euclidean distance.
[0091] For example, in step S312, the index building unit 21 can calculate and determine the first distance between the current query vector and the candidate neighbor vectors. The index building unit 21 can transform the irregular vector distance calculation into a regular matrix multiplication (GEMM) to fully utilize the computing power of the GPU's Tensor Cores.
[0092] The matrix operation form of the first distance can be represented as follows:
[0093] ;
[0094] Where D represents the matrix operation form of the first distance, i.e., matrix distance. Q is the current query vector, which can be a batch of query vectors, and the number of Q can be 1. C is the set of candidate neighbor vectors corresponding to the current query vector. Q n is the modulus of all query vectors in Q; C Let T be the magnitude of all candidate neighbor vector nodes in C; T represents the matrix transpose. It is the standard, general form of matrix multiplication, which accounts for the vast majority of the computation.
[0095] Optionally, see Figure 4 Step S312 may include steps S3121-S3123.
[0096] In step S3121, the current query vector is converted into query data in a preset format, and the candidate neighbor vector is converted into candidate data in a preset format.
[0097] According to the example embodiment, the preset format query data can be preset format data of the current query vector. For example, the preset format query data can be query vector data in half-precision floating-point numbers (e.g., FP16 or BF16). The preset format candidate data can be preset format data of candidate neighbor vectors. For example, the preset format candidate data can be candidate neighbor vector data in half-precision floating-point numbers (e.g., FP16 or BF16).
[0098] For example, the index building unit 21 can convert the current query vector into query data in a preset format (e.g., FP16 format) and convert the candidate neighbor vector into candidate data in a preset format (e.g., FP16 format).
[0099] In step S3122, the first intermediate distance between the preset format query data and the preset format candidate data is determined.
[0100] According to the example embodiment, the first distance intermediate result can be an intermediate result that accounts for most of the computational cost in the matrix operation of the first distance. For example, the first distance intermediate result can be... As a result, for example, index building unit 21 can determine the first intermediate distance between the preset format query data and the preset format candidate data ( The index building unit 21 can force the use of single-precision floating-point numbers (FP32) in the accumulator inside matrix multiplication (GEMM) to prevent precision loss.
[0101] In step S3123, the first distance is determined based on the pre-stored modulus of the current query vector, the modulus of the candidate neighbor vectors, and the intermediate result of the first distance.
[0102] According to the example embodiment, the magnitude of the current query vector can be the length of the current query vector, for example, the Euclidean norm. The magnitude of the candidate neighbor vector can be the length of the candidate neighbor vector, for example, the Euclidean norm.
[0103] For example, the index building unit 21 can determine the magnitude of the current query vector and the magnitude of the candidate neighbor vectors based on the magnitude of the current query vector. The result. Afterwards, the index building unit 21 can be based on... Intermediate results of the first distance ( ), determine the first distance.
[0104] After obtaining the intermediate result of the first distance, the index building unit 21 can directly perform the broadcast addition of the squared term of the vector magnitude in the register file (i.e., calculate the...). The results are processed, and the Warp-level Top-k selection algorithm is immediately run. Only a small number of results with the smallest distance after filtering are written back, and the output is the final first distance result, avoiding writing the huge intermediate result matrix back to the video memory.
[0105] The technical solution of this application can fully utilize the computing power of GPU Tensor Cores by converting distance calculation into GEMM.
[0106] In step S313, the candidate neighbor vectors are sorted according to the first distance to determine the first candidate neighbor vector sequence of the current query vector.
[0107] According to the example embodiment, the first candidate neighbor vector sequence can be a sorted sequence of candidate vectors. For example, the index building unit 21 can sort the candidate neighbor vectors using an on-chip sorting algorithm to determine the first candidate neighbor vector sequence for the current query vector. The shared memory is reset as a candidate point temporary storage area, and the vector IDs and corresponding first distances of the first candidate neighbor vector sequence are stored using a SoA layout. Since the vector IDs and corresponding first distances are completely resident on-chip, the sorting process does not consume any video memory bandwidth and avoids global synchronization.
[0108] Optionally, step S313 may specifically involve: sorting the candidate neighbor vectors based on a first distance using either a bitonic sorting or a radix sorting based on shared memory, to determine the first candidate neighbor vector sequence for the current query vector.
[0109] According to the example implementation, shared memory-based bitonic sorting can be a comparative sorting network that recursively arranges candidate neighbor vectors into a "bitonic sequence" and then merges them. Shared memory-based radix sorting can be a non-comparative integer sorting algorithm that sorts each digit of the number (from least significant digit to most significant digit).
[0110] For example, the index building unit 21 can sort the candidate neighbor vectors based on the first distance, either using a bitonic sort based on shared memory or a radix sort based on shared memory, to determine the first candidate neighbor vector sequence for the current query vector.
[0111] In step S314, it is determined whether the first candidate neighbor vector sequence meets the preset stopping condition.
[0112] According to the example embodiment, the preset stopping condition can be a condition for stopping the expansion of the first candidate neighbor vector sequence. For example, the preset stopping condition can be that the first candidate neighbor vector sequence reaches a preset number of iterations or that no new candidate neighbor vectors are added to the first candidate neighbor vector sequence.
[0113] For example, the index building unit 21 can determine whether the first candidate neighbor vector sequence meets the preset stopping condition.
[0114] If the first candidate neighbor vector sequence meets the preset stopping condition, then proceed to step S315.
[0115] In step S315, the first candidate neighbor vector sequence is determined as the candidate neighbor vector sequence of the current query vector.
[0116] If the first candidate neighbor vector sequence meets the preset stopping condition, the index building unit 21 can determine the first candidate neighbor vector sequence as the candidate neighbor vector sequence of the current query vector.
[0117] If the first candidate neighbor vector sequence does not meet the preset stopping condition, then step S316 is executed. In step S316, the step of determining the candidate neighbor vector sequence of the current query vector of the i-th data subset is executed again.
[0118] If the first candidate neighbor vector sequence does not meet the preset stopping condition, the index building unit 21 can execute steps S311-S316 again until the first candidate neighbor vector sequence meets the preset stopping condition.
[0119] In step S320, all query vectors of the i-th data subset are traversed to determine the candidate neighbor vector sequence of all query vectors.
[0120] According to the example embodiment, the total query vectors can be all vector data of the i-th data subset. Each vector data corresponds to a sequence of candidate neighbor vectors. The index building unit 21 can traverse all query vectors in the i-th data subset and execute step S310 to determine the sequence of candidate neighbor vectors for all query vectors.
[0121] In step S330, on the GPU, based on preset pruning rules, the candidate neighbor vectors in the candidate neighbor vector sequence are pruned to obtain the adjacency list corresponding to the current query vector.
[0122] According to the example embodiment, the preset pruning rule can be a pruning rule for filtering candidate neighbor vectors. For example, the preset pruning rule can be a heuristic pruning rule (e.g., the MRNG pruning strategy of NSG, the edge selection rule of HNSW, the robust pruning rule of the Vamana algorithm, etc.). The adjacency list can record all other vector nodes (i.e., neighbor vectors) directly connected to each vector node in the graph structure.
[0123] For example, the index building unit 21 can prune the candidate neighbor vectors in the candidate neighbor vector sequence on the GPU based on preset pruning rules to obtain the adjacency list corresponding to the current query vector.
[0124] Optionally, see Figure 5 Step S330 may include steps S331-S333.
[0125] In step S331, the candidate neighbor vector sequence is grouped into a second preset number of candidate matrices.
[0126] According to the example embodiment, the candidate matrix can be a small matrix composed of several candidate neighbor vectors in the candidate neighbor vector sequence group. The second preset number can be the number of candidate matrices.
[0127] For example, the index building unit 21 can use a clustering algorithm to group the candidate neighbor vector sequence into a second preset number of candidate matrices. This configuration allows for grouping closely spaced candidate neighbor vectors into small matrices, reducing the processing time for subsequent pruning.
[0128] In step S332, the second distance between the candidate matrix and the known neighbors of the current query vector is determined.
[0129] According to the example embodiment, the known neighbors of the current query vector can be the already determined neighbor vectors of the current query vector. The second distance can be the distance between the candidate matrix and the known neighbors of the current query vector; for example, the second distance can be the Euclidean distance.
[0130] For example, index building unit 21 can determine the second distance between the candidate matrix and the known neighbors of the current query vector. Index building unit 21 can transform irregular vector distance calculations into regular matrix multiplication (GEMM).
[0131] In step S333, based on the preset pruning rules and according to the second distance, the candidate neighbor vectors in the candidate neighbor vector sequence are pruned to obtain the adjacency list corresponding to the current query vector.
[0132] According to the example embodiment, the index building unit 21 prunes the candidate neighbor vectors in the candidate neighbor vector sequence based on a preset pruning rule and according to the second distance, so as to obtain the adjacency list corresponding to the current query vector.
[0133] The index building unit 21 can prune the candidate neighbor vectors in the candidate neighbor vector sequence by comparing the second distance corresponding to each candidate matrix and using the MRNG pruning strategy based on NSG, so as to obtain the adjacency list corresponding to the current query vector.
[0134] When reading the adjacency list, the index building unit 21 no longer reads a single adjacency list by a single thread, but instead uses a Warp (32 threads) to collaboratively read a continuous slice of the adjacency list. This collaborative loading strategy ensures that access requests to global memory are merged.
[0135] In step S340, all query vectors of the i-th data subset are traversed to determine the adjacency list corresponding to all query vectors.
[0136] According to the example embodiment, each vector data corresponds to an adjacency list. The index building unit 21 can traverse all query vectors in the i-th shard data subset and execute step S330 to determine the adjacency list corresponding to all query vectors.
[0137] In step S350, on the GPU, reverse edges are inserted into the graph structure corresponding to the adjacency list of all query vectors to construct the local graph vector index of the i-th data subset.
[0138] According to the example embodiment, the graph structure corresponding to the adjacency list can be a graph structure composed of vector nodes and the edges of the vector nodes. An edge represents the connection between vector nodes; for example, an edge connects a vector node to its neighboring vectors. The edges in the graph structure have a direction. A reverse edge is an edge with the opposite direction to the original edge.
[0139] For example, index building unit 21 can insert the reverse edge corresponding to each edge into the graph structure corresponding to the adjacency list of all query vectors on the GPU to construct the local graph vector index of the i-th data subset. Index building unit 21 can allocate a buffer in shared memory to temporarily store the reverse edge requests generated by the current thread block. Index building unit 21 can first perform histogram statistics and prefix scan, then perform a global atomic addition only once in the full warp to reserve GPU memory space, and finally coordinate to merge and write the reverse edges, which can reduce the contention of atomic operations by up to 32 times and solve the bottleneck of atomic writing of reverse edges.
[0140] Through the above embodiments, the technical solution of this application can determine the candidate neighbor vector sequence of the current query vector in the i-th data shard subset. The technical solution of this application can traverse all query vectors in the i-th data shard subset to determine the candidate neighbor vector sequence of all query vectors. The technical solution of this application can prune the candidate neighbor vectors in the candidate neighbor vector sequence based on a preset pruning rule to obtain the adjacency list corresponding to the current query vector. The technical solution of this application can traverse all query vectors in the i-th data shard subset to determine the adjacency list corresponding to all query vectors. The technical solution of this application can insert reverse edges into the graph structure corresponding to the adjacency list of all query vectors to construct the local graph vector index of the i-th data shard subset.
[0141] The technical solution of this application improves the L2 cache hit rate by up to 58.7% compared with the traditional GPU porting solution through hotspot-aware shared memory optimization, effectively solving the bandwidth bottleneck.
[0142] Optionally, see Figure 6 Step S500 may include steps S510-S540.
[0143] In step S510, the navigation point of the i-th data subset is determined based on the local graph vector index of the i-th data subset.
[0144] According to the example embodiment, a navigation point can be the vector node in the local graph vector index that is farthest from the geometric center of the fragmented data subset. There can be multiple navigation points.
[0145] For example, index building unit 21 can determine the navigation point of the i-th data subset based on the local graph vector index of the i-th data subset. Index building unit 21 can determine a set of vector nodes in the local graph vector index that is farthest from the geometric center of the i-th data subset as navigation points.
[0146] In step S520, all local graph vector indices are traversed to obtain all navigation points.
[0147] According to the example embodiment, each local graph vector index corresponds to a navigation point. For example, the index building unit 21 can traverse all local graph vector indices to obtain all navigation points.
[0148] In step S530, the metagraph corresponding to all local graph vector indices is determined based on all navigation points.
[0149] According to the example embodiment, a meta-graph can be a graph structure that includes the connectivity relationships between various local graph vector indices. For example, the meta-graph can be a high-precision NSG graph structure or an HNSW graph structure.
[0150] For example, index building unit 21 can determine the metagraph corresponding to all local graph vector indices based on all navigation points. Index building unit 21 can load all navigation points into the GPU, establish connection relationships between local graph vector indices based on the navigation points, and thus obtain the metagraph.
[0151] In step S540, a hierarchical global graph vector index is constructed based on all local graph vector indices and metagraphs.
[0152] According to the example embodiment, the index construction unit 21 can construct a hierarchical global graph vector index based on all local graph vector indices and metagraphs. The index construction unit 21 can determine the global graph vector index based on all local graph vector indices and metagraphs. The index construction unit 21 can construct a hierarchical global graph vector index based on the global graph vector index and all local graph vector indices.
[0153] Optionally, see Figure 7 Step S540 may include steps S541-S542.
[0154] In step S541, the global graph vector index of a first preset number of fragmented data subsets is determined based on all local graph vector indices and metagraphs.
[0155] According to the example embodiment, the global graph vector index can be a graph structure that includes the connection relationships between various data subsets. For example, the index building unit 21 can determine the global graph vector index of a first preset number of data subsets based on all local graph vector indices and metagraphs. The index building unit 21 can establish the connection relationships of the data subsets based on all local graph vector indices and metagraphs, thereby obtaining the global graph vector index.
[0156] In step S542, a hierarchical global graph vector index is constructed based on the global graph vector index and all local graph vector indices.
[0157] According to the example embodiment, the index building unit 21 can construct a hierarchical global graph vector index based on the global graph vector index and the metagraph. The hierarchical global graph vector index includes a two-layer structure: an upper-layer global graph vector index and a lower-layer local graph vector index. The upper-layer global graph vector index is used to quickly locate the target fragmented data subset, while the lower-layer local graph vector index is used for accurate searching. The two-layer structure ensures global connectivity and maintains a very high recall rate.
[0158] Through the above embodiments, the technical solution of this application can determine the navigation point of the i-th data subset using the local graph vector index of the i-th data subset. The technical solution of this application can traverse all local graph vector indices to obtain all navigation points. The technical solution of this application can determine the metagraph corresponding to all local graph vector indices using all navigation points. The technical solution of this application can construct a hierarchical global graph vector index using all local graph vector indices and metagraphs.
[0159] The local graph vector index generated by the technical solution of this application does not change the underlying graph structure of NSG or HNSW, but only reconstructs the construction process. Therefore, the generated index is fully compatible with existing CPU query algorithms, and the query latency and recall are almost identical to the CPU-built version (with an error of less than 2%), making it a plug-and-play alternative.
[0160] The technical solution of this application, through optimized data layout, shared memory settings, and real-time write-back strategy, achieves peak memory usage during the construction process of hierarchical global graph vector index that is less than 10% higher than the CPU baseline, demonstrating good economic efficiency.
[0161] According to another aspect of this application, this application also provides a non-volatile computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is capable of implementing the GPU-based graph vector index construction method as described above.
[0162] According to another aspect of this application, this application also provides an electronic device, including: one or more processors; and a storage device for storing one or more programs, which, when executed by one or more processors, enable the one or more processors to implement the GPU-based graph vector index construction method as described above.
[0163] According to another aspect of this application, this application also provides a computer program product, including: a computer program stored on a computer-readable storage medium; the computer program includes program instructions that, when executed by a computer, cause the computer to perform the GPU-based graph vector index construction method as described above.
[0164] Finally, it should be noted that the above description is merely a preferred embodiment of this application and is not intended to limit this application. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art can still modify the technical solutions of the foregoing embodiments or make equivalent substitutions for some of the technical features. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A GPU-based graph vector index construction method, characterized in that, The method includes: The original dataset is divided into fragments based on a clustering algorithm to obtain a first preset number of fragmented data subsets; Send the i-th data subset to the GPU, where i is a positive integer; Construct the local graph vector index of the i-th data subset on the GPU; Send the (i+1)th data fragment to the GPU until all local graph vector indices are obtained; Based on all the local graph vector indices, construct a hierarchical global graph vector index; The step of constructing the local graph vector index of the i-th data subset on the GPU includes: On the GPU, the step of determining the candidate neighbor vector sequence of the current query vector of the i-th data subset is performed; Traverse all query vectors of the i-th data subset to determine the candidate neighbor vector sequence of all query vectors; In the GPU, based on preset pruning rules, the candidate neighbor vectors in the candidate neighbor vector sequence are pruned to obtain the adjacency list corresponding to the current query vector; Traverse all query vectors of the i-th data subset to determine the adjacency list corresponding to all query vectors; In the GPU, reverse edges are inserted into the graph structure corresponding to the adjacency list of all query vectors to construct the local graph vector index of the i-th data subset.
2. The method according to claim 1, characterized in that, The step of determining the candidate neighbor vector sequence of the current query vector for the i-th data subset includes: Based on the current graph structure corresponding to the current query vector in the i-th data subset, expand the candidate neighbor vector of the current query vector; Determine the first distance between the current query vector and the candidate neighbor vector; Based on the first distance, the candidate neighbor vectors are sorted to determine the first candidate neighbor vector sequence of the current query vector; Determine whether the first candidate neighbor vector sequence satisfies the preset stopping condition; If so, then the first candidate neighbor vector sequence is determined to be the candidate neighbor vector sequence of the current query vector; If not, repeat the step of determining the candidate neighbor vector sequence of the current query vector of the i-th data subset.
3. The method according to claim 2, characterized in that, Determining the first distance between the current query vector and the candidate neighbor vector includes: The current query vector is converted into query data in a preset format, and the candidate neighbor vector is converted into candidate data in a preset format. Determine the first intermediate distance between the preset format query data and the preset format candidate data; The first distance is determined based on the pre-stored magnitude of the current query vector, the magnitude of the candidate neighbor vector, and the intermediate result of the first distance.
4. The method according to claim 2, characterized in that, The step of sorting the candidate neighbor vectors according to the first distance to determine the first candidate neighbor vector sequence of the current query vector includes: Based on the first distance, the candidate neighbor vectors are sorted using either a bitone sort based on shared memory or a radix sort based on shared memory to determine the first candidate neighbor vector sequence for the current query vector.
5. The method according to claim 1, characterized in that, The step of pruning the candidate neighbor vectors in the candidate neighbor vector sequence based on preset pruning rules to obtain the adjacency list corresponding to the current query vector includes: The candidate neighbor vector sequence is grouped into a second preset number of candidate matrices; Determine the second distance between the candidate matrix and the known neighbors of the current query vector; Based on the preset pruning rules, the candidate neighbor vectors in the candidate neighbor vector sequence are pruned according to the second distance to obtain the adjacency list corresponding to the current query vector.
6. The method according to claim 1, characterized in that, The step of constructing a hierarchical global graph vector index based on all the local graph vector indices includes: Based on the local graph vector index of the i-th data subset, determine the navigation point of the i-th data subset; Traverse all the local graph vector indices to obtain all navigation points; Based on all the navigation points, determine the metagraph corresponding to all the local graph vector indices; The hierarchical global graph vector index is constructed based on all the local graph vector indices and the metagraph.
7. The method according to claim 6, characterized in that, The step of constructing the hierarchical global graph vector index based on all the local graph vector indices and the metagraph includes: Based on all the local graph vector indices and the metagraph, determine the global graph vector index of the first preset number of fragmented data subsets; The hierarchical global graph vector index is constructed based on the global graph vector index and all the local graph vector indices.
8. A GPU-based graph vector index construction device, characterized in that, The device includes: Based on a clustering algorithm, the original dataset is divided into pieces to obtain a first preset number of piece data subsets. A module that sends the i-th data subset to the GPU, where i is a positive integer; The module that constructs the local graph vector index of the i-th data subset in the GPU; The module that sends the (i+1)th data fragment to the GPU until all local graph vector indices are obtained; A module for constructing a hierarchical global graph vector index based on all the local graph vector indices; Specifically, constructing the local graph vector index of the i-th data subset on the GPU includes: In the GPU, a sequence of candidate neighbor vectors for the current query vector of the i-th data subset is determined; Traverse all query vectors of the i-th data subset to determine the candidate neighbor vector sequence of all query vectors; In the GPU, based on preset pruning rules, the candidate neighbor vectors in the candidate neighbor vector sequence are pruned to obtain the adjacency list corresponding to the current query vector; Traverse all query vectors of the i-th data subset to determine the adjacency list corresponding to all query vectors; In the GPU, reverse edges are inserted into the graph structure corresponding to the adjacency list of all query vectors to construct the local graph vector index of the i-th data subset.
9. A non-volatile computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the GPU-based graph vector index construction method as described in any one of claims 1-7.