Homomorphic k-nearest neighbor search method, device and equipment based on gap amplification ordering
The homomorphic k-nearest neighbor retrieval method based on gap amplification sorting, utilizing slot group coding and homomorphic encryption, achieves efficient and secure homomorphic k-nearest neighbor retrieval on large-scale databases. It solves the computational bottleneck of sorting and selection in the ciphertext field, optimizes computational complexity, and improves retrieval accuracy.
Patent Information
- Application Number
- CN202611682242.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-28
- Publication Date
- 2026-11-27
AI Technical Summary
Existing homomorphic k-nearest neighbor retrieval methods have high computational complexity on large-scale databases and cannot be directly sorted and selected in the ciphertext domain, resulting in the risk of information leakage and low computational efficiency.
A homomorphic k-nearest neighbor retrieval method based on gap amplification sorting is adopted. By using slot group coding and homomorphic encryption, the candidate records and query vectors are securely outsourced to the computing server. By leveraging the parallel computing capabilities of on-ring homomorphic encryption, and combining distance extended coding, gap amplification symbol approximation and shift rectified linear unit approximation, the entire link from distance calculation to top-k extraction is parallelized and fixed.
It achieves efficient and secure generation of encrypted top-k results in the ciphertext field, avoiding information leakage and optimizing computational complexity by orders of magnitude, thus combining security, computational efficiency, and retrieval accuracy.
Smart Images

