Historical context-based large language model user query rewriting system and method

Through a large language model user query rewriting system based on historical context, combined with the weighted scoring mechanism of the BM25 model and the BGE vector model, the DeepSeek model is solved for the problem of generating unsuitable content and resource consumption in the information retrieval system, achieving the accuracy and simplicity of the query, and optimizing the user experience and information retrieval performance.

CN120234402APending Publication Date: 2025-07-01CHINA UNIV OF MINING & TECH
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202510268907.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-07
Publication Date
2025-07-01

AI Technical Summary

Technical Problem

In the information retrieval system, the query rewriting method based on the DeepSeek model has problems such as generating content that is not suitable for the current dialogue scenario, difficulty in understanding the context, high complexity of multiple intention analysis, system complexity and high resource consumption.

Method used

The user query rewriting system based on historical context is adopted. Through the two-stage process, the candidate query and context are weighted and scored using the BM25 model and the BGE vector model, and combined with the candidate query-context alignment scoring mechanism, avoiding direct call to the DeepSeek model for scoring, enhancing the richness and accuracy of the query content.

Benefits of technology

It significantly reduces the cost of rewriting the DeepSeek model, improves the accuracy, clarity, information adequacy and simplicity of query, optimizes the user experience, and improves the performance of information retrieval.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120234402A_ABST
    Figure CN120234402A_ABST
Patent Text Reader

Abstract

The invention provides a big language model user query rewriting method and system based on historical context, and belongs to the technical field of artificial intelligence. The method comprises the following steps: firstly, collecting a data set containing user query and historical dialogues, redesigning a new instruction, taking a DeepSeek model as a query revisor, and further optimizing the preliminarily rewritten query to obtain a final query version; the method comprises the following steps: calling a DeepSeek model through an API (Application Program Interface), rewriting a query by utilizing the DeepSeek model under the guidance assistance of a designed instruction, optimizing an original query, generating a plurality of improved candidate queries, storing the improved candidate queries in a query pool, and then scoring all queries in the query pool by adopting a candidate query-context alignment scoring mechanism, and selecting the candidate query with the highest score as a preliminary optimization result. According to the method, the query rewriting frame based on the open source large model is constructed, so that the rewriting quality of user query is effectively improved, and the performance of information retrieval is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention provides a large language model user query rewriting system and method based on historical context, belonging to the field of artificial intelligence technology. Background Art

[0002] In information retrieval systems, the accuracy of user queries and the precision of expressions are crucial for improving the relevance of search results and optimizing the user experience. Traditional query processing methods mainly rely on keyword matching and simple logical rules, but they are often insufficient when dealing with queries in complex contexts, implicit intentions, or professional fields. In recent years, with the rapid development of large language models (LLMs, such as DeepSeek models), especially the application of models based on the Transformer architecture, they have shown great potential in understanding complex language structures and generating coherent texts, bringing revolutionary progress to query rewriting technology. This technological advancement provides new solutions for more accurate and intelligent query processing.

[0003] In conversational search systems, users can satisfy complex information needs through multi-round interactions, and one of the key steps is to generate appropriate search queries for each user statement related to the context. The powerful capabilities of DeepSeek models in task-solving have prompted researchers to integrate them into existing conversational search systems to optimize each query. For example, Wang et al. used the few-shot method to generate paragraphs related to the query (Query2doc) and combined the generated content with the original query to form a new query text; Ma et al. optimized the query using a pre-trained rewriting model before retrieving the query; Fengran et al. applied the open-source DeepSeek model to improve query rewriting in conversational search, especially by resolving ambiguous queries to handle ambiguities in the conversation history.

[0004] Despite these advancements, there are still some problems: The method of generating relevant paragraphs based on DeepSeek models may introduce content that is not suitable for the current conversation scenario, resulting in a decline in retrieval performance; Independently trained rewriting models not only require high-quality data sources but also need to solve the problems of context understanding and multiple intention parsing and have a high dependence on the retrieval system; Directly performing data augmentation on the historical conversation or calling the API to let the DeepSeek model act as a query scorer will increase the system complexity and consume a large amount of token resources. Summary of the Invention

