Query context optimization method, optimization device, and computer program

The method and apparatus optimize query context for LLMs by using a question-and-answer history knowledge base and user feedback to enhance prompt performance and adaptability, addressing the inefficiencies of traditional fine-tuning and prompting methods.

JP2026089004APending Publication Date: 2026-05-29HITACHI LTD

Patent Information

Authority / Receiving Office
JP · JP
Patent Type
Applications
Current Assignee / Owner
HITACHI LTD
Filing Date
2025-06-23
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Optimizing query context for large language models (LLMs) is challenging due to the high cost and labor-intensive process of fine-tuning, difficulty in adapting prompts to new semantic scenarios, and the need for continuous monitoring and improvement, which hinders efficient performance maintenance.

Method used

A method and apparatus that utilize a question-and-answer history knowledge base to select candidate cases based on confidence levels, construct optimized query contexts, and incorporate user feedback to improve prompt performance, utilizing text transformation diagrams for further optimization.

Benefits of technology

Enhances prompt generalization and reduces the likelihood of repeating past errors by leveraging historical data and confidence levels, making prompt generation more controllable and adaptable.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 2026089004000001_ABST
    Figure 2026089004000001_ABST
Patent Text Reader

Abstract

This invention provides a method and apparatus for optimizing query contexts to improve their performance. [Solution] The query context optimization method includes querying a question-and-answer history knowledge base that stores a plurality of question-and-answer history records including query context history and answer history, and the confidence level of each question-and-answer history, based on a first query context, obtaining at least one candidate question-and-answer case that matches the semantics of the first query context and the confidence level of each candidate question-and-answer case, selecting at least one candidate question-and-answer case whose confidence level satisfies a predetermined threshold as a target case, and constructing a second query context based on the target case and the first query context.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data analysis processing, and specifically to a method and apparatus for optimizing query context, and a computer program.

Background Art

[0002] Many companies are using large language models (LLMs) to build private knowledge base applications. When integrating private domain knowledge into LLMs, usually two methods, fine-tuning and prompting, are used. Since the cost of fine-tuning the model is high and difficult to control, more and more companies are adopting the prompting method which is relatively cost-effective and provides more direct and timely feedback for optimizing the performance of applications.

[0003] However, it is not easy to find the optimal prompt for the LLM to execute tasks. Usually, repeated corrections and tests by experts are required, which are very time-consuming and labor-intensive. Even for well-designed prompts, it may be difficult to effectively popularize them in new semantic scenarios, and usually, the performance history of the prompts needs to be continuously monitored and improved when not supported. As a result, it becomes difficult to maintain and improve the prompts over time.

Summary of the Invention

Problems to be Solved by the Invention

[0004] At least one embodiment of this application provides a method and apparatus for optimizing query context to improve the performance of query context.

Means for Solving the Problems

[0005] According to a first aspect of the present application, in at least one embodiment, The process involves querying a question-and-answer history knowledge base, which stores multiple question-and-answer history records, each containing a query context history and an answer history, and the confidence level of each question-and-answer history, based on a first query context, and obtaining at least one candidate question-and-answer case that matches the semantics of the first query context, as well as the confidence level of each candidate question-and-answer case. Select at least one candidate question-and-answer case that satisfies a predetermined threshold of confidence as the target case, A method for optimizing a query context is provided, which includes constructing a second query context based on the aforementioned target example and the first query context.

[0006] Alternatively, the above method further includes inputting the second query context into a model and obtaining the response generated from the model and its confidence level.

[0007] Alternatively, the above method further includes storing the second query context and the answer generated from the model as a newly generated question-and-answer example, along with the confidence level generated from the model, in the question-and-answer history knowledge base.

[0008] Alternatively, the aforementioned question-and-answer case history further includes case type indication information, where the case types include positive cases and negative cases. In the above method, Receiving user feedback information on the answers generated from the aforementioned model, The system further includes generating example type information for the newly generated question-and-answer example based on the feedback information and storing it in the question-and-answer history knowledge base.

[0009] Alternatively, the question-and-answer history may further include thought chain information corresponding to the query context history.

[0010] Alternatively, constructing a second query context based on the aforementioned target example and the first query context is: This includes embedding the first query context and the target example into the corresponding module in the prompt template to obtain the second query context, Here, the prompt template includes a plurality of submodules, and the plurality of submodules include a question-and-answer example module for embedding the target example.

