Vector retrieval method and device, storage medium and program product

By performing hierarchical compression and storage of node data in the nearest neighbor graph, and using node representations with high compression ratios for preliminary queries and node representations with low compression ratios for precise queries, the problems of insufficient resource utilization and high query latency in disk-based vector retrieval schemes are solved, thereby improving query efficiency and reducing I/O amplification.

CN121786233APending Publication Date: 2026-04-03BEIJING VOLCANO ENGINE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-30
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

Existing disk-based vector retrieval schemes suffer from insufficient resource utilization, high query latency, and low throughput. In particular, disk I/O amplification leads to system performance bottlenecks in large-scale data searches.

Method used

A two-level node representation hierarchical storage method is adopted to compress the node data of the nearest neighbor graph in layers. The node data with high compression ratio resides in the first storage space (such as memory), while the node data with low compression ratio is stored in the second storage space (such as disk). The high compression ratio node representation is used for preliminary querying to reduce storage resource consumption, and the low compression ratio node representation is read for precise querying when needed.

Benefits of technology

It improves query efficiency, reduces query latency, reduces invalid I/O, and significantly enhances the overall performance of the near nearest neighbor search system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121786233A_ABST
    Figure CN121786233A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a vector retrieval method and device, a storage medium and a program product, a first vector in a vector retrieval request is compressed at a first compression ratio and a second compression ratio to obtain a second vector and a third vector, and the first compression ratio is higher than the second compression ratio; querying a first candidate node similar to a second vector from each first-level node representation of the neighbor graph, wherein the first-level node representation comprises vectors compressed at a first compression rate; second candidate nodes similar to the third vector are queried from the second-level node representation of the first candidate nodes, the original vectors of the second candidate nodes are similar vectors of the first vector, and the second-class node data comprises an adjacency list and vectors compressed at a second compression rate. According to the method, hierarchical compression and hierarchical storage are performed on neighbor graph node data, two-stage query is adopted to improve query efficiency and reduce query delay and I / O amplification, asynchronous scheduling is performed on multiple query coroutines, the CPU utilization rate is improved, and heuristic beam search is adopted to optimize the cache hit rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a vector retrieval method, device, storage medium, and program product. Background Technology

[0002] Vector retrieval is frequently involved in various applications, such as content search and artificial intelligence. The industry typically employs nearest-neighbor graph indexes to achieve low-latency, high-throughput vector retrieval, such as Hierarchical Navigable Small World (HNSW) graphs. However, as data volumes continue to grow, these solutions are prone to memory bottlenecks. To support large-scale vector searches exceeding memory capacity (i.e., disk-based vector searches), recent Approximate Nearest Neighbor Search (ANNS) systems often utilize solid-state drives (SSDs) to store large vector indexes, thus overcoming memory limitations.

[0003] However, in disk-based vector retrieval schemes, data needs to be read into memory. The vector retrieval process involves waste of I / O (read / write) and computing resources, and may cause disk I / O amplification, resulting in insufficient resource utilization and query latency, causing performance bottlenecks of high latency and low throughput in the system. Summary of the Invention

[0004] This disclosure provides a vector retrieval method, device, storage medium, and program product to improve vector query efficiency, reduce query latency, and reduce disk I / O amplification.

[0005] In a first aspect, embodiments of this disclosure provide a vector retrieval method, including:

[0006] Receive a vector retrieval request, the vector retrieval request including a first vector, for requesting the retrieval of similar vectors of the first vector;

[0007] The first vector is compressed at a first compression ratio to obtain a second vector, and the first vector is compressed at a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio;

[0008] From the first-level node representation of the nearest neighbor graph, at least one first candidate node similar to the second vector is queried; wherein the nearest neighbor graph adopts a two-level node representation structure and adopts a hierarchical storage method, wherein the first-level node representation is stored in a first storage space, including the first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space, including the second compressed vector of each node generated based on the second compressed vector and its adjacency list;

[0009] Based on at least one first candidate node, a second candidate node similar to the third vector is queried in the second-level node representation of the nearest neighbor graph, and the original vector of the second candidate node is used as the similar vector of the first vector.

[0010] Secondly, embodiments of this disclosure provide a vector retrieval device, comprising:

[0011] A receiving unit is configured to receive a vector retrieval request, wherein the vector retrieval request includes a first vector and is configured to request the retrieval of similar vectors of the first vector;

[0012] A compression unit is configured to compress the first vector at a first compression ratio to obtain a second vector, and to compress the first vector at a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio.

[0013] The first query unit is used to query at least one first candidate node that is similar to the second vector from the first-level node representation of the nearest neighbor graph; wherein the nearest neighbor graph adopts a two-level node representation structure and a hierarchical storage method, wherein the first-level node representation is stored in a first storage space and includes a first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space and includes a second compressed vector of each node generated based on the second compressed vector and its adjacency list;

[0014] The second query unit is configured to query a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on at least one first candidate node, and use the original vector of the second candidate node as the similar vector of the first vector.

[0015] Thirdly, embodiments of this disclosure provide an electronic device, including: a processor and a memory;

[0016] The memory stores computer-executed instructions;

[0017] The processor executes computer execution instructions stored in the memory, causing the at least one processor to perform the vector retrieval method as described in the first aspect and various possible designs of the first aspect.

[0018] Fourthly, embodiments of this disclosure provide a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the vector retrieval method described in the first aspect and various possible designs of the first aspect.

[0019] Fifthly, embodiments of this disclosure provide a computer program product, including a computer program that, when executed by a processor, implements the vector retrieval method as described in the first aspect and various possible designs of the first aspect.

[0020] The vector retrieval method, device, storage medium, and program product provided in this disclosure include: receiving a vector retrieval request, the vector retrieval request including a first vector, for requesting the retrieval of similar vectors of the first vector; compressing the first vector according to a first compression ratio to obtain a second vector, and compressing the first vector according to a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio; querying at least one first candidate node similar to the second vector from the first-level node representation of the nearest neighbor graph; wherein the nearest neighbor graph adopts a two-level node representation structure and adopts a hierarchical storage method, wherein the first-level node representation is stored in a first storage space, including the first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space, including the second compressed vector of each node and its adjacency list, the second compressed vector of each node being generated based on the second compression ratio; and querying a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on at least one first candidate node, and using the original vector of the second candidate node as the similar vector of the first vector. This embodiment reduces storage resource consumption by pre-compressing and storing the node data of the nearest neighbor graph in a vector layer. It also improves query efficiency, reduces query latency, and reduces invalid I / O and I / O amplification by using the first-level node representation with a high compression ratio for preliminary querying and then using the second-level node representation with a low compression ratio for precise querying. Attached Figure Description

[0021] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 A schematic diagram illustrating a scenario of a vector retrieval method provided in an embodiment of this disclosure;

[0023] Figure 2This is a schematic diagram of a vector retrieval method provided in an embodiment of the present disclosure;

