Vector indexing method in dynamic data scene

By constructing a hybrid step-size index structure based on coverage in a dynamic data scenario, approximate nearest neighbor search and dynamic management of vertices are achieved, which solves the problems of high index structure maintenance cost and low search efficiency in the existing technology, and improves the performance of large-scale applications. Vector indexing performance for data and artificial intelligence applications.

CN118673183AActive Publication Date: 2024-09-20UNIV OF ELECTRONICS SCI & TECH OF CHINA

Patent Information

Application Number
CN202410721608.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-05
Publication Date
2024-09-20
Estimated Expiration
2044-06-05

AI Technical Summary

Technical Problem

The existing approximate nearest neighbor search algorithm lacks efficient support in dynamic data scenarios, especially when adding and deleting data in real time, resulting in high maintenance costs for the index structure and low search efficiency, and cannot meet the needs of big data and artificial intelligence applications.

Method used

A hybrid step index structure (HSG) based on coverage is used to implement approximate nearest neighbor search by constructing a hybrid step graph, combining the vertex addition algorithm of relative distance and the vertex deletion algorithm of incoming edge weights, and indexing the graph through coverage Iterative optimization supports real-time data addition and deletion in dynamic data flow mode.

Benefits of technology

It realizes high-performance vector indexing in dynamic data flow mode, improves search efficiency and recall rate, supports large-scale vector similarity retrieval, and is suitable for artificial intelligence and big data applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118673183A
    Figure CN118673183A
Patent Text Reader

Abstract

The invention discloses a vector indexing method in a dynamic data scene, and provides an approximate nearest neighbor search algorithm based on an HSG index structure, a vertex addition algorithm based on a relative distance and an HSG vertex deletion algorithm based on an incoming edge weight by constructing a mixed step index structure HSG based on a coverage rate. Performing index map evaluation and iterative optimization based on the coverage rate, and finally adding and deleting data in real time and iteratively optimizing an index structure in a dynamic data flow mode based on an HSG index structure and an approximate nearest neighbor algorithm to realize high-performance vector indexing. The method solves the problem that a current mainstream algorithm only supports the literature of a static data set, can add and delete data in real time in a dynamic data stream mode, can iteratively optimize an index structure, improves the search efficiency and the recall rate, provides effective support for larger-range application of technologies such as artificial intelligence and big data, and provides more extensive and more efficient search methods. And a theoretical reference and a practical basis are provided for research of a larger-scale vector similarity retrieval mechanism.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of software algorithms, and in particular relates to a vector indexing method in a dynamic data scenario. Background Art

[0002] In recent times, vectors have attracted more and more attention as a data type for expressing unstructured data such as images, videos, and text. E-commerce platforms implement image search functions by converting images into vectors, natural language science converts text into vectors for semantic analysis, and vector data types are also widely used in fields such as machine vision, speech recognition, and personalized advertising.

[0003] Many approximate nearest neighbor search engines targeting different usage scenarios have been born. The approximate nearest neighbor algorithms used by these approximate nearest neighbor search engines are mainly divided into four types, namely, Hash-based, PQ (Product Quantization)-based, graph-based, and tree-based methods. However, the existing approximate nearest neighbor algorithms do not fully support the dynamic addition and deletion of data. Although most algorithms can simultaneously obtain high recall rates and search efficiency, they need to know the data set or training set in advance when building the index, that is, they need to roughly know the distribution pattern of the data in the data set. Even if most algorithms implement the deletion function, their implementation method is simply to mark the deleted data, and they do not actually delete the data in the index. When these algorithms are introduced into database application scenarios, the known practice is to temporarily store the newly added vectors, mark the deleted vectors, and then periodically update the full amount. This is very costly and is obviously not an elegant method when the data scale is large.

[0004] The graph-based approximate nearest neighbor algorithm has received a lot of attention since it was proposed. The literature "Hajebi K, Abbasi-Yadkori Y, Shahbazi H, et al. Fast approximate nearest-neighbor search with k-nearest neighbor graph Twenty-Second International Joint Conference on Artificial Intelligence. 2011" proposed the K-NN graph. The literature "Malkov Y, Ponomarenko A, Logvinov A, et al. Approximate nearest neighbor algorithm based on navigable small world graphs. Information Systems, 2014, 45: 61-68" proposed an approximate nearest neighbor search algorithm based on a navigable small world (NSW) graph, in which vertices correspond to vectors, edges correspond to connections between them, and a greedy search algorithm is used when searching for the nearest neighbor. The paper "Malkov YA, Yashunin DA. Efficient and robust approximate nearest neighbor search using hierarchical navigable small world graphs. IEEE transactions on pattern analysis and machine intelligence, 2018, 42(4): 824-836" proposed an approximate nearest neighbor search method for hierarchical navigable small world (HNSW) graphs based on NSW, which greatly accelerated the search efficiency. The paper "Fu C, Xiang C, Wang C, et al. Fast approximate nearest neighbor search with the navigating spreading-out graph. arXiv preprint arXiv: 1707.00143, 2017." After observing the previous graph-based approximate nearest neighbor algorithms, four aspects are first clarified: ensuring the connectivity of the graph; reducing the average out-degree of the graph; shortening the search path; and reducing the index size.Then, a new graph structure that meets the above four aspects is proposed: Navigating Spreading-out Graph (NSG). The literature "Jayaram Subramanya S, DevvritF, Simhadri HV, et al. Diskann: Fast accurate billion-point nearest neighbor search on a single node. Advances in Neural Information Processing Systems, 2019, 32" proposes a new graph construction algorithm: Vamana, and extends it to SSD (solid state drive).