[0011] Alternatively, the above method is: Based on a predefined different text transformation diagram structure, the second query context is transformed to obtain at least two prompt candidates, Each prompt candidate is input into the model, and the response output from the model is obtained. Based on the response output from the model, the performance of the prompt candidates is evaluated, and the text conversion diagram structure is optimized based on the performance of the prompt candidates. The method further includes generating new question-and-answer examples of optimal performance prompt candidates and their corresponding answers, and storing them in the question-and-answer history knowledge base along with the confidence level generated from the model.

[0012] According to a second aspect of the present application, in at least one embodiment, A query module used to query a question and answer history knowledge base that stores multiple question and answer history histories, each containing a query context history and an answer history, and the confidence level of each question and answer history, based on a first query context, and to obtain at least one candidate question and answer that matches the semantics of the first query context and the confidence level of each candidate question and answer; A selection module used to select at least one candidate question-and-answer case that satisfies a predetermined threshold of confidence as a target case, A query context optimization device is provided, which includes a construction module used to construct a second query context based on the aforementioned target example and the first query context.

[0013] Alternatively, the device further includes an input module used to input the second query context into a model and to obtain the response generated from the model and its confidence level.

[0014] Alternatively, the device further includes an update module used to store the second query context and the answers generated from the model as newly generated question-and-answer examples, along with the confidence level generated from the model, in the question-and-answer history knowledge base.

[0015] According to a third aspect of the present application, in at least one embodiment, a query context optimization device is provided which includes a processor, memory, and a program or instruction stored in the memory and executable by the processor, wherein the program or instruction, when executed by the processor, realizes the method according to the first aspect.

[0016] According to a fourth aspect of the present application, in at least one embodiment, a computer-readable storage medium is provided which stores a program that, when executed by a processor, implements the method described in the first aspect.

[0017] According to a fifth aspect of the present application, in at least one embodiment, a computer program is provided which, when executed by a processor, includes computer instructions that implement the method described in the first aspect. [Effects of the Invention]

[0018] Compared with the prior art, the method and apparatus for optimizing query context according to the embodiments of the present application improve the generalization performance of prompts by using historical data in the process of searching for Q&A cases. In addition, since positive cases, negative cases, and the confidence level of cases are considered, the model can reduce the possibility of repeating past errors. The embodiments of the present application further optimize and organize different parts of the prompt using a text transformation diagram, making it easier to control and adjust various elements in prompt generation.

Brief Description of the Drawings

[0019] By reading the following detailed description of the preferred embodiments, various other advantages and merits will become apparent to those skilled in the art. The drawings are only used to illustrate the preferred embodiments and are not considered as a limitation to the present application. Also, throughout the drawings, the same components are denoted by the same reference numerals.

[0020] [Figure 1] It is a schematic flowchart of the method for optimizing query context in the embodiments of the present application. [Figure 2] It is a diagram showing specific examples of steps 11-12 of the optimization method in the embodiments of the present application. [Figure 3] It is a diagram showing a specific example of step 13 of the optimization method in the embodiments of the present application. [Figure 4] It is a diagram showing a specific example of text transformation diagram optimization in the embodiments of the present application. [Figure 5] It is a configuration diagram of the apparatus for optimizing query context in the embodiments of the present application. [Figure 6] It is another configuration diagram of the apparatus for optimizing query context in the embodiments of the present application.

Modes for Carrying Out the Invention

[0021] The following describes exemplary embodiments of the present application in more detail with reference to the attached drawings. While exemplary embodiments of the present application are shown in the drawings, it should be understood that the present application can be realized in various forms, not limited to the embodiments described herein. These embodiments are shown to allow for a more thorough understanding of the present application and to fully convey its scope to those skilled in the art.