[0024] Figure 3 This is a schematic diagram of the structure of a storage page provided in an embodiment of the present disclosure;

[0025] Figure 4 A schematic diagram illustrating the scheduling of worker threads according to an embodiment of this disclosure;

[0026] Figure 5 This is a structural block diagram of a vector retrieval device provided in an embodiment of the present disclosure;

[0027] Figure 6 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present disclosure. Detailed Implementation

[0028] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this disclosure, and not all embodiments. Based on the embodiments of this disclosure, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this disclosure.

[0029] In disk-based vector retrieval schemes, the node data of the nearest neighbor graph is stored in a page-based layout. Each storage page stores the node data of multiple nodes. Each node's data includes vector data and a corresponding adjacency list. During vector retrieval, the node data needs to be read into memory. Data access is typically achieved through two types of memory-disk interaction mechanisms:

[0030] 1) Memory-disk interaction scheme based on operating system management cache (mmap)

[0031] Technical essence: It adopts memory-mapped I / O (such as mmap memory mapping) and relies on the operating system's built-in caching mechanism to handle data interaction; during the search, it follows the best-first paradigm, iteratively pulling vector node data and neighbor node data from the disk from the entry point, and the implementation logic is simple and does not require a custom caching module.

[0032] Core flaws: Limited cache control capabilities, unable to optimize for the graph traversal characteristics of ANNS, further amplifying the problems of low I / O efficiency and poor cache hit rate; and completely dependent on OS scheduling, making it difficult to balance CPU and I / O usage in low-resource scenarios.

[0033] 2) Memory-disk interaction scheme based on self-managed buffer pool

[0034] Technical essence: Construct a custom buffer pool and explicitly control the retention of hot data in the buffer pool through customized replacement strategies (such as the most recently used strategy, the first-in-first-out strategy, etc.); it also performs searches based on paged storage, but can independently adjust cache priority and reduce dependence on the operating system (OS).

[0035] Core drawbacks: High implementation complexity and high development and maintenance costs; and it does not solve the inherent problems of ANNS search, still facing challenges such as excessive I / O prefetching and mismatch between CPU and I / O utilization, and cannot fundamentally improve query throughput.

[0036] The aforementioned solutions are not adapted to the access characteristics of graph-based approximate nearest neighbor search (i.e., vector search), resulting in query throughput that is far lower than that of memory-based storage solutions. Furthermore, they suffer from inherent and insurmountable deficiencies in key dimensions such as resource utilization and I / O efficiency. Meanwhile, existing disk-based vector retrieval solutions share common core flaws:

[0037] 1) Serial I / O and computation waste resources: In the best-first search, I / O and computation are serialized step by step, and the CPU is idle for a lot of time while waiting for slow disk reads; synchronous I / O requires waiting for the slowest read in the batch to complete, resulting in low I / O pipeline utilization.

[0038] 2) Suboptimal disk layout causes I / O amplification: Storage pages are packaged in order of node identifier (ID), and related nodes in the graph are stored in a scattered manner. I / O loads the entire page into memory but only uses the data of a single node, resulting in serious I / O amplification. Fixed-size node data also leads to storage page fragmentation, wasting storage and bandwidth. Existing graph reordering algorithm optimizations cannot be used for practical large-scale applications due to high computational overhead at large scale.

[0039] 3) Inefficient cache management and low hit rate: Existing pagination-based caching methods cannot adapt to ANNS load, resulting in an extremely low cache hit rate, which directly drags down query performance.

[0040] To address the aforementioned technical problems, this disclosure provides a vector retrieval method. This method pre-compresses the node data of the nearest neighbor graph using a hierarchical vector compression mechanism, i.e., compression at different compression ratios. High-compression-ratio (low-precision) node data resides permanently in the first storage space, while low-compression-ratio (high-precision) node data is stored in the second storage space. The first storage space can be accessed when needed, reducing storage resource consumption. Furthermore, the method uses the high-compression-ratio first-level node representation for initial querying to narrow the query range, followed by the low-compression-ratio second-level node representation for precise querying. This improves query efficiency, increases query throughput, reduces query latency, and minimizes invalid disk I / O and disk I / O amplification, thereby significantly enhancing the overall performance of the Approximate Nearest Neighbor Search (ANNS) system.

[0041] The application scenarios of the vector retrieval method in this disclosure embodiment are as follows: Figure 1 As shown, this application is used in electronic devices such as terminal devices or servers. Specifically, it receives a vector retrieval request, which includes a first vector, and requests the retrieval of similar vectors of the first vector; compresses the first vector according to a first compression ratio to obtain a second vector, and compresses the first vector according to a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio; from the first-level node representation of the nearest neighbor graph, it queries at least one first candidate node similar to the second vector; wherein the nearest neighbor graph adopts a two-level node representation structure and adopts a hierarchical storage method, wherein the first-level node representation is stored in a first storage space, including the first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space, including the second compressed vector of each node and its adjacency list, wherein the second compressed vector of each node is generated based on the second compression ratio; based on at least one first candidate node, it queries the second-level node representation of the nearest neighbor graph for a second candidate node similar to the third vector, and uses the original vector of the second candidate node as the similar vector of the first vector.

[0042] The vector retrieval method disclosed in this embodiment essentially transforms all data (text, images, audio, etc.) into points (vectors) in a mathematical space, and measures and retrieves the most semantically or content-similar data by calculating the distance between these points. The core application of vector retrieval is handling semantic matching of unstructured data, widely empowering various systems: in the search and recommendation field, it upgrades from "keyword matching" to "semantic understanding," enabling e-commerce and content platforms to more accurately recommend similar products and information; in generative AI and large-scale model applications, it serves as a key component of RAG (Retrieval Augmentation), providing real-time and accurate evidence for AI responses and effectively preventing "illusions"; within enterprises, it can quickly locate knowledge from massive amounts of documents, creating intelligent customer service and efficient knowledge bases; simultaneously, it provides the underlying technology support for cutting-edge scenarios such as cross-modal interaction (image search, voice retrieval) and security risk control (anomaly detection, biometrics). In short, vector search solutions are applicable to any scenario that requires understanding the "meaning" of content and performing intelligent association and retrieval.

[0043] The vector retrieval method of this disclosure will be described in detail below with reference to specific embodiments.

[0044] refer to Figure 2 , Figure 2 This is a schematic flowchart of a vector retrieval method provided in an embodiment of the present disclosure. The method of this embodiment can be applied to electronic devices such as terminal devices or servers. The vector retrieval method includes:

[0045] S201. Receive a vector retrieval request, the vector retrieval request including a first vector, for requesting the retrieval of similar vectors of the first vector.

[0046] In this embodiment, when it is necessary to query similar vectors of the first vector, a vector retrieval request can be triggered. The vector retrieval request includes the first vector and is used to request the retrieval of similar vectors of the first vector. The first vector can be a vector obtained by vectorizing the data to be queried in any application scenario.