[0005] Objective of the Invention: Aiming at the deficiencies of the prior art, a large language model user query rewriting system and method based on historical context are proposed. Through a two-stage query rewriting process, the richness of the query content is enhanced, the reference ambiguity is effectively eliminated, and the topic conversion in the context is identified, thereby ensuring the accuracy, clarity, sufficiency of information, and conciseness of the query. This method uses the BM25 model and the BGE vector model to perform weighted scoring on the candidate queries and the context, avoiding calling the DeepSeek model for each candidate query and scoring the rewritten content, significantly reducing the cost of rewriting by the DeepSeek model.

[0006] To achieve the above technical objectives, the present invention adopts the following technical solutions:

[0007] A large language model user query rewriting system based on historical context, comprising a data input layer, a query optimizer, a candidate query pool, a candidate query-context alignment scoring mechanism, and a query optimization output layer connected in sequence;

[0008] The data input layer is used to receive the user's original query and relevant historical context data and transfer them to the query optimizer;

[0009] The query optimizer is DeepSeek, which is used to perform preliminary processing and optimization on the input data to generate candidate queries, and DeepSeek is trained in advance with professional knowledge according to the technical field requirements;

[0010] The candidate query pool is used to store the optimized candidate queries, which are stored in a dictionary manner;

[0011] The candidate query-context alignment scoring mechanism is used to select candidate queries from the candidate query pool;

[0012] Combined with the historical context data, it is used to score each candidate query and evaluate its matching degree and quality with the context,

[0013] The query optimization output layer is used to output the candidate query with the highest score, that is, to optimize and rewrite the original query as the query problem, which can improve the retrieval effect, handle fuzzy queries, and optimize the user experience.

[0014] A rewriting method for a large language model user query rewriting system based on historical context, the specific steps are as follows:

[0015] Step 1: Perform data screening on the natural language data set. The natural language data set includes the original query, the query rewritten by humans, relevant context information, and the corresponding relevant text links; set the screening conditions according to needs, and then extract the effective data set containing the original query and its relevant historical context content from the data set to form the required effective data set;

[0016] Step 2: Manually design prompt words based on the four characteristics of accuracy, clarity, information sufficiency and simplicity. The prompt words are designed around the professional terms in the user's question field, data characteristics and expected query direction. The following are specific and detailed design requirements:

[0017] Step 3: Input the valid data set into DeepSeek for query rewriting, and use the designed prompt words to assist DeepSeek in generating the rewritten candidate query-context data pairs, where the candidate query-context data pairs include multiple candidate queries and the context content corresponding to each candidate query;

[0018] Step 4: Repeat step 3 to traverse each data in the valid data set, and store the generated candidate query-context data pairs in the candidate query pool;

[0019] Step 5: Score the candidate query-context data pair using the candidate query-context alignment scoring mechanism;

[0020] Step 6: At the query optimization output layer, the candidate query with the highest score is selected as the query after preliminary rewriting according to the score calculated by the alignment scoring mechanism;

[0021] Step 7: Repeat steps 1 to 6 for the query after preliminary rewriting for a preset number of cycles, and output the final rewritten query, thereby eliminating the problems of sentence ambiguity and unclear reference in the query content.

[0022] Furthermore, the dataset is QReCC, which includes question rewriting, retrieval and reading comprehension; QReCC uses a dictionary to store the complete data after manual rewriting, and the complete data after manual rewriting is integrated into a complete data by the original query question, the manually rewritten query, the relevant context information and the corresponding relevant text link information, and the complete data is used as the element of the dictionary; different elements are used as key-value pairs of the dictionary, where the key is a descriptive name and the value is the corresponding data. The sources of data records include the QuAC-Conv, NQ-Conv and TREC-Conv datasets included in QReCC, which ensures the diversity and breadth of the data, and ensures the adequacy of the context information and the coherence of the conversation.

[0023] Furthermore, the specific rules for manually designing prompt words based on the four characteristics of accuracy, clarity, information sufficiency and conciseness are as follows:

[0024] Clear goals:

[0025] Clearly define the purpose of rewriting: The prompt should clearly indicate the goal of rewriting, including simplifying the language, changing the style, adjusting the tone, or optimizing the structure; specifically describe the output requirements: including word count limits, target audience, and language style;

[0026] Context information:

[0027] Provide background information: The prompt should contain sufficient context to help the model understand the context and intention of the original text; clearly define the theme and field: label as technology, literature, or business to ensure that the rewritten content conforms to the terminology and expression habits of the specific field;

[0028] Language and vocabulary:

[0029] Specify the language: including English, Chinese, to ensure the correct language of the rewritten text; vocabulary selection: label as simple vocabulary, professional terms, synonym replacement, to ensure that the vocabulary selection meets the target;

[0030] Avoid ambiguity:

[0031] Clear expression: The prompt should avoid being vague or ambiguous to ensure that the DeepSeek model accurately understands the requirements, including manually annotated examples to help the DeepSeek model better understand the expected output.

[0032] Furthermore, the prompt is about the professional terms, data characteristics, and expected query directions in the field of the user's question, ensuring that the DeepSeek model can understand the intention and providing examples for the DeepSeek model. The examples include reasonable conversion methods from the original query to the rewritten query. Only provide the current query and the conversation context for the DeepSeek model to generate a reconstructed query:

[0033] When API quota control is required, select the zero-shot learning (ZSL) framework. The DeepSeek model is based on the current query Q t and its related conversation context Conv t to generate a reconstructed query Utilize the understanding and execution ability of the DeepSeek model for the designed prompt to achieve query rewriting: Combine the conversation context Conv t with the current query Q t to form an instruction I and input it as a prompt message into the DeepSeek model to sample and generate a reconstructed query

[0034]

[0035] Among them, || represents text concatenation, LLM is the DeepSeek model, and t represents the current moment.

[0036] Furthermore, the prompt words are professional terms, data features, and expected query directions related to the user's question area, ensuring that the DeepSeek model can understand the intent. Provide examples to the DeepSeek model. The examples include reasonable conversion methods from the original query to the rewritten query, provide the current query and conversation context, and also provide manually annotated examples to the DeepSeek model to generate a reconstructed query:

[0037] When it is necessary to ensure the expected situation of the rewritten result, select the few-shot learning FSL framework. The DeepSeek model understands the instruction requirements based on the examples. Each manually annotated example includes three key elements: query Q, conversation context Conv, and rewritten query Concatenate multiple examples containing these key elements. The example S is expressed as:

[0038]

[0039] Among them, n represents the number of examples. By placing S between the instruction I and the test instance (Conv t ,Q t ) as a prompt to the DeepSeek model, a reconstructed query is generated Then it is sampled:

[0040]

[0041] Use the FSL setting to prompt the DeepSeek model as a rewrite reviser. In addition to the query Q, conversation context Conv, and rewrite In addition, introduce an initial rewrite for each example The concatenation of examples with the initial rewrite introduced is expressed as:

[0042]

[0043] Among them, n represents the number of examples. Input a test instance (Conv t ,Q t ), along with an initial rewrite Obtain the revised reconstructed query through the following process

[0044]

[0045] Among them, represents the instruction of the query reviser.

[0046] Furthermore, use the candidate query-context alignment scoring mechanism to evaluate the quality of candidate queries. The score calculation method is as follows: Loop through multiple candidate queries in the candidate query pool to pair the candidate query qi Score its corresponding context Conv, and calculate the BM25 score using the following formula:

[0047]

[0048] where f(q i , Conv) is the frequency of the query term in the context Conv, |Conv| is the context length, AVGDL is the average context length, k1 = 1.5, b = 0.75, and both k1 and b are adjustment factors. IDF(q i ) is the inverse document frequency term, as shown below:

[0049]

[0050] where IDF(q i ) is calculated using the total number of contexts N, and n(q i ) is the number of contexts containing q i ;

[0051] Calculate the dense score, that is, the correlation score between the candidate query and the context. Embed both the query and the context into a high-dimensional continuous vector space, and calculate the Dense alignment score using the following formula:

[0052]