[0022] Furthermore, the terms "one embodiment" or "one example" as used throughout the specification mean that certain features, structures, or characteristics related to an embodiment are included in at least one embodiment of the present application. Therefore, "in one embodiment" or "in one example" as used elsewhere in the specification does not necessarily refer to the same embodiment. Also, these specific features, structures, or characteristics may be incorporated into one or more embodiments in any and appropriate manner. Terms such as "first," "second," etc., in the specification and claims of the present application are not used to describe a specific order or sequence, but rather to distinguish similar subjects. It should be understood that any data used in this manner is appropriately interchangeable so that the embodiments of the present application described herein may be carried out in an order other than that illustrated or described herein. Furthermore, the terms "includes" and "have" and any variations thereof are intended to be non-exclusive. For example, a process, method, system, product, or apparatus including a series of steps or units is not necessarily limited to those steps or units explicitly listed, and may include other steps or units not explicitly listed or specific to those processes, methods, products, or apparatus. In the specification and claims, “and / or” indicates at least one of the linked subjects.

[0023] In each embodiment of this application, the magnitude of the numbers for each process described below does not indicate the order of execution. Rather, the execution order of each process is determined by its function and inherent logic, and should be understood as not constituting any limitation on the implementation processes of the embodiments of this application.

[0024] The following description provides examples without limiting the scope, applicability, or arrangement described in the claims. The function and configuration of the elements discussed can be modified without departing from the spirit and scope of this disclosure. Various procedures or components can be appropriately omitted, replaced, or added in each example. For example, the described method may be performed in a different order than described, and various steps may be added, omitted, or combined. Furthermore, features described with reference to some examples may be combined in other examples. In the embodiments of this application, prompt and query context usually refer to the same feature.

[0025] Figure 1 shows a query context optimization method according to an embodiment of the present application, and Figure 2 is a specific example based on the optimization method of the embodiment of the present application. As shown in Figure 1, the query context optimization method includes the following steps.

[0026] In step 11, a query is made to the question-and-answer history knowledge base based on the first query context, and at least one candidate question-and-answer case that matches the semantics of the first query context and the confidence level of each candidate question-and-answer case are obtained. Here, the question-and-answer history knowledge base stores multiple question-and-answer case histories and the confidence level of each question-and-answer case history. Each question-and-answer case history includes a query context history and an answer history.

[0027] Here, the first query context is typically text, and may be a query text (user question) specifically entered by the user, or it may be text that further integrates relevant knowledge based on the query text entered by the user. For example, Retrieval-augmented Generation (RAG) technology is used to search for relevant information to the query text and embed the retrieved information into the query text.

[0028] In the embodiment of the present application, a question-and-answer history knowledge base is pre-built, and the question-and-answer history knowledge base stores multiple question-and-answer case histories and the confidence level of each question-and-answer case history, and each question-and-answer case history includes a query context history and an answer history. Here, each question-and-answer case history includes one query context history and a corresponding answer history. The answer history is an answer generated by a model (e.g., a large-scale language model) for the query context history, and the confidence level of the answer history is the confidence level of the answer history generated by the model. In the embodiment of the present application, in step 11, the question-and-answer history knowledge base is queried using the first query context to obtain at least one candidate question-and-answer case that matches the semantics of the first query context. Here, matching the semantics means that the semantic similarity is greater than or equal to a predetermined threshold. For example, the semantic similarity between the first query context and each query context history of the question-and-answer example history is calculated, and query context histories whose semantic similarity is equal to or greater than the predetermined threshold are determined, thereby designating the question-and-answer example histories corresponding to these query context histories as candidate question-and-answer examples.

[0029] Using Figure 2 as an example, by querying the Q&A history knowledge base, three Q&A history entries that match the first query context (i.e., the current query context in Figure 2) are obtained as candidate Q&A examples. These are a positive example with an 89% confidence level, a positive example with a 21% confidence level, and a negative example with a 55% confidence level, respectively. In Figure 2, the green "√" indicates a positive example, the red "×" indicates a negative example, "Question" indicates the query context of a single Q&A history entry which may include the user's question, related knowledge (such as related knowledge for RAG generation), and thoughts (i.e., chain information of thoughts), and "Answer" indicates the answer generated by the model and its confidence level.

[0030] In step 12, at least one candidate question-and-answer case that satisfies a predetermined threshold of confidence is selected as the target case.

[0031] In this embodiment of the present invention, in step 12, one or more target cases can be obtained by selecting and targeting candidate question-and-answer cases whose confidence level meets a predetermined threshold (for example, above the predetermined threshold) based on the confidence level of each candidate question-and-answer case. Taking Figure 2 as an example, assuming that the predetermined threshold is 50%, a positive case with a confidence level of 21% is excluded from the above three question-and-answer case histories, thereby obtaining a positive case with a confidence level of 89% and a negative case with a confidence level of 55% as target cases.