[0005] A large number of experiments and literature have shown that hash-based algorithms are simple, efficient, and easy to implement, but have low accuracy. PQ-based algorithms are simple and accurate, but are almost unusable when the amount of data is large. Although graph-based algorithms have no theoretical guarantees, they have achieved a very good balance between search efficiency and recall rate. The disadvantage is that it takes a long time to build the graph and consumes a lot of memory. Tree-based algorithms are more efficient at low dimensions, but their efficiency decreases when the dimension increases.

[0006] With the widespread application of big data and the increasing demand for vector data management, the combination of vector data and traditional databases is imperative. The main work content is concentrated on transforming the existing approximate nearest neighbor search algorithm according to the usage scenario, for example, performing hybrid queries after combining with traditional structured data, or designing a hierarchical system after combining search engines with databases.

[0007] In summary, many efficient and flexible approximate nearest neighbor search algorithms and approximate nearest neighbor search engines have been proposed, but there is still a lack of efficient approximate nearest neighbor algorithms that support dynamic data streams. Therefore, there is an urgent need for an index structure that supports real-time addition and deletion of data, providing an efficient and flexible vector indexing method for applications such as big data and artificial intelligence. Summary of the invention

[0008] To solve the above technical problems, the present invention provides a vector indexing method in a dynamic data scenario, aiming to overcome the deficiency that the current mainstream algorithm only supports static data sets, realize the application of approximate nearest neighbor algorithm in dynamic data flow mode, explore high-performance vector indexing key technologies, and provide effective support for the wider application of technologies such as artificial intelligence and big data.

[0009] The technical solution adopted by the present invention is: a vector indexing method in a dynamic data scenario, and the specific steps are as follows:

[0010] S1. Construct a coverage-based hybrid step-length index structure: hybrid step-length graph HSG;

[0011] S2, based on step S1, perform approximate nearest neighbor search in the hybrid step length graph HSG;

[0012] S3, based on step S1, implement a vertex adding algorithm based on relative distance;

[0013] S4, based on step S1, implement the HSG vertex deletion algorithm based on the incoming edge weight;

[0014] S5. Based on step S1, perform index graph evaluation and iterative optimization based on coverage;

[0015] S6. Based on steps S2-S5, the approximate nearest neighbor algorithm adds and deletes data in real time under the dynamic data flow mode, iteratively optimizes the index structure, and realizes high-performance vector indexing.

[0016] Furthermore, the step S1 is specifically as follows:

[0017] In the HSG, there are both long edges and short edges, which are divided by relative distance; the short edges come from the K-ANN graph, that is, for any vertex in the index graph, the k vertices closest to it in the index graph are connected as neighbors; at the same time, if there is an edge, any vertex of which does not belong to the k approximate nearest neighbors of another vertex, then this edge is a long edge.

[0018] Among them, the short edges are responsible for searching the k approximate nearest neighbors with the highest similarity to the target, and the long edges are responsible for quickly searching for vertices with high similarity to the query target starting from the starting vertex of the graph; the HSG chooses to limit the average degree of short edges and long edges separately, does not require global information of the data set, and supports incremental updates of the index graph.

[0019] Furthermore, the step S2 is specifically as follows:

[0020] S21, input the query vector, add the starting vertex to the waiting queue, and add the long edge neighbors of the head vertex of the waiting queue to the waiting queue;

[0021] For any approximate nearest neighbor search, input the query vector, add the starting vertex to the waiting queue, start from the starting vertex, quickly search the vertices that are closer to the query target through the long edge, and only calculate the distance between the long edge neighbor of the current waiting queue head vertex and the target vertex, and add the long edge neighbor of the waiting queue head vertex to the waiting queue.

[0022] S22, after one round of iteration, determine whether the head vertex of the waiting queue has changed, if it has changed, repeat step S21 until there is no change, if there is no change, proceed to step S23;

[0023] S23, take out the head vertex of the waiting queue, add the short edge neighbor of the head vertex to the waiting queue, add the head vertex to the top queue, and determine whether the top queue is added successfully;

