Method and device for optimizing data query based on quantum technology and medium
By optimizing data query through quantum computing, quantum principal component analysis and quantum K-means clustering algorithms are used to extract the dominant feature vector of user query, generate a preloaded dataset and optimize cache management. This solves the problems of insufficient prediction and computational efficiency bottleneck of traditional LRU algorithm in complex query mode, and realizes efficient and real-time data query.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-21
- Publication Date
- 2026-03-13
AI Technical Summary
Traditional LRU caching algorithms rely on historical access time information and fail to delve into the deep semantic features of user query behavior, resulting in insufficient predictive ability under complex query patterns. Furthermore, machine learning enhancement solutions suffer from significant computational efficiency bottlenecks in large-scale data scenarios, making it difficult to meet real-time requirements.
Using quantum computing technology, quantum principal component analysis and quantum K-means clustering algorithms are used to extract the dominant feature vectors of user query data, generate a preloaded dataset, and load it into an LRU cache list based on similarity order. Combined with a dynamic scoring model, cache management is optimized.
It significantly improves the response speed and hit rate of data queries, solves the computational pressure of feature extraction and similarity matching for high-dimensional data, and achieves a balance between real-time performance and accuracy.
Smart Images

Figure CN121658692A_ABST
Abstract
Description
Technical Field
[0001] The application generally relates to the field of database technology, and in particular to a method, device and medium for optimizing data query based on quantum technology. Background Technology
[0002] In database management systems, data query efficiency is one of the core performance indicators. To bridge the speed gap between memory and external storage, caching technology is widely used. The key lies in how to efficiently manage limited memory space and pre-store the data most likely to be accessed, thereby improving the hit rate of data queries.
[0003] Among numerous cache replacement algorithms, the Least Recently Used (LRU) algorithm is a classic and commonly used strategy. The core idea of the LRU algorithm is that "data that has been recently accessed is more likely to be accessed again in the future." It typically uses a linked list structure to maintain the data items in the cache: when data is accessed, it is moved to the head of the list, indicating that it is "recently used"; and when cache space is insufficient, the "least recently used" data is evicted from the tail of the list. This strategy based on temporal locality is simple to implement and highly effective in certain scenarios.
[0004] However, traditional LRU algorithms primarily rely on historical access time information, failing to delve into the semantic features behind access behavior. Therefore, they exhibit insufficient predictive ability when dealing with complex and ever-changing query patterns. To make them more intelligent, existing technologies have proposed combining machine learning with LRU. The basic principle of this approach is: analyze user query content and records over a period of time to extract their textual features; then, based on these features, cluster and filter a batch of semantically similar data from the database, and preload them into the LRU list according to their similarity to the core features. This is equivalent to a "smart preheating" of the cache, ensuring it includes not only recently accessed data but also data predicted to be accessed based on user interests. Subsequently, the system dynamically adjusts the position of data or determines its retention or removal based on the actual frequency of data usage in the list.
[0005] While the aforementioned machine learning enhancement schemes have improved the accuracy of data pre-selection, their computational bottlenecks have become increasingly apparent with the explosive growth of data volume. On the one hand, the computational cost of extracting high-dimensional features from massive amounts of text is enormous; on the other hand, performing large-scale similarity matching and clustering analysis in high-dimensional space poses a severe performance challenge to traditional computing architectures. These factors can lead to significant delays in the data preprocessing stage, thereby diminishing the overall benefits of caching optimization.
[0006] Against this backdrop, quantum computing technology has demonstrated its potential to solve this problem. The parallel processing capabilities and acceleration effect of quantum computing on complex algorithms offer a new technological approach for solving high-dimensional data feature extraction and rapid similarity matching. Considering the use of quantum computing to accelerate key steps in feature extraction and similar data retrieval, thereby enabling the entire intelligent data query system to achieve unprecedented processing speed while maintaining predictive accuracy, has become a promising research direction. Summary of the Invention
[0007] This disclosure addresses some of the shortcomings mentioned in the background art by providing a method, device, and medium for optimizing data querying based on quantum technology.
[0008] In a first aspect, embodiments of this disclosure provide a method for optimizing data querying based on quantum technology, comprising the following steps: S1. Collect the user's query text data at the current time and within the historical time window, and construct a bag-of-words model after preprocessing the query text data; S2. Encode the feature vectors in the bag-of-words model using quantum states, and extract the dominant feature vectors of the query text data using a quantum principal component analysis algorithm; S3. Based on the dominant feature vector, retrieve multiple data items from the target database that satisfy the similarity condition with the dominant feature vector, and generate a preloaded dataset; S4. Load the preloaded dataset into the head position of the LRU cache list according to the similarity order with the dominant feature vector.
[0009] In one embodiment of the first aspect, Step S1 involves preprocessing the query text data and then constructing a bag-of-words model, including: The collected query text data is segmented and stop word filtered to create a feature vocabulary. A single query text is represented as a feature vector based on the feature vocabulary, where the values of each dimension of the vector represent the frequency of occurrence of the corresponding word in the query text. Different weight coefficients are assigned to the feature vectors of the current query text and the historical query text, with the weight coefficient of the current query text being higher than that of the historical query text.
[0010] In one embodiment of the first aspect, step S2, which involves extracting the dominant feature vector of the query text data using a quantum principal component analysis algorithm, includes: The covariance matrix of the sample matrix corresponding to the bag-of-words model is converted into a density operator; The eigenvalues and eigenvectors of the density operator are solved using a quantum phase estimation algorithm. The top K feature vectors with the highest probability measurement values are selected as the dominant feature vectors, where K is a preset positive integer.
[0011] In one embodiment of the first aspect, step S3 retrieves multiple data items from the target database that satisfy the similarity condition with the dominant feature vector, generating a preloaded dataset, including: S31. Convert the text data in the target database into feature vectors according to the same feature vocabulary as the bag-of-words model; S32. The feature vectors are clustered using the quantum K-means clustering algorithm to obtain multiple data clusters; S33. Calculate the similarity distance between the centroid vector of each data cluster and the dominant feature vector; S34. Select the top T data items from the data cluster with the smallest similarity distance to form the preloaded dataset, where T is a preset positive integer.
[0012] In one embodiment of the first aspect, step S32 employs a quantum K-means clustering algorithm to cluster the feature vectors, obtaining multiple data clusters, including: S321. Configure three registers on the quantum circuit to store the sample vector of the data to be tested, the centroid eigenvector, and the fidelity measurement result, respectively. S322. Calculate the fidelity between the data sample and each centroid through quantum exchange testing; S323. Based on the fidelity measurement results, divide the data samples into the data clusters with the highest fidelity. S324. Iteratively update the centroid position until the preset convergence condition is met.
[0013] In one embodiment of the first aspect, step S4, loading the preloaded dataset into the head position of the LRU cache list according to its similarity to the dominant feature vector, includes: Based on the similarity between the data items and the dominant feature vector, from high to low, the data items are inserted into the head of the LRU cache list in sequence. Add metadata including the loading timestamp and initial similarity score to each newly loaded data item.
[0014] In one embodiment of the first aspect, the method further includes: Monitor the access timestamps and access frequency of data items stored in the LRU cache list; Establish a comprehensive scoring model based on time decay and access frequency; When cache space is insufficient, the data item with the lowest overall score will be evicted first.
[0015] In one embodiment of the first aspect, the method further includes: Monitor the scale of data processing and the status of computing resources; When quantum computing resources are detected to be unavailable or the amount of data to be processed is lower than a preset threshold, the algorithm switches to classical principal component analysis and classical K-means clustering to perform the corresponding computational tasks.
[0016] In a second aspect, embodiments of this disclosure provide an electronic device including a memory and a processor, wherein the memory stores a program that runs on the processor, and the processor, when running the program, performs the steps of the quantum technology-based optimized data query method described in the first aspect. In a third aspect, embodiments of this disclosure provide a computer-readable storage medium having computer instructions stored thereon, which, when executed, perform the steps of the method for optimizing data querying based on quantum technology as described in the first aspect.
[0017] This disclosure proposes a method, device, and medium for optimizing data querying based on quantum technology, which has the following beneficial effects: (1) To solve the bottleneck of computational efficiency, quantum principal component analysis (QPCA) and quantum K-means clustering algorithm are adopted. By utilizing the characteristics of quantum parallel computing, the high-dimensional matrix operation and similarity calculation are accelerated, which significantly reduces the time complexity of feature extraction and data analysis and enables real-time processing of large-scale data query optimization tasks.
[0018] (2) A quantum-classical collaborative processing mechanism is adopted to automatically switch the processing mode according to the data scale and resource availability. This can give full play to the advantages of quantum computing when resources are sufficient, and ensure the basic functions of the system when resources are limited, thereby improving the robustness and practical value of the system.
[0019] (3) The overall technical solution optimizes the entire process from feature extraction to cache management. It significantly shortens the query response time, provides a smoother data query experience, and meets the needs of application scenarios with high real-time requirements. Attached Figure Description
[0020] Figure 1 This is a flowchart illustrating a method for optimizing data querying based on quantum technology. Figure 2 This is a schematic diagram of the quantum circuit for quantum principal component analysis according to an embodiment of this disclosure. Detailed Implementation
[0021] The present application / disclosure will now be described in further detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application / disclosure and are not intended to limit the scope of the present application / disclosure. Furthermore, it should be noted that, for ease of description, only the parts relevant to the present application / disclosure are shown in the accompanying drawings, not the entire structure.
[0022] In the field of database system performance optimization, improving data query efficiency has always been one of the core research topics. Among them, the cache management mechanism based on the LRU (Least Recently Used) algorithm is widely used due to its simplicity and low overhead. The traditional LRU algorithm manages cached pages by maintaining a linked list structure sorted by access time, placing the most recently accessed page at the front of the list, while the least recently used page is gradually moved to the end and evicted when space is needed. Although this design based on the principle of temporal locality optimizes the data exchange efficiency between memory and secondary storage to a certain extent, it is essentially a passive response mechanism and fails to fully consider the deep semantic features contained in user query behavior.
[0023] With the development of machine learning technology, existing technologies are beginning to explore the integration of intelligent prediction mechanisms into LRU cache management. These improved solutions draw on the design principles of recommender systems, analyzing user historical query records to construct a bag-of-words model to extract feature patterns from query text, and then retrieving semantically similar data items from the database and preloading them into the cache based on these features. This approach transforms the LRU linked list from a decision mechanism solely reliant on timestamps into an intelligent prediction system based on content similarity, improving cache hit rates to some extent. However, when facing large-scale data scenarios, traditional machine learning methods face significant computational efficiency bottlenecks in feature extraction and similarity calculation. Operations such as feature dimensionality reduction of high-dimensional text data and cluster analysis of massive datasets consume substantial computational resources, leading to increased system response latency and making it difficult to meet the real-time requirements of application scenarios.
[0024] To overcome the aforementioned technical bottlenecks, this disclosure proposes using quantum computing technology to optimize the feature extraction process. Specifically, it utilizes quantum principal component analysis (QPC) algorithms to reduce the dimensionality of user query data, accelerating the eigenvalue decomposition of the covariance matrix through the parallel processing capabilities of quantum states. The unique advantage of quantum computing lies in its ability to leverage quantum superposition and entanglement to achieve exponentially faster computations on high-dimensional matrices. This quantum-based processing effectively addresses the computational pressure faced by traditional computers when processing large-scale, high-dimensional data, significantly improving the efficiency and stability of feature extraction, thus providing a new technical path for building more intelligent and efficient data query optimization systems.
[0025] Example 1 Figure 1 is a flowchart of a method for optimizing data query based on quantum technology according to the present disclosure. The following will refer to Figure 1 to describe the method for optimizing data query based on quantum technology of the present disclosure in detail.
[0026] In step 101, query text data of the user at the current moment and within a historical time window is collected, and after preprocessing the query text data, a bag-of-words model is constructed. The feature vectors in the bag-of-words model are encoded in quantum states, and the dominant feature vectors of the query text data are extracted through a quantum principal component analysis algorithm.
[0027] Step 1011, in the data collection and weight assignment stage, user query data is continuously collected through a data interface. This data includes the current real-time query content and historical query records within a preset time range. In order to accurately reflect the changing trend of the user's query intention, a dynamic weight assignment mechanism is adopted to assign different importance weights to query data in different time periods. Specifically, the weight ratio of the current query data is set to a, and the total weight ratio of the data in the query record is set to b (a + b = 1). This weight assignment is achieved through the repeated representation of feature vectors, that is, the current query data appears repeatedly in the sample matrix according to the weight ratio for the corresponding number of times, while the historical query data reduces its repeated times according to a time decay factor. This design ensures that both the latest query intention of the user can be captured in a timely manner and the feature learning of the historical query pattern can be taken into account.
[0028] Step 1012, in the feature representation and bag-of-words model construction stage, the weighted query text is deeply preprocessed. The preprocessing steps include multiple sub-steps such as text cleaning, word segmentation, stop word filtering, and stemming.
[0029] In this embodiment, the text cleaning stage is mainly responsible for removing noise data such as irrelevant punctuation marks, special characters, and numbers to ensure the purity of the text content. Word segmentation includes splitting a continuous text sequence into independent lexical units to form a basic lexical set. Subsequently, based on a preset stop word list, words with high frequency but low semantic value are filtered out, such as auxiliary words like "de", "le", "zai", etc. To further optimize the feature quality, stemming is performed to merge words with different word forms into a unified basic form, effectively reducing the feature dimension and enhancing semantic consistency. These processing steps together ensure the normalization and standardization of the text data, effectively improving the quality and efficiency of feature extraction. It should be particularly noted that the core characteristic of the bag-of-words model is to ignore the original order information of the words in the text and regard the text as an unordered set of words. Although this processing method loses some syntactic structure information, it greatly simplifies the mathematical representation of the text and provides convenience for subsequent vectorization processing.
[0030] In one embodiment, after text preprocessing, statistical analysis is performed on all preprocessed words. Words are filtered based on metrics such as word frequency and document frequency, retaining the most representative set of keywords to construct a dynamic vocabulary. The size of the vocabulary is optimized to ensure sufficient semantic expressive power while avoiding the curse of dimensionality. This vocabulary forms the basis of the entire feature space, providing a standardized reference system for subsequent vectorization operations.
[0031] In one embodiment, each query text is transformed into a numerical feature vector based on the constructed vocabulary. Specifically, each query sample is represented as an M-dimensional vector, where M is the size of the vocabulary. For the i-th word in the vocabulary, the value of its corresponding dimension in the vector represents the number of times that word appears in the current query text. Thus, the previously collected N text samples together constitute an N×M-dimensional sample matrix X, where each row represents a sample and each column represents the frequency of a feature word across all samples. To eliminate the influence of text length differences on feature representation, all feature vectors are normalized, converting the values of each dimension to a uniform dimensional range.
[0032] Step 1013: Prepare quantum states for the processed bag-of-words model, and calculate the most important eigenvalues and eigenvectors of the covariance matrix of the matrix through quantum principal component analysis.
[0033] In this embodiment, after constructing the bag-of-words model and vectorizing the text, the core quantum computing processing stage begins. Leveraging the parallelism of quantum computing, the most representative main feature patterns are efficiently extracted from the high-dimensional sample matrix. This process sequentially includes two key steps: quantum state preparation and quantum principal component analysis.
[0034] First, in the quantum state preparation stage, the sample data is mapped to the quantum computing space. Specifically, each sample vector (i.e., each row of the matrix) in the N×M dimensional sample matrix X obtained in step 1012 is transformed into a corresponding quantum state using a specific quantum encoding technique. This embodiment preferentially adopts amplitude encoding, that is, encoding the numerical information of each dimension of the normalized vector into the amplitude of a superposition of multiple qubits. This step is the foundation for realizing subsequent quantum algorithms. It enables the sample data, which originally required a large amount of memory to store on a computer, to exist in the amplitude of the quantum state in an exponentially compressed form, creating a prerequisite for subsequent exponentially accelerated computation.
[0035] After quantum state preparation, a quantum principal component analysis (QPCA) algorithm is executed to solve for the principal components of the sample matrix covariance matrix. In QPCA, the covariance matrix (calculated from the sample matrix X) is first represented as a density operator. Then, this density operator is diagonalized using a quantum phase estimation-based algorithm. This algorithm divides the quantum circuit into eigenvalue registers and state registers, simulates the time evolution of the density operator through controlled unitary transformation operations, and reads the phase information in the eigenvalue register in the form of quantum states; this information corresponds to the eigenvalues of the covariance matrix. Through multiple measurements, a series of eigenvalues can be obtained with a certain probability; the eigenvalues with the highest probability are the principal eigenvalues of the covariance matrix.
[0036] In this embodiment, principal component analysis (PCA) is a data dimensionality reduction technique that compresses information from a high-dimensional feature space into a low-dimensional subspace by finding the projection direction that maximizes the variance of the original data. The mathematical basis of this dimensionality reduction process is the variance maximization principle—to retain as much of the original data variation information as possible in the projected low-dimensional space. Since the more dispersed the distribution of data points, the greater their variance and the richer the information they contain, variance becomes an ideal indicator of the degree of information retention in the projection direction. From a linear algebra perspective, this optimization problem can be transformed into eigenvalue analysis of the sample covariance matrix. The diagonal elements of the covariance matrix of the sample matrix X represent the independent variances of each feature dimension, and the sum of the variances of all dimensions equals the trace of the covariance matrix. Therefore, maximizing the sum of variances after projection is mathematically equivalent to solving the optimization problem of eigenvalue decomposition of the covariance matrix. Specifically, it is necessary to decompose the sample matrix X and calculate the eigenvalues and eigenvectors of its covariance matrix, where the magnitude of the eigenvalue directly reflects the magnitude of the data variance in the direction of the corresponding eigenvector. The breakthrough of quantum principal component analysis (QPCA) lies in its completely different computational paradigm. Unlike traditional algorithms that require the complete computation of all eigenvalues, QPCA fully leverages the parallel processing and exponential storage capabilities of quantum systems. Through techniques such as quantum phase estimation, it can directly extract the top K most important eigenvalues and eigenvectors with extremely high efficiency. This characteristic aligns well with practical application needs because, in most scenarios, the main features of data are concentrated in a few dominant eigenvalues. By preparing the density matrix corresponding to the data and utilizing the natural evolution characteristics of quantum states under eigenbases, QPCA enables the main eigenvalues to be measured and extracted with a higher probability.
[0037] In one embodiment, quantum principal component analysis based on quantum phase estimation can be specifically performed as follows: (1) Convert the covariance matrix into a density operator The corresponding spectral decomposition is as follows: eigenvalues are , It is an eigenvector.
[0038] (2) Using the idea of the HHL algorithm, let Then, the phase estimation algorithm is used to calculate the formula. To extract the corresponding feature values.
[0039] The quantum circuit is divided into two registers: the first register stores the eigenvalues of the covariance matrix, and the second register is used to prepare the density operator. And the corresponding simulated density quantity U, such as Figure 2 As shown.
[0040] (3) Several eigenvalues are obtained with different probabilities through the above circuit. The one with the highest probability is the principal eigenvalue of the matrix. Select the eigenvalues with the highest probability, calculate their eigenvectors, and form a new matrix composed of eigenvectors. This is the solution of quantum principal component analysis, which is the main feature of the data queried by the user within a certain period of time.
[0041] In this embodiment, query text information is collected, converted into a bag-of-words model, and a sample matrix is constructed. Quantum principal component analysis is then performed on this matrix to extract its most important eigenvalues and eigenvectors. Obtaining these eigenvalues and eigenvectors is equivalent to obtaining the main features of the user's queries within a recent time period, providing a basis for searching for data with similar features in the database.
[0042] In step 102, based on the dominant feature vector, multiple data items that satisfy the similarity condition with the dominant feature vector are retrieved from the target database to generate a preloaded dataset.
[0043] In this embodiment, after obtaining the dominant feature vector extracted by quantum principal component analysis, the process proceeds to the similar data retrieval stage. This involves searching the target database for data items highly similar to the user's query features and forming a new dataset. If a classical computing architecture is used to implement this process, it will unfold in four steps to ensure the accuracy and efficiency of the retrieval.
[0044] Step 201: Construct database feature vectors. To achieve accurate comparison with query features, the text data in the database is transformed into a unified numerical representation. The standardized vocabulary established in Step 101 is reused as the basis of the feature space to ensure consistency of feature dimensions. For each piece of text data in the database, a complete preprocessing workflow is performed, including text cleaning, word segmentation, and stop word filtering, and then a corresponding feature vector is generated based on the vocabulary. The dimensions of each feature vector are consistent with the size of the vocabulary, and the values of each dimension represent the frequency of the corresponding word in the data item. After frequency statistics are completed, all feature vectors are normalized to eliminate the bias caused by differences in text length and ensure the accuracy of subsequent similarity calculations.
[0045] Step 202: Use the K-means clustering algorithm to perform cluster analysis on the data in the database. Databases typically contain massive amounts of data, making direct global similarity matching calculations extremely costly. Therefore, the K-means clustering algorithm is used as a preprocessing step for data filtering. This algorithm divides the feature vectors in the database into K distinct clusters based on their intrinsic similarity. Each cluster represents a group of data items tightly clustered in the feature space. Through an iterative optimization process, the centroid vector of each cluster is calculated. This centroid serves as the mean of all data points within the cluster, effectively representing the feature distribution of the entire cluster.
[0046] Step 203 involves performing cluster-level similarity matching. This includes calculating the similarity between the multiple dominant feature vectors obtained from quantum principal component analysis and the centroid vector of each cluster. Euclidean distance is used as the similarity metric, and the distance from each centroid to each dominant feature vector is calculated. To comprehensively evaluate the overall similarity, the average distance from each centroid to all dominant feature vectors is calculated, and the cluster corresponding to the centroid with the smallest average distance is selected as the candidate dataset.
[0047] Step 204 involves refined data filtering within the selected candidate clusters. Each data item in the candidate cluster is traversed, and the distance between its feature vector and the dominant feature vector is calculated. By setting a distance threshold or a maximum number of items T, the T data items with the smallest distances are selected, forming the final pre-loaded dataset. These data items are sorted in ascending order of their distance from the dominant feature vector, ensuring that the most relevant data is placed first. This hierarchical filtering mechanism, which first performs coarse selection based on cluster-level matching and then refines the selection through item-level matching, can control computational complexity while ensuring retrieval quality.
[0048] In one embodiment, when processing massive databases, the K-means clustering operation performed in step 202 can be replaced with a quantum K-means clustering algorithm to achieve the same effect. This algorithm, as a quantum-classical hybrid algorithm, maintains the basic framework of classical K-means while significantly improving computational efficiency by introducing quantum computing technology.
[0049] In this embodiment, the core innovation of the quantum K-means algorithm lies in optimizing the similarity calculation process by leveraging the characteristics of quantum parallel computing. The algorithm first transforms classical data into quantum state representations, encoding the feature vectors and initial centroid vectors in the database into corresponding quantum states through a quantum state preparation process. Subsequently, using the core technology of quantum swap testing, it calculates the fidelity between the quantum state of the sample under test and each centroid quantum state in parallel. This fidelity measure accurately reflects the similarity between two quantum states in Hilbert space. When the measurement results show that the fidelity of a sample with a specific centroid reaches its maximum value, the sample is assigned to the corresponding data cluster. Compared to the classical algorithm, which requires sequential execution of similarity calculations, the quantum K-means algorithm achieves parallel processing through quantum superposition, enabling multiple similarity comparisons to be completed simultaneously.
[0050] In one embodiment, based on step 201, the step of using the quantum K-means algorithm can be specifically performed as follows: S2011. Randomly select K data vectors from the database as initial centroids; S2012. Three registers are reserved on the quantum circuit. The first register is used to store the vector of the data sample being tested; the second register is used to store the eigenvectors of the K centroids; the third register is an auxiliary register used to output the result and record the fidelity between the two quantum states. S2013. Record the fidelity between this data and each centroid, compare them, and assign the data to the cluster with the highest fidelity. This indicates whether the data belongs to this cluster; S2014. Repeat steps S2011 to S2013 until all data in the database has been measured. S2015, According to the formula Readjust the centroids and repeat steps S2011 to S2015 until the centroids no longer change, or until a preset number of iterations is reached, then stop iterating and output the centroid vector for each cluster.
[0051] In this embodiment, the dataset of the T data points closest to the main feature vector is obtained from the database to prepare for writing to the memory LRU linked list later.
[0052] In step 103, the preloaded dataset is loaded into the head position of the LRU cache list according to its similarity to the dominant feature vector. The data items stored in the LRU cache list are dynamically maintained, and data items that meet the eviction criteria are evicted based on access timestamps and access frequency information.
[0053] In this embodiment, after similar data retrieval is completed and a preloaded dataset is generated, the cache optimization implementation phase begins. An improved LRU cache management mechanism loads predicted data into memory and establishes a dynamic maintenance strategy to improve data query hit rate.
[0054] Step 301: The preloaded dataset is loaded into the head position of the LRU cache list according to its similarity to the dominant feature vector. The cache injection process adopts a priority strategy based on semantic similarity. Data items in the preloaded dataset are sorted according to their similarity to the dominant feature vector, with higher similarity indicating higher priority. When loading the LRU cache list, this priority order is followed, inserting the data item with the highest similarity into the head position of the list, and data items with lower similarity are arranged sequentially to the left. This injection mechanism ensures that the cache space always prioritizes storing data most relevant to the user's current query intent. Simultaneously, when the injection of new data causes a cache overflow, a cache eviction process is automatically triggered to maintain the total cache capacity limit.
[0055] Step 302 involves creating a metadata record for each newly loaded data item to manage the lifecycle of cached data. This metadata includes key information such as the load timestamp, initial similarity score, access count counter, and last access time. When a data item is matched by a user query, its last access timestamp is immediately updated, and the data item is moved to the head of the LRU list while its access count is incremented. This dynamic adjustment mechanism ensures that frequently accessed data remains in a prominent position in the cache.
[0056] Step 303 employs a multi-dimensional evaluation-based eviction strategy to maintain the cached data items stored in the LRU cache list. An eviction algorithm based on a weighted scoring model is constructed to evaluate the current value of each data item. This algorithm incorporates parameters such as the initial similarity score, access frequency, and last access time of the data item into a unified evaluation system to generate a comprehensive value score. When cache space needs to be released, the data items with the lowest scores are prioritized for eviction. These data items typically have low semantic relevance and have not been accessed for a long time. The eviction process starts from the tail of the LRU list, gradually removing the data items with the lowest comprehensive scores, while ensuring that newly added high-value data can obtain sufficient cache space. This cache eviction mechanism ensures that the cached content is always kept in an optimal state.
[0057] This disclosure provides a method, device, and medium for optimizing data querying based on quantum technology. First, user query data and query records are collected and constructed into a bag-of-words model to build a sample matrix. Then, quantum principal component analysis is used to extract the main eigenvalues and eigenvectors from the sample matrix. Next, based on the established vocabulary, a eigenvector is generated for each data point in the database. Using K-means clustering, the data in the database is clustered into clusters centered at K centroids. The distance between each centroid and the principal eigenvector is calculated, and the data from the cluster with the closest centroid is selected as the dataset to be written into an LRU linked list. Finally, the T data points from the selected cluster whose eigenvectors are closest to the principal eigenvector are loaded into the LRU linked list according to their distance, for use in subsequent queries. This design helps to provide a high hit rate for the LRU linked list in data queries, improving the speed and efficiency of data retrieval.
[0058] In a second aspect, embodiments of this disclosure provide an electronic device including a memory and a processor, wherein the memory stores a program that runs on the processor, and the processor, when running the program, performs the steps of the quantum technology-based optimized data query method described in the first aspect. In a third aspect, embodiments of this disclosure provide a computer-readable storage medium having computer instructions stored thereon, which, when executed, perform the steps of the method for optimizing data querying based on quantum technology as described in the first aspect.
Claims
1. A method for optimizing data querying based on quantum technology, characterized in that, Includes the following steps: S1. Collect the user's query text data at the current time and within the historical time window, and construct a bag-of-words model after preprocessing the query text data; S2. Encode the feature vectors in the bag-of-words model using quantum states, and extract the dominant feature vectors of the query text data using a quantum principal component analysis algorithm; S3. Based on the dominant feature vector, retrieve multiple data items from the target database that satisfy the similarity condition with the dominant feature vector, and generate a preloaded dataset; S4. Load the preloaded dataset into the head position of the LRU cache list according to the similarity order with the dominant feature vector.
2. The method for optimizing data query based on quantum technology according to claim 1, characterized in that, Step S1 involves preprocessing the query text data and then constructing a bag-of-words model, including: The collected query text data is segmented and stop word filtered to create a feature vocabulary. A single query text is represented as a feature vector based on the feature vocabulary, where the values of each dimension of the vector represent the frequency of occurrence of the corresponding word in the query text. Different weight coefficients are assigned to the feature vectors of the current query text and the historical query text, with the weight coefficient of the current query text being higher than that of the historical query text.
3. The method for optimizing data query based on quantum technology according to claim 1, characterized in that, Step S2, which involves extracting the dominant feature vector of the query text data using a quantum principal component analysis algorithm, includes: The covariance matrix of the sample matrix corresponding to the bag-of-words model is converted into a density operator; The eigenvalues and eigenvectors of the density operator are solved using a quantum phase estimation algorithm. The top K feature vectors with the highest probability measurement values are selected as the dominant feature vectors, where K is a preset positive integer.
4. The method for optimizing data query based on quantum technology according to claim 1, characterized in that, Step S3 retrieves multiple data items from the target database that satisfy the similarity condition with the dominant feature vector, generating a preloaded dataset, including: S31. Convert the text data in the target database into feature vectors according to the same feature vocabulary as the bag-of-words model; S32. The feature vectors are clustered using the quantum K-means clustering algorithm to obtain multiple data clusters; S33. Calculate the similarity distance between the centroid vector of each data cluster and the dominant feature vector; S34. Select the top T data items from the data cluster with the smallest similarity distance to form the preloaded dataset, where T is a preset positive integer.
5. The method for optimizing data query based on quantum technology according to claim 4, characterized in that, Step S32 uses the quantum K-means clustering algorithm to cluster the feature vectors, resulting in multiple data clusters, including: S321. Configure three registers on the quantum circuit to store the sample vector of the data to be tested, the centroid eigenvector, and the fidelity measurement result, respectively. S322. Calculate the fidelity between the data sample and each centroid through quantum exchange testing; S323. Based on the fidelity measurement results, divide the data samples into the data clusters with the highest fidelity. S324. Iteratively update the centroid position until the preset convergence condition is met.
6. The method for optimizing data query based on quantum technology according to claim 1, characterized in that, Step S4, which loads the preloaded dataset into the head position of the LRU cache list according to its similarity to the dominant feature vector, includes: Based on the similarity between the data items and the dominant feature vector, from high to low, the data items are inserted into the head of the LRU cache list in sequence. Add metadata including the loading timestamp and initial similarity score to each newly loaded data item.
7. The method for optimizing data query based on quantum technology according to claim 1, characterized in that, The method further includes: Monitor the access timestamps and access frequency of data items stored in the LRU cache list; Establish a comprehensive scoring model based on time decay and access frequency; When cache space is insufficient, the data item with the lowest overall score will be evicted first.
8. The method for optimizing data query based on quantum technology according to claim 1, characterized in that, The method further includes: Monitor the scale of data processing and the status of computing resources; When quantum computing resources are detected to be unavailable or the amount of data to be processed is lower than a preset threshold, the algorithm switches to classical principal component analysis and classical K-means clustering to perform the corresponding computational tasks.
9. An electronic device, characterized in that, The device includes a memory and a processor, wherein the memory stores a program that runs on the processor, and the processor executes a method for optimizing data query based on quantum technology as described in any one of claims 1-8 when running the program.
10. A computer-readable storage medium storing computer instructions thereon, characterized in that, The computer instructions, when executed, perform a method for optimizing data query based on quantum technology as described in any one of claims 1-8.