A vector query method, device, equipment, medium and product in a database

By iteratively updating and mapping nodes level by level in the vector database, the input/output overhead caused by random access to node encoding vectors is resolved, thereby improving query efficiency and reducing memory usage.

CN123138252APending Publication Date: 2026-11-20WUHAN DAMENG DATABASE
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611562848.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-10
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

In vector databases, the encoding vectors of randomly accessed nodes result in significant input/output overhead, impacting retrieval efficiency.

Method used

By obtaining the query vector, codebook, and current node, and iteratively updating the current node based on the distance between the current node's neighboring nodes and the query vector, until a local minimum is identified, and mapping is performed level by level in the hierarchical graph until the full dense base layer is reached, the query result is determined, avoiding random reading that relies on neighboring node identifiers.

Benefits of technology

It reduces input/output overhead in the vector query process, improves query efficiency, and reduces memory usage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123138252A_ABST
    Figure CN123138252A_ABST
Patent Text Reader

Abstract

The application discloses a vector query method and device in a database, equipment, medium and product. Including: obtaining a query vector, a codebook and a current node; based on the first distance between the neighbor nodes of the current node and the query vector, iteratively updating the current node until a local minimum value is identified, and the current node corresponding to the local minimum value is determined as the local minimum value point of the current level; the local minimum value point is determined as the current node of the next level, the next level is determined as the new current level, the local minimum value point of the new current level is determined, and the process is repeated until the new current level is the full amount dense base layer in the hierarchical graph; in the case that the current level is the full amount dense base layer in the hierarchical graph, the second distance between the neighbor nodes of the current node and the query vector is determined, and based on the second distance and the access state of the corresponding neighbor node, the current node is iteratively updated until the access state of all current nodes indicates that it has been accessed. It can reduce the input and output overhead.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database technology, and in particular to a vector query method, apparatus, device, medium, and product for databases. Background Technology

[0002] Vector databases store datasets in vector form. The amount of vector data stored in vector databases typically reaches hundreds of millions, making direct searches extremely time-consuming.

[0003] Hierarchical Navigable Small World with Product Quantization (HNSWPQ) is an approximate nearest neighbor search algorithm that can retrieve nodes within a hierarchical navigable graph based on product quantization encoding. However, when calculating the distance between a node and the query vector during the retrieval process, it is necessary to randomly address and read the corresponding encoded vector based on the node's identifier, and then combine it with the codebook to complete the distance calculation. This generates a large amount of input / output (I / O) overhead, limiting the retrieval efficiency. Summary of the Invention

[0004] This invention provides a method, apparatus, device, medium, and product for vector querying in a database to solve the problem of large input / output overhead caused by the encoding vectors of random access nodes.

[0005] According to one aspect of the present invention, a vector query method for a database is provided, comprising: Obtain the query vector, codebook, and current node. The current node includes nodes at the current level in the hierarchical graph, which is constructed by mapping vector data in the vector database to nodes in multiple levels. Based on the first distance between the neighboring nodes of the current node and the query vector, the current node is iteratively updated until a local minimum is identified according to the first distance, and the current node corresponding to the local minimum is determined as the local minimum point of the current level. The mapping node of the local minimum point in the next level is determined as the current node of the next level, the next level is determined as the new current level, the local minimum point of the new current level is determined, until the new current level is the full dense base layer in the layered graph, and the current node of the full dense base layer is determined. When the current level is the full dense base layer in the layered graph, the second distance between the neighboring nodes of the current node and the query vector is determined. Based on the second distance and the access status of the corresponding neighboring nodes, the current node of the full dense base layer is iteratively updated until the access status of all current nodes indicates that they have been visited. The current node is selected as the query result according to the second distance. The neighboring node includes an encoding vector, which is indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoding vector, the query vector, and the codebook. The second distance is determined based on the encoding vector, the query vector, and the codebook.

[0006] According to another aspect of the present invention, a vector query apparatus for a database is provided, comprising: The acquisition module is used to acquire the query vector, codebook, and current node. The current node includes the node of the current level in the hierarchical graph. The hierarchical graph is constructed by mapping vector data in the vector database to nodes in multiple levels. The first determining module is used to iteratively update the current node based on the first distance between the neighboring nodes of the current node and the query vector, until a local minimum is identified based on the first distance, and determine the current node corresponding to the local minimum as the local minimum point of the current level. The second determining module is used to determine the mapping node of the local minimum point in the next level as the current node of the next level, determine the next level as the new current level, determine the local minimum point of the new current level, until the new current level is the full dense base layer in the layered graph, and determine the current node of the full dense base layer. The selection module is used to determine the second distance between the neighboring nodes of the current node and the query vector when the current level is the full dense base layer in the layered graph. Based on the second distance and the access status of the corresponding neighboring nodes, the current node of the full dense base layer is iteratively updated until the access status of all current nodes indicates that they have been visited. The current node is selected as the query result according to the second distance. The neighboring node includes an encoding vector, which is indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoding vector, the query vector, and the codebook. The second distance is determined based on the encoding vector, the query vector, and the codebook.

[0007] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the method described in any embodiment of the present invention.

[0008] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the method described in any embodiment of the present invention.

[0009] According to another aspect of the present invention, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the method described in any embodiment of the present invention.

[0010] The technical solution of this invention involves obtaining a query vector, a codebook, and a current node. The current node includes nodes at the current level in a hierarchical graph, which is constructed by mapping vector data in a vector database to nodes at multiple levels. Based on a first distance between the current node's neighboring nodes and the query vector, the current node is iteratively updated until a local minimum is identified according to the first distance. The current node corresponding to the local minimum is then determined as the local minimum point of the current level. The mapping node of the local minimum point at the next level is determined as the current node of the next level, and the next level is determined as the new current level. The local minimum point of the new current level is then determined until the new current level is the full dense base in the hierarchical graph. The process involves determining the current node of the full dense base layer in the layered graph. When the current layer is the full dense base layer in the layered graph, a second distance is determined between the current node's neighboring nodes and the query vector. Based on the second distance and the access status of the corresponding neighboring nodes, the current nodes of the full dense base layer are iteratively updated until the access status of all current nodes indicates that they have been accessed. The current node is then selected as the query result based on the second distance. The neighboring nodes include encoded vectors, which are indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoded vector, the query vector, and the codebook, and the second distance is determined based on the encoded vector, the query vector, and the codebook. This embodiment of the invention directly obtains the encoded vectors of the current node's neighboring nodes based on the current node, eliminating the need to traverse disk files and randomly read the complete data information of neighboring nodes based on their identifiers. This avoids the large input / output overhead caused by batch loading the encoded vectors of all corresponding neighboring nodes, improving vector query efficiency and effectively reducing memory usage during the vector query process.

