Filtering vector retrieval method, system, device and storage medium
By using hierarchical clustering and a hybrid inverted index structure, combined with a filtering tree and a nearest neighbor graph, the vector retrieval method is optimized, solving the problem of balancing the performance of filtered and unfiltered queries in a large-scale disk environment, and achieving efficient and low-latency vector retrieval.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-27
- Publication Date
- 2026-03-27
AI Technical Summary
Existing technologies struggle to balance the performance of both filtered and unfiltered queries in large-scale disk environments, and they also suffer from high memory peaks during the construction process, making it difficult to achieve a balance between disk friendliness, filtering robustness, and retrieval accuracy.
By performing hierarchical clustering on vector data, a multi-level vector space structure is constructed. Combining a filter tree and a nearest neighbor graph, a distance-first strategy and label filtering conditions are used to select candidate nodes. Furthermore, disk access is optimized through a hybrid inverted index structure, thereby achieving efficient filtered vector retrieval.
While ensuring high accuracy and low latency, it reduces peak memory usage, improves query efficiency, and ensures stable retrieval performance under different filter selectivity rates.
Smart Images

Figure CN121009183B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of information retrieval and database systems, and particularly relates to a filtering vector retrieval method, system, device and storage medium. BACKGROUND
[0002] In recent years, vector retrieval technology plays a core role in tasks such as Large Language Model (LLM) and Retrieval-Augmented Generation (RAG). In order to improve query speed and reduce resource consumption, Approximate Nearest Neighbor Search (ANNS) has become a mainstream technology path, among which graph structure index and partition compression index (such as inverted file and product quantization) are widely used.
[0003] In real applications, vector retrieval is often accompanied by structured filtering conditions, forming a filtering vector retrieval scenario. The filtering predicate can include tenant, time, label and other fields, and its role is to filter out a subset that meets the conditions in the database, and perform vector similarity retrieval in the subset. Since the target data after filtering is usually sparse and unevenly distributed, the system needs to reduce invalid calculations and Random I / O while ensuring recall rate, which puts higher requirements on index structure and execution strategy.
[0004] Existing solutions mostly adopt three ways of post-filtering, pre-filtering or inline filtering. Post-filtering filters the result set after retrieval, which is simple to implement, but in the low selectivity scenario, it needs to expand the candidate size to ensure recall, resulting in rising computational overhead and delay; pre-filtering filters the data partition that meets the predicate in advance through the index, which can reduce the pressure of candidate generation, but is easily affected by data fragmentation; inline filtering attempts to integrate filtering conditions during index traversal, and its performance depends on the global connectivity and local pruning ability of the index structure.
[0005] Graph structure index (neighbor graph) has the advantages of high recall and low delay in the non-filtering scenario, but its construction process is usually accompanied by high peak memory occupation, and in the filtering condition, it is easy to have weak subgraph connectivity and path cut-off problems, thereby affecting the performance stability. Partition compression index has good disk sequential access ability and low memory occupation, but when high precision and multiple filtering conditions are needed, its local structure is difficult to effectively support global search.
[0006] Therefore, the prior art is difficult to effectively balance between disk friendliness, filtering robustness, construction cost and retrieval accuracy. There is an urgent need for a general solution that simultaneously considers filtering and non-filtering query performance and significantly reduces the peak memory construction in the order of magnitude of billions and in the disk environment.
[0007] In view of this, the present application is proposed. SUMMARY
[0008] The purpose of the present application is to provide a filtering vector retrieval method, system, device and storage medium, which can realize low delay, high accuracy and disk-friendly vector retrieval service while meeting structured filtering conditions.
[0009] The purpose of the present application is achieved by the following technical solutions:
[0010] A filtering vector retrieval method, comprising:
[0011] Hierarchical clustering of vector data to form a multi-level vector space structure, and resident in memory of the center point vector data of each cluster, and the rest of the vector data resident in the disk;
[0012] Constructing a filter tree and a neighbor graph based on the multi-level vector space structure: the center point vector data of each cluster is taken as a node of the filter tree and the neighbor graph, and the node in the filter tree and the node in the neighbor graph record the label information of the corresponding cluster;
[0013] Based on the distance from the center point vector data of the cluster, the vector data of each cluster on the disk is constructed into an inverted data block, and is segmented in combination with the label information of the vector data;
[0014] In the query phase, according to the query vector in the query request, the distance priority strategy is used to preliminarily screen the candidate nodes from the filter tree, and the neighbor search is performed in the neighbor graph in combination with the candidate nodes to obtain the final node set; if the query request contains a label filtering condition, the target label is determined, the downward search is performed along the node path containing the target label in the filter tree, the distance priority strategy is used to preliminarily screen the candidate nodes, and the neighbor search process is controlled in combination with the target label;
[0015] Load the entire inverted data block or the vector data in the corresponding segment of the cluster to which each node in the final node set belongs from the disk to the memory, combine the distance between the loaded vector data and the query vector, and output the retrieval result.
[0016] A filtering vector retrieval system for implementing the foregoing method, comprising:
[0017] The hierarchical clustering unit is configured to perform hierarchical clustering on the vector data to form a multi-level vector space structure, and to store center point vector data of each cluster in the memory and the rest of the vector data on the disk.
[0018] The filter tree and the neighbor graph construction unit is configured to construct the filter tree and the neighbor graph based on the multi-level vector space structure, and to store the center point vector data of each cluster as nodes of the filter tree and the neighbor graph, and record label information of the cluster to which each node in the filter tree and the neighbor graph belongs.
[0019] The hybrid inverted structure construction unit is configured to construct the vector data of each cluster on the disk into inverted data blocks based on the distance from the center point vector data of the cluster, and to segment the inverted data blocks in combination with the label information of the vector data.
[0020] The node selection unit based on the filter tree and the neighbor graph is configured to, in a query stage, preliminarily select candidate nodes from the filter tree based on a query vector in a query request by using a distance-first strategy, perform neighbor search in the neighbor graph in combination with the candidate nodes, and obtain a final node set; if the query request contains a label filtering condition, determine a target label, perform downward search along a node path containing the target label in the filter tree, preliminarily select candidate nodes by using the distance-first strategy, and control the neighbor search process in combination with the target label.
[0021] The search result output unit is configured to load the entire inverted data block or the vector data in the corresponding segment of the cluster to which each node in the final node set belongs from the disk into the memory, output a search result in combination with the distance between the loaded vector data and the query vector.
[0022] A processing device, comprising: one or more processors; a memory for storing one or more programs;
[0023] When the one or more programs are executed by the one or more processors, the one or more processors implement the foregoing method.
[0024] A readable storage medium storing a computer program, when the computer program is executed by a processor, the foregoing method is implemented.
[0025] From the technical solutions provided by the application, on one hand, by introducing the independent filtering tree structure on the proximity graph, the filtering logic can be efficiently pushed down in the retrieval process, and all candidate nodes can meet the filtering condition before entering the graph index (proximity graph), thereby effectively avoiding a large number of invalid candidate generation and random I / O (input / output) access in the low selectivity scenario; on the other hand, the proximity graph structure is kept unchanged, and the high performance in the no-filtering retrieval scenario is ensured. In addition, by introducing the hybrid inverted structure that fuses the spatial proximity and label consistency, the vectors with the same semantic label and similar distance are aggregated into a unified cluster (i.e. the vector data in the label consistent segment in the inverted data block), and the retrieval result output process in the low selectivity query is further accelerated. Thanks to the above improvements, the application achieves a balance in filtering accuracy, query delay and system throughput. BRIEF DESCRIPTION OF DRAWINGS
[0026] In order to more clearly illustrate the technical solutions of the embodiments of the application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the application, and other drawings can be obtained by those skilled in the art without creative labor.
[0027] Figure 1 A flowchart of a filtering vector retrieval method provided by the embodiment of the application.
[0028] Figure 2 A structural schematic diagram of a filtering tree provided by the embodiment of the application.
[0029] Figure 3 A structural schematic diagram of a proximity graph provided by the embodiment of the application.
[0030] Figure 4 A schematic diagram of the organization and disk layout of the hybrid inverted structure provided by the embodiment of the application.
[0031] Figure 5 A schematic diagram of a filtering vector retrieval system provided by the embodiment of the application.
[0032] Figure 6 A schematic diagram of a processing device provided by the embodiment of the application. DETAILED DESCRIPTION
[0033] With reference to the accompanying drawings, the technical solutions in the embodiments of the present application will be described clearly and completely. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments of the present application, all the other embodiments obtained by a person of ordinary skill in the art without creative effort belong to the protection scope of the present application.
[0034] Firstly, the terms possibly used in the present application are described as follows.
[0035] The terms "comprise", "contain", "include", "have" or other similar semantic descriptions should be interpreted as non-exclusive inclusion. For example, the inclusion of a technical feature element (such as raw materials, components, ingredients, carriers, dosage forms, materials, sizes, parts, components, mechanisms, devices, steps, processes, methods, reaction conditions, processing conditions, parameters, algorithms, signals, data, products or articles, etc.) should be interpreted as not only including the explicitly listed technical feature element, but also including other technical feature elements not explicitly listed in the art.
[0036] The term "consisting of" means excluding any technical feature element not explicitly listed. If this term is used in the claims, the term will make the claim closed, so that it does not contain technical feature elements other than the explicitly listed technical feature elements, except for conventional impurities related thereto. If the term only appears in a certain clause of the claim, it is only limited to the elements explicitly listed in that clause, and the elements described in other clauses are not excluded from the overall claim.
[0037] A filtering vector retrieval method, system, device and storage medium provided by the present application are described in detail below. The contents not described in detail in the embodiments of the present application belong to the prior art known to those skilled in the art. If no specific conditions are specified in the embodiments of the present application, the conventional conditions or the conditions recommended by the manufacturer are used. If no manufacturer of the reagent or instrument used in the embodiments of the present application is specified, it is a conventional product that can be obtained by market purchase.
[0038] Embodiment one
[0039] The embodiments of the present application provide a filtering vector retrieval method, as shown in Figure 1 The method mainly comprises the following steps:
[0040] Step 1: Hierarchical clustering based on distance measurement is performed on vector data.
[0041] In the embodiment of the present application, all vector data in the data set is hierarchically clustered (specifically, hierarchical clustering based on distance measurement), forming a multi-level vector space structure. Preferably, a distance-based clustering algorithm is used to cluster all vector data, completing the division of initial clustering clusters. Exemplarily, the distance-based clustering algorithm can be a K-means clustering algorithm. Then, a hierarchical clustering strategy is used to organize the initial clustering clusters according to levels, forming a multi-level vector space structure.
[0042] In the embodiment of the present application, the core purpose of hierarchical clustering is to construct a clustering tree structure (multi-level vector space structure), which can use a top-down or bottom-up hierarchical clustering strategy. For example, in the top-down hierarchical clustering strategy, starting from a large clustering cluster, each time a clustering cluster is further divided into multiple sub-clustering clusters, and the center point vector data of these sub-clustering clusters are used as the next layer of nodes, and the process is recursively performed until the stop condition (for example, the number of remaining vectors is less than a set value) is met. In this way, a clustering tree structure is finally formed.
[0043] On this basis, the center point vector data of each clustering cluster in the multi-level vector space structure (i.e., the non-leaf nodes in the clustering tree structure) can be used as data in the resident memory, and the remaining vector data (i.e., the leaf nodes in the clustering tree structure) can be used as data in the resident disk, thereby effectively reducing memory usage.
[0044] In the embodiment of the present application, the distance measurement method can be implemented according to the existing scheme as needed. Exemplarily, Euclidean distance, cosine distance, etc. can be selected.
[0045] Step 2, constructing a filter tree and a neighbor graph.
[0046] In the embodiment of the present application, a filter tree (Filter Tree) is constructed based on the multi-level vector space structure, and the center point vector data of each clustering cluster is used as a node of the filter tree. In addition, a neighbor graph is constructed, and the nodes in the neighbor graph are the center point vector data of each clustering cluster. If two center point vector data of each clustering cluster satisfy a set similarity relationship, an edge is added between the corresponding nodes. The nodes in the filter tree and the nodes in the neighbor graph both record the label information of the corresponding clustering cluster. The label information here can include all label sets (i.e., the labels corresponding to the vector data in the clustering cluster) recorded in the node in the clustering cluster. In addition, the label information of the node in the filter tree can also record other information content, which will be described later.
[0047] Step 3, constructing a hybrid inverted structure and segmenting and organizing the disk data.
[0048] In the embodiment of the present application, the vector data of each cluster on the disk is constructed into an inverted data block based on the distance from the center point vector data of the cluster, and is segmented in combination with the label information of the vector data.
[0049] The preferred implementation of this step is as follows: for each cluster, the vector data of each cluster on the disk is sorted based on the distance from the center point vector data of the cluster, a hybrid inverted structure is constructed, and an inverted data block is formed, wherein one cluster corresponds to one inverted data block; the vector data in the inverted data block is divided into a label consistent segment and a label independent segment according to the label information, which is used to read the vector data in the corresponding segment according to the target label when the query request contains a label filtering condition. The vector data in the label consistent segment has the same label information, and the vector data in the label independent segment has different label information; and the inverted data block, the block header metadata and the segment header metadata are stored in a disk page alignment manner, the block header metadata records the number of vector data in the inverted data block, and the segment header metadata records the number, offset address, size information (such as data type and vector dimension, which can directly reflect the actual space occupied by the vector data) and other metadata of the vector data in the corresponding segment.
[0050] Then, the segment header metadata, the block header metadata and the inverted data block are written to the disk, specifically, a disk layout is constructed for subsequent reading of the vector data in the corresponding inverted data block; the disk layout includes two parts: the first part is a data area, which records the inverted data block corresponding to each cluster; the second part is a metadata index area, which records the segment header metadata and the block header metadata.
[0051] Step 4, node selection process based on filter tree and neighbor graph.
[0052] In the query stage, the query vector in the query request is used to preliminarily screen the candidate nodes from the filter tree using the distance-first strategy; based on the preliminarily screened candidate nodes, a neighbor search is performed in the neighbor graph, and the searched nodes form the final node set; wherein if the query request contains a label filtering condition, the corresponding target label is determined for the filtering tree screening and the neighbor graph search process.
[0053] The preferred implementation of this step is as follows:
[0054] (1) The distance-first strategy is used to preliminarily screen the candidate nodes from the filter tree.
[0055] In the preliminary screening process, if the input query contains a label filtering condition, the pruning in the filter tree according to the label information is preferred, that is, only the nodes related to the target label are accessed, and the irrelevant part is skipped, thereby narrowing the search range, and based on the distance priority strategy, the candidate nodes closer to the query vector are selected, further improving the accuracy and efficiency of the neighbor search. The specific process is as follows: if the query request contains a label filtering condition, the downlink search is performed along the node path containing the target label in the filter tree, and the distance priority strategy is used to preliminarily screen the candidate nodes; for the node path containing the target label, the distance between the query vector and each node is calculated, the nodes are sorted in the order of distance from the query vector from near to far, and are maintained in the first priority queue; at each step of downlink search, the nodes more likely to hit are accessed preferentially according to the order of distance from near to far, that is, the node closest to the query vector is taken out from the first priority queue to start downlink search, and the new node obtained in the downlink search process is maintained in the second priority queue and inserted into the first priority queue; the second priority queue has a fixed capacity, when the second priority queue is not filled, the new node obtained in the downlink search process will be added to the second priority queue, if the second priority queue is filled, and the distance between the new node obtained in the downlink search process and the query vector is less than the maximum value of the distance between each node in the second priority queue and the query vector, the new node obtained in the downlink search process is used to replace the node corresponding to the maximum distance from the query vector in the second priority queue; when the number of new nodes obtained by downlink search is the number of leaf nodes (i.e. the end node of a branch in the filter tree) in the filter tree reaches a preset threshold, the preliminary screening process is completed; the nodes in the second priority queue are the candidate nodes screened preliminarily.
[0056] (2) performing neighbor search in the neighbor graph.
[0057] Some nodes (e.g., one or more nodes) in the candidate nodes preliminarily screened out are taken as entry points for an extended search in the near-neighbor graph; if the query request contains a label filtering condition, the near-neighbor search process is controlled in combination with the target label, including: only the adjacent nodes of the target label are subjected to the extended search, or the extended search is performed in a priority manner, wherein the priority of the adjacent nodes with the target label is higher than that of the adjacent nodes without the target label; if the query request does not contain a label filtering condition, the extended search is performed according to the spatial proximity (jump vector search), so as to improve the recall rate; in the extended search process, a candidate set is maintained for recording the plurality of nodes with the closest distance to the query vector obtained in each step of the extended search process, the candidate set has a fixed capacity, if the candidate set is not filled, the new nodes searched will be added to the candidate set, if the candidate set is filled and the distance between the new node searched and the query vector is smaller than the maximum value in the distance between each node in the candidate set and the query vector, the new node is used to replace the node in the candidate set corresponding to the maximum distance from the query vector, so that the candidate set always contains the current optimal several results; as the extended search is promoted, when the maximum value (i.e., the farthest distance) in the distance between each node in the candidate set and the query vector is smaller than the minimum value (i.e., the closest distance) in the distance between the unvisited adjacent nodes and the query vector, the extension process is ended, and the candidate set is output as the final node set; wherein the specific number of the nodes can be set according to the actual situation, and generally, the candidate nodes are sorted according to the distance from the query vector from near to far, and the nodes are taken from the front end of the sorting.
[0058] Step 5, output the search result.
[0059] In the embodiment of the application, the vector data in the entire inverted data block or the corresponding segment of the cluster to which each node in the final node set belongs is loaded from the disk to the memory, and the search result is output in combination with the distance between each loaded vector data and the query vector.
[0060] The preferred embodiment of the present step is as follows:
[0061] (1) For each node in the final node set, the location of the corresponding cluster cluster inverted data block is queried in the metadata index area according to the cluster cluster to which the node belongs (by querying the offset address recorded), and the vector data in the corresponding inverted data block is read from the data area and loaded into the memory; wherein, when the query request contains a label filtering condition, the vector data of the label consistent segment in the corresponding inverted data block is loaded in combination with the target label, or if the overall proportion of the label filtered in the label filtering condition in the data set (the set composed of all vector data in the hierarchical clustering in the foregoing step 1) is higher than a set threshold, the vector data of the entire inverted data block is loaded; when the query request does not contain a label filtering condition, the vector data of the label-independent segment in the inverted data block or the entire inverted data block is loaded; block-level sequential reading is used in the loading process, the disk page alignment design is fully utilized, and the data loading performance is improved.
[0062] (2) If the query request contains a label filtering condition, and the overall proportion of the label filtered in the label filtering condition in the data set is higher than a set threshold, the vector data of the entire inverted data block is loaded, then the vector data in the loaded inverted data block is filtered according to the target label; the distances between the filtered vector data and the query vector are calculated respectively, the filtered vector data are sorted in ascending order of distance, and the first k vector data in the sorted order are taken as the retrieval result; if the query request contains a label filtering condition, and the vector data in the corresponding label consistent segment is loaded in combination with the target label, or the query request does not contain a label filtering condition, the distances between the loaded vector data and the query vector are calculated, the vector data are sorted in ascending order of distance, and the first k vector data in the sorted order are taken as the retrieval result.
[0063] As can be understood by those skilled in the art, the input vector data described in the embodiments of the present application can be derived from the embedding representation of various upstream tasks, such as image feature encoding, text encoding or multi-modal semantic embedding. Essentially, it is a structured high-dimensional vector set, which is usually output by a pre-trained model or a vectorization module (such as Transformer, BERT, etc.) as the input of a subsequent downstream retrieval system or recommendation module. Among them, Transformer is a transformation neural network, and BERT is a bidirectional encoder based on Transformer.
[0064] Compared with the prior art, the application realizes double pruning search paths of labels and space by constructing a filter tree supporting label information and combining a hierarchical clustering strategy of vector space; meanwhile, the high-performance search ability in a non-filtering scenario is reserved by introducing a neighbor graph, so that stable search effects are ensured under various filtering selection rates. In addition, the application reasonably divides label consistent segments and label independent segments by using a hybrid segmented organization of disk inverted lists, and effectively reduces the number of disk I / O (input / output) times by combining a disk page alignment strategy, so that the response speed in a query delay sensitive scenario is improved.
[0065] In order to more clearly show the technical solutions provided by the application and the technical effects produced, the method provided by the embodiments of the application is described in detail below with specific embodiments.
[0066] I. Overall introduction of the scheme.
[0067] Considering that the traditional vector retrieval scheme often faces the following problems when meeting the two constraints of spatial similarity retrieval + label filtering at the same time: first, if only relying on vector space index (such as filter tree or neighbor graph) for label-free neighbor search, and then adding label filtering at the end of the result, a large number of invalid expansion and irrelevant I / O will be introduced, resulting in a significant increase in delay; second, if the label dimension is indexed separately and connected with the vector index, the contradiction of "filtering effective but neighbor recall insufficient" often occurs, and it is difficult to achieve stable performance balance between different label selection rates (low selection rate / high selection rate / no filtering). Based on this, the embodiment of the present application proposes a "memory-disk hierarchical, label-space dual pruning, filter tree-neighbor graph combined" architecture: in the index construction stage (i.e. the above steps 1~3), first, the full amount of vectors are clustered and layered, a part of representative vector data (i.e. the center point vectors of the cluster) is selected to reside in memory, and the remaining vectors reside in disk, and two types of memory indexes (filter tree and neighbor graph) are constructed simultaneously to serve different retrieval paths; on the disk side, the hybrid inverted structure facing the query scene is generated with the center point vectors of the cluster as the granularity, the vectors in the same cluster are divided into "label consistent segment" and "label irrelevant segment" according to the distance from the center point, and the block-page alignment strategy is used to reduce random I / O. In the online query stage (i.e. the above steps 4~5), first, the filter tree is used to quickly prune according to the label condition and lock the candidate node according to the distance priority strategy, then the candidate node is used as the entrance to expand the search on the neighbor graph, and finally the inverted data block of the corresponding cluster is selectively read into memory according to the search result on the neighbor graph, and the fine screening and result aggregation are performed; thereby realizing the cooperative pruning of "filtering and space", and maintaining relatively stable recall and delay performance under different label selection rates.
[0068] II. Detailed introduction of the scheme.
[0069] The scheme provided by the embodiment of the present application mainly includes: index construction stage and online query stage, and the related steps of each stage will be introduced in detail.
[0070] 1. Index construction stage.
[0071] The index construction stage mainly includes: hierarchical clustering, memory index construction, construction and segmented organization of hybrid inverted structure (Hybrid Postings), and disk index and layout output.
[0072] (1) Hierarchical clustering.
[0073] In the embodiment of the present application, all vectors are clustered based on distance measurement to form a multi-level vector space structure. Preferably, K-means or other distance-based clustering methods can be used to complete the division of initial clustering clusters, and then a hierarchical clustering strategy is used to form a multi-level vector space structure; for large-scale data sets, sampling or hierarchical clustering can be performed first to ensure the representative distribution of the center points in the global space.
[0074] In the embodiment of the present application, the center point vector of each clustering cluster is used as a "memory resident vector", and the remaining vectors in the clustering cluster are used as "disk resident vectors". The number of center point vectors (the number of clustering clusters) and the number of levels can be flexibly set according to the data size, memory budget and target delay, and the present application does not limit the specific values. Through the hierarchical clustering strategy, only the highly representative center point set is retained in the memory, and a wider vector space structure is covered with smaller memory occupation, which provides a good skeleton for subsequent "tree-graph joint indexing".
[0075] (2) Memory index construction.
[0076] In the embodiment of the present application, the constructed memory index mainly refers to the filter tree and the neighbor graph.
[0077] (2.1) Constructing a filter tree. The multi-level vector space structure is used as the topology, and each clustering cluster center point vector is mapped to a node in the filter tree. As shown in the following formula (1), an example of the structure of the filter tree is shown, and each circle represents a node. In this example, a three-level vector space structure is used. Figure 2
[0078] Preferably, the label metadata related to the clustering cluster of each node is recorded as the label information of the node, and the filter tree is used to support the efficient filtering retrieval of subsequent labeled conditions. The label metadata includes but is not limited to: the label set in which the clustering cluster appears, and the approximate count or proportion of each label, etc. The present application does not limit the encoding method of the specific metadata, and can be implemented by using set, interval statistics, abstract count, etc. The filter tree is used to perform "label first and space later" pruning when the query contains a label condition: when the target label is queried, only the "node branch containing the target label" needs to be followed down, thereby skipping a large number of irrelevant branches; on this basis, the distance between the query vector and the node center point is combined to preferentially drill down the branch that is more likely to hit, thereby reducing invalid expansion.
[0079] When the tag metadata is a tag set, filtering can be directly combined with the tag filtering condition; when the tag metadata contains a tag set and also contains count and proportion, since the filtering tree has a clear parent-child node inclusion relationship, filtering can also be performed therefrom, and the principle is as follows: the node of the filtering tree is the vector data of the center point, which aggregates the tag metadata of all vectors in the cluster, if the target tag in the query does not appear in the tag set of the node, it can be reasonably inferred that the node and all its child nodes do not contain data satisfying the condition. Therefore, pruning can be directly performed during traversal, and the node and its entire subtree can be skipped.
[0080] (2.2) Construct a neighbor graph. The neighbor graph is a graph index structure, which can provide neighbor jumping capability in a filtering-free scenario to improve search recall rate and efficiency. In order to retain the native neighbor search performance in the filtering-free scenario, while making up for the possible recall deficiency of the filtering tree on complex spatial structures, the present application constructs a neighbor graph with the center point vectors of all cluster centers as nodes, and the edges of the neighbor graph represent the similarity relationship between the center point vectors of the cluster (for example, each node maintains the connection of several adjacent nodes). As shown in FIG. 3, it is a structure example of the neighbor graph, each circle represents a node, and the horizontal line represents the edge of the node. Figure 3
[0081] The neighbor graph supports neighbor traversal of “jumping-expansion” from any entry point. In the query stage, if there is no tag filtering condition, the neighbor graph can directly provide efficient neighbor expansion; if there is a tag filtering condition, the node tag metadata can be referred to for immediate filtering during traversal, and only the nodes satisfying the tag constraint are retained to continue expansion. Through the cooperation of the filtering tree and the neighbor graph, the range can be quickly narrowed when there is filtering, and the neighbor search capability with high recall can be maintained when there is no filtering.
[0082] The filtering tree and the neighbor graph constructed above are all stored in the memory.
[0083] (3) Construction and segmented organization of hybrid postings.
[0084] In the embodiment of the present application, the hybrid postings are constructed on the disk in units of “cluster”, which are used to store the “disk resident vectors” in the cluster. Specifically:
[0085] (3.1) Distance ordering and blocking: The disk resident vectors in the cluster are sorted according to their distance from the center point vector of the cluster from near to far, and are constructed into inverted data blocks. Each inverted data block contains all vector data of the resident disk in the corresponding cluster, and the block header saves the entry number (i.e. the number of vector data) of the inverted data block, etc.
[0086] (3.2) Tag segmentation: further divide the chunk into two types of segments according to the query scenario: one is tag consistent segment, which means that the vectors in the segment have the same target tag (or a small set of target tags), and the segment is preferentially served for low selection rate filtering query; the other is tag independent segment, which means that the segment does not distinguish tags and is used for batch sequential reading in no filtering or high tag selection rate scenario. Different clustering clusters can adopt different segment proportions according to the sparsity / density of tag distribution, and the application does not limit the specific proportion value.
[0087] (3.3) Page alignment and I / O friendly: in order to reduce random I / O overhead, each inverted data block, segment header metadata and index item is preferably stored in an integer multiple (such as a multiple of 4KB) of disk page size, which facilitates sequential reading of the inverted data block in the query stage.
[0088] Through the above organization mode, when the query contains tag filtering and the selection rate is low, the "tag consistent segment" can be directly located and preferentially read, avoiding loading a large amount of irrelevant data from the source; and when there is no filtering or the selection rate is high, it can fall into the sequential scanning path of the "tag independent segment", and the throughput advantage of sequential reading is fully utilized.
[0089] As shown in Figure 4 , an example of the organization and disk layout of the hybrid inverted structure is shown, and each rectangle represents a vector data, and a tag independent segment and a tag consistent segment form an inverted data block.
[0090] (4) Disk index and layout output.
[0091] In the embodiment of the application, after the hybrid inverted structure is constructed, a stable disk layout needs to be output for the query stage to quickly locate. The layout includes two parts: one is the data area, that is, the inverted data blocks of each clustering cluster are sequentially written according to the clustering cluster or according to the file grouping; the other is the metadata index area, which records the segment header metadata and the block header metadata, including the file offset, length, block item number and segment type (tag consistent / independent) of each clustering cluster (and each segment and each block thereof).
[0092] Preferably, a global directory can be maintained in the file header or an independent metadata file, which supports locating the corresponding clustering cluster metadata (file offset, length, block item number and segment type) in constant time according to the ID of the center point vector data, and further locating the target segment / block. The file header or independent metadata file refers to an additional maintained metadata structure, which can be configured as part of the storage structure, and the global directory refers to a position mapping table for recording the metadata of each clustering cluster in the storage. The application does not limit the specific file splitting and directory organization strategy, as long as the block level addressing and reading can be efficiently and stably completed during the query. Thus, the index construction stage is completed.
[0093] 2. Online query phase.
[0094] The online query phase mainly includes: label pruning and distance-first strategy on the filter tree, extended search on the neighbor graph, block-oriented disk access and data loading, candidate vector fine screening and result aggregation.
[0095] (1) Label pruning and distance-first strategy on the filter tree.
[0096] After receiving the query vector and optional label filtering condition, first enter the filter tree for "label first, space second" pruning. Specifically, according to the target label in the query request, proceed downward along the node path containing the target label, and skip branches that do not contain the target label, thereby quickly narrowing the candidate range.
[0097] Preferably, at each step of downward access, the distance between the query vector and the node is referred to, and the node that is more likely to hit is selected for priority access according to the distance from near to far, and the downward search is performed; when the number of new nodes obtained by the search reaches a preset threshold, the search is ended and the preliminarily screened candidate nodes are output as the entry of the next stage. The present application does not limit the threshold setting, distance measurement type and early termination condition, which can be flexibly selected according to data distribution and performance target.
[0098] (2) Extended search on the neighbor graph.
[0099] One or more candidate nodes preliminarily screened are used as entry points, and the extended search is performed on the neighbor graph. Preferably, when there is a label filtering condition, only the adjacent center points that meet the label condition are subjected to the extended search, or the nodes that do not meet the condition are given low priority processing to avoid invalid traversal on the neighbor graph; when there is no filtering condition, the extended search can be completely performed according to spatial proximity. In the process of the extended search, a small-scale candidate set can be maintained to record the current optimal nodes (i.e. some nodes closest to the query vector), and an access flag is used to avoid repeated expansion. As the extended search progresses, when the worst distance of the candidate set (i.e. the maximum value in the distances between the nodes in the candidate set and the query vector) is better than the best reachable estimate of the unvisited adjacent nodes (i.e. the minimum value in the distances between the unvisited adjacent nodes and the query vector), the convergence can be achieved, and the final node set for accessing the disk is output. Through the two-stage process of "pruning on the tree + expansion on the graph", the ability of the filter tree to quickly narrow the range under the label condition is inherited, and the high recall performance of the neighbor graph under complex spatial structure is retained.
[0100] (3) Block-oriented disk access and data loading.
[0101] According to the node set obtained by the foregoing process, the mixed inverted position of the corresponding cluster is searched in the metadata index area, and an actual data loading stage is entered. Preferably, if the query has a label filtering condition, and the single node in the node set output by the extended search exists in a "label consistent segment" in the cluster, the vector data in the segment is preferentially loaded into the memory by block, or if the overall proportion of the label filtered in the label filtering condition in the data set is higher than a set threshold, the vector data of the entire inverted data block is loaded; if there is no filtering or a high selection rate scenario, the "label independent segment" or the entire inverted data block is directly loaded. In engineering, block-level sequential reading combined with page alignment design can significantly reduce the number of random I / Os; concurrent reading of multiple clusters can use batch prefetching and queuing scheduling to balance throughput and delay. It should be noted that the present application does not limit the block size, batch concurrency, and cache strategy, which can be adaptively adjusted according to the device bandwidth and system load.
[0102] (4) Candidate vector fine screening and result aggregation.
[0103] After the relevant vector data is loaded into the memory by the foregoing process, the distance from the query vector is calculated, and the candidate sequence is formed by sorting from near to far, and the top k vector data in the sequence is extracted as the retrieval result.
[0104] Specifically, if the query contains a label filtering condition, and the overall proportion of the label filtered in the label filtering condition in the data set is higher than a set threshold, the vector data of the entire inverted data block is loaded, in which case only the vector consistent with the filtering condition is retained for final sorting. If the query request contains a label filtering condition, and the corresponding label consistent segment is loaded with the vector data of the target label, or does not contain a filtering condition, the Top-k result is directly generated according to the distance sorting, i.e., the first k vector data in the candidate sequence is selected. It should be noted that the present application does not set an early termination process, and the entire inverted data block of the cluster involved must be calculated before the final nearest neighbor result set is output. Finally, the Top-k result and its related information (such as the label of the vector data) are returned to the upper layer application, and a query process is completed.
[0105] Those skilled in the art can understand that the label of the vector data belongs to the general technical terms in the art, for example, the vector data is {2, 1, 4, 7}, and the label can be color: red, date: September 15, etc., that is, the label belongs to the additional description of the vector data. Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiments can be realized by software, or can be realized by means of software and necessary general hardware platform. Based on such understanding, the technical solutions of the above embodiments can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a U disk, a mobile hard disk, etc.), and includes a plurality of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the method described in each embodiment of the application.
[0106] Embodiment two
[0107] The application also provides a filtering vector retrieval system, which is mainly used for implementing the method provided in the above embodiments, as shown in the figure, the system mainly includes: Figure 5
[0108] A hierarchical clustering unit is configured to perform hierarchical clustering on the vector data to form a multi-level vector space structure, and to store the center point vector data of each clustering cluster in the memory and the remaining vector data on the disk.
[0109] A filtering tree and a neighbor graph construction unit is configured to construct the filtering tree and the neighbor graph based on the multi-level vector space structure, and to take the center point vector data of each clustering cluster as the nodes of the filtering tree and the neighbor graph, and to record the label information of the corresponding clustering cluster in the nodes of the filtering tree and the nodes of the neighbor graph.
[0110] A hybrid inverted structure construction unit is configured to construct the vector data of each clustering cluster on the disk into an inverted data block based on the distance of the center point vector data of the clustering cluster, and to segment the inverted data block in combination with the label information of the vector data.
[0111] A node selection unit based on the filtering tree and the neighbor graph is configured to, in a query stage, preliminarily screen the candidate nodes from the filtering tree according to the query vector in the query request by using a distance-first strategy, to perform a neighbor search in the neighbor graph in combination with the candidate nodes, and to obtain a final node set; if the query request contains a label filtering condition, to determine a target label, to perform a downward search along the node path containing the target label in the filtering tree, to preliminarily screen the candidate nodes by using the distance-first strategy, and to control the neighbor search process in combination with the target label.
[0112] The retrieval result output unit is used for loading the vector data in the entire inverted data block or the corresponding segment of the cluster to which each node in the final node set belongs from the disk into the memory, combining the distance between the loaded vector data and the query vector, and outputting the retrieval result.
[0113] The details of the related processing involved in each unit in the system have been described in detail in the previous embodiments, and thus will not be described again.
[0114] Those skilled in the art can clearly understand that, for the convenience and brevity of description, only the division of the above functional modules is taken as an example, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the system is divided into different functional modules to complete all or part of the functions described above.
[0115] Embodiment three
[0116] The application further provides a processing device, as shown in the drawings, mainly comprising: one or more processors; a memory for storing one or more programs; wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided by the foregoing embodiments. Figure 6
[0117] Further, the processing device further comprises at least one input device and at least one output device; in the processing device, the processor, the memory, the input device and the output device are connected through a bus.
[0118] In the embodiments of the application, the specific types of the memory, the input device and the output device are not limited; for example:
[0119] The input device can be a touch screen, an image acquisition device, a physical button or a mouse, etc.
[0120] The output device can be a display terminal.
[0121] The memory can be a random access memory (RAM) or a non-volatile memory such as a disk memory.
[0122] Embodiment four
[0123] The application further provides a readable storage medium storing a computer program, when the computer program is executed by a processor, the method provided by the foregoing embodiments is implemented.
[0124] The readable storage medium in the embodiments of the present application can be arranged in the foregoing processing device as a memory in the processing device. In addition, the readable storage medium can also be a U disk, a mobile hard disk, a read-only memory (ROM), a magnetic disk or an optical disk, and various media capable of storing program codes.
[0125] The above merely describes the preferred embodiments of the present application, but the protection scope of the present application is not limited to this. Any person skilled in the art can easily think of changes or replacements within the technical scope disclosed by the present application, which should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims. The information disclosed in the background section of the present application is merely intended to deepen the understanding of the general background of the present application, and should not be regarded as acknowledging or implying in any form that the information constitutes the prior art known by the person skilled in the art.
Claims
1. A filtering vector retrieval method, characterized by, The method comprises the following steps: Hierarchical clustering of vector data to form a multi-level vector space structure, the center point vector data of each cluster is resident in the memory, and the rest of the vector data is resident in the disk; Based on the multi-level vector space structure, a filter tree and a neighbor graph are constructed: the center point vector data of each cluster is taken as a node of the filter tree and the neighbor graph, and the nodes in the filter tree and the nodes in the neighbor graph record the label information of the corresponding cluster; Based on the distance from the center point vector data of the cluster, the vector data of each cluster on the disk is constructed into an inverted data block, and the vector data is segmented in combination with the label information; In the query stage, according to the query vector in the query request, the distance priority strategy is used to preliminarily screen the candidate nodes from the filter tree, and the neighbor search is performed in the neighbor graph in combination with the candidate nodes to obtain the final node set; If the query request contains a label filtering condition, the target label is determined, the downward search is performed along the node path containing the target label in the filter tree, the distance priority strategy is used to preliminarily screen the candidate nodes, and the neighbor search process is controlled in combination with the target label; The entire inverted data block or the vector data in the corresponding segment of the cluster to which each node in the final node set belongs is loaded from the disk to the memory, the distance between the loaded vector data and the query vector is combined, and the retrieval result is output.
2. The filtering vector retrieval method according to claim 1, wherein, The hierarchical clustering of vector data to form a multi-level vector space structure comprises: All vector data is clustered by using a distance-based clustering algorithm to complete the division of initial cluster; and the initial cluster is organized according to levels by using a hierarchical clustering strategy to form a multi-level vector space structure.
3. The filtering vector retrieval method of claim 1, wherein, The vector data of each cluster on the disk is sorted based on the distance from the center point vector data of the cluster to construct a hybrid inverted structure to form an inverted data block; wherein one cluster corresponds to one inverted data block. The vector data in the inverted data block is divided into a label consistent segment and a label independent segment according to the label information, which is used to read the vector data in the corresponding segment according to the target label when the query request contains a label filtering condition; wherein the vector data in the label consistent segment has the same label information, and the vector data in the label independent segment has different label information. Furthermore, the inverted data block, the block header meta information and the segment header meta information are stored in a disk page alignment manner, the number of vector data in the inverted data block is recorded in the block header meta information, and the number, offset address and size information of the vector data in the corresponding segment are recorded in the segment header meta information. The method further comprises the following steps:
4. The filtering vector retrieval method according to claim 3, wherein, A disk layout is constructed for reading the vector data in the corresponding inverted data block; The disk layout comprises two parts: a first part is a data area, recording the inverted data block corresponding to each cluster; and a second part is a metadata index area, recording the segment header meta information and the block header meta information. For each node in the final node set, the location of the corresponding inverted data block is queried in the metadata index area according to the cluster to which the node belongs, and the vector data in the corresponding inverted data block is read from the data area and loaded into the memory; wherein, when the query request contains a label filtering condition, the vector data in the label consistent segment of the corresponding inverted data block is loaded in combination with the target label, or if the overall proportion of the filtered label in the data set is higher than a set threshold, the vector data of the entire inverted data block is loaded; when the query request does not contain a label filtering condition, the vector data in the label-independent segment or the entire inverted data block is loaded; wherein, the data set is a set composed of all vector data when the hierarchical clustering is performed.
5. The filtering vector retrieval method of claim 1, wherein, The downlink search along the node path containing the target label in the filter tree adopts a distance-first strategy to preliminarily screen candidate nodes, and includes the following steps: For the node path containing the target label, the distance between the query vector and each node is calculated, the nodes are sorted in order from near to far according to the distance from the query vector, and are maintained in a first priority queue. In each step of the downlink search, the node closest to the query vector is taken out from the first priority queue to start the downlink search, and the new nodes obtained in the downlink search process are maintained in a second priority queue. When the second priority queue is not filled, the new nodes obtained in the downlink search process are all added to the second priority queue and inserted into the first priority queue. The second priority queue has a fixed capacity. If the second priority queue is filled and the distance between the new node obtained in the downlink search process and the query vector is less than the maximum distance between the nodes in the second priority queue and the query vector, the new node obtained in the downlink search process is used to replace the node corresponding to the maximum distance in the second priority queue. When the number of new nodes obtained in the downlink search reaches a preset threshold, the preliminary screening process is completed. The nodes in the second priority queue are the candidate nodes screened preliminarily.
6. The filtering vector retrieval method of claim 1, wherein, The neighbor search in the neighbor graph in combination with the candidate nodes includes: Some nodes in the candidate nodes screened preliminarily are used as entry points for an extended search in the neighbor graph. If the query request contains a label filtering condition, the neighbor search process is controlled in combination with the target label, including: only the adjacent nodes with the target label are subjected to the extended search, or the extended search is performed in a priority manner, wherein the priority of the adjacent nodes with the target label is higher than that of the adjacent nodes without the target label; if the query request does not contain a label filtering condition, the extended search is performed according to the spatial proximity; In the extended search process, a candidate set is maintained to record the plurality of nodes with the closest distance to the query vector obtained in each step of the extended search process, the candidate set has a fixed capacity, if the candidate set is not filled, the new node searched will be added to the candidate set, if the candidate set is filled and the new node searched has a distance to the query vector smaller than the maximum distance of the nodes in the candidate set to the query vector, the node in the candidate set corresponding to the maximum distance is replaced by the new node; as the extended search proceeds, when the maximum distance of the nodes in the candidate set to the query vector is smaller than the minimum distance of the unvisited adjacent nodes to the query vector, the extension process is ended and the candidate set is output as the final node set.
7. The filtering vector retrieval method of claim 4, wherein, The distance between each vector data loaded and the query vector is output to include the retrieval result, and the distance between each vector data loaded and the query vector is output to include the retrieval result. If the query request contains a label filtering condition and the overall proportion of the labels belonging to the label filtering condition in the data set is higher than a set threshold, the vector data in the loaded inverted data block is filtered according to the target label; the distance between each filtered vector data and the query vector is calculated, each filtered vector data is sorted in ascending order of distance, and the first k vector data in the sorted order is taken as the retrieval result; If the query request contains a label filtering condition and the vector data in the corresponding label consistent segment loaded in combination with the target label, or the query request does not contain a label filtering condition, the distance between each loaded vector data and the query vector is calculated, each vector data is sorted in ascending order of distance, and the first k vector data in the sorted order is taken as the retrieval result.
8. A filtering vector retrieval system, characterized by, The method for implementing any one of claims 1-7 comprises: A hierarchical clustering unit is configured to perform hierarchical clustering on the vector data to form a multi-level vector space structure, and to keep the center point vector data of each clustering cluster in the memory and the remaining vector data on the disk. A filter tree and a neighbor graph construction unit is configured to construct a filter tree and a neighbor graph based on the multi-level vector space structure: the center point vector data of each clustering cluster is taken as a node of the filter tree and the neighbor graph, and the nodes in the filter tree and the nodes in the neighbor graph record the label information of the corresponding clustering cluster. A hybrid inverted structure construction unit is configured to construct the vector data of each clustering cluster on the disk into an inverted data block based on the distance of the center point vector data of the clustering cluster, and to segment the inverted data block based on the label information of the vector data. A node selection unit based on the filter tree and the neighbor graph is configured to, in the query stage, preliminarily select candidate nodes from the filter tree according to the query vector in the query request, perform neighbor search on the candidate nodes in the neighbor graph to obtain a final node set; if the query request contains a label filtering condition, a target label is determined, a downward search is performed along the node path containing the target label in the filter tree, candidate nodes are preliminarily selected using a distance-first strategy, and the neighbor search process is controlled in combination with the target label. The retrieval result output unit is configured to load the vector data in the entire inverted data block or the corresponding segment of the cluster to which each node in the final node set belongs from the disk into the memory, combine the loaded vector data with the distance between the query vector, and output the retrieval result.
9. A processing device, characterized by The computer program product comprises: one or more processors; a memory configured to store one or more programs; wherein the one or more programs, when executed by the one or more processors, enable the one or more processors to implement the method according to any one of claims 1-7.
10. A readable storage medium, storing a computer program, characterized in that, The computer program, when executed by a processor, implements the method according to any one of claims 1-7.
Citation Information
Patent Citations
Distributed intelligent retrieval method and system for spatio-temporal data
CN118838937A
Vector indexing method and device, electronic equipment and readable storage medium
CN119046285A