[0032] In step 13, a second query context is constructed based on the target example and the first query context.

[0033] Herein, an embodiment of the present invention obtains the second query context in step 13 by embedding the first query context and the target example into corresponding modules in a prompt template. Herein, the prompt template includes a plurality of submodules, each of which includes at least a Q&A example module for embedding the target example. Of course, the prompt template further includes other modules for embedding the contents of the first query context, such as a prompt prefix module, a prompt suffix module, an output constraint module, and an extraction field definition / type / legal value module. Figure 3 provides an example of the modularization of a prompt template, in which the two target examples extracted in step 12 are each embedded in a Q&A example module.

[0034] Through the steps described above, the embodiment of the present invention can improve the performance of the constructed query context by using confidence levels to select candidate question-and-answer examples, selecting more reliable examples to build a query context, and minimizing the likelihood of past errors being repeated in the model.

[0035] Following step 13 above, the embodiment of the present invention inputs the second query context into the model and obtains the answer and its confidence level generated from the model.

[0036] Furthermore, the embodiment of the present application updates the question-and-answer history knowledge base based on newly generated answers. For example, the second query context and the answers generated from the model are used as newly generated question-and-answer examples and are stored in the question-and-answer history knowledge base along with the confidence level generated from the model.

[0037] In the embodiments of the present application, the question-and-answer history of the question-and-answer history knowledge base further includes case type indicator information for indicating the type of case, and the case types include positive cases and negative cases. In actual use, the embodiments of the present application receive user feedback information on the answers generated from the model. The feedback information is typically used to indicate whether the user is satisfied with the answer or whether the answer is correct. That is, based on the user feedback information, case type indicator information is generated for the newly generated question-and-answer case and stored in the question-and-answer history knowledge base. It can be seen that the embodiments of the present application improve the generalization performance of prompts by utilizing historical data in the search process of question-and-answer cases. Furthermore, because positive cases, negative cases and confidence levels of the cases are taken into consideration, the model can reduce the likelihood of repeating past errors.

[0038] To help the model better understand and complete tasks (for example, to understand user questions and generate answers), the Q&A history of the embodiments of the present application may further include Chain of Thought (CoT) information corresponding to the query context history. The Chain of Thought information is a series of sub-problems obtained by decomposing the query context history. The performance of the large model can be significantly improved by involving the large model step by step and decomposing a single complex problem into a series of intermediate steps (one step each of sub-problems) and solving them sequentially. The series of intermediate steps of reasoning described above constitutes a Chain of Thought. The Chain of Thought can enhance the reasoning ability of the large model, improve the interpretability of the answers generated by the large model, and enhance the controllability and flexibility of the resolution process of the large model. After introducing the Chain of Thought information, in step 11, the embodiments of the present application generate a first Chain of Thought corresponding to the first query context based on the first query context. When querying the aforementioned question-and-answer history knowledge base, the first query context and the first thought chain are used as matching texts, each query context history and its corresponding thought chain information in the question-and-answer history knowledge base are used as a single search text, and the semantic similarity between the matching text and each search text is calculated. Subsequently, search texts whose semantic similarity is equal to or greater than the predetermined threshold are determined, and the question-and-answer example histories corresponding to these search texts are designated as candidate question-and-answer examples.

[0039] As an alternative embodiment, the embodiment of the present application, after step 13, transforms the second query context based on a different predefined text transformation diagram structure to obtain at least two prompt candidates. Each prompt candidate is then input into a model, and the output response from the model is obtained. The performance of the prompt candidates is then evaluated based on the output response from the model. For example, the optimization process can be made more direct and efficient by directly evaluating the performance of the prompt candidates based on metrics such as the F1 score, accuracy, and recall rate obtained when the model generates the response. In this way, the embodiment of the present application optimizes the text transformation diagram structure based on the evaluated performance of the prompt candidates, and optimizes the text transformation function, for example, by heuristic search. Furthermore, the prompt candidate with the best performance and its corresponding response are newly generated as question-and-answer examples and stored in the question-and-answer history knowledge base along with the confidence level generated from the model. Of course, when storing in the question-and-answer history knowledge base, the thought chain information corresponding to the optimally performing prompt candidate may also be stored. The response corresponding to the optimal performance prompt candidate is output as the final response corresponding to the second query context.