[0011] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0012] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0013] Figure 1 This is a flowchart of a vector query method in a database provided in Embodiment 1 of the present invention; Figure 2 This is a flowchart of a vector query method in a database provided in Embodiment 2 of the present invention; Figure 3 This is a flowchart of a data persistence method provided in an embodiment of the present invention; Figure 4 This is a flowchart of a vector query method in the current level provided by an embodiment of the present invention; Figure 5 This is a flowchart of a vector query method in a full-scale dense base layer provided by an embodiment of the present invention; Figure 6 This is a schematic diagram of the structure of a vector query device in a database provided in Embodiment 3 of the present invention; Figure 7 A schematic diagram of an electronic device that can be used to implement embodiments of the present invention is shown. Detailed Implementation

[0014] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0015] It should be noted that the terms "comprising" and "having" and any variations thereof in the specification, claims and accompanying drawings of this invention are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are explicitly listed, but may include other steps or units that are not explicitly listed or that are inherent to such processes, methods, products or devices.

[0016] The HNSWPQ method combines Hierarchical Navigable Small World (HNSW) indexing and Product Quantization (PQ). The conventional storage scheme of the HNSWPQ method consists of two parts: memory is used to store the PQ codebook, metadata of the hierarchical graph, and entry points; disk is used to persistently store information about graph nodes (i.e., nodes in the hierarchical graph). Node information includes, but is not limited to, the node's identifier, its PQ encoded vector, and / or the identifiers of its neighboring nodes. Although product quantization can compress the original node vectors, accelerating distance calculation, during vector lookup, the HNSWPQ method needs to initiate addressing and reading operations one by one based on the identifiers of discretely distributed neighboring nodes. The random access characteristic of the hierarchical graph generates a large amount of random disk input / output and memory access overhead, which can easily cause retrieval lag. This invention reduces input / output overhead by directly carrying the encoded vectors of the current node's neighboring nodes in the current node's information.

[0017] Example 1 Figure 1 This is a flowchart illustrating a vector query method in a database according to Embodiment 1 of the present invention. This embodiment is applicable to situations where vector queries are performed based on hierarchical graphs in a vector database. The method can be executed by a vector query device in a database, which can be implemented in hardware and / or software and can be configured in an electronic device. For example, the electronic device can be a computer, server, or workstation. Figure 1 As shown, the method includes: S110. Obtain the query vector, codebook, and current node. The current node includes the node of the current level in the hierarchical graph. The hierarchical graph is constructed by mapping vector data in the vector database to nodes in multiple levels.

[0018] In this embodiment, the query vector can be a vector used for matching in a vector database. The query vector can be obtained through a specific data interface call or extracted from a specific field of a structured query statement; this invention does not impose any limitations on this. The codebook can be a codebook used to encode vectors. The codebook can be a product quantization codebook. The codebook can be maintained by the vector database. The codebook can be constructed before performing a vector query. The vector database can be a database used to store vectors. Vector data can be vectors in the vector database.

[0019] For example, the codebook construction process includes: selecting vectors from a vector database as samples, dividing the samples into multiple sub-vectors, clustering the sub-vectors, and using the cluster centers obtained from the clustering as the codebook.

[0020] The current node can be the node currently being processed. A node can indicate vector data in a vector database. A node can be represented as an index with a specific structure. For example, a node can include an index indicating a vector, a vector encoding, and an index indicating the vector's position in the hierarchical graph. The hierarchical graph can consist of multiple nodes, containing a topological structure with multiple levels. A node can be distributed across multiple levels. The current level can be the level currently being processed. The current level can be one of several levels corresponding to the current node.

[0021] Specifically, the query vector is retrieved and loaded into memory; the codebook is retrieved from the vector database and loaded into memory; and the current node is read from disk and loaded into memory.

[0022] S120. Based on the first distance between the neighboring nodes of the current node and the query vector, iteratively update the current node until a local minimum is identified according to the first distance, and determine the current node corresponding to the local minimum as the local minimum point of the current level.

[0023] The neighboring node includes an encoding vector, which is indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoding vector, the query vector, and the codebook.

[0024] In this embodiment, a neighboring node can be a node that is topologically adjacent to the current node at the current level. The topology can be understood as the layout of nodes within a hierarchical graph. The location of a node is not limited to physical storage location; it can also be a logical location. Nodes topologically adjacent to the current node can involve multiple different levels. In this invention, a neighboring node is a node at the current level. The neighboring node can be determined based on the current node.

[0025] For example, the current node may carry information describing its neighboring nodes. This information may be used to indicate neighboring nodes and / or their corresponding vectors. The vectors corresponding to the neighboring nodes may be encoded based on a codebook and then stored in the information.

[0026] The first distance can be the distance between the vector corresponding to a neighboring node in the current level and the query vector. The first distance can be determined based on the encoding of the vector corresponding to the neighboring node and the encoding of the query vector. The smaller the first distance, the closer the vector corresponding to the neighboring node is to the query vector. A local minimum can be the minimum first distance between the neighboring nodes of each current node and the query vector in the current level. A local minimum point can be the node corresponding to the vector closest to the query vector in the current level. A local minimum point can be the current node corresponding to the minimum first distance. The encoded vector can be the encoded result obtained by encoding the vector according to the codebook. The encoded vector can be a PQ encoded vector.