[0053] where and E Conv are the dense embedding vectors of the candidate query q i and the context Conv from the dense retrieval model (BAAI / bge-large-en-vl.5), respectively.

[0054] Finally, combine the BM25 score and the Dense score using the following formula to obtain the hybrid score:

[0055] Hybrid = α · BM25(q i , Conv) + Dense(q i , Conv)

[0056] where the parameter α is set to 0.5 to balance the contributions of the BM25 score and the Dense score.

[0057] A computer device includes a processor and a memory. The processor is electrically connected to the memory. The memory is used to store instructions and data, and the processor is used to execute the method for rewriting user queries of a large language model based on historical contexts.

[0058] Beneficial effects: Through a two-stage query rewriting process, this method enhances the richness of the query content, effectively eliminates referential ambiguity, and identifies topic transitions in the context, thereby ensuring the accuracy, clarity, sufficiency, and conciseness of the query. In addition, this method uses the BM25 model and the BGE vector model to perform weighted scoring on candidate queries and context, avoiding the process of calling the API for each candidate query to let the large language model (DeepSeek model) score, and significantly reducing the cost of rewriting by the DeepSeek model. Brief Description of the Drawings

[0059] Figure 1 It is a schematic diagram of the method for rewriting user queries of the large language model based on historical context of the present invention. Detailed Embodiment

[0060] The following further describes the embodiments of the present invention with reference to the drawings:

[0061] As Figure 1 shown, the present invention discloses a large language model user query rewriting system based on historical context, which adopts a two-stage processing flow, specifically including the following key components: data input layer, query optimizer, candidate query pool, candidate query-context alignment scoring mechanism, and query optimization output layer. First, in the first stage, the data input layer consists of the query submitted by the user and the relevant historical context information, where the query appears in the form of the original query and the preliminarily rewritten query respectively in the two stages; then the query optimizer is composed of the DeepSeek open-source large model, which acts as a query rewriter and a query reviser respectively, and realizes their respective functions with carefully designed different instructions; then the role of the candidate query pool is to store multiple optimized queries processed by the query optimizer for subsequent operations; secondly, in the second stage, then the candidate query-context alignment scoring mechanism scores the matching degree of each candidate query and the context through the sparse retrieval algorithm BM25 and the dense retrieval algorithm, and evaluates the quality of the candidate query in the form of a mixed score; finally, the query optimization output layer contains each candidate query and its corresponding score, and by comparing the scores, the candidate query with the highest score is selected as the final optimized query.

[0062] A method for rewriting user queries of a large language model based on historical context includes the following steps:

[0063] Step 1: It involves screening data from the official dataset QReCC to obtain a valid dataset containing the original query Q0 and its relevant context information. The data source QReCC used includes authoritative datasets such as QuAC-Conv, NQ-Conv, and TREC-Conv. For the detailed distribution of the screened dataset, see Table 1;

[0064] Table 1 Dataset Distribution

[0065]

[0066] Step 2: Starting from four characteristics: accuracy, clarity, sufficiency of information, and conciseness, carefully design instructions so that the DeepSeek model can better optimize and improve user queries;

[0067] Step 3: This method uses the DeepSeek model to optimize queries. The selected effective dataset is used as input, leveraging the powerful language understanding and generation capabilities of the DeepSeek model as a query rewriter. During the operation, to guide the model to generate more satisfactory results, the prompt words designed in Step 2 are used. These prompt words are designed around the professional terms in the field of the user's question, data characteristics, and the expected query direction to ensure that the model can understand the intention. At the same time, appropriate examples are provided to the model, which show the reasonable transformation methods from the original query to the rewritten query, helping the model learn and master the rewriting pattern. Through such operations, the DeepSeek model generates the rewritten query Q1, providing a more accurate query statement for the subsequent retrieval task, which helps improve work efficiency and the accuracy of analysis results;

[0068] Step 4: Repeat the operation in Step 3 for each data in the dataset, and store the generated multiple candidate queries and their corresponding context contents in the candidate query pool. The candidate query pool uses a list to store this information for subsequent processing. During this process, the candidate query pool acts as a storage container that collects all possible candidate queries generated by the previous steps and the associated context information. The purpose of this is to provide a data basis for the subsequent candidate query-context alignment scoring mechanism, ensuring that there is sufficient data for screening and evaluation, so as to find the best query rewriting result that best meets the user's needs and historical context;