[0024] Search for high-quality k approximate nearest neighbors through short edges. If the result queue is less than k or the distance between the head vertex of the waiting queue and the target vertex is less than the maximum value of the result queue, the head vertex of the waiting queue is added to the result queue and deleted from the waiting queue. Otherwise, the addition fails, the search ends, and the result queue is returned. If the addition is successful, the short-edge neighbor of the head vertex is added to the waiting queue, and step S23 is repeated until the addition fails.

[0025] Furthermore, the step S3 is specifically as follows:

[0026] S31, input the added vector and perform an approximate nearest neighbor search on the target vector;

[0027] Start from the starting vertex and search for the k vertices closest to the target vertex; the returned results include: k approximate nearest neighbors and all vertices visited during the entire search process.

[0028] Among them, the vertices in the top-k list are added as short-side neighbors of the target vertex, and the vertices that have been visited during the search process and are not in the top-k list are added as long-side neighbors of the target vertex.

[0029] S32, adding short-side neighbors according to the result returned in step S31;

[0030] When adding short edges, determine whether to add new vertices as neighbors of the vertices in the top-k list. When the number of short edge neighbors of the vertices in the top-k list has reached the degree limit, it is necessary to delete the neighbor with the largest distance and then add the new vertex as a neighbor.

[0031] Among them, deleting edges will cause two problems, as follows:

[0032] (1) A connected graph becomes a disconnected graph;

[0033] (2) The short edge added earlier is clipped by the vertex added later, while the short edge added earlier should exist as a long edge.

[0034] If problem (1) occurs, the connectivity of the graph is determined by breadth-first traversal. If the graph becomes disconnected due to the deletion of the edge, the edge is saved in a special set to maintain the connectivity of the graph. If problem (2) occurs, the parameters are adjusted so that the old long edges are retained when the long edges are trimmed, and the deleted short edges are not actually deleted but moved to the long edge set.

[0035] S33, adding long side neighbors according to the result returned in step S31;

[0036] The returned result is an ordered queue sorted from largest to smallest according to the distance to the newly added vertex, which is divided into two parts. Queue 1 is the vertices traversed through the long edges during the search process, and queue 2 is the vertices traversed through the short edges.

[0037] If the number of vertices in queue two is less than x, no long edge is added; if the number of vertices in queue two is equal to x, a long edge is added from the tail vertex of queue one to the newly added vertex; if the number of vertices in queue two is greater than x, a long edge is first added from the tail vertex of queue one to the xth vertex in queue two, and then starting from the xth vertex in queue two, a long edge is added from the vertex of the last long edge added to the vertex every x vertices.

[0038] Here, x represents an optional parameter.

[0039] Furthermore, the step S4 is specifically as follows:

[0040] S41, input a deletion vector, first delete all short edges of the target vertex, and perform a 1-ANN search on the short edge neighbors of the target vertex starting from itself and the deleted vertex;

[0041] S42, if the degree of the vertex is less than k, a short edge neighbor compensation operation is performed, and after the short edge compensation is completed, all long edges of the target vector are deleted;

[0042] S43, according to the search algorithm, the long edge is no longer used after step S21, so the generation of a non-connected long edge graph should be avoided, and it is determined whether the product of the number of in-edges and the number of out-edges of the long edge of the deleted target vertex is greater than a preset threshold t;

[0043] Where t represents the parameter specified by the user; if the product of the number of incoming edges and the number of outgoing edges of the long edge of the target vertex is less than t, the long edge compensation algorithm 1 is used; if the product of the number of incoming edges and the number of outgoing edges of the long edge of the target vertex is greater than t, the long edge compensation algorithm 2 is used, as follows:

[0044] (1) Long edge compensation algorithm 1: weight-based compensation algorithm;

[0045] The distances of the long edges of the deleted vertex are summed up and recorded as ds. The distance of any incoming edge is recorded as di. The incoming edge neighbors of the deleted vertex and the outgoing edge neighbors of the deleted vertex are connected according to the probability of di / ds.

[0046] (2) Long edge compensation algorithm 2: Replace the target vertex with the nearest vertex;

[0047] Find a vertex to replace the deleted vertex, select the vertex closest to the deleted vertex, and transfer all the long edges of the deleted vertex to this vertex.

[0048] Furthermore, the step S5 is specifically as follows:

[0049] S51, input parameter x, and perform breadth-first traversal starting from the starting vertex;

[0050] Suppose the vertex set Vr is the set of vertices that can be reached by long edges. Take the vertices in Vr as the starting vertices and perform x rounds of breadth-first traversal to obtain the set of coverable vertices Vc. Output the coverage ratio |Vr+Vc| / |V|.

[0051] Among them, x represents an optional parameter, and the vertex set V represents the set of all vertices.