[0027] Specifically, based on the information carried by the current node, the neighboring nodes and their corresponding encoding vectors of the current node are directly retrieved from memory. The query vector is encoded based on the codebook, and the first distance between the current node's neighboring nodes and the query vector is determined based on the encoded query vector and the encoding vector. The minimum value of the first distance corresponding to the current node is recorded, and the neighboring node corresponding to the minimum value is determined as the new current node. The current node and the minimum value are updated again based on the first distance between the current node's neighboring nodes and the query vector. If the minimum value of the current node is not less than the minimum value of the previous current node, then the minimum value of the previous current node is identified as a local minimum, and the corresponding previous current node is determined as a local minimum point.

[0028] S130. Determine the mapping node of the local minimum point in the next level as the current node of the next level, determine the next level as the new current level, determine the local minimum point of the new current level, until the new current level is the full dense base layer in the layered graph, and determine the current node of the full dense base layer.

[0029] In this embodiment, the next level can be the level below the current level in the layered graph. The next level and the current level are distinguished by their logical order. By traversing the layered graph level by level, the scope of vector queries can be narrowed, improving the efficiency of vector queries. A mapping node can be a mapping of the current node to the next level. A mapping node can also be a copy of the current node to the next level. The full dense base layer can be the logical last layer in the layered graph.

[0030] Specifically, the local minimum point obtained at the current level is inherited as the current node of the next level, and the next level is processed as the current level. Local minimum points are determined level by level until the full dense base layer of the layered graph is traversed. The local minimum point of the previous level of the full dense base layer is determined as the current node of the full dense base layer.

[0031] For example, the current node also includes cross-level links. A cross-level link can be a link from the current node to its corresponding node in the next level. The corresponding node in the next level can be a copy of the current node. The copy can be a logical copy. Based on the cross-level link, you can enter the next level and use the corresponding node in the next level as the current node.

[0032] S140. When the current level is the full dense base layer in the layered graph, determine the second distance between the neighboring nodes of the current node and the query vector. Based on the second distance and the access status of the corresponding neighboring nodes, iteratively update the current node of the full dense base layer until the access status of all the current nodes indicates that they have been visited. Select the current node as the query result according to the second distance.

[0033] The second distance is determined based on the encoding vector, the query vector, and the codebook.

[0034] In this embodiment, the second distance can be the distance between the neighboring nodes of the current node in the full dense base layer and the query vector. The second distance can be determined based on the encoding vectors of the neighboring nodes indicated by the current node and the encoding of the query vector. The access status can be an indication of whether a node in the full dense base layer has been accessed. The access status can be indicated by a specific identifier appended to the node. The query result can be the result obtained by querying based on the query vector. The query result can be represented as a vector or a unique identifier of the node.

[0035] Specifically, in the full-dense base layer, the second distance between the current node's neighboring nodes and the query vector is determined and recorded. The maximum value among the recorded second distances is determined. If a second distance smaller than the maximum value exists, and the access status of the corresponding neighboring node indicates it has not been visited, then that neighboring node is designated as the new current node. Since multiple current nodes may be determined at once, the current nodes are visited one by one according to the order of their second distances from the query vector, and their access status is updated until all current nodes indicate they have been visited. The current node with the smallest second distance from the query vector among all current nodes is selected as the query result.

[0036] The technical solution of this invention involves obtaining a query vector, a codebook, and a current node. The current node includes nodes at the current level in a hierarchical graph, which is constructed by mapping vector data in a vector database to nodes at multiple levels. Based on a first distance between the current node's neighboring nodes and the query vector, the current node is iteratively updated until a local minimum is identified according to the first distance. The current node corresponding to the local minimum is then determined as the local minimum point of the current level. The mapping node of the local minimum point at the next level is determined as the current node of the next level, and the next level is determined as the new current level. The local minimum point of the new current level is then determined until the new current level is the full dense base in the hierarchical graph. The process involves determining the current node of the full dense base layer in the layered graph. When the current layer is the full dense base layer in the layered graph, a second distance is determined between the current node's neighboring nodes and the query vector. Based on the second distance and the access status of the corresponding neighboring nodes, the current nodes of the full dense base layer are iteratively updated until the access status of all current nodes indicates that they have been accessed. The current node is then selected as the query result based on the second distance. The neighboring nodes include encoded vectors, which are indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoded vector, the query vector, and the codebook, and the second distance is determined based on the encoded vector, the query vector, and the codebook. This embodiment of the invention directly obtains the encoded vectors of the current node's neighboring nodes based on the current node, eliminating the need to traverse disk files and randomly read the complete data information of neighboring nodes based on their identifiers. This avoids the large input / output overhead caused by batch loading the encoded vectors of all corresponding neighboring nodes, improving vector query efficiency and effectively reducing memory usage during the vector query process.

[0037] In one embodiment, the current node includes an entry point, and obtaining the codebook and the current node includes: S1101. Obtain the metadata file, which includes the metadata information and codebook of the layered graph.

[0038] In this embodiment, the metadata file can be understood as a file that stores the metadata of the vector database. The metadata file can be persistently stored on disk and maintained periodically by the vector database. The metadata information can be information used to describe the metadata of the hierarchical graph. For example, the metadata information may include the number of nodes in the hierarchical graph, the identifier of the node located at the entrance of the hierarchical graph, the calculation method of the level and / or distance, etc.

[0039] Specifically, a metadata file is read from the disk through a specific data interface, and the codebook and metadata information in the metadata file are loaded into memory.

[0040] S1102. Read the entry point from the metadata information, the entry point including the entry point of the layered graph.

[0041] In this embodiment, the entry point can be the top-level entry point in the hierarchical graph. The entry point can serve as the first queried node in the hierarchical graph. The entry point can be used to initialize the current node.

[0042] Specifically, the entry point identifier is obtained from the metadata information, and the entry point is located in the hierarchical graph based on the entry point identifier, and the entry point is taken as the first current node.