[0040] Figure 4 provides an example of an optimization direction for a text transformation diagram, where each part of the prompt is transformed by multiple operators (e.g., text concatenation operators, text transformation intermediate operators). In Figure 3, the field description edge nodes represent the parts of the prompt, and the prompt may be the second query context described above. In Figure 4, node n i and n j For this, the text concatenation operator connects to the intermediate node n kBy synthesizing, the length of the text can be reduced, and the consumption of model computation resources can be decreased. The entire prompt can be seen as being divided into subprompts such as a "title" describing the task, term definitions, or fusion shots (few-shots, i.e., target Q&A examples). Once the knowledge context and fusion shots are prepared, the subprompts are transformed by applying text variants to the structure. Formally, the subprompt transformation process is a dynamic function diagram, where each node calculates a new value based on the output of its subnode. When the calculation reaches the root node, the final complete prompt is generated. By using text transformation diagrams to optimize and organize different parts of the prompt, it becomes easier to control and adjust the various elements in prompt generation.

[0041] Referring to Figure 5, one configuration of the query context optimization device according to the embodiment of the present application is: A query module 51 is used to query a question and answer history knowledge base that stores multiple question and answer history histories, each containing a query context history and an answer history, and the confidence level of each question and answer history, based on a first query context, and to obtain at least one candidate question and answer that matches the semantics of the first query context and the confidence level of each candidate question and answer. A selection module 52 is used to select at least one candidate question-and-answer case that satisfies a predetermined threshold of confidence as a target case, The system includes a construction module 53 used to construct a second query context based on the aforementioned target example and the first query context.

[0042] The above module enables the embodiment of the present invention to improve the performance of the query context.

[0043] Alternatively, the device further includes an input module used to input the second query context into a model and to obtain the response generated from the model and its confidence level.

[0044] Alternatively, the device further includes an update module used to store the second query context and the answers generated from the model as newly generated question-and-answer examples, along with the confidence level generated from the model, in the question-and-answer history knowledge base.

[0045] Alternatively, the aforementioned question-and-answer case history further includes case type indication information, where the case types include positive and negative cases. The above device is A receiving module used to receive user feedback information on the answers generated from the aforementioned model, The system further includes a storage module used to generate example type instruction information for the newly generated question-and-answer example based on the feedback information and to store it in the question-and-answer history knowledge base.

[0046] Alternatively, the question-and-answer history may further include thought chain information corresponding to the query context history.

[0047] Alternatively, the build module is further used to obtain the second query context by embedding the first query context and the target example into corresponding modules within a prompt template, where the prompt template includes a plurality of submodules, each of which includes a question-and-answer example module for embedding the target example.

[0048] Alternatively, the above device is Based on a predefined different text transformation diagram structure, the second query context is transformed to obtain at least two prompt candidates, Each prompt candidate is input into the model, and the response output from the model is obtained. Based on the response output from the model, the performance of the prompt candidates is evaluated, and the text conversion diagram structure is optimized based on the performance of the prompt candidates. The system further includes a text conversion module used to store newly generated question-and-answer examples of optimally performing prompt candidates and their corresponding answers, along with the confidence level generated from the model, in the question-and-answer history knowledge base.

[0049] Furthermore, each system according to the above embodiment is a device corresponding to the query context optimization method described above, and the implementation forms in each embodiment are all applicable to the embodiment of the device and can achieve the same technical effects. The device according to the embodiment of the present application can implement all the steps of the method implemented in the embodiment of the method described above and can achieve the same technical effects. Here, the parts of this embodiment that are the same as those in the embodiment of the method and the beneficial effects will not be described in detail.

[0050] Referring to Figure 6, this is another configuration diagram of a query context optimization device according to an embodiment of the present invention. The device includes a processor 601, a transceiver 602, a memory 603, a user interface 604, and a bus interface.

[0051] In the embodiment of the present invention, the device further includes a program stored in memory 603 and executable by processor 601.