[0052] If the coverage rate is greater than the preset coverage rate threshold, the coverage rate is output after the traversal is completed. If the coverage rate is less than the preset coverage rate threshold, the process proceeds to step S52.

[0053] S52, performing iterative optimization based on the coverage obtained in step S51;

[0054] When calculating the coverage rate, the vertex set Vm = V-Vr-Vc is obtained, that is, the set of omitted vertices. For all vertices in Vm, x rounds of breadth-first traversal are performed through the short edges with itself as the starting point. The number of vertices belonging to Vm encountered by each vertex in Vm during the traversal is recorded, and the vertex with the largest number is selected to re-add the long edge, and then x rounds of breadth-first traversal are performed with the vertex as the starting point. Step S52 is repeated until the coverage rate meets the standard.

[0055] Beneficial effects of the present invention: The method of the present invention constructs a hybrid step index structure HSG based on coverage, proposes an approximate nearest neighbor search algorithm based on the HSG index structure, a vertex addition algorithm based on relative distance, and an HSG vertex deletion algorithm based on the incoming edge weight, and performs index graph evaluation and iterative optimization based on coverage. Finally, based on the HSG index structure, the approximate nearest neighbor algorithm adds and deletes data in real time under a dynamic data flow mode, iteratively optimizes the index structure, and realizes high-performance vector indexing. The method of the present invention solves the problem that the current mainstream algorithm only supports static data sets, can add and delete data in real time under a dynamic data flow mode, and can iteratively optimize the index structure, improve search efficiency and recall rate, and provide effective support for a wider range of applications of technologies such as artificial intelligence and big data, and provide theoretical reference and practical basis for a wider and larger-scale study of vector similarity retrieval mechanisms. BRIEF DESCRIPTION OF THE DRAWINGS

[0056] Figure 1The present invention is a flowchart of a vector indexing method in a dynamic data scenario.

[0057] Figure 2 Flow chart of the HSG search strategy in an embodiment of the present invention.

[0058] Figure 3 The figure is a flow chart of an algorithm for adding vertices based on relatively close distances in an embodiment of the present invention.

[0059] Figure 4 The figure is a flowchart of a weight-based vertex deletion algorithm in an embodiment of the present invention.

[0060] Figure 5 The flowchart is a coverage-based evaluation method and iterative optimization strategy in an embodiment of the present invention. DETAILED DESCRIPTION

[0061] The method of the present invention is further described below in conjunction with the accompanying drawings and embodiments.

[0062] like Figure 1 As shown, a flow chart of a vector indexing method in a dynamic data scenario of the present invention, the specific steps are as follows:

[0063] S1. Construct a coverage-based hybrid step-length index structure: hybrid step-length graph HSG;

[0064] S2, based on step S1, perform approximate nearest neighbor search in the hybrid step length graph HSG;

[0065] S3, based on step S1, implement a vertex adding algorithm based on relative distance;

[0066] S4, based on step S1, implement the HSG vertex deletion algorithm based on the incoming edge weight;

[0067] S5. Based on step S1, perform index graph evaluation and iterative optimization based on coverage;

[0068] S6. Based on steps S2-S5, the approximate nearest neighbor algorithm adds and deletes data in real time under the dynamic data flow mode, iteratively optimizes the index structure, and realizes high-performance vector indexing.

[0069] In this embodiment, the step S1 is specifically as follows:

[0070] The index structure of most current Approximate Nearest Neighbor (ANN) algorithms only supports static data sets and cannot meet the requirements of dynamic data changes. The existing K-ANN algorithm can support dynamic data streams to a certain extent, but the index graph maintenance cost is high, the search efficiency is extremely low, and it cannot be actually applied to large-scale data. Therefore, it is necessary to study the index graph structure that efficiently supports dynamic data streams while taking into account search performance and recall rate. This embodiment proposes a hybrid stride index structure based on coverage: Hybrid Strides Graph (HSG). Under the condition of effectively controlling the vertex degree, the long and short edges between the vertices are reasonably configured to ensure the coverage of the index graph on the vertex set. During the search process, first quickly jump to the vicinity of the target through the long edge, and then filter the accurate results through the short edge, taking into account search performance and recall rate.

[0071] The construction process of HSG needs to reliably guarantee the configuration of asynchronous long edges. First, the long edges and short edges of HSG are borrowed from the NSG (navigating spreading-out graph) and K-ANN algorithm ideas respectively, but NSG relies on global information to construct index edges, so it is necessary to study the index edge construction method for dynamic data scenarios.

[0072] In the HSG, there are both long edges and short edges, which are divided by relative distance; the short edges come from the K-ANN graph, that is, for any vertex in the index graph, the k vertices closest to it in the index graph are connected as neighbors; at the same time, if there is an edge, any vertex of which does not belong to the k approximate nearest neighbors of another vertex, then this edge is a long edge.