[0047] S202. Compress the first vector according to the first compression ratio to obtain the second vector, and compress the first vector according to the second compression ratio to obtain the third vector; wherein the first compression ratio is higher than the second compression ratio.

[0048] In this embodiment, in order to retrieve the first vector based on the nearest neighbor graph involved in S203, the first vector needs to be compressed in two stages. That is, the first vector is compressed according to a first compression ratio to obtain the second vector, and then compressed according to a second compression ratio to obtain the third vector. The first compression ratio is higher than the second compression ratio. See S203 for details.

[0049] S203. From the first-level node representation of the nearest neighbor graph, query at least one first candidate node that is similar to the second vector; wherein, the nearest neighbor graph adopts a two-level node representation structure and adopts a hierarchical storage method, wherein, the first-level node representation is stored in a first storage space, including the first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space, including the second compressed vector of each node generated based on the second compressed vector and its adjacency list.

[0050] In this embodiment, the node data of the nearest neighbor graph is compressed in advance to reduce the resources occupied by the node data. Each node data in the nearest neighbor graph includes a vector and an adjacency list. The adjacency list of the current node is used to record the neighboring nodes connected to the current node. During compression, the vector of each node is compressed using a first compression ratio and a second compression ratio. The compression method can be any feasible vector compression method, such as product quantization, RabbitQ, etc. Finally, the first-level node representation and the second-level node representation of the nearest neighbor graph can be obtained. The first-level node representation of each node includes a first compressed vector obtained by compression with the first compression ratio. The second-level node representation of each node includes the adjacency list of the node and a second compressed vector obtained by compression with the second compression ratio. The first compression ratio is higher than the second compression ratio. That is, for any node, the amount of data in the first-level node representation is less than the amount of data in the second-level node representation. Correspondingly, the precision of the first-level node representation is also lower than that of the second-level node representation. For example, the vector compressed with the first compression ratio has a size of 1 bit per dimension, and the vector compressed with the second compression ratio has a size of 4 bits per dimension. In this way, the first-level node representation of the nearest neighbor graph occupies relatively little storage space and can reside permanently in the first storage space (e.g., memory); while the second-level node representation occupies relatively more storage space and can be stored in the second storage space (e.g., disk), and read into memory when needed. Compared with storing the original node data of the nearest neighbor graph in the second storage space (e.g., disk) and performing vector retrieval based on the original node data, this saves storage space and reduces I / O bandwidth usage. It should be noted that the adjacency list in the second-level node representation can be compressed or not.

[0051] Based on the first-level and second-level node representations of the nearest neighbor graph, upon receiving a vector retrieval request, in order to facilitate vector retrieval from the first-level and second-level node representations of each node in the nearest neighbor graph, the first vector needs to be compressed using the first compression ratio and the second compression ratio, respectively, to obtain the second vector and the third vector. The second vector is used for vector retrieval in the first-level node representation of each node, and the third vector is used for vector retrieval in the second-level node representation of each node.

[0052] In this embodiment, since the representations of each first-level node in the nearest neighbor graph are stored in a first storage space (e.g., memory), candidate nodes similar to the second vector can be directly queried from the representations of each first-level node. These candidate nodes are denoted as first candidate nodes. For example, the similarity between the first compressed vector and the second vector of each node can be obtained from the representations of each node's first-level node. After sorting the similarity from high to low, one or more nodes ranked first are selected as first candidate nodes. The similarity can be determined in any way, such as calculating the distance between the second vector and the first compressed vector in each first-level node representation as the similarity. Since both the second vector and each first-level node representation use a large first compression ratio, the amount of information is reduced. Therefore, when querying first candidate nodes similar to the second vector, the query speed can be greatly improved, but the accuracy is relatively reduced. This can be used as a preliminary query to narrow down the query range for subsequent precise queries.

[0053] S204. Based on the at least one first candidate node, query the second-level node representation of the nearest neighbor graph for a second candidate node that is similar to the third vector, and use the original vector of the second candidate node as the similar vector of the first vector.

[0054] In this embodiment, after finding a first candidate node similar to the second vector, a further precise query is performed on the first candidate node based on the corresponding second-level node representation. The second compressed vector in the second-level node representation is compressed using the second compression ratio. Therefore, a third vector compressed using the second compression ratio is needed to perform a further precise query on the second-level node representation of the first candidate node. That is, from the second-level node representation of the first candidate node, a second candidate node similar to the third vector is queried. The query process can adopt any feasible graph traversal method.

[0055] In this embodiment, the second-level node representations of each node in the nearest neighbor graph are initially stored in the second storage space (e.g., disk). During subsequent vector queries, some second-level node representations of the nearest neighbor graph are read from the second storage space into the first storage space (e.g., memory). Furthermore, to fully utilize memory resources, ensure adequate page swapping in low-resource scenarios, reduce invalid disk I / O, and lower query latency, the second-level node representations of frequently accessed nodes in the nearest neighbor graph can be cached in memory, and cleanup can be performed based on strategies such as most recently used. Therefore, the second-level node representation of the first candidate node may or may not be cached in the first storage space. If it is not cached in the first storage space, it needs to be read from the second storage space into the first storage space. Then, from the second-level node representations of the first candidate node in the nearest neighbor graph, a query can be performed to find second candidate nodes similar to the third vector. The query can be based on the similarity between the third vector and the second compressed vector in the second-level node representation of the first candidate node. For example, after sorting the similarity from high to low, one or more nodes ranked first can be selected as second candidate nodes. The similarity can be determined in any way, such as calculating the distance between the third vector and the second compressed vector in the second-level node representation of the first candidate node as the similarity. In this embodiment, only precise queries are needed within the range of the first candidate node, which improves query speed and reduces query latency. Furthermore, the second-level node representation of the first candidate node has also been compressed and may be pre-cached in the first storage space, thus reducing the amount of data that needs to be read from the second-level node representation in the first storage space, reducing invalid I / O, and reducing I / O amplification.

[0056] Furthermore, after finding a second candidate node similar to the third vector, since the vectors in the first-level node representation and the second-level node representation of the second candidate node are both compressed, the original vector (i.e. the uncompressed vector) corresponding to the second candidate node can be determined as the similar vector of the first vector, and the similar vector of the first vector is output.

[0057] The vector retrieval method provided in this embodiment involves receiving a vector retrieval request, which includes a first vector, for requesting the retrieval of similar vectors of the first vector; compressing the first vector according to a first compression ratio to obtain a second vector, and compressing the first vector according to a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio; querying at least one first candidate node similar to the second vector from the first-level node representation of the nearest neighbor graph; wherein the nearest neighbor graph adopts a two-level node representation structure and uses a hierarchical storage method, wherein the first-level node representation is stored in a first storage space, including the first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space, including the second compressed vector of each node and its adjacency list, wherein the second compressed vector of each node is generated based on the second compression ratio; and querying a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on at least one first candidate node, and using the original vector of the second candidate node as the similar vector of the first vector. This embodiment reduces storage resource consumption by pre-compressing and storing the node data of the nearest neighbor graph in a vector layer. It also improves query efficiency, reduces query latency, and reduces invalid I / O and I / O amplification by using the first-level node representation with a high compression ratio for preliminary querying and then using the second-level node representation with a low compression ratio for precise querying.

