Vector data K neighbor query method and system, electronic equipment and storage medium
By using technologies such as affinity graph indexing and Oblivious Sort in a trusted execution environment on the server, the privacy leakage problem in vector nearest neighbor retrieval is solved, and data security and privacy protection of K-nearest neighbor queries of vector data are achieved.
Patent Information
- Application Number
- CN202510746339.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-10-17
AI Technical Summary
Existing vector nearest neighbor retrieval methods have privacy leakage issues. Attackers may obtain vector database, query request or query result information during query processing through memory access patterns.
In the trusted execution environment of the server, by selecting the proximity graph index node of the vector database as the reference node, calculating the neighbor information and inserting it into the priority queue, the oblivious sort and private information retrieval technology are used to protect the privacy of the query process and prevent attackers from inferring data information.
The data security of the K-nearest neighbor query process of vector data is improved, which prevents attackers from obtaining sensitive information during the query processing and protects the privacy of the query results.
Smart Images

Figure CN120804171A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of information retrieval, and particularly relates to a vector data K nearest neighbor query method and system, an electronic device and a storage medium. BACKGROUND
[0002] Vector nearest neighbor search has provided basic support for many applications in the fields of data mining, database and information retrieval for decades. For dense continuous vector nearest neighbor search, relevant solutions include tree structure-based methods, such as Revisiting kd-tree proposed by Parikshit Ram et al., which is a kd-tree based on a random rotation version for vector approximate search; Revisited cover-tree proposed by Zhi-Jie Wang et al., which is an improved cover tree method for nearest neighbor search problems; hash-based methods, such as DB-LSH proposed by Yao Tian et al., which supports efficient vector nearest neighbor search on large-scale high-dimensional data sets; PM-LSH proposed by Bolong Zheng et al., which combines the data indexing framework of LSH and PM-tree to overcome the performance problems of traditional LSH methods in approximate nearest neighbor search on high-dimensional data; quantization-based methods, such as PQ proposed by Herve Jégou et al., which decomposes a high-dimensional space into a Cartesian product of multiple low-dimensional subspaces and separately quantizes each subspace for approximate nearest neighbor search; and RaBitQ proposed by Gao J et al., which is inspired by PQ and designs a new random quantization method to quantize D-dimensional vectors into D-bit strings, constructs an index stage by normalizing data vectors, and then constructs a codebook and calculates the quantized vectors of data vectors. In the commonly used Euclidean space, graph-based methods perform better than other types of popular algorithms. Graph-based nearest neighbor search is based on a greedy strategy and needs to retrieve the nearest neighbors from a data set for a given query. Vector nearest neighbor search can provide accurate approximate results while improving query speed and exhibits superior performance when processing large-scale high-dimensional data sets.
[0003] However, the above vector nearest neighbor search method has a privacy leakage problem. Attackers can obtain the memory access pattern of the query processing process, and thus infer vector database, query request or query result information. SUMMARY
[0004] The main purpose of the embodiments of the present application is to provide a vector data K nearest neighbor query method and system, an electronic device and a storage medium, which aims to improve the data security in the vector data K nearest neighbor query process.
[0005] To achieve the above object, one aspect of the embodiment of the present application provides a vector data K nearest neighbor query method applied to a trusted execution environment of a server, the vector data K nearest neighbor query method comprising the following steps:
[0006] In response to a query vector, a node of a proximity graph index of a vector database is selected as a reference node;
[0007] Neighbor information is determined according to the reference node and the proximity graph index, wherein the neighbor information comprises an index value and a data vector of a neighbor node;
[0008] A vector space distance of each neighbor node from the query vector is calculated according to the neighbor information;
[0009] The vector space distance of the neighbor node is inserted into a priority queue with a length of L;
[0010] A node is selected from the priority queue as a new reference node, and the priority queue is updated according to the new reference node until all nodes in the priority queue are used as reference nodes in a historical round, and a query result is determined according to the first K nodes in the priority queue.
[0011] In some embodiments, the neighbor information is determined according to the reference node and the proximity graph index, comprising the following steps:
[0012] The index value of the neighbor node of the reference node is determined by querying the proximity graph index according to the index value of the reference node;
[0013] The data vector of the neighbor node is obtained by querying a vector database located in the trusted execution environment by using a private information retrieval technique according to the index value of the neighbor node.
[0014] In some embodiments, the neighbor information is determined according to the reference node and the proximity graph index, comprising the following steps:
[0015] The index value of the neighbor node of the reference node is determined by querying the proximity graph index according to the index value of the reference node;
[0016] The data vector of the neighbor node is obtained by accessing a vector database located outside the trusted execution environment by using a data encryption technique according to the index value of the neighbor node.
[0017] In some embodiments, the vector space distance of the neighbor node is inserted into a priority queue with a length of L, comprising the following steps:
[0018] The index value and the vector space distance of each neighbor node are combined into a queue element of the priority queue.
[0019] sort all the queue elements in the priority queue based on the vector space distance, to obtain a sorted priority queue with a length of L.
[0020] In some embodiments, the step of sorting all the queue elements in the priority queue based on the vector space distance, to obtain a sorted priority queue with a length of L, comprises the following steps:
[0021] performing a sorting operation on all the queue elements in the priority queue based on the vector space distance by using an Oblivious Sort algorithm, to obtain a queue element sorting result of the vector space distance in ascending order;
[0022] updating the priority queue according to the first L queue elements in the sorting result.
[0023] In some embodiments, the step of selecting a node in the priority queue as a new reference node comprises the following steps:
[0024] traversing the nodes in the priority queue from the first queue element, and matching the index value of the current traversed node with a reference data set, wherein the reference data set is used to store the index values of historical reference nodes;
[0025] in the case that the index value of the current traversed node does not exist in the reference data set, determining the current traversed node as a new reference node.
[0026] In some embodiments, the affinity graph index is obtained by the following steps:
[0027] defining an index value for each data vector in the vector database;
[0028] taking the index value as a node of the affinity graph index, and determining an edge of the affinity graph index according to the vector distance between each pair of data vectors, to obtain a constructed affinity graph index;
[0029] loading the constructed affinity graph index into the trusted execution environment.
[0030] To achieve the above object, another aspect of the embodiment of the present application proposes a vector data K-nearest neighbor query system, which is applied to a trusted execution environment of a server side, and comprises:
[0031] a first module, configured to select a node of an affinity graph index of a vector database as a reference node in response to a query vector;
[0032] determining neighbor information according to the reference node and the affinity graph index, wherein the neighbor information comprises an index value and a data vector of a neighbor node;
[0033] calculating vector space distance between each of the neighbor nodes and the query vector according to the neighbor information;
[0034] inserting the vector space distance of the neighbor node into a priority queue with a length of L;
[0035] selecting a node from the priority queue as a new reference node, and updating the priority queue according to the new reference node until all nodes in the priority queue are used as reference nodes in a historical round, and determining a query result according to the first K nodes in the priority queue.
[0036] To achieve the above object, another aspect of the embodiment of the present application provides an electronic device, which comprises a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection communication between the processor and the memory, and the program is executed by the processor to realize the method provided by the above embodiment.
[0037] To achieve the above object, another aspect of the embodiment of the present application provides a storage medium, which is a computer readable storage medium, for computer readable storage, and the storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to realize the method provided by the above embodiment.
[0038] The vector data K-nearest neighbor query method, system, electronic device and storage medium provided by the present application can separately isolate the vector data K-nearest neighbor query process, and improve the data security in the query process. BRIEF DESCRIPTION OF DRAWINGS
[0039] Figure 1 is a flowchart of the vector data K-nearest neighbor query method provided by the embodiment of the present application;
[0040] Figure 2 is a schematic diagram of an application scenario provided by an embodiment of the present application;
[0041] Figure 3 is a schematic diagram of a vector data K nearest neighbor query process provided by an embodiment of the present application;
[0042] Figure 4 is a schematic diagram of a vector data K nearest neighbor query process provided by another embodiment of the present application;
[0043] Figure 5 is a schematic diagram of a proximity graph index provided by an embodiment of the present application;
[0044] Figure 6 is a schematic diagram of distances between neighbor nodes and a query point provided by an embodiment of the present application;
[0045] Figure 7 is a schematic diagram of a hardware structure of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0046] In order to make the objects, technical solutions and advantages of the present application clearer, further detailed description will be made to the present application in combination with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, and are not used to limit the present application.
[0047] It should be noted that although the functional modules are divided in the system, and the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order from the module division in the system or the order in the flowchart. The terms "first", "second", etc. in the specification and claims and the above drawings are used to distinguish similar objects, and do not necessarily describe a specific order or sequence.
[0048] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which the present application belongs. The terms used herein are only for the purpose of describing the embodiments of the present application, and are not intended to limit the present application.
[0049] First, the meanings of several terms involved in the present application are analyzed:
[0050] Trusted Execution Environment (TEE) is a secure computing environment that provides an isolated execution space for protecting sensitive data and code from unauthorized access and tampering, and is used for processing sensitive data and performing critical operations.
[0051] Oblivious Sort is a sorting algorithm used in the context of protecting data privacy. In traditional sorting algorithms, the access pattern of data may depend on the value of input data, and this pattern may leak sensitive information about the data through observation of the sorting process, while Oblivious Sort is a sorting algorithm whose memory access pattern is always fixed while sorting data, ensuring that the sorting process does not leak any access pattern about the input data.
[0052] Private Information Retrieval (PIR) is a cryptographic technique that allows users to obtain the desired data from a database or server without revealing the specific query content. The core principle is to use encryption and confusion to prevent the server from learning the specific data items retrieved by the user when returning the query results, while the user cannot obtain information unrelated to the query.
[0053] Symmetric Cryptography (SC) is a cryptographic technique that uses a single key for data encryption and decryption, and the core is that the sender and the receiver share the same key. In the encryption process, the plaintext is generated by the encryption algorithm and the shared key together to generate the ciphertext; the receiver uses the same key and algorithm to restore the plaintext.
[0054] The embodiment of the present application provides a vector data K nearest neighbor query method, system, electronic equipment and storage medium, and aims to improve the data security in the vector data K nearest neighbor query process.
[0055] The vector data K nearest neighbor query method, system, electronic equipment and storage medium provided by the embodiment of the present application are specifically described by the following embodiments. First, the vector data K nearest neighbor query method in the embodiment of the present application is described.
[0056] The vector data K nearest neighbor query method provided by the embodiment of the present application relates to the technical field of information retrieval. The vector data K nearest neighbor query method provided by the embodiment of the present application can be applied to a terminal, can be applied to a server end, and can also be software running in a terminal or a server end. In some embodiments, the terminal can be a smart phone, a tablet computer, a notebook computer, a desktop computer, etc.; the server end can be configured as an independent physical server, can be configured as a server cluster or a distributed system composed of multiple physical servers, can also be configured as a cloud server providing cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN, and basic cloud computing services such as big data and artificial intelligence platforms; and the software can be an application for implementing the vector data K nearest neighbor query method, but is not limited to the above forms.
[0057] The application is operable with numerous general purpose or special purpose computer system environments or configurations. Examples of well-known computing systems, environments, and / or configurations that can be suitable for use with the application include personal computers, server computers, handheld or laptop devices, tablet devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like. The application can be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, and the like, that perform particular tasks or implement particular abstract data types. The application can also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules can be located in both local and remote computer storage media including memory storage devices.
[0058] According to some embodiments of the application, the vector data K-nearest neighbor query method provided by the embodiments of the application is applied to a scenario in which a client checks information of a vector database of a server. Please refer to Figure 2 The client sends a query vector to the server. A trusted execution environment (TEE) is built in the server. After receiving the query vector, the server executes the vector data K-nearest neighbor query method provided by the embodiments of the application in the TEE to obtain a query result. The server returns the query result to the client.
[0059] The trusted execution environment of the embodiments of the application can be implemented based on software and hardware technologies. For the hardware level, in the server hardware, a target hardware region can be isolated by memory isolation and processor core isolation to execute the trusted execution environment of the embodiments of the application. For the software level, a permission verification mechanism and a data encryption mechanism are used to protect data in the target hardware region. Specifically, permission verification is performed on data or programs accessing the data in the target hardware region. Only data that passes the verification is allowed to access the target hardware region, and only programs that pass the verification are allowed to execute in the target hardware region. For data allowed to enter the target hardware region, the data is encrypted by using an encryption algorithm when the data enters the target hardware region. The encrypted data can be decrypted and used only under specific conditions by using a correct key, effectively preventing the data from being stolen or tampered with during transmission. The trusted execution environment can be created in the server by using the above-mentioned software and hardware combination technologies. Exemplarily, the TEE of the embodiments of the application can also use SGX or TDX, but is not limited thereto.
[0060] SGX enables certain parts of an application to execute in an isolated environment called an "enclave." This enclave is independent from the operating system, hypervisor, or other applications. SGX is able to ensure that code executing in the enclave has not been modified and that data remains intact during processing. Only authorized code can enter the enclave and access the data within, even the system administrator or the operating system itself cannot directly access the data and code within the enclave.
[0061] TDX provides virtual machine / container level isolation to protect sensitive data and applications from unauthorized access. TDX achieves this goal through hardware isolated virtual machines that are isolated at the hardware level so that sensitive data and applications are not affected by other applications or system environments.
[0062] Figure 1 is an optional flowchart of the vector data K-nearest neighbor query method provided by the embodiments of the present application, Figure 1 The method in the embodiment can include, but is not limited to, steps S101 to S105.
[0063] Step S101, in response to a query vector, selecting a node of a proximity graph index of a vector database as a reference node;
[0064] Step S102, determining neighbor information according to the reference node and the proximity graph index, wherein the neighbor information includes index values and data vectors of neighbor nodes;
[0065] Step S103, calculating vector space distances between each neighbor node and the query vector according to the neighbor information;
[0066] Step S104, inserting the vector space distances of the neighbor nodes into a priority queue with a length of L;
[0067] Step S105, selecting a node from the priority queue as a new reference node, and updating the priority queue according to the new reference node, until all nodes in the priority queue have been used as reference nodes in the historical rounds, and determining a query result according to the first K nodes in the priority queue.
[0068] In steps S101-S105 of some embodiments, in response to the query vector in the trusted execution environment of the server, a node of the proximity graph index of the vector database is selected as a reference node, neighbor information is determined according to the reference node and the proximity graph index, the vector space distance between each neighbor node and the query vector is calculated according to the neighbor information, the vector space distance of the neighbor node is inserted into a priority queue with a length of L, a node is selected from the priority queue as a new reference node, and the priority queue is updated according to the new reference node until all nodes in the priority queue are used as reference nodes in the historical round, and the query result is determined according to the first K nodes in the priority queue. The embodiment can isolate the vector data K nearest neighbor query process alone, protect the privacy in the vector database K nearest neighbor query process, prevent attackers from obtaining the memory access mode of the query processing process, and thus infer the vector database, the query request or the query result information.
[0069] In step S101 of some embodiments, the client initiates a query request to the server, and the server determines whether it needs to query the vector database by analyzing the query request. In the case of determining that it needs to query the vector database, in order to protect the privacy of the vector data query process, a permission verification mechanism is defined according to the trusted execution environment, and the query request is verified for permission, for example, the IP address or the client identity of the query request is verified. For the query request that passes the permission verification, a natural language processing technology is used to extract the query content to obtain a query vector, and then the query vector is sent to the trusted execution environment for vector data query. Further, before sending the query vector to the trusted execution environment, the query vector can be encrypted, and then the ciphertext state of the query vector is sent to the trusted execution environment for vector data query.
[0070] In the embodiment, the proximity graph index (Proximity Graph, PG) of the vector database is loaded in the trusted execution environment in advance. In the offline stage, the proximity graph index (Proximity Graph, PG) is generated according to the vector data set stored in the vector database of the server. In the query stage, the client sends a query request to the server, the server generates a query vector Q based on the query request, completes the vector data K nearest neighbor query in the TEE of the server based on the query vector Q, and returns the query result to the client. It can be understood that the method of the embodiment of the application is applicable to vector database queries of different modalities, including but not limited to text, picture, audio, video, etc.
[0071] According to some embodiments of the application, the proximity graph index in step S101 can be obtained by the following steps, including:
[0072] Step S201, defining an index value for each data vector in the vector database;
[0073] Step S202, taking the index value as a node of the proximity graph index, and determining an edge of the proximity graph index according to the vector distance between each two data vectors, to obtain a constructed proximity graph index;
[0074] Step S203, loading the constructed proximity graph index into a trusted execution environment.
[0075] Specifically, an index value is defined for each data vector in the vector database, and the vector distance (such as Euclidean distance, cosine similarity) between each two data vectors in the vector database is calculated. For two data vectors with a vector distance less than a preset distance value, it is determined that there is an association relationship between the two data vectors. The index value is taken as a node of the proximity graph index, and if there is an association relationship between two data vectors corresponding to two index values, an edge between the two nodes in the proximity graph index is constructed, thereby obtaining a constructed proximity graph index. That is, each node of the proximity graph index represents an index value of a data vector, and each edge of the proximity graph index represents an association relationship between data vectors corresponding to the index values, and the vector database stores the data vectors and their index values. The vector query is performed through the proximity graph index, which can improve the query efficiency.
[0076] Further, the constructed proximity graph index is loaded into a trusted execution environment for storage, which can prevent tampering of the proximity graph index by an attacker, and subsequent querying of the proximity graph index in the trusted execution environment can also shield the query logic from the outside, improving data security.
[0077] In the embodiment, in the trusted execution environment, in response to a query vector, any one node of the proximity graph index or a defined entry node can be selected as a reference node to be analyzed in the current round.
[0078] In step S102 of some embodiments, neighbor information is determined according to the reference node and the proximity graph index. Specifically, nodes having a connection relationship with the reference node are selected from the proximity graph index to obtain index values of a plurality of neighbor nodes, and then the data vectors of the neighbor nodes are queried from the vector database based on the index values of the neighbor nodes.
[0079] In an embodiment, step S102 can include but is not limited to the following steps:
[0080] Step S301, querying the proximity graph index according to the index value of the reference node to determine the index values of the neighbor nodes of the reference node;
[0081] Step S302, according to the index value of the neighbor node, a private information retrieval technology is used to query the vector database located in the trusted execution environment to obtain the data vector of the neighbor node.
[0082] Specifically, referring to Figure 3 , in the case that the TEE space is sufficient, the vector database can be stored in the TEE, and the process of querying the vector database based on the index value is also performed in the TEE, thereby solving the problem of data privacy and access pattern leakage and protecting the K-Nearest Neighbor query privacy. Further, when querying the vector database based on the index value, a private information retrieval (PIR) technology can also be used to access the vector database to obtain the data vector of the neighbor node.
[0083] In another embodiment, step S102 can include but is not limited to the following steps:
[0084] Step S401, according to the index value of the reference node, querying the proximity graph index to determine the index value of the neighbor node of the reference node;
[0085] Step S402, according to the index value of the neighbor node, using a data encryption technology to access the vector database located outside the trusted execution environment to obtain the data vector of the neighbor node.
[0086] Specifically, referring to Figure 4 , the data amount of the vector database is large, and if the vector database is set in the TEE, the hardware requirement for the TEE is high, which will increase the hardware cost and affect the running of other programs. Based on this, the embodiment of the present application can also store the vector database in an area outside the TEE, and at this time, the process of querying the vector database based on the index value involves the interaction between the TEE and the external vector database, which has a certain privacy leakage risk. In order to reduce the privacy leakage risk of this process, the same symmetric encryption (SC) algorithm can be configured between the TEE and the vector database, the TEE uses a key to encrypt the index value of the neighbor node, and sends the ciphertext state of the index value to the vector database outside the TEE. The vector database decrypts the ciphertext state of the index value, then queries the corresponding data vector according to the index value, and then encrypts the data vector using the above key, and then sends the ciphertext state of the data vector to the TEE. The TEE decrypts the ciphertext state of the data vector to obtain the data vector of the neighbor node.
[0087] In step S103 of some embodiments, after obtaining the neighbor information of each neighbor node of the reference node, the vector space distance between each neighbor node and the query vector is calculated according to the neighbor information, that is, for each neighbor information, the vector space distance (such as the cosine distance) between the data vector in the neighbor information and the query vector is calculated, that is, the vector space distance of the neighbor node is obtained.
[0088] In step S104 of some embodiments, after obtaining the vector space distance of each neighbor node, the vector space distance of the neighbor node is inserted into a priority queue with a length of L as an element. In this embodiment, the priority queue includes L queue elements in which the vector space distances are sorted from small to large, and each queue element includes the index value of a node and its vector space distance.
[0089] According to some embodiments of the present application, step S104 can include but is not limited to the following steps:
[0090] Step S501, combining the index value and the vector space distance of each neighbor node into a queue element of the priority queue;
[0091] Step S502, performing a sorting operation on all queue elements of the priority queue based on the vector space distance to obtain a sorted priority queue with a length of L.
[0092] Specifically, when inserting the queue element containing the vector space distance into the priority queue, the multiple vector space distances need to be sorted, and this process can be implemented using the queue structure constructed in the TEE. In the current round, the index value and the vector space distance of each neighbor node are combined into a queue element of the priority queue, and all queue elements of the priority queue are sorted. Specifically, the Oblivious Sort sorting method can be used to sort the queue elements of the priority queue based on the vector space distance to obtain sorted queue elements, and the sorting order is sorted from small to large according to the vector space distance. Since the fixed length of the priority queue is L, the first L queue elements are inserted into the priority queue, and the remaining queue elements are overflowed and deleted.
[0093] The first K queue elements in the sorted node queue are intercepted to obtain the selected K neighbor nodes. In the element sorting process of the node queue, the access mode of the data can be hidden, and the attacker cannot infer any information of the original data based on the memory access mode, thereby improving the security of the vector K nearest neighbor query process.
[0094] According to some embodiments of the present application, step S502 can include but is not limited to the following steps:
[0095] Step S601, performing a sorting operation on all queue elements of the priority queue based on the vector space distance using the Oblivious Sort algorithm to obtain a queue element sorting result in which the vector space distances are sorted from small to large;
[0096] Step S602, updating the priority queue according to the first L queue elements in the sorting result.
[0097] Specifically, in the current round, the index value and the vector space distance of each neighbor node of the reference node are combined into a queue element of the priority queue. If the reference node has N neighbor nodes, there are N queue elements, plus the L queue elements of the priority queue obtained in the last round. The L+N queue elements of the priority queue are sorted, and the Oblivious Sort sorting method can be used to sort the L+N queue elements based on the vector space distance to obtain sorted queue elements, and the sorting order is from small to large according to the vector space distance. Then, the queue elements are inserted into the priority queue according to the sorting order of the L+N queue elements. Since the fixed length of the priority queue is L, the queue elements exceeding L are deleted due to overflow. In this embodiment, the Oblivious Sort algorithm is executed in the TEE to sort the priority queue, thereby improving the security of the entire sorting process.
[0098] In step S105 of some embodiments, a node that is not determined as a reference node in the historical rounds is selected from the priority queue as a new reference node, and steps S102 to S104 are repeated to update the queue elements in the priority queue according to the new reference node. The reference node is iterated and steps S102 to S104 are executed until all nodes in the priority queue are used as reference nodes in the historical rounds. Then, the query result is determined according to the first K nodes in the priority queue.
[0099] According to some embodiments of the present application, the step of selecting a node from the priority queue as a new reference node in step S105 can include but is not limited to the following steps:
[0100] Step S701, starting from the first queue element, traverses the nodes in the priority queue, and matches the index value of the currently traversed node with a reference data set, wherein the reference data set is used to store the index values of the historical reference nodes.
[0101] Step S702, in the case where the index value of the currently traversed node does not exist in the reference data set, the currently traversed node is determined as a new reference node.
[0102] In the embodiment, a reference data set is created, and the index value of the reference node determined initially is written into the reference data set. In the process of selecting a node from the priority queue as a new reference node, the nodes in the priority queue are traversed from the first queue element, and the index value of the currently traversed node is matched with the reference data set. In the case that the index value of the currently traversed neighbor node does not exist in the reference data set, the currently traversed node is determined as the new reference node, and the new reference node is added to the reference data set. In the case that the index value of the currently traversed neighbor node exists in the reference data set, the next node in the priority queue is traversed.
[0103] According to some embodiments of the present application, the overall process of the online data vector K-nearest neighbor query of the embodiments of the present application is as follows:
[0104] S10, the entry node 1 marked as "x" in the affinity graph index is taken as a current node u0 to start the query. Specifically, as shown in Figure 5 .
[0105] Given a query point Q (i.e., a query vector), the entry node of the affinity graph index is taken as a current node u0 = 1 to start the query, and K nearest neighbor points of the query point Q are to be found.
[0106] S20, neighbor information of the current node is queried according to the current node u0. Specifically, one of the following two methods can be used to implement:
[0107] Sub-method 1:
[0108] According to u0 = 1, PIR query is performed on the PG and vector data set in the TEE to obtain the neighbor information of the node, i.e., the neighbor node set S1 = {2, 3} and the neighbor vector data set V1 = {v2, v3}.
[0109] Sub-method 2: According to u0 = 1, the PG is queried in the TEE to obtain the neighbor node set S1 = {2, 3}, and then the neighbor vector data set V1 = {v2, v3} of the node is obtained based on the SC outside the TEE.
[0110] S30, a priority queue with a length of L is maintained, and the neighbor nodes {u1, u2,..., u n of the current node are traversed, the distance between each neighbor node and the query point Q is calculated , and is inserted into the queue as a queue element. When inserted, ObliviousSort is used to compare the distance sizes of all to sort. Please refer to Figure 6 for the specific implementation as follows:
[0111] The neighbor node set S1 = {2, 3} is traversed, and the distances dist 2,Q of v2 and Q point and the distances dist 3,Q of v3 and Q point are calculated in turn to obtain {2, dist 2,Q} and {3, dist 3,Q}. The Oblivious Sort algorithm is used to sort {2, dist 2,Q} and {3, dist 3,Q} and the existing elements in the queue according to the distance from small to large, so as to insert {2, dist 2,Q} and {3, dist 3,Q} into the queue in order.
[0112] In step S40, the first node not processed in steps S20 and S30 is found in the queue, and the node is taken as the current node, and steps S20 to S40 are performed. If all the neighbor nodes of the nodes in the queue have been processed, the query ends, and the K nodes in the current queue are the query result output.
[0113] In the vector K nearest neighbor query process, the application embodiment protects the access mode and data privacy. The PG, PIR, SC and Oblivious Sort technologies are used in the TEE to protect the privacy of the vector K nearest neighbor query process while maximizing the query processing efficiency.
[0114] The application embodiment further provides a vector data K nearest neighbor query system applied to a trusted execution environment of a server. The vector data K nearest neighbor query system includes:
[0115] A first module configured to select a node of a proximity graph index of a vector database as a reference node in response to a query vector;
[0116] A second module configured to determine neighbor information according to the reference node and the proximity graph index, wherein the neighbor information includes an index value and a data vector of a neighbor node;
[0117] A third module configured to calculate a vector space distance between each neighbor node and the query vector according to the neighbor information;
[0118] A fourth module configured to insert the vector space distance of the neighbor node into a priority queue with a length of L;
[0119] A fifth module configured to select a node from the priority queue as a new reference node, and update the priority queue according to the new reference node until all the nodes in the priority queue are used as the reference node in a historical round, and determine a query result according to the first K nodes in the priority queue.
[0120] It can be understood that the contents in the above-mentioned vector data K nearest neighbor query method embodiment are all applicable to the present system embodiment, the present system embodiment specifically implements the same functions as the above-mentioned vector data K nearest neighbor query method embodiment, and achieves the same beneficial effects as the above-mentioned vector data K nearest neighbor query method embodiment.
[0121] The present application embodiment further provides an electronic device, which comprises a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for realizing connection communication between the processor and the memory, and the program is executed by the processor to realize the above-mentioned vector data K nearest neighbor query method. The electronic device can be any intelligent terminal including a tablet computer, a vehicle-mounted computer, etc.
[0122] Please refer to Figure 7 , Figure 7 The hardware structure of the electronic device of another embodiment is illustrated, which comprises:
[0123] The processor 901 can be implemented in the form of a general CPU (Central Processing Unit), a microprocessor, an ASIC (Application Specific Integrated Circuit), or one or more integrated circuits, etc., for executing related programs to realize the technical solutions provided by the present application embodiment;
[0124] The memory 902 can be implemented in the form of a ROM (Read Only Memory), a static storage device, a dynamic storage device, or a RAM (Random Access Memory), etc. The memory 902 can store an operating system and other application programs, and when the technical solutions provided by the present application embodiment are implemented by software or firmware, the related program codes are saved in the memory 902 and called and executed by the processor 901 to realize the vector data K nearest neighbor query method of the present application embodiment;
[0125] The input / output interface 903 is used to realize information input and output;
[0126] The communication interface 904 is used to realize the communication interaction between the present device and other devices, which can realize communication through a wired manner (for example, a USB, a network cable, etc.) or a wireless manner (for example, a mobile network, WIFI, Bluetooth, etc.);
[0127] The bus 905 transmits information between various components (for example, the processor 901, the memory 902, the input / output interface 903, and the communication interface 904) of the device;
[0128] The processor 901, the memory 902, the input / output interface 903, and the communication interface 904 are communicatively connected with each other through the bus 905.
[0129] The embodiment of the present application further provides a storage medium, which is a computer readable storage medium, used for computer readable storage, and stores one or more programs, which can be executed by one or more processors to implement the above-mentioned vector data K nearest neighbor query method.
[0130] The memory is a non-transitory computer readable storage medium, and can be used to store non-transitory software programs and non-transitory computer executable programs. In addition, the memory can include a high-speed random access memory, and can further include a non-transitory memory, for example, at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some embodiments, the memory can optionally include a memory remotely arranged relative to the processor, and the remote memory can be connected to the processor through a network. Examples of the network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.
[0131] The embodiments described in the embodiments of the present application are used to more clearly illustrate the technical solutions of the embodiments of the present application, and do not constitute a limitation on the technical solutions provided by the embodiments of the present application. It can be understood by those skilled in the art that, with the evolution of technology and the appearance of new application scenarios, the technical solutions provided by the embodiments of the present application are also applicable to similar technical problems.
[0132] Those skilled in the art can understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of the present application, and can include more or fewer steps than those shown in the figures, or combine certain steps, or different steps.
[0133] The system embodiments described above are only schematic, and the units described as separate components can or can not be physically separate, that is, can be located in one place, or can be distributed on multiple network units. According to actual needs, part or all of the modules can be selected to achieve the purpose of the embodiments of the present application.
[0134] Those skilled in the art can understand that all or some steps in the above disclosed method, the function modules / units in the system and the device can be implemented as software, firmware, hardware and their appropriate combinations.
[0135] The terms "first", "second", "third", "fourth", and the like in the description and in the claims of this application, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It is to be understood that the use of the terms so termed is interchangeable under appropriate circumstances such that the embodiments of the application described herein are, for example, capable of orderly or chronological mundane operation, reverse order operation, based on circuitry availability, based on stated preference or the like, and that "default" or other orderings are thus permissible. Further, the terms "comprise", "comprising", "include", "including", and the like, are specifically intended to be open-ended. That is, references to individual steps and the like do not suhstantially exclude the presence of two or more of a recited step or its integral sub-steps or additional steps whether or not readily ascertainable from the description or the like. Further, the words "a" or "an", as used herein in the disclosure and elsewhere, are used indiscriminately and are to be interpreted in the same way, i.e. as meaning "one or more".
[0136] It should be understood that, in the application, "at least one" refers to one or more, and "multiple" refers to two or more. "And / or" is used to describe the relationship between the associated objects, which means that there can be three relationships, for example, "A and / or B" can represent three cases: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally represents an "or" relationship between the front and rear associated objects. "At least one of the following" or similar expressions means any combination of these items, including any combination of single or multiple items. For example, at least one of a, b or c can mean a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0137] In several embodiments provided by the application, it should be understood that the disclosed system and method can be implemented in other ways. For example, the above-described system embodiments are only illustrative, for example, the division of the above-mentioned units is only a logical functional division, and actual implementation can have another division manner, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed objects can be indirect coupling or communication connection between systems or units through some interfaces, which can be electrical, mechanical or other forms.
[0138] The units described above as separate components can or can not be physically separate, and the components shown as units can or can not be physical units, i.e. they can be located in one place or distributed on multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the embodiment.
[0139] In addition, each function unit in each embodiment of the present application can be integrated in one processing unit, or each unit can be physically present separately, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software function unit.
[0140] If the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in part, or all or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes multiple instructions used to cause a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods in the embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various program storage media.
[0141] The preferred embodiments of the embodiments of the present application are described above with reference to the accompanying drawings, and the scope of the rights of the embodiments of the present application is not limited thereto. Any modifications, equivalent replacements and improvements made by those skilled in the art without departing from the scope and essence of the embodiments of the present application shall be within the scope of the rights of the embodiments of the present application.
Claims
1. A vector data K-nearest neighbor query method, characterized in that: Applied in a trusted execution environment on a server, the vector data K-nearest neighbor query method includes the following steps: In response to the query vector, selecting a node of an affinity graph index of the vector database as a reference node; Determining neighbor information according to the reference node and the affinity graph index, wherein the neighbor information includes an index value and a data vector of the neighbor node; Calculating a vector space distance between each of the neighbor nodes and the query vector according to the neighbor information; Inserting the vector space distance of the neighbor node into a priority queue of length L; A node is selected from the priority queue as a new reference node, and the priority queue is updated according to the new reference node until all nodes in the priority queue are used as reference nodes in historical rounds, and the query result is determined according to the first K nodes in the priority queue.
2. The vector data K-nearest neighbor query method according to claim 1, characterized in that: Determining neighbor information according to the reference node and the affinity graph index comprises the following steps: Querying the affinity graph index according to the index value of the reference node to determine the index value of the neighbor node of the reference node; According to the index value of the neighbor node, a private information retrieval technology is used to query the vector database located in the trusted execution environment to obtain the data vector of the neighbor node.
3. The vector data K-nearest neighbor query method according to claim 1, characterized in that: Determining neighbor information according to the reference node and the affinity graph index comprises the following steps: Querying the affinity graph index according to the index value of the reference node to determine the index value of the neighbor node of the reference node; According to the index value of the neighbor node, a data encryption technology is used to access a vector database located outside the trusted execution environment to obtain the data vector of the neighbor node.
4. The vector data K-nearest neighbor query method according to claim 1, characterized in that: Inserting the vector space distances of the neighboring nodes into a priority queue of length L comprises the following steps: Combining the index value and the vector space distance of each neighbor node into a queue element of a priority queue; A sorting operation is performed on all the queue elements of the priority queue based on the vector space distance to obtain a sorted priority queue with a length of L.
5. The vector data K-nearest neighbor query method according to claim 4, characterized in that: The step of performing a sorting operation on all the queue elements in the priority queue based on the vector space distance to obtain a sorted priority queue with a length of L includes the following steps: Using the Oblivious Sort algorithm to perform a sorting operation on all the queue elements of the priority queue based on the vector space distance, to obtain a result of sorting the queue elements in ascending order of vector space distance; Update the priority queue according to the first L queue elements in the sorting result.
6. The vector data K-nearest neighbor query method according to claim 4, characterized in that: The step of selecting a node from the priority queue as a new reference node comprises the following steps: Traversing the nodes in the priority queue starting from the first queue element, and matching the index value of the currently traversed node with a reference data set, wherein the reference data set is used to store the index values of historical reference nodes; In the case that the index value of the currently traversed node does not exist in the reference data set, the currently traversed node is determined as a new reference node.
7. The vector data K-nearest neighbor query method according to claim 1, characterized in that: The affinity graph index is obtained by the following steps: Define an index value for each data vector in the vector database; The index value is used as a node of the affinity graph index, and the edges of the affinity graph index are determined according to the vector distances between each pair of data vectors to obtain a constructed affinity graph index; The constructed affinity graph index is loaded into the trusted execution environment.
8. A vector data K-nearest neighbor query system, characterized by: Applied in a trusted execution environment on a server, the vector data K-nearest neighbor query system includes: A first module is configured to select a node of an affinity graph index of a vector database as a reference node in response to a query vector; A second module is configured to determine neighbor information based on the reference node and the affinity graph index, wherein the neighbor information includes an index value and a data vector of the neighbor node; A third module is configured to calculate the vector space distance between each neighbor node and the query vector based on the neighbor information; A fourth module is configured to insert the vector space distance of the neighboring node into a priority queue of length L; The fifth module is used to select a node from the priority queue as a new reference node, and update the priority queue according to the new reference node until all nodes in the priority queue are used as reference nodes in historical rounds, and determine the query result according to the first K nodes in the priority queue.
9. An electronic device, characterized in that: The electronic device includes a memory, a processor, a program stored in the memory and executable on the processor, and a data bus for implementing connection and communication between the processor and the memory. When the program is executed by the processor, the steps of the method described in any one of claims 1 to 7 are implemented.
10. A storage medium, which is a computer-readable storage medium and is used for computer-readable storage, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the steps of any one of claims 1 to 7.