[0073] Among them, the short edge is responsible for searching the k approximate nearest neighbors with the highest similarity to the target, and the long edge refers to the NSG composition strategy and is responsible for quickly searching for vertices with high similarity to the query target starting from the starting vertex of the graph;

[0074] Graph-based approximate nearest neighbor algorithms, such as HNSW, NSG, Vamana (DiskANN), etc., all have a common and clear basic graph construction idea: while ensuring connectivity, try to reduce the average degree and reduce the drop in recall caused by the degree reduction. HSG faces a choice: limit the average degree to a level that is almost the same as the average degree of most graph-based approximate nearest neighbor algorithms, or limit the long and short edges separately so that their respective average degrees are almost the same as NSG and K-ANN respectively.

[0075] In order to maintain the robustness of the graph after deletion operations, the HSG chooses to limit the average degrees of short edges and long edges separately, does not require global information of the dataset, and supports incremental updates of the index graph.

[0076] There is an important equilibrium point in the graph-based approximate nearest neighbor algorithm: the average degree. When the degree in the graph increases, the recall rate can usually be improved, and the robustness of the index graph will be better, and it is less likely to have a disconnected graph. However, due to the large degree, the number of distance calculations in each iteration during the search process also increases. These extra calculations are meaningless, so a large amount of computing resources will be wasted, resulting in a decrease in search efficiency. When the average degree of the index graph decreases within a certain range, the search efficiency can be improved, but the recall rate will decrease to a certain extent. If the average degree is too low, a disconnected graph is likely to appear, in which case the recall rate will drop significantly.

[0077] In order to reduce the negative impact of increased degree on search efficiency, through observation, experiment and theoretical analysis, it is found that in the search process, long edges can indeed effectively improve search efficiency. However, in each iteration of a search, it is not always necessary to traverse the long and short edges of the current vertex. In each iteration, only one of the two can play a role: if the long side neighbor is closer to the target, then the short side neighbor must be far away, so the short side neighbor does not need to be calculated; if the short side neighbor is closer to the target, then the long side neighbor must be far away, so the long side neighbor does not need to be calculated.

[0078] like Figure 2 As shown, in this embodiment, the step S2 is specifically as follows:

[0079] S21, input the query vector, add the starting vertex to the waiting queue, and add the long edge neighbors of the head vertex of the waiting queue to the waiting queue;

[0080] For any approximate nearest neighbor search, input the query vector, add the starting vertex to the waiting queue, start from the starting vertex, quickly search the vertices that are closer to the query target through the long edge, and only calculate the distance between the long edge neighbor of the current waiting queue head vertex and the target vertex, and add the long edge neighbor of the waiting queue head vertex to the waiting queue.

[0081] Because the head vertex of the waiting queue is the vertex closest to the target among all previously calculated vertices, it can be considered as the calculation result of the short-side neighbor. This method reduces the amount of calculation and improves the search speed.

[0082] S22, after one round of iteration, determine whether the head vertex of the waiting queue has changed, if it has changed, repeat step S21 until there is no change, if there is no change, proceed to step S23;

[0083] S23, take out the head vertex of the waiting queue, add the short edge neighbor of the head vertex to the waiting queue, add the head vertex to the top queue, and determine whether the top queue is added successfully;

[0084] Search for high-quality k approximate nearest neighbors through short edges. If the result queue is less than k or the distance between the head vertex of the waiting queue and the target vertex is less than the maximum value of the result queue, the head vertex of the waiting queue is added to the result queue and deleted from the waiting queue. Otherwise, the addition fails, the search ends, and the result queue is returned. If the addition is successful, the short-edge neighbor of the head vertex is added to the waiting queue, and step S23 is repeated until the addition fails.

[0085] like Figure 3 As shown, in this embodiment, step S3 is specifically as follows:

[0086] S31, input the added vector and perform an approximate nearest neighbor search on the target vector;

[0087] Starting from the starting vertex, search for the k (short edge degree limit) vertices closest to the target vertex; the returned results include: k approximate nearest neighbors and all vertices visited during the entire search process.

[0088] Among them, the vertices in the top-k list are added as short-side neighbors of the target vertex, and the vertices that have been visited during the search process and are not in the top-k list are added as long-side neighbors of the target vertex.

[0089] The search process of step S31 is consistent with the search algorithm of step S2, the only difference is that the returned result not only returns the k approximate nearest neighbors, but also returns all the vertices visited during the entire search process.

[0090] S32, adding short-side neighbors according to the result returned in step S31;

[0091] When adding short edges, determine whether to add new vertices as neighbors of the vertices in the top-k list. When the number of short edge neighbors of the vertices in the top-k list has reached the degree limit, it is necessary to delete the neighbor with the largest distance and then add the new vertex as a neighbor.

[0092] Among them, deleting edges will cause two problems, as follows:

[0093] (1) A connected graph becomes a disconnected graph;

