Spatial and high-dimensional approximate nearest neighbor hybrid query method and system for electronic maps

CN118277494BActive Publication Date: 2026-10-23SHANGHAI JIAOTONG UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211738410.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-30
Publication Date
2026-10-23
Estimated Expiration
2042-12-30

AI Technical Summary

Technical Problem

利用融合距离度量机制建立邻接图解决查询效率与准确性的问题,实现高效准确的空间范围和k近似最近邻混合查询

Benefits of technology

[0042]本发明创新性地设计了一种基于邻接图的空间与高维近似最近邻混合查询方法,大大优化了空间与高维向量混合查询效率,在查询选择率大的时候与现有相关技术比有很大的效率优势。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118277494B_ABST
    Figure CN118277494B_ABST
Patent Text Reader

Abstract

The application provides a system and method for spatial and high-dimensional approximate nearest neighbor hybrid query of an electronic map, comprising: a data processing module, which is used for reading data in a disk into a memory as spatial data sets and high-dimensional vector data sets and processing the data into a data structure that can be processed by index construction; an index construction module, which is used for constructing a final adjacency graph index by using an index construction method on the data structure processed by the data processing; and a query module, which is used for receiving a query request and returning a query result. The application uses a fusion distance measurement mechanism to establish an adjacency graph to solve the problems of query efficiency and accuracy, realizes efficient and accurate spatial range and k approximate nearest neighbor hybrid query, and greatly optimizes the efficiency of spatial and high-dimensional vector hybrid query, and has a great efficiency advantage over the prior art when the query selection rate is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to spatial indexing and high-dimensional vector indexing technologies, and in particular to a hybrid query method and system for spatial data and unstructured data, specifically to a hybrid query method and system for spatial and high-dimensional approximate nearest neighbors of electronic maps. Background Technology

[0002] With the booming development of the internet, more and more users are accessing it, exceeding 4.57 billion in 2020. The widespread adoption of applications such as social networks and email has led to a rapid increase in massive amounts of multimedia data (i.e., images, voice, text, music, and video). For example, users using mobile devices to communicate, share interesting experiences, and express personal opinions on social networks (such as Twitter, Instagram, Weibo, and WeChat) generate records, which typically include images, videos, text, and voice data. Instagram users upload an average of 95 million photos and videos daily, while Facebook users post 5.1 million comments and 2.93 million status updates every hour. People and devices connected to the internet generate more than 2.5 trillion bytes of data daily. This multimedia data often stores not only the location information of spatial objects (or positions of interest, POIs) but also keywords with semantic information. This presents challenges for the mixed query analysis of spatial data and unstructured data.

[0003] POI stands for Point of Interest. On electronic maps, POIs represent restaurants, supermarkets, government offices, tourist attractions, transportation facilities, and so on. POIs are the core data of electronic maps. For ordinary users, the name and location information contained in POI data can satisfy their basic needs for "finding a destination" on an electronic map, thereby triggering navigation services. For example, a user provides an image and needs to search for the top ten restaurants within a five-kilometer radius that are closest to the image. Here, "five-kilometer radius" requires spatial range querying, while "similar restaurant search" requires vector similarity querying. This necessitates indexing the location and image information of POIs to answer such mixed queries involving spatial and unstructured data.

[0004] Currently, there are many different indexing methods and systems for spatial data and unstructured data. For example, for spatial data indexing, there are technologies such as R-trees, KD-trees, and grid indexes, and corresponding processing platforms for large spatial data, such as Simba, GeoSpark, and SpatialSpark. For unstructured data, there are PASE systems that support two approximate nearest neighbor search algorithms, IVFFlat and HNSW, and AnalyticDB-V systems (ADBV for short) that support mixed queries of one-dimensional attributes and high-dimensional vectors. Figure 4 And Milvus, a similarity search system specifically built for large-scale vector data (see...). Figure 3 ). Figure 3 Milvus primarily consists of three components: the query engine, the GPU engine, and the storage engine. The query engine supports efficient query processing of vector data and is optimized for modern CPUs by reducing cache misses and utilizing SIMD instructions. The GPU engine is a co-processing engine that accelerates performance through extensive parallelism. It also supports multiple GPU devices for improved efficiency. The storage engine supports data storage and combines an LSM-based architecture for dynamic data management; it runs on various storage systems, including native systems, Amazon S3, and HDFS. Figure 4 ADBV provides an interface that enables users to express mixed queries using SQL semantics by transforming unstructured data into high-dimensional data. It adopts a lambda framework and leverages the advantages of Approximate Nearest Neighbor Search (ANNS) technology to support mixed data analysis.

[0005] The above work has the following three shortcomings in the application of spatial and high-dimensional approximate nearest neighbor hybrid queries:

[0006] 1) Existing spatial big data processing platforms (Simba, GeoSpark, SpatialSpark) are inefficient at querying high-dimensional vector data and do not support the optimization of mixed queries of spatial data and high-dimensional vector data.

[0007] 2) High-dimensional vector data processing engines and systems (PASE, Vearch, Mixer) provide functions such as vector retrieval and similarity query, but these studies have not considered the problem of mixed query and optimization of structured and unstructured data (high-dimensional vector data).

[0008] 3) Existing mixed query processing systems for structured and unstructured data (Milvus, ADBV, PandaDB) support mixed query optimization for one-dimensional structured data and high-dimensional vector data, but none of them consider the case of mixed queries for spatial data and high-dimensional vector data. Summary of the Invention