Figure CN123178688A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of fully homomorphic encryption and privacy-preserving vector retrieval technology, and in particular to a homomorphic k-nearest neighbor retrieval method, apparatus and device based on gap amplification sorting. Background Technology
[0002] k-Nearest Neighbor (kNN) retrieval compares the distances between a query vector and database records, returning the k records with the smallest distances. It is widely used in biometric retrieval, medical data analysis, fraud detection, recommendation systems, and search enhancement applications. In outsourced scenarios where both the database and the query contain sensitive information, data owners want the computing server to perform nearest neighbor calculations without access to the plaintext database, query vector, or search results. Fully homomorphic encryption allows the computing server to perform operations directly on the ciphertext, thus providing a cryptographic computational foundation for non-interactive privacy-preserving nearest neighbor retrieval.
[0003] Homomorphic encryption, suitable for approximate real number operations, can encode multiple real numbers into the same ciphertext slot and achieve parallel vector computation through addition, multiplication, and rotation. Distance calculation can be completed by subtraction, squaring, and in-slot reduction, but nearest neighbor retrieval also requires comparing encrypted distances, forming rankings, and extracting the top-k records. Ciphertext cannot directly participate in conditional branching; sign functions, sorting, and selection must be transformed into polynomial circuits or fixed comparison networks. Therefore, sorting and selection often become the main computational bottlenecks of homomorphic k-nearest neighbors.
[0004] Existing ciphertext sorting schemes often use encoded scalar distances as input, aiming for a general symbol approximation or complete sorting across the entire comparison interval. For k-nearest neighbors, the ranking of adjacent neighbors is often determined by the difference between two near-zero distances. To uniformly improve the symbol approximation accuracy over a wide interval, high-degree polynomials and deep multiplication circuits are required; if a complete sorting or permutation network is used, a large amount of order information beyond what is needed for top-k retrieval will be calculated.
[0005] Furthermore, when the database size exceeds the capacity of a single ciphertext or a fixed candidate pool, performing global pairwise comparisons across the entire database incurs a comparison burden that grows quadratically with the database size. Directly selecting clusters in the plaintext and processing only the selected clusters will leak the cluster selection results to the computing server; simply retrieving different clusters separately without merging them in the ciphertext domain will not yield a global top-k result. Another technical challenge that large-scale homomorphic nearest neighbor retrieval needs to address is how to maintain the selected clusters, intra-block winners, and final record identifiers in an encrypted state after pre-clustering, while avoiding control flow related to the ciphertext data.
[0006] Therefore, there is an urgent need for a homomorphic k-nearest neighbor retrieval method and system that can generate encrypted top-k results end-to-end from encrypted feature vectors, improve the resolution of near-zero distance difference comparisons, avoid complete sorting, and complete candidate selection and ciphertext merging on a pre-clustered large-scale database through a common fixed execution trajectory. Summary of the Invention
[0007] Therefore, it is necessary to provide a homomorphic k-nearest neighbor retrieval method, apparatus, and device based on gap amplification sorting, which can perform end-to-end privacy-preserving nearest neighbor retrieval with a circuit complexity linearly related to the candidate size, without the need for intermediate decryption and without leaking the data-related control flow, and with the sorting accuracy focused on the nearest neighbor boundary.
[0008] A homomorphic k-nearest neighbor retrieval method based on gap amplification sorting, the method comprising: Based on the size of the public candidate pool, the private key holder encodes multiple candidate records into their respective candidate slots, pads the query vector with zeros and copies it to each candidate slot, performs homomorphic encryption on the encoded candidate records and query vectors, and sends the encrypted candidate record ciphertext and query vector ciphertext to the computing server.
[0009] The computing server receives the candidate record ciphertext and the query vector ciphertext, performs ciphertext subtraction on the candidate record ciphertext and the query vector ciphertext in the same candidate slot group to obtain the difference ciphertext, performs slot-by-slot squaring operation on the difference ciphertext to obtain the square distance ciphertext, and performs rotation accumulation on the square distance ciphertext according to the candidate slot group to obtain the encrypted square distance of each candidate record.
[0010] The computing server uses the encrypted squared distance as input and performs normalization processing on each encrypted squared distance according to the upper bound of the public distance. For each normalized encrypted squared distance, a distance expansion code and a distance replication code are constructed respectively. The distance expansion code and the distance replication code are then subjected to ciphertext subtraction to obtain the distance difference ciphertext containing the pairwise normalized distance difference between candidate records.
[0011] The computing server takes the distance difference ciphertext as input and performs gap amplification symbolic approximation on the distance difference ciphertext. The gap amplification symbolic approximation first maintains the positive and negative directions of the distance difference and amplifies the near-zero distance difference by a near-zero amplification polynomial. Then, the outer polynomial performs smooth saturation mapping on the amplification result to obtain the approximate comparison result ciphertext of the size relationship between candidate records.
[0012] The computing server takes the ciphertext of the approximate comparison result as input, performs rotation accumulation on the ciphertext of the approximate comparison result according to the candidate slot group, obtains the ciphertext rank value corresponding to each candidate record, and after affine mapping the ciphertext rank value to the public rank domain, performs shift rectified linear unit approximation on the ciphertext rank value in the public rank domain according to the number of nearest neighbors k, so as to extract the encryption gating response corresponding to the top k candidate records.
[0013] The computing server returns the encrypted gating response to the private key holder. After decryption, the private key holder performs a threshold test on the decrypted value and obtains the nearest neighbor record identifier based on the candidate slot position mapping that passes the threshold test.
[0014] A homomorphic k-nearest neighbor retrieval device based on gap amplification sorting includes a private key holding device and a computing server device. The device includes: The private key holder device includes a parameter and key module, a preprocessing and encryption module, and a result decryption module.
[0015] The computing server equipment includes a ciphertext distance module, a ciphertext difference encoding and ranking module, and a candidate extraction module.
[0016] The Cipher Distance module is used to perform ciphertext subtraction between the ciphertext of the candidate record and the ciphertext of the query vector, slot-by-slot square sum rotation accumulation, and output the encrypted square distance.
[0017] The ciphertext difference encoding and ranking module receives the encrypted squared distance, performs normalization, distance expansion encoding and distance replication encoding construction, gap amplification symbol approximation and ciphertext rank aggregation, and outputs the ciphertext rank value.
[0018] The candidate extraction module is used to receive the ciphertext rank value, perform a shift-rectified linear unit approximation, and output an encrypted gating response.
[0019] When the computing server operates in single candidate pool mode, the candidate extraction module outputs an encrypted top-k response. When operating in pre-clustering expansion mode, it also generates a globally encrypted top-k record through the clustering scheduling and repackaging module and the hierarchical merging module.
[0020] A computer device includes a memory and a processor, the memory storing a computer program, and the processor executing the computer program performing the following steps: Based on the size of the public candidate pool, the private key holder encodes multiple candidate records into their respective candidate slots, pads the query vector with zeros and copies it to each candidate slot, performs homomorphic encryption on the encoded candidate records and query vectors, and sends the encrypted candidate record ciphertext and query vector ciphertext to the computing server.
[0021] The computing server receives the candidate record ciphertext and the query vector ciphertext, performs ciphertext subtraction on the candidate record ciphertext and the query vector ciphertext in the same candidate slot group to obtain the difference ciphertext, performs slot-by-slot squaring operation on the difference ciphertext to obtain the square distance ciphertext, and performs rotation accumulation on the square distance ciphertext according to the candidate slot group to obtain the encrypted square distance of each candidate record.
[0022] The computing server uses the encrypted squared distance as input and performs normalization processing on each encrypted squared distance according to the upper bound of the public distance. For each normalized encrypted squared distance, a distance expansion code and a distance replication code are constructed respectively. The distance expansion code and the distance replication code are then subjected to ciphertext subtraction to obtain the distance difference ciphertext containing the pairwise normalized distance difference between candidate records.
[0023] The computing server takes the distance difference ciphertext as input and performs gap amplification symbolic approximation on the distance difference ciphertext. The gap amplification symbolic approximation first maintains the positive and negative directions of the distance difference and amplifies the near-zero distance difference by a near-zero amplification polynomial. Then, the outer polynomial performs smooth saturation mapping on the amplification result to obtain the approximate comparison result ciphertext of the size relationship between candidate records.
[0024] The computing server takes the ciphertext of the approximate comparison result as input, performs rotation accumulation on the ciphertext of the approximate comparison result according to the candidate slot group, obtains the ciphertext rank value corresponding to each candidate record, and after affine mapping the ciphertext rank value to the public rank domain, performs shift rectified linear unit approximation on the ciphertext rank value in the public rank domain according to the number of nearest neighbors k, so as to extract the encryption gating response corresponding to the top k candidate records.
[0025] The computing server returns the encrypted gating response to the private key holder. After decryption, the private key holder performs a threshold test on the decrypted value and obtains the nearest neighbor record identifier based on the candidate slot position mapping that passes the threshold test.
[0026] The aforementioned homomorphic k-nearest neighbor retrieval method, apparatus, and device based on gap amplification sorting firstly, through slot group encoding and homomorphic encryption, allows the private key holder to securely outsource the database and query vector to the computing server with only one encrypted upload, avoiding the information leakage risk and communication overhead caused by multiple rounds of interaction and decryption. Secondly, ciphertext subtraction and slot-by-squaring sum-of-sigma rotation accumulation are completed within a common fixed execution trajectory, fully utilizing the single-instruction multiple-data parallel capability of on-ring homomorphic encryption to calculate the squared distance of all candidate records in one go. Furthermore, this process does not introduce any conditional branches related to the values of candidate records or query vectors, fundamentally eliminating the possibility of side-channel leakage. Then, by constructing distance extension encoding and distance replication encoding and performing ciphertext subtraction, the original requirement of O(m²) independent comparisons for pairwise distance difference calculation is transformed into a single ciphertext subtraction that can generate all m² pairs of comparison values in parallel, achieving an order-of-magnitude optimization of computational complexity at the cryptographic level. Furthermore, the adopted gap-amplified sign approximation structure first amplifies the small distance difference that determines the adjacent rankings using a near-zero distance difference amplification polynomial and moves it out of the transition region of the outer saturation function. Then, a smooth saturation mapping outputs the comparison result that approximates the sign function. This eliminates the need to use a high-order general polynomial to uniformly approximate the sign function over a wide interval during the ranking stage. Instead, the polynomial accuracy is concentrated in the near-zero interval where the k-nearest neighbor boundary is most sensitive, effectively controlling the circuit multiplication depth while ensuring the accuracy of the top-k boundary comparison. Furthermore, after rotating and accumulating the ciphertext rank value, the top-k corresponding slots are directly approximated and gated using a shift-rectified linear unit. Compared to existing schemes that rely on complete sorting or global comparison networks, this constrains the computational load from O(m²) to a level linearly related to the candidate pool size. Moreover, changes in the number of nearest neighbors k only adjust the public bias without altering the depth and shape of the extraction circuit, allowing the same set of homomorphic parameters and circuit structure to adapt to different k values. Finally, after decryption, threshold detection is used to map the record identifier to the candidate slot position, restoring the record identifier so that the final output directly corresponds to the original database index without additional identifier restoration overhead. In summary, the entire chain of parallelization and standardization from distance calculation to top-k extraction is achieved in the ciphertext domain, which combines security, computational efficiency and retrieval accuracy. Attached Figure Description
[0027] Figure 1 This is a flowchart of a homomorphic k-nearest neighbor retrieval method based on gap amplification sorting in one embodiment; Figure 2 This is a schematic diagram of the overall workflow consisting of a private key holder, a homomorphic computation server, a core homomorphic processing chain, and an optional pre-clustering extension path in one embodiment. Figure 3 This is a schematic diagram of the homomorphic k-nearest neighbor method for a single candidate pool in one embodiment; Figure 4This is a schematic diagram of the layout for candidate slot group packaging and distance extension encoding and distance replication encoding in one embodiment; Figure 5 This is a schematic diagram of gap amplification symbol approximation, ciphertext rank aggregation, and shift rectification extraction in one embodiment; Figure 6 This is a schematic diagram of global rank expansion for a single candidate pool with multiple ciphertexts in one embodiment; Figure 7 This is a schematic diagram of the complete process of pre-clustering fixed-capacity scheduling of homomorphic nearest neighbors in one embodiment; Figure 8 This is a schematic diagram of rank-specific cryptographic cluster selector repackaging and hierarchical merging in one embodiment; Figure 9 Here is a block diagram of a homomorphic k-nearest neighbor retrieval system module in one embodiment; Figure 10 This is a comparison chart of the ranking phase runtime in one embodiment with that of existing methods; Figure 11 This is a structural block diagram of a homomorphic k-nearest neighbor retrieval device based on gap amplification sorting in one embodiment; Figure 12 This is an internal structural diagram of a computer device in one embodiment. Detailed Implementation
[0028] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0029] In one embodiment, such as Figure 1 As shown, a homomorphic k-nearest neighbor retrieval method based on gap amplification sorting is provided, including the following steps: Step 102: The private key holder encodes multiple candidate records into corresponding candidate slots according to the size of the public candidate pool, pads the query vector with zeros and copies it to each candidate slot, performs homomorphic encryption on the encoded candidate records and query vectors, and sends the encrypted candidate record ciphertext and query vector ciphertext to the computing server.
[0030] Step 104: Calculate the ciphertext of the candidate record and the ciphertext of the query vector received by the server. Perform ciphertext subtraction on the ciphertext of the candidate record and the ciphertext of the query vector in the same candidate slot group to obtain the difference ciphertext. Perform slot-by-slot squaring operation on the difference ciphertext to obtain the square distance ciphertext. Perform rotation accumulation on the square distance ciphertext according to the candidate slot group to obtain the encrypted square distance of each candidate record.
[0031] Step 106: The server calculates the encrypted squared distance as input and performs normalization processing on each encrypted squared distance according to the upper bound of the public distance. For each normalized encrypted squared distance, a distance extension code and a distance replication code are constructed respectively. The distance extension code and the distance replication code are subtracted by ciphertext to obtain the distance difference ciphertext containing the pairwise normalized distance difference between candidate records.
[0032] Step 108: The computing server takes the distance difference ciphertext as input and performs gap amplification symbolic approximation on the distance difference ciphertext. The gap amplification symbolic approximation first maintains the positive and negative directions of the distance difference and amplifies the near-zero distance difference using a near-zero amplification polynomial. Then, the outer polynomial performs smooth saturation mapping on the amplification result to obtain the approximate comparison result ciphertext of the size relationship between candidate records.
[0033] Step 110: The computing server takes the ciphertext of the approximate comparison result as input, performs rotation accumulation on the ciphertext of the approximate comparison result according to the candidate slot group, obtains the ciphertext rank value corresponding to each candidate record, maps the ciphertext rank value to the public rank domain by affine mapping, and performs shift rectified linear unit approximation on the ciphertext rank value in the public rank domain according to the number of nearest neighbors k, so as to extract the encryption gating response corresponding to the top k candidate records.
[0034] Step 112: The computing server returns the encrypted gating response to the private key holder. After decryption, the private key holder performs a threshold test on the decrypted value and obtains the nearest neighbor record identifier based on the candidate slot position mapping that passes the threshold test.
[0035] In the aforementioned homomorphic k-nearest neighbor retrieval method based on gap amplification sorting, firstly, by using slot group encoding and homomorphic encryption, the private key holder only needs to upload the database and query vector securely to the computing server once, avoiding the information leakage risk and communication overhead caused by multiple rounds of interaction and decryption. Secondly, ciphertext subtraction and slot-by-squaring sum-of-sigma rotation accumulation are completed within a common fixed execution trajectory, fully utilizing the single-instruction multiple-data parallel capability of on-ring homomorphic encryption to calculate the squared distance of all candidate records in one go. Moreover, this process does not introduce any conditional branches related to the values of candidate records or query vectors, fundamentally eliminating the possibility of side-channel leakage. Then, by constructing distance extension encoding and distance replication encoding and performing ciphertext subtraction, the original O(m²) independent comparisons required for pairwise distance difference calculation are transformed into a single ciphertext subtraction that can generate all m² pairs of comparison values in parallel, achieving an order-of-magnitude optimization of computational complexity at the cryptographic level. Furthermore, the adopted gap-amplified sign approximation structure first amplifies the small distance difference that determines the adjacent rankings using a near-zero distance difference amplification polynomial and moves it out of the transition region of the outer saturation function. Then, a smooth saturation mapping outputs the comparison result that approximates the sign function. This eliminates the need to use a high-order general polynomial to uniformly approximate the sign function over a wide interval during the ranking stage. Instead, the polynomial accuracy is concentrated in the near-zero interval where the k-nearest neighbor boundary is most sensitive, effectively controlling the circuit multiplication depth while ensuring the accuracy of the top-k boundary comparison. Furthermore, after rotating and accumulating the ciphertext rank value, the top-k corresponding slots are directly approximated and gated using a shift-rectified linear unit. Compared to existing schemes that rely on complete sorting or global comparison networks, this constrains the computational load from O(m²) to a level linearly related to the candidate pool size. Moreover, changes in the number of nearest neighbors k only adjust the public bias without altering the depth and shape of the extraction circuit, allowing the same set of homomorphic parameters and circuit structure to adapt to different k values. Finally, after decryption, threshold detection is used to map the record identifier to the candidate slot position, restoring the record identifier so that the final output directly corresponds to the original database index without additional identifier restoration overhead. In summary, the entire chain of parallelization and standardization from distance calculation to top-k extraction is achieved in the ciphertext domain, which combines security, computational efficiency and retrieval accuracy.
[0036] In one embodiment, from the time the computing server receives the input ciphertext to the time it returns the encrypted gating response, it performs all operations according to a common fixed execution trajectory that is independent of the ciphertext data value. The common fixed execution trajectory is determined by the candidate pool size, feature dimension, candidate slot group layout, and the number of nearest neighbors k. The computing server does not perform intermediate decryption during the entire execution period. The homomorphic encryption is on-ring homomorphic encryption that supports near-real number single instruction multiple data operations. When executing the common fixed execution trajectory, the computing server uses the multiplication calculation key and the rotation calculation key corresponding to the candidate slot group layout.
[0037] In one embodiment, the public candidate pool contains m candidate records, each candidate slot group contains m slots, the feature dimension d of the candidate records satisfies d ≤ m, the d feature components of the i-th candidate record occupy the first d slots in the i-th candidate slot group, and the remaining slots are set to zero; the rotation accumulation adopts a rotation step size. Perform a rotation addition on the squared distance ciphertext, where, The distance expansion encoding copies the i-th normalized encrypted squared distance to all m slots of the i-th candidate slot group. The distance copy encoding repeats the complete distance vector formed by the m normalized encrypted squared distances m times, so that the j-th slot in the i-th candidate slot group stores the distance value of the j-th candidate record.
[0038] In one embodiment, the upper bound of the public distance is obtained, and the encrypted squared distances are normalized based on the squared Euclidean distance between the current candidate record and the query vector to obtain the normalized encrypted squared distance: ; in, The normalized encrypted squared distance. To make the upper limit of the public distance, For query vector, For candidate records; obtain any pairwise normalized distance difference based on the normalized encrypted squared distance: where, Indicates the first Squared Euclidean distance between candidate vectors and query vector; distance difference index and Used to distinguish candidate records participating in the comparison.
[0039] ; in, For pairwise normalized distance difference, , These are the normalized encrypted squared distances corresponding to two different candidate records, with the smaller normalized encrypted squared distance corresponding to the smaller ciphertext rank value.
[0040] In one embodiment, the near-zero amplification polynomial of the distance difference is an odd symmetric polynomial, corresponding to a slope near the origin that is greater than the slope far from the origin and a bounded output amplitude; within the range of the pairwise normalized distance difference, the following objective function is approximated by a thirteenth-order Chebyshev approximation to obtain the near-zero amplification polynomial of the distance difference: ; in, To construct the objective function of a near-zero distance difference amplification polynomial, The pairwise normalized distance difference, with a value ranging from -1 / 2 to 1 / 2, is used as the input for near-zero amplification. Near-zero amplification is then applied to this pairwise normalized distance difference, shifting the near-zero distance difference that determines the adjacent ranking out of the saturation interval of the outer function. A smooth saturation mapping is then performed using a 119th-order polynomial approximation of a logic function with a kurtosis of 70, mapping the amplified distance difference to a bounded interval centered at 1 / 2, thus obtaining an approximate comparison result. ; in, For approximate comparison results, The output of the function is the result of near-zero amplification through the corresponding number of layers. In actual homomorphic operations, each layer is approximated using the polynomials described above. This is a logic function with a kurtosis of 70. (Subscript) This represents the number of near-zero magnification layers, and is a positive integer. 70 represents the natural constant, and 70 is the kurtosis parameter of the logic function.
[0041] In one embodiment, all approximate comparison results in each candidate slot group, excluding the self-comparison term, are rotated and accumulated to obtain the ciphertext rank value of each candidate record. Half of the self-comparison term is used as a reference bias so that candidate records with smaller distances have smaller ciphertext rank values. The ciphertext rank values are then subjected to an affine mapping to map them to a publicly disclosed rectified approximate input domain, resulting in the mapped value: ; in, The rank of the ciphertext. For mapping values, The number of candidate records in the current candidate pool; with the inflection point And the slope is The shift-rectified linear unit performs an approximation on the mapped value, such that the change in the number of nearest neighbors k under a fixed candidate pool size m only changes the public bias without increasing the multiplication depth of the extraction circuit, generating an encrypted top-k gated response.
[0042] In one embodiment, when the square of the total number of candidate records is greater than half the ring dimension, the candidate records of the total number of candidate records are divided into fixed-length ciphertext partitions: ; in, The number of fixed-length ciphertext partitions, The total number of candidate records. The number of common candidates for each partition is calculated; the local ciphertext rank value within each ciphertext partition is calculated, and a gap amplification symbol approximation is performed once for each unordered ciphertext partition. The ranking correction amount in the opposite direction is derived from the approximation output in one direction by rotation, public masking, and copying. The local ciphertext rank value is combined with the ranking correction amount from other ciphertext partitions to form the global ciphertext rank value, and this is performed based on the total number of candidate records.
[0043] In one embodiment, a homomorphic k-nearest neighbor retrieval method based on pre-clustering fixed-capacity scheduling includes the following steps: The private key holder obtains c pre-divided plaintext database clusters, cluster representative vectors for each cluster, and fixed capacity layouts that satisfy the common capacity constraints of each cluster. It fills each cluster into the common capacity and splits it into fixed-capacity candidate blocks. After encoding and homomorphically encrypting the cluster representative vectors, all fixed-capacity candidate blocks, query vectors, validity weight channels, and record identifier metadata channels, it sends them to the computing server.
[0044] The computing server receives the encrypted cluster representative vector ciphertext and performs encrypted squared distance calculation, pairwise distance difference encoding, gap amplification symbol approximation, and ciphertext rank aggregation operation on the cluster representative vector pool composed of the cluster representative vector ciphertext. This generates r sets of rank-specific encrypted cluster selectors, which identify the clusters corresponding to each rank in the ciphertext field.
[0045] The computing server takes all the size-fixed candidate blocks as input and executes a common fixed execution trajectory on all size-fixed candidate blocks, which is independent of the ciphertext value of the rank-specific cryptographic cluster selector. It obtains the cryptographic local winning record of each size-fixed candidate block. The cryptographic local winning record includes a score channel, a validity weight channel, and a record identifier metadata channel.
[0046] The computing server performs ciphertext multiplication on each channel of the specific encrypted cluster selector and the corresponding encrypted local winning record of the cluster, and performs homomorphic summation along the cluster dimension. It merges the block winning records under the same cluster representative rank, and then performs the final merge on the cluster-level candidates under different cluster representative rank to obtain the global encrypted top-k records.
[0047] The computing server returns the globally encrypted top-k records to the private key holder, who then decrypts them, excludes zero-weight outputs, and restores the nearest neighbor record identifiers.
[0048] It is worth noting that the database size is The common capacity relaxation parameter is The maximum public capacity per cluster is Each cluster is based on the common block capacity. Split into There are 100 candidate blocks with fixed capacity, and each cluster... satisfy ;No. Weight of each valid record The weight of the record to be filled is zero, and it is set to 1. This creates a scoring channel for subsequent descending-order merging.
[0049] Each cluster represents a ranking. A corresponding set of lengths is Rank-specific cryptographic cluster selector ,in and The computing server does not decrypt. In the case of all Each volumetric candidate block performs the same number of gap amplification symbol approximations and output operations of the same shape.
[0050] For local rankings Generate an encryption prefix indicator based on the ciphertext rank value. ,make And in season , and then Perform a square cleanup.
[0051] Calculate separately , and To form an encrypted local winning record , For local rankings The corresponding aggregate score, For the first The original scores of the candidate records, It represents the ranking selection quantity after the adjacent prefix difference is squared and cleaned. For the first The identifier metadata of each candidate record, The first result obtained by gating summation Name output metadata channel value, and These are the corresponding score channel value and weight channel value for the output.
[0052] For clusters representing rankings Block number and local rankings ,calculate ,in, For each cluster, the repackaged record, after gating and summing along the cluster dimension, represents the rank corresponding to the cluster. The repackaging record execution block winners are merged, and then no more than [number] records are repackaged. Cluster-level candidates are eventually merged across clusters.
[0053] when At that time, The candidate records are divided into A fixed-length encrypted partition, in which It is the ring dimension and The number of common candidates for each partition; Calculate the local ciphertext rank value within each ciphertext partition, and perform a gap amplification symbol approximation for each unordered ciphertext partition by performing a packing operation. The ranking correction in the opposite direction is derived from an approximate output in one direction through rotation, public masking, and duplication. The local ciphertext rank is combined with the ranking corrections from other ciphertext partitions to form the global ciphertext rank, and then adjusted according to the total number of candidate records. Perform the steps to generate an encrypted top-k response.
[0054] When the multi-stage homomorphic computation exhausts the multiplication layer budget of the current ciphertext, a homomorphic ciphertext refresh is performed on the corresponding intermediate ciphertext within the common fixed execution trajectory. Homomorphic ciphertext refresh is a black-box refresh operation that does not depend on the ciphertext data values.
[0055] In one embodiment, such as Figure 2 As shown, the entire system consists of a private key holder and a homomorphic computation server. The private key holder holds the plaintext database, query vectors, and decryption private keys, and sets up database, query, preprocessing and encryption, decryption and post-processing, and nearest neighbor index output functions; optionally, the private key holder also forms a pre-clustered fixed-capacity layout offline before encryption and uploading.
[0056] Candidate records and query vectors in the database are preprocessed and encrypted to form database ciphertext and query ciphertext, respectively, and then sent to the homomorphic computation server. Internally, the homomorphic computation server follows a common, fixed execution trajectory independent of the ciphertext data values, sequentially performing squared distance calculation, distance expansion encoding and distance replication encoding, gap amplification ranking, and candidate extraction, generating the first k encrypted responses or encrypted locally winning records that can continue to participate in the merging process.
[0057] In the pre-clustering extension mode Figure 2 The optional extension path in the code reuses the core homomorphic processing chain for all sized candidate blocks, followed by rank-specific cryptographic cluster selector repackaging and hierarchical merging; see [link to specific steps for extension path]. Figure 7 and Figure 8 The computing server does not perform intermediate decryption during the entire online process, but only returns the encrypted result; the private key holder performs decryption, threshold detection and metadata recovery after receiving the encrypted result, and outputs the nearest neighbor record identifier.
[0058] In one embodiment, a single-candidate pool end-to-end homomorphic k-nearest neighbor retrieval is performed. This embodiment mainly describes a single-candidate pool homomorphic k-nearest neighbor sub-process. See also Figure 3 The private key holder owns the database. Query vector The process involves using a homomorphic encryption private key, calculating the received ciphertext on the server side, and performing a fixed homomorphic operation. This process can be directly applied to systems with a scale of [missing information - likely related to scale or size]. The complete database can also serve as a common subprocess for cluster representation vector pools, size-determining candidate blocks, or merge candidate pools in the pre-clustering extension described later.
[0059] Step S1: The private key holder encodes multiple candidate records into corresponding candidate slots according to the size of the public candidate pool, pads the query vector with zeros and copies it to the candidate slots, and then sends the candidate records and query vectors to the computing server after homomorphic encryption.
[0060] In this step, see Figure 4 Single-ciphertext basic layout uses There are slots. The i-th d-dimensional candidate vector. Write the first d slots of the i-th candidate slot group of length m, and set the remaining slots to zero; copy the query vector q m times after padding with zeros of the same length. The slot positions of the candidate records remain unchanged in the subsequent distance, ranking, and extraction stages, so that the decrypted target slot positions can be directly mapped to the candidate record identifiers.
[0061] The private key holder generates the encryption key, the multiplication key required for relinearization, and the rotation key corresponding to all rotation steps based on the final layout. For the pre-clustering extension implementation that requires refreshing the ciphertext, a refresh key is also generated. The computing server only holds the computing key required to execute the public circuit and does not hold the decryption private key.
[0062] Step S2: The computing server performs ciphertext subtraction and slot-by-squaring sum-of-squares rotation on the ciphertext of the candidate record and the ciphertext of the query vector to obtain the encrypted squared distance of each candidate record, and performs proportional normalization on the encrypted squared distance according to the upper bound of the public distance.
[0063] In this step, the difference between the candidate record ciphertext and the query vector ciphertext is first calculated, and then slot-by-slot squaring is performed on the difference ciphertext. For the candidate slot group length m, 1, 2, 4, ... are used sequentially. The rotation step size is used for rotation addition. Since only the first d feature slots in each candidate slot group are non-zero, the squared Euclidean distance between the corresponding candidate record and the query vector is stored at the predetermined position of each candidate slot group after reduction. The squaring operation consumes one ciphertext multiplication layer, and rotation addition does not increase the multiplication depth.
[0064] set up To provide a public upper bound for the squared Euclidean distance between candidate records in the input domain and the query vector, the th... Squared distance of candidate records Scaling to Proportional scaling does not change the distance order and makes... Located between zero and halfway. When each feature component has been normalized to zero to one and the dimension is... At that time, it can be taken In other data domains, Determined by input constraints, offline statistical boundaries, or confirmed common clipping ranges.
[0065] (1) (2) Step S3: Construct distance expansion coding and distance replication coding for the normalized encrypted squared distance, and subtract the distance expansion coding from the distance replication coding to obtain the distance difference ciphertext containing the pairwise distance differences between candidate records.
[0066] In this step, distance spread coding... Copy to the A length of Continuous slot groups; distance replication encoding converts the distance vector repeat The second time. After subtracting the two codes, the third time... The first candidate slot group Individual slots for storage ,all Paired distance differences are formed in parallel within a slot layout. The distance differences are located between -1 / 2 and -1 / 2, with smaller distances corresponding to smaller ciphertext ranks.
[0067] (3) In equation (3), For the normalized distance vector, and These represent distance extended coding and distance replication coding, respectively. Indicates slot index is The components, of which , For candidate slot group index, This is the slot group index. This formula uses slot indices starting from zero.
[0068] One specific encoding method is as follows: First, select and scale the reduced distance using a public mask that is non-zero only in the first slot of each candidate slot group. Then, replicate the distance within the group with a negative binary rotation step size to obtain the distance expansion encoding. Next, select different slots in each group using a diagonal public mask and rotate and accumulate them with a binary step size of m to obtain the distance replication encoding. This implementation trades one additional explicit-confidential multiplication layer for fewer rotations; the specific trade-off can be set based on the rotation cost and the remaining number of multiplication layers.
[0069] Step S4: Perform a gap amplification symbolic approximation on the distance difference ciphertext. The gap amplification symbolic approximation includes a near-zero amplification polynomial that maintains the positive and negative directions of the distance difference and an outer polynomial that performs a smooth saturation mapping on the amplification result.
[0070] In this step, see Figure 5 The near-zero distance difference amplification polynomial is chosen as a polynomial approximation of an odd symmetric function to maintain the positive and negative directions of the distance difference; it has a large slope near the origin to move small non-zero distance differences out of the difficult transition region of the outer saturation approximation; its output amplitude is controlled to ensure that it remains within the design range of subsequent polynomials after one or more layers are stacked.
[0071] An optional implementation method is For the objective function, construct a 13th-order Chebyshev approximation on the interval from -1 / 2 to 1 / 2. If a narrower near-zero pending interval is required, it can be used... , The stacked structure has a layered structure, where half of the interlayer is a public plaintext scaling factor. The final stage output is input to a polynomial approximation of a logic function with a kurtosis of 70 to obtain an approximate comparison result close to one, zero, or half the point of equality.
[0072] (4) (5) (6) In equations (4) to (6), The input for near-zero amplification is the pairwise normalized distance difference; the input for subsequent layers is the output of the previous layer scaled by a public factor of 0.5. Describe the objective function The thirteenth-order Chebyshev approximate polynomial; Represents a single-layer amplification function. Indicates by Composite functions formed by layer amplification This represents the comparison target after the composite function is mapped by the outer logic function. The actual ciphertext evaluation uses the corresponding polynomial approximation.
[0073] Each thirteenth-order gap-amplification polynomial can be implemented using a Chebyshev basis and a low-depth polynomial evaluation strategy, chosen between first, second, or third-order gap amplification. The outer logic function can use a 119th-order Chebyshev approximation. In a public implementation, the multiplication depths for single-layer, two-layer, and three-layer gap-amplification comparisons are 11, 15, and 19, respectively; the actual configuration is determined based on the candidate pool size, the minimum effective interval of the normalized distance, the allowed rank error, and the remaining modulus chain.
[0074] (7) In equation (7), Indicates use The multiplication depth required for a near-zero amplification sign approximation circuit. 7 represents the total depth of each near-zero amplification layer, and 7 represents the depth of the outer logic function approximation.
[0075] To avoid writing the indistinguishability of approximate comparisons near discontinuities as an absolute guarantee, the system pre-sets a near-zero undetermined half-width and a comparison saturation error. For n candidate records, the external saturation error can be selected to be less than [value missing]. To ensure that the cumulative error in the worst case is less than half a rank unit; the normalized distance interval of the top-k boundary should also be greater than the sum of the near-zero unresolved interval and the homomorphic numerical error.
[0076] (8) In equation (8), To compare the maximum permissible saturation error of the function outside the near-zero undecided interval, This represents the total number of candidate records participating in the comparison for this rank aggregation; in the case of a single candidate pool. and demand .
[0077] Step S5: The approximate comparison results are rotated and accumulated according to the candidate slot group to obtain the ciphertext rank aligned with the candidate slot position, and the ciphertext rank is approximated by a shift-rectified linear unit based on the number of nearest neighbors k to generate an encrypted top-k response.
[0078] In this step, the comparison result of the rank of the i-th candidate record being approximately 0.5 with all j not equal to i is taken. The sum. The comparison results in each candidate slot group are reduced using rotation step sizes of 1, 2, 4, ..., and the predetermined positions of the candidate slot groups are obtained within a range of approximately The ciphertext rank is determined by the distance. The smaller the distance, the smaller the ciphertext rank. Then... Centered on and Scaling maps the ciphertext rank affine to the publicly available rectified approximation input range.
[0079] (9) (10) The inflection point of the shift rectifier linear unit is set as follows: This places the first non-target ranking on one side of the inflection point, and the top-k targets on the other side; the slope can be chosen as follows. This maps the target rank closest to the inflection point to the unit order of magnitude. For a fixed m, changing k only alters the public bias; the approximate polynomial and multiplication depth remain unchanged. Since the candidate slot positions are already aligned with the record identifiers, the terminal output only needs to generate the gating values for the target slots, eliminating the need for full sorting or permutation recovery.
[0080] (11) In equations (9) to (11), The rank of the ciphertext (i.e., the rank of the first ciphertext) (approximate rank of candidate records) Its affine mapping value, This is the input to the shift rectifier function; Given the current size of the candidate pool, The number of nearest neighbors to be extracted. The slope of the linear segment. This is a shift-rectified linear unit function. Summation index. Traversing except the first Other candidate records besides the one already recorded.
[0081] In one publicly available configuration, a 13th-order shift-rectified linear unit approximation is used when the candidate pool size is no more than 128; a 27th-order approximation is used when the size is 256; a 55th-order approximation is used when the size is 512; and a 119th-order approximation is used when the size is 1024, corresponding to depths of approximately 4, 5, 6, and 7 layers, respectively. The above orders are calibration examples on a discrete-rank grid and do not constitute a necessary constraint for all input distributions.
[0082] See Figure 10 In the ranking phase public evaluation using the same encoded distance input, both the method of this embodiment and existing methods generate candidate rankings in the ciphertext domain. As the database size increases from 128 to 16384, the running time of the method of this embodiment is lower than that of existing methods at all report sizes, with speedup ratios of approximately 2 to 8 times as indicated in the figure. This figure only reflects the hardware, homomorphic parameters, and minimum distance gap configuration described in the original technical materials and does not constitute a fixed performance guarantee for other hardware, data distributions, or parameter combinations.
[0083] Step S6: The computing server returns the encrypted top-k response to the private key holder, who then decrypts it and performs threshold detection to recover the nearest neighbor record identifier based on the candidate slot position.
[0084] In this step, the server calculates the undecrypted distance, comparison result, rank, or gated output. The private key holder decrypts the final ciphertext and considers slots that reach the public detection threshold as top-k targets; one public configuration uses 0.2 as the detection threshold. If the final output also contains weights and metadata channels, zero-weight outputs are first excluded, and then the metadata is restored or normalized based on the gate value.
[0085] In one embodiment, multi-ciphertext expansion of a single candidate pool, see [link to documentation]. Figure 6 ,when When the number of available slots for a single ciphertext is greater than the number of available slots, this embodiment divides the m candidate records into... There are ciphertext partitions, where m' is the number of common candidates in each partition. Each partition independently performs distance calculation, difference coding, and local ranking as described in Example 1 to obtain the local ciphertext rank within the partition.
[0086] For each unordered partition pair, a gap-amplified sign approximation is performed only once to obtain a cross-partition comparison result in one direction. The ranking correction in the opposite direction is obtained by a complementary ranking transformation: first, the existing comparison output is accumulated by a binary step rotation, then a public mask retaining only the predetermined slots is applied, followed by replication with a rotation step size related to the partition size. Thus, a second high-cost approximation comparison is replaced with a single public mask multiplication and a logarithmic-order rotation.
[0087] Let the encryption correction count obtained from partition j on partition i be . Then, the global rank of candidate records in partition i is composed of the local rank, the correction amount from other partitions, and the common partition capacity constant. After the global rank assembly is completed, the rank normalization parameter and shift-rectified bias are determined by the total number of candidates m instead of the partition capacity m' to maintain the global top-k semantics.
[0088] (12) In equation (12), and Representing partitions The local rank and global rank vectors corresponding to each candidate. For partitioning For partitions The resulting ranking correction count vector; here This is a ciphertext partition index. For the number of partitions, The number of common candidates for each fixed-length partition.
[0089] This embodiment is used for cases where clustering is not employed but the candidate pool exceeds the capacity of a single ciphertext. For larger databases, the following pre-clustering extension can also be used to avoid global pairwise ranking among all partition pairs.
[0090] In one embodiment, large-scale homomorphic k-nearest neighbor retrieval after pre-clustering, see [link to documentation]. Figure 7 This embodiment describes how to perform large-scale homomorphic k-nearest neighbor retrieval after the database has pre-completed k-means clustering at the private key holder. Clustering is an offline preprocessing step performed by the private key holder before encryption and uploading, and is not the online homomorphic k-means calculation performed by the server. In the online phase, the server still performs a common fixed execution trajectory on the encrypted representative vector, all sized candidate blocks, and the merged candidate pool.
[0091] The private key holder obtains a capacity-constrained clustering result that has been pre-completed on a plaintext database, the clustering result containing... Cluster and its cluster representative vector Assume the database size is... The common capacity relaxation parameter is Then the maximum public capacity of each cluster is Each cluster is filled to the common capacity. And split into There are 100 candidate blocks for sizing, among which This represents the public block capacity supported by the single-candidate pool process. This embodiment uses the pre-clustered layout as the input to the private key holder before encrypted upload, without limiting capacity conflict allocation, centroid updates, or stopping conditions.
[0092] (13) In equation (13), Indicates the first Clusters, The number of valid records. The total number of records in the database. For the number of clusters, For common capacity relaxation parameters, The maximum public capacity per cluster, For each public capacity, The number of candidate blocks per cluster with fixed capacity. This indicates rounding up to the nearest integer.
[0093] Each uploaded record must contain at least an encrypted feature channel, an encrypted validity or weight channel, and an encrypted record identifier metadata channel. The weight of a valid record can be set to one, while the weight and metadata of an invalid record are set to zero. This is based on the already calculated normalized distance. The records can be used to construct a combined score. This ensures that closer, valid records receive higher scores, while invalid padding records do not gain a positive score advantage. If a valid record is located exactly at the public furthest distance boundary and is tied with the padding record, there may ultimately be fewer than k positive weight outputs, and the private key holder should discard the zero-weight record.
[0094] (14) In equation (14), For the first The validity weight of each record. The combined score for this record. For the first The score of each record minus the first The difference between the scores of each record.
[0095] The computing server first reuses the distance calculation, difference encoding, and gap amplification ranking from Example 1 on a candidate pool composed of encrypted cluster representative vectors. For the cluster representative ranking... Generate a set of rank-specific encryption cluster selectors based on the rank of the ciphertext. . Approximate representation of the first Is the cluster located at the ? Each selected cluster represents a ranking, but the identifier of the selected cluster is always kept encrypted.
[0096] The computation server then performs a local homomorphic nearest neighbor search on all cL sized candidate blocks, instead of processing only the clusters indicated by the representative selector. All candidate blocks undergo the same public operation sequence, the same number of approximate comparisons, and the same output shape, ensuring that the computational control flow does not reveal the selected cluster, the actual number of valid records, or the intra-block winner.
[0097] For each cluster Candidate blocks and local rankings The computing server generates encrypted local winning records. See also Figure 8 First, construct the first rank based on the ciphertext. The encrypted prefix indicator of the name ;make , season , then calculate To reduce non-target residuals. After squared cleanup The gating score, weight, and record identifier metadata are summed along the candidate slot dimension to obtain an encrypted record that can continue to participate in the merging process, instead of just obtaining a mask.
[0098] (15) (16) In equations (15) and (16), For local winning rankings, the value ranges from 1 to... ; Indicates the first Is the record located before the local record? The encrypted prefix indicating the name, It represents the ranking selection quantity after the adjacent prefix difference is squared and cleaned. For the first The identifier metadata of each candidate record, The first result obtained by gating summation Name output metadata channel value; and These represent the score channel value and weight channel value for the corresponding output. (Sum index) Iterate through the records in the current candidate block.
[0099] For clusters representing rankings Candidate blocks and local rankings Calculation on the server side: (17) The same multiply-add structure is applied to the score, weight, and metadata channels, respectively. This selector repackages the local winning records of the selected clusters in the ciphertext domain. The computation server neither decrypts the representative selection results nor performs plaintext routing based on the representative selection results. In equation (17), For cluster index, Number the candidate blocks within the cluster. For the winning ranking within the block, This is the rank index representing the selected cluster. Indicates the first Is the cluster located at the ? The number of encrypted selections for each selected rank. For the first The first cluster The first block Named encrypted partial winning record This is a repacked record after gating and summing along the cluster dimension; The selected cluster represents the number of clusters. This place The index is used for ranking, and the magnification level in equation (5) is distinguished according to the formula in which it is located.
[0100] Each cluster represents a ranking. The Lk repackaging records generated from the L candidate blocks are merged into a cluster-level top-k list. When Lk does not exceed the capacity of a single candidate pool, a single candidate pool ranking and extraction can be performed; when Lk exceeds the capacity of the candidate pool, hierarchical merging is performed according to a public tree structure determined only by L, k, and B. After merging the block winners representing the rankings of each cluster, a maximum of rk cluster-level candidate records are obtained. Then, a final cross-cluster merging is performed to obtain the globally encrypted top-k records.
[0101] The accuracy of pre-cluster expansion depends on the number of selected clusters, *r*, and the data distribution. *r* is a publicly available tradeoff parameter between accuracy and latency, calibrated via offline representative coverage scans or validation sets, but a given *r* configuration cannot be used as a recall guarantee for arbitrary data distributions. To calibrate selector repackaging errors, assume that the absolute value of each record's scalar channel does not exceed *R*, and that the residuals of the unselected selectors and the bias of the selected selectors both do not exceed *R*. Local extraction perturbation does not exceed Homomorphic numerical error does not exceed ; If it may affect the plaintext boundary score interval of the top-k list. satisfy The corresponding boundary comparison direction remains unchanged under this configuration.
[0102] (18) In equation (18), To influence the plaintext boundary score interval of the final nearest neighbor selection, To extract the upper bound of the perturbation locally, This is the upper bound of the cluster selector error. The upper bound of the absolute value of the scalar channel for each record. For the number of clusters, This is the upper bound of the homomorphic numerical error.
[0103] When the multi-stage homomorphic computation of the pre-clustering extension exhausts the multiplication layer budget of the current ciphertext, CKKS homomorphic ciphertext refresh can be invoked as a black-box refresh operation within a common fixed execution trajectory. The paper does not disclose universally applicable precise insertion positions, refresh output scales, or refreshed layer numbers; therefore, this embodiment does not impose unfounded limitations on these parameters.
[0104] In a publicly available evaluation configuration, the parameter combination is as follows: ; The number of ciphertext-level gap symbol calls for direct global block ranking is 2080, while the corresponding number of calls for pre-clustering expansion is 152, a reduction of approximately 13.7 times. This statistic does not include terminal shift rectification extraction. These figures only illustrate the technical effect under a specific publicly available configuration and do not constitute a fixed multiple guarantee for other data sizes, hardware, or parameters.
[0105] In publicly available SIFT feature validation configurations, pre-clustering expansion achieved 100% precision and recall across reported database sizes ranging from 1024 to 131072 and top-8 parameter combinations; the used The number of representative coverages observed in the corresponding offline scans is not less than the number of coverages observed in the scans. This result reflects the implementation effects of the specified data subset, query, clustering layout, and common parameters, and cannot be interpreted as a guarantee of distribution independence.
[0106] In one embodiment, the homomorphic encryption parameters, number of layers, and computation key configuration are implemented using RNS-CKKS, which supports near-real number single instruction multiple data operations. A ciphertext with a ring dimension of N can provide at most... A complex number of slots. The candidate pool is considered when selecting N. Slot layout, gap amplification and multiplication depth of shift rectifier polynomials, key switching auxiliary modulus, target security level, and whether homomorphic ciphertext refresh is used.
[0107] One public implementation uses CKKS parameters with a 128-bit security level; it takes into account configurations with sufficient depth and slot budget. In configurations requiring deeper circuitry or a single ciphertext layout of 256 records, take The above N values are implementation examples. The actual prime number chain, working scale, special auxiliary modulus, and refresh level budget should be determined jointly by the target accuracy, circuit depth, and security estimates, and should not be increased without constraints by simply adding layers at a fixed N.
[0108] Existing technologies publicly implement RNS-CKKS and OpenFHE. Each ciphertext-to-ciphertext multiplication is counted in a multiplication layer, and rescaling is performed after the multiplication. The implementation employs an improved rescaling method and a hybrid key switching with double boosting to reduce scale management and key switching overhead in deep circuits. The complete prime chain, working scale, special auxiliary modulus, and refresh layer budget are still jointly determined by the target accuracy, circuit depth, and security estimation. This embodiment does not fabricate values not disclosed in the paper.
[0109] The rotation computation key is derived from the final slot layout. At a minimum, positive binary rotations with distance reduction, negative binary rotations with distance extension coding, candidate slot group length multiple rotations with distance replication coding, and rank aggregation rotations are used; extract and replication rotations required for complementary rank transformations are also used. The absence of a computation key corresponding to any actual rotation step size will prevent the corresponding slot transformation from being executed; the computation key required for optional homomorphic ciphertext refresh is generated according to the refresh interface of the homomorphic library used.
[0110] In one optional verification method, the decryption result is compared slot-by-slot with the plaintext reference result under the same input, with a focus on checking the distance normalization range, near-zero comparison unresolved intervals, ciphertext rank error, selector residual, repackaging error, and final top-k boundary. Final decryption is performed locally only on the private key holder who simultaneously possesses both the database and the query.
[0111] In one embodiment, the system is deployed, see [link to documentation]. Figure 9This embodiment introduces a homomorphic k-nearest neighbor retrieval system based on gap amplification sorting and pre-clustering fixed-capacity scheduling. The parameter and key module, as well as the preprocessing and encryption module, are deployed on the private key holder. The ciphertext distance module, ciphertext difference encoding and ranking module, candidate extraction module, clustering scheduling and repackaging module, and hierarchical merging module are deployed on the computing server. The result decryption module is deployed on the private key holder. Each module can be carried by different program units on the same electronic device, or can be deployed separately on devices connected via a network.
[0112] The parameter and key module sets the homomorphic encryption context based on the candidate pool size, approximate comparison depth, target precision, and security level, and generates encryption keys, decryption keys, multiplication calculation keys, rotation calculation keys, and optional refresh calculation keys. The preprocessing and encryption module constructs a single-candidate pool slot layout in single-candidate pool mode, and obtains the already formed pre-clustered fixed-capacity layout in pre-clustering expansion mode, completing fixed-capacity filling and block division, and encrypting candidate records, cluster representation vectors, query vectors, and multi-channel metadata.
[0113] The ciphertext distance module performs ciphertext difference, slot-by-slot squaring, rotation reduction, and public upper bound normalization. The ciphertext difference encoding and ranking module constructs distance extension encoding and distance replication encoding, performs gap amplification sign approximation on paired distance differences, and aggregates ciphertext ranks according to candidate slot groups. The candidate extraction module performs shift-rectified linear unit approximation top-k gating in direct or final merging mode, and generates encrypted local winning records that can be further merged in local block mode.
[0114] The clustering scheduling and repackaging module generates a rank-specific encrypted cluster selector on the cluster representative vector pool, triggers the same common fixed execution trajectory for all sized candidate blocks, and performs channel-by-channel multiplication and addition on the rank-specific encrypted cluster selector and the encrypted local winning record. The hierarchical merging module performs intra-cluster block merging and cross-cluster final merging according to the capacity of the common candidate pool; when the multi-stage homomorphic computation exhausts the multiplication layer budget of the current ciphertext, black-box homomorphic ciphertext refresh can be called in the common fixed execution trajectory. The result decryption module only decrypts the final gated record, excludes invalid padding by weight or output mask threshold, and restores the record identifier.
[0115] In the semi-honest computing server model, online visible information includes public homomorphic encryption parameters, candidate pool shape, ciphertext size, and in pre-clustering extension , , , , and The layout parameters are publicly available. The computing server does not obtain the plaintext database, query vector, distance, ciphertext rank, cluster identifier, local winner, or final record identifier. This embodiment does not advocate malicious security, output integrity, or circuit privacy; if these properties are required, appropriate protocols should be added outside this system.
[0116] It should be understood that, although Figures 1-3 , Figure 7 The steps in the flowchart are shown sequentially as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order in which these steps are executed, and they can be performed in other orders. Figures 1-3 , Figure 7 At least some of the steps in the process may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily completed at the same time, but can be executed at different times. The execution order of these sub-steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least some of the sub-steps or stages of other steps.
[0117] In one embodiment, such as Figure 11 As shown, a homomorphic k-nearest neighbor retrieval device based on gap amplification sorting is provided, comprising: a private key holding terminal device 1102 and a computing server device 1104, wherein: The private key holder device 1102 includes a parameter and key module, a preprocessing and encryption module, and a result decryption module.
[0118] The computing server device 1104 includes a ciphertext distance module, a ciphertext difference encoding and ranking module, and a candidate extraction module.
[0119] The Cipher Distance module is used to perform ciphertext subtraction between the ciphertext of the candidate record and the ciphertext of the query vector, slot-by-slot square sum rotation accumulation, and output the encrypted square distance.
[0120] The ciphertext difference encoding and ranking module receives the encrypted squared distance, performs normalization, distance expansion encoding and distance replication encoding construction, gap amplification symbol approximation and ciphertext rank aggregation, and outputs the ciphertext rank value.
[0121] The candidate extraction module is used to receive the ciphertext rank value, perform a shift-rectified linear unit approximation, and output an encrypted gating response.
[0122] When the computing server operates in single candidate pool mode, the candidate extraction module outputs an encrypted top-k response. When operating in pre-clustering expansion mode, it also generates a globally encrypted top-k record through the clustering scheduling and repackaging module and the hierarchical merging module.
[0123] Specific limitations regarding the homomorphic k-nearest neighbor retrieval device based on gap amplification sorting can be found in the limitations of the homomorphic k-nearest neighbor retrieval method based on gap amplification sorting mentioned above, and will not be repeated here. Each module in the aforementioned homomorphic k-nearest neighbor retrieval device based on gap amplification sorting can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0124] In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as follows: Figure 12 As shown, the computer device includes a processor, memory, network interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The network interface is used to communicate with external terminals via a network connection. When executed by the processor, the computer program implements a homomorphic k-nearest neighbor retrieval method based on gap amplification sorting. The display screen can be a liquid crystal display (LCD) or an e-ink display. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad mounted on the computer device casing, or an external keyboard, touchpad, or mouse.
[0125] Those skilled in the art will understand that Figures 11-12 The structure shown is merely a block diagram of a portion of the structure related to the present application and does not constitute a limitation on the computer device to which the present application is applied. Specific computer devices may include more or fewer components than those shown in the figure, or combine certain components, or have different component arrangements.
[0126] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, the processor executing the computer program to perform the following steps: Based on the size of the public candidate pool, the private key holder encodes multiple candidate records into their respective candidate slots, pads the query vector with zeros and copies it to each candidate slot, performs homomorphic encryption on the encoded candidate records and query vectors, and sends the encrypted candidate record ciphertext and query vector ciphertext to the computing server.
[0127] The computing server receives the candidate record ciphertext and the query vector ciphertext, performs ciphertext subtraction on the candidate record ciphertext and the query vector ciphertext in the same candidate slot group to obtain the difference ciphertext, performs slot-by-slot squaring operation on the difference ciphertext to obtain the square distance ciphertext, and performs rotation accumulation on the square distance ciphertext according to the candidate slot group to obtain the encrypted square distance of each candidate record.
[0128] The computing server uses the encrypted squared distance as input and performs normalization processing on each encrypted squared distance according to the upper bound of the public distance. For each normalized encrypted squared distance, a distance expansion code and a distance replication code are constructed respectively. The distance expansion code and the distance replication code are then subjected to ciphertext subtraction to obtain the distance difference ciphertext containing the pairwise normalized distance difference between candidate records.
[0129] The computing server takes the distance difference ciphertext as input and performs gap amplification symbolic approximation on the distance difference ciphertext. The gap amplification symbolic approximation first maintains the positive and negative directions of the distance difference and amplifies the near-zero distance difference by a near-zero amplification polynomial. Then, the outer polynomial performs smooth saturation mapping on the amplification result to obtain the approximate comparison result ciphertext of the size relationship between candidate records.
[0130] The computing server takes the ciphertext of the approximate comparison result as input, performs rotation accumulation on the ciphertext of the approximate comparison result according to the candidate slot group, obtains the ciphertext rank value corresponding to each candidate record, and after affine mapping the ciphertext rank value to the public rank domain, performs shift rectified linear unit approximation on the ciphertext rank value in the public rank domain according to the number of nearest neighbors k, so as to extract the encryption gating response corresponding to the top k candidate records.
[0131] The computing server returns the encrypted gating response to the private key holder. After decryption, the private key holder performs a threshold test on the decrypted value and obtains the nearest neighbor record identifier based on the candidate slot position mapping that passes the threshold test.
[0132] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAM bus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0133] The technical features of the above embodiments can be combined in any way. For the sake of brevity, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0134] The embodiments described above are merely illustrative of several implementation methods of this application, and while the descriptions are specific and detailed, they should not be construed as limiting the scope of the invention. It should be noted that those skilled in the art can make various modifications and improvements without departing from the concept of this application, and these all fall within the protection scope of this application. Therefore, the protection scope of this application should be determined by the appended claims.
Claims
1. A homomorphic k-nearest neighbor retrieval method based on gap amplification sorting, characterized in that, The method includes: Based on the size of the public candidate pool, the private key holder encodes multiple candidate records into corresponding candidate slots, pads the query vector with zeros and copies it to each candidate slot, performs homomorphic encryption on the encoded candidate records and the query vector, and sends the encrypted candidate record ciphertext and query vector ciphertext to the computing server. The computing server receives the candidate record ciphertext and the query vector ciphertext, performs ciphertext subtraction on the candidate record ciphertext and the query vector ciphertext in the same candidate slot group to obtain the difference ciphertext, performs slot-by-slot squaring operation on the difference ciphertext to obtain the square distance ciphertext, and performs rotation accumulation on the square distance ciphertext according to the candidate slot group to obtain the encrypted square distance of each candidate record. The computing server takes the encrypted squared distance as input and performs normalization processing on each encrypted squared distance according to the public distance upper bound. It constructs distance expansion code and distance replication code for each normalized encrypted squared distance, and performs ciphertext subtraction on the distance expansion code and the distance replication code to obtain distance difference ciphertext containing the pairwise normalized distance difference between candidate records. The computing server takes the distance difference ciphertext as input and performs gap amplification symbolic approximation on the distance difference ciphertext. The gap amplification symbolic approximation first maintains the positive and negative directions of the distance difference and amplifies the near-zero distance difference by a near-zero amplification polynomial, and then performs smooth saturation mapping on the amplification result by an outer polynomial to obtain the approximate comparison result ciphertext of the size relationship between candidate records. The computing server takes the ciphertext of the approximate comparison result as input, performs rotation accumulation on the ciphertext of the approximate comparison result according to the candidate slot group to obtain the ciphertext rank value corresponding to each candidate record, and after affine mapping the ciphertext rank value to the public rank domain, performs shift rectified linear unit approximation on the ciphertext rank value in the public rank domain according to the number of nearest neighbors k, so as to extract the encryption gating response corresponding to the top k candidate records. The computing server returns the encrypted gating response to the private key holder. After decryption, the private key holder performs a threshold test on the decrypted value and obtains the nearest neighbor record identifier based on the candidate slot position that passes the threshold test.
2. The method according to claim 1, characterized in that, During the period from receiving the input ciphertext to returning the encrypted gating response, the computing server performs all operations according to a common fixed execution trajectory that is independent of the value of the ciphertext data. The common fixed execution trajectory is determined by the candidate pool size, feature dimension, candidate slot group layout and the number of nearest neighbors k, and the computing server does not perform intermediate decryption during the entire execution period. The homomorphic encryption is a ring-based homomorphic encryption that supports near-real number single-instruction multiple-data operations. When the computing server executes the common fixed execution trajectory, it uses the multiplication calculation key and the rotation calculation key corresponding to the candidate slot group layout.
3. The method according to claim 1, characterized in that, The public candidate pool contains m candidate records. Each candidate slot group contains m slots. The feature dimension d of the candidate record satisfies d≤m. The d feature components of the i-th candidate record occupy the first d slots in the i-th candidate slot group, and the remaining slots are set to zero. The rotation accumulation uses a rotation step size. Perform a rotation addition on the squared distance ciphertext, where, This ensures that the first slot of each candidate slot group converges the squared distance between the current candidate record and the query vector. The distance expansion encoding copies the i-th normalized encrypted squared distance to all m slots of the i-th candidate slot group. The distance copy encoding repeats the complete distance vector composed of the m normalized encrypted squared distances m times, so that the j-th slot in the i-th candidate slot group stores the distance value of the j-th candidate record.
4. The method according to claim 3, characterized in that, Normalization is performed on each encrypted squared distance based on the upper bound of the public distance, including: Obtain the upper bound of the public distance, and normalize each encrypted squared distance based on the squared Euclidean distance between the current candidate record and the query vector to obtain the normalized encrypted squared distance: ; in, The normalized encrypted squared distance. To make the upper limit of the public distance, For query vector, Candidate records; among them, This represents the squared Euclidean distance between the candidate vector and the query vector. Indicates the candidate record index; Obtain any pairwise normalized distance difference based on the normalized encrypted squared distance: ; in, For pairwise normalized distance difference, , These are the normalized encrypted squared distances corresponding to two different candidate records, with the smaller normalized encrypted squared distance corresponding to the smaller ciphertext rank value.
5. The method according to claim 4, characterized in that, The near-zero distance difference amplification polynomial is an odd symmetric polynomial, corresponding to a slope near the origin that is greater than the slope far from the origin and a bounded output amplitude. Within the range of values for the pairwise normalized distance difference, the following objective function is approximated by a thirteenth-order Chebyshev approximation to obtain the near-zero amplified polynomial of the distance difference: ; in, To construct the objective function of a near-zero distance difference amplification polynomial, The input is the pairwise normalized distance difference for near-zero amplification operations, with a value ranging from -1 / 2 to 1 / 2; Near-zero amplification is performed on the paired normalized distance differences, shifting the near-zero distance differences that determine the adjacent rankings out of the saturation interval of the outer function. A smooth saturation mapping is then performed using a 119th-order polynomial approximation of a logic function with a kurtosis of 70, mapping the amplified distance differences to a bounded interval centered at half the circumference, resulting in an approximate comparison result ciphertext. ; in, The ciphertext is an approximate comparison result. The output of the function is the result of near-zero amplification through the corresponding number of layers. In actual homomorphic operations, each layer is approximated using the polynomials described above. For a logic function with a kurtosis of 70, the subscript... This represents the number of near-zero magnification layers, and is a positive integer. 70 represents the natural constant, and 70 is the kurtosis parameter of the logic function.
6. The method according to claim 5, characterized in that, After affinely mapping the ciphertext rank value to the public rank domain, a shift-rectified linear unit approximation is performed on the ciphertext rank value in the public rank domain based on the nearest neighbor number k, including: The ciphertext of all approximate comparison results except for the self-comparison term in each candidate slot group is rotated and accumulated to obtain the ciphertext rank value of each candidate record. Half of the self-comparison term is used as the reference bias so that the candidate record with smaller distance has a smaller ciphertext rank value. The ciphertext rank is then subjected to an affine mapping, mapping it to the publicly available rectified approximation input domain, to obtain the mapped value: ; in, The rank of the ciphertext. For mapping values, This represents the number of candidate records in the current candidate pool. Inflection point And the slope is The shift-rectified linear unit performs an approximation on the mapped value, such that the change in the number of nearest neighbors k under a fixed candidate pool size m only changes the public bias without increasing the multiplication depth of the extraction circuit, generating an encrypted top-k gated response.
7. The method according to claim 5, characterized in that, When the square of the total number of candidate records is greater than half the ring dimension, the candidate records of the total number of candidate records are divided into fixed-length ciphertext partitions: ; in, The number of fixed-length ciphertext partitions, This represents the number of candidate records in the current candidate pool. The number of common candidates for each partition; Calculate the local ciphertext rank value within each ciphertext partition, and perform a packing gap amplification symbol approximation for each unordered ciphertext partition. Derive the ranking correction amount in the opposite direction from the approximation output in one direction by rotation, public masking, and copying. Combine the local ciphertext rank value with the ranking correction amount from other ciphertext partitions to form the global ciphertext rank value, and perform the operation based on the total number of candidate records.
8. The method according to claim 1, characterized in that, In the pre-clustered fixed-capacity scheduling mode, the method includes: The private key holder obtains c pre-divided plaintext database clusters, cluster representative vectors for each cluster, and fixed capacity layouts that satisfy the common capacity constraints of each cluster. It fills each cluster into the common capacity and splits it into fixed-capacity candidate blocks. After encoding and homomorphically encrypting the cluster representative vectors, all fixed-capacity candidate blocks, query vectors, validity weight channels, and record identifier metadata channels, it sends them to the computing server. The computing server receives the encrypted cluster representative vector ciphertext, and performs the calculation of the encrypted squared distance, the encoding of the pairwise distance difference, the gap amplification symbol approximation, and the ciphertext rank aggregation operation on the cluster representative vector pool composed of the cluster representative vector ciphertext, to generate r sets of rank-specific encrypted cluster selectors. The rank-specific encrypted cluster selectors identify the clusters corresponding to each rank in the ciphertext domain. The computing server takes all the size-fixed candidate blocks as input and executes a common fixed execution trajectory on all the size-fixed candidate blocks, which is independent of the ciphertext value of the rank-specific encryption cluster selector, to obtain the encryption local winning record of each size-fixed candidate block. The encryption local winning record includes a score channel, a validity weight channel, and a record identifier metadata channel. The computing server performs ciphertext multiplication on each rank-specific encryption cluster selector and the corresponding local encryption winner record of the cluster channel by channel and performs homomorphic summation along the cluster dimension. It merges the block winner records under the same cluster representative rank and then performs the final merge on the cluster-level candidates under different cluster representative rank to obtain the global encryption top-k records. The computing server returns the globally encrypted top-k record to the private key holder, who then decrypts it, excludes zero-weight outputs, and restores the nearest neighbor record identifier.
9. A homomorphic k-nearest neighbor retrieval device based on gap amplification sorting, characterized in that, The apparatus includes a private key holder device and a computing server device, and the apparatus includes: The private key holding device includes a parameter and key module, a preprocessing and encryption module, and a result decryption module; The computing server device includes a ciphertext distance module, a ciphertext difference encoding and ranking module, and a candidate extraction module; The ciphertext distance module is used to perform ciphertext subtraction between the candidate record ciphertext and the query vector ciphertext, slot-by-slot square sum rotation accumulation, and output the encrypted square distance; The ciphertext difference encoding and ranking module is used to receive the encrypted squared distance, perform normalization, distance expansion encoding and distance replication encoding construction, gap amplification symbol approximation and ciphertext rank aggregation, and output the ciphertext rank value; The candidate extraction module is used to receive the ciphertext rank value, perform a shift-rectified linear unit approximation, and output an encryption gating response; When the computing server operates in single candidate pool mode, the candidate extraction module outputs an encrypted top-k response. When operating in pre-clustering expansion mode, it also generates a global encrypted top-k record through the clustering scheduling and repackaging module and the hierarchical merging module.
10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 8.