[0094] (2) The short edge added earlier is clipped by the vertex added later, while the short edge added earlier should exist as a long edge.

[0095] If problem (1) occurs, the connectivity of the graph is determined by breadth-first traversal. If the graph becomes disconnected due to the deletion of the edge, the edge is saved in a special set, which is used to maintain the connectivity of the graph, so the set of edges must exist. If problem (2) occurs, the parameters are adjusted so that the old long edges are retained when the long edges are trimmed. For the deleted short edges, although the absolute distance of the edges has not changed, because shorter edges have appeared, the original short edges become relatively long edges compared to these new shorter edges. In this case, the short edges are not actually deleted, but moved to the long edge set.

[0096] S33, adding long side neighbors according to the result returned in step S31;

[0097] The returned result is an ordered queue sorted from largest to smallest according to the distance to the newly added vertex, which is divided into two parts. Queue 1 is the vertices traversed through the long edges during the search process, and queue 2 is the vertices traversed through the short edges.

[0098] If the number of vertices in queue two is less than x, no long edge is added; if the number of vertices in queue two is equal to x, a long edge is added from the tail vertex of queue one to the newly added vertex; if the number of vertices in queue two is greater than x, a long edge is first added from the tail vertex of queue one to the xth vertex in queue two, and then starting from the xth vertex in queue two, a long edge is added from the vertex of the last long edge added to the vertex every x vertices.

[0099] Here, x represents an optional parameter.

[0100] Most of the current graph-based approximate nearest neighbor algorithms do not support vertex deletion. Some algorithms only provide mark deletion, that is, the deleted data in the index is marked but not actually deleted, and the marked deleted data is skipped when the index is used or filtered when the results are returned. The disadvantage is that after frequent additions and deletions of data, the index data only increases but does not decrease, which not only greatly wastes space, but also sharply reduces search efficiency. It is often necessary to regenerate the full index regularly, which is very time-consuming.

[0101] like Figure 4 As shown, in this embodiment, the step S4 is specifically as follows:

[0102] S41, input a deletion vector, first delete all short edges of the target vertex, and perform a 1-ANN search on the short edge neighbors of the target vertex starting from itself and the deleted vertex;

[0103] S42, if the degree of the vertex is less than k, a short edge neighbor compensation operation is performed, and after the short edge compensation is completed, all long edges of the target vector are deleted;

[0104] S43, according to the search algorithm, the long edge is no longer used after step S21, so the generation of a non-connected long edge graph should be avoided, and it is determined whether the product of the number of in-edges and the number of out-edges of the long edge of the deleted target vertex is greater than a preset threshold t;

[0105] Where t represents the parameter specified by the user; if the product of the number of incoming edges and the number of outgoing edges of the long edge of the target vertex is less than t, the long edge compensation algorithm 1 is used; if the product of the number of incoming edges and the number of outgoing edges of the long edge of the target vertex is greater than t, the long edge compensation algorithm 2 is used, as follows:

[0106] (1) Long edge compensation algorithm 1: weight-based compensation algorithm;

[0107] According to the definition of long edges, we hope that the long edges are as long as possible. At this time, the distances of the incoming edges of the long edges of the deleted vertex are summed up and recorded as ds. The distance of any incoming edge is recorded as di. The incoming edge neighbors of the deleted vertex and the outgoing edge neighbors of the deleted vertex are connected according to the probability of di / ds.

[0108] (2) Long edge compensation algorithm 2: Replace the target vertex with the nearest vertex;

[0109] To reduce the time of the deletion operation, think from the perspective of the graph and find a vertex to replace the deleted vertex. At this time, select the vertex closest to the deleted vertex and transfer all the long edges of the deleted vertex to this vertex.

[0110] The quality of the index graph is crucial. Approximate nearest neighbor search results are the most direct way to evaluate it. Higher recall rates and higher search efficiency indicate better quality of the index graph. However, this is an abstract result. It is impossible to obtain information about the index graph based on this result, and the index graph cannot be optimized based on this result. Therefore, it is necessary to have clear standards to judge the quality of the index graph, and this standard can provide guidance for further optimization of the index graph. According to the design concept of HSG, ideally sparse and extensive long edges can improve search efficiency, dense and accurate short edges can improve recall, and long edges are used to speed up the search. Therefore, it is hoped that most of the vertices in the index graph or their vicinity can be reached through long edges starting from the starting vertex.

[0111] like Figure 5 As shown, in this embodiment, the step S5 is specifically as follows:

[0112] S51, input parameter x, and perform breadth-first traversal starting from the starting vertex;

[0113] Suppose the vertex set Vr is the set of vertices that can be reached by long edges. Take the vertices in Vr as the starting vertices and perform x rounds of breadth-first traversal to obtain the set of coverable vertices Vc. Output the coverage rate |Vr+Vc| / |V|. The higher the coverage rate, the better.