[0069] Step 5: For each pair of candidate query-context data pairs in the candidate query pool in Step 4, calculate and assign a corresponding score to each candidate query by implementing the candidate query-context alignment scoring mechanism proposed in this method;

[0070] Step 6: At the query optimization output layer, select the candidate query with the highest score as the preliminarily rewritten query Q2 according to the scores calculated by the alignment scoring mechanism;

[0071] Step 7: Repeat the operations in Steps 1 to 6, with the difference that in Step 1, a valid dataset for query Q2 and its related context content is used, and under the guidance of a preset instruction that stipulates the specific rules and criteria that DeepSeek needs to follow when performing query revision, DeepSeek, as a query reviser, understands the semantics and intent of query Q2, and at the same time combines the context to grasp the background information of the query. Then, according to the rules in the preset instruction, DeepSeek performs operations such as lexical substitution, sentence structure adjustment, or deletion of redundant information on query Q2. At the same time, the coherence and logic of the context will also be considered to ensure that the revised query still has clear semantics and a reasonable logical structure in the new context, without ambiguity or contradiction.

[0072] Furthermore, in Step 3, by using the DeepSeek open-source large model as a query rewriter, during the operation, in order to guide the model to generate results that better meet the requirements, well-designed prompt words are used. These prompt words are designed around the professional terms, data characteristics, and expected query directions in the user's question area to ensure that the model can understand the intent. At the same time, appropriate examples are also provided to the model, and these examples demonstrate reasonable conversion methods from the original query to the rewritten query to help the model learn and master the rewriting pattern. Through such operations, the DeepSeek model generates the rewritten query DeepSeek model.

[0073] On this basis, in one stage, two ways are explored to prompt the DeepSeek model to play the role of a query rewriter:

[0074] (1) In the ZSL framework, the DeepSeek model is designed to generate a reconstructed query only based on the current query Q t and its related dialogue context Conv t to generate a reconstructed query In this process, it completely depends on the DeepSeek model's ability to understand and execute instructions to achieve query rewriting. Specifically, the dialogue context Conv t is combined with the current query Q t to form an instruction I, which is used as a prompt message and input into the DeepSeek model to sample and generate a reconstructed query

[0075]

[0076] where, || represents text concatenation.

[0077] (2) In the FSL framework, each example consists of three key elements: a query Q, a dialogue context Conv, and a rewritten query Chaining these examples, the connection of the examples can be expressed as:

[0078]

[0079] where n represents the number of examples. By placing S between the instruction I and the test instance (Conv t ,Q t ) as a hint to the DeepSeek model, rewrite Then it is sampled as follows:

[0080]

[0081] When facing the task of query rewriting for the DeepSeek model to generate queries with specific attributes, a series of challenges may be encountered. The present invention proposes a solution, that is, using the DeepSeek model as a rewriting reviser in the second stage. The core function of this rewriting reviser is to carefully revise the provided initial rewriting.

[0082] In this work, the FSL setting is adopted to prompt the DeepSeek model as a rewriting reviser. In addition to the query Q, the conversation context Conv, and the rewriting In addition, an initial rewriting is introduced for each example The concatenated representation of these examples with the introduced initial rewriting is:

[0083]

[0084] where n represents the number of examples. For a test instance (Conv t ,Q t ), along with an initial rewriting The revised rewriting is obtained through the following process

[0085]

[0086] where represents the instruction of the query reviser.

[0087] Furthermore, step 4 first collects a set of candidate query sets that have been processed and optimized by the query optimizer. These candidate query sets contain potential query revision options, which not only maintain a certain semantic relevance to the original query but also meet the aforementioned property requirements. Subsequently, the method uniformly stores these candidate queries in a specially designed candidate query pool for subsequent scoring and ranking processing.

[0088] Furthermore, step 5 proposes to implement a candidate query-context alignment scoring mechanism to evaluate the quality of candidate queries. This scoring mechanism uses a hybrid scoring method that combines BM25 sparse retrieval and dense retrieval.