[0043] In one embodiment, the step of iteratively updating the current nodes of the full dense base layer based on the second distance and the access status of the corresponding neighbor nodes until the access status of all current nodes indicates that they have been visited includes: S1401. Determine the current node in the full dense base layer as a candidate node and add it to the candidate queue.

[0044] In this embodiment, the candidate queue can be a queue used to maintain accessed and unaccessed nodes. The candidate queue can store the identifiers of the current nodes that have been accessed and those that have not. During initialization, the first accessed current node in the full dense base layer can be added to the candidate queue. The current nodes maintained in the candidate queue can be designated as candidate nodes.

[0045] Specifically, the current node in the full dense base layer is added to the candidate queue as a candidate node, and the access status of the candidate node can be unvisited.

[0046] S1402. Select the candidate node with the smallest candidate distance from the candidate queue, and the access identifier indicates that the node has not been visited, as the target candidate node. Update the corresponding access identifier to indicate that the node has been visited. The candidate distance includes the distance between the candidate node and the query vector. The access identifier indicates whether the current node has been visited. The candidate node includes nodes in the candidate queue.

[0047] In this embodiment, the candidate distance can be the distance between a candidate node and the query vector. The candidate distance can be maintained by a candidate queue. The access identifier can be an identifier indicating the access status, and it is maintained by the candidate node. The access identifier can be a Boolean value, which is not limited herein. The target candidate node can be the candidate node with the smallest candidate distance in the candidate queue and whose access identifier indicates that it has not been visited.

[0048] Specifically, from the candidate queue, the candidate node with the smallest candidate distance and whose access identifier indicates that it has not been visited is selected as the target candidate node. The access identifier of the target candidate node is then updated to indicate that the target candidate node has been visited.

[0049] S1403. Determine the third distance between the candidate neighbor nodes of the target candidate node and the query vector. Add the candidate neighbor nodes whose third distance is less than the maximum distance and whose access identifier indicates that they have not been accessed to the candidate node as the candidate node into the candidate queue. Use the third distance as the corresponding candidate distance. The maximum distance includes the largest candidate distance in the candidate queue.

[0050] In this embodiment, a candidate neighbor node can be a neighbor node of the target candidate node in the full dense base layer. The maximum distance can be the largest candidate distance in the candidate queue. The maximum distance can dynamically change as candidate nodes are added to the candidate queue. The third distance can be the distance between a candidate neighbor node and the query vector. The third distance can be determined based on the encoding vector of the candidate neighbor node and the encoding of the query vector. The encoding vector of the candidate neighbor node is indicated by the target candidate node.

[0051] Specifically, based on the vector encoding of the candidate neighbor nodes and the codebook-based encoding of the query vector, the third distance between the candidate neighbor nodes of the target candidate node and the query vector is determined. Candidate neighbor nodes whose third distance is less than the maximum distance are identified as candidate nodes, their corresponding access flags are initialized to indicate that they have not been accessed, and their corresponding third distances are used as candidate distances.

[0052] S1404. Repeatedly select and access the candidate nodes from the candidate queue until all the candidate nodes in the candidate queue have been accessed.

[0053] Specifically, the process involves repeatedly selecting unvisited candidate nodes from the candidate queue that have a candidate distance less than the maximum distance, and visiting them as target candidate nodes, until all candidate nodes in the candidate queue have been visited.

[0054] For example, the maximum number of candidate nodes in the candidate queue can be a preset number. The preset number can be a number preset based on experience before performing a vector query, or a number preset based on the dimension of the query vector during the vector query; this invention does not impose any limitations on this. When the number of candidate nodes in the candidate queue reaches the maximum number, no more candidate neighbor nodes are added to the candidate queue as candidate nodes. Instead, candidate nodes in the candidate queue are selected and visited until all candidate nodes in the candidate queue have been visited.

[0055] In one embodiment, the candidate queue includes candidate nodes sorted in ascending order according to the candidate distance, and the step of selecting the current node as the query result based on the second distance includes: The first candidate node in the candidate queue is selected as the query result.

[0056] Specifically, since the candidate nodes in the candidate queue are sorted in ascending order of candidate distance, after all candidate nodes in the candidate queue have been visited, the candidate node at the head of the candidate queue is the node closest to the query vector, and the candidate node at the head of the candidate queue is used as the query result.

[0057] Example 2 Figure 2 This is a flowchart illustrating a vector query method in a database according to Embodiment 2 of the present invention. This embodiment is an optimization based on any of the above embodiments, and mainly includes a detailed description of the process for determining local extreme points in the current level. It should be noted that technical details not described in detail in this embodiment can be found in any of the above embodiments. Figure 2 As shown, the method includes: S210. Obtain the query vector, codebook, and current node, wherein the current node includes the node of the current level in the hierarchical graph.

[0058] S220. Based on the identifier of the current node, locate the node data file corresponding to the current node and determine the encoding vector of the neighboring nodes of the current node.

[0059] In this embodiment, the node data file can be a file used to store information about nodes in a hierarchical graph. Each node can correspond to one node data file. The node data file can be persistently stored on disk. The node data file can be in tabular form. The node data file can indicate, for example, the unique identifier of the node, the unique identifiers of the nodes adjacent to the node, the hierarchy of the nodes adjacent to the node, the node's encoding vector, and / or the encoding vectors of the nodes adjacent to the node. When determining the encoding vectors of neighboring nodes, it is not necessary to read the corresponding encoding vectors from disk separately for each neighboring node. Only the node data file of the current node needs to be read to obtain the encoding vectors of all neighboring nodes corresponding to the current node at once. Replacing multiple random address reads with a single read of the node data file effectively reduces input / output overhead and alleviates memory pressure, thereby improving query efficiency.

[0060] Specifically, based on the identifier of the current node, the node data file corresponding to the current node is located on the disk, loaded into memory, and the encoding vectors of the current node's neighboring nodes are obtained from the node data file.

[0061] Optionally, the node data file includes at least one of the following: the identifier of the current node, the encoding vector of the current node, an array of identifiers of the current node's neighboring nodes, and an array of encoding vectors of the current node's neighboring nodes.