[0114] Among them, x represents an optional parameter, and the vertex set V represents the set of all vertices.

[0115] If the coverage rate is greater than the preset coverage rate threshold, the coverage rate is output after the traversal is completed. If the coverage rate is less than the preset coverage rate threshold, the process proceeds to step S52.

[0116] S52, performing iterative optimization based on the coverage obtained in step S51;

[0117] When calculating the coverage rate, the vertex set Vm = V-Vr-Vc is obtained, that is, the set of omitted vertices. For all vertices in Vm, x rounds of breadth-first traversal are performed with itself as the starting point through the short edges. The number of vertices belonging to Vm encountered by each vertex in Vm during the traversal is recorded, and the vertex with the largest number is selected (if not unique, one is selected randomly) to re-add the long edge, and then x rounds of breadth-first traversal are performed with the vertex as the starting point. Step S52 is repeated until the coverage rate meets the standard.

[0118] In summary, the method of the present invention solves the problem that the current mainstream algorithm only supports static data sets. It can add and delete data in real time under the dynamic data flow mode, and can iteratively optimize the index structure to improve search efficiency and recall rate. It provides effective support for the wider application of technologies such as artificial intelligence and big data, and provides theoretical reference and practical basis for broader and larger-scale research on vector similarity retrieval mechanism.

[0119] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the scope of protection of the present invention is not limited to such specific statements and embodiments. For those skilled in the art, the present invention may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of the claims of the present invention.

Claims

1. A vector indexing method in a dynamic data scenario, the specific steps are as follows: S1. Construct a coverage-based hybrid step-length index structure: hybrid step-length graph HSG; S2, based on step S1, perform approximate nearest neighbor search in the hybrid step length graph HSG; S3, based on step S1, implement a vertex adding algorithm based on relative distance; S4, based on step S1, implement the HSG vertex deletion algorithm based on the incoming edge weight; S5. Based on step S1, perform index graph evaluation and iterative optimization based on coverage; S6. Based on steps S2-S5, the approximate nearest neighbor algorithm adds and deletes data in real time under the dynamic data flow mode, iteratively optimizes the index structure, and realizes high-performance vector indexing.

2. The vector indexing method in a dynamic data scenario according to claim 1, characterized in that: The step S1 is specifically as follows: In the HSG, there are both long edges and short edges, which are divided by relative distance; the short edges come from the K-ANN graph, that is, for any vertex in the index graph, the k vertices closest to it in the index graph are connected as neighbors; at the same time, if there is an edge, any vertex of which does not belong to the k approximate nearest neighbors of another vertex, then this edge is a long edge; Among them, the short edges are responsible for searching the k approximate nearest neighbors with the highest similarity to the target, and the long edges are responsible for quickly searching for vertices with high similarity to the query target starting from the starting vertex of the graph; the HSG chooses to limit the average degree of short edges and long edges separately, does not require global information of the data set, and supports incremental updates of the index graph.

3. The vector indexing method in a dynamic data scenario according to claim 1, characterized in that: The step S2 is specifically as follows: S21, input the query vector, add the starting vertex to the waiting queue, and add the long edge neighbors of the head vertex of the waiting queue to the waiting queue; For any approximate nearest neighbor search, input the query vector, add the starting vertex to the waiting queue, start from the starting vertex, quickly search for vertices that are closer to the query target through the long edge, and only calculate the distance between the long edge neighbor of the current waiting queue head vertex and the target vertex, and add the long edge neighbor of the waiting queue head vertex to the waiting queue; S22, after one round of iteration, determine whether the head vertex of the waiting queue has changed, if it has changed, repeat step S21 until there is no change, if there is no change, proceed to step S23; S23, take out the head vertex of the waiting queue, add the short edge neighbor of the head vertex to the waiting queue, add the head vertex to the top queue, and determine whether the top queue is added successfully; Search for high-quality k approximate nearest neighbors through short edges. If the result queue is less than k or the distance between the head vertex of the waiting queue and the target vertex is less than the maximum value of the result queue, the head vertex of the waiting queue is added to the result queue and deleted from the waiting queue, otherwise the addition fails, the search ends, and the result queue is returned; if the addition is successful, the short edge neighbor of the head vertex is added to the waiting queue, and step S23 is repeated until the addition fails.