[0058] Based on any of the above embodiments, the first storage space is memory, and the second storage space is a disk; of course, the first and second storage spaces can also be other feasible storage spaces, and this embodiment is not limited thereto. Optionally, the memory uses a second-level node representation that includes a slotted buffer pool and caches some nodes at the node granularity.

[0059] Based on any of the above embodiments, when querying for a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph according to at least one first candidate node in S204, the query may specifically include:

[0060] Determine the storage location of the second-level node represented by the first candidate node;

[0061] If the second-level node of the first candidate node is cached in the first storage space, then the query for the second candidate node is based on the second-level node of the first candidate node in the first storage space; or

[0062] If the second-level node representation of the first candidate node is not cached in the first storage space, then the second-level node representation of the first candidate node is read from the second storage space into the first storage space, and then the second candidate node is queried based on the second-level node representation of the first candidate node in the first storage space.

[0063] In this embodiment, the storage location of the second-level node representation of the first candidate node can be determined first, that is, whether the second-level node representation of the first candidate node is cached in the first storage space. If it is cached in the first storage space, the second candidate node can be queried directly based on the second-level node representation of the first candidate node cached in the first storage space. That is, there is no need to read it from the second storage space to the first storage space, which reduces the waiting time and reduces query latency and I / O. If it is not cached in the first storage space, the second-level node representation of the first candidate node needs to be read from the second storage space to the first storage space, and then the second candidate node can be queried based on the second-level node representation of the first candidate node cached in the first storage space.

[0064] Optionally, when determining the storage location of the second-level node representation of the first candidate node, it can be based on a pre-stored index data set in the first storage space. This pre-stored index data set includes index data of the second-level node representations of all nodes in the nearest neighbor graph. The index data includes node identifiers (VIDs) and storage location information of the second-level node representation in either the first or second storage space. Optionally, the storage location information of the second-level node representation in either the first or second storage space may include a location identifier and a specific storage location. The location identifier is used to mark whether the second-level node is represented in the first or second storage space. For example, a location identifier of 1 indicates that the second-level node is cached in the first storage space, and a location identifier of 0 indicates that the second-level node is not cached in the first storage space, i.e., it is stored in the second storage space. If the second-level node representation is cached in the first storage space, the specific storage location indicates the location information of the second-level node in the first storage space; if the second-level node representation is not cached in the first storage space, the specific storage location indicates the location information of the second-level node in the second storage space. Optionally, the index data set can be stored in the first storage space in array form or other forms, and can be continuously updated by writing to and clearing the second-level node representation in the first storage space. The index data set can eliminate the access overhead of the second-level node representation.

[0065] When determining the storage location of the second-level node representation of the first candidate node based on the index data set pre-stored in the first storage space, the index data of the second-level node representation of the first candidate node can be queried based on the node identifier (VID) of the first candidate node, and then the storage location of the second-level node representation of the first candidate node can be determined based on the index data.

[0066] Based on any of the above embodiments, a page-based storage layout can be used in the second storage space to store the second-level node representations of the nearest neighbor graph, and multiple second-level node representations of nodes can be stored in each storage page.

[0067] Optionally, the format of the stored pages can be as follows: Figure 3 As shown, it includes three functional areas: header, metadata array, and data stack.

[0068] The page header has a fixed length, such as 5 bytes, and is used to store page management metadata, including the number of nodes (Count) and heap pointers (HeapStart, HeapUsed). The page management metadata is used to implement the overall scheduling and space management of the stored pages.

[0069] The metadata array consists of fixed-size entries stored from the beginning to the end of the page. Each entry includes, but is not limited to, a node identifier (VID) and a second-level node indicating its position in the data heap. It may also include a node type identifier. The second-level node indicating its position in the data heap may include the starting offset and length within the data heap. Furthermore, the entries are arranged in order according to their node identifiers (VIDs) to support fast location based on binary search.

[0070] The data heap is used to store the second-level node representations of each node, stored from the end of the page to the beginning of the page; the metadata array is stored in reverse order of the data heap, which enables dynamic sharing of page space, minimizes internal fragmentation, and ensures dense storage of metadata and the data heap.

[0071] Of course, the format of the stored pages is not limited to the examples above; other formats may also be used.

[0072] Furthermore, when reading the second-level node representation of the first candidate node from the second storage space into the first storage space, the target storage page where the second-level node representation of the first candidate node is located in the second storage space can be determined first. This determination can be done in any feasible way. For example, if the second-level node representation is not cached in the index data set pre-stored in the first storage space, the specific storage location represents the storage page (e.g., page identifier PageID) where the second-level node representation of the first candidate node is located in the second storage space. The target storage page where the second-level node representation of the first candidate node is located in the second storage space can be determined based on the index data of the first candidate node. Further, the metadata of the first candidate node can be queried from the metadata array of the target storage page based on the node identifier of the first candidate node, for example, using binary search or other query methods. Then, the second-level node representation of the first candidate node is read from the data heap of the target storage page based on the metadata of the first candidate node and cached in the first storage space for subsequent distance calculation and graph traversal operations.

[0073] Based on any of the above embodiments, to adapt to the data access characteristics of vector queries, a slot-based buffer pool can be constructed in the first storage space. The second-level node representations in the first storage space are organized according to node granularity, that is, each slot in the slot-based buffer pool stores the second-level node representation of one node, thereby achieving efficient management of the layout of the first storage space of the nearest neighbor graph. In specific implementation, an anonymous virtual first storage space region (e.g., allocated via mmap) can be allocated to the slot-based buffer pool in the first storage space. Its size can be configured as a specified proportion of the total index size (i.e., the buffer ratio), and the first storage space region can be divided into several slots. The size of each slot is adapted to the storage requirements of the second-level node representation of a single node. At the same time, an idle slot can be tracked and managed through a free list.

[0074] Furthermore, when reading the second-level node representation of the first candidate node from the second storage space into the first storage space, an empty slot in the slotted buffer pool can be found first according to the free list, and then the second-level node representation of the first candidate node can be read from the second storage space into the empty slot, thereby achieving efficient management of the second node data. Optionally, in the index data set pre-stored in the first storage space, if the second-level node representation is cached in the first storage space, the specific storage location represents the location information of the second-level node representation in the first storage space. Specifically, it can be the slot of the second-level node representation in the slotted buffer pool, and the target slot of the second-level node representation of the first candidate node in the slotted buffer pool of the first storage space can be determined according to the index data of the first candidate node.