[0062] In this embodiment, the identifier can be a unique identifier for the node. For example, the identifier can be a name or number, etc. The identifier array can be an array formed by the identifiers of neighboring nodes. The encoding vector array can be an array composed of the encoding vectors of neighboring nodes. The elements in the encoding vector array correspond one-to-one with the elements in the identifier array.

[0063] Specifically, the node data file includes at least: the identifier of the current node, the encoding vector of the current node, an array of identifiers of the current node's neighboring nodes, and / or an array of encoding vectors of the current node's neighboring nodes.

[0064] S230. Based on the encoding vector, the query vector, and the codebook, determine the first distance between the neighboring nodes of the current node and the query vector, and the minimum value of the first distance.

[0065] Specifically, the query vector is quantized and encoded according to the codebook. The encoded vector and the query vector are added bit by bit. The sum of each bit is accumulated and the sum is used as the first distance between the neighboring node and the query vector. The minimum value of the first distances among all the neighboring nodes of the current node is determined.

[0066] S240. The neighbor node corresponding to the minimum value is determined as the new current node. The current node is updated and the minimum value is determined repeatedly according to the first distance until a local minimum value is identified according to the minimum value. The current node corresponding to the local minimum value is determined as the local minimum point of the current level.

[0067] Specifically, the neighboring node corresponding to the minimum value is determined as the new current node. The first distance between the neighboring nodes of the current node and the query vector is determined, and the corresponding minimum value is determined, until the minimum value is no longer monotonically decreasing. The minimum of the minimum is identified as a local minimum, and the current node corresponding to the local minimum is determined as the local minimum point of the current level.

[0068] S250. Determine the mapping node of the local minimum point in the next level as the current node of the next level, determine the next level as the new current level, determine the local minimum point of the new current level, until the new current level is the full dense base layer in the layered graph, and determine the current node of the full dense base layer.

[0069] S260. When the current level is the full dense base layer in the layered graph, determine the second distance between the neighboring nodes of the current node and the query vector. Based on the second distance and the access status of the corresponding neighboring nodes, iteratively update the current node of the full dense base layer until the access status of all current nodes indicates that they have been visited. Select the current node as the query result according to the second distance.

[0070] The neighboring node includes an encoding vector, which is indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoding vector, the query vector, and the codebook. The second distance is determined based on the encoding vector, the query vector, and the codebook.

[0071] The technical solution of this invention involves obtaining a query vector, a codebook, and a current node, where the current node includes nodes at the current level in a hierarchical graph. Based on the identifier of the current node, the node data file corresponding to the current node is searched to determine the encoding vectors of the current node's neighboring nodes. Based on the encoding vectors, the query vector, and the codebook, a first distance between the current node's neighboring nodes and the query vector, and the minimum value of the first distance, are determined. The neighboring node corresponding to the minimum value is identified as the new current node. The process of updating the current node based on the distance and determining the minimum value is repeated until a local minimum is identified based on the minimum value. The current node corresponding to the local minimum is identified as the local minimum point at the current level. The mapping node of the local minimum point at the next level is identified as the current node at the next level, and the next level is identified as the new current level. The system first determines the local minimum point of the new current level until the new current level is a full dense base layer in the layered graph, and then determines the current node of the full dense base layer. If the current level is a full dense base layer in the layered graph, it determines the second distance between the neighboring nodes of the current node and the query vector. Based on the second distance and the access status of the corresponding neighboring nodes, iteratively updates the current nodes of the full dense base layer until the access status of all current nodes indicates that they have been accessed. The current node is then selected as the query result based on the second distance. The neighboring nodes include encoding vectors, which are indicated by the current node corresponding to the neighboring nodes. The first distance is determined based on the encoding vector, the query vector, and the codebook, and the second distance is determined based on the encoding vector, the query vector, and the codebook. The technical solution of this invention obtains the encoding vectors of neighboring nodes based on the node data file, avoiding the large input / output overhead caused by batch loading the encoding vectors of all corresponding neighboring nodes. By reading the node data file of the current node on the disk only once to obtain the encoding vectors of all corresponding neighboring nodes, the efficiency of vector query is improved and the memory usage during the vector query process is reduced.

[0072] In one embodiment, determining the first distance between the neighboring nodes of the current node and the query vector based on the encoding vector, the query vector, and the codebook includes: S2301. Determine the vector table of the query vector based on the codebook and the query vector.

[0073] In this embodiment, the vector table can be an encoded vector obtained by encoding the query vector according to the codebook.

[0074] Specifically, based on the codebook, the query vector is split into several sub-vectors, and each sub-vector is encoded with each cluster center in the codebook. A vector table is then formed based on the index of the sub-vector and its corresponding encoding.

[0075] S2302. Determine the first distance between the neighbor node and the query vector based on the encoded vector and the vector table.

[0076] Specifically, determine the sub-vector corresponding to each element in the encoding vector, look up the corresponding code in the vector table based on the index of the sub-vector, determine the sum of the element and the corresponding code for each element, accumulate the sums, and obtain the first distance between the neighboring node and the query vector.

