Prompt generation method, computer equipment and computer program
By using block processing and caching of fragment information, the problem of excessively long prompt words in multi-turn dialogue scenarios is solved, improving the efficiency and accuracy of model response and ensuring the coherence and conciseness of dialogue.
Patent Information
- Application Number
- CN202511234814.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-29
- Publication Date
- 2025-11-28
AI Technical Summary
In multi-turn dialogue scenarios, the length of prompts increases continuously, leading to wasted computing resources and a decline in model response quality, which affects user experience.
The response information generated by the target model is divided into multiple fragments, and the minimum number of semantic units in each fragment is less than that in the original response information. Target fragment information associated with new question information is retrieved, and prompt words are created based on these fragments to help the model understand the context.
It effectively reduces the length of prompts, improves the efficiency and accuracy of response generation, ensures the coherence and conciseness of dialogue, and reduces redundant information.
Smart Images

Figure CN121031591A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a prompt word generation method, computer device, and computer program. Background Technology
[0002] With the application and development of artificial intelligence technology, dialogue systems based on large models (LM) have been widely used in many application scenarios such as intelligent customer service, education / training, medical consultation, personal digital assistants, content / creative generation, and games / virtual social interaction, thanks to their powerful semantic understanding, contextual memory, and multi-turn dialogue capabilities.
[0003] In multi-turn dialogue scenarios, historical dialogues are typically concatenated with the current question to form prompts. This helps the large model understand the context of the multi-turn dialogue and accurately generate responses to the current question. However, as the number of dialogue turns increases, the historical dialogue content within the prompts grows, causing the prompt length to increase continuously, sometimes exceeding the maximum number of the smallest semantic units (tokens) allowed by the large model. This not only wastes computational resources but may also reduce the quality of the model's response and negatively impact the user experience. Summary of the Invention
[0004] In view of the above problems, this application provides the following solution:
[0005] The first aspect of this application provides a method for generating prompt words, the method comprising:
[0006] Obtain the first response information for output; the first response information is the response information generated by the target model corresponding to the first question information;
[0007] The first response information is segmented to obtain multiple first fragment information associated with the first response information;
[0008] The plurality of first fragment information is cached; the number of the smallest semantic units input to the target model corresponding to each first fragment information is less than the number of the smallest semantic units input to the target model corresponding to the first response information;
[0009] In response to user input of second question information belonging to the same dialogue scenario as the first question information, target segment information associated with the second question information is retrieved from the plurality of first segment information, and the target segment information is used as a memory of the second question information;
[0010] Based on the second question information and the target fragment information, a prompt word corresponding to the second question information is created according to the prompt word template used to guide the target model; the prompt word includes the target fragment information required to help the target model understand the context of the dialogue scenario when the target model generates the second response information of the second question information.
[0011] A second aspect of this application provides a computer device, the computer device comprising: at least one communication element, at least one memory, and at least one processor, wherein:
[0012] The communication element is used to obtain the question information input by the user;
[0013] The memory is used to store multiple computer instructions;
[0014] The processor is used to load and execute the computer instructions to implement the various steps of the prompt word generation method provided in the first aspect of this application.
[0015] The third aspect of this application provides an artificial intelligence-based computer program that can be embedded in an application or operating system as part of the application or operating system to perform the various steps of the prompt word generation method provided in the first aspect of this application. Attached Figure Description
[0016] The above and other features, advantages, and aspects of the embodiments of this disclosure will become more apparent from the accompanying drawings and the following detailed description. Throughout the drawings, the same or similar reference numerals denote the same or similar elements. It should be understood that the drawings are schematic, and the originals and elements are not necessarily drawn to scale.
[0017] Figure 1 This is a flowchart illustrating a prompt word generation method proposed in Embodiment 1 of this application;
[0018] Figure 2 This is a flowchart illustrating a prompt word generation method proposed in Embodiment 2 of this application;
[0019] Figure 3 This is a flowchart illustrating a prompt word generation method proposed in Embodiment 3 of this application;
[0020] Figure 4 This is a flowchart illustrating a prompt word generation method proposed in Embodiment 4 of this application;
[0021] Figure 5 This is a flowchart illustrating an optional application scenario of a prompt word generation method proposed in an embodiment of this application.
[0022] Figure 6 This is a schematic diagram of the structure of a prompt word generation device provided in an embodiment of this application;
[0023] Figure 7 This is a schematic diagram of the hardware structure of a computer device applicable to the prompt word generation method proposed in this application. Detailed Implementation
[0024] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is only for explaining specific embodiments and is not intended to limit the application. The embodiments of this application are described below with reference to the accompanying drawings. It will be understood by those skilled in the art that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0025] The terms "first," "second," etc., used throughout this application and in the accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of units is not necessarily limited to those units, but may include other units not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0026] To address the technical problems described in the background section, this application provides a method for generating prompt words. The method for generating prompt words according to this application will be described in detail below with reference to the accompanying drawings.
[0027] Reference Figure 1 This is a flowchart illustrating a prompt word generation method proposed in Embodiment 1 of this application. This method can be applied to computer devices, such as terminal devices or servers, such as applications with question-and-answer functionality running on the terminal device or cloud services provided by a cloud server. Alternatively, it can be implemented by a server in conjunction with a terminal device to achieve the prompt word generation method proposed in this application. Figure 1 As shown, the prompt word generation method proposed in this embodiment may include, but is not limited to:
[0028] Step S11: Obtain the first response information for output; the first response information is the response information generated by the target model corresponding to the first question information;
[0029] In this embodiment, the target model can be an AI model based on large-scale pre-training and possessing complex dialogue capabilities, such as a general-purpose large model. This model can be obtained using technologies such as Transformer or its architectural variants (e.g., using only encoder-only / decoder-only, encoder-decoder, or MoE (Mixture of Experts, a neural network architecture)) or other infrastructures, combined with distributed training techniques (e.g., using 3D parallel strategies such as data parallelism, model parallelism, and pipeline parallelism). Thus, in dialogue system applications, the target model, leveraging its powerful generalization capabilities such as task processing and context learning, as well as its emergent capabilities such as complex reasoning, zero / few-shot learning, and cross-modal understanding, accurately understands the query intent of the user's input question information (Query), generates and outputs corresponding responses, and meets the user's needs.
[0030] The target model can be a generative model or a generative language model (GLM), such as large language models (LLMs), GPT (Generative Pre-trained Transformer) series models, large visual models, multimodal large models, and other general large models. This application does not restrict the type of target model.
[0031] Based on this, in a dialogue scenario, the computer device responds to the user's input of a first question by calling the target model to generate a first response to the first question. This response is then output to the user. When the first question is the initial input in any dialogue scenario, the context of that scenario does not exist. In this case, the first question can be used as a prompt, or Retrieval-Augmented Generation (RAG) can be employed to retrieve relevant knowledge fragments / texts from the knowledge base. These fragments are then concatenated with the first question to form a prompt, which is then input into the target model to generate the first response. This application does not detail the implementation method of how the target model generates the first response.
[0032] When the first question information is a question information that is not the first input in any dialogue scenario, in order to improve the accuracy and efficiency of the response, this application can filter fragment information related to the first question information from the historical dialogue when creating prompt words in combination with the historical dialogue in the dialogue scenario, so as to reduce the length of the prompt words, while retaining the context required to assist the target model in generating the first response information of the first question information, thereby improving the accuracy of the first response information generated by the target model based on the prompt words. The process of creating the prompt words can refer to the steps of creating the prompt words for the second question information described below, which will not be detailed in this embodiment.
[0033] The question information input by the user in each round can be one or more data types, including text, image, video, or audio. Different data types of question information can be obtained by corresponding input components. For example, the user can input question information by voice, or by using other input components such as fingers, styluses, mice, keyboards, or joysticks to perform input operations on the touch screen or accessories (such as input operations on the interactive interface), so that the computer device can obtain the question information input by the user in this round. This application does not restrict the data type and input method of the question information input by the user in each round, and can flexibly select according to the actual task processing needs.
[0034] For the response information generated by the target model to answer the questions in the current round of input, the target model can directly feed it back or feed it back to the corresponding output component in the user terminal, such as a display screen or audio player, after data format conversion, and the output component will output the response information. In this embodiment of the application, in order to facilitate the creation of prompt words for subsequent input questions and improve the accuracy of the response information generated by the target model, for the response information used to output as an answer to the input questions in the current round, instead of directly caching it for concatenation with the input questions in the next round to construct prompt words, this application proposes to process the question information into multiple fragments of information and then cache them according to the method described in the following steps, so that fragments of information related to the input questions in the next round can be selected to create prompt words, thereby reducing the length of the prompt words.
[0035] Therefore, for the response information generated by the target model in each round to the question information, while outputting it to the user, the response information used for output can be obtained. According to the methods described in steps S12 and S13, the response information obtained in this round is processed to prepare for the creation of prompt words for the next round of question information. This helps to improve the creation efficiency of the prompt words, greatly reduces the length of the prompt words after multiple rounds of dialogue, and retains the context used to help the target model understand the question information for the next round, thereby improving the efficiency and accuracy of response generation.
[0036] Step S12: The first response information is segmented to obtain multiple first fragment information associated with the first response information;
[0037] Step S13: Cache multiple first fragment information; the number of minimum semantic units corresponding to the input target model for each first fragment information is less than the number of minimum semantic units corresponding to the input target model for the first response information;
[0038] Following the above analysis, for any response given to the user in any round of dialogue within a conversational scenario, such as the first response information obtained in this instance, before caching, it can be processed by segmentation, dividing it into multiple first fragment information. Each first fragment information can represent a complete semantic meaning, rather than simply dividing the first response information into multiple parts and treating each part as a first fragment information. To ensure the smooth and reliable execution of subsequent retrievals, this application can combine the overall semantics of the first response information to complete missing parts in the subject-verb-object grammatical structures of each segmented part, or replace the referential parts with corresponding entities (parsing pronouns such as "it," "he," and "this," or the specific content referred to by elliptical sentences, and replacing them with the referent entities), so as to obtain semantically complete and clear fragment information, thus achieving semantic alignment between each first fragment information and the first response information. This application does not limit the segmentation processing method in step S12.
[0039] In one possible implementation, this application may adopt the RAG processing method to convert the first response information into multiple first fragment information, that is, multiple chunks associated with the first response information. Each chunk may be a semantically clear and complete statement / paragraph, etc., but is not limited to this chunking processing method.
[0040] In practical applications of this application, due to the diverse data types of the first response information, for text-based first response information, semantic segmentation can be directly performed, processing each segmented text portion into semantically complete first fragment information. When the first response information is image data, to avoid segmenting key objects (such as a face), object detection can be performed on the image data first to identify key object regions. Then, non-key object regions can be segmented according to preset segmentation rules, such as using overlapping segmentation to avoid loss of edge information, or dynamically adjusting the block size (the length of the fragment information). For example, densely texted image regions are segmented into smaller blocks than sparsely texted image regions (i.e., the corresponding first fragment information is shorter). This application does not restrict the segmentation processing method for first response information of different data types; it can be determined as needed.
[0041] In one possible implementation, to facilitate subsequent retrieval, the semantically complete segmented information can be vectorized, where each first segment can be a vector. During this vectorization process, different types of encoders (such as text, natural images, or images containing text) can be used to obtain multiple first segment information in vector form for different information types (e.g., text encoder, visual encoder, or image-text encoder). Alternatively, this application can vectorize the first response information based on an encoder to obtain the corresponding response feature vector, and then perform segmentation to obtain multiple first segment information in vector form.
[0042] Thus, when caching multiple first fragment information associated with the first response information, a vector index engine such as FAISS or Milvus can be used to build corresponding vector indexes to cache each first fragment information, so that subsequent queries can be made based on the vector index to retrieve each first fragment information associated with the first response information. For first fragment information that is not in vector form, a response identifier of the first response information can also be added, such as a timestamp or the round number of the first response information. As needed, a scene identifier of the dialogue scenario to which the first response information belongs can also be added. This application does not restrict the caching method for each first fragment information associated with each response information in the same dialogue scenario.
[0043] Therefore, this application can employ a session-level caching approach to associate the response information of each round of dialogue within the same dialogue scenario (in this application, a multi-turn dialogue scenario) with various fragment information, thereby achieving short-term memory of the dialogue scenario context and maintaining the dialogue sessions within that scenario. The implementation method is not limited in this application. Furthermore, the question information in each round of the dialogue scenario is related; typically, the question information input in the current round is related to the question information input in the previous round, thus ensuring the continuation of the user's query intent, i.e., the query intent of adjacent rounds of question input is related.
[0044] It should be understood that the lengths of the various first fragment information pieces associated with the first response information obtained through the block processing in step S12 are usually not consistent. That is, the number of tokens converted from each first fragment information piece may be different. A token refers to the smallest semantic unit input to the target model (an indivisible semantic unit that can be processed using a word segmenter / segmentation rules). This application does not impose any restrictions on the size of the number of tokens corresponding to each first fragment information piece, and it can be determined as appropriate. However, regardless of how the first response information is block-processed, the number of tokens for each first fragment information piece is less than the number of tokens corresponding to the first response information piece. The sum of the number of tokens for each first fragment information piece is basically the same as the number of tokens corresponding to the first response information piece. The difference lies in the completion or replacement of subject, verb, object, and other words during the acquisition of the first fragment information piece, but the sum of the number of tokens for some first fragment information pieces is less than the number of tokens corresponding to the first response information piece.
[0045] Step S14: In response to the user input of a second question that belongs to the same dialogue scenario as the first question information, retrieve the target segment information associated with the second question information from multiple first segment information, and use the target segment information as a memory of the second question information;
[0046] In this application, based on the above analysis, for non-first-round question information in multi-turn dialogues, it is hoped that historical fragment information retained from the multi-turn dialogue can be used to create prompt words for the question information, thereby improving the quality of the prompt words and ultimately improving the response information generated by the target model based on the prompt words. Therefore, after detecting the second question information input by the user, it can first be determined whether there is historical question information belonging to the same dialogue scenario as the second question information. If there is no historical question information, it means that the second question information is the first-round question information of the current dialogue scenario, and prompt words for the second question information can be directly created based on the second question information.
[0047] Conversely, if historical question information exists, it indicates that the second question information is not the first-round question information in the current dialogue scenario. To improve the quality of prompt word generation and the accuracy of the response information generated by the target model, while avoiding excessively long prompt words that exceed the maximum length allowed by the target model's input, thus affecting the target model's performance (such as reducing the processing efficiency and accuracy of the target model's response information generation), this application will retrieve target fragment information associated with the second question information from the various first fragment information cached in the current dialogue scenario (i.e., various historical fragment information associated with historical response information). This includes the first fragment information with the highest matching degree with the second question information, or k (e.g., 2 or 3, etc., this application does not limit the value of K) first fragment information with a high matching degree, as the memory of the second question information, used to construct the prompt words for the second question information.
[0048] It should be noted that this application does not limit the number of first fragment information contained in the target fragment information. The number can be determined based on factors such as the number of dialogue rounds maintained in the short-term memory of a dialogue scenario, the hardware resources of the target model deployment device, and the required dialogue response speed, to ensure that the length of the prompt words in the last round of the dialogue scenario (such as the number of tokens corresponding to the prompt words) is less than the maximum length allowed by the target model input (i.e., the maximum number of tokens allowed for input). For example, if a dialogue scenario contains many dialogue rounds / insufficient hardware resources / high real-time response requirements, the number of retrieved target fragment information may be small, and one target fragment information is preferred; conversely, the number of retrieved target fragment information can be appropriately increased to enrich the prompt words and improve the richness and accuracy of the generated response information.
[0049] The determination of whether the first and second question information belong to the same dialogue scenario (i.e., a multi-turn dialogue scenario) can be based on the definition of the dialogue scenario. For example, question information sharing the same dialogue identifier, m consecutive turns of dialogue, input time within a preset dialogue time window, related query intents across turns (intent inheritance / continuation), and input time between user-initiated dialogue creation / start / end commands are considered to be within the same dialogue scenario. This application does not restrict the implementation method for identifying question information within the same dialogue scenario. It should be understood that the response information corresponding to the question information in each turn of dialogue can be processed in blocks as described above, caching the various fragments associated with each response information.
[0050] Step S15: Based on the second question information and the target fragment information, create prompt words corresponding to the second question information according to the prompt word template used to guide the target model.
[0051] Combination Figure 2 The flowchart of the prompt word generation method shown in this application embodiment is as follows: according to the method described above, the target fragment information associated with the second question information is retrieved from the various fragment information cached in the historical response information of the current dialogue scenario. That is, after the first fragment information associated with the first question information is cached, the target fragment information and the second question information can be directly filled into the corresponding variables in the prompt word template used to guide the target model to create a prompt word corresponding to the second question information. Alternatively, the target fragment information and the second question information retrieved this time can be merged with the prompt word created in the previous round to create a prompt word corresponding to the second question information according to the prompt word template of the multi-round dialogue. This application does not limit the implementation method of step S15.
[0052] Therefore, the prompt words created in the embodiments of this application may include: target fragment information needed to help the target model understand the context of the dialogue scenario (i.e., the current dialogue scenario) when the target model generates the second response information for the second question information, but are not limited to this.
[0053] In some embodiments, in conjunction with the above description of multi-turn dialogue scenarios, the prompt word template of this application for multi-turn dialogue scenarios takes into account contextual coherence, intent inheritance, and task orientation. Within the same dialogue scenario, as the number of dialogue turns increases, the prompt word template can be incrementally updated so that the prompt words created accordingly include information on each question already input in the current dialogue scenario (i.e., information on each historical question and information on the currently input second question), as well as target fragment information retrieved in the corresponding turn. Compared to prompt word generation methods that include historical response information, this application can effectively control the length of the prompt words to avoid reducing the efficiency of dialogue operation due to excessively long prompt words. It also ensures that the prompt words generated in each turn contain the key information currently generated in the dialogue scenario, ensuring dialogue coherence and accuracy. This allows the target model to accurately understand the context of the dialogue scenario based on the prompt word content, guaranteeing the accuracy of the generated response information, reducing redundant information, and making the dialogue more concise and fluent.
[0054] Of course, for the above-mentioned prompt word template, this application can also adopt a full update method, that is, when generating prompt words corresponding to the input question information in each round of dialogue, the target fragment information associated with the second question information in each historical round is retrieved from all historical fragment information associated with the current dialogue scenario cache, that is, from the historical fragment information associated with each historical response information stored separately. The corresponding variables in the prompt word template are then filled in by combining the corresponding historical question information and the second question information, and prompt words corresponding to the second question information are created. This application does not limit the implementation method of step S15.
[0055] In summary, in the embodiments of this application, in a multi-turn dialogue based on a target model, the response information generated by the target model for output (such as feedback to the user) in each turn is processed into multiple fragment information associated with the response information. Thus, when responding to new question information input by the user that is not in the first round (such as the second question information mentioned above) and creating its prompt words, the target fragment information associated with the new question information will be retrieved from these fragment information and used as a memory of the new question information to create the prompt words corresponding to the new question information. Compared with combining the complete response information containing the target fragment information to create the prompt words corresponding to the new question information, since the number of tokens corresponding to the target fragment information is less than the number of tokens corresponding to the complete response information, this application greatly shortens the length of the prompt words. Moreover, since the target fragment information is semantically complete and related to the new question information, the created prompt words retain the key information in the historical dialogue, reduce redundant information, and improve the efficiency and accuracy of the dialogue.
[0056] It should be noted that the prompt word generation method proposed in this application is applicable to multi-turn dialogue scenarios. This multi-turn dialogue scenario refers to the continuous, context-dependent multiple information interactions between a user and a dialogue system (such as a chatbot or intelligent assistant) based on a target model in human-computer interaction, in order to complete a specific goal / task or topic. Unlike single-turn dialogue (i.e., a question-and-answer scenario), the multi-turn dialogue scenario proposed in this application requires the system to remember and understand the context of the current dialogue in order to provide coherent and accurate responses. Therefore, the dialogue scenario proposed in this application has core characteristics such as the continuous evolution of the dialogue state, the preservation of dialogue history (such as the original record of multi-turn interactions between the user and the system, i.e., the question information input by the user and the corresponding response information generated by the target model fed back by the dialogue system), and the dependency of contextual information. Subsequent responses not only depend on the currently input question information but also on the previous relevant dialogue history to correctly understand the currently input question information, ensuring that the response information to the question information is not only grammatically correct but also coherent and relevant to the dialogue history.
[0057] As can be seen, the prompt generation method proposed in this application needs to maintain the dialogue scenario to which the user-input question information belongs. For example, based on the entire dialogue history, the current dialogue state is updated and maintained in real time (i.e., tracked) to indicate whether the current dialogue scenario / dialogue interaction window has ended, thereby determining whether there is a dialogue history in the current dialogue scenario to which the current input question information belongs, that is, determining whether the second question information and the first question information belong to the same dialogue scenario, but it is not limited to the dialogue state tracking method described in this application.
[0058] In one possible implementation, due to the semantic coherence of the context within the same dialogue scenario, this application can perform semantic similarity analysis on the second question information input by the user and the first question information (historical question information) to obtain the semantic similarity between the second question information and the first question information. By comparing this semantic similarity with a pre-configured similarity threshold, it can be determined whether the second question information and the first question information belong to the same dialogue scenario. Thus, in response to the semantic similarity being greater than the similarity threshold, the computer device determines that the second question information and the first question information belong to the same dialogue scenario. When creating the prompt word for the second question information, it can be implemented according to the methods described in steps S24 and S25. The similarity threshold can be the minimum semantic similarity between two question information belonging to the same dialogue scenario. To improve the reliability of judging question information belonging to the same dialogue scenario, this application configures a larger similarity threshold. This application does not limit its value and can determine it based on the actual requirements of the actual dialogue scenario type.
[0059] In one possible implementation, since in practical applications, the time of each round of dialogue for tasks or topics is usually continuous, and the interaction for that task or topic ends within a certain duration (usually a short duration), followed by an interaction for another task or topic, this application can determine the historical duration of each round of dialogue within the same dialogue scenario based on the dialogue history data of each dialogue scenario. This duration can be used as the duration of a dialogue time window to identify whether different question information belongs to the same dialogue time window, i.e., to determine whether different question information belongs to the same dialogue scenario. The dialogue time window can represent the first and last input times within the same dialogue scenario, i.e., the start and end times of the same dialogue scenario. The difference between these two times is the continuous interaction duration of multiple rounds of dialogue within the same dialogue scenario, i.e., the duration of a dialogue time window.
[0060] Based on this, in the absence of a clear end signal for the dialogue (such as "goodbye" or "no more questions"), questions entered continuously by the user within a short period of time (such as 15 minutes or 30 minutes, which can be flexibly configured according to the actual situation) can be identified as the same dialogue scenario. In this regard, this application can configure a corresponding input time (timestamp) for each question entered by the user, so as to identify multiple rounds of dialogue in the same dialogue scenario by the question information entered multiple times within the duration of a dialogue time window.
[0061] Thus, after detecting the new question information (second question information) input by the user, the input time of the second question information can be determined, and it can be compared with the input time of the first question information input by the user last time. The input time difference between the second question information and the first question information can be determined, and the input time difference can be compared with the duration of a pre-configured dialogue time window. If the input time difference is less than the duration of a dialogue time window, it indicates that the second question information and the first question information belong to the same dialogue scenario, which can be implemented according to the methods described in steps S24 and S25.
[0062] Conversely, if the input interval between the first and second question information is too long—that is, the input time difference is greater than or equal to the duration of a dialogue time window—it indicates that the second and first question information do not belong to the same dialogue scenario. If the first question information is an input adjacent to the second question information, then the second question information is determined to be the first round of input in the current dialogue scenario, while the first question information could be the last round of input in the previous dialogue scenario. This first question information and its associated cached fragments cannot be used as memory for the second question information to help the target model understand the context of the dialogue scenario in which the second question information resides. In this case, following the description above of the method for creating prompts corresponding to the first round of question information, prompts corresponding to the second question information can be created to avoid adding cached memories of other dialogue scenarios to these prompts, which could interfere with the target model's understanding of the current dialogue scenario's context and lead to inaccurate responses generated by the target model.
[0063] In one possible implementation, to achieve short-term memory for each question information and avoid creating excessively long prompt words, this application can also constrain the number of dialogue rounds within the same dialogue scenario. This allows for the identification of the most recent rounds (e.g., 5-10 rounds, which can be denoted as the first dialogue round threshold; this threshold can be configured based on actual circumstances or dialogue scenario type, and this application does not impose any restrictions on this) as belonging to the same dialogue scenario. This allows the computer device to record the number of rounds of the question information input by the user each time. This can be done by statistically analyzing the detected dialogue start signal or restarting the statistical analysis after the previous dialogue scenario ends. The computer device can then determine the difference in dialogue rounds between the second and first question information input by the user. If this difference is less than the first dialogue round threshold, it can be determined that the second and first question information belong to the same dialogue scenario, and the methods described in steps S24 and S25 above can be executed to create the prompt word corresponding to the second question information. Conversely, if the difference is less than the threshold, the prompt word can be created according to the traditional prompt word generation method. Of course, this application can also combine other methods described in the context for determining whether different question information belongs to the same dialogue scenario to further determine whether misjudgments are made.
[0064] In one possible implementation, this application can also determine whether different input question information belongs to the same dialogue scenario by using explicit dialogue identifiers. In this case, the system will assign a corresponding dialogue identifier, such as a dialogue ID, to each new dialogue scenario / dialogue interaction window, and require subsequent input question information to carry this dialogue identifier, so as to determine whether the corresponding question information belongs to the same dialogue scenario by detecting whether the dialogue identifiers carried by each question information are consistent.
[0065] Therefore, after the computer device determines the dialog identifier associated with the second question information input by the user (i.e., the dialog identifier carried in this input request, which also includes the second question information input this time), in response to the dialog identifier being the same as the dialog identifier associated with the first question information, it determines that the second question information and the first question information belong to the same dialog scenario, and continues to execute the method described in steps S24 and S25 above to create the prompt word corresponding to the second question information; conversely, if it determines that the second question information and the first question information do not belong to the same dialog scenario, and if there is no historical question information belonging to the same dialog scenario as the second question information, the prompt word corresponding to the second question information can be created according to the traditional prompt word generation method.
[0066] In some embodiments, to improve the accuracy and reliability of determining whether different question information belongs to the same dialogue scenario, this application can combine the various detection methods listed above. (Refer to...) Figure 3 The flowchart shown in Embodiment 3 of this application illustrates a prompt word generation method. This embodiment can describe another optional implementation method for determining whether the second question information and the first question information belong to the same dialogue scenario, such as... Figure 3 As shown, the method may include:
[0067] Step S31: Determine whether the second question information entered by the user is associated with the second dialogue identifier. If yes, proceed to step S32; otherwise, proceed to step S33.
[0068] Step S32: Detect whether the second dialogue identifier is the same as the first dialogue identifier associated with the first question information. If yes, proceed to step S37; if no, proceed to step S38.
[0069] Step S33: Determine the input time difference between the second question information and the first question information;
[0070] Step S34: Detect whether the input time difference is greater than the duration of a dialog time window; if yes, proceed to step S37; if no, proceed to step S35.
[0071] In some other embodiments, as analyzed above, this application can determine whether the second question information and the first question information belong to the same dialogue scenario by detecting whether the difference in dialogue rounds between the second question information and the first question information is greater than the first dialogue round threshold. The implementation process can be referred to the description of the corresponding part of the above embodiments.
[0072] Step S35: Perform semantic similarity analysis on the second question information and the first question information to obtain the corresponding semantic similarity.
[0073] Step S36: Detect whether the semantic similarity is greater than the similarity threshold; if yes, proceed to step S37; if no, proceed to step S38.
[0074] Step S37: Determine that the second question information and the first question information belong to the same dialogue scenario;
[0075] Step S38: Determine that the second question information and the first question information do not belong to the same dialogue scenario.
[0076] It should be noted that the detection method for determining whether two pieces of question information belong to the same dialogue scenario includes, but is not limited to, the combination of the three dimensions described in this embodiment. It can also be implemented by combining two or other dimensions. The implementation process is similar, and this application will not provide detailed examples of each one.
[0077] Furthermore, the duration, round threshold, or similarity threshold of the aforementioned dialogue time window can be pre-configured fixed values, meaning that the duration, round threshold, or similarity threshold are the same for different dialogue scenarios. Preferably, at least one of the aforementioned duration, round threshold, and similarity threshold of the dialogue time window can be configured based on the type of the current dialogue scenario, thereby allowing different types of dialogue scenarios to have different pre-configured dialogue time window durations, round thresholds, and similarity thresholds. This application does not impose any restrictions on this.
[0078] For example, in dialogue scenarios with strict requirements for question-and-answer accuracy (high rigor), such as multi-turn dialogues in professional fields like medical / legal consultation, a higher similarity threshold is configured, such as 0.85; the number of turns threshold and the duration of the dialogue time window are both relatively small, such as a number of turns threshold of 5 and a dialogue time window duration of 15 minutes. In dialogue scenarios with less stringent requirements for question-and-answer accuracy, such as e-commerce customer service scenarios, the similarity threshold can be appropriately reduced, such as 0.6; the number of turns threshold and the duration of the dialogue time window can both be larger, such as a number of turns threshold of 10 and a dialogue time window duration of 24 hours. This application does not limit the size of each threshold.
[0079] In some embodiments, based on the above analysis, the requirements for response information generated based on the target model may differ for different types of dialogue scenarios. Some require high-precision responses, while others require adaptation to business needs. Different semantic similarity analysis methods can be used to determine the semantic similarity between the second question information and the first question information.
[0080] In one possible implementation, for dialogue scenarios requiring high accuracy, the semantic similarity between the second and first question information can be determined based on vector similarity and entity association (entity inheritance). For dialogue scenarios requiring high business adaptability, the semantic similarity between the second and first question information can be determined based on query intent association / transition relationship and domain matching degree, but is not limited to the semantic similarity analysis method described in this application.
[0081] In some other embodiments, within a natural language processing scenario, the semantic similarity analysis implementation method in step S35 can further perform entity recognition on the second question information input by the user. After obtaining at least one second entity associated with the second question information, the at least one second entity is matched with each first entity associated with the first question information to obtain the semantic similarity between the second question information and the first question information. Optionally, the entity overlap / matching degree between the second entity and the first entity, or the number of key first entities contained in each second entity, can be obtained to determine / convert into the semantic similarity between the second question information and the first question information. This can then be compared with a corresponding threshold to determine whether the second question information and the first question information belong to the same dialogue scenario.
[0082] In this application, the entity recognition can be named entity recognition (NER), which refers to named entities, such as names of people, places, organizations, times, products, or proprietary names of specific fields, which are words or phrases in text that have specific meanings and refer to a certain object in the real world. This application does not limit the entity recognition method, such as rule-based / machine learning / deep learning / pre-trained models to realize named entity recognition of problem information. The implementation process is not described in detail in this application.
[0083] In another possible implementation, as analyzed above, it can be determined whether they belong to the same dialogue scenario by analyzing the intent chains of different question information. Therefore, step S35 can specifically include: performing intent recognition on the second question information input by the user to obtain the second query intent of the second question information, obtaining the intent transition weight between the first query intent and the second query intent of the first question information, such as obtaining the intent transition weight based on the second query information and a predefined intent transition matrix. Then, the intent transition weight or the transformation processing result can be used as the semantic similarity between the second question information and the first question information. By comparing it with the corresponding intent transition threshold, it can be determined whether the second question information and the first question information belong to the same dialogue scenario.
[0084] The intent transition matrix is a probabilistic model that describes the patterns and probabilities of a user switching from the current intent to the next intent during a dialogue (especially a task-oriented dialogue). This application can obtain the matrix based on statistical analysis of historical dialogue data from the same dialogue scenario; it can also be constructed based on rules and prior knowledge, etc. This application does not restrict the construction method. Since each element of the intent transition matrix can be the probability of the next intent occurring given the current intent, after determining the candidate intent to which the first query intent is likely to transition, the intent transition weight of the second query intent is determined based on the matching degree / similarity between the candidate intent and the second query intent. The larger the value, the greater the probability of the first query intent transitioning to the second query intent, and the more likely they belong to the same dialogue scenario.
[0085] Reference Figure 4 This is a flowchart illustrating a prompt word generation method proposed in Embodiment 4 of this application. Figure 4 As shown, the method for generating prompt words may include, but is not limited to:
[0086] Step S41: Obtain the first response information for output; the first response information is the response information generated by the target model corresponding to the first question information;
[0087] Step S42: The first response information is divided into multiple initial fragment information; each initial fragment information contains a complete semantic unit;
[0088] Step S43: Based on the entity relationship between multiple initial fragment information, adjust the corresponding initial fragment information to obtain multiple first fragment information associated with the first response information;
[0089] In this embodiment, during the block processing of the response information used for output in each round, in addition to the implementation method described in the corresponding part of the above embodiment, the semantic segmentation implementation method described in steps S42 and S43 can also be adopted. The first response information obtained from the target model response is divided into multiple semantically complete initial fragment information (initial chunks, i.e., complete semantic units, also known as single semantic fragments), that is, after being able to independently express a complete intent or describe the smallest linguistic / non-linguistic unit, the semantic completeness of each initial fragment information can be verified by analyzing the entity association relationships (i.e., entity relationships, such as coreference, temporal, logical or combinatorial relationships, etc.) contained in each initial fragment information. For example, through intent / syntactic / reference resolution, the semantically incomplete initial fragment information can be adjusted to obtain the semantically complete first fragment information.
[0090] In the implementation of step S42 above, the chunk segmentation method of the RAG method can be used. Optionally, this application performs block processing on the first response information based on a sliding window of a preset length (which can be obtained based on historical chunk length statistics, or determined based on experience or experiments, or dynamically adjusted based on the maximum input length of different types of target models, etc., and this application does not limit the value of the preset length). In this processing, the overlap rate between the fragment information in two adjacent sliding window movements can be controlled to reach a preset value, such as 20%, to maintain semantic coherence, but is not limited to the implementation method described in this application.
[0091] Optionally, this application can also segment the first response information through syntactic analysis, such as segmenting the first response information based on subject-verb-object structure, to ensure that each initial segment information contains a complete subject-verb-object structure. Optionally, this application can also use an intent classification model to identify each task boundary in the first response information and segment it into different initial segment information accordingly.
[0092] Of course, this application can also use at least two combinations of semantic boundary detection algorithms as described above to segment the first response information into multiple initial fragment information. After adjustment to obtain the semantically complete first fragment information, it can be converted into vectors and cached so that it can be implemented through vector similarity algorithm in subsequent retrieval.
[0093] Step S44: Cache multiple first fragment information; the number of tokens corresponding to the input target model for each first fragment information is less than the number of tokens corresponding to the input target model for the first response information;
[0094] Step S45: In response to the user input of a second question that belongs to the same dialogue scenario as the first question information, retrieve the target segment information associated with the second question information from multiple first segment information, and use the target segment information as a memory of the second question information;
[0095] Step S46: Fill the corresponding variables in the prompt word template after the previous round of filling with the second question information and the target fragment information, create prompt words corresponding to the second question information, and record the prompt word template after this round of filling.
[0096] In this embodiment of the application, the prompt word template used to guide the target model can be enhanced and updated to achieve incremental updates of prompt words for each round in the same dialogue scenario, such as the implementation methods of steps S45 and S46. As the number of dialogue rounds in the same dialogue scenario increases, the variables in the prompt word template for the corresponding round are synchronously updated to the target fragment information retrieved in the corresponding round and the question information of that round.
[0097] In one possible implementation, given a defined prompt word template, incremental updates of prompt words for each round within the same dialogue scenario can be implemented. In this case, based on the prompt words corresponding to the second question information, the target fragment information, and the first question information, prompt words corresponding to the second question information can be created according to the prompt word template used to guide the target model. The prompt words created in this round are recorded for use when creating prompt words corresponding to the next round of question information.
[0098] In one possible implementation, given a defined prompt template, this application can also employ a full-fill method to create prompts for each round. In this case, historical question information and second question information belonging to the dialogue scenario to which the first question information belongs, along with target fragment information serving as memories of the corresponding question information, can be filled into the corresponding variables in the prompt template used to guide the target model. This creates a prompt corresponding to the second question information, ensuring that the prompt contains question information from each round of the same dialogue scenario and the retrieved corresponding memories. It is understood that the memory of the current round's question information can also serve as the memory of the next round's question information, thus maintaining key contextual information within the same dialogue scenario.
[0099] It should be noted that the prompt word templates in the above embodiments of this application can be configured or called when responding to the dialogue start command in the dialogue scenario, so that appropriate prompt word templates can be configured or called in different types of dialogue scenarios, or a general prompt word template for multi-turn dialogue can be directly called. This application does not limit the format of the prompt word template.
[0100] Based on the prompt word generation method described in the above embodiments, and by implementing block processing of the response information used for output in each round using the RAG method to obtain the fragment information associated with the response information, combined with... Figure 5 The example shown illustrates a method for generating prompts applicable to multi-turn dialogue scenarios.
[0101] Suppose a user creates a new dialogue window (interaction window) in the dialogue system and enters the first question, "Where is City A?". After detection, it is found that the first question belongs to the first round of questions in the current dialogue scenario (i.e., the dialogue window created this time). That is, the cache space for the current dialogue scenario does not store fragment information. Based on the first question, prompt words corresponding to the first question can be created according to the prompt word template used to guide the target model. For example, the first question can be transmitted as prompt words to the target model to generate the first response information.
[0102] Suppose the first response could be: "City A is the capital of country Z, located in the eastern part of country Z. On the map, it is roughly situated in the plains area of City A, bordering Municipality B to the east, Province C to the south, Province D to the west, and Province E to the north. City A is the center of country X and one of the largest cities in the world." Figure 5 As shown, this information can be fed back to the user for viewing. Simultaneously, when caching the first response information, this application first processes it into chunks according to the method described above, obtaining multiple semantically clear and complete first fragment information associated with it, i.e., multiple chunks (representing the i-th first fragment information, i=1, 2, ..., m, where m is the number of first fragment information obtained from the chunking). In this example, the first response information is processed into chunks, obtaining 5 chunks associated with the first response information, which are then cached in the cache space for the dialogue interaction window (e.g., ...). Figure 5 (The historical cache database shown). For example... Figure 5 As shown, these 5 chunks can be represented as follows: Chunk 1: City A is the capital of country Z. Chunk 2: City A is located in the eastern part of country Z, in the plains region. Chunk 3: City A is bordered by Municipality B to the east, Province C to the south, Province D to the west, and Province E to the north. Chunk 4: City A is the center of country Z. Chunk 5: City A is one of the largest cities in the world.
[0103] In the example above, the five chunks in this example, relative to the corresponding text parts in the first response information, have had their pronouns replaced with explicit entities, that is, the implicit subject "City A" has been added, so that the semantics of each chunk are complete and the independence and reusability of each chunk are ensured.
[0104] When a user inputs a new question (denoted as the second question): "Where is Municipality B located in City A?", and after determining that it belongs to the same dialogue scenario as the first question, RAG can retrieve target fragment information associated with the second question from historical cache data, following the same processing method used for the first question as described above. For example, it can use one or more similarity detection methods, such as text similarity, vector similarity, or Euclidean distance, to determine the fragment with a similarity greater than a threshold or the highest similarity to the first question as the target fragment information. In this example, the most relevant target fragment information retrieved for the second question, such as "chunk3: City A is bordered by Municipality B to the east, Province C to the south, Province D to the west, and Province E to the north," is used as the memory for the second question, and prompts for this second question are created according to the prompt template.
[0105] user="Where is City A?"
[0106] City A is bordered by Municipality B to the east, Province C to the south, Province D to the west, and Province E to the north.
[0107] user="Where is Municipality B located in City A?"
[0108] As can be seen, the prompt words created in this application are significantly shorter than those created by directly using the first response information as the second question information. Thus, by inputting the prompt words of the second question information into the target model to guide the target model to generate the second response information corresponding to the second question information, the consumption of computing resources is greatly reduced, the efficiency of dialogue operation is improved, and the accuracy of the second response information is improved because the prompt words reduce redundant information.
[0109] Following the example above, the second response information generated by this application can be: "Municipality B is located southeast of City A. Specifically, Municipality B is approximately at xx degrees North latitude and xx degrees East longitude, while City A is located at xx degrees North latitude and xxx degrees East longitude. Therefore, Municipality B is approximately southeast of City A, about 100 kilometers away. Geographically, Municipality B is northwest of City A, separated by the plains of City A in the North China Plain." Following the method described above, the second response information is segmented to obtain multiple second fragments of information associated with it, i.e., various chunks, for example: chunk6: Municipality B is located southeast of City A. chunk7: Municipality B is at xx degrees North latitude and xx degrees East longitude. chunk8: City A is at xx degrees North latitude and xxx degrees East longitude. chunk8: Municipality B is in the southeast. chunk10: Municipality B is about 100 kilometers away from City A. chunk11: Municipality B and City A are separated by the plains of City A.
[0110] Similarly, this application can continue to cache the various fragment information obtained in this round. For example, it can associate and cache the fragment information with the dialogue identifier of the dialogue scene, or the input time or dialogue round identifier of the question information in this round. The caching implementation method is not described in detail in this application. In this way, after obtaining the third question information input by the user, that is, when starting the next round of dialogue, the processing method of the question information in the previous round of dialogue can be repeated to continue generating the prompt words corresponding to the third question information until the current dialogue scene ends. The implementation process is not described in detail in this application.
[0111] Therefore, the prompt generation method proposed in this application, in multi-turn dialogue scenarios, can process and cache the historical response information (which is the response information generated in the current round relative to the next round of dialogue) into multiple historical fragments. Then, when a new round of question information is obtained and its prompts are created, the method retrieves the relevant target fragment information from these historical fragments. Specifically, it retrieves key local information from the historical response information (which can be determined based on similarity calculation) for the current round's input question information and merges it with the current round's question information, creating the prompts for that round according to the prompt template. Compared to fusing complete historical response information with the current round's question information, the prompts created in this application only use key local information from the historical response information, reducing redundant information and ensuring dialogue coherence and accuracy. This significantly reduces the number of tokens required for the input target model corresponding to the prompts, reduces the computational resource consumption of the target model in generating response information based on the prompts, and improves the dialogue's operational efficiency and response accuracy.
[0112] In practical applications, as multi-turn dialogues become longer, the target model is more prone to forgetting early information. To maintain the context of the dialogue scenario, in multi-turn dialogue scenarios, after processing the response information into blocks using a method similar to RAG, this application uses these fragments as a temporary contextual history (short-term memory) cache for that multi-turn dialogue scenario. Thus, following the method described above, after inputting question information in each dialogue turn, this application first checks whether it belongs to the same dialogue scenario as the question information input in the previous turn. If they do not belong to the same dialogue scenario, this turn can be considered a newly created dialogue scenario, and the fragment information associated with the previous dialogue scenario can be deleted to release cache resources and avoid interference with the prompt generation process in each turn of the current dialogue scenario. This application does not restrict the method for controlling the deletion of temporary cached historical fragment information.
[0113] In one possible implementation, in response to a dialogue end command in the dialogue scenario (such as when a user enters information indicating the end of the dialogue in the dialogue interaction window, such as "goodbye," or when a user triggers a new dialogue, indicating the end of the previous dialogue scenario, etc.; this application does not restrict the method of generating the dialogue end command), all cached fragment information associated with each response information belonging to the dialogue scenario can be deleted. In this case, the historical cache data only caches fragment information generated in each round under the current dialogue scenario. In the method of generating all prompt words, the target fragment information associated with the question information of the current round can be directly retrieved from the historical cache information from multiple fragment information associated with the response information of each round, so as to combine the question information of each round and create the prompt words of the current round according to the prompt word template.
[0114] In one possible implementation, this application can also implement dynamic deletion control for consecutive multi-turn dialogues based on a dialogue time window. Specifically, it deletes fragment information from all cached fragment information associated with each response information belonging to the dialogue scenario, where the time difference between the corresponding cached time and the current time is greater than the duration of a dialogue time window. Thus, for the fragment information cached in consecutive dialogue rounds, corresponding identifiers such as cache time / input time of the corresponding question information can be recorded. As the dialogue rounds increase, fragment information corresponding to times outside a dialogue time window is deleted, while the cached fragment information closest to the current time (i.e., within the duration of the dialogue time window) is retained.
[0115] In one possible implementation, besides the dynamic updating of the historical cache database based on the dialogue time window described above, this application can also be implemented based on each dialogue turn, retaining only the fragment information and question information of the most recent few dialogue turns, and promptly deleting the fragment information and question information of earlier dialogue turns. Therefore, this application can also delete fragment information from all cached fragment information associated with each response information belonging to the dialogue scenario where the difference between the dialogue turn to which the corresponding response information belongs and the current dialogue turn is greater than a second dialogue turn threshold.
[0116] Therefore, this application can manage the dialogue history cache database corresponding to multi-turn dialogue scenarios in accordance with, but not limited to, the dynamic update methods described above, and promptly delete fragment information that is irrelevant to or has a low matching degree to the input question information in the current turn. This facilitates the rapid location of target fragment information associated with the question information, so as to generate concise prompt words. Compared with the implementation method of filtering target fragment information from a large amount of historical knowledge, this application improves the efficiency and reliability of prompt word generation.
[0117] Based on the above-described embodiments of this application, a prompt word generation method is provided. The apparatus for performing the above-described prompt word generation method will be described below.
[0118] Reference Figure 6 This is a schematic diagram of a prompt word generation device provided in an embodiment of this application. Figure 6 As shown, the prompt word generation device may include:
[0119] The first response information acquisition module 61 is used to acquire first response information for output; the first response information is response information generated by the target model that corresponds to the first question information.
[0120] The block processing module 62 is used to perform block processing on the first response information to obtain multiple first fragment information associated with the first response information;
[0121] The caching module 63 is used to cache the plurality of first fragment information; the number of the smallest semantic units corresponding to each first fragment information input to the target model is less than the number of the smallest semantic units corresponding to the first response information input to the target model;
[0122] The retrieval module 64 is used to respond to user input of second question information belonging to the same dialogue scenario as the first question information, and to retrieve target fragment information associated with the second question information from the plurality of first fragment information, wherein the target fragment information is used as a memory of the second question information;
[0123] The prompt word creation module 65 is used to create prompt words corresponding to the second question information based on the second question information and the target fragment information, according to the prompt word template used to guide the target model; the prompt words include the target fragment information required to assist the target model in understanding the context of the dialogue scenario when the target model generates the second response information of the second question information.
[0124] In some embodiments, the retrieval module 64 may include at least one of the following units:
[0125] A semantic similarity analysis unit is used to perform semantic similarity analysis on the second question information input by the user and the first question information, in response to the semantic similarity being greater than a similarity threshold;
[0126] The first determining unit is configured to determine the input time difference between the second question information input by the user and the first question information, in response to the input time difference being less than the duration of a dialogue time window;
[0127] The second determining unit is used to determine the dialogue round difference between the second question information input by the user and the first question information, in response to the dialogue round difference being less than the first dialogue round threshold.
[0128] The third determining unit is used to determine the dialog identifier associated with the second question information input by the user, in response to the dialog identifier being the same as the dialog identifier associated with the first question information.
[0129] Among them, at least one of the duration of the dialogue time window, the round threshold, and the similarity threshold can be configured based on the type of the current dialogue scenario.
[0130] Optionally, the semantic similarity analysis unit may include:
[0131] An entity recognition unit is used to perform entity recognition on the second question information input by the user to obtain at least one second entity associated with the second question information;
[0132] The first matching unit is used to match the at least one second entity with each of the first entities associated with the first question information to obtain the semantic similarity between the second question information and the first question information.
[0133] Optionally, the semantic similarity analysis unit may include:
[0134] The intent recognition unit is used to recognize the intent of the second question information input by the user and obtain the second query intent of the second question information.
[0135] The intent transfer weight acquisition unit is used to obtain the intent transfer weight between the first query intent and the second query intent of the first question information, so as to serve as the semantic similarity between the second question information and the first question information.
[0136] In some embodiments, the block processing module 62 may include:
[0137] A segmentation unit is used to segment the first response information into multiple initial fragment information; each initial fragment information contains a complete semantic unit.
[0138] An adjustment unit is configured to adjust the corresponding initial fragment information based on the entity relationships between the multiple initial fragment information to obtain multiple first fragment information associated with the first response information.
[0139] In some embodiments, the above-described prompt word creation module 65 may include any of the following creation units:
[0140] The first creation unit is used to fill the corresponding variables in the prompt word template after the previous round of filling with the second question information and the target fragment information, create a prompt word corresponding to the second question information, and record the prompt word template after this round of filling.
[0141] The second creation unit is used to create prompt words corresponding to the second question information based on the second question information, the target fragment information, and the prompt words corresponding to the first question information, according to the prompt word template used to guide the target model, and record the prompt words created in this round;
[0142] The third creation unit is used to fill the corresponding variables in the prompt word template used to guide the target model with the historical question information belonging to the dialogue scenario, the second question information, and the target fragment information as the memory of the corresponding question information, and create prompt words corresponding to the second question information;
[0143] The prompt word template can be configured when responding to the dialogue start command of the dialogue scenario.
[0144] In some embodiments, the above-described prompt word generation apparatus may further include any of the following deletion modules:
[0145] The first deletion module is used to delete all cached fragment information that is associated with each reply information belonging to the dialogue scenario in response to the dialogue end command of the dialogue scenario.
[0146] The second deletion module is used to delete, from all the cached fragment information associated with each response information belonging to the dialogue scenario, fragment information whose time difference between the corresponding cache time and the current time is greater than the duration of a dialogue time window.
[0147] The third deletion module is used to delete, from all cached fragment information associated with each response information belonging to the dialogue scenario, fragment information where the difference between the dialogue round to which the corresponding response information belongs and the current dialogue round is greater than a second dialogue round threshold.
[0148] This application also provides a computer program product including computer-readable instructions, which, when executed on a computer device, cause the computer device to implement any of the prompt word generation methods provided in this application.
[0149] This application also provides a computer-readable storage medium that carries one or more computer programs. When the one or more computer programs are executed by a computer device, the computer device is able to implement any of the prompt word generation methods provided in this application.
[0150] Reference Figure 7 This is a schematic diagram of the hardware structure of a computer device applicable to the prompt generation method proposed in this application. The computer device can be a server (such as a cloud server) or a terminal device supporting multi-turn dialogue processing capabilities, such as... Figure 7 As shown, the computer device may include, but is not limited to, at least one communication element 71, at least one memory 72, and at least one processor 73, wherein:
[0151] At least one communication element 71, at least one memory 72, and at least one processor 73 can communicate via a bus. The bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be categorized as an address bus, data bus, control bus, etc. For ease of representation, Figure 7 The bus is represented by a single bidirectional line, but this does not mean that there is only one bus or one type of bus.
[0152] The communication element 71 can be used to obtain user-input question information. In this embodiment, the communication element 71 may include at least one wireless communication element and / or at least one wired communication element to meet the corresponding communication requirements. This application does not limit the composition structure of the communication element 71 to achieve this function and its corresponding communication transmission mechanism, which can be determined as appropriate.
[0153] The memory 72 can be used to store multiple computer instructions for implementing the prompt word generation method proposed in the embodiments of this application; the processor 73 can load and execute the computer instructions stored in the memory 102 to implement each step of the prompt word generation method proposed in the embodiments of this application. The implementation process can be referred to the description of the corresponding part of the method embodiments above.
[0154] In practical applications, when the computer device is a server, the user uses a terminal device to transmit the input question information to the server through a communication network. The server then executes the prompt word generation method proposed in this application, inputs the generated prompt word into the target model to generate the response information corresponding to the question information, and then feeds back the response information to the user's terminal device for display, so that the user can input the question information for the next round of dialogue. This interactive processing completes multiple rounds of dialogue.
[0155] In this embodiment, memory 72 may include at least one volatile memory, and may also include at least one non-volatile memory or other storage medium. Processor 73 may include any one or more of a central processing unit (CPU), a graphics processing unit (GPU), or other processors.
[0156] It should be understood that, Figure 7 The structure of the computer device shown does not constitute a limitation on the computer device in the embodiments of this application. In practical applications, the computer device may include more than Figure 7 The computer device may include more or fewer components, or a combination of certain components. If the computer device is a user terminal, it may also include input / output components such as a display, microphone, speaker, power management module, various sensors, and antenna, which will not be listed in detail in this application.
[0157] This application also proposes an artificial intelligence-based computer program, which can be embedded in an application or operating system as part of that application or operating system to implement the prompt generation method proposed in this application. In this case, the artificial intelligence-based computer program can be an intelligent agent (AI agent) capable of providing intelligent functions in a dialogue format. It can autonomously perceive the environment, analyze data based on the powerful capabilities of the target model, and perform tasks to provide users with a natural and intelligent conversational interactive experience. This application does not detail how it is embedded into the application or operating system as an embedded component to implement intelligent functions in a dialogue format. Optionally, the intelligent agent can control other components of the embedded application or operating system through interface calls or other interactive methods to respond to user input, but is not limited to this.
[0158] The aforementioned applications can be web applications such as browsers, app stores (app markets), instant messaging software, settings software, or other standalone applications. Optionally, if the intelligent agent is an embedded component of the browser, it is essentially the browser's intelligent assistant. After the user enters question information in the browser's output window or a created floating dialog window, the browser's embedded intelligent agent will replace the traditional browser engine and generate concise and refined prompts based on the target model according to the prompt generation method proposed in this application. The prompts are then input into the target model to generate corresponding response information, which is fed back to the user as the intelligent agent's response result.
[0159] For example, a user makes a restaurant reservation through a browser. The user enters information about wanting to reserve dinner at restaurant A through the browser page. The detected user input is transmitted to an intelligent agent, which analyzes the input and can access restaurant A's reservation interface. The agent, acting as a waiter, converses with the user, asking questions about reservation details such as "What cuisine do you prefer?", "Which day would you like to dine?", "What time?", and "How many people are dining?". During this process, for user input such as "What are some recommended Sichuan dishes?", "Which days this weekend are available?", and "Are there private rooms available tonight?", the agent can accurately understand the user's intent by combining context, generating short prompts to input into the target model, and feeding back the response information generated by the target model to the user. Simultaneously, this information is processed into chunked information caches. The implementation process is not detailed in this application.
[0160] Similarly, when a user searches for knowledge related to domain B using a browser, the intelligent agent can act as a search engine, providing accurate and complete answers based on the target model. For example, if a user enters "Help me find a suitable laptop for office work" into a browser, the intelligent agent might respond, "Okay, what are your configuration requirements? For example, budget, brand preference?" If the user enters "Budget around 8000, want a lightweight laptop," the intelligent agent might respond, "We recommend the following models: 1. Thinkxx - 7999 yuan 2. Dell xxx - 8299 yuan 3. xxMateBook X Pro - 7899 yuan, would you like to see a detailed comparison?" etc. It should be understood that the intelligent agent can also be embedded in dedicated applications such as e-commerce software, travel search software, financial management software, or weather search software. The implementation process is similar and will not be detailed in this application.
[0161] When the aforementioned intelligent agent is embedded in an app store to provide intelligent functions through dialogue, the agent can implement the original functions of the app store program through API calls, etc. These functions can be used through interactive dialogue. For example, upon entering the app store's main interface, the agent can be automatically or triggered to enter a dialogue window, guiding the user to input their intention to enter the app store, such as downloading type X software. The agent can update the displayed interface content based on the user's voice / text input, guiding the user step-by-step through the software download process, etc. The implementation process is not detailed in this application.
[0162] If the aforementioned intelligent agent is embedded into the operating system of a computer device (such as a terminal device), it becomes part of the operating system and provides intelligent functions. In this case, the intelligent agent can provide a natural language interactive experience in a conversational manner, just like the native functions of the operating system, enabling comprehensive control from file operations to system settings. It is evident that this intelligent agent is essentially an intelligent assistant to the operating system, capable of meeting the user's system-level operational needs of the computer device (such as a terminal device) through dialog pop-ups, updating the display content of the screen, or updating the output content of other output components. The implementation process is not detailed in this application. It should be understood that the intelligent agent embedded in the operating system can control various applications within the computer device (such as a terminal device). For example, if a user inputs the voice command "Help me find the PDF document I modified last week," the agent can generate corresponding prompts and search for documents matching the user's intent based on the target model. The output would be: "Three files matching the criteria have been found: 1. / Documents / report.pdf (modified 3 days ago) 2. / Downloads / contract.pdf (modified 5 days ago) 3. / Work / project.pdf (modified 1 week ago). Which file do you want to open? Or can I sort by modification time?" This response can be segmented into multiple fragments and cached. Later, the user can reply based on the actual situation, such as "View the modifications to the third document." The agent can then generate corresponding prompts using the prompt generation method proposed in this application and input them into the target model to generate the modifications for the document " / Work / project.pdf".
[0163] Similarly, the intelligent agent proposed in this application, embedded in the operating system, can also achieve system control as part of the operating system, such as adjusting the screen brightness of computer devices (e.g., terminal devices), real-time performance monitoring, security and permission management, or updating system configuration / maintenance. For example, if a user inputs "My computer is a bit slow, please optimize it for me," the intelligent agent might reply, "System performance issues detected. The following optimizations are recommended: 1. Memory cache cleanup - can free up approximately 512MB of memory; 2. Startup item optimization - can disable 3 unnecessary startup programs; 3. Disk defragmentation - can improve file access speed; should we perform all optimizations now or select specific items?" This can be displayed in a pop-up window or intelligent agent dialog window, and the intelligent agent can process it in blocks to obtain related fragment information and cache it. After the user selects an optimization method, the agent combines the target fragment information related to the input information in the cached fragment information to generate a prompt input target model. Based on the target model, the agent can optimize the computer according to the optimization strategy the user wants to execute.
[0164] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0165] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented entirely or partially as a computer program product. The various embodiments in this specification are described in a progressive or parallel manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus and computer devices disclosed in the embodiments, since they correspond to the methods disclosed in the embodiments, the descriptions are relatively simple, and relevant parts can be referred to the method section.
Claims
1. A method for generating prompt words, the method comprising: Obtain the first response information used for output; The first response information is the response information generated by the target model corresponding to the first question information; The first response information is segmented to obtain multiple first fragment information associated with the first response information; The plurality of first fragment information is cached; the number of the smallest semantic units input to the target model corresponding to each first fragment information is less than the number of the smallest semantic units input to the target model corresponding to the first response information; In response to user input of second question information belonging to the same dialogue scenario as the first question information, target segment information associated with the second question information is retrieved from the plurality of first segment information, and the target segment information is used as a memory of the second question information; Based on the second question information and the target fragment information, a prompt word corresponding to the second question information is created according to the prompt word template used to guide the target model; the prompt word includes the target fragment information required to help the target model understand the context of the dialogue scenario when the target model generates the second response information of the second question information.
2. The method according to claim 1, wherein the second question information, which is in response to user input and belongs to the same dialogue scenario as the first question information, includes at least one of the following: Perform semantic similarity analysis between the second question information input by the user and the first question information, and respond when the semantic similarity is greater than the similarity threshold; Determine the input time difference between the second question information input by the user and the first question information, in response to the input time difference being less than the duration of a dialogue time window; Determine the dialogue round difference between the second question information input by the user and the first question information, in response to the dialogue round difference being less than a first dialogue round threshold; Determine the dialog identifier associated with the second question information entered by the user, in response to the dialog identifier being the same as the dialog identifier associated with the first question information.
3. The method according to claim 2, wherein performing semantic similarity analysis on the second question information input by the user and the first question information includes: Entity recognition is performed on the second question information input by the user to obtain at least one second entity associated with the second question information; The at least one second entity is matched with each of the first entities associated with the first question information to obtain the semantic similarity between the second question information and the first question information.
4. The method according to claim 2, wherein performing semantic similarity analysis on the second question information input by the user and the first question information includes: The intent of the second question information input by the user is identified to obtain the second query intent of the second question information; The intent transfer weight between the first query intent and the second query intent of the first question information is obtained and used as the semantic similarity between the second question information and the first question information.
5. The method according to claim 2, wherein: At least one of the following—the duration of the dialogue time window, the round threshold, and the similarity threshold—can be configured based on the type of the current dialogue scenario.
6. The method according to any one of claims 1-5, wherein the step of segmenting the first response information to obtain a plurality of first fragment information associated with the first response information comprises: The first response information is divided into multiple initial fragment information; Each of the initial fragment information contains a complete semantic unit; Based on the entity relationships between the multiple initial fragment information, the corresponding initial fragment information is adjusted to obtain multiple first fragment information associated with the first response information.
7. The method according to any one of claims 1-5, wherein creating a prompt word corresponding to the second question information based on the second question information and the target fragment information, according to a prompt word template for guiding the target model, includes any one of the following: Fill the corresponding variables in the prompt word template after the previous round of filling with the second question information and the target fragment information, create a prompt word corresponding to the second question information, and record the prompt word template after this round of filling; Based on the second question information, the target fragment information, and the prompt words corresponding to the first question information, according to the prompt word template used to guide the target model, a prompt word corresponding to the second question information is created, and the prompt word created in this round is recorded; Fill the corresponding variables in the prompt word template used to guide the target model with the historical question information belonging to the dialogue scenario, the second question information, and the target fragment information as the memory of the corresponding question information, and create prompt words corresponding to the second question information; The prompt word template can be configured when responding to the dialogue start command of the dialogue scenario.
8. The method according to any one of claims 1-5, further comprising any one of the following: In response to the dialogue end command of the dialogue scenario, delete all cached fragment information that is associated with each reply information belonging to the dialogue scenario. From all the cached fragment information associated with each response information belonging to the aforementioned dialogue scenario, delete fragment information whose corresponding cache time and current time differ from the current time by more than the duration of a dialogue time window. From all cached fragment information associated with each response information belonging to the aforementioned dialogue scenario, delete fragment information where the difference between the dialogue round to which the corresponding response information belongs and the current dialogue round is greater than the second dialogue round threshold.
9. A computer device, the computer device comprising: At least one communication element, at least one memory, and at least one processor, wherein: The communication element is used to obtain the question information input by the user; The memory is used to store multiple computer instructions; The processor is used to load and execute the computer instructions to perform the following steps: Obtain the first response information for output; the first response information is the response information generated by the target model corresponding to the first question information; The first response information is segmented to obtain multiple first fragment information associated with the first response information; The plurality of first fragment information is cached; the number of the smallest semantic units input to the target model corresponding to each first fragment information is less than the number of the smallest semantic units input to the target model corresponding to the first response information; In response to user input of second question information belonging to the same dialogue scenario as the first question information, target segment information associated with the second question information is retrieved from the plurality of first segment information, and the target segment information is used as a memory of the second question information; Based on the second question information and the target fragment information, a prompt word corresponding to the second question information is created according to the prompt word template used to guide the target model; the prompt word includes the target fragment information required to help the target model understand the context of the dialogue scenario when the target model generates the second response information of the second question information.
10. An artificial intelligence-based computer program, said computer program being embeddable as part of an application or operating system, for performing the following processes: Obtain the first response information for output; the first response information is the response information generated by the target model corresponding to the first question information; The first response information is segmented to obtain multiple first fragment information associated with the first response information; The plurality of first fragment information is cached; the number of the smallest semantic units input to the target model corresponding to each first fragment information is less than the number of the smallest semantic units input to the target model corresponding to the first response information; In response to user input of second question information belonging to the same dialogue scenario as the first question information, target segment information associated with the second question information is retrieved from the plurality of first segment information, and the target segment information is used as a memory of the second question information; Based on the second question information and the target fragment information, a prompt word corresponding to the second question information is created according to the prompt word template used to guide the target model; the prompt word includes the target fragment information required to help the target model understand the context of the dialogue scenario when the target model generates the second response information of the second question information.
Citation Information
Cited By
Voice control browser operation method and system based on double-agent real-time communication
CN121884813A
Problem processing method, device and equipment
CN122240797A
A problem processing method, apparatus and device
CN122240797B