A topic-aware context adaptive regulation method, system, device and medium for power safety multi-turn dialogue
By constructing an intelligent context routing layer and utilizing a lightweight large language model for topic identification and semantic relevance analysis, the system adaptively manages multi-turn dialogues in power safety, solving the problem of topic interference in the power safety analysis platform and improving output accuracy and user experience.
Patent Information
- Application Number
- CN202610883059.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-18
- Publication Date
- 2026-11-03
AI Technical Summary
In the single-session application scenario of the intrinsic safety analysis platform for electricity, when users have continuous multi-round dialogues with the dedicated analysis model, there is a problem of mutual interference between different topics. Existing technologies have difficulty in achieving an effective balance between maintaining necessary continuity and isolating irrelevant interference.
By constructing an intelligent context routing layer, utilizing a lightweight large language model for topic identification and semantic relevance analysis, the context of multi-turn dialogues in power safety is adaptively managed. Different strategies are used to filter and reorganize historical dialogue fragments, and domain-specific guidance instructions are injected to ensure adaptive control of topic awareness.
It effectively alleviates the context interference problem in single-window multi-turn dialogue of power safety analysis models, improves the accuracy and reliability of model output, adapts to the professional needs of the power safety field, is suitable for business scenarios such as dispatching and command and on-site inspection, and improves user experience and platform usability.
Smart Images