[0077] In one example Figure 3 This is a flowchart of a data persistence method provided by an embodiment of the present invention. First, before vector querying, a codebook (i.e., a PQ codebook) is constructed based on the vectors in the vector database. The vectors in the vector database are then encoded using the PQ codebook. Based on the vector encoding (i.e., PQ encoding) of the vectors in the vector database, nodes in a hierarchical graph are formed, and each node constitutes the hierarchical graph. Metadata information of the hierarchical graph and the PQ codebook are collected and written to a metadata file. All nodes in the hierarchical graph are traversed. For each node, the node's identifier (i.e., node identifier (ID)), the node's vector encoding (i.e., PQ encoding), and the identifier array of neighboring nodes (i.e., neighbor ID array) are obtained. Based on the neighboring node's identifier array, the neighboring node's encoded vector array (i.e., neighbor's PQ encoding) is obtained. The node's identifier, node's vector encoding, neighboring node's identifier array, and neighboring node's encoded vector array are written to a node data file. The metadata file and node data file are persistently saved on disk.

[0078] In one example Figure 4This is a flowchart of a vector query method in the current layer provided by an embodiment of the present invention. First, the codebook (i.e., the PQ codebook) and the metadata information of the layered graph are loaded into memory from the metadata file. The entry point is loaded from the metadata information. The query vector is encoded according to the codebook to obtain the vector table (i.e., the PQ distance table). Traversal begins from the top layer of the layered graph, and the traversed layer is determined as the current layer. The current node in the current layer is determined, and the neighboring nodes of the current node are traversed. The neighboring node with the smallest first distance is taken as the new current node. It is determined whether there is a neighboring node with an even smaller first distance among the current node's neighbors. If there is, the current node is updated. If not, a local minimum is identified, and the node corresponding to the local minimum is taken as the local minimum point. The next node can be accessed through cross-layer links from the local minimum point. The local minimum point of the previous layer is taken as the starting point of the next layer, and the starting point is taken as the current node. The next layer is taken as the current layer, and the layered graph is traversed level by level until the current layer is a fully dense base layer.

[0079] In one example Figure 5 This is a flowchart of a vector query method in a full-dense base layer provided by an embodiment of the present invention. The method involves initializing a candidate queue, adding the first current node in the full-dense base layer to the candidate queue, retrieving the nearest unvisited candidate node from the queue as the target candidate node, marking the target candidate node as visited, and determining the third distance between the target candidate node's candidate neighbor nodes and the query vector. If the third distance is less than the maximum distance (i.e., closer than the farthest point in the candidate queue, the farthest point being the candidate node corresponding to the maximum value) and the candidate queue is not full (i.e., the number of candidate nodes in the candidate queue is less than a preset maximum number), then the candidate neighbor node is added as a candidate node to the candidate queue, and the third distance is used as the candidate distance. The nodes are then sorted in ascending order according to the corresponding candidate distance. Otherwise, the method continues to visit candidate nodes in the candidate list until all candidate nodes in the candidate list have been visited. Finally, the vector or node identifier corresponding to the first candidate node in the candidate queue is returned as the query result. The present invention will be described by way of example below: In one example, the method for persistently saving metadata files and node data files includes: training a PQ codebook (i.e., codebook), PQ encoding vectors (i.e., node encoding vectors) and an HNSW graph structure (i.e., a hierarchical graph) in memory; storing the metadata information of the graph (i.e., the hierarchical graph) (including the number of nodes (i.e., the number of nodes in the hierarchical graph), entry point ID (i.e., the identifier of the entry point), the graph hierarchy, distance calculation method, etc.) and the PQ codebook into the metadata file, as shown in Table 1.

[0080] Table 1 Metadata File Structure Each node in the hierarchical graph is constructed according to the following format: node ID (i.e., node identifier), PQ encoding vector (i.e., node encoding vector), neighbor ID array (i.e., neighbor node identifier array), and neighbor PQ encoding vector array (i.e., neighbor node encoding vector array). The node is stored in a data file (i.e., node data file). The format of the node data file is shown in Table 2.

[0081] Table 2 Node Data File Structure In one example, a vector query method in a database includes: loading the metadata information of a graph from a metadata file and the PQ codebook into memory; loading the entry point from the metadata file into memory; loading the node data file of the entry point into memory based on the identifier of the entry point; and calculating the PQ distance table (i.e., the vector table) using the target vector q (i.e., the query vector) and the PQ codebook.

[0082] In the upper layer (i.e., the current level of the non-full dense base layer), the entry point uses the PQ encoded vector array of the neighbors to quickly calculate the distance (i.e., the first distance) with the query vector through the PQ distance table, selects the nearest neighbor (i.e. the neighbor node corresponding to the minimum value) and loads it into memory as the new current position (i.e., the current node), and repeats this process until the local minimum (i.e., the local minimum value) of the layer (i.e., the current level) is reached.

[0083] After the current level search is completed, jump to the next level using cross-level connections between nodes, and use the nearest point found in the upper level (i.e., the local minimum point) as the starting point of the lower level (i.e., the current node) to repeat the search process.

[0084] A fine-grained search is performed in the full dense base layer, including: maintaining a top_k queue (i.e., the candidate queue, where k is the maximum number of candidate nodes in the candidate queue), sorted in ascending order by distance (i.e., candidate distance). Initially, the starting point (i.e., the current node) is added to the queue (i.e., the candidate queue). The candidate node (i.e., the target candidate node) that is closest in distance (i.e., the third distance) and has not been visited is taken from the queue. The distance between the neighbor and the query vector is calculated using the PQ encoded vector array of its neighbors (i.e., the third distance between the candidate neighbor nodes of the target candidate node and the query vector), and the current node is marked as visited (i.e., the corresponding visit flag is updated to indicate that it has been visited). If a neighbor is closer and has not been visited, it is loaded into memory and added to the candidate queue (i.e., the candidate neighbor node whose third distance is less than the maximum distance and whose visit flag indicates that it has not been visited is added to the candidate queue as a candidate node). This process is repeated until all nodes in the queue have been visited.

[0085] Example 3 Figure 6 This is a schematic diagram of a vector query device in a database provided in Embodiment 3 of the present invention. Figure 6 As shown, the device includes: The acquisition module 610 is used to acquire the query vector, codebook and current node. The current node includes the node of the current level in the hierarchical graph. The hierarchical graph is constructed by mapping vector data in the vector database to nodes in multiple levels. The first determining module 620 is used to iteratively update the current node based on the first distance between the neighboring nodes of the current node and the query vector, until a local minimum is identified based on the first distance, and determine the current node corresponding to the local minimum as the local minimum point of the current level. The second determining module 630 is used to determine the mapping node of the local minimum point in the next level as the current node of the next level, determine the next level as the new current level, determine the local minimum point of the new current level, until the new current level is the full dense base layer in the layered graph, and determine the current node of the full dense base layer. The selection module 640 is used to determine the second distance between the neighboring nodes of the current node and the query vector when the current level is the full dense base layer in the layered graph. Based on the second distance and the access status of the corresponding neighboring nodes, the current node of the full dense base layer is iteratively updated until the access status of all the current nodes indicates that they have been visited. The current node is selected as the query result according to the second distance. The neighboring node includes an encoding vector, which is indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoding vector, the query vector, and the codebook. The second distance is determined based on the encoding vector, the query vector, and the codebook.

[0086] The technical solution of this invention involves acquiring a query vector, a codebook, and a current node through an acquisition module. The current node includes nodes at the current level in a hierarchical graph, which is constructed by mapping vector data in a vector database to nodes at multiple levels. A first determining module iteratively updates the current node based on a first distance between its neighboring nodes and the query vector until a local minimum is identified based on the first distance. The current node corresponding to the local minimum is then determined as the local minimum point at the current level. A second determining module determines the mapping node of the local minimum point at the next level as the current node at the next level, designates the next level as the new current level, and determines the local minimum point at the new current level until the new current level is a node in the hierarchical graph. A full dense base layer is used to determine the current node of the full dense base layer. When the current level is the full dense base layer in the layered graph, a selection module determines a second distance between the current node's neighboring nodes and the query vector. Based on the second distance and the access status of the corresponding neighboring nodes, the current node of the full dense base layer is iteratively updated until the access status of all current nodes indicates that they have been accessed. The current node is then selected as the query result based on the second distance. The neighboring nodes include encoded vectors, which are indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoded vector, the query vector, and the codebook, and the second distance is determined based on the encoded vector, the query vector, and the codebook. This embodiment of the invention directly obtains the encoded vectors of the current node's neighboring nodes based on the current node, eliminating the need to traverse disk files and randomly read the complete data information of neighboring nodes based on their identifiers. This avoids the large input / output overhead caused by batch loading the encoded vectors of all corresponding neighboring nodes, improving vector query efficiency and effectively reducing memory usage during the vector query process.

[0087] In one embodiment, the current node includes an entry point, and the acquisition module 610 is specifically used for: Obtain the metadata file, which includes the metadata information and codebook of the hierarchical graph; The entry point is read from the metadata information, and the entry point includes the entry point of the hierarchical graph.

[0088] In one embodiment, the first determining module 620 further includes: The lookup unit is used to find the node data file corresponding to the current node based on the identifier of the current node, and to determine the encoding vectors of the neighboring nodes of the current node; The first determining unit is configured to determine, based on the encoding vector, the query vector, and the codebook, a first distance between the neighboring nodes of the current node and the query vector, and the minimum value of the first distance; The second determining unit is used to determine the neighbor node corresponding to the minimum value as the new current node, repeatedly update the current node according to the first distance and determine the minimum value, until a local minimum value is identified according to the minimum value.

[0089] In one embodiment, the node data file includes at least one of the following: the identifier of the current node, the encoding vector of the current node, an array of identifiers of the current node's neighboring nodes, and an array of encoding vectors of the current node's neighboring nodes.

[0090] In one embodiment, the first determining unit is specifically used for: Based on the codebook and the query vector, determine the vector table of the query vector; Based on the encoded vector and the vector table, a first distance between the neighbor node and the query vector is determined.

[0091] In one embodiment, module 640 is selected and is specifically used for: The current node in the full dense base layer is identified as a candidate node and added to the candidate queue; Select the candidate node with the smallest candidate distance from the candidate queue and whose access identifier indicates that it has not been visited as the target candidate node, and update the corresponding access identifier to indicate that it has been visited. The candidate distance includes the distance between the candidate node and the query vector. The access identifier indicates whether the current node has been visited. The candidate node includes the nodes in the candidate queue. Determine the third distance between the candidate neighbor nodes of the target candidate node and the query vector. Add the candidate neighbor nodes whose third distance is less than the maximum distance and whose access identifier indicates that they have not been visited to the candidate node as the candidate node in the candidate queue. Use the third distance as the corresponding candidate distance. The maximum distance includes the largest candidate distance in the candidate queue. Repeatedly select and access the candidate nodes from the candidate queue until all the candidate nodes in the candidate queue have been accessed.

[0092] In one embodiment, the candidate queue includes candidate nodes sorted in ascending order according to the candidate distance, and the selection module 640 is specifically used for: The first candidate node in the candidate queue is selected as the query result.

[0093] The vector query device for a database provided in this embodiment of the invention can execute a vector query method for a database provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method execution.

[0094] Example 4 Figure 7 A schematic diagram of an electronic device that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0095] like Figure 7 As shown, the electronic device 710 includes at least one processor 711 and a memory, such as a read-only memory (ROM) 712 or a random access memory (RAM) 713, communicatively connected to the at least one processor 711. The memory stores computer programs executable by the at least one processor. The processor 711 can perform various appropriate actions and processes based on the computer program stored in the ROM 712 or loaded from storage unit 718 into the RAM 713. The RAM 713 can also store various programs and data required for the operation of the electronic device 710. The processor 711, ROM 712, and RAM 713 are interconnected via a bus 714. An input / output (I / O) interface 715 is also connected to the bus 714.