[0075] Based on any of the above embodiments, existing nearest-neighbor graph storage schemes outside the first storage space mostly organize node data in a random or indiscriminate manner, resulting in a lack of effective locality of node data within storage pages. That is, node data that is topologically or spatially adjacent is not aggregated for storage. This leads to frequent access to discretely distributed node data across storage pages during the nearest-neighbor graph traversal process, triggering a large amount of random second storage space I / O, thereby causing low I / O efficiency and limited system throughput. To address this, this embodiment proposes an affinity-oriented data placement strategy with the core objective of improving storage page-level data locality. Based on the characteristic that "spatial proximity vectors are often traversed collaboratively in the search trajectory," this strategy improves data access locality and reduces the frequency of invalid second storage space I / O by aggregating and co-locating node data of affinity nodes and reasonably filtering non-affinity records, thereby significantly improving the access efficiency of the nearest-neighbor graph.

[0076] Specifically, firstly, the affinity node set is determined. For any node in the nearest neighbor graph, multiple affinity nodes of that node are determined. The second-level node representation of that node and the second-level node representations of its affinity nodes are constructed into an affinity node set. This set is then placed contiguously in the storage pages of the second storage space according to the set granularity. In other words, the affinity node set is stored in one storage page of the second storage space, avoiding the storage of the affinity node set across storage pages as much as possible.

[0077] When determining multiple affinity nodes for a given node, the distance between the vectors of two nodes can be compared to a preset distance threshold. If the distance between the vectors of two nodes is less than the preset distance threshold, then the two nodes are considered affinity nodes. The preset distance threshold can be determined based on vector clustering statistics. It can be the average distance between the 5th percentile centroids of all clusters, or it can be determined by performing the clustering process during vector compression, or by other methods.

[0078] Furthermore, to address the high computational overhead of O(|𝑃|²) caused by pairwise verification of all vectors, this embodiment integrates the affinity recognition process into the construction process of the greedy nearest neighbor graph. It reuses the candidate set and distance calculation results (distance list) generated in the neighbor selection stage, and only filters no more than 𝑘 nearest affinity candidate vectors within a preset distance threshold range for each node, and stores them in the set. This method only requires filtering for each node, avoiding extra traversal of the dataset. The 𝑘 value (i.e., the number of nodes included in each second-level node representation set) is set according to the storage page capacity (i.e., the maximum number of records per page), ensuring that the second-level node representation set of each affinity is not stored across multiple storage pages.

[0079] Furthermore, when reading the second-level node representation of the first candidate node from the second storage space into the first storage space, if it is determined that the second-level node representation of the first candidate node belongs to any affinity node set, then the second-level node representations of all nodes in that affinity node set are read from the second storage space into the first storage space, thereby realizing the pre-reading of the second-level node representation of affinity nodes, improving access efficiency, increasing cache hit rate, and reducing query latency.

[0080] Optionally, when the aforementioned set of second-level node representations is stored in a storage page of the second storage space, if the remaining space of the current storage page is insufficient to store a complete set of second-level node representations and there are second-level node representations without affinity nodes, a greedy filling strategy can be adopted to prioritize storing second-level node representations without affinity nodes; or, when there are no second-level node representations without affinity nodes, the set of affinity nodes is split into multiple subsets and stored in the current storage page and other storage pages, that is, the remaining space of the current storage page is used to store second-level node representations without affinity nodes to fill the remaining space; if the remaining space of the current storage page is insufficient to store a complete set of second-level node representations and there are no second-level node representations without affinity nodes, then any set of second-level node representations is split into subsets, one subset is stored in the remaining space of the current storage page (the size of the subset can be equal to the size of the remaining space of the current storage page), and the other subsets are stored in other storage pages. When reading, it is necessary to read each subset across pages into the first storage space.

[0081] Optionally, the affinity node set and the second-level node representation without affinity nodes in the current storage page can be identified to distinguish between the without affinity nodes and each affinity node set. For example, the identifier of the second-level node representation without affinity nodes is 0, and the identifiers of each second-level node representation set are incremented sequentially. The second-level node representations in the same second-level node representation set are marked with the same identifier. When reading any second-level node representation, if the identifier is 0, only one second-level node representation is read into the first storage space; if the identifier is not 0, all second-level node representations with that identifier are read into the first storage space.

[0082] Based on any of the above embodiments, in order to reduce CPU idleness caused by I / O blocking in the second storage space and improve CPU utilization, this embodiment adopts an asynchronous runtime framework driven by coroutines. Multiple query coroutines are scheduled on a single worker thread. When a query coroutine is blocked by I / O in the second storage space, the CPU execution flow is scheduled to other query coroutines to avoid CPU idleness. Specifically, in S203, from the second-level node representation of the first candidate node in the nearest neighbor graph, a second candidate node similar to the third vector is queried, such as... Figure 4 As shown, it may include:

[0083] Query tasks are processed in batches using multiple query coroutines on worker threads, with at most one query coroutine running on a worker thread at any given time. If any of the first query coroutines is blocked (e.g., waiting to read data from the second storage space), the worker thread is switched from the first query coroutine to a ready second query coroutine. The second query coroutine is either any second-level node representation that does not need to read any node from the second storage space, or a second-level node representation that has already completed reading any node from the second storage space. This avoids CPU idleness due to I / O blocking, improves CPU utilization, ensures efficient query performance, and reduces I / O latency.

[0084] It should be noted that the query tasks handled by different query coroutines on the worker thread can be the same, that is, all belonging to the query task of querying similar vectors of the first vector (which can be different subtasks), or they can be different query tasks, that is, different query coroutines handle the query task of querying similar vectors of different vectors. The query task is also the graph traversal task of the nearest neighbor graph.

[0085] Optionally, in this embodiment, a queue of pending coroutines can be used to maintain query coroutines that have completed reading data from the second storage space. Any query coroutine that does not need to read the second-level node representation of any node from the second storage space, or that has completed reading the second-level node representation of any node from the second storage space, enters a ready state and is added to the queue of pending coroutines. For example, for the second query coroutine, after the second query coroutine completes reading data from the second storage space, it is added to the queue of pending coroutines. Then, when the first query coroutine enters a blocked state, the worker thread can be controlled to pause the first query coroutine and select the second query coroutine from the queue of pending coroutines. The worker thread then runs the second query coroutine, thus achieving rapid switching of query coroutines. The first query coroutine can initiate asynchronous I / O operations to read data from the second storage space before pausing. After initiating the asynchronous I / O operation, the first query coroutine pauses, relinquishing control and avoiding the occupation of thread resources.

[0086] Optionally, in this embodiment, a scheduler can also be run on the worker thread. The scheduler models the incoming batch query tasks as query coroutines, controls the switching of query coroutine creation (assigning control), and maintains the queue of coroutines to be run and polls the queue of coroutines to be run (polling to see if each I / O operation is completed).

[0087] Based on any of the above embodiments, and based on the first storage space caching mechanism, this embodiment further proposes a prefetching mechanism and cache-aware heuristic beam search, prioritizing candidate nodes cached in the first storage space to achieve opportunistic exploration and hide I / O latency. Specifically, S203 queries a second candidate node similar to the third vector from the second-level node representation of the first candidate node in the nearest neighbor graph, including:

[0088] Construct a candidate node set based on at least one first candidate node, and perform a beam search on the candidate node set;

[0089] In each iteration of the beam search, for each candidate node in the candidate node set, sort them according to their similarity to the third vector, select the third candidate node with the highest similarity and the second-level node representation cached in the first storage space, add the neighboring nodes of the third candidate node to the candidate node set based on the second-level node representation of the third candidate node, and migrate the third candidate node from the candidate node set to the explored node set;

[0090] After the beam search process is completed, one or more nodes are selected from the explored node set according to their similarity from high to low to determine them as second candidate nodes.

[0091] In this embodiment, considering that the traditional greedy bundle search process selects the candidate node with the highest similarity for graph traversal in each iteration, it may encounter a situation where the second-level node representation of the candidate node with the highest similarity in a certain iteration is not cached in the first storage space and needs to wait to be read from the second storage space into the first storage space, thus causing I / O blocking in that iteration; in order to solve the above-mentioned technical problem of the traditional greedy bundle search process, this embodiment introduces opportunistic exploration, that is, in any iteration, before a preset order (e.g., the first N) of similarity sorted from high to low, a third candidate node with the highest similarity and whose second-level node representation is cached in the first storage space is selected for graph traversal, and is not limited to only performing graph traversal on the second-level node representation of the most similar candidate node. When performing graph traversal on the third candidate node, the similarity between the neighboring nodes of the third candidate node and the third vector is determined according to the second-level node representation of the third candidate node, and the neighboring nodes of the third candidate node are added to the candidate node set, so that in the next iteration, the candidate node set can be sorted again from high to low according to the similarity with the third vector to select the third candidate node. After completing the graph traversal of the third candidate node in this iteration, the third candidate node is moved from the candidate node set to the explored node set. In this embodiment, opportunistic exploration is used to avoid I / O blocking during the iteration process and reduce overall query latency.

[0092] In each iteration, if one or more candidate nodes in the preset order of sorting are second-level nodes that are not cached in the first storage space, they are read from the second storage space into the first storage space through asynchronous I / O operations to achieve pre-fetching and support the operation of subsequent iterations.

[0093] Furthermore, if the second-level node representations of all candidate nodes before the preset order of similarity sorted from high to low in any iteration are not cached in the first storage space, I / O blocking will occur. Asynchronous I / O operations can be used to read the second-level node representations of all candidate nodes before the preset order from the second storage space into the first storage space, thereby improving the cache hit rate.

[0094] Furthermore, in any iteration, when adding the neighboring nodes of the third candidate node to the candidate node set, considering that some neighboring nodes may have already been traversed in the previous iterations, the neighboring nodes of the third candidate node that have not been traversed can be added to the candidate node set. Specifically, the neighboring nodes of the third candidate node that have been traversed can be filtered out based on the explored node set.

[0095] Furthermore, since the iteration process may continuously add new candidate nodes to the candidate node set, in order to prevent the candidate node set from expanding indefinitely and the iteration process from failing to end, this embodiment can prune the candidate node set, retaining a preset number of candidate nodes with the highest similarity ranking, thus ensuring that the number of candidate nodes in the candidate node set does not exceed a preset number. The iteration process can end after the candidate node graph in the candidate node set has been traversed.

[0096] Since the candidate nodes that have completed the graph traversal are added to the set of explored nodes, one or more nodes are selected from the set of explored nodes in descending order of similarity after the bundle search process is completed to be determined as the second candidate nodes.

[0097] Based on the above embodiments, in each iteration of the beam search, the candidate node set is sorted from high to low according to its similarity to the third vector. Before a preset order (e.g., the first N nodes), a third candidate node with the highest similarity and whose second-level node is cached in the first storage space is selected. Specifically, the candidate node with the highest similarity to the third vector can be determined first, denoted here as the top-level candidate node, and B candidate nodes (B+1=N) with similarity after the top-level candidate node are determined. A lookahead set is constructed from these B candidate nodes. Further, it is first determined whether the second-level node data of the top-level candidate node is cached in the first storage space. If the second-level node data of the top-level candidate node is cached in the first storage space, then the top-level candidate node is also the aforementioned third candidate node. A graph traversal is performed directly on the top-level candidate node based on its second-level node data. If the second-level node data of the top-level candidate node is not cached in the first storage space... If the second node data is not cached in the first storage space, then the candidate node whose second node data is cached in the first storage space is selected from the lookup set in descending order of similarity as the aforementioned third candidate node. Based on the second node data of this candidate node, a graph traversal is performed on the candidate node. Asynchronous I / O operations can also be used to read the second node data of the top-level candidate node and the candidate nodes in the lookup set whose second node data is not cached in the first storage space from the second storage space to the first storage space. If the second node data of the top-level candidate node is not cached in the first storage space, and the second node data of all candidate nodes in the lookup set are not cached in the first storage space, then the top-level candidate node is processed by default, and the second node data of the top-level candidate node is read from the second storage space to the first storage space. Alternatively, the second node data of all candidate nodes in the lookup set can be read from the second storage space to the first storage space.

[0098] By combining the opportunistic exploration of candidate nodes in the first storage space with asynchronous data prefetching, I / O latency is effectively hidden, I / O stall time and overall query latency are reduced, and the cache hit rate during queries is optimized.

[0099] Corresponding to the vector retrieval method in the above embodiment, Figure 5 This is a structural block diagram of a vector retrieval device provided in an embodiment of this disclosure. For ease of explanation, only the parts relevant to the embodiments of this disclosure are shown. (Refer to...) Figure 5 The vector retrieval device 500 includes: a receiving unit 501, a compression unit 502, a first query unit 503, and a second query unit 504.

[0100] The receiving unit 501 is used to receive a vector retrieval request, the vector retrieval request including a first vector, and is used to request the retrieval of similar vectors of the first vector;

[0101] Compression unit 502 is used to compress the first vector according to a first compression ratio to obtain a second vector, and to compress the first vector according to a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio;

[0102] The first query unit 503 is used to query at least one first candidate node that is similar to the second vector from the first-level node representation of the nearest neighbor graph; wherein the nearest neighbor graph adopts a two-level node representation structure and a hierarchical storage method, wherein the first-level node representation is stored in a first storage space and includes a first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space and includes a second compressed vector of each node generated based on the second compressed vector and its adjacency list;

[0103] The second query unit 504 is configured to query a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on at least one first candidate node, and use the original vector of the second candidate node as the similar vector of the first vector.