[0009] To address the shortcomings of existing technologies, this invention provides a hybrid query method supporting spatial data and high-dimensional vector data: a hybrid query method for spatial and high-dimensional approximate nearest neighbors based on adjacency graphs. It utilizes a fusion distance metric mechanism to establish an adjacency graph, solving the problems of query efficiency and accuracy, and achieving efficient and accurate hybrid queries for spatial range and k-approximate nearest neighbors. To this end, this invention also provides a hybrid query system for spatial and high-dimensional approximate nearest neighbors based on adjacency graphs.

[0010] In a first aspect, embodiments of the present invention propose a hybrid spatial and high-dimensional approximate nearest neighbor query method for electronic maps, the method comprising the following steps:

[0011] Data processing: Divide the data on the disk into spatial datasets and high-dimensional vector datasets, read them into memory, process them into indexes, and build a data structure that can be processed;

[0012] Index building: The final adjacency graph index is constructed from the processed data structure using index building methods;

[0013] Query: Receives query requests and returns query results.

[0014] In some embodiments, the present invention provides a spatial and high-dimensional approximate nearest neighbor hybrid query method for electronic maps. In the data processing step, the data in the disk is divided into spatial datasets and high-dimensional vector datasets and read into memory, specifically input in CSV text format.

[0015] In some embodiments, the present invention provides a hybrid spatial and high-dimensional approximate nearest neighbor query method for electronic maps. In the data processing step, the input data type is CSV, including a spatial dataset S and a high-dimensional vector dataset V. The data processing step determines whether the data conforms to specifications, and then assembles the spatial data and high-dimensional vector data into an items set according to their indices. Each item includes the latitude and longitude (x0, y0), (x1, y1), (x2, y2)...(x...). n ,y n And a high-dimensional vector vec0, vec1, vec2...vec n .

[0016] In some embodiments, the present invention provides a spatial and high-dimensional approximate nearest neighbor hybrid query method for electronic maps, wherein the index construction step specifically includes:

[0017] Define the fusion distance formula between two data: Given a set of items consisting of spatial data and high-dimensional vector data, the distance between any two items is defined as Distance = a * spatial_distance + b * vector_distance, where spatial_distance is the spatial distance between the two items, vector_distance is the high-dimensional vector distance between the two items, and a and b are the parameters of these two distances, respectively.

[0018] Initialization phase: First, each item is initialized as a node. Then, for each node, S nodes are randomly generated as the current node's adjacent nodes. Then, the fusion distance between the current node and its adjacent nodes is calculated, and the L nodes with the closest distance are taken as the final adjacent nodes. Here, S and L are two parameters that need to be set manually. Each node mainly consists of two parts: the item and the set of IDs of its adjacent nodes, Neighbors.

[0019] Optimization and pruning phase: This phase explores even closer neighbors by further exploring the neighbors of neighbors. For each node, first, K nodes other than itself are randomly selected from all nodes. Assuming the node being processed is v, when u1 is a neighbor of v and u2 is a neighbor of u1, the fusion distance between v and u2 needs to be calculated. If this distance is smaller than the distance between v and the farthest neighbor, the farthest neighbor is removed and u2 is added as a new neighbor of v.

[0020] In some embodiments, the present invention provides a hybrid query method for spatial and high-dimensional approximate nearest neighbors of an electronic map, wherein in the formula for defining the fusion distance between two data points, a is set to 1, and b is set to 2*vector distance / spatial distance according to the order of magnitude ratio of spatial distance and vector distance.

[0021] In the initialization phase, S is set to k / 4, and L is set to a number slightly larger than k. The larger S and L are, the higher the quality of the graph construction, but the corresponding construction time and computational load will also increase. k represents the number of query results. The queryer can specify how many of the most relevant results to retrieve, and k can be arbitrarily specified by the queryer.

[0022] Once the index is built, the index file will be persisted to disk.

[0023] In some embodiments, the present invention provides a spatial and high-dimensional approximate nearest neighbor hybrid query method for electronic maps. In the query step, the corresponding index file is read from the disk, and each query undergoes a two-stage search of coarse filtering followed by fine filtering to output the final result to a specified file.

[0024] In some embodiments, the present invention provides a spatial and high-dimensional approximate nearest neighbor hybrid query method for electronic maps. The coarse filtering refers to not calculating the distance between all adjacent points and the high-dimensional vector in the query each time, but randomly selecting m*k distances from the current point for calculation, where k is obtained from the query parameters and represents the number of query results. The queryer can specify how many of the most relevant results to retrieve, and k can be arbitrarily specified by the queryer. m is a decimal between 0 and 1, and the smaller m is, the coarser the granularity of the coarse filtering stage. After each calculation, the point with the largest distance less than the current result set is updated to the result set. The fine filtering refers to: when the number of times the result set is updated each time is less than the threshold, a greedy strategy of calculating the distance of all adjacent points is adopted to ensure the final accuracy.

[0025] Secondly, embodiments of the present invention propose a spatial and high-dimensional approximate nearest neighbor hybrid query system for electronic maps, comprising:

[0026] The data processing module is used to divide the data on the disk into spatial datasets and high-dimensional vector datasets, read them into memory, process them into indexes, and build data structures that can be processed.

[0027] The index building module is used to construct the final adjacency graph index from the processed data structure using index building methods;

[0028] The query module is used to receive query requests and return query results.