[0052] The transceiver 602 is used to send and receive data under the control of the processor. The aforementioned processor 601 is A procedure to read a computer program in memory, query a question-and-answer history knowledge base which stores multiple question-and-answer history histories, each containing a query context history and an answer history, and the confidence level of each question-and-answer history, based on a first query context, and obtain at least one candidate question-and-answer case that matches the semantics of the first query context and the confidence level of each candidate question-and-answer case; A procedure for selecting at least one candidate question-and-answer case that satisfies a predetermined threshold of confidence as a target case, The procedure for constructing a second query context based on the aforementioned target example and the first query context is executed.

[0053] In the embodiment of this application, when the computer program is executed by the processor 601, it can implement each process of the embodiment of the query context optimization method described above and achieve the same technical effects. To avoid repetition, this will not be described in detail here.

[0054] In Figure 6, the bus architecture includes any number of interconnected buses and bridges, specifically connecting one or more processors, including processor 601, and various types of memory circuits, including memory 603. The bus architecture may also connect various other types of circuits, such as peripherals, regulators, and power management circuits. These are all publicly known in the art and will not be described further in this text. Interfaces are provided by the bus interface. The transceiver 602 may consist of multiple elements, i.e., including a transmitter and a receiver, and provides a unit that communicates with various other types of devices over a transmission medium. Depending on the user terminal, the user interface 604 may be an interface that connects internally or externally to necessary equipment. The connected equipment includes, but is not limited to, keypads, displays, speakers, microphones, and joysticks.

[0055] Processor 601 manages the bus architecture and normal processing. Memory 603 can store data used when processor 601 is working.

[0056] The apparatus in this embodiment is a device corresponding to the query context optimization method described above, and the implementation forms in each of the above embodiments can all be applied to the embodiment of the device and achieve the same technical effects. In this device, the transceiver 602 and the memory 603, and the transceiver 602 and the processor 601 are connected communicably by a bus interface, and the functions of the processor 601 can be realized by the transceiver 602, and the functions of the transceiver 602 can be realized by the processor 601. Herein, the device according to the embodiment of the present application can realize all the steps of the method realized in the embodiment of the method and achieve the same technical effects, so the parts and beneficial effects of this embodiment that are the same as those of the embodiment of the method will not be specifically described here.

[0057] Furthermore, in some embodiments of the present application, when executed by a processor, The steps include querying a question-and-answer history knowledge base that stores multiple question-and-answer history records, each containing a query context history and an answer history, and the confidence level of each question-and-answer history, based on a first query context, and obtaining at least one candidate question-and-answer case that matches the semantics of the first query context and the confidence level of each candidate question-and-answer case, A step of selecting at least one candidate question-and-answer case that satisfies a predetermined threshold of reliability as a target case, A computer-readable storage medium is provided which stores a program that implements the step of constructing a second query context based on the aforementioned target example and the first query context.

[0058] When the program is executed by the processor, it can implement all the implementations of the query context optimization method described above and achieve the same technical effect; therefore, to avoid repetition, it will not be described in detail here.

[0059] Furthermore, in the embodiments of the present application, a computer program including computer instructions is provided. When executed by the processor, these computer instructions can implement each process of the embodiment of the query context optimization method described above and achieve the same technical effects, and are not described in detail here to avoid repetition.

[0060] Those skilled in the art will understand that the units and algorithmic steps of each example described with reference to the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are ultimately performed by hardware or by software will depend on the specific application of the technical means and the design limitations. Those skilled in the art may implement the described functions in different ways for each specific application, but these implementations should not exceed the scope of this application.

[0061] For convenience and simplicity, the specific operating processes of the systems, apparatus, and units described above will not be repeated here; please refer to the corresponding processes in the above-described method embodiments. This will be obvious to those skilled in the art.

[0062] In the embodiments of this application, it should be understood that the disclosed apparatus and methods may be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For example, the division of units is merely a division of logical function, and there may be other division methods in actual implementation. For example, multiple units or components may be combined, integrated into another system, or some features may be ignored or not performed. Also, the coupling, direct coupling, and communication connections between each component shown or discussed may be indirect coupling or communication connections via interfaces, apparatus, or units, and may be electrical, mechanical, or of other forms.

[0063] The units described above as individual components may or may not be physically separated. The components shown as units may or may not be physical units. That is, they may be located in one place or in multiple network units. Some or all of these units can be selected as needed to achieve the objectives of the embodiments of this application.

