Vector retrieval methods, devices, equipment, media, and products based on heterogeneous storage
Patent Information
- Application Number
- CN202610689665.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-19
- Publication Date
- 2026-08-14
AI Technical Summary
然而,目前GPU的视频随机存取存储器(Video Random AccessMemory,VRAM,简称显存)的容量难以容纳大规模数据集,若直接将向量数据进行量化处理后存储于显存中,则难以保证检索精度,检索结果不准确
[0009]根据本发明的另一方面,提供了一种计算机程序产品,所述计算机程序产品包括计算机程序,所述计算机程序在被处理器执行时实现本发明任一实施例所述的基于异构存储的向量检索方法。
Smart Images

Figure CN122570798A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, to technologies such as memory, graph data, and databases, and particularly to a vector retrieval method, apparatus, device, medium, and product based on heterogeneous storage. Background Technology
[0002] With the explosive growth of applications such as vector databases, recommendation systems, and multimodal retrieval, there is often a need for fast (e.g., millisecond-level) retrieval of high-dimensional floating-point vectors with a large number of data points (e.g., billions), such as Approximate Nearest Neighbor (ANN) retrieval.
[0003] Graphics Processing Units (GPUs) have become the preferred hardware for accelerating ANN retrieval due to their massively parallel computing capabilities. However, the current video random access memory (VRAM) of GPUs is insufficient to accommodate large-scale datasets. If vector data is directly quantized and stored in VRAM, it is difficult to guarantee retrieval accuracy, resulting in inaccurate retrieval results. Summary of the Invention
[0004] This invention provides a vector retrieval method, apparatus, device, storage medium, and product based on heterogeneous storage, which can optimize existing vector data-based retrieval schemes.
[0005] According to one aspect of the present invention, a vector retrieval method based on heterogeneous storage is provided, comprising: The GPU sends the target node identifier of the current candidate node in the node queue to the CPU. The node queue includes candidate nodes sorted by a first distance. The first distance is the distance between the vector node and the query vector, which is calculated by the GPU using the quantization encoding of the vector nodes in the video memory. The vector node belongs to the vector dataset to be retrieved. The current candidate node is the first number of candidate nodes in the node queue with the smallest first distance. The CPU moves the target original vector data corresponding to the target node identifier from the host-side storage space to the video memory. The GPU uses the original target vector data to calculate the second distance between the current candidate node and the query vector. The GPU determines the vector retrieval result based on the second distance between the current candidate node and the query vector.
[0006] According to another aspect of the present invention, a vector retrieval device based on heterogeneous storage is provided, comprising: A node identifier sending module is used to send the target node identifier of the current candidate node in the node queue to the central processing unit (CPU) via a graphics processing unit (GPU). The node queue includes candidate nodes sorted according to a first distance, where the first distance is the distance between a vector node and a query vector calculated by the GPU using the quantization encoding of vector nodes in video memory. The vector node belongs to the vector dataset to be retrieved, and the current candidate node is the first number of candidate nodes in the node queue with the smallest first distance. The data transfer module is used to transfer the target original vector data corresponding to the target node identifier from the host-side storage space to the video memory via the CPU; The second distance calculation module is used to calculate the second distance between the current candidate node and the query vector using the target original vector data via the GPU. The retrieval result determination module is used to determine the vector retrieval result by means of the GPU based on the second distance between the current candidate node and the query vector.
[0007] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: At least two processors; And a memory that is communicatively connected to the at least two processors; The memory stores a computer program that can be executed by the at least two processors, and the computer program is executed by the at least two processors to enable the at least two processors to execute the vector retrieval method based on heterogeneous storage as described in any embodiment of the present invention.
[0008] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the vector retrieval method based on heterogeneous storage as described in any embodiment of the present invention.
[0009] According to another aspect of the present invention, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the vector retrieval method based on heterogeneous storage as described in any embodiment of the present invention.
[0010] The vector retrieval scheme based on heterogeneous storage in this invention stores the quantized encoding of vector nodes in video memory and the original vector data of vector nodes in host-side storage. The GPU uses the quantized encoding in video memory to calculate the coarse distance between the vector node and the query vector, and sends the identifiers of a certain number of nodes with smaller distances in a node queue sorted according to the coarse distance to the CPU. This allows the CPU to move the corresponding original vector data from the host-side storage to video memory. The GPU can then calculate the precise distance between the vector node and the query vector based on the original vector data, and determine the vector retrieval result based on the precise distance. This fully utilizes the collaborative work of the GPU and CPU, effectively saving video memory storage space while ensuring the accuracy and precision of the vector retrieval results.
[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention, 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 the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0013] Figure 1 This is a flowchart of a vector retrieval method based on heterogeneous storage provided according to an embodiment of the present invention; Figure 2 This is a flowchart of another vector retrieval method based on heterogeneous storage provided according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of a vector retrieval device based on heterogeneous storage according to an embodiment of the present invention; Figure 4 This is a schematic diagram of the structure of an electronic device that implements the vector retrieval method based on heterogeneous storage according to an embodiment of the present invention. Detailed Implementation
[0014] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0015] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0016] Figure 1 This is a flowchart illustrating a vector retrieval method based on heterogeneous storage according to an embodiment of the present invention. This embodiment is applicable to vector retrieval scenarios, specifically vector retrieval in applications related to vector databases, recommendation systems, and multimodal retrieval. This method can be executed by a vector retrieval device based on heterogeneous storage, which can be implemented in hardware and / or software. This heterogeneous storage-based vector retrieval device can be configured in an electronic device, such as a computer or server. Figure 1 As shown, the method includes: Step 101: The target node identifier of the current candidate node in the node queue is sent to the central processing unit (CPU) through the graphics processing unit (GPU). The node queue includes candidate nodes sorted according to the size of a first distance. The first distance is the distance between the vector node and the query vector, which is calculated by the GPU using the quantization encoding of the vector nodes in the video memory. The vector node belongs to the vector dataset to be retrieved. The current candidate node is the first number of candidate nodes in the node queue with the smallest first distance.
[0017] For example, the dataset of vectors to be retrieved includes multiple vectors to be retrieved (denoted as retrieval vectors). Each retrieval vector can be considered a vector node, and each vector node is associated with a node identifier. The retrieval vectors can be vectors from a vector database or vectors from a recommendation system; their specific meaning is not limited. For example, they could be vectors constructed based on the features of videos in a recommendation system. The query vector is the vector that needs to be matched for retrieval. It can be a vector constructed based on query information or search information, such as when a user inputs a search statement or search keywords in natural language, converting the search statement or search keywords into a vector to obtain the query vector.
[0018] In this embodiment of the invention, the vector retrieval method is not limited; for example, it can be ANN retrieval. Assuming a dataset consisting of N D-dimensional vectors (equivalent to the dataset of vectors to be retrieved), the goal of ANN retrieval is usually to find the K nearest vectors to a query vector in the dataset. It allows for a certain probability of returning non-exact nearest neighbors in exchange for lower computational cost. Common distance metrics include Euclidean distance and inner product.
[0019] For example, the precision and length of the vector to be retrieved are not limited; for instance, it can be a 768-dimensional vector with a precision of float32. The dataset typically contains a large number of vectors; for example, 1 billion vectors would require approximately 3TB of storage space. However, most current GPU memory has a maximum capacity of only about 80GB, which is insufficient to accommodate such a large dataset. If the dataset is stored in host-side storage and the CPU performs the retrieval, the throughput is low, the efficiency is poor, and it is difficult to meet the needs of fast retrieval scenarios. If the vector data is directly quantized and stored in GPU memory, it is difficult to guarantee retrieval accuracy, resulting in inaccurate retrieval results. In this embodiment of the invention, a heterogeneous storage scheme is proposed. The original vector data to be retrieved is pre-quantized to obtain quantized encoding, which is stored in GPU memory. The original vector data is stored in host-side storage, and the GPU and CPU work together to complete the retrieval process, resulting in efficient and accurate retrieval results. Among them, host-side storage space can be, for example, Dynamic Random Access Memory (DRAM), Solid State Drive (SSD), DRAM plus SSD (e.g., hot nodes are cached in DRAM, and cold nodes are read asynchronously from SSD), and Compute Express Link (CXL) memory expansion, etc.
[0020] Optionally, the quantization encoding is obtained based on product quantization or random binary quantization.
[0021] Product Quantization (PQ) divides a D-dimensional vector into M subspaces. Each subspace is independently clustered to obtain 256 centroids (codebooks), and the nearest centroid ID of each segment is represented by an 8-bit encoding. The original vector (4D bytes) is compressed to M bytes, with a compression ratio of 4D / M. A typical setting is M = D / 4, resulting in a compression ratio of 16. After quantization, the storage overhead can be reduced to 1 / 16 of the original data.
[0022] Randomized Binary Quantization (RaBitQ) projects the centered vector onto a unit hypersphere, quantizing each dimension to 1 bit and storing it in packed uint8 (ceil(D / 8) bytes), achieving a compression ratio of 32. After quantization, the storage overhead can be reduced to 1 / 32 of the original data.
[0023] Optionally, quantization encoding can also be based on other quantization methods, such as Scalar Quantization (SQ8), Inverted File with Product Quantization (IVFPQ), Optimized Product Quantization (PQ), and 4-bit quantization.
[0024] For example, the distance between a vector node and a query vector is calculated using the quantization encoding of vector nodes in GPU memory. This distance is denoted as the first distance, which can be understood as a coarse or approximate distance between the vector node and the query vector. For instance, the query vector is quantized using the same quantization method as the vector node to obtain its quantization encoding, and the distance between the quantization encoding of the vector node and the quantization encoding of the query vector is calculated. For each vector node in the dataset to be retrieved, the corresponding first distance can be calculated individually or in batches, and a node queue can be constructed based on the first distance. For example, after calculating the first distance for all vector nodes, the node queue can be constructed in ascending order of the first distance; alternatively, the first distance for each vector node can be calculated in batches, and the node queue can be dynamically updated based on the calculated first distances. The vector nodes included in the node queue are denoted as candidate nodes.
[0025] For example, in this step, a candidate node with the smallest first distance from the current node queue is selected as the current candidate node, and the node identifier associated with the current candidate node is recorded as the target node identifier. The first number can be set according to actual needs. For example, if the node queue construction has considered the first distance between all vector nodes and the query vector, the first number can be greater than the target number, where the target number is the number of elements required in the search results, such as K in the aforementioned ANN search. The first number could, for example, be twice the target number, allowing the original vector data for calculating the second distance to be obtained all at once. If the node queue is dynamically updated, the first number can be less than the target number, thus enabling the batch transfer of the original vector data. The original vector data after the second distance calculation can be cleared from the GPU memory, saving GPU memory space. The GPU sends the target node identifier to the CPU to instruct the CPU to transfer the corresponding original vector data to the GPU memory.
[0026] Step 102: The CPU moves the target original vector data corresponding to the target node identifier from the host-side storage space to the video memory.
[0027] For example, after receiving the target node identifier, the CPU finds the original vector data of the vector node corresponding to the target node identifier in the host-side storage space, records it as the target original vector data, and moves the target original vector data to the video memory.
[0028] Step 103: Calculate the second distance between the current candidate node and the query vector using the target original vector data via the GPU.
[0029] For example, the GPU can use the original target vector data to calculate the distance between the current candidate node and the query vector, denoted as the second distance. This can be understood as the precise distance between the vector node and the query vector. For instance, for a given current candidate node, the distance between the original target vector data of that current candidate node and the query vector is calculated to obtain the second distance corresponding to that current candidate node.
[0030] Step 104: The GPU determines the vector retrieval result based on the second distance between the current candidate node and the query vector.
[0031] For example, if the original vector data of all vector nodes requiring second distance calculation has been obtained and the second distance calculation has been completed, the nodes can be sorted in ascending order according to the second distance, and the vector nodes with the highest number of target nodes selected can be used as the vector retrieval results. If only a portion of the original vector data of the vector nodes requiring second distance calculation is obtained and the second distance calculation is completed each time, the retrieval result set can be dynamically maintained and updated. For example, each update can retain the vector nodes with the smallest number of target nodes in the retrieval result set, and the vector retrieval result can be determined based on the last updated retrieval result set.
[0032] The vector retrieval method based on heterogeneous storage in this invention stores the quantized encoding of vector nodes in video memory and the original vector data of vector nodes in host-side storage. The GPU uses the quantized encoding in video memory to calculate the coarse distance between the vector node and the query vector, and sends the identifiers of a certain number of nodes with smaller distances in a node queue sorted according to the coarse distance to the CPU. This allows the CPU to move the corresponding original vector data from the host-side storage to video memory. The GPU can then calculate the precise distance between the vector node and the query vector based on the original vector data, and determine the vector retrieval result based on the precise distance. This method can fully utilize the collaborative work of the GPU and CPU, effectively saving video memory storage space while ensuring the accuracy and precision of the vector retrieval results.
[0033] In some embodiments, the host-side storage space includes a pinned memory pool, which can be pre-allocated and supports Direct Memory Access (DMA) direct transfer. A Compute Unified Device Architecture (CUDA) stream enables the CPU as the producer to concurrently move the target raw vector data corresponding to the target node identifier to the pinned memory pool, while the GPU as the consumer asynchronously receives the target raw vector transferred via DMA and performs related calculations. This allows for deep temporal overlap between transmission and computation, eliminating GPU idle time waiting for I / O and further improving retrieval efficiency.
[0034] Among them, the page-locked (pinned) host memory allocated by cudaHostAlloc supports direct DMA transfers, and the host-to-device (H2D) bandwidth can reach the theoretical peak of PCIe (approximately 64 GB / s for PCIe 4.0×16), which is 1.5 to 2 times faster than pageable memory. CUDA streams support time overlap between H2D transfers and GPU kernel execution.
[0035] In some embodiments, in order to reduce the amount of raw vector data to be transported in batches and improve retrieval efficiency, a graph is constructed based on the dataset of vectors to be retrieved to obtain a graph structure, which can be called a vector neighbor relationship graph or an index topology graph. The vectors to be retrieved are constructed as nodes in the graph, and the edges between nodes represent the neighbor relationship. Each node has a corresponding graph neighbor table, which includes neighbor nodes that have edges with the current node. Therefore, the graph neighbor table corresponding to each vector node can also be stored in the host-side storage space. In addition to transporting the target raw vector data corresponding to the target node identifier to the video memory, the target graph neighbor table corresponding to the target node identifier can also be transported to realize the batch calculation of the first distance and the dynamic update of the node queue.
[0036] For example, graph structures can be constructed using graph indexing algorithms. The specific graph indexing algorithm used can be selected according to actual needs, such as Hierarchical Navigable Small-World (HNSW), Vamana, Navigating Spreading-out Graph (NSG), and Space Partition Tree and Graph (SPTAG). Taking HNSW as an example, the maximum out-degree R of the graph is typically between 32 and 128. During retrieval, it starts from a fixed starting point (medoid) and performs a greedy search along the edges, expanding the neighbors of the current best candidate node at each step until no closer node can be found. The core of the Vamana algorithm's graph construction is the Robust Pruning strategy, which maintains a candidate set of size L for each node. Alpha-pruning ensures the connectivity and small-world properties of the graph, allowing the greedy search to converge with a path length of O(log N).
[0037] In some embodiments, the method further includes: transferring the target graph neighbor table corresponding to the target node identifier from the host-side storage space to the video memory via the CPU; obtaining the unvisited neighbor nodes corresponding to the current candidate node via the GPU based on the target graph neighbor table, calculating the first distance corresponding to the unvisited neighbor nodes, and updating the node queue based on the first distance corresponding to the unvisited neighbor nodes, wherein the unvisited neighbor nodes are vector nodes among the neighbor nodes corresponding to the current candidate node whose first distance has not been calculated.
[0038] For example, after the CPU returns the target raw vector data and the target graph neighbor table each time, the GPU, in addition to calculating the second distance corresponding to the target raw vector data, also obtains the unvisited neighbor nodes corresponding to the current candidate nodes based on the target graph neighbor table. For example, it reads each neighbor node contained in the target graph neighbor table, determines whether the neighbor node has had its first distance calculated, and if it has not, it is determined to be an unvisited neighbor node. The corresponding first distance is then calculated, that is, a coarse distance between the unvisited neighbor node and the query vector is calculated based on the quantization encoding of the unvisited neighbor node in video memory, and the node queue is updated according to the first distance corresponding to the unvisited neighbor node, such as inserting it into the node queue according to the magnitude of the first distance corresponding to the unvisited neighbor node. For example, the node queue has a maximum length. For a certain unvisited neighbor node, if its corresponding first distance is less than the first distance corresponding to any candidate node in the node queue, it can be inserted into the node queue; if its corresponding first distance is greater than the first distance corresponding to all candidate nodes in the node queue, the unvisited neighbor node can be discarded.
[0039] In some embodiments, the host-side storage space includes a fixed memory pool. A unified computing device architecture is used to concurrently move the target original vector data corresponding to the target node identifier and the target graph neighbor table to the fixed memory pool, with the CPU acting as the producer. The GPU, acting as the consumer, asynchronously receives the target original vector and the target graph neighbor table transferred via Direct Memory Access (DMA) and performs related calculations. This allows the transfer of the original vector data and the target graph neighbor table to deeply overlap with the computation in time, eliminating idle time for GPU waiting for I / O and further improving retrieval efficiency.
[0040] In some embodiments, determining the vector retrieval result by the GPU based on the second distance between the current candidate node and the query vector includes: updating the retrieval result set by the GPU based on the second distance between the current candidate node and the query vector, wherein the retrieval result set includes at most a second number of vector nodes with the smallest second distance; in response to the node identifiers of all candidate nodes in the node queue being sent to the CPU, determining the vector retrieval result based on the most recently updated retrieval result set. Thus, the retrieval result set can be dynamically updated, retaining a certain number of vector nodes with the smallest second distance, saving storage space. The second number can be determined based on the target number, such as being equal to the target number.
[0041] Figure 2 This is a flowchart of another vector retrieval method based on heterogeneous storage provided by an embodiment of the present invention. This embodiment is an optimization based on the above-mentioned optional embodiments. Figure 2 As shown, the method includes: Step 201: Calculate the third distance between the query vector and the candidate search nodes using the original vector data of the third number of candidate search nodes in the GPU memory. The candidate search node is the vector node closest to the target centroid, and the target centroid is the third number of centroids obtained by clustering the dataset of vectors to be retrieved.
[0042] Traditional graph indexing techniques use a single medoid (global center node) as the starting point, which is inefficient for unevenly distributed datasets. This invention addresses this by using K-means clustering during the construction phase to find K (third-order) evenly distributed representative starting points, i.e., candidate nodes for search starting points, which can be denoted as candidate search nodes. For example, for the vector dataset to be retrieved, K centroids are determined based on K-means clustering. For each centroid, the nearest vector to the current centroid is found in the dataset, thus determining the corresponding candidate search node. The original vector data of the candidate search node is stored in GPU memory, or the node ID of the candidate search node is stored in GPU memory. The corresponding original vector data is then retrieved from the host-side storage space based on the node ID.
[0043] In this embodiment of the invention, a suitable quantization encoding method can be selected according to actual needs. For PQ quantization, the compression ratio is 16, and there is no multiplication in the approximate distance calculation. It involves M lookup table accumulations and can be used as a general solution, balancing accuracy and storage. For RaBitQ quantization, the compression ratio is 32. It uses bitwise operations and compensation factors in the approximate distance calculation, making it suitable for very large datasets and providing more extreme compression and storage.
[0044] For example, this embodiment uses PQ quantization encoding as an example. PQ training is performed on the dataset of vectors to be retrieved. A codebook is obtained through subspace clustering. All vectors to be retrieved in the dataset are quantized and encoded, and written to corresponding files, such as {prefix}_pq_pivots.bin and {prefix}_pq_compressed.bin, and stored in GPU memory. A graph is constructed using Vaman to obtain the graph structure, which is then merged with the original vector data and written to disk sectors, such as {prefix}_disk.index (metadata) and {prefix}_disk.index (data sectors). A third number of candidate search nodes are written to a file, such as {prefix}_medoids.bin, and stored in GPU memory.
[0045] For example, a query vector is obtained, which can be multiple vectors indicated by a batch query request. After obtaining the query vector, the GPU can first initialize and construct a PQ distance lookup table. For each query q, the distance between it and the centroids of all PQ subspaces is calculated. Subsequently, the search starting point is calculated. If there is no third number of candidate search nodes, a preset vector node can be used as the search starting point. If there is, the original vector data of the third number of candidate search nodes are used to calculate the third distance between the query vector and each candidate search node. The third distance is an accurate distance, not a coarse quantized approximation, which can eliminate the error in the selection of the starting point.
[0046] Step 202: Determine the starting vector node to be added to the node queue based on the third distance, and create the node queue.
[0047] For example, the candidate search node with the smallest third distance is determined as the search starting point, that is, the first vector node added to the node queue, denoted as the starting vector node, and added to the node queue. The first distance between the starting vector node and the query vector can be calculated to facilitate the sorting of candidate nodes in the subsequent node queue.
[0048] Step 203: Send the target node identifier of the current candidate node in the node queue to the CPU via the GPU.
[0049] Among them, the current candidate node is the candidate node with the smallest distance in the first number of nodes in the node queue.
[0050] For example, when the node queue is first created, it only includes the starting vector node. The starting vector node can be directly identified as the current candidate node, and the corresponding target node identifier can be sent to the CPU. As the number of candidate nodes in the node queue increases, the first number of current candidate nodes can be identified each time, realizing the batch sending of target node identifiers and improving retrieval efficiency. Optionally, candidate nodes that have already sent target node identifiers to the CPU can be removed from the node queue.
[0051] For example, if the query vector can be multiple vectors indicating a batch query request, that is, there are multiple query vectors, then the target node identifiers of the current candidate nodes in the node queues corresponding to the multiple query vectors can be sent in parallel.
[0052] Step 204: The CPU moves the target node identifier's original vector data and the target graph neighbor table from the host-side storage space to the video memory.
[0053] For example, if there are multiple query vectors, the target node identifiers corresponding to different query vectors may be duplicated. After the CPU performs deduplication, it obtains a list of node identifiers consisting of nodes that need to acquire data. This triggers the backend to read the corresponding target original vector data and the target graph neighbor table, which can be written into a fixed memory pool and asynchronously transmitted to the video memory via H2D. During the H2D transmission, the GPU can execute other streams in parallel.
[0054] Optionally, the raw vector data can be stored in float16 (half precision), further saving DRAM and SSD bandwidth and storage space, halving the storage footprint with minimal loss of precision.
[0055] Optionally, in the host-side storage space, the data adopts a sector-aligned format. Each storage node contains raw vector data, neighbor counts, and a graph neighbor table, which are tightly packed in a fixed-length slot. This supports multiple nodes packed into a single sector (small node mode) or a single node spanning multiple sectors (large node mode).
[0056] Step 205: Calculate the second distance between the current candidate node and the query vector using the original target vector data via GPU, and update the retrieval result set.
[0057] After the original target vector data has been transferred to the GPU memory, the GPU can calculate the precise distance between each current candidate node and the query vector, i.e., the second distance, and update the retrieval result set based on the second distance.
[0058] Step 206: Obtain the unvisited neighbor nodes corresponding to the current candidate node through the GPU based on the target graph neighbor table, calculate the first distance corresponding to the unvisited neighbor nodes, and update the node queue based on the first distance corresponding to the unvisited neighbor nodes.
[0059] The unvisited neighbor node is a vector node among the neighbor nodes of the current candidate node that has not had its first distance calculated.
[0060] For example, assuming the maximum length of the node queue is a preset length, if the current length has not been reached, unvisited neighbor nodes can be directly inserted into the node queue. During insertion, the nodes are sorted according to the size of the first distance. If the length has been reached, the first distance corresponding to the unvisited neighbor node is compared with the first distance corresponding to the existing candidate nodes in the node queue. Based on the comparison result, it is determined whether to directly insert the unvisited neighbor node into the node queue. If the first distance corresponding to the unvisited neighbor node is greater than the first distance corresponding to all candidate nodes in the node queue, the unvisited neighbor node can be discarded.
[0061] Step 207: Determine whether the node identifiers of all candidate nodes in the node queue have been sent to the CPU. If yes, proceed to step 208; otherwise, return to step 203.
[0062] For example, if all the node identifiers of the candidate nodes in the node queue have been sent to the CPU, if the node queue is empty, it can be determined that the query is complete and step 208 is executed; otherwise, return to step 203, redetermine the current candidate nodes, and continue to send the next batch of target node identifiers.
[0063] Step 208: Determine the vector retrieval results based on the most recently updated retrieval result set.
[0064] For example, after the query is completed, the vector nodes in the search result set are sorted according to the second distance to obtain the vector search results.
[0065] The vector retrieval method based on heterogeneous storage in this invention pre-quantizes and encodes the vector dataset to be retrieved. The quantized encoding of vector nodes is stored in GPU memory, while the original vector data of the vector nodes is stored in host-side storage. Furthermore, the GPU memory stores the nearest candidate search nodes corresponding to multiple centroids obtained through clustering. After obtaining the query vector, the search starting point is determined more dynamically and accurately based on the precise distance between the query vector and each candidate search node. The GPU uses the quantized encoding in GPU memory to calculate the approximate distance between the vector node and the query vector, and sends the identifiers of a certain number of nodes with smaller distances in the node queue sorted according to this approximate distance to the CPU. This allows the CPU to move the corresponding original vector data and graph neighbor table from host-side storage to GPU memory. The GPU can then calculate the precise distance between the vector node and the query vector based on the original vector data, determine the vector retrieval result based on this precise distance, and dynamically update the node queue. This fully utilizes the collaborative work of the GPU and CPU, effectively saving GPU memory storage space while ensuring the accuracy and precision of the vector retrieval results, and further improving retrieval efficiency.
[0066] Figure 3 This is a schematic diagram of the structure of a vector retrieval device based on heterogeneous storage according to an embodiment of the present invention. Figure 3 As shown, the device includes: The node identifier sending module 301 is used to send the target node identifier of the current candidate node in the node queue to the central processing unit (CPU) through the graphics processing unit (GPU). The node queue includes candidate nodes sorted according to a first distance. The first distance is the distance between the vector node and the query vector, which is calculated by the GPU using the quantization encoding of the vector nodes in the video memory. The vector node belongs to the vector dataset to be retrieved. The current candidate node is the first number of candidate nodes in the node queue with the smallest first distance. Data transfer module 302 is used to transfer the target original vector data corresponding to the target node identifier from the host-side storage space to the video memory via the CPU; The second distance calculation module 303 is used to calculate the second distance between the current candidate node and the query vector using the target original vector data through the GPU; The retrieval result determination module 304 is used to determine the vector retrieval result by means of the GPU based on the second distance between the current candidate node and the query vector.
[0067] The vector retrieval device based on heterogeneous storage in this invention stores the quantized encoding of vector nodes in video memory and the original vector data of vector nodes in host-side storage. The GPU uses the quantized encoding in video memory to calculate the coarse distance between the vector node and the query vector, and sends the identifiers of a certain number of nodes with smaller distances in a node queue sorted according to the coarse distance to the CPU. This allows the CPU to move the corresponding original vector data from the host-side storage to video memory. The GPU can then calculate the precise distance between the vector node and the query vector based on the original vector data, and determine the vector retrieval result based on the precise distance. This fully utilizes the collaborative work of the GPU and CPU, ensuring the accuracy and precision of the vector retrieval results while effectively saving video memory storage space.
[0068] Optional, also includes: The graph neighbor table transport module is used to transport the target graph neighbor table corresponding to the target node identifier from the host-side storage space to the video memory via the CPU. The queue update module is used to obtain the unvisited neighbor nodes corresponding to the current candidate node through the GPU according to the target graph neighbor table, calculate the first distance corresponding to the unvisited neighbor nodes, and update the node queue according to the first distance corresponding to the unvisited neighbor nodes, wherein the unvisited neighbor nodes are vector nodes among the neighbor nodes corresponding to the current candidate node whose first distance has not been calculated.
[0069] Optionally, determining the vector retrieval result by the GPU based on the second distance between the current candidate node and the query vector includes: updating the retrieval result set by the GPU based on the second distance between the current candidate node and the query vector, wherein the retrieval result set includes at most a second number of vector nodes with the smallest second distance; in response to the node identifiers of all candidate nodes in the node queue being sent to the CPU, determining the vector retrieval result based on the most recently updated retrieval result set.
[0070] Optionally, the host-side storage space includes a fixed memory pool; through a unified computing device architecture flow, the CPU acts as a producer to concurrently move the target original vector data corresponding to the target node identifier and the target graph neighbor table to the fixed memory pool, and the GPU acts as a consumer to asynchronously receive the target original vector and the target graph neighbor table transferred through direct memory access DMA and perform related calculations.
[0071] Optionally, the device may also include: The third distance calculation module is used to calculate the third distance between the query vector and the candidate search nodes by using the original vector data of the third number of candidate search nodes in the GPU memory. The candidate search nodes are the vector nodes closest to the target centroid, and the target centroid is the third number of centroids obtained by clustering the dataset of vectors to be retrieved. The starting vector node determination module is used to determine the first vector node to be added to the node queue based on the third distance.
[0072] Optionally, the quantization encoding is obtained based on product quantization or random binary quantization.
[0073] The vector retrieval device based on heterogeneous storage provided in the embodiments of the present invention can execute the vector retrieval method based on heterogeneous storage provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0074] Figure 4 A schematic diagram of an electronic device that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0075] like Figure 4 As shown, the electronic device 10 includes at least two processors 11 (CPU and GPU are not distinguished in the figure, but are collectively referred to as processors), and memory such as read-only memory (ROM) 12 and random access memory (RAM) 13, which are communicatively connected to the at least two processors 11. The memory stores computer programs that can be executed by the at least two processors. The processors 11 can perform various appropriate actions and processes based on the computer programs stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processors 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0076] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0077] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as vector retrieval methods based on heterogeneous memory.
[0078] In some embodiments, the heterogeneous storage-based vector retrieval method can be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the heterogeneous storage-based vector retrieval method described above can be performed. Alternatively, in other embodiments, processor 11 can be configured to perform the heterogeneous storage-based vector retrieval method by any other suitable means (e.g., by means of firmware).
[0079] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0080] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0081] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0082] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0083] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0084] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0085] This disclosure provides a computer program product, including a computer program that, when executed by a processor, implements the vector retrieval method based on heterogeneous storage provided in the above embodiments.
[0086] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0087] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A vector retrieval method based on heterogeneous storage, characterized in that, include: The GPU sends the target node identifier of the current candidate node in the node queue to the CPU. The node queue includes candidate nodes sorted by a first distance. The first distance is the distance between the vector node and the query vector, which is calculated by the GPU using the quantization encoding of the vector nodes in the video memory. The vector node belongs to the vector dataset to be retrieved. The current candidate node is the first number of candidate nodes in the node queue with the smallest first distance. The CPU moves the target original vector data corresponding to the target node identifier from the host-side storage space to the video memory. The GPU uses the original target vector data to calculate the second distance between the current candidate node and the query vector. The GPU determines the vector retrieval result based on the second distance between the current candidate node and the query vector.
2. The method according to claim 1, characterized in that, Also includes: The CPU moves the target graph neighbor table corresponding to the target node identifier from the host-side storage space to the video memory. The GPU obtains the unvisited neighbor nodes corresponding to the current candidate node according to the target graph neighbor table, calculates the first distance corresponding to the unvisited neighbor nodes, and updates the node queue according to the first distance corresponding to the unvisited neighbor nodes. The unvisited neighbor nodes are vector nodes among the neighbor nodes corresponding to the current candidate node whose first distance has not been calculated.
3. The method according to claim 2, characterized in that, The step of determining the vector retrieval result by the GPU based on the second distance between the current candidate node and the query vector includes: The GPU updates the retrieval result set based on the second distance between the current candidate node and the query vector, wherein the retrieval result set includes at most a second number of vector nodes with the smallest second distance; In response to the fact that the node identifiers of all candidate nodes in the node queue have been sent to the CPU, the vector retrieval result is determined based on the most recently updated retrieval result set.
4. The method according to claim 2, characterized in that, The host-side storage space includes a fixed memory pool; through a unified computing device architecture flow, the CPU acts as a producer to concurrently move the target original vector data corresponding to the target node identifier and the target graph neighbor table to the fixed memory pool, and the GPU acts as a consumer to asynchronously receive the target original vector and the target graph neighbor table transferred through direct memory access DMA and perform related calculations.
5. The method according to claim 1, characterized in that, Also includes: The third distance between the query vector and the candidate search nodes is calculated by using the original vector data of the third number of candidate search nodes in the GPU memory. The candidate search nodes are the vector nodes that are closest to the target centroid, and the target centroid is the third number of centroids obtained by clustering the dataset of vectors to be retrieved. The first vector node to be added to the node queue is determined based on the third distance.
6. The method according to any one of claims 1-5, characterized in that, The quantization encoding is obtained based on product quantization or random binary quantization.
7. A vector retrieval device based on heterogeneous storage, characterized in that, include: A node identifier sending module is used to send the target node identifier of the current candidate node in the node queue to the central processing unit (CPU) via a graphics processing unit (GPU). The node queue includes candidate nodes sorted according to a first distance, where the first distance is the distance between a vector node and a query vector calculated by the GPU using the quantization encoding of vector nodes in video memory. The vector node belongs to the vector dataset to be retrieved, and the current candidate node is the first number of candidate nodes in the node queue with the smallest first distance. The data transfer module is used to transfer the target original vector data corresponding to the target node identifier from the host-side storage space to the video memory via the CPU; The second distance calculation module is used to calculate the second distance between the current candidate node and the query vector using the target original vector data via the GPU. The retrieval result determination module is used to determine the vector retrieval result by means of the GPU based on the second distance between the current candidate node and the query vector.
8. An electronic device, characterized in that, The electronic device includes: At least two processors; and The memory is communicatively connected to the at least two processors; wherein, The at least two processors include a graphics processing unit (GPU) and a central processing unit (CPU), and the memory stores a computer program that can be executed by the at least two processors, the computer program being executed by the at least two processors to enable the at least two processors to perform the vector retrieval method based on heterogeneous storage as described in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the vector retrieval method based on heterogeneous storage as described in any one of claims 1-6.
10. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the vector retrieval method based on heterogeneous storage according to any one of claims 1-6.