[0104] The vector retrieval device provided in this embodiment receives a vector retrieval request, the vector retrieval request including a first vector, for requesting the retrieval of similar vectors of the first vector; compresses the first vector according to a first compression ratio to obtain a second vector, and compresses the first vector according to a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio; queries at least one first candidate node similar to the second vector from the first-level node representation of the nearest neighbor graph; wherein the nearest neighbor graph adopts a two-level node representation structure and adopts a hierarchical storage method, wherein the first-level node representation is stored in a first storage space, including a first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space, including a second compressed vector of each node and its adjacency list, the second compressed vector of each node being generated based on the second compression ratio; according to at least one first candidate node, queries a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph, and uses the original vector of the second candidate node as a similar vector of the first vector. This embodiment reduces storage resource consumption by pre-compressing and storing the node data of the nearest neighbor graph in a vector layer. It also improves query efficiency, reduces query latency, and reduces invalid I / O and I / O amplification by using the first-level node representation with a high compression ratio for preliminary querying and then using the second-level node representation with a low compression ratio for precise querying.

[0105] In one or more embodiments of this disclosure, the first storage space is memory, and the second storage space is a disk; the memory includes a slotted buffer pool, which represents the second-level nodes of a subset of nodes cached at the node granularity.

[0106] In one or more embodiments of this disclosure, when the second query unit 504 queries a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on at least one first candidate node, it is configured to:

[0107] The index data representing the second-level node of the at least one first candidate node is queried from the pre-stored index data set in the first storage space. The index data includes the node identifier and the storage location represented by the second-level node.

[0108] Based on the index data of the second-level node of the at least one first candidate node, if it is determined that the second-level node is cached in the first storage space, then the second candidate node is queried from the first storage space based on the second-level node representation of the at least one first candidate node;

[0109] Based on the index data of the second-level nodes of the at least one first candidate node, it is determined that the second-level node representation is cached in the second storage space. Then, the second-level node representation of the at least one candidate node is read from the second storage space and cached in the first storage space. The second candidate node is queried from the first storage space based on the second-level node representation of the at least one first candidate node.

[0110] In one or more embodiments of this disclosure, the first storage space is memory and the second storage space is a disk; on the disk, second-level nodes belonging to the affinity node set are placed continuously according to the set granularity, and different affinity node sets are distinguished by set tags within the storage page.

[0111] In one or more embodiments of this disclosure, the device further includes a storage unit for:

[0112] If the remaining space of the current storage page is insufficient to store a complete second-level node representation of an affinity node set, then the remaining space of the current storage page is used to store the second-level node representation of a node without affinity. When there is no second-level node representation of a node without affinity, the affinity node set is split into multiple subsets and stored in the current storage page and other storage pages.

[0113] In one or more embodiments of this disclosure, the second query unit 504 is further configured to:

[0114] When the second-level node representation of any first candidate node in the disk is read into the first storage space, the second-level node representations of other nodes with the same set label are also read into the first storage space.

[0115] In one or more embodiments of this disclosure, when the second query unit 504 queries a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on at least one candidate node, it is configured to:

[0116] Query tasks are processed in batches using multiple query coroutines on worker threads;

[0117] If the first query coroutine is blocked, control the worker thread to switch to the second query coroutine, which is in a ready state.

[0118] In one or more embodiments of this disclosure, the second query unit 504 is further configured to:

[0119] Any query coroutine enters a blocked state when it needs to read the second-level node representation of any node from the second storage space; and / or

[0120] Any query coroutine enters the ready state and is added to the queue of coroutines to be run when it does not need to read the second-level node representation of any node from the second storage space, or when it has finished reading the second-level node representation of any node from the second storage space.

[0121] Accordingly, if the first query coroutine is in a blocked state, the worker thread is controlled to switch to the second query coroutine, which is in a ready state.

[0122] The worker thread is controlled to pause the execution of the first query coroutine, and a second query coroutine is selected from the queue of coroutines to be run, and the second query coroutine is run on the worker thread.

[0123] In one or more embodiments of this disclosure, the second query unit 504, when querying a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on at least one first candidate node, is configured to:

[0124] A candidate node set is constructed based on the at least one first candidate node, and a beam search is performed on the candidate node set;

[0125] In each iteration of the beam search, each candidate node in the candidate node set is sorted according to its similarity to the third vector. The candidate node with the highest similarity and the second-level node representation is selected as the third candidate node cached in the first storage space. Based on the second-level node representation of the third candidate node, the neighboring nodes of the third candidate node are added to the candidate node set, and the third candidate node is migrated from the candidate node set to the explored node set.

[0126] After the beam search process is completed, one or more nodes are selected from the explored node set according to their similarity from high to low to determine them as the second candidate nodes.

[0127] In one or more embodiments of this disclosure, the second query unit 504 is further configured, in each iteration of the beam search, to:

[0128] The second-level nodes that are located before the preset order in the sorting and whose second-level nodes are not cached in the first storage space are read from the second storage space into the first storage space.

[0129] In one or more embodiments of this disclosure, after adding the neighboring nodes of the target candidate node to the candidate node set, the second query unit 504 is further configured to:

[0130] The candidate node set is pruned, retaining a preset number of candidate nodes whose similarity ranking is the highest.

[0131] The device provided in this embodiment can be used to execute the technical solutions of the above method embodiments. Its implementation principle and technical effect are similar, and will not be described again here.

[0132] To implement the above embodiments, this disclosure also provides an electronic device.

[0133] refer to Figure 6 The diagram illustrates a structural schematic of an electronic device 600 suitable for implementing embodiments of the present disclosure. The electronic device 600 can be a terminal device or a server. The terminal device can include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, personal digital assistants (PDAs), tablet computers, portable media players (PMPs), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 6 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.

[0134] like Figure 6As shown, electronic device 600 may include a processing unit (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 602 or a program loaded from storage device 608 into random access memory (RAM) 603. RAM 603 also stores various programs and data required for the operation of electronic device 600. The processing unit 601, ROM 602, and RAM 603 are interconnected via bus 604. Input / output (I / O) interface 605 is also connected to bus 604.

[0135] Typically, the following devices can be connected to I / O interface 605: input devices 606 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 607 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 608 including, for example, magnetic tapes, hard disks, etc.; and communication devices 609. Communication device 609 allows electronic device 600 to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 6 An electronic device 600 with various devices is shown; however, it should be understood that it is not required to implement or possess all of the devices shown. More or fewer devices may be implemented or possessed alternatively.

[0136] In particular, according to embodiments of this disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this disclosure include a computer program product comprising a computer program carried on a computer-readable storage medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 609, or installed from a storage device 608, or installed from a ROM 602. When the computer program is executed by a processing device 601, it performs the functions defined in the methods of embodiments of this disclosure.

[0137] It should be noted that the computer-readable storage medium described in this disclosure can be a computer-readable signal medium, a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this disclosure, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this disclosure, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable storage medium can be transmitted using any suitable medium, including but not limited to: wires, optical fibers, RF (radio frequency), etc., or any suitable combination thereof.

[0138] The aforementioned computer-readable storage medium may be included in the aforementioned electronic device; or it may exist independently and not assembled into the electronic device.

[0139] The aforementioned computer-readable storage medium carries one or more programs, which, when executed by the electronic device, cause the electronic device to perform the method shown in the above embodiments.

[0140] Computer program code for performing the operations of this disclosure can be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, and C++, and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0141] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.