4. The vector indexing method in a dynamic data scenario according to claim 1, characterized in that: The step S3 is specifically as follows: S31, input the added vector and perform an approximate nearest neighbor search on the target vector; Start from the starting vertex and search for the k vertices closest to the target vertex; the returned results include: k approximate nearest neighbors and all vertices visited during the entire search process; The vertices in the top-k list are added as short-side neighbors of the target vertex, and the vertices that have been visited during the search and are not in the top-k list are added as long-side neighbors of the target vertex. S32, adding short-side neighbors according to the result returned in step S31; When adding short edges, determine whether to add new vertices as neighbors of the vertices in the top-k list. When the number of short edge neighbors of the vertices in the top-k list has reached the degree limit, the neighbor with the largest distance needs to be deleted, and then the new vertex is added as a neighbor. Among them, deleting edges will cause two problems, as follows: (1) A connected graph becomes a disconnected graph; (2) The short edge added earlier is clipped by the vertex added later, and the short edge added earlier should exist as a long edge; If problem (1) occurs, the connectivity of the graph is determined by breadth-first traversal. If the graph becomes disconnected due to the deletion of the edge, the edge is saved in a special set to maintain the connectivity of the graph. If problem (2) occurs, the parameters are adjusted so that the old long edges are retained when the long edges are trimmed, and the deleted short edges are not actually deleted but moved to the long edge set. S33, adding long side neighbors according to the result returned in step S31; The returned result is an ordered queue sorted from largest to smallest according to the distance to the newly added vertex, which is divided into two parts: queue one is the vertices traversed through the long edge during the search process, and queue two is the vertices traversed through the short edge; If the number of vertices in queue 2 is less than x, no long edge is added; if the number of vertices in queue 2 is equal to x, a long edge is added from the tail vertex of queue 1 to the newly added vertex; if the number of vertices in queue 2 is greater than x, a long edge is first added from the tail vertex of queue 1 to the xth vertex in queue 2, and then starting from the xth vertex in queue 2, a long edge is added from the vertex of the last long edge added to the vertex every x vertices; Here, x represents an optional parameter.

5. The vector indexing method in a dynamic data scenario according to claim 1, characterized in that: The step S4 is specifically as follows: S41, input a deletion vector, first delete all short edges of the target vertex, and perform a 1-ANN search on the short edge neighbors of the target vertex starting from itself and the deleted vertex; S42, if the degree of the vertex is less than k, a short edge neighbor compensation operation is performed, and after the short edge compensation is completed, all long edges of the target vector are deleted; S43, according to the search algorithm, the long edge is no longer used after step S21, so the generation of a non-connected long edge graph should be avoided, and it is determined whether the product of the number of in-edges and the number of out-edges of the long edge of the deleted target vertex is greater than a preset threshold t; Where t represents the parameter specified by the user; if the product of the number of incoming edges and the number of outgoing edges of the long edge of the target vertex is less than t, the long edge compensation algorithm 1 is used; if the product of the number of incoming edges and the number of outgoing edges of the long edge of the target vertex is greater than t, the long edge compensation algorithm 2 is used, as follows: (1) Long edge compensation algorithm 1: weight-based compensation algorithm; The distances of the long edges of the deleted vertex are summed up, recorded as ds, and the distance of any incoming edge is recorded as di. The incoming edge neighbors of the deleted vertex and the outgoing edge neighbors of the deleted vertex are connected according to the probability of di / ds; (2) Long edge compensation algorithm 2: Replace the target vertex with the nearest vertex; Find a vertex to replace the deleted vertex, select the vertex closest to the deleted vertex, and transfer all the long edges of the deleted vertex to this vertex.

6. The vector indexing method in a dynamic data scenario according to claim 1, characterized in that: The step S5 is specifically as follows: S51, input parameter x, and perform breadth-first traversal starting from the starting vertex; Let the vertex set Vr be the set of vertices that can be reached through long edges, and perform x rounds of breadth-first traversal with the vertices in Vr as the starting vertices to obtain the set of covered vertices Vc, and output the coverage ratio |Vr+Vc| / |V|; Among them, x represents an optional parameter, and the vertex set V represents the set of all vertices; If the coverage rate is greater than the preset coverage rate threshold, the coverage rate is output after the traversal is completed. If the coverage rate is less than the preset coverage rate threshold, the process proceeds to step S52. S52, performing iterative optimization based on the coverage obtained in step S51; When calculating the coverage rate, the vertex set Vm = V-Vr-Vc is obtained, that is, the set of omitted vertices. For all vertices in Vm, x rounds of breadth-first traversal are performed through the short edges with itself as the starting point. The number of vertices belonging to Vm encountered by each vertex in Vm during the traversal is recorded, and the vertex with the largest number is selected to re-add the long edge, and then x rounds of breadth-first traversal are performed with the vertex as the starting point. Step S52 is repeated until the coverage rate meets the standard.

Citation Information

Patent Citations

  • Approximate nearest neighbor search method combining VP tree and guide nearest neighbor graph

    CN112287185A

  • Vector database retrieval method and system, electronic equipment and storage medium

    CN117251641A

  • Approximate nearest neighbor search for single instruction, multiple thread (SIMT) or single instruction, multiple data (SIMD) type processors

    US20210157606A1

Cited By

  • Vector index construction method and device and storage medium

    CN121166697A

  • Vector index construction method, apparatus, and storage medium

    CN121166697B