[0029] In some embodiments, the present invention provides a hybrid query system for spatial and high-dimensional approximate nearest neighbors of an electronic map. The data processing module receives a CSV file as input, comprising a spatial dataset S and a high-dimensional vector dataset V. The data processing module determines whether the data conforms to specifications and then assembles the spatial data and high-dimensional vector data into an items set based on their indices. Each item includes the latitude and longitude (x0, y0), (x1, y1), (x2, y2)...(x...). n ,y n And a high-dimensional vector vec0, vec1, vec2...vec n .

[0030] In some embodiments, the present invention provides a spatial and high-dimensional approximate nearest neighbor hybrid query system for electronic maps, wherein the index building module includes a definition module, an initialization module, and an optimization and pruning module;

[0031] The definition module is used to define the fusion distance formula between two data: given a set of items consisting of spatial data and high-dimensional vector data, the distance formula between any two items is Distance = a*spatial_distance + b*vector_distance, where spatial_distance is the spatial distance between the two items, vector_distance is the high-dimensional vector distance between the two items, and a and b are the parameters of these two distances respectively.

[0032] The initialization module first initializes each item as a node. Then, for each node, it randomly generates S nodes as the adjacent nodes of the current node. Then, it calculates the fusion distance between the current node and its adjacent nodes and takes the L nodes with the closest distance as the final adjacent nodes. Here, S and L are two parameters that need to be set manually. Each node mainly consists of two parts: the item and the set of IDs of its adjacent nodes, Neighbors.

[0033] The optimized pruning module is used to further explore closer neighbors by exploring the neighbors of neighboring neighbors. Specifically, for each Node, K nodes other than itself are randomly selected from all nodes. Assuming the currently processed Node is v, when u1 is a neighbor of v and u2 is a neighbor of u1, the fusion distance between v and u2 needs to be calculated. If this distance is smaller than the distance between v and the farthest neighbor, the farthest neighbor is removed and u2 is added as a new neighbor of v.

[0034] In some embodiments, the present invention provides a hybrid query system for spatial and high-dimensional approximate nearest neighbors of an electronic map. In the definition module, a is set to 1, and b is set to 2 * vector distance / spatial distance according to the order of magnitude ratio of spatial distance and vector distance. In the initialization module, S is set to k / 4, and L is set to a number slightly larger than k. The larger S and L are, the higher the quality of the graph construction, but the corresponding construction time and computational load will also increase. k represents the number of query results. The queryer can specify how many of the most relevant results to retrieve, and k can be arbitrarily specified by the queryer. After the index construction module completes the index construction, it persists the index file to the disk.

[0035] In some embodiments, the present invention provides a spatial and high-dimensional approximate nearest neighbor hybrid query system for electronic maps. The query module includes a coarse filtering module and a fine filtering module. In the query module, the corresponding index file is read from the disk. Each query goes through the two-stage search of the coarse filtering module and the fine filtering module to output the final result to a specified file.

[0036] In some embodiments, the present invention provides a spatial and high-dimensional approximate nearest neighbor hybrid query system for electronic maps. The coarse filtering module is used to, instead of calculating the distance between all adjacent points and the high-dimensional vector in the query, randomly select m*k points of the current point for calculation. k is obtained from the query parameters and represents the number of query results. The queryer can specify how many of the most relevant results to retrieve, and k can be arbitrarily specified by the queryer. m is a decimal between 0 and 1; the smaller m is, the coarser the granularity of the coarse filtering stage. After each calculation, the point with the largest distance less than the current result set is updated in the result set.

[0037] The fine filtering module is used to ensure the final accuracy by employing a greedy strategy of calculating the distance of all adjacent points when the number of times the result set is updated is less than the threshold.

[0038] Thirdly, embodiments of the present invention also provide a spatial and high-dimensional approximate nearest neighbor hybrid query device for electronic maps, comprising at least one processor; and a memory coupled to the at least one processor, the memory storing executable instructions, characterized in that: when executed by the at least one processor, the executable instructions cause the implementation of the steps of the method in the first aspect described above.

[0039] Fourthly, embodiments of the present invention also provide a chip for performing the steps of the method in the first aspect described above. Specifically, the chip includes a processor for retrieving and running a computer program from a memory, such that a device having the chip installed performs the steps of the method in the first aspect described above.

[0040] Fifthly, embodiments of the present invention also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the methods described in the first aspect above.

[0041] Compared with the prior art, the beneficial effects of the present invention are as follows:

[0042] This invention innovatively designs a hybrid query method based on adjacency graphs, combining spatial and high-dimensional approximate nearest neighbor methods. This method significantly optimizes the efficiency of hybrid queries using spatial and high-dimensional vectors, and offers a substantial efficiency advantage over existing related technologies when the query selectivity is high. Attached Figure Description

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

[0044] Figure 1 This is a diagram showing the overall architecture of a spatial and high-dimensional approximate nearest neighbor hybrid query system for an electronic map according to an embodiment of the present invention.

[0045] Figure 2 This is a schematic diagram of the search process of the query module in an embodiment of the present invention;

[0046] Figure 3 This is a diagram of the existing Milvus system architecture.

[0047] Figure 4 Displayed as an existing ADBV system architecture diagram;

[0048] Figure 5 The flowchart shown is a method for hybrid spatial and high-dimensional approximate nearest neighbor query of an electronic map according to an embodiment of the present invention.

[0049] Figure 6 The diagram shows a comparison of experimental results in an embodiment of the present invention. Detailed Implementation Plan

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

[0051] Before introducing the relevant technologies, we will first provide some necessary definitions.

[0052] Definition 1 (Spatial Range Query): Given a rectangular range R in space and a spatial dataset S with dimension ds, the spatial range query range(R,S) refers to querying all data in S that are within R.