[0089] Specifically, given a candidate query q i and its corresponding context Conv, this scoring mechanism first calculates the BM25 alignment score. The formula for the BM25 alignment score is as follows:

[0090]

[0091] where f(q i , Conv) is the frequency of the query term in the context Conv, |Conv| is the context length, AVGDL is the average context length, k1 = 1.5, b = 0.75, and both k1 and b are adjustment factors. IDF(q i ) is the inverse document frequency term, as shown below:

[0092]

[0093] where IDF(q i ) is calculated using the total number of contexts N, and n(q i ) is the number of contexts that contain q i .

[0094] Next, this scoring mechanism calculates the dense score, which is the correlation score between the candidate query and the context. When both the query and the context are embedded in a high-dimensional continuous vector space, the formula for the Dense alignment score is as follows:

[0095]

[0096] where and E Conv are the dense embedding vectors of the candidate query q i and the context Conv from the dense retrieval model (BAAI / bge-large-en-vl.5), respectively.

[0097] Finally, the hybrid score is obtained by combining the BM25 score and the Dense score, and the formula is as follows:

[0098] Hybrid = α · BM25(q i , Conv) + Dense(q i , Conv)

[0099] where the parameter α is set to 0.5 to balance the contributions of the BM25 score and the Dense score.

[0100] Furthermore, after step 7 completes the first query rewriting and optimization process, the operations in steps 1 to 6 are repeated. Under the guidance of preset instructions, DeepSeek, as a query reviser, further revises and improves the query to achieve the accuracy and integrity of the query.

[0101] To illustrate the effectiveness of the present invention, a comparative experiment is conducted between this method and the current mainstream methods of query rewriting. Sparse retrieval (Sparse) and dense retrieval (Dense) use the BM25 retriever and the BGE dense retriever respectively. The evaluation metrics are shown in Table 2, and the experimental results are shown in Tables 3, 4, 5, and 6:

[0102] Table 2 Introduction to Evaluation Metrics

[0103] MRR Measures the ability of the model to rank positive samples at the front MAP Considers the ranking and relevance of retrieval results R@10 Measures the proportion of relevant documents retrieved by the retrieval system from all relevant documents NDCG A metric that measures the quality of the retrieval result ranking, considering the relevance scores and positions of relevant documents

[0104] Table 3 Comparison of Experimental Results between This Method and Comparative Methods on the QReCC Dataset

[0105]

[0106] Among them, the numbers in bold and black indicate the highest scores, the numbers with underlines below indicate the second-highest scores, Z indicates under the ZSL framework, F indicates under the FSL framework, RW indicates query rewriting under the action of the DeepSeek model, ED indicates query editing under the action of the DeepSeek model, RV indicates query revision under the action of the DeepSeek model (the corresponding letters in the subsequent tables are as shown before), Original indicates using the original query, Human indicates human query rewriting, T5QR indicates query rewriting under the action of the T5 model fine-tuned for the query rewriting task, and CQR indicates query rewriting under the action of the DeepSeek model without adopting the scoring mechanism and prompt words of this method. According to the experimental results, this method and other comparative mainstream methods all show a high level and achieve the best results in most metrics.

[0107] Table 4 Ablation Experiment Results of This Method on the QReCC Dataset

[0108]

[0109] It can be intuitively analyzed from the ablation experiment that adopting the alignment scoring mechanism can effectively improve the performance of the query in the retrieval process whether it is query rewriting in the first stage or query revision in the second stage. Because the richness of the query content is enhanced during the rewriting and revision processes, the referential ambiguity is effectively eliminated, and the topic transitions in the context are identified.

[0110] Table 5 The experimental results of this method using instructions different from CQR are as follows:

[0111]

[0112]

[0113] It can be observed from the table that without adopting the alignment scoring mechanism, the instructions designed by the present invention can still achieve good results in most cases, indicating the effectiveness, rigor, and scientific nature of the instructions of the present invention for prompting the DeepSeek model.

[0114] Table 6 The experimental results of the present method on the dataset in the field of coal mine safety are as follows:

