A history query pattern multiplexing and parameter adaptive rewriting method
By abstracting historical queries into a structured schema and performing intent parsing, slot alignment, and context migration, the problems of inference latency and structure drift in intelligent query systems are solved, achieving a fast response and high hit rate adaptive rewriting effect.
Patent Information
- Application Number
- CN202611210831.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-11
- Publication Date
- 2026-11-27
AI Technical Summary
Existing intelligent query systems suffer from increased inference latency, structural drift risk, and context pollution when faced with similar queries that only involve changes in entities. Furthermore, they lack adaptive rewriting strategies and struggle to effectively utilize historical query logic and user feedback for optimization.
By abstracting historical queries into a structured schema, and employing intent parsing, slot identification, slot alignment, and context migration mechanisms, combined with user feedback, parameters are adaptively rewritten, enabling schema reuse and adaptive parameter rewriting.
It significantly reduces inference latency and structural drift risk, improves response speed and hit rate, achieves controllable adjustment of interpretability and adaptive rewriting, and forms a closed-loop learning mechanism.
Smart Images

Figure CN123178431A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of natural language processing and structured query generation technology, specifically to a method for reusing historical query patterns and adaptively rewriting parameters. Background Technology
[0002] With the increasing demand for enterprise data analysis, intelligent query systems are widely used in scenarios such as business intelligence data retrieval, natural language database queries, and work order retrieval. Users submit query requests to the system using natural language, which is then converted into structured query statements and executed, returning the results. In practice, users often repeatedly submit similar queries with only different entities for the same query objective. When a user changes "query the return rate of product A in East China last quarter" to "query the return rate of product B in South China last quarter," only the product name and region change, while the overall query structure remains the same.
[0003] Existing one-time query generation schemes based on large language models infer the entire query structure from scratch each time based on the current user input, failing to fully utilize query logic that has been successfully validated in the user's past history. This leads to the system re-inferring the entire query structure when faced with similar queries where only the entities change, resulting in increased inference latency and the risk of structure drift, thus increasing the probability of execution failure. Furthermore, existing recommendation schemes based on query logs typically only reuse text at the text level, failing to abstract historical queries into transferable schema structures or perform parameterized replacement of entity slots and time slots within the schema. Even when the user only changes the entity name, the entire question still needs to be manually modified.
[0004] Furthermore, the effective context of time range, organizational scope, and ranking preferences in multi-turn sessions often remains valid for current similar queries. However, existing solutions directly concatenate historical session text into the model, easily leading to context pollution, slot conflicts, and permission violations. Regarding parameter rewriting, different business scenarios have varying requirements for the aggressiveness of rewriting. High-risk financial queries should prioritize reusing high-confidence patterns and only replacing explicit entities, while exploratory analytical queries can allow for greater parameter expansion. However, existing solutions lack adaptive rewriting control strategies based on scenario risk and pattern confidence. In terms of feedback loops, user actions such as clicking the first result, modifying the query, and performing a secondary search reflect the success of pattern reuse and parameter rewriting. However, existing solutions struggle to translate this feedback into continuous optimization of pattern selection weights and rewriting control parameters.
[0005] Therefore, the core issues for improving the response speed, hit rate and interpretability of intelligent query systems are how to abstract structured patterns from historical successful queries, establish entity alignment and slot mapping between the current query and historical patterns, safely inject transferable contexts into the current query, and dynamically adjust and rewrite parameters based on satisfaction feedback. Summary of the Invention
[0006] The present invention aims to at least solve one of the technical problems existing in the prior art, and provides a method for reusing historical query patterns and adaptively rewriting parameters.
[0007] To achieve the above objectives, this invention provides a method for reusing historical query patterns and adaptively rewriting parameters, comprising: Step S1: Perform intent parsing and slot identification on the current query text to obtain the current query object containing the intent type and slot set; Step S2: Retrieve candidate patterns from the pattern library, which is constructed from historical successful query records through pattern abstraction. Each pattern object contains intent type, slot set, constraint template and satisfaction prior. Calculate the matching score between the current query object and each of the pattern objects and retain the candidate patterns with the highest ranking. Step S3: Under the slot type constraint, establish the alignment mapping between the slot of the current query object and the slot of the candidate pattern, and replace the placeholder in the constraint template with the corresponding entity value to obtain the candidate structured query; Step S4: Calculate the migration score for the transferable context items in the historical session context, and inject the context items that meet the migration conditions and do not conflict with the explicit slots of the current query object into the candidate structured query. Step S5: Calculate the rewrite confidence based on the matching score, the alignment quality of the alignment mapping, the migration score, and the satisfaction prior; adaptively select a rewrite strategy based on the rewrite confidence and execute the target query. Step S6: Collect user behavior feedback on the target query execution results, convert it into satisfaction labels, and update the satisfaction prior and the calculation parameters of the rewrite confidence of the corresponding pattern object in the pattern library.
[0008] Furthermore, the pattern abstraction includes: performing intent classification on each record in the historical successful query records, mapping the query target to the intent type; extracting the slot set from the original question and the corresponding structured query, each slot containing a slot name, slot type, original text fragment, and binding relationship; abstracting the conditions in the structured query other than the slot value into the constraint template, with the slot value represented by a placeholder; encoding the intent type, slot type sequence, constraint key sequence, and aggregation operator into a pattern vector; when the similarity between the newly abstracted pattern and the existing patterns in the pattern library exceeds a preset merging threshold, merging the reuse frequency and updating the satisfaction prior.
[0009] Further, step S1 also includes encoding the current query text to obtain a query vector; in step S2, the recall adopts a dual-channel approach combining a structured recall channel and a semantic recall channel. The structured recall channel matches structurally similar patterns based on the intent type and slot type set of the current query object, while the semantic recall channel recalls semantically similar patterns based on the cosine similarity between the query vector and the pattern vector; the matching score is calculated as follows: ; in, For the current query text With the Candidate patterns The matching score between them, The current query text, For the first One candidate pattern, For the currently queried object, For structured recall channels based on intent Figure 1 The structural matching score is calculated based on consistency, slot structure similarity, and constraint key similarity. The semantic recall channel calculates a semantic matching score based on the cosine similarity between the query vector and the pattern vector. The aforementioned satisfaction level is the prior. For historical reuse frequency, , , , These are the weighting coefficients.
[0010] Furthermore, the establishment of the alignment mapping includes: allowing only slots of the same or compatible types to establish mappings; for entity fragments in the current query object, searching for canonical entities in the entity knowledge base, and calculating type consistency and hierarchical consistency with historical entities in the candidate patterns; the alignment quality is determined based on the average alignment score of each mapping pair, and the alignment score is calculated as follows: ; in, The alignment score is given. For the slot entities in the currently queried object, For the slot entities in the candidate pattern, For type matching, For knowledge base links, For syntactic position similarity, For co-occurrence statistics, , , , These are the weighting coefficients.
[0011] Furthermore, the transfer score is calculated as follows: ; in, The migration score, For the transferable context item, This indicates the continued validity of the context item in a history of successful queries. This indicates the relevance of the context item to the intent of the current query object. This indicates the time freshness of the context item. This indicates the degree of conflict between the context item and the explicit slot of the currently queried object. For the currently queried object, The set of slots for the currently queried object. , , , This is the weighting coefficient; when a certain type of context value has been explicitly given in the current query object, the same type of context item in the historical session will not overwrite the current value.
[0012] Furthermore, the rewrite confidence level is calculated as follows: ; in, For the rewrite confidence level, For the Sigmoid function, For the matching score, The alignment quality, The mean of the transfer score, The aforementioned satisfaction level is the prior. Based on the scenario risk level, to For parameters; The rewriting strategy includes: when the rewriting confidence is higher than a first preset threshold and the scenario risk level is lower than a preset risk threshold, the mode priority rewriting is performed, and the mode skeleton is directly reused to replace only the entity; when the rewriting confidence is between the first preset threshold and the second preset threshold, hybrid rewriting is performed, the mode skeleton is reused and non-core conditions are allowed to be modified; when the rewriting confidence is lower than the second preset threshold or there is a slot conflict, conservative rewriting is performed, and only the recommended mode is provided for user confirmation.
[0013] Furthermore, the satisfaction rating is calculated as follows: ; in, The satisfaction label is... Mark the first result. Copy the result marker. Mark the results as favorites. To normalize the dwell time, To re-check the marker after modification, Mark the result as empty. Mark as negative review to The weighting coefficients are used; the update employs a stability constraint method, and the update formula for the prior satisfaction level is: ; in, This is the updated prior for the satisfaction level. It is a smoothing coefficient and its value ranges from zero in the open interval to the preset upper limit value.
[0014] Furthermore, step S6 also includes: when the satisfaction tag of a certain pattern object is lower than a preset satisfaction threshold in the feedback of a preset number of consecutive failures, the pattern object is marked as a downgraded pattern. The downgraded pattern is only used as a recommendation candidate in subsequent recalls and is not automatically executed; the update of the calculation parameters adopts the ranking loss optimization, and the pattern selection loss is: ; in, Choose a loss for the pattern. For the candidate structured query corresponding to positive feedback For candidate structured queries corresponding to negative feedback. This is the sorting score function.
[0015] Furthermore, in step S3, for slots that are required in the candidate patterns but not explicitly given by the current query object, they are filled in according to the following priority: first, the default value in the current session context is used; second, the default value of the pattern in the candidate patterns is used; and third, the slots are filled in from the context migration results of step S4. If the slots are still missing and the slots correspond to high-risk constraints, execution is blocked and a clarification request is returned.
[0016] Further, in step S5, a rewrite explanation object is generated before executing the target query. The rewrite explanation object includes the reused pattern identifier, slot mapping relationship, migrated context items, the type of the rewrite strategy, and the value of the rewrite confidence. The ranking score of the candidate structured query is calculated as follows: ; in, For the first The ranking score of each of the candidate structured queries. For the first The rewrite confidence of each candidate, The satisfaction prior for the corresponding pattern. To normalize the reuse frequency, For the cost of execution, As a risk penalty item, to These are the weighting coefficients.
[0017] The beneficial effects of this invention are as follows: This invention abstracts historical successful queries into a structured pattern containing intent, slots, and constraint templates. When users only change the query entity, the validated query skeleton can be directly reused and parameter-level replacements can be performed, which significantly reduces the inference latency and structural drift risk caused by the full generation of a large language model.
[0018] This invention employs a structured context transfer mechanism to evaluate the persistence, intent relevance, time freshness, and conflict level of context items such as time range, organizational range, and sorting preference, thereby avoiding the risks of context pollution, slot conflicts, and permission overstepping caused by directly splicing together the original text of historical sessions.
[0019] This invention adaptively selects a rewriting strategy based on pattern matching confidence, entity alignment quality, scenario risk, and historical satisfaction, enabling controllable adjustment of the rewriting intensity and allowing high-risk queries to be handled conservatively while low-risk queries are executed quickly.
[0020] This invention transforms user clicks, re-searches, negative reviews, and empty results into satisfaction tags, and feeds back to update the prior information of the pattern library and rewrite control parameters, forming a closed-loop learning mechanism oriented towards the effect of pattern reuse. This enables the system to automatically adjust with changes in business without the need for frequent manual maintenance. Attached Figure Description
[0021] Figure 1 This is an overall flowchart of the historical query pattern reuse and parameter adaptive rewriting method according to an embodiment of the present invention; Figure 2 This is a schematic diagram illustrating the historical query pattern abstraction process in an embodiment of the present invention; Figure 3 This is a schematic diagram of dual-channel recall and slot alignment according to an embodiment of the present invention. Detailed Implementation
[0022] To make the objectives, technical solutions, and beneficial effects of this application clearer, the following detailed description, in conjunction with the accompanying drawings and specific embodiments, further illustrates this application. It should be understood that the specific embodiments described in this specification are merely for explaining this application and are not intended to limit it.
[0023] The overall technical solution of the historical query mode reuse and parameter adaptive rewriting method of the present invention will be described below.
[0024] See Figure 1 The historical query mode reuse and parameter adaptive rewriting method of the present invention includes steps S1 to S6, and each step will be described in detail below.
[0025] Step S1 involves performing intent parsing and slot identification on the current query text to obtain the current query object containing the intent type and slot set.
[0026] The current query text is a natural language question or semi-structured query entered by the user on the query terminal. Intent parsing refers to identifying the user's query target category from the current query text. The query target category includes, but is not limited to, single-entity indicator queries, multi-entity comparison queries, time-series trend queries, ranking queries, and detailed drill-down queries. Slot identification refers to identifying variable entity fragments from the current query text and labeling their types. These types include, but are not limited to, products, regions, times, organizations, personnel, and enumeration values. In a further embodiment, step S1 also includes semantically encoding the current query text to obtain a query vector, which is used for similarity calculation in subsequent semantic recall channels.
[0027] Intent parsing and slot identification can employ a joint intent-slot identification method based on a pre-trained language model, a rule-based sequence labeling method, or a conditional random field-based sequence labeling method. The commonality of these methods is that they all take natural language text as input and simultaneously output intent category labels and slot sequences with type annotations. In a preferred embodiment, a joint intent-slot identification method based on a pre-trained language model is used, which has advantages in understanding long-tail expressions and cross-domain generalization.
[0028] The current query object is represented as ,in For the intent type, For the set of slots, This is the set of entity values for each slot. This refers to the current session context. When step S1 further includes semantic encoding, the current query object further includes a query vector. .
[0029] Step S2 is to recall the candidate pattern set from the pattern library.
[0030] The pattern library is constructed from historical successful query records through pattern abstraction. Pattern abstraction refers to separating the fixed logical parts from the variable entity parts of historical queries to form reusable structured query patterns. Specifically, pattern abstraction includes five sub-processes: intent classification, slot extraction, constraint templating, pattern vectorization, and pattern merging.
[0031] Each pattern object in the pattern library contains an intent type, a set of slots, a constraint template, and a satisfaction prior. The intent type describes the query target category for that pattern. The set of slots defines the replaceable parameters in that pattern, their types, and binding relationships. The constraint template describes filtering conditions, sorting methods, and aggregation methods other than slot values, where slot values are represented by placeholders. The satisfaction prior reflects the cumulative user satisfaction with that pattern over historical usage.
[0032] The recall employs a dual-channel approach combining a structured recall channel and a semantic recall channel. The structured recall channel retrieves structurally matching patterns from the pattern library based on the intent type, slot type set, and constraint key set of the current query object. The semantic recall channel recalls semantically similar patterns based on the cosine similarity between the query vector and each pattern vector. The complementary relationship between the structured and semantic recall channels lies in the fact that the structured recall channel excels at precisely matching patterns with the same query structure, while the semantic recall channel excels at recalling patterns with different wording but similar intents. In alternative implementations, only the structured recall channel or only the semantic recall channel may be used, but the dual-channel approach offers better recall coverage and accuracy than the single-channel approach.
[0033] A comprehensive matching score is calculated by combining the matching results from the two channels. This comprehensive matching score integrates structural matching score, semantic matching score, prior satisfaction level, and historical reuse frequency. Candidate patterns ranked highest based on the comprehensive matching score are retained, with the number of top-ranked patterns set to a preset Top-K value. When the comprehensive matching score falls below a preset matching threshold, the system enters a conservative rewriting mode.
[0034] Step S3 involves establishing an alignment mapping and performing entity replacement for each candidate pattern under slot type constraints to obtain candidate structured queries.
[0035] The alignment mapping refers to establishing a one-to-one correspondence between the slots of the current queried object and the slots of the candidate patterns. The slot type constraint means that only slots of the same type or compatible types are allowed to establish mappings to prevent entity replacement mismatches. The compatible type refers to types that have hierarchical or synonymous relationships in the entity knowledge base.
[0036] Alignment mapping can be established using precise alignment methods based on type constraints and knowledge base links, alignment methods based on syntactic position similarity, or weighted combinations of these methods. The commonality among these methods is that they all determine the optimal mapping relationship by evaluating the multi-dimensional similarity between the current query slot and the pattern slot. In a preferred embodiment, a four-dimensional weighted combination of type matching, knowledge base links, syntactic position similarity, and co-occurrence statistics is used.
[0037] Based on the alignment mapping, each placeholder in the constraint template is replaced with the corresponding entity value in the current query object to generate the candidate structured query. Simultaneously, the alignment quality of the alignment mapping is output, which is the mean or minimum alignment score of each mapping pair, used for the rewrite confidence calculation in subsequent step S5.
[0038] Step S4 involves extracting transferable context items from the historical session context and the current session context, calculating a transfer score for each transferable context item, and injecting context items that meet the transfer conditions and are conflict-free into the candidate structured query.
[0039] The structured context transfer described herein is a key step that distinguishes this invention from existing technologies. Existing technologies directly concatenate historical dialogue text into a large language model, which easily leads to context pollution, slot conflicts, and permission violations. This invention employs a structured transfer approach, independently evaluating the suitability of each context item for transfer to the current query.
[0040] The migrationable context items include, but are not limited to, time range, organization range, permission domain, default sort, page size, display fields, currency, time zone, and data source partition.
[0041] The migration score is determined based on a multi-dimensional evaluation of persistence effectiveness, intent relevance, time freshness, and conflict level. Persistence effectiveness indicates the degree to which the context item remains effective in historical successful queries. Intent relevance indicates the degree of association between the context item and the intent type of the current query object. Time freshness indicates the time distance of the context item from the current moment. Conflict level indicates the degree of contradiction between the context item and the explicit slots of the current query object.
[0042] The migration rules are as follows: when a certain type of context value has been explicitly given in the current query object, the same type of context item in the historical session will not overwrite the current value. When the migration score is higher than a preset migration threshold and the conflict level is lower than a preset conflict threshold, the context item is injected into the candidate structured query. When the migration score is at the boundary and there is ambiguity, a clarification request is triggered.
[0043] Step S5 involves calculating the rewrite confidence based on the comprehensive matching score, alignment quality, transfer score, and satisfaction prior, adaptively selecting a rewrite strategy based on the rewrite confidence, and executing the target query.
[0044] The rewrite confidence score is a quantitative indicator that comprehensively evaluates the reliability of the current rewrite result. The calculation of the rewrite confidence score integrates information from the matching dimension, alignment dimension, migration dimension, and historical satisfaction dimension, while deducting the negative impact of scenario risks.
[0045] The rewriting strategy is an adaptively selected execution strategy based on the numerical range of the rewriting confidence level. The rewriting strategy includes three types: pattern-first rewriting, hybrid rewriting, and conservative rewriting. Pattern-first rewriting is suitable for high-confidence, low-risk scenarios, directly reusing the pattern skeleton, replacing only entities, and executing automatically. Hybrid rewriting is suitable for medium-confidence scenarios, reusing the pattern skeleton while allowing minor adjustments to non-core filtering conditions. Conservative rewriting is suitable for low-confidence or high-risk scenarios, only recommending patterns for user confirmation and not executing automatically. The commonality of these three strategies is that they are all based on the query skeleton of the candidate patterns; the difference lies in the degree of automation and the range of allowed adjustments.
[0046] After selecting a rewriting strategy, the ranking score of each candidate structured query is calculated. The candidate query with the highest ranking score that passes permission and syntax checks is selected as the target query and executed. Before execution, a rewriting explanation object is generated. This object contains the reused schema identifier, slot mapping relationship, migrated context items, rewriting strategy type, and rewriting confidence value, used to show the user the basis for the rewriting and audit traceability.
[0047] Step S6 involves collecting user behavior feedback, converting it into satisfaction tags, and updating the pattern library parameters.
[0048] The user behavior feedback includes actions such as clicking the first result, ignoring all results, modifying and re-checking, copying results, adding to favorites, giving negative reviews, dwell time, empty results, and execution timeout. This user behavior feedback is then converted into normalized satisfaction tags.
[0049] Based on the satisfaction labels, the following parameters are updated: the prior satisfaction of the corresponding pattern object in the pattern library, the weight coefficients in the comprehensive matching score calculation, the weight coefficients in the alignment mapping, the weight coefficients in the context transfer, and the parameters in the rewritten confidence calculation. The update employs a stability constraint to prevent excessive deweighting of the pattern due to a single negative feedback event.
[0050] The steps S1 to S6 above constitute a complete closed loop of "query parsing - pattern recall - slot alignment - context migration - adaptive rewriting - satisfaction feedback", which enables the system to continuously improve response speed, hit rate and interpretability while ensuring the stability of the query structure.
[0051] Regarding "pattern objects": A pattern object refers to a structured, reusable query pattern abstracted from historical successful queries. In this invention, a pattern object specifically refers to a structured query pattern containing intent types, parameterized slot sets, and condition constraint templates. Its core functions in query reuse are: providing a query skeleton, defining replaceable parameter bits, and storing fixed query logic. The pattern object separates query logic from variable entities, enabling similar queries to generate new queries through parameter replacement without re-reasoning. This is the key mechanism for solving the technical problem described in this invention.
[0052] Schema objects can be implemented in, but are not limited to, the following ways: SQL query template schema objects, whose constraint templates are represented by SQL WHERE, ORDER BY, and GROUP BY clause templates; DSL query template schema objects, whose constraint templates are represented by domain-specific language filtering and aggregation syntax templates; API parameter template schema objects, whose constraint templates are represented by API request parameter key-value pair templates; and graph database query template schema objects, whose constraint templates are represented by graph query language node matching and relation traversal templates. All of these different forms of schema objects include intent classification, parameterized replaceable slots, and a fixed query logic skeleton. In a preferred embodiment, SQL query template schema objects are used.
[0053] Regarding the "dual-channel recall": Dual-channel recall refers to a retrieval method that simultaneously utilizes two different retrieval strategies to recall candidate patterns from a pattern library. In this invention, dual-channel recall specifically combines structured matching recall and semantic vector recall. Structured matching recall performs precise structure matching based on intent type, slot type set, and constraint key set, while semantic vector recall performs semantic nearest neighbor retrieval based on the cosine similarity between the query vector and the pattern vector. The reason for adopting a dual-channel approach is that single structured matching cannot cover synonym graph queries with varying wording, and single semantic retrieval cannot accurately distinguish between queries with different structures but similar semantics. The two complementary channels can simultaneously guarantee both recall and precision.
[0054] Semantic recall channels can also employ nearest neighbor retrieval methods based on locality-sensitive hashing or full-text retrieval methods based on inverted indexes, while structured recall channels can employ relation matching methods based on knowledge graphs.
[0055] Regarding "alignment mapping": Alignment mapping refers to the process of establishing a correspondence between the current query slot and candidate pattern slots. In this invention, alignment mapping specifically refers to slot-level alignment based on type constraints and knowledge base entity links. Before establishing the mapping, the compatibility of slot types is verified, and the alignment accuracy is improved through entity normalization in the knowledge base. Type constraints prevent incorrect substitutions across types, and knowledge base links ensure the legality of entity values at the business level.
[0056] Alignment mapping can be achieved through one or more of the following methods in combination: precise alignment based on type matching score and knowledge base link score, fuzzy alignment based on syntactic position similarity score, and statistical alignment based on co-occurrence statistics score.
[0057] Regarding "transfer score": Migration score refers to a quantitative assessment of whether a context item is suitable for migration from a historical session to the current query. In this invention, the migration score is specifically calculated based on four dimensions: persistence effectiveness, intent relevance, time freshness, and slot conflict. These four orthogonal dimensions measure the safety and effectiveness of migration. Relying solely on time freshness cannot identify semantic conflicts, and relying solely on intent relevance cannot exclude expired context. This four-dimensional assessment forms a complete basis for migration decisions.
[0058] Regarding "rewriting confidence level": Rewrite confidence refers to a quantitative indicator that comprehensively evaluates the reliability of the current rewrite result. In this invention, rewrite confidence is specifically a comprehensive metric that integrates matching score, alignment quality, transfer quality, satisfaction prior, and scenario risk. A nonlinear mapping function compresses the multidimensional input into a scalar value between zero and one. This confidence level simultaneously considers the accuracy of pattern matching, the correctness of entity replacement, the safety of context transfer, and the satisfaction level of historical usage, providing multidimensional support for the selection of rewrite strategies.
[0059] The nonlinear mapping function can be a Sigmoid function, a Tanh function, or a piecewise linear function. In a preferred embodiment, a Sigmoid function is used.
[0060] Example 1: Enterprise BI Data Query Scenario The following section provides a more detailed explanation of each step of the present invention in the context of specific applications in enterprise BI data query scenarios.
[0061] In this embodiment, a data analyst from a company uses a BI query system to query the return rate of each product. Last week, the analyst successfully queried "Return rate of Product A in East China in Q1 2025". The system executed the query successfully and returned the results, which the analyst then clicked and exported. This week, the analyst entered "Check the return rate of Product B". The following explains how the system processes this query based on the method of this invention.
[0062] The execution process of step S1: The system receives the current query text "Check the return rate of product B", performs intent parsing on the query text, and identifies that the query belongs to the "single entity indicator query" intent type. Simultaneously, it performs slot identification, recognizing "product B" as the entity value of the product type slot and "return rate" as the entity value of the indicator type slot. No explicit entity values were identified for the time slot or the region slot. The system encodes the current query text into a query vector using a semantic encoding model. The current organization recorded in the current session context is "South China Region".
[0063] The current query object obtained from this is "Single Entity Indicator Inquiry" {product: “Product B”, metric: “Return Rate”} Query vector, \{org: “South China Region”\}).
[0064] The execution process of step S2: The system retrieves candidate patterns from the pattern library. In the pattern library, the analyst's successful query last week, "Return Rate of Product A in East China in Q1 2025," has been abstracted into the following pattern object: "Single Entity Indicator Inquiry" \{product, region, time\_range, metric\}, \{filter: product=\{product\} AND region=\{region\} AND time\_range=\{time\_range\}, metric=\{metric\}\}, , ; The specific process of schema abstraction is as follows: The system performs intent classification on the successfully queried "Return Rate of Product A in East China in Q1 2025" from last week, determining its intent type to be "Single Entity Indicator Query". Four slots are extracted from the original question and the corresponding SQL query: the original value of the product type slot "Product A", the original value of the region type slot "East China", the original value of the time_range type slot "Q1 2025", and the original value of the metric type slot "Return Rate". "Product A", "East China", and "Q1 2025" in the SQL query are replaced with placeholders {product}, {region}, and {time_range} to form a constraint template. The intent type, slot type sequence, and constraint key sequence are encoded into a schema vector. .
[0065] The structured recall channel retrieves patterns from the pattern library that match the intent type "single entity metric query" and whose slot type set {product, metric}, based on the intent type of the current query object and the slot type set contains the slot type of the current query object. .
[0066] Semantic recall channel calculates query vector and pattern vector The semantic matching score is obtained by calculating the cosine similarity. .
[0067] The overall matching score is calculated as follows: ; The value is higher than the preset matching threshold of 0.5. Proceed to the subsequent entity replacement and parameter rewriting stage.
[0068] The execution process of step S3: The system establishes the slots and... Alignment mapping between slots.
[0069] For the "product" slot: "Product B" in the current query represents the product type. The historical entity in the product slot is "Product A". Since both are product types, the type matching is correct. The system searches for "Product B" and "Product A" in the entity knowledge base, confirming that they belong to the same product category. The knowledge base links are... Alignment score: ; For the metric slot: the current query's "return rate" and The metric slots are consistent, and the alignment score is 1.0.
[0070] For region slots: If the current query does not explicitly provide a region, the slot is marked as unmapped.
[0071] For the time_range slot: The current query does not explicitly provide a time range, so this slot is marked as unmapped.
[0072] Based on the alignment mapping of the mapped slots, In the constraint template, the product placeholder is replaced with "Product B", while the metric placeholder remains "Return Rate". The region and time_range placeholders have not yet been replaced, pending context migration in step S4 and unmapped slot processing in step S3. Alignment quality. .
[0073] For unmapped region slots, the current organization recorded in the current session context is "South China Region". The current session default value is used according to priority, and the region is set to "South China Region".
[0074] The execution process of step S4: The system from Extract transferable context items from the associated historical session context. The historical session context is {region="East China", time_range="2025Q1", sort="metric_desc"}.
[0075] Calculate the migration score for time_range="2025Q1": ; Among them, persistent effectiveness This is because the time window has been effective in multiple recent queries, indicating intent relevance. This is because "single entity indicator query" is highly correlated with time limits and time freshness. Because it had been about a week since the last use, the degree of conflict... This is because the current query does not explicitly specify a time range. The migration score of 0.665 is higher than the preset migration threshold of 0.3, so "time_range="2025Q1" is migrated to the candidate structured query.
[0076] Calculate migration score for region="East China": ; Level of conflict This is because the current session context has switched the organization to "South China," which directly conflicts with the historical "East China." Although the migration score of 0.36 is higher than the preset migration threshold, the conflict level of 1.0 is higher than the preset conflict threshold of 0.5. Therefore, region="East China" will not be migrated, and the current query uses the "South China" determined in step S3.
[0077] The migration score for sort="metric_desc" is 0.55, indicating high persistence and intent relevance with no conflicts. It is migrated to the candidate structured query.
[0078] After context shifting, the candidate structured query becomes "Query the return rate of product B in South China in Q1 2025, sorted in descending order of return rate".
[0079] The execution process of step S5: The system calculates the rewrite confidence level: ; Pick Calculations yielded .
[0080] If the risk level is higher than the first preset threshold of 0.7 and the scenario risk level is lower than the preset risk threshold of 0.5, the system will prioritize rewriting the execution mode strategy, directly reuse the mode skeleton, replace only the entity, and execute automatically.
[0081] The system generates a rewrite interpretation object: pattern identifier. The slot mapping relationship is {product: Product A → Product B}. The migrated context item is {time_range: 2025Q1, sort: metric_desc}. The unmigrated item is {region: not migrated due to organization switch}. The rewrite strategy type is "pattern-first rewrite" and the rewrite confidence is 0.91.
[0082] Perform the target query and return the return rate of product B in South China in Q1 2025.
[0083] The execution process of step S6: The analyst clicked on the first result and exported the data. The system collected user behavior feedback: .
[0084] Calculate satisfaction labels: ; renew Prior satisfaction: ; Write the updated satisfaction level back into the schema library to complete the closed loop.
[0085] Example 2: E-commerce product selection scenario The following section provides a detailed explanation of each step of the present invention in the context of e-commerce product selection scenarios.
[0086] In this embodiment, an e-commerce platform operator uses a product data query system. The operator had previously successfully queried "Top 50 Best-Selling Women's Spring Dresses" and is now entering "Top 50 Best-Selling Men's Summer T-Shirts".
[0087] The execution process of step S1: The system performs intent parsing and slot identification on the current query text "Men's Clothing Category Summer T-shirt Sales Ranking". Intent parsing determines that the query belongs to the "Category Product Sorting Query" intent type. The slot identification results are as follows: the entity value of the category type slot is "Men's Clothing", the entity value of the season type slot is "Summer", the entity value of the product_type type slot is "T-shirt", and the entity value of the metric type slot is "Sales". The current query text is then encoded to obtain a query vector.
[0088] The execution process of step S2: The schema library contains schema objects abstracted from the last successful query: "Category Product Sorting Search" \{category, season,product\_type, metric, topn\}, \{filter: category=\{category\} ANDseason=\{season\} AND product\_type=\{product\_type\}, metric=\{metric\},sort: metric\_desc, limit=\{topn\}\},
[0089] The structured recall channel matches the intent type "category product sorting query". The slot type set \{category, season, product_type, metric\} highly matches the corresponding slot in the pattern. The structured matching score is... Cosine similarity is calculated for semantic recall channels. The overall matching score is 0.89. Proceed to the next steps.
[0090] The execution process of step S3: Establish alignment mapping for category slots: "Men's Clothing" and "Women's Clothing" are both category types. The knowledge base confirms that they belong to the same level category, with a type matching score of 1.0 and a knowledge base linking score of 0.92. The alignment score is 0.95.
[0091] Establish alignment mapping for the "season" slot: "Summer" and "Spring" are both of the "season" type, with a type matching score of 1.0 and a knowledge base link score of 0.90. The alignment score is 0.94.
[0092] Establish alignment mapping for the product_type slot: "T-shirt" and "dress" are both of type product_type, type matching score 1.0, knowledge base link score 0.75. Alignment score 0.88.
[0093] For the metric slot: "Sales" should be kept consistent with the alignment score of 1.0.
[0094] The topn slots are the required slots that are not explicitly given in the current query. The default value Top50 is used according to priority.
[0095] Replace each placeholder in the constraint template with the current entity value. Alignment quality. .
[0096] The execution process of step S4: The context of the last successful query was {sort: metric_desc, display_fields:product_name, sales_volume, price}. Both the sorting method and the displayed fields scored highly and showed no conflicts, indicating a move to the candidate structured query.
[0097] The execution process of step S5: Rewrite confidence If the value exceeds the first preset threshold, the execution mode will be rewritten first. The system automatically generates and executes a structured query for "Top 50 Summer T-shirts in Men's Apparel Category", retaining the original sorting and display field logic.
[0098] The execution process of step S6: The operations staff browsed the query results and copied the ranking data, collecting positive feedback. Update Satisfaction priors are used to increase the recall weight of the model.
[0099] Example 3: Operation and Maintenance Log Query Scenario The following section provides a detailed explanation of each step of the present invention in the context of a specific application scenario for querying operation and maintenance logs.
[0100] In this embodiment, the operations and maintenance engineer uses a log analysis system. The engineer had previously successfully queried the "Top 100 ERROR logs of the service payment-api in the last hour", and is now inputting the "TIMEOUT logs of the gateway-api in the last 30 minutes".
[0101] The execution process of step S1: The system performs intent parsing on the current query text and determines the intent type to be "log detail query". The slot identification results are: service type slot entity value "gateway-api", time_window type slot entity value "last 30 minutes", and level type slot entity value "TIMEOUT". No explicit entity values for topn type slots were identified.
[0102] The execution process of step S2: The schema library contains schema objects abstracted from the last successful query: "Log details query" \{service, time\_window, level,topn\}, \{filter: service=\{service\} AND time IN \{time\_window\}AND level=\{level\}, limit=\{topn\}, fields: timestamp, message, trace\_id,sort: timestamp\_desc\}, ; The overall matching score is calculated to be 0.91. Proceed to the next steps.
[0103] The execution process of step S3: The service slot mapping "gateway-api" is replaced with "payment-api", with a type matching score of 1.0. The knowledge base confirms the service name is valid, resulting in an alignment score of 0.95. The time_window slot mapping "last 30 minutes" is replaced with "last 1 hour", with an alignment score of 0.92. The level slot mapping "TIMEOUT" is replaced with "ERROR", both being log level enumeration types, resulting in an alignment score of 0.98.
[0104] The topn slots are the required slots not explicitly specified in the current query. The default value of Top100 is used based on priority.
[0105] Replace each placeholder in the constraint template with the current entity value to obtain a candidate structured query: "Query the top 100 TIMEOUT logs of gateway-api in the last 30 minutes". (Alignment quality) .
[0106] The execution process of step S4: Field projections and index partitions in the context of the last successfully queried historical session have high migration scores and no conflicts, and are migrated to candidate structured queries.
[0107] The execution process of step S5: Rewrite confidence The execution mode prioritizes rewriting strategies, automatically executing queries. If the returned result is not empty after execution, the system normally returns the TIMEOUT log details.
[0108] If the execution result is empty and the engineer immediately initiates a second search for "gateway-api logs of all levels in the last 30 minutes", then proceed to step S6.
[0109] The execution process of step S6: The system collects user behavior feedback: the result is empty. The engineer immediately re-examined .
[0110] The satisfaction rating was calculated as a negative value. The system is downgraded. The system establishes a satisfaction prior and simultaneously reduces the migration weight of field projection in this context transition, while increasing the priority of explicit slots. This negative feedback, through closed-loop learning, makes the system more cautious in migrating field projection configurations in subsequent similar scenarios.
[0111] Example 4: Intelligent Customer Service Cross-Conversation Context Migration Scenario This embodiment focuses on explaining the structured context transfer mechanism in step S4.
[0112] In a certain intelligent customer service system, an agent inquired about the "refund progress of a member's order" for a customer in the morning. The conversation context included {channel="APP", time_range="last 7 days", sort="latest priority"}. In the afternoon, another customer inquired about "member points redemption records". The agent entered "check points redemption records" without specifying the time or channel.
[0113] The execution process of step S4: Instead of piecing together the complete original dialogue from the morning session and feeding it into the generative model, the system calculates transfer scores for each context item separately.
[0114] For channel="APP": This is because the information from different channels is not always consistent. This is because the points redemption system is not closely linked to the channels used for it. , . Due to insufficient intent relevance, the transfer score is below the transfer threshold of 0.4, and the channel will not be transferred.
[0115] For time_range="last 7 days": , , , . If the migration score is above the threshold and there are no conflicts, the time_range="last 7 days" value will be migrated.
[0116] For sort="latest first": , , , . The sort was migrated.
[0117] Ultimately, the candidate structured query used the default time window "last 7 days" and sorting method "latest priority," and channel information was not migrated. The system displayed the message "Migration time_range=last 7 days, sort=latest priority; channel not migrated."
[0118] Example 5: Conservative Rewriting Scenario for High-Risk Financial Inquiries This embodiment focuses on illustrating the adaptive selection of the rewriting strategy in step S5.
[0119] In the financial shared service center, the user enters "View the head office's expense details for June 2025". System recall mode. The risk level of this model .
[0120] The execution process of step S5: Rewrite the confidence calculation: ; ; It falls between the first preset threshold of 0.7 and the second preset threshold of 0.4, but The risk level exceeds the preset risk threshold of 0.5. The rewrite controller enters conservative rewrite mode: the system generates candidate queries and slot mappings, but does not execute them directly. Instead, it requires the user to confirm the organizational scope, accounting period, and account permissions.
[0121] After user confirmation, the system executes the query. If the user modifies the accounting period conditions, the system records negative feedback and lowers the automatic execution priority of this mode in high-risk scenarios.
[0122] Example 6: Scenario of Continuous Optimization of Pattern Library Driven by Satisfaction Feedback This embodiment focuses on explaining the closed-loop learning mechanism in step S6.
[0123] During the long-term operation of the enterprise knowledge base, users continuously provide feedback on the results of pattern reuse, including clicks, copying, re-searching, negative reviews, empty results, and dwell time.
[0124] The system will record each execution as a feedback sample. The system periodically updates the following parameters: Pattern success rate Updated via exponential moving average: ; In pattern recall weight Optimize the loss by ranking positive and negative sample pairs: ; Alignment model parameters and migration parameters This is optimized by rewriting the cross-entropy loss of the confidence score: ; When a certain type of "product metric query" mode consistently achieves high satisfaction, this mode will have a high overall matching score. Increased weight leads to higher recall priority. When a certain pattern is continuously... When an empty result or negative review occurs, the system marks the mode as a downgrade mode, retaining only the recommendation and not executing it automatically.
[0125] If the new parameter version improves the duplicate search rate, empty result rate, and negative review rate after being released in a gray-scale environment, it will be fully implemented; otherwise, it will revert to the previous version of the parameters.
[0126] In summary, the embodiments of the present invention have at least the following technical effects: By abstracting historical successful queries into a structured pattern containing intent, slots, and constraint templates, the validated query skeleton can be directly reused and parameter-level replacements can be performed when the user only changes the query entity. This significantly reduces the inference latency and structural drift risk caused by the full generation of a large language model.
[0127] A structured context transfer mechanism is adopted to evaluate the persistence, intent relevance, time freshness, and conflict degree of context items such as time range, organizational range, and sorting preference, respectively, avoiding the risks of context pollution, slot conflict, and permission overstepping caused by directly splicing the original text of historical sessions.
[0128] Based on pattern matching confidence, entity alignment quality, scenario risk, and historical satisfaction, an adaptive rewriting strategy is selected, enabling controllable adjustment of the rewriting intensity. This allows high-risk queries to be handled conservatively while low-risk queries to be executed quickly.
[0129] By converting user clicks, re-searches, negative reviews, and empty results into satisfaction tags, and feeding back these tags to update the prior information in the pattern library and rewrite control parameters, a closed-loop learning mechanism oriented towards the effectiveness of pattern reuse is formed. This allows the system to automatically adjust to changes in business without the need for frequent manual maintenance.
[0130] It is understood that the above embodiments are merely exemplary implementations used to illustrate the principles of the present invention, and the present invention is not limited thereto. For those skilled in the art, various modifications and improvements can be made without departing from the spirit and essence of the present invention, and these modifications and improvements are also considered to be within the scope of protection of the present invention.
Claims
1. A method for reusing historical query patterns and adaptively rewriting parameters, characterized in that, include: Step S1: Perform intent parsing and slot identification on the current query text to obtain the current query object containing the intent type and slot set; Step S2: Retrieve candidate patterns from the pattern library, which is constructed from historical successful query records through pattern abstraction. Each pattern object contains intent type, slot set, constraint template and satisfaction prior. Calculate the matching score between the current query object and each of the pattern objects and retain the candidate patterns with the highest ranking. Step S3: Under the slot type constraint, establish the alignment mapping between the slot of the current query object and the slot of the candidate pattern, and replace the placeholder in the constraint template with the corresponding entity value to obtain the candidate structured query; Step S4: Calculate the migration score for the transferable context items in the historical session context, and inject the context items that meet the migration conditions and do not conflict with the explicit slots of the current query object into the candidate structured query. Step S5: Calculate the rewrite confidence based on the matching score, the alignment quality of the alignment mapping, the migration score, and the satisfaction prior; adaptively select a rewrite strategy based on the rewrite confidence and execute the target query. Step S6: Collect user behavior feedback on the target query execution results, convert it into satisfaction labels, and update the satisfaction prior and the calculation parameters of the rewrite confidence of the corresponding pattern object in the pattern library.
2. The historical query pattern reuse and parameter adaptive rewriting method according to claim 1, characterized in that, The pattern abstraction includes: performing intent classification on each record in the historical successful query records, mapping the query target to the intent type; extracting the slot set from the original question and the corresponding structured query, where each slot contains a slot name, slot type, original text fragment, and binding relationship; abstracting the conditions in the structured query other than the slot value into the constraint template, where the slot value is represented by a placeholder; encoding the intent type, slot type sequence, constraint key sequence, and aggregation operator into a pattern vector; and merging the reuse frequency and updating the satisfaction prior when the similarity between the newly abstracted pattern and the existing patterns in the pattern library exceeds a preset merging threshold.
3. The historical query pattern reuse and parameter adaptive rewriting method according to claim 1, characterized in that, Step S1 further includes encoding the current query text to obtain a query vector; in step S2, the recall adopts a dual-channel approach combining a structured recall channel and a semantic recall channel. The structured recall channel matches structurally similar patterns based on the intent type and slot type set of the current query object, while the semantic recall channel recalls semantically similar patterns based on the cosine similarity between the query vector and the pattern vector; the matching score is calculated as follows: ; in, For the current query text With the Candidate patterns The matching score between them, The current query text, For the first One candidate pattern, For the currently queried object, The structure matching score for the structured recall channel is calculated based on intent consistency, slot structure similarity, and constraint key similarity. The semantic recall channel calculates a semantic matching score based on the cosine similarity between the query vector and the pattern vector. The aforementioned satisfaction level is the prior. For historical reuse frequency, , , , These are the weighting coefficients.
4. The historical query pattern reuse and parameter adaptive rewriting method according to claim 1, characterized in that, The establishment of the alignment mapping includes: allowing only slots of the same or compatible types to establish mappings; for entity fragments in the current query object, searching for canonical entities in the entity knowledge base, and calculating type consistency and hierarchical consistency with historical entities in the candidate patterns; the alignment quality is determined based on the average alignment score of each mapping pair, and the alignment score is calculated as follows: ; in, The alignment score is given. For the slot entities in the currently queried object, For the slot entities in the candidate pattern, For type matching, For knowledge base links, For syntactic position similarity, For co-occurrence statistics, , , , These are the weighting coefficients.
5. The historical query pattern reuse and parameter adaptive rewriting method according to claim 1, characterized in that, The migration score is calculated as follows: ; in, The migration score, For the transferable context item, This indicates the continued validity of the context item in a history of successful queries. This indicates the relevance of the context item to the intent of the current query object. This indicates the time freshness of the context item. This indicates the degree of conflict between the context item and the explicit slot of the currently queried object. For the currently queried object, The set of slots for the currently queried object. , , , This is the weighting coefficient; when a certain type of context value has been explicitly given in the current query object, the same type of context item in the historical session will not overwrite the current value.
6. The historical query pattern reuse and parameter adaptive rewriting method according to claim 5, characterized in that, The rewrite confidence level is calculated as follows: ; in, For the rewrite confidence level, For the Sigmoid function, For the matching score, The alignment quality, The mean of the transfer score, The aforementioned satisfaction level is the prior. Based on the scenario risk level, to For parameters; The rewriting strategy includes: when the rewriting confidence is higher than a first preset threshold and the scenario risk level is lower than a preset risk threshold, the mode priority rewriting is performed, and the mode skeleton is directly reused to replace only the entity; when the rewriting confidence is between the first preset threshold and the second preset threshold, hybrid rewriting is performed, the mode skeleton is reused and non-core conditions are allowed to be modified; when the rewriting confidence is lower than the second preset threshold or there is a slot conflict, conservative rewriting is performed, and only the recommended mode is provided for user confirmation.
7. The historical query pattern reuse and parameter adaptive rewriting method according to claim 1, characterized in that, The satisfaction rating is calculated as follows: ; in, The satisfaction label is... Mark the first result. Copy the result marker. Mark the results as favorites. To normalize the dwell time, To re-check the marker after modification, Mark the result as empty. Mark as negative review to The weighting coefficients are used; the update employs a stability constraint method, and the update formula for the prior satisfaction level is: ; in, This is the updated prior for the satisfaction level. It is a smoothing coefficient and its value ranges from zero in the open interval to the preset upper limit value.
8. The historical query pattern reuse and parameter adaptive rewriting method according to claim 1, characterized in that, Step S6 further includes: when the satisfaction label of a certain pattern object is lower than a preset satisfaction threshold in the feedback of a preset number of consecutive failures, the pattern object is marked as a downgraded pattern. The downgraded pattern is only used as a recommendation candidate in subsequent recalls and is not automatically executed; the update of the calculation parameters adopts the ranking loss optimization, and the pattern selection loss is: ; in, Choose a loss for the pattern. For the candidate structured query corresponding to positive feedback For candidate structured queries corresponding to negative feedback. This is the sorting score function.
9. The historical query pattern reuse and parameter adaptive rewriting method according to claim 1, characterized in that, In step S3, for slots in the candidate patterns that are required but not explicitly given by the current query object, they are filled in according to the following priority: first, the default value in the current session context is used; second, the default value of the pattern in the candidate patterns is used; and third, the slots are filled in from the context migration results of step S4. If the slot is still missing and corresponds to a high-risk constraint, execution is blocked and a clarification request is returned.
10. The historical query pattern reuse and parameter adaptive rewriting method according to any one of claims 1 to 9, characterized in that, In step S5, a rewrite explanation object is generated before executing the target query. This object includes a reused pattern identifier, slot mapping relationships, migrated context items, the type of the rewrite strategy, and the rewrite confidence value. The ranking score of the candidate structured query is calculated as follows: ; in, For the first The ranking score of each of the candidate structured queries. For the first The rewrite confidence of each candidate, The satisfaction prior for the corresponding pattern. To normalize the reuse frequency, For the cost of execution, As a risk penalty item, to These are the weighting coefficients.