[0053] Definition 2 (k-approximate nearest neighbor search): Given a high-dimensional vector dataset V and a query vector U, the k-approximate nearest neighbor search kANNs(U,V) refers to the k vectors in the query set V that are approximately the nearest neighbors to the query vector U. These k vectors are not necessarily the k closest vectors to U in V, and a certain degree of error is allowed.

[0054] Definition 3 (Spatial Range and k-Approximate Nearest Neighbor Hybrid Query): Given a spatial dataset S and a high-dimensional vector dataset V, where each spatial data and high-dimensional vector are in one-to-one correspondence according to their index positions, R is the spatial rectangular range to be queried, and U is the corresponding query vector, a spatial range and k-approximate nearest neighbor hybrid query Q(U,R) is to retrieve the k vectors in V that satisfy the spatial information of the approximate nearest neighbor query vector U within S.

[0055] Definition 4 (KNN Graph): Given a high-dimensional vector dataset V, construct an undirected graph where each vector's neighbors are the K nearest neighbors in V.

[0056] Definition 5 (Query Selectivity): Given a rectangular spatial range R and a spatial dataset S, query selectivity = number of data points in the spatial dataset that fall within R / total number of data points in the spatial dataset.

[0057] The index proposed in this invention is primarily memory-based. The construction of the proximity graph is mainly based on the idea that "the neighbor of a point's neighbor may also be a neighbor of that point." To improve query efficiency, a two-stage query is adopted: first, coarse filtering for rapid convergence, and then fine filtering to ensure recall. The main process is as follows: first, the data processing module reads structured and unstructured data into memory and processes it into a structured set; then, the set is input into the index building module to construct the graph index; finally, for each input spatial range and k-nearest neighbor (k) mixed query, the query module can obtain the corresponding k-nearest neighbor results.

[0058] like Figure 1 As shown, the spatial and high-dimensional approximate nearest neighbor hybrid query system based on adjacency graphs of the present invention comprises three modules: a data processing module, an index building module, and a query module.

[0059] (1) Data processing module

[0060] The data processing module reads data from the disk into memory and processes it into data structures that the index building module can handle. The data processing module receives spatial datasets and high-dimensional vector datasets in CSV text format, and outputs data structures that the index building module can process.