[0096] Multiple components in electronic device 710 are connected to I / O interface 715, including: input unit 716, such as keyboard, mouse, etc.; output unit 717, such as various types of displays, speakers, etc.; storage unit 718, such as disk, optical disk, etc.; and communication unit 719, such as network card, modem, wireless transceiver, etc. Communication unit 719 allows electronic device 710 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0097] Processor 711 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 711 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 711 performs the various methods and processes described above, such as the methods proposed in this invention.

[0098] In some embodiments, the method proposed in this invention can be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 718. In some embodiments, part or all of the computer program can be loaded and / or installed on electronic device 710 via ROM 712 and / or communication unit 719. When the computer program is loaded into RAM 713 and executed by processor 711, one or more steps of the method described above can be performed. Alternatively, in other embodiments, processor 711 can be configured to perform the method proposed in this invention by any other suitable means (e.g., by means of firmware).

[0099] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard parts (ASSPs), systems-on-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0100] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0101] In the context of this invention, a computer-readable storage medium stores computer instructions that are used to cause a processor to execute and implement the method provided by this invention.

[0102] The present invention also provides a computer program product comprising a computer program that, when executed by a processor, implements the method provided according to embodiments of the present invention.

[0103] Computer-readable storage media can be tangible media that may contain or store computer programs for use by or in conjunction with an instruction execution system, apparatus, or device. Computer-readable storage media can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0104] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device for displaying information to the user, such as a cathode ray tube (CRT) or a liquid crystal display (LCD); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0105] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0106] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system. It addresses the shortcomings of traditional physical hosts and Virtual Private Server (VPS) services, such as high management difficulty and weak business scalability.