Figure CN123030710A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent analysis technology for power safety, and in particular to a topic-aware context-adaptive control method, system, device, and medium for multi-turn dialogue in power safety. Background Technology
[0002] In single-session application scenarios of the intrinsic safety analysis platform for power systems, there is a technical flaw where different topics interfere with each other during continuous multi-round dialogues between the user and the dedicated analysis model. For example, if a user first discusses transformer fault diagnosis and then inquires about the risks of switching operations, the model's generated response may incorrectly include transformer-related equipment information, leading to biased risk assessment conclusions. This contextual confusion problem reduces the professionalism and reliability of the model's output.
[0003] Current common solutions employ fixed-length sliding windows to manage context. This method mechanically retains the most recent rounds of dialogue while discarding earlier historical information. Its drawback is that when users engage in in-depth, multi-round discussions on the same complex topic, prematurely discarding key historical context disrupts the coherence and depth of analysis; conversely, when users switch topics, irrelevant information may remain, causing interference. Another approach relies on users actively clearing the dialogue or starting a new session, which doesn't align with natural and efficient human-computer interaction habits and is impractical in business scenarios requiring rapid, continuous consultation on different security issues. Existing research on context management based on general semantic similarity lacks in-depth adaptation to the characteristics of the power safety vertical. Power safety dialogue topics have relatively clear boundaries, are dense with technical terminology, and are logically rigorous. General methods struggle to accurately identify the switching points between technical topics, failing to achieve an effective balance between maintaining necessary coherence and isolating irrelevant interference.
[0004] This invention proposes a topic-aware, context-adaptive management method for multi-turn dialogues in power safety. Its core principle lies in constructing an intelligent context routing layer between the user and the power safety analysis model. This routing layer analyzes the semantic content of the user's current query in real time, combines it with a pre-built knowledge system in the power safety domain, automatically determines the professional topic to which the query belongs, and assesses its relevance to existing dialogue history. Depending on different scenarios such as topic continuation, topic deepening, or topic switching, the system adaptively employs different context management strategies to filter and reorganize the dialogue history of the input model, and injects domain-specific guidance instructions. This ensures necessary continuity while fundamentally preventing cross-topic knowledge contamination and logical interference. Summary of the Invention
[0005] In view of the above-mentioned existing problems, the present invention provides a topic-aware context-adaptive control method, system, device and medium for multi-turn dialogue in power security to solve the problems of cross-topic confusion, context management imbalance and poor adaptability in multi-turn dialogue in power security.
[0006] To solve the above-mentioned technical problems, the present invention provides the following technical solution: In a first aspect, the present invention provides a topic-aware context-adaptive control method for multi-turn dialogue in power security, comprising: Get the user's current query text; A lightweight large language model is selected as the topic-aware model. The topic-aware model is used to identify the topic of the query text to obtain the topic category and corresponding confidence level of the current query. Calculate the semantic relevance score between the current query topic category and the most recent historical topic in the dialogue history; The context management strategy for the current round is determined based on the current topic category, the corresponding confidence level, and the semantic relevance score. Based on the context management strategy, historical dialogue fragments matching the current strategy are selected, and guiding instructions are generated; The historical dialogue fragments, the current query text, and the guidance instructions are combined into new prompt words, which are then input into the power safety analysis model to obtain the answer for the current round. The questions and answers for the current round and the corresponding topic categories are then updated in the dialogue history to achieve adaptive control of topic-aware context.
[0007] As a preferred embodiment of the topic-aware context-adaptive control method for multi-turn dialogue in power safety as described in this invention, the topic identification of the query text includes: Obtain the topics for power safety dialogues and categorize them into different topic categories; The topic perception model is fine-tuned using instructions to obtain the fine-tuned topic perception model. Input the user's current query text into the fine-tuned topic awareness model, output the topic category of the current query, and calculate the confidence score of the corresponding topic category.
[0008] The beneficial effects of this preferred technical solution are that it accurately identifies topics based on the domain topic system and fine-tuning model, the confidence quantification is reliable, and the accuracy of topic judgment is improved.
[0009] As a preferred embodiment of the topic-aware context-adaptive control method for multi-turn dialogue in power safety as described in this invention, the semantic relevance score calculation includes: Extraction rules are used to extract the core power safety professional terms in the current query text and the most recent historical topics in the dialogue history, forming a first term set and a second term set. The similarity between the first term set and the second term set is calculated as a semantic relevance score.
[0010] As a preferred embodiment of the topic-aware context-adaptive control method for multi-turn dialogue in power safety as described in this invention, the determination of the context management strategy for the current turn includes: In response to a confidence level greater than or equal to the first threshold, a first judgment is made between the topic category of the current query and the topic category of the most recent historical topic in the dialogue history; Based on the first judgment result, a second judgment is made on the semantic relevance score to obtain the corresponding context management strategy.
[0011] As a preferred embodiment of the topic-aware context-adaptive control method for multi-turn dialogue in power security as described in this invention, the first judgment includes: If the topic category of the current query is the same as the topic category of the most recent historical topic in the conversation history, it is determined to be a topic continuation, and a coherence enhancement strategy is selected. In response to the fact that the topic category of the current query is different from the topic category of the most recent historical topic in the dialogue history, a second judgment is made on the semantic relevance score; If the semantic relevance score is greater than the second threshold but less than the third threshold, it is determined to be a related topic switch, and the association bridging strategy is selected. If the semantic relevance score is less than or equal to the second threshold, it is determined to be an irrelevant topic switch, and the isolation and reset strategy is selected. If the semantic relevance score is greater than or equal to the third threshold, it is determined to be a strongly related topic shift, and a coherence enhancement strategy is selected.
[0012] The beneficial effects of this preferred technical solution are that it accurately distinguishes topic types through layered judgment, adopts an adaptive matching strategy, balances coherence and isolation, and improves the stability of the dialogue.
[0013] As a preferred embodiment of the topic-aware context-adaptive control method for multi-turn dialogue in power safety as described in this invention, the method includes: filtering historical dialogue fragments that match the current strategy, which includes: In response to the coherence enhancement strategy, all historical question-and-answer pairs with the same topic tags as the current query topic category are filtered out from the dialogue history to form a complete historical fragment; In response to the association bridging strategy, select at most two-round question-and-answer pairs that are weakly related to the current query topic from the dialogue history to form a short bridging history fragment. In response to the isolation reset policy, all specific historical dialogue content is cleared, only system-level fixed commands and current user query text are retained, and no historical question-and-answer pairs are retained.
[0014] The beneficial effects of this preferred technical solution are that it can accurately filter historical fragments according to topics, adaptively retain or clear them, purify the context, and improve the accuracy of answers.
[0015] As a preferred embodiment of the topic-aware context-adaptive control method for multi-turn dialogue in power safety as described in this invention, the method involves combining the historical dialogue fragments, the current query text, and the guidance instructions into new prompt words, including: In response to the context management strategy being a coherence enhancement strategy, an instruction template is selected to prompt the model to focus on the current topic; In response to the context management strategy being an association bridging strategy, an instruction template is selected to prompt the model in conjunction with relevant historical topics; In response to the context management strategy of isolation and reset, select an instruction template to prompt the model to ignore previous topics and focus only on the current issue; Enter the topic category name of the current query text into the placeholder in the instruction template to generate the specific guidance instruction text; The generated guidance instructions are combined with the filtered historical dialogue fragments and the current query text to form new prompt words.
[0016] Secondly, the present invention provides a topic-aware context-adaptive control system for multi-turn dialogue in power security, comprising: The text retrieval module is used to retrieve the text currently being queried by the user. The topic identification module is used to select a lightweight large language model as the topic perception model, and use the topic perception model to identify the topic of the query text to obtain the topic category and corresponding confidence level of the current query. The calculation module is used to calculate the semantic relevance score between the topic category of the current query and the most recent historical topic in the dialogue history; The strategy determination module is used to determine the context management strategy for the current round based on the topic category, corresponding confidence level, and semantic relevance score of the current query. The instruction generation module is used to filter out historical dialogue fragments that match the current strategy according to the context management strategy, and generate guiding instructions; The control module is used to combine the historical dialogue fragments, the current query text, and the guidance instructions into new prompt words, input them into the power safety analysis model, obtain the answer for the current round, update the question and answer for the current round and the corresponding topic category to the dialogue history, and realize adaptive control of topic-aware context.
[0017] Thirdly, the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, characterized in that the processor, when executing the computer program, implements the steps of the aforementioned topic-aware context-adaptive control method for multi-turn dialogue in power safety.
[0018] Fourthly, the present invention provides a computer-readable storage medium having a computer program stored thereon, characterized in that, when the computer program is executed by a processor, it implements the steps of the topic-aware context-adaptive control method for multi-turn dialogue in power safety.
[0019] Compared with existing technologies, the beneficial effects of this invention are as follows: This invention effectively alleviates the contextual interference problem in power safety analysis models during multi-turn dialogues within a single window. Experimental verification shows that this method can reduce information interference between different topics while fully maintaining the contextual coherence required for in-depth discussion within the same topic. It solves the problem that existing sliding window or manual reset methods cannot simultaneously address this issue, significantly improving the accuracy and reliability of the model's output in complex continuous dialogues. This invention achieves intelligent context management without user intervention, greatly enhancing user experience and platform usability. Users do not need to learn to start new dialogues or input special commands to naturally conduct multi-topic consultations within the same window, and the system automatically maintains topic purity. It is particularly suitable for business scenarios such as dispatching and command, and on-site inspections that require continuous consultation on multiple safety issues. This invention constructs a topic perception system based on knowledge in the field of power safety, which is highly targeted, with a clear and traceable management decision-making process. The output dialogue logs include topic tags and strategy selection information, facilitating operation and maintenance personnel to analyze model behavior and optimize the system, meeting the power industry's requirements for interpretable and auditable key artificial intelligence systems. As a key component of intelligent dialogue management, this method can be organically combined with the power safety knowledge base and professional analysis models to form a full-chain solution from data and models to reliable applications, thereby enhancing the overall effectiveness and practicality of the intelligent power safety analysis platform. Attached Figure Description
[0020] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0021] Figure 1 This is a schematic diagram of the overall process logic of a topic-aware context-adaptive control method for multi-turn dialogue in power security, provided as an embodiment of the present invention. Figure 2The above is an overall flowchart of a topic-aware context-adaptive control method for multi-turn dialogue in power security, provided in one embodiment of the present invention. Figure 3 This is a flowchart illustrating the real-time dialogue context management of a topic-aware context adaptive control method for multi-turn dialogue in power safety, provided as an embodiment of the present invention. Detailed Implementation
[0022] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of the present invention.
[0023] Example 1, referring to Figures 1-3 As an embodiment of the present invention, a topic-aware context-adaptive control method for multi-turn dialogue in power security is provided, comprising: S100: Get the user's current query text; In this embodiment of the invention, a topic classification system for the field of power safety is established. This system is based on the Southern Power Grid's safety production risk management system, power safety work procedures, and historical accident analysis reports. Power safety dialogues are divided into multiple primary categories, including equipment safety, operation safety, work safety, emergency management, and safety supervision. Each primary category can be further subdivided. For example, the equipment safety category can be subdivided into subcategories such as transformers, circuit breakers, and transmission lines. Each category is configured with a corresponding set of professional terms and keywords.
[0024] The user's current query text is the training data for the model, which comes from the company's historical security incident records, procedural documents, and manually constructed dialogue samples. Business experts have labeled the power safety topic categories to which the data belongs, resulting in approximately 52,000 high-quality labeled samples.
[0025] S200: Select a lightweight large language model as the topic-aware model, use the topic-aware model to identify the topic of the query text, and obtain the topic category and corresponding confidence level of the current query. In one optional embodiment, the lightweight large language model can be the lightweight Qwen-7B-Chat. The lightweight Qwen-7B-Chat model is loaded and initialized; the user query text is input into the model, and the power safety topic tag system is used for prompt guidance; the model outputs the topic category and confidence score; the output results are parsed using regular expressions to obtain standardized topic classification results. In another alternative embodiment, the lightweight large language model can also be a lightweight Llama-3-8B-Instruct, using the quantized lightweight Llama-3-8B-Instruct as a base; construct a classification instruction template for the power safety field, input user queries; the model performs instructional classification, outputs predicted topics and probabilities; extracts the category with the highest probability as the final topic category, and uses the probability as the confidence level; In this embodiment of the invention, the lightweight large language model includes the lightweight DeepSeek-7B model; Specifically, the system obtains the user's current query text and inputs it into a lightweight large language model finely tuned for the power safety field. The model performs semantic parsing and feature extraction on the query text, matches it with a pre-set power safety topic classification system, and outputs the topic category and confidence level corresponding to the current query, thus completing topic identification.
[0026] S300: Calculate the semantic relevance score between the current query topic category and the most recent historical topic in the conversation history; S400: Determine the context management strategy for the current round based on the topic category, corresponding confidence level, and semantic relevance score of the current query. S500: Filter historical dialogue fragments that match the current strategy based on the context management strategy, and generate guidance instructions; S600: Combines historical dialogue fragments, current query text, and guidance instructions into new prompt words, inputs them into the power safety analysis model, obtains the answer for the current round, updates the question and answer for the current round and the corresponding topic category to the dialogue history, and realizes adaptive control of topic-aware context.
[0027] like Figure 2 As shown, the system receives the user's current query, identifies the topic category and confidence level of the current query through the topic awareness module, and calculates the semantic relevance with historical topics. Based on this, it determines the relationship between the current query and historical topics. Depending on the situation, it uses coherence enhancement, relevance bridging, or isolation reset strategies. The context reorganization module filters and reorganizes historical dialogues according to the strategies and injects guiding instructions. It calls the power intrinsic safety analysis model to generate and output answers, updates the dialogue history and topic tags, and then monitors the user's subsequent interactions to determine whether there is topic confusion or answer deviation. If there are no abnormalities, it directly enters the next round of dialogue. If there are problems, it records feedback, optimizes parameters, and re-enters the dialogue loop, realizing topic awareness context adaptive control for multi-round dialogues for power safety.
[0028] It should be noted that this invention adaptively determines the context strategy through topic identification and relevance calculation, accurately filters historical dialogues and injects guiding instructions, effectively avoids cross-topic interference in multi-round dialogues in power safety, and ensures coherent and accurate analysis within the topic; it can achieve pure context control without manual operation by the user, improves the professionalism of the model's answers and the efficiency of interaction, and is suitable for continuous consultation scenarios at power sites.
[0029] In this embodiment of the invention, step S200 includes the following sub-steps A1-A3; In A1: Obtain the topics of power safety dialogues and categorize them into different topic categories; In A2: Fine-tune the topic perception model using instructions to obtain the fine-tuned topic perception model; In A3: The user's current query text is input into the fine-tuned topic-aware model, which outputs the topic category of the current query and calculates the confidence level of the corresponding topic category.
[0030] In one optional embodiment, fine-tuning the topic-aware model can be based on direct preference optimization. This involves compiling sample pairs of correct and incorrect topic classification labels for the same user query, constructing preference training data in the instruction format, loading the lightweight large language model to be fine-tuned, freezing the main model parameters, and enabling only the output layer parameters required for preference optimization. Using the probability distribution of topic categories output by the model as input, a loss function based on relative preference is constructed to measure the model's preference for correct labels. The preference data is input into the model, and the model parameters are updated through backpropagation to make the model more inclined to output correct labels within the power safety topic system. The topic classification accuracy and confidence stability of the model are evaluated on a test set. After fine-tuning, the topic-aware model is obtained. In another alternative embodiment, fine-tuning the topic-aware model can also be done using an adapter-based approach. A small bottleneck adapter network is inserted into the Transformer layer of the lightweight large language model, freezing the main model parameters and retaining only the trainable parameters of the adapter module. User query-topic tag samples from the power safety domain are compiled into instruction-formatted training data, including instruction templates for the topic recognition task. A low learning rate and batch size are set, optimizing only the parameters of the adapter module to avoid affecting the model's general semantic capabilities. The instruction data is input into the model, and the adapter parameters are updated through backpropagation, enabling the model to learn the semantic features and classification logic of power safety topics. After training, the adapter module is merged with the base model to obtain a lightweight model adapted for power safety topic awareness. In this embodiment of the invention, the instruction fine-tuning of the topic awareness model includes the LoRA (Low-Rank Adaptation) lightweight fine-tuning method, which is consistent with the fine-tuning method used in the prior art for power security analysis; Specifically, the base model is DeepSeek-7B, and low-rank decomposition matrices have been added to the Q, K, V, and O projection matrices of the self-attention layer, as well as to the gate_proj, up_proj, and down_proj modules of the feedforward network layer.
[0031] The specific configuration is as follows: rank 64, alpha 128, dropout rate 0.05. Training uses a learning rate of 2e-4, with a warm-up period of 100 steps. The optimizer is AdamW (β1=0.9, β2=0.999), the batch size is 8, the training epochs are 3, and the gradient clipping threshold is 1.0.
[0032] During the instruction fine-tuning phase, the input format is "[Question] + [Power Safety Domain Context]", and the output is the topic category label. Only the cross-entropy loss of the output part is calculated.
[0033] Finally, 5% of the data was reserved as a validation set to check the classification accuracy. If there was no improvement for two consecutive epochs, the process was stopped early, and the best-performing model was saved as a checkpoint.
[0034] The reserved validation set, comprising 3,000 labeled samples, covers 8 primary topic categories and 24 secondary subcategories. The samples are evenly distributed across categories. After fine-tuning, the model achieved a macro-average classification accuracy of 94.5% on the reserved validation set. The F1 scores for core categories such as transformer faults, switching operations, and relay protection all exceeded 93%. The confusion matrix showed that the main classification errors occurred between similar procedure categories, such as work permit issuance and work permit authorization, which was in line with expectations.
[0035] In one optional embodiment, the confidence score can be calculated using the difference between the maximum and second-highest probabilities. The model outputs the original score for each topic category, which is then converted into probabilities for each category using softmax. The maximum and second-highest probability values are then extracted. The confidence score is the difference between the maximum and second-highest probabilities. The larger the difference, the more certain the current topic classification is; the smaller the difference, the less certain the classification is. In another alternative embodiment, the confidence level can also be calculated using the entropy normalization method. First, the probability distribution of all topic categories is calculated. Then, the entropy is calculated using the information entropy formula. The entropy value is the product of the probability of each category and the negative of the logarithm of that probability. The results are then summed. The confidence level is 1 minus the entropy value divided by the maximum possible entropy value. The smaller the entropy, the more certain the classification, and the higher the confidence level. The larger the entropy, the more ambiguous the classification, and the lower the confidence level. In this embodiment of the invention, calculating the confidence level includes calculation using softmax probability; Specifically, the system inputs the user's current query text into the topic-aware model, and the model outputs the topic category and confidence level. The confidence level output by the topic-aware model is obtained through softmax probability calculation.
[0036] Given input query The model outputs a set of topic categories. , This represents the total number of topic categories. The model first calculates the logit value for each category. Then, after being converted into a probability distribution using the softmax function, it is expressed as: in, Indicates a given query Under the conditions, topic categories The posterior probability, , These represent the original logit values output by the model. The total number of all topic categories.
[0037] The confidence level is taken as the maximum probability, expressed as: when When the confidence level is high, the topic classification result is reliable; when... At this time, the system will additionally trigger domain terminology matching for secondary verification.
[0038] It should be noted that LoRA lightweight fine-tuning improves topic recognition accuracy, with a macro average accuracy of 94.5% and a core category F1 score exceeding 93%. Combined with softmax confidence and secondary verification, the classification is stable, reliable, and suitable for power industry scenarios.
[0039] In this embodiment of the invention, step S300 includes the following sub-steps B1-B2; In B1: Extraction rules are used to extract the core power safety professional terms in the current query text and the most recent historical topics in the dialogue history, forming the first term set and the second term set. In B2: The similarity between the first term set and the second term set is calculated as a semantic relevance score.
[0040] In one optional embodiment, the semantic relevance score can be calculated using a semantic vector matching method based on cosine similarity. The current query topic text and historical topic text are input into a text encoder finely tuned for the power safety field to generate corresponding high-dimensional semantic vectors. The cosine value of the angle between the two vectors in space is calculated to obtain a similarity value in the range of 0 to 1. The cosine value is mapped to a semantic relevance score, where the closer the value is to 1, the more relevant the topic is semantically, and the closer it is to 0, the less relevant the topic is. In another optional embodiment, the semantic relevance score can also be calculated using the concept path similarity method based on the power safety knowledge graph. This involves extracting key entities and concepts in the power safety field from the current query topic and historical topic texts, and mapping them to preset power safety knowledge graph nodes. In the knowledge graph, the shortest path length between two nodes is calculated, and the concept relevance is obtained by combining the node's hierarchical depth and common ancestor node. The path distance and hierarchical weight are then normalized to obtain the final semantic relevance score. In this embodiment of the invention, calculating the semantic relevance score includes calculating the Jaccard similarity between the current query and the core term set of historical topics; Specifically, for the current query Excerpts from a dialogue with history Extract the electrical safety terminology from each part and construct a terminology set. and .
[0041] The terminology extraction adopts the following rules: priority is given to matching from the pre-set power safety terminology database using the positive maximum matching method; if a term is not included in the terminology database, the top 20 words with the highest weights are selected as supplements based on TF-IDF weights.
[0042] The Jaccard similarity is calculated as follows: in, This indicates the number of elements in the intersection of two sets of terms. This represents the number of elements in the union. When the union is empty, the similarity is defined as 0.
[0043] The core terminology of historical dialogue fragments The terminology was obtained by weighting the terms extracted from the most recent three rounds of dialogue, with more recent rounds given higher weight.
[0044] It should be noted that, based on the extraction of power industry terminology and weighted Jaccard similarity calculation, the relevance of topics is accurately reflected, and weighted voting strengthens recent information, adapting to power scenarios and improving the accuracy and stability of topic switching judgment.
[0045] In this embodiment of the invention, step S400 includes the following sub-steps C1-C6; In C1: In response to a confidence level greater than or equal to the first threshold, a first judgment is made between the topic category of the current query and the topic category of the most recent historical topic in the dialogue history; In C2: Based on the first judgment result, a second judgment is made on the semantic relevance score to obtain the corresponding context management strategy.
[0046] In C3: If the topic category of the current query is the same as the topic category of the most recent historical topic in the conversation history, it is determined to be a topic continuation, and the coherence enhancement strategy is selected. In C4: In response to the fact that the topic category of the current query is different from the topic category of the most recent historical topic in the dialogue history, a second judgment is made on the semantic relevance score; In C5: In response to a semantic relevance score that is greater than the second threshold and less than the third threshold, it is determined to be a related topic switch, and the association bridging strategy is selected. In C6: In response to a semantic relevance score that is less than or equal to the second threshold, it is determined to be an irrelevant topic switch, and the isolation reset strategy is selected; In C7: In response to a semantic relevance score greater than or equal to the third threshold, a strong topic shift is identified, and a coherence enhancement strategy is selected.
[0047] In embodiments of the present invention, such as Figure 3 As shown, when the confidence level of the current query is greater than or equal to the first threshold of 0.7, it is determined whether the topic category of the current query is the same as the topic category of the most recent historical topic in the dialogue history. If they are the same, it is determined to be a topic continuation, and the coherence enhancement strategy is selected. If the topic category of the current query is different from the topic category of the most recent historical topic in the dialogue history, the semantic relevance score is further judged, with a second threshold of 0.1 and a third threshold of 0.4. If the semantic relevance score is greater than the second threshold but less than the third threshold, i.e., between 0.1 and 0.4, it is determined to be a related topic switch, and the association bridging strategy is selected. If the semantic relevance score is less than or equal to the second threshold of 0.1, it is determined to be an irrelevant topic switch, and the isolation and reset strategy is selected.
[0048] If the semantic relevance score is greater than or equal to the third threshold of 0.4, it means that although the current query topic and the historical topic belong to different topic categories, they are strongly related at the semantic level. In this case, it is judged as a strong topic change, and the coherence enhancement strategy is still selected.
[0049] In this embodiment of the invention, step S500 includes the following sub-steps D1-D3; In D1: In response to the coherence enhancement strategy, all historical question-and-answer pairs with the same topic tags as the current query topic category are filtered from the dialogue history to form a complete historical fragment; In D2: In response to the association bridging strategy, select at most two-round question-and-answer pairs that are weakly related to the current query topic from the dialogue history to form a short bridging history fragment. In D3: In response to the isolation reset policy, all specific historical dialogue content is cleared, only system-level fixed commands and current user query text are retained, and no historical question-and-answer pairs are retained.
[0050] In this embodiment of the invention, for the coherence enhancement strategy, the system filters out all question-answer pairs whose topic tags are the same as the current query topic category from the dialogue history to form a complete historical segment.
[0051] Specifically, each round in the dialogue history is traversed, and the topic tag for that round is extracted. If the tag matches the current topic, the round is retained. Finally, these rounds are pieced together into a coherent context in chronological order. For example, multiple follow-up questions about the same equipment malfunction, or step-by-step consultations on the same operating procedure, are all retained.
[0052] For the relevance bridging strategy, the system selects at most 1 to 2 rounds of question-and-answer pairs that are weakly related to the current query topic from the dialogue history, forming a short bridging history segment.
[0053] Specifically, first calculate the association type between the current topic and each round of historical dialogue, including equipment association, procedure association, and operation association. Identify the rounds with matching types, and then prioritize retaining segments containing the same equipment type (e.g., transformer-related) or associated operation steps (e.g., operation tickets and risk assessments or adjacent procedure clauses). For example, when switching from transformer maintenance to switchgear maintenance, retain one round of transformer-related dialogue; when switching from safety procedures to emergency plans, retain segments related to procedure numbers.
[0054] The isolation reset strategy is applicable to scenarios involving switching between completely unrelated topics; Specifically, the system will clear all historical Q&A content, retaining only system role definition instructions, basic session configuration parameters, and user identity and permission information. At this point, the context consists of basic system instructions plus the current user query, responding to new topics with zero historical context to avoid interference from previous content in the new discussion. The filtered history, the current user query, and the guidance instructions generated according to the strategy are combined into new prompts. These guidance instructions are used to clearly inform the model of the current focus of the dialogue, such as asking the user to focus on a particular topic or ignoring previous discussions on that topic.
[0055] In this embodiment of the invention, step S600 includes the following sub-steps E1-E5; In E1: In response to the context management strategy being a coherence enhancement strategy, an instruction template is selected to prompt the model to focus on the current topic; In E2: In response to the context management strategy being an association bridging strategy, select an instruction template for prompting the model to incorporate relevant historical topics; In E3: In response to the context management strategy being an isolation reset strategy, select the instruction template used to prompt the model to ignore previous topics and focus only on the current issue; In E4: Fill the placeholder of the instruction template with the topic category name of the current query text to generate the specific guidance instruction text; In E5: The generated guidance instructions are combined with the filtered historical dialogue fragments and the current query text to form new prompt words.
[0056] In this embodiment of the invention, each of the three screening strategies has a corresponding instruction template, used to convey different contextual usage methods to the model. It is worth noting that all strategies share a set of basic system instructions, the model role is set as a power safety analysis expert, and responses involving power operations must comply with specific regulations and are based solely on knowledge in the field of power safety.
[0057] The instruction template for enhancing coherence is suitable for topic continuation scenarios. The template content is: Please conduct an in-depth analysis around the topic [{topic_name}]. The current dialogue is a continuation of previous discussions. When answering, please refer to the following historical context. Where {topic_name} is the standardized name of the current topic, such as "Transformer Fault Diagnosis" or "Switching Operation Risk Assessment".
[0058] Example: Replace {topic_name} in the above template with "Relay protection setting verification".
[0059] The instruction template for the relevance bridging strategy is suitable for switching between weakly related topics. The template content is: "Transfer the current discussion to the topic [{current_topic}]. You can refer to the related history given below, but the focus is still on answering the current question. The historical content is for reference only; if it is irrelevant to the current question, you can ignore it." The parameter {current_topic} is the name of the topic to which the current query belongs.
[0060] Example: Replace {current_topic} with "infrared temperature measurement".
[0061] The isolation reset policy instruction template is applicable to completely unrelated topic switching scenarios. The template content is: Ignore all previous historical conversations. The current question belongs to the topic [{current_topic}]. Please answer directly based on your knowledge in the field of power safety, and do not cite any historical information.
[0062] Example: Replace {current_topic} with "device inspection".
[0063] like Figure 3 As shown, the recombined prompts are input into the power safety analysis model, and the answer for this round is returned to the user. At the same time, the question-and-answer pair and the corresponding topic tags for this round are updated to the dialogue history.
[0064] The power safety analysis model is a fine-tuned version of the general large language model, specifically designed for power safety issues such as equipment fault diagnosis, operational risk assessment, and interpretation of regulations and clauses.
[0065] In this embodiment of the invention, GLM-4-9B-Chat from Zhipu AI is selected as the base model. This model has 9 billion parameters, adopts the GLM pre-training architecture, and natively supports Chinese dialogue, instruction following, and domain question answering.
[0066] To make the model more adaptable to power safety scenarios, it was further pre-trained using approximately 50GB of power safety domain corpus. Approximately 80,000 domain question-answer pairs were constructed for instruction fine-tuning, and a power safety knowledge graph of approximately 100,000 entities and 500,000 triples was integrated to enhance knowledge recall.
[0067] The specific inputs to the model include user queries, reconstructed context, and system instructions, while the output is a text response that conforms to power safety professional standards.
[0068] This large-scale analysis model works in collaboration with the previously mentioned topic-aware model. The topic-aware model specifically determines which professional topic the user's question belongs to and decides what kind of context to use. The large-scale analysis model is responsible for generating the final professional answer. The two work together, defining the context first and then generating the answer.
[0069] The system records every context management decision, including topic classification results, relevance scores, selected strategies, and whether users subsequently exhibit corrective behavior or negative feedback. Operations personnel can periodically export these logs to analyze erroneous decision cases and use them to supplement the training data of the topic awareness model or manually adjust the strategy thresholds.
[0070] It should be noted that this invention adapts multi-round dialogues on power safety through hierarchical decision-making and dynamic strategies, accurately distinguishes between topic continuation, weakly related switching, and irrelevant switching, automatically filters the context and injects dedicated guidance instructions, taking into account both intra-topic coherence and cross-topic isolation; the dual-model division of labor and cooperation improves the professionalism and accuracy of the answers, the decision is traceable and supports closed-loop optimization, no manual operation by the user is required, and significantly improves the efficiency and reliability of power safety consultation.
[0071] Example 2, referring to Table 1, differs from the first example. It provides a verification test for topic-aware context-adaptive control in multi-turn dialogue for power safety, and verifies the technical effects of the method.
[0072] Taking a real-world dialogue scenario as an example, the user discussed the verification of relay protection settings for 110 kV tower lines in the first few rounds. In the fourth round, the user asked about precautions for infrared temperature measurement during routine substation inspections. The system identified the new query topic as equipment inspection, which had low relevance to the historical topic of relay protection. This triggered an isolation and reset strategy. The prompts submitted to the model included basic instructions, instructions to focus on equipment inspection issues, and the user's current question. The model's generated answer focused on infrared temperature measurement and did not involve relay protection settings.
[0073] The experimental hardware configuration consisted of a server equipped with an NVIDIA A100 graphics card, and the software environment was an Ubuntu operating system. The PyTorch deep learning framework was used, and the core analysis model used in the experiment was a large language model specifically for the power safety industry, which was fine-tuned based on corpora in the power safety field.
[0074] To objectively evaluate the effectiveness of the method, a dedicated test set was constructed from historical data of power grid intrinsic safety analysis. The data source was the records of safety hazards and accidents stored in the company's internal Dameng database over the past two years, with a total of 2,000 records extracted.
[0075] Technical personnel familiar with the business compiled the problem descriptions and cause analyses from these records into test sequences that simulated real dialogues using AI-assisted manual editing. Each dialogue sequence contained 4 to 6 rounds of question and answer, with deliberate arrangements for switching between different professional topics. Ultimately, a test set containing 425 dialogue sequences and a total of 2040 rounds of question and answer was constructed. Each round of question and answer was labeled with the expected topic category and the theoretically relevant historical context.
[0076] Three comparison benchmark methods are established: Benchmark 1: Input all historical dialogue context; Benchmark 2: Input the history of the last three rounds of dialogue (sliding window); Benchmark 3: Clear the history when topic keyword changes are detected (naive reset).
[0077] The method of this invention is referred to as the test method.
[0078] The evaluation is conducted by combining automated quantitative indicators with model assessment.
[0079] There are two automation metrics: First, topic isolation: For each round in the test set marked as "topic switching occurred," a set of keywords for "historical topics that should be ignored" is extracted. The percentage of these irrelevant keywords appearing in the model's response (number of irrelevant words / total number of words in the response) is then calculated. The lower this percentage, the better the isolation effect. For easy comparison, isolation is defined as (1 - percentage of irrelevant words) × 100, meaning higher isolation is better. For example, if the model's response contains no irrelevant keywords at all, the isolation is 100; if half the words are irrelevant, the isolation is 50.
[0080] Second, the score for topic coherence: For each round in the test set marked as "topic continuation and requiring historical reference", define its "key information points that must be referenced", such as equipment parameters, procedure clause numbers, etc. Check whether the model's answer completely and accurately contains these information points, and calculate the score according to the inclusion ratio (number of included information points / total number of information points × 100).
[0081] The deepseek-v3.2 large language model was selected for model evaluation. 425 randomly sampled rounds of model responses were scored using a 5-point scale, considering both topic isolation and logical coherence. Specific scoring criteria were set as follows: Topic isolation: 5 points indicates the answer is completely focused on the current topic, with no trace of historical information interfering; 1 point indicates the answer is severely confused by historical content, with a large amount of irrelevant information mixed in. Logical coherence: 5 points indicates the answer can naturally and accurately integrate relevant key historical information when it needs to reference history; 1 point indicates the answer is disconnected from the historical context or contains citation errors. The main results are shown in Table 1, obtained by running the various comparison methods on the constructed test set.
[0082] Table 1. Results of running the comparison method on the test set.
[0083] As shown in Table 1, the topic isolation score of the baseline (all history) is only 58.2, indicating that irrelevant historical information seriously interferes with the current answer. This can lead to problems such as still referencing a large number of device parameters from the previous topic after switching topics. Its coherence score is the highest at 88.5 because all history is preserved and will not be missed when needed.
[0084] The isolation of baseline 2 (sliding window) increased to 72.8, while the coherence decreased to 65.4, indicating that although the sliding window discards some old history, it may also lose early key information under the same topic.
[0085] The baseline 3 (naive reset) has an isolation of 94.5, which almost completely isolates historical interference, but the coherence is only 12.7, indicating that the model is basically unable to refer to history when it is necessary to continue the discussion, and the dialogue has serious breaks.
[0086] The isolation score of the method in this invention reaches 92.1, which is very close to the best benchmark three, indicating that it can effectively identify topic switching and isolate irrelevant history. The score is slightly lower than benchmark three because in the scenario of "weakly related topic switching", 1-2 rounds of related history are selectively retained as a bridge. This part of history may bring a very small number of marginal related words, resulting in a slight decrease in isolation score. However, the topic coherence score is 84.3, which is significantly better than benchmark two (65.4) and benchmark three (12.7), and only slightly lower than benchmark one (88.5). In actual dialogue experience, the benefits far outweigh the disadvantages. This result proves that the method in this invention achieves the best balance between isolating interference and maintaining coherence: in the scenario of topic continuation, it can completely retain the necessary history to obtain coherence close to "all history"; in the scenario of topic switching, it can effectively cut off interference like "naive reset". The model scoring results also consistently show that the method in this invention has the best overall performance in terms of focus and coherence.
[0087] Example 3 illustrates a schematic scheme of a topic-aware context-adaptive control method for multi-turn dialogue in power security, as described in this embodiment. It should be noted that the technical solution of this topic-aware context-adaptive control system for multi-turn dialogue in power security belongs to the same concept as the technical solution of the aforementioned topic-aware context-adaptive control method for multi-turn dialogue in power security. Details not described in detail in this embodiment can be found in the description of the aforementioned topic-aware context-adaptive control method for multi-turn dialogue in power security.
[0088] This embodiment presents a topic-aware, context-adaptive control system for multi-turn dialogue in power security, comprising: The text retrieval module is used to retrieve the text currently being queried by the user. The topic identification module is used to select a lightweight large language model as the topic perception model, and use the topic perception model to identify the topic of the query text to obtain the topic category and corresponding confidence level of the current query. The calculation module is used to calculate the semantic relevance score between the topic category of the current query and the most recent historical topic in the dialogue history; The strategy determination module is used to determine the context management strategy for the current round based on the topic category, corresponding confidence level, and semantic relevance score of the current query. The instruction generation module is used to filter out historical dialogue fragments that match the current strategy according to the context management strategy, and generate guiding instructions; The control module is used to combine the historical dialogue fragments, the current query text, and the guidance instructions into new prompt words, input them into the power safety analysis model, obtain the answer for the current round, update the question and answer for the current round and the corresponding topic category to the dialogue history, and realize adaptive control of topic-aware context.
[0089] This embodiment also provides a computer device applicable to a topic-aware context-adaptive control method for multi-turn dialogues in power safety, including: The system includes a memory and a processor. The memory stores computer-executable instructions, and the processor executes these instructions to implement a topic-aware context-adaptive control method for multi-turn dialogue in power security, as proposed in the above embodiments.
[0090] This embodiment also provides a storage medium storing a computer program that, when executed by a processor, implements a topic-aware context-adaptive control method for multi-turn dialogue in power security as proposed in the above embodiment.
[0091] The storage medium proposed in this embodiment and the topic-aware context-adaptive control method for implementing multi-turn dialogue for power security proposed in the above embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.
[0092] Based on the above description of the implementation methods, those skilled in the art will clearly understand that the present invention can be implemented using software and necessary general-purpose hardware, and of course, it can also be implemented using hardware. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as a computer floppy disk, read-only memory (ROM), random access memory (RAM), flash memory, hard disk, or optical disk, etc., including several instructions to cause a computing device (which may be a personal computer, server, or network device, etc.) to execute the methods of the various embodiments of the present invention.
[0093] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A topic-aware, context-adaptive control method for multi-turn dialogue in power security, characterized in that, include: Get the user's current query text; A lightweight large language model is selected as the topic-aware model. The topic-aware model is used to identify the topic of the query text to obtain the topic category and corresponding confidence level of the current query. Calculate the semantic relevance score between the current query topic category and the most recent historical topic in the dialogue history; The context management strategy for the current round is determined based on the current topic category, the corresponding confidence level, and the semantic relevance score. Based on the context management strategy, historical dialogue fragments matching the current strategy are selected, and guiding instructions are generated; The historical dialogue fragments, the current query text, and the guidance instructions are combined into new prompt words, which are then input into the power safety analysis model to obtain the answer for the current round. The questions and answers for the current round and the corresponding topic categories are then updated in the dialogue history to achieve adaptive control of topic-aware context.
2. The topic-aware context-adaptive control method for multi-turn dialogue in power security as described in claim 1, characterized in that, Topic identification of the query text includes: Obtain the topics for power safety dialogues and categorize them into different topic categories; The topic perception model is fine-tuned using instructions to obtain the fine-tuned topic perception model. Input the user's current query text into the fine-tuned topic awareness model, output the topic category of the current query, and calculate the confidence score of the corresponding topic category.
3. The topic-aware context-adaptive control method for multi-turn dialogue in power security as described in claim 2, characterized in that, The semantic relevance score calculation includes: Extraction rules are used to extract the core power safety professional terms in the current query text and the most recent historical topics in the dialogue history, forming a first term set and a second term set. The similarity between the first term set and the second term set is calculated as a semantic relevance score.
4. The topic-aware context-adaptive control method for multi-turn dialogue in power security as described in claim 3, characterized in that, Determining the context management strategy for the current round includes: In response to a confidence level greater than or equal to the first threshold, a first judgment is made between the topic category of the current query and the topic category of the most recent historical topic in the dialogue history; Based on the first judgment result, a second judgment is made on the semantic relevance score to obtain the corresponding context management strategy.
5. A topic-aware context-adaptive control method for multi-turn dialogue in power security as described in claim 3 or 4, characterized in that, The first judgment includes: If the topic category of the current query is the same as the topic category of the most recent historical topic in the conversation history, it is determined to be a topic continuation, and a coherence enhancement strategy is selected. If the topic category of the current query is different from the topic category of the most recent historical topic in the dialogue history, a second judgment is made on the semantic relevance score; If the semantic relevance score is greater than the second threshold but less than the third threshold, it is determined to be a related topic switch, and the association bridging strategy is selected. If the semantic relevance score is less than or equal to the second threshold, it is determined to be an irrelevant topic switch, and the isolation and reset strategy is selected. If the semantic relevance score is greater than or equal to the third threshold, it is determined to be a strongly related topic shift, and a coherence enhancement strategy is selected.
6. The topic-aware context-adaptive control method for multi-turn dialogue in power security as described in claim 5, characterized in that, The historical dialogue segments that match the current strategy include: In response to the coherence enhancement strategy, all historical question-and-answer pairs with the same topic tags as the current query topic category are filtered from the dialogue history to form a complete historical fragment; In response to the association bridging strategy, select at most two-round question-and-answer pairs that are weakly related to the current query topic from the dialogue history to form a short bridging history fragment. In response to the isolation reset policy, all specific historical dialogue content is cleared, only system-level fixed commands and current user query text are retained, and no historical question-and-answer pairs are retained.
7. A topic-aware context-adaptive control method for multi-turn dialogue in power security as described in claim 6, characterized in that, Combining the historical dialogue fragments, the current query text, and the guidance instructions into new prompt words includes: In response to the context management strategy being a coherence enhancement strategy, an instruction template is selected to prompt the model to focus on the current topic; In response to the context management strategy being an association bridging strategy, an instruction template is selected to prompt the model in conjunction with relevant historical topics; In response to the context management strategy of isolation and reset, select an instruction template to prompt the model to ignore previous topics and focus only on the current issue; Enter the topic category name of the current query text into the placeholder in the instruction template to generate the specific guidance instruction text; The generated guidance instructions are combined with the filtered historical dialogue fragments and the current query text to form new prompt words.
8. A topic-aware context-adaptive control system for multi-turn dialogue in power security, employing the topic-aware context-adaptive control method for multi-turn dialogue in power security as described in any one of claims 1-7, characterized in that, include: The text retrieval module is used to retrieve the text currently being queried by the user. The topic identification module is used to select a lightweight large language model as the topic perception model, and use the topic perception model to identify the topic of the query text to obtain the topic category and corresponding confidence level of the current query. The calculation module is used to calculate the semantic relevance score between the topic category of the current query and the most recent historical topic in the dialogue history; The strategy determination module is used to determine the context management strategy for the current round based on the topic category, corresponding confidence level, and semantic relevance score of the current query. The instruction generation module is used to filter out historical dialogue fragments that match the current strategy according to the context management strategy, and generate guiding instructions; The control module is used to combine the historical dialogue fragments, the current query text, and the guidance instructions into new prompt words, input them into the power safety analysis model, obtain the answer for the current round, update the question and answer for the current round and the corresponding topic category to the dialogue history, and realize adaptive control of topic-aware context.
9. A computer device, characterized in that, include: A memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the topic-aware context-adaptive control method for multi-turn dialogue in power security as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, It stores a computer program, which, when executed by a processor, implements the steps of a topic-aware context-adaptive control method for multi-turn dialogue in power safety as described in any one of claims 1 to 7.