[0061] like Figure 1 As shown, the data processing module requires the input data to be CSV, including a spatial dataset S and a high-dimensional vector dataset V. The data processing module will determine whether the data conforms to the specifications, and then assemble the spatial data and high-dimensional vector data into an item set according to the subscripts. Each item includes the latitude and longitude of a spatial point (x0, y0), (x1, y1), (x2, y2)...(x... n ,y nAnd a high-dimensional vector vec0, vec1, vec2...vec n .

[0062] (2) Index building module

[0063] The index building module's function is to construct the final adjacency graph index from the data structure output by the data processing module using an index building algorithm. The index building module takes the output of the data processing module as input and sets the parameters a, b, S, L, and k required for building the graph index. a and b are the weighting coefficients for spatial distance and vector distance in the fusion distance, respectively. Generally, a is set to 1, and b is set to 2 * vector distance / spatial distance, depending on the order of magnitude of the spatial and vector distances. S is generally set to k / 4, and L is set to a number slightly larger than k. Larger values ​​for S and L result in higher graph quality but also increased construction time and computational load. k represents the number of query results; the queryer can specify how many of the most relevant results to retrieve, and k can be arbitrarily specified by the queryer. Once the index building is complete, the index file is persisted to disk.

[0064] The input to the index building module is the set of items output by the data processing module. The overall structure is an undirected graph composed of interconnected nodes. Each node mainly consists of two parts: the item and the set of IDs of its neighboring nodes (Neighbors). Node: The endpoint of a network connection, or the connection point of two (or more) lines.

[0065] There are three main types of existing indexing algorithms: one is hierarchical, such as tree-based algorithms. These algorithms perform well when the vector dimension is low, but their performance deteriorates significantly when dealing with massive amounts of data with increasing vector dimensions. Another type is hash-based algorithms. These algorithms group similar high-dimensional vectors into the same hash bucket through feature extraction or clustering. For each query vector, they first calculate which hash bucket it belongs to, then traverse all vectors in that bucket to find the closest approximation. When finding k closest approximations, this algorithm has to traverse many hash buckets. Research shows that this type of algorithm has low search efficiency and low recall. The last type is adjacency graph-based algorithms. Generally, the search efficiency of this type of algorithm is highly dependent on the quality of the graph construction. These three algorithms were invented specifically for high-dimensional vector searches and do not address or optimize for mixed spatial and high-dimensional vector query scenarios.

[0066] The index construction algorithm of this invention is based on adjacency graphs. To optimize the computational and time-consuming process of constructing the KNN graph in Definition 4, we adopt an approximate KNN graph construction method, sacrificing some accuracy to significantly improve the efficiency of graph construction and search. Since we need to measure the similarity between two data points, we first define the fusion distance formula between them:

[0067] Definition 6 (Fused Distance Formula): Given a set of items consisting of spatial data and high-dimensional vector data, the distance between any two items is calculated as Distance = a * spatial_distance + b * ...

[0068] `vector_distance` is a function where `spatial_distance` is the spatial distance between two items, and `vector_distance` is the high-dimensional vector distance between two items (the distance referred to here is Euclidean distance by default). `a` and `b` are the parameters of these two distances, respectively. Generally, `a` is set to 1, and `b` is set to 2 * vector distance / spatial distance according to the order of magnitude ratio between the spatial distance and the vector distance.

[0069] The construction of this method mainly involves the following two stages:

[0070] Initialization Phase: First, each item is initialized as a Node. Then, for each Node, S Nodes are randomly generated as its neighbors. The fusion distance between the current Node0 and its neighbors is then calculated, and the L closest neighbors are selected as the final neighbors. S and L are two parameters that need to be manually set. S is typically set to k / 4, and L is set to a number slightly larger than k. Larger values ​​for S and L result in higher graph quality, but also increased construction time and computational cost. Once the index is built, the index file is persisted to disk.

[0071] The optimization and pruning phase: This phase explores even closer neighbors by further exploring the neighbors of neighboring neighbors. For each node, we first randomly select K neighbors from all nodes except itself. Assuming the node being processed is v, when u1 is a neighbor of v and u2 is a neighbor of u1, we need to calculate the fusion distance between v and u2. If this distance is smaller than the distance between v and the farthest neighbor, we remove the farthest neighbor and add u2 as a new neighbor of v. Through continuous adjustments to the algorithm, the neighbors of Node 0 keep changing until convergence, ultimately constructing a hierarchy like... Figure 1 The nodes Node1, Node2, Node3, and Node4 shown are the final adjacency graph indices of the adjacent nodes of Node0.

[0072] (3) Query module

[0073] The query module receives query requests and returns query results. It reads the corresponding index file from the disk. Each query undergoes a two-stage search to output the final results to a specified file. The parameters that need to be set are m, threshold, and k: k represents the number of query results; the queryer can specify how many of the most relevant results to retrieve, and k can be arbitrarily specified by the queryer. m is a decimal between 0 and 1; the smaller m is, the coarser the granularity of the coarse filtering stage. threshold indicates that during fine filtering, if the number of times the result set is updated is less than threshold, a greedy strategy that calculates the distances of all adjacent points is used to filter the results more finely.

[0074] like Figure 2 As shown, Figure 2 The query on the left mainly consists of three parts: a rectangular query box containing the latitude and longitude of the spatial points at the bottom left and top right corners, and a high-dimensional vector vec. q , k represents the k closest results.

[0075] Figure 2 The Result Set on the right consists of k results sorted in ascending order by the Euclidean distance of the high-dimensional vectors. Each result contains spatial information (x'1, y'1), (x'2, y'2), (x'3, y'3)...(x'...y'2 ... k ,y' k ) and high-dimensional vectors vec'1, vec'2, vec'3...vec' k .

[0076] Typical nearest neighbor graph search algorithms primarily employ a greedy strategy. This involves starting from the origin, calculating the distances between all its adjacent vertices and the high-dimensional vector in the query, then selecting the neighbor with the smallest distance and iterating in this way until the closest vertex to the high-dimensional vector in the query is found. This algorithm has two main problems: the first is... Figure 2 As shown, it is almost necessary to calculate all nodes n (e.g. Figure 2 As shown, all nodes are from n0 to n 11 The first problem is that the distance between the vector and the query's high-dimensional vector is computationally intensive; the second problem is that it is easy to get stuck in local optima when the amount of data is large.

[0077] Our search algorithm optimizes these two problems through a two-stage search. First, it maintains a queue of the top k closest results, performing coarse filtering followed by fine filtering. Coarse filtering means that instead of calculating the distance between all adjacent points and the high-dimensional vector in the query, it randomly selects m*k points from the current point for calculation. Here, k represents the number of query results, which the queryer can specify—the number of most relevant results to retrieve, and k can be arbitrarily assigned by the queryer. m is a decimal between 0 and 1; the smaller m is, the coarser the granularity of the coarse filtering stage. After each calculation, the point with the largest distance less than the current result set is updated in the result set. Fine filtering means that when the number of times the result set is updated is less than the threshold, a greedy strategy of calculating the distances of all adjacent points is used to ensure the final accuracy.

[0078] like Figure 5 As shown, the present invention provides a spatial and high-dimensional approximate nearest neighbor hybrid query method for electronic maps, comprising the following steps:

[0079] Data processing: Divide the data on the disk into spatial datasets and high-dimensional vector datasets, read them into memory, process them into indexes, and build data structures that can be processed;

[0080] Index building: The final adjacency graph index is constructed from the processed data structure using index building methods;

[0081] Query: Receives query requests and returns query results.

[0082] In the data processing step, the input data type is CSV text format, including a spatial dataset S and a high-dimensional vector dataset V. The data processing step determines whether the data conforms to the specifications, and then assembles the spatial data and high-dimensional vector data into an items set according to their indices. Each item includes the latitude and longitude of a spatial point (x0, y0), (x1, y1), (x2, y2)...(x...). n ,y n And a high-dimensional vector vec0, vec1, vec2...vec n .

[0083] The index building step, specifically the index building method, includes:

[0084] Define the fusion distance formula between two data sets: Given a set of items consisting of spatial data and high-dimensional vector data, the distance between any two items is defined as Distance = a * spatial_distance + b * ...

[0085] vector_distance, where spatial_distance is the spatial distance between two items, vector_distance is the high-dimensional vector distance between two items, and a and b are the parameters of these two distances respectively; a is set to 1, and b is set to 2 * vector distance / spatial distance according to the order of magnitude ratio of spatial distance and vector distance;

[0086] Initialization Phase: First, each item is initialized as a Node. Then, for each Node, S Nodes are randomly generated as its neighbors. The fusion distance between the current Node and its neighbors is calculated, and the L closest Nodes are taken as the final neighbors. Here, S and L are two parameters that need to be set manually. Each Node mainly consists of two parts: the item and the set of IDs of its neighbors, Neighbors. S is set to k / 4, and L is set to a number slightly larger than k. The larger S and L are, the higher the quality of the graph construction, but the corresponding construction time and computation will also increase. k represents the number of query results. The queryer can specify how many of the most relevant results to retrieve, and k can be arbitrarily specified by the queryer.

[0087] Optimization and pruning phase: This phase explores closer neighbors by further exploring the neighbors of neighbors. For each node, firstly, K nodes other than itself are randomly selected from all nodes. Assuming the node being processed is v, when u1 is a neighbor of v and u2 is a neighbor of u1, the fusion distance between v and u2 needs to be calculated. If this distance is smaller than the distance between v and the farthest neighbor, the farthest neighbor is removed and u2 is added as a new neighbor of v.

[0088] Once the index is built, the index file will be persisted to disk.

[0089] In the query step, the corresponding index file is read from the disk. Each query undergoes a two-stage search process: coarse filtering followed by fine filtering, to output the final result to a specified file. Coarse filtering refers to not calculating the distance between all adjacent points and the high-dimensional vector in the query, but instead randomly selecting m*k distances from the current point for calculation. k represents the number of query results; the queryer can specify how many of the most relevant results to retrieve, and k can be arbitrarily specified by the queryer. m is a decimal between 0 and 1; the smaller m is, the coarser the granularity of the coarse filtering stage. After each calculation, the point with the largest distance less than the current result set is updated in the result set. Fine filtering refers to using a greedy strategy of calculating the distances of all adjacent points to ensure final accuracy when the number of times the result set is updated is less than a threshold.

[0090] This invention innovatively designs a hybrid query method based on adjacency graphs, combining spatial and high-dimensional approximate nearest neighbor methods. This method significantly optimizes the efficiency of hybrid queries using spatial and high-dimensional vectors. The following experiments demonstrate that, when the query selectivity is high, this invention has a significant efficiency advantage over existing related technologies.

[0091] I. Experimental testing equipment:

[0092] A Linux server equipped with an Intel(R) Xeon(R) Platinum 8369B 2.7GHz processor and 256GB of RAM.

[0093] II. Experimental Procedure:

[0094] 1. First, the adjacency graph index is obtained by processing the dataset through the data processing module and the index building module respectively.

[0095] 2. Then, for different selection rates or different k, 100 queries are randomly generated (each query includes a randomly generated circular spatial range and a high-dimensional vector from the query dataset).

[0096] 3. Then, use the index query module to query the above-generated query to obtain result set A and record the response time of each query.

[0097] 4. Then, by scanning the entire dataset, we brute-force calculate the first k correct result sets B that completely fit the spatial range and are similar to the target vector.

[0098] 5. The recall rate for each query is obtained by comparing A and B.

[0099] III. Experimental Results

[0100] 1. The dataset results are as follows:

[0101]

[0102]

[0103] OSM dataset download address: https: / / www.openstreetmap.org.

[0104] Gowalla dataset download link: Eunjoon Cho, Seth A Myers, and Jure Leskovec. 2011. Friendship and mobility: user movement in location-based social networks. In SIGKDD. 1082–1090.

[0105] Download link for the DEEP1B dataset: Artem Babenko and Victor Lempitsky. 2016. Efficient indexing of billion-scale datasets of deepdescriptors. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition. 2055–2063.

[0106] SIFT1B dataset download address: Hervé Jégou, Romain Tavenard, Matthijs Douze, and Laurent Amsaleg. 2011. Searching in one billion vectors: re-rank with source coding. In ICASSP. 861–864.

[0107] 2. The experimental results comparison chart is shown below. Figure 6 As shown, Figure 6 (a) shows the response time variation curves of the four algorithms under different query selectivity on the OS dataset. Figure 6 (b) shows the response time variation curves of the four algorithms on the OD dataset under different query selectivity. Figure 6 (c) shows the response time variation curves of the four algorithms on the GS dataset under different query selectivity. Figure 6 (d) shows the response time variation curves of the four algorithms on the GD dataset under different query selectivity. Figure 6 (e) represents the relationship curves between response time and recall for the four algorithms on the OS dataset. Figure 6 (f) represents the relationship curves between response time and recall for the four algorithms on the OD dataset. Figure 6 (g) represents the relationship curves between response time and recall for the four algorithms on the GS dataset. Figure 6 (h) represents the relationship curves between response time and recall for the four algorithms on the GD dataset.

[0108] from Figure 6 The comparison of experimental results shows that when the query selectivity rate is around 10%, -4 The query efficiency of the method of the present invention is generally better than that of the other three methods. Moreover, the method of the present invention has a good effect in terms of accuracy and efficiency, and can achieve the accuracy of the other three methods in less time.

[0109] The following is an embodiment of the method and system of the present invention, illustrated with an electronic map:

[0110] First, we obtain the geographical coordinates and images of businesses on an electronic map. Then, we convert the images into feature vectors using a deep learning model, resulting in a high-dimensional vector dataset with spatial coordinates. This dataset is then indexed using the system modules of this invention. Our query system can then answer queries that combine spatial range and high-dimensional vectors. For example, given a restaurant image, the system can identify the top k most relevant businesses within a 5-kilometer radius of that restaurant. Here, "5 kilometers" represents the spatial range, and the provided restaurant image is the target vector.

[0111] Furthermore, embodiments of the present invention also provide a hybrid spatial and high-dimensional approximate nearest neighbor query device for electronic maps, comprising:

[0112] At least one processor; a memory coupled to the at least one processor, the memory storing executable instructions, wherein the executable instructions, when executed by the at least one processor, cause the method steps of the first aspect of the invention to be implemented.

[0113] The present invention provides a spatial and high-dimensional near nearest neighbor hybrid query device for electronic maps, wherein the processor and memory can be set separately or integrated together.

[0114] For example, memory may include random access memory, flash memory, read-only memory, programmable read-only memory, non-volatile memory, or registers. The processor may be a central processing unit (CPU), or a graphics processing unit (GPU). Memory can store executable instructions. The processor can execute the executable instructions stored in memory to implement the various processes described herein.

[0115] It is understood that the memory in this embodiment can be volatile memory or non-volatile memory, or may include both. The non-volatile memory can be ROM (Read-Only Memory), PROM (Programmable ROM), EPROM (Erasable PROM), EEPROM (Electrically Erasable EPROM), or flash memory. The volatile memory can be RAM (Random Access Memory), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as SRAM (Static RAM), DRAM (Dynamic RAM), SDRAM (Synchronous DRAM), DDR SDRAM (Double Data Rate SDRAM), ESDRAM (Enhanced SDRAM), SLDRAM (Synchlink DRAM), and DRRAM (Direct Rambus RAM). The memories described herein are intended to include, but are not limited to, these and any other suitable types of memory.

[0116] In some implementations, the memory stores elements such as upgrade packages, executable units, or data structures, or subsets thereof, or extended sets thereof: operating systems and applications.

[0117] The operating system includes various system programs, such as the framework layer, core library layer, and driver layer, used to implement various basic business functions and handle hardware-based tasks. The application programs include various applications used to implement various application functions. Programs implementing the methods of this invention can be included within these application programs.

[0118] In this embodiment of the invention, the processor executes the method steps provided in the first aspect by calling a program or instruction stored in the memory, specifically a program or instruction stored in an application program.

[0119] Furthermore, embodiments of the present invention also provide a chip for performing the method in the first aspect described above. Specifically, the chip includes a processor for calling and running a computer program from a memory, such that a device having the chip installed performs the method in the first aspect described above.

[0120] Furthermore, embodiments of the present invention also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the method of the first aspect of the present invention.

[0121] For example, machine-readable storage media can include, but are not limited to, various known and unknown types of non-volatile memory.

[0122] Those skilled in the art will understand that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can implement the described functions in different ways for each specific application, but such implementation should not be considered beyond the scope of this application.

[0123] In the embodiments of this application, the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the division of units is merely a logical functional division, and other division methods may exist in actual implementation. For example, multiple units or components may be combined or integrated into another system. Furthermore, the coupling between the various units can be direct coupling or indirect coupling. Additionally, the functional units in the embodiments of this application can be integrated into a processing unit, or they can exist as separate physical entities, etc.

[0124] It should be understood that in the various embodiments of this application, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0125] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a machine-readable storage medium. Therefore, the technical solution of this application can be embodied in the form of a software product, which can be stored in a machine-readable storage medium. This software product may include several instructions to cause an electronic device to execute all or part of the processes of the technical solution described in the embodiments of this application. The aforementioned storage medium may include various media capable of storing program code, such as ROM, RAM, removable disk, hard disk, magnetic disk, or optical disk.

[0126] The above description is merely a specific embodiment of this application, and the scope of protection of this application is not limited thereto. Those skilled in the art can make changes or substitutions within the technical scope disclosed in this application, and all such changes or substitutions should be within the scope of protection of this application.

Claims

1. A hybrid spatial and high-dimensional approximate nearest neighbor query method for electronic maps, characterized in that, The method includes the following steps: Data processing: Divide the data on the disk into spatial datasets and high-dimensional vector datasets, read them into memory, process them into indexes, and build data structures that can be processed; Index building: The final adjacency graph index is constructed from the processed data structure using index building methods; Query: Receives query requests and returns query results; In the data processing step, the input data type is CSV, including a spatial dataset s and a high-dimensional vector dataset V. The data processing step determines whether the data conforms to the specifications, and then assembles the spatial data and high-dimensional vector data into an items set according to their indices. Each item includes the latitude and longitude of a spatial point (x0, y0), (x1, y1), (x2, y2)...(x...). n ,y n And a high-dimensional vector vec0, vec1, vec2...vec n ; The index building step, specifically the index building method, includes: Define the fusion distance formula between two data sets: Given a set of items consisting of spatial data and high-dimensional vector data, the distance between any two items is defined as Distance = a spatial_distance + b vector_distance, where spatial_distance is the spatial distance between two items, vector_distance is the high-dimensional vector distance between two items, and a and b are the parameters of these two distances respectively; Initialization phase: First, each item is initialized as a node. Then, for each node, S nodes are randomly generated as the current node's adjacent nodes. Then, the fusion distance between the current node and its adjacent nodes is calculated, and the L nodes with the closest distance are taken as the final adjacent nodes. Here, S and L are two parameters that need to be set manually. Each node consists of two parts: the item and the set of IDs of its adjacent nodes, Neighbors. Optimization pruning phase: This phase explores even closer neighbors by further exploring the neighbors of neighbors. For each node, firstly, K nodes other than itself are randomly removed from all nodes. Assuming the node being processed is v, when u1 is a neighbor of v and u2 is a neighbor of u1, the fusion distance between v and u2 needs to be calculated. If this distance is smaller than the distance between v and the farthest neighbor, then the farthest neighbor is removed and u2 is added as a new neighbor of v.

2. The method according to claim 1, characterized in that, In the data processing step, the data in the disk is divided into spatial datasets and high-dimensional vector datasets and read into memory, specifically in CSV text format.

3. The method according to claim 1, characterized in that: In the formula defining the fusion distance between two data points, a is set to 1, and b is set to 2 according to the order of magnitude ratio between spatial distance and vector distance. Vector distance / spatial distance; In the initialization phase, S is set to k / 4, and L is set to a number larger than k. The larger S and L are, the higher the quality of the graph construction, and the corresponding construction time and computation amount will also increase. k represents the number of query results, and k can be arbitrarily specified by the queryer. Once the index is built, the index file will be persisted to disk.

4. The method according to claim 1, characterized in that: In the query step, the corresponding index file is read from the disk. Each query goes through a two-stage search process of coarse filtering followed by fine filtering to output the final result to the specified file.

5. The method according to claim 4, characterized in that: The coarse filtering refers to not calculating the distance between all adjacent points and the high-dimensional vector in the query each time, but instead randomly selecting the m of the current point. The calculation is performed on k results, where k represents the number of query results and can be arbitrarily specified by the queryer; m is a decimal between 0 and 1, and the smaller m is, the coarser the granularity of the coarse filtering stage; after each calculation, the point in the calculation result that is the largest distance from the current result set is updated to the result set. The fine filtering refers to using a greedy strategy that calculates the distance between all adjacent points to ensure the final accuracy when the number of times the result set is updated is less than the threshold.

6. A hybrid spatial and high-dimensional approximate nearest neighbor query system for electronic maps, characterized in that, include: The data processing module is used to divide the data on the disk into spatial datasets and high-dimensional vector datasets, read them into memory, process them into indexes, and build data structures that can be processed. The index building module is used to construct the final adjacency graph index from the processed data structure using index building methods; The query module is used to receive query requests and return query results; The data processing module receives CSV data as input, including a spatial dataset s and a high-dimensional vector dataset V. The module determines if the data conforms to specifications and then assembles the spatial data and high-dimensional vector data into an items set based on their indices. Each item contains the latitude and longitude of a spatial point: (x0, y0), (x1, y1), (x2, y2)...(x...). n ,y n And a high-dimensional vector vec0, vec1, vec2...vec n ; The index building module includes a definition module, an initialization module, and an optimization and pruning module; The definition module is used to define the fusion distance formula between two data sets: given a set of items consisting of spatial data and high-dimensional vector data, the distance formula between any two items is Distance = a spatial_distance + b vector_distance, where spatial_distance is the spatial distance between two items, vector_distance is the high-dimensional vector distance between two items, and a and b are the parameters of these two distances respectively; The initialization module first initializes each item as a node, and then for each node, it randomly generates S nodes as the current node's adjacent nodes. Then, it calculates the fusion distance between the current node and its adjacent nodes, and takes the L nodes with the closest distance as the final adjacent nodes. S and L are two parameters that need to be set manually; each Node consists of two parts: item and the set of IDs of its neighboring Nodes, Neighbors; The optimized pruning module is used to further explore closer neighbors by exploring the neighbors of neighbors. Specifically, for each Node, K nodes other than itself are randomly removed from all Nodes. Assuming the Node being processed is v, when u1 is a neighbor of v and u2 is a neighbor of u1, the fusion distance between v and u2 needs to be calculated. If this distance is smaller than the distance between v and the farthest neighbor, the farthest neighbor is removed and u2 is added as a new neighbor of v.

7. The system according to claim 6, characterized in that, In the definition module, 'a' is set to 1, and 'b' is set to 2 according to the order of magnitude ratio between spatial distance and vector distance. Vector distance / spatial distance; In the initialization module, S is set to k / 4, and L is set to a number larger than k. The larger S and L are, the higher the quality of the graph construction, and the corresponding construction time and computation amount will also increase. k represents the number of query results, and k can be arbitrarily specified by the queryer. After completing the index building, the index building module will persist the index file to the disk.

8. The system according to claim 6, characterized in that, The query module includes a coarse filtering module and a fine filtering module; In the query module, the corresponding index file is read from the disk. Each query goes through a two-stage search involving a coarse filtering module and a fine filtering module to output the final result to a specified file.

9. The system according to claim 8, characterized in that: The coarse filtering module is used to randomly select the m value of the current point instead of calculating the distance between all adjacent points and the high-dimensional vector in the query. The calculation is performed on k results, where k represents the number of query results and can be arbitrarily specified by the queryer; m is a decimal between 0 and 1, and the smaller m is, the coarser the granularity of the coarse filtering stage; after each calculation, the point in the calculation result that is the largest distance from the current result set is updated to the result set. The fine filtering module is used to ensure the final accuracy by employing a greedy strategy of calculating the distance of all adjacent points when the number of times the result set is updated is less than the threshold.

10. A hybrid spatial and high-dimensional approximate nearest neighbor query device for electronic maps, comprising at least one processor; and a memory coupled to the at least one processor, the memory storing executable instructions, characterized in that: When executed by the at least one processor, the executable instructions cause the implementation of the steps of the method according to any one of claims 1 to 5.

11. A chip, characterized in that: Includes a processor for retrieving and running a computer program from memory, causing a device on which the chip is mounted to perform the steps of the method as described in any one of claims 1 to 5.

12. A computer-readable storage medium storing a computer program thereon, characterized in that: When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 5 above.

Citation Information

Patent Citations

  • Method for determining live broadcast resources, equipment, medium and program product

    CN113301442A

  • Measuring the free energy in an evaluation

    US20220108176A1