[0115]

[0116] Example 1:

[0117]

[0118] Example 2:

[0119]

[0120]

[0121] Example 3:

[0122]

[0123]

Claims

1. A user query rewriting system based on a large language model of historical context, characterized by: It includes a sequentially connected data input layer, a query optimizer, a candidate query pool, a candidate query-context alignment scoring mechanism, and a query optimization output layer; The data input layer receives the user's original query and related historical context data and passes them to the query optimizer; The query optimizer is DeepSeek, which is used to perform preliminary processing and optimization on the input data to generate candidate queries. DeepSeek is trained with professional knowledge in advance according to the needs of the technical field; The candidate query pool is used to store the optimized candidate queries in a dictionary format; A candidate query-context alignment scoring mechanism is used to select candidate queries from the candidate query pool; Combined with historical context data, each candidate query is scored to assess its matching degree and quality with the context. The query optimization output layer is used to output the candidate query with the highest score, that is, the query question after optimizing and rewriting the original query, which can improve the retrieval effect, handle fuzzy queries, and optimize the user experience.

2. A rewriting method using the large language model user query rewriting system based on historical context according to claim 1, characterized in that: The specific steps are as follows: Step 1: Screen the natural language data set, which includes the original query, the manually rewritten query, the relevant context information, and the corresponding relevant text links; Set the screening conditions as needed, and then extract the valid data set containing the original query and its related historical context content from the data set to form the required valid data set; Step 2: Manually design prompt words based on the four characteristics of accuracy, clarity, information sufficiency and simplicity. The prompt words are designed around the professional terms in the user's question field, data characteristics and expected query direction. The following are specific and detailed design requirements: Step 3: Input the valid data set into DeepSeek for query rewriting, and use the designed prompt words to assist DeepSeek in generating the rewritten candidate query-context data pairs, where the candidate query-context data pairs include multiple candidate queries and the context content corresponding to each candidate query; Step 4: Repeat step 3 to traverse each data in the valid data set, and store the generated candidate query-context data pairs in the candidate query pool; Step 5: Score the candidate query-context data pair using the candidate query-context alignment scoring mechanism; Step 6: At the query optimization output layer, the candidate query with the highest score is selected as the query after preliminary rewriting according to the score calculated by the alignment scoring mechanism; Step 7: Repeat steps 1 to 6 for the query after preliminary rewriting for a preset number of cycles, and output the final rewritten query, thereby eliminating the problems of sentence ambiguity and unclear reference in the query content.

3. The method for rewriting user queries based on a large language model with historical context according to claim 2, characterized in that: The dataset is QReCC, which includes question rewriting, retrieval and reading comprehension. QReCC uses a dictionary to store the complete data after manual rewriting. The complete data after manual rewriting is integrated into a complete data by the original query question, the manually rewritten query, the relevant context information and the corresponding relevant text link information, and the complete data is used as the element of the dictionary. Different elements are used as key-value pairs of the dictionary, where the key is a descriptive name and the value is the corresponding data. The sources of data records include the QuAC-Conv, NQ-Conv and TREC-Conv datasets that come with QReCC, ensuring the diversity and breadth of the data, as well as the adequacy of the context information and the coherence of the conversation.

4. The method for rewriting user queries based on a large language model with historical context according to claim 2, characterized in that: The specific rules for manually designing prompt words based on the four characteristics of accuracy, clarity, information adequacy and conciseness are as follows: Clear goals: Clearly define the purpose of the rewrite: The prompt should clearly indicate the goal of the rewrite, including simplifying the language, changing the style, adjusting the tone, or optimizing the structure; specify the output requirements: including word count, target audience, and language style; Contextual information: Provide background information: The prompt words should contain enough context to help the model understand the context and intention of the original text; clarify the subject and field: mark it as science, literature or business, and ensure that the rewritten content conforms to the terminology and expression habits of the specific field; Language and Vocabulary: Specify the language: including English and Chinese, to ensure that the language of the rewritten text is correct; Vocabulary selection: mark as simple vocabulary, professional terms, synonym replacement, to ensure that the vocabulary selection meets the target; Avoid ambiguity: Clear expression: Prompt words should avoid ambiguity or ambiguity to ensure that the DeepSeek model accurately understands the requirements, including manually annotated examples to help the DeepSeek model better understand the expected output.