[0142] The units described in the embodiments of this disclosure can be implemented in software or in hardware. The name of a unit does not necessarily limit the unit itself; for example, the first acquisition unit can also be described as "a unit that acquires at least two Internet Protocol addresses".

[0143] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), and so on.

[0144] The electronic device, computer-readable storage medium, and computer program product provided in this disclosure embodiment receive a vector retrieval request, the vector retrieval request including a first vector, for requesting the retrieval of similar vectors of the first vector; compress the first vector according to a first compression ratio to obtain a second vector, and compress the first vector according to a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio; query at least one first candidate node similar to the second vector from the first-level node representation of the nearest neighbor graph; wherein the nearest neighbor graph adopts a two-level node representation structure and adopts a hierarchical storage method, wherein the first-level node representation is stored in a first storage space, including a first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space, including a second compressed vector of each node and its adjacency list, the second compressed vector of each node being generated based on the second compression ratio; according to at least one first candidate node, query a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph, and use the original vector of the second candidate node as a similar vector of the first vector. This embodiment reduces storage resource consumption by pre-compressing and storing the node data of the nearest neighbor graph in a vector layer. It also improves query efficiency, reduces query latency, and reduces invalid I / O and I / O amplification by using the first-level node representation with a high compression ratio for preliminary querying and then using the second-level node representation with a low compression ratio for precise querying.

[0145] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.

[0146] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.

[0147] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.

Claims

1. A vector retrieval method, characterized in that, include: Receive a vector retrieval request, the vector retrieval request including a first vector, for requesting the retrieval of similar vectors of the first vector; The first vector is compressed at a first compression ratio to obtain a second vector, and the first vector is compressed at a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio; From the first-level node representation of the nearest neighbor graph, at least one first candidate node similar to the second vector is queried; wherein the nearest neighbor graph adopts a two-level node representation structure and adopts a hierarchical storage method, wherein the first-level node representation is stored in a first storage space, including the first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space, including the second compressed vector of each node generated based on the second compressed vector and its adjacency list; Based on the at least one first candidate node, a second candidate node similar to the third vector is queried in the second-level node representation of the nearest neighbor graph, and the original vector of the second candidate node is used as the similar vector of the first vector.

2. The method according to claim 1, characterized in that, The first storage space is memory, and the second storage space is a disk; the memory includes a slotted buffer pool, which represents the second-level nodes of some nodes cached at the node granularity.

3. The method according to claim 1, characterized in that, The step of querying a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on the at least one first candidate node includes: The index data represented by the second-level node of the at least one first candidate node is queried from the pre-stored index data set in the first storage space. The index data includes the node identifier and the storage location represented by the second-level node. Based on the index data of the second-level node of the at least one first candidate node, if it is determined that the second-level node is cached in the first storage space, then the second candidate node is queried from the first storage space based on the second-level node representation of the at least one first candidate node; Based on the index data of the second-level nodes of the at least one first candidate node, it is determined that the second-level node representation is cached in the second storage space. Then, the second-level node representation of the at least one candidate node is read from the second storage space and cached in the first storage space. The second candidate node is queried from the first storage space based on the second-level node representation of the at least one first candidate node.

4. The method according to claim 1, characterized in that, The first storage space is memory, and the second storage space is a disk. On the disk, the second-level nodes belonging to the affinity node set are placed continuously according to the set granularity, and different affinity node sets are distinguished by set tags within the storage page.

5. The method according to claim 4, characterized in that, The method further includes: If the remaining space of the current storage page is insufficient to store a complete second-level node representation of an affinity node set, then the remaining space of the current storage page is used to store the second-level node representation of a node without affinity. When there is no second-level node representation of a node without affinity, the affinity node set is split into multiple subsets and stored in the current storage page and other storage pages.

6. The method according to claim 4 or 5, characterized in that, The method further includes: When the second-level node representation of any first candidate node in the disk is read into the first storage space, the second-level node representations of other nodes with the same set label are also read into the first storage space.

7. The method according to claim 1, characterized in that, The step of querying a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on the at least one candidate node includes: Query tasks are processed in batches using multiple query coroutines on worker threads; If the first query coroutine is blocked, control the worker thread to switch to the second query coroutine, which is in a ready state.

8. The method according to claim 7, characterized in that, The method further includes: Any query coroutine enters a blocked state when it needs to read the second-level node representation of any node from the second storage space; and / or Any query coroutine enters the ready state and is added to the queue of coroutines to be run when it does not need to read the second-level node representation of any node from the second storage space, or when it has finished reading the second-level node representation of any node from the second storage space. Accordingly, if the first query coroutine is in a blocked state, the worker thread is controlled to switch to the second query coroutine, which is in a ready state. The worker thread is controlled to pause the execution of the first query coroutine, and a second query coroutine is selected from the queue of coroutines to be run, and the second query coroutine is run on the worker thread.

9. The method according to claim 1, characterized in that, The step of querying a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on the at least one first candidate node includes: A candidate node set is constructed based on the at least one first candidate node, and a beam search is performed on the candidate node set; In each iteration of the beam search, each candidate node in the candidate node set is sorted according to its similarity to the third vector. The candidate node with the highest similarity and the second-level node representation is selected as the third candidate node cached in the first storage space. Based on the second-level node representation of the third candidate node, the neighboring nodes of the third candidate node are added to the candidate node set, and the third candidate node is migrated from the candidate node set to the explored node set. After the beam search process is completed, one or more nodes are selected from the explored node set according to their similarity from high to low to determine them as the second candidate nodes.

10. A vector retrieval device, characterized in that, include: A receiving unit is configured to receive a vector retrieval request, wherein the vector retrieval request includes a first vector and is configured to request the retrieval of similar vectors of the first vector; A compression unit is configured to compress the first vector at a first compression ratio to obtain a second vector, and to compress the first vector at a second compression ratio to obtain a third vector; wherein the first compression ratio is higher than the second compression ratio. The first query unit is used to query at least one first candidate node that is similar to the second vector from the first-level node representation of the nearest neighbor graph; wherein the nearest neighbor graph adopts a two-level node representation structure and a hierarchical storage method, wherein the first-level node representation is stored in a first storage space and includes a first compressed vector of each node generated based on the first compression ratio; the second-level node representation is stored in the first storage space or the second storage space and includes a second compressed vector of each node generated based on the second compressed vector and its adjacency list; The second query unit is configured to query a second candidate node similar to the third vector in the second-level node representation of the nearest neighbor graph based on at least one first candidate node, and use the original vector of the second candidate node as the similar vector of the first vector.

11. An electronic device, characterized in that, include: Processor and memory; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-9.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, implement the method as described in any one of claims 1-9.

13. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-9.