[0107] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0108] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A vector query method in a database, characterized in that, include: Obtain the query vector, codebook, and current node. The current node includes nodes at the current level in the hierarchical graph, which is constructed by mapping vector data in the vector database to nodes in multiple levels. Based on the first distance between the neighboring nodes of the current node and the query vector, the current node is iteratively updated until a local minimum is identified according to the first distance, and the current node corresponding to the local minimum is determined as the local minimum point of the current level. The mapping node of the local minimum point in the next level is determined as the current node of the next level, the next level is determined as the new current level, the local minimum point of the new current level is determined, until the new current level is the full dense base layer in the layered graph, and the current node of the full dense base layer is determined. When the current level is the full dense base layer in the layered graph, the second distance between the neighboring nodes of the current node and the query vector is determined. Based on the second distance and the access status of the corresponding neighboring nodes, the current node of the full dense base layer is iteratively updated until the access status of all current nodes indicates that they have been visited. The current node is selected as the query result according to the second distance. The neighboring node includes an encoding vector, which is indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoding vector, the query vector, and the codebook. The second distance is determined based on the encoding vector, the query vector, and the codebook.

2. The method according to claim 1, characterized in that, The current node includes the entry point. Obtaining the codebook and the current node includes: Obtain the metadata file, which includes the metadata information and codebook of the hierarchical graph; The entry point is read from the metadata information, and the entry point includes the entry point of the hierarchical graph.

3. The method according to claim 1, characterized in that, Based on the first distance between the current node's neighboring nodes and the query vector, the current node is iteratively updated until a local minimum is identified according to the first distance, including: Based on the identifier of the current node, locate the node data file corresponding to the current node and determine the encoding vectors of the neighboring nodes of the current node; Based on the encoding vector, the query vector, and the codebook, determine the first distance between the current node's neighboring nodes and the query vector, and the minimum value of the first distance; The neighbor node corresponding to the minimum value is determined as the new current node. The current node is updated and the minimum value is determined repeatedly according to the first distance until a local minimum value is identified based on the minimum value.

4. The method according to claim 3, characterized in that, The node data file includes at least one of the following: the identifier of the current node, the encoding vector of the current node, an array of identifiers of the current node's neighboring nodes, and an array of encoding vectors of the current node's neighboring nodes.

5. The method according to claim 3, characterized in that, Determining the first distance between the current node's neighboring nodes and the query vector based on the encoding vector, the query vector, and the codebook includes: Based on the codebook and the query vector, determine the vector table of the query vector; Based on the encoded vector and the vector table, a first distance between the neighbor node and the query vector is determined.

6. The method according to claim 1, characterized in that, The step of iteratively updating the current nodes of the full dense base layer based on the second distance and the access status of the corresponding neighbor nodes until the access status of all current nodes indicates that they have been visited includes: The current node in the full dense base layer is identified as a candidate node and added to the candidate queue; Select the candidate node with the smallest candidate distance from the candidate queue and whose access identifier indicates that it has not been visited as the target candidate node, and update the corresponding access identifier to indicate that it has been visited. The candidate distance includes the distance between the candidate node and the query vector. The access identifier indicates whether the current node has been visited. The candidate node includes the nodes in the candidate queue. Determine the third distance between the candidate neighbor nodes of the target candidate node and the query vector. Add the candidate neighbor nodes whose third distance is less than the maximum distance and whose access identifier indicates that they have not been visited to the candidate node as the candidate node in the candidate queue. Use the third distance as the corresponding candidate distance. The maximum distance includes the largest candidate distance in the candidate queue. Repeatedly select and access the candidate nodes from the candidate queue until all the candidate nodes in the candidate queue have been accessed.

7. The method according to claim 6, characterized in that, The candidate queue includes candidate nodes sorted in ascending order according to the candidate distance, and the step of selecting the current node as the query result based on the second distance includes: The first candidate node in the candidate queue is selected as the query result.

8. A vector query device for a database, characterized in that, include: The acquisition module is used to acquire the query vector, codebook, and current node. The current node includes the node of the current level in the hierarchical graph. The hierarchical graph is constructed by mapping vector data in the vector database to nodes in multiple levels. The first determining module is used to iteratively update the current node based on the first distance between the neighboring nodes of the current node and the query vector, until a local minimum is identified based on the first distance, and determine the current node corresponding to the local minimum as the local minimum point of the current level. The second determining module is used to determine the mapping node of the local minimum point in the next level as the current node of the next level, determine the next level as the new current level, determine the local minimum point of the new current level, until the new current level is the full dense base layer in the layered graph, and determine the current node of the full dense base layer. The selection module is used to determine the second distance between the neighboring nodes of the current node and the query vector when the current level is the full dense base layer in the layered graph. Based on the second distance and the access status of the corresponding neighboring nodes, the current node of the full dense base layer is iteratively updated until the access status of all current nodes indicates that they have been visited. The current node is selected as the query result according to the second distance. The neighboring node includes an encoding vector, which is indicated by the current node corresponding to the neighboring node. The first distance is determined based on the encoding vector, the query vector, and the codebook. The second distance is determined based on the encoding vector, the query vector, and the codebook.

9. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the method of any one of claims 1-7.

11. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the method according to any one of claims 1-7.