5. The method for rewriting user queries based on a large language model with historical context according to claim 4, characterized in that: The prompt words are professional terms, data features, and expected query directions surrounding the user's question field, ensuring that the DeepSeek model can understand the intent and providing examples for the DeepSeek model. The examples include reasonable conversion methods from the original query to the rewritten query. Only the current query and conversation context are provided to allow the DeepSeek model to generate a reconstructed query: When you need to control the consumption of API quota, choose the zero-shot learning ZSL framework. The DeepSeek model is based on the current query Q t and its related conversation context Conv t To generate the refactored query The DeepSeek model is used to understand and execute the designed prompt words to achieve query rewriting: Conversion context Conv t With the current query Q t Combined into an instruction I, it is fed into the DeepSeek model as a hint to sample and generate a reconstructed query Among them, || represents text concatenation, LLM is the DeepSeek model, and t represents the current time.

6. The method for rewriting user queries based on a large language model with historical context according to claim 4, characterized in that: The prompt words are professional terms, data features, and expected query directions surrounding the user's question field, ensuring that the DeepSeek model can understand the intent and provide examples for the DeepSeek model. The examples include reasonable conversion methods from the original query to the rewritten query, providing the current query and conversation context, and providing manually annotated examples to the DeepSeek model so that the DeepSeek model can generate reconstructed queries: When it is necessary to ensure the expected rewriting results, the FSL framework is selected. The DeepSeek model understands the instruction requirements based on examples. Each manually annotated example includes three key elements: query Q, dialogue context Conv, and rewritten query By stringing together multiple examples containing these key elements, example S is represented as: Where n is the number of examples, by placing S between instruction I and test instance (Conv t ,Q t ) as a hint to the DeepSeek model to generate a reconstructed query Then it is sampled: The FSL setting prompts the DeepSeek model as a rewrite reviser, in addition to the query Q, session context Conv and rewrite In addition, an initial rewrite is introduced for each example The concatenation of the examples that introduced the initial rewrite is represented as: Where n represents the number of examples, input a test instance (Conv t ,Q t ), accompanied by an initial rewrite The revised refactored query is obtained by the following process in, Indicates the command to query the fixer.

7. A method for rewriting user queries based on a large language model with historical context according to claim 5 or 6, characterized in that: The candidate query-context alignment scoring mechanism is used to evaluate the quality of candidate queries, and the score is calculated as follows: Cycle through multiple candidate queries in the candidate query pool to select candidate query q i And its corresponding context Conv is scored, and the BM25 score is calculated using the following formula: Among them, f(q i ,Conv) is the frequency of the query term in the context Conv, |Conv| is the context length, AVGDL is the average context length, k1=1.5, b=0.75, k1 and b are adjustment factors; IDF(q i ) is the inverse document frequency term, as follows: Among them, IDF(q i ) is calculated using the total number of contexts N, and n(q i ) is the one containing q i The number of contexts; Calculate the dense score, that is, the relevance score between the candidate query and the context, embed both the query and the context into a high-dimensional continuous vector space, and calculate the Dense alignment score using the following formula: in and E Conv They are the candidate queries q from the dense retrieval model (BAAI / bge-large-en-vl.5) i and the dense embedding vector of the context Conv; Finally, the BM25 score and the Dense score are combined to get the hybrid score using the following formula: Hybrid=α·BM25(q i ,Conv)+Dense(q i ,Conv) The parameter α is set to 0.5 to balance the contribution of BM25 score and Dense score.

8. A computer device, characterized in that: It includes a processor and a memory, wherein the processor is electrically connected to the memory, the memory is used to store instructions and data, and the processor is used to execute the large language model user query rewriting method based on historical context as described in any one of claims 2-6.

Citation Information

Cited By

  • Intelligent voice interaction method and device based on large language model

    CN120727012A

  • Method for large language model selection and query routing via offline quality estimation and token-efficent context optimization

    US12705051B1