[0064] Furthermore, each functional unit in each embodiment of the present application may be integrated into a single processing unit, physically provided separately, or two or more may be integrated into a single unit.

[0065] The aforementioned functions may be implemented in the form of software function modules and, if sold or used as independent products, stored on a computer-readable storage medium. Based on this understanding, the substantial or prior art contribution of the technical means of the present application, or the portion of such technical means, may appear in the form of a computer software program. The computer software program is stored on a storage medium and contains several instructions causing a computer device (which may be a personal computer, server, or network device) to perform all or some steps of the methods described in each embodiment of the present application. The storage medium includes various media capable of storing program code, such as U disks, mobile hard disks, ROMs, RAMs, magnetic disks, or optical disks.

[0066] The above description is a specific embodiment of the present application, but the scope of protection of this application is not limited to these. Any changes or substitutions that a person skilled in the art can easily conceive within the scope of the art disclosed herein are all included within the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

Claims

1. A method for optimizing the query context, The process involves querying a question-and-answer history knowledge base, which stores multiple question-and-answer history records, each containing a query context history and an answer history, and the confidence level of each question-and-answer history, based on a first query context, and obtaining at least one candidate question-and-answer case that matches the semantics of the first query context, as well as the confidence level of each candidate question-and-answer case. Select at least one candidate question-and-answer case that satisfies a predetermined threshold of confidence as the target case, A method for optimizing a query context, characterized by comprising: constructing a second query context based on the aforementioned target example and the first query context.

2. The method for optimizing a query context according to claim 1, further comprising inputting the second query context into a model and obtaining the response generated from the model and its confidence level.

3. The method for optimizing a query context according to claim 2, further comprising saving the second query context and the answer generated from the model as a newly generated question-and-answer example, along with the confidence level generated from the model, in the question-and-answer history knowledge base.

4. The aforementioned question-and-answer case history further includes case type indication information, and the case types include positive cases and negative cases. In the above query context optimization method, Receiving user feedback information on the answers generated from the aforementioned model, The query context optimization method according to claim 3, further comprising generating example type instruction information for the newly generated question-and-answer example based on the feedback information and storing it in the question-and-answer history knowledge base.

5. The query context optimization method according to claim 4, characterized in that the aforementioned question-and-answer history further includes thought chain information corresponding to the query context history.

6. Constructing a second query context based on the aforementioned target example and the first query context is: This includes embedding the first query context and the target example into the corresponding module in the prompt template to obtain the second query context, The query context optimization method according to claim 1, wherein the prompt template includes a plurality of submodules, and the plurality of submodules include a question-and-answer example module for embedding the target example.

7. Based on a predefined different text conversion diagram structure, the second query context is converted to obtain at least two prompt candidates, Each prompt candidate is input into the model, and the response output from the model is obtained. Based on the response output from the model, the performance of the prompt candidates is evaluated, and the text conversion diagram structure is optimized based on the performance of the prompt candidates. The query context optimization method according to claim 6, further comprising: using the optimal performance prompt candidates and their corresponding answers as newly generated question-and-answer examples, and storing them together with the confidence level generated from the model in the question-and-answer history knowledge base.

8. A query context optimization device, A query module used to query a question-and-answer history knowledge base that stores multiple question-and-answer history histories, each containing a query context history and an answer history, and the confidence level of each question-and-answer history, based on a first query context, and to obtain at least one candidate question-and-answer case that matches the semantics of the first query context, and the confidence level of each candidate question-and-answer case; A selection module used to select at least one candidate question-and-answer case that satisfies a predetermined threshold of confidence as a target case, A query context optimization device characterized by including a construction module used to construct a second query context based on the aforementioned target example and the first query context.

9. The query context optimization apparatus according to claim 8, further comprising an input module used to input the second query context into a model and to obtain the answer generated from the model and its confidence level.

10. The query context optimization device according to claim 9, further comprising an update module used to store the answers generated from the second query context and the model as newly generated question-and-answer examples, along with the confidence level generated from the model, in the question-and-answer history knowledge base.

11. A computer program that, when executed by a processor, includes computer instructions that implement the query context optimization method described in any one of claims 1 to 7.