Electricity safety intelligent question and answer method and system, electronic equipment and medium
By using an intelligent question-and-answer method and system for electricity safety, combined with a large language model and multi-channel retrieval tools, multi-round reasoning loops and evidence verification for electricity safety issues are realized. This solves the limitations of manual inspection and the interpretability problem of the large language model, thereby improving the accuracy of analysis and the performance of the system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-16
- Publication Date
- 2026-03-13
AI Technical Summary
Existing electricity safety inspections rely on manual inspections, which makes it difficult to identify potential hidden risks and cannot meet the complex needs of modern power systems. Furthermore, the application of large language models suffers from illusion problems and poor interpretability of output results.
The method of intelligent question answering for electricity safety is adopted. It uses a large language model to analyze intent, generate reasoning guidance instructions, activate the reasoning and action thinking chain to carry out multiple rounds of reasoning loops, combine multi-channel retrieval tools to retrieve evidence in parallel, and perform evidence sufficiency verification in each round of loop. The tool scheduling strategy is optimized to achieve adaptive adjustment.
It improves the analytical precision and accuracy of answers to complex electrical safety issues, enhances the traceability and interpretability of the reasoning process, reduces model illusions, and ensures system performance.
Smart Images

Figure CN121660065A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent electricity safety technology, specifically to an intelligent question-and-answer method and system for electricity safety, electronic equipment, and media. Background Technology
[0002] The rapidly developing power industry today has an increasingly urgent need for stable power supply, especially with the new electricity consumption patterns brought about by distributed energy, electric vehicles, and energy storage devices posing a more severe challenge to electricity safety management. At the same time, power grid companies are increasingly extending their safety control to the grassroots level, which places higher demands on the professional capabilities of on-site operators.
[0003] Current electricity safety inspections still primarily rely on manual checks by frontline workers. This traditional method often fails to identify potential hidden risks, allowing end-point faults to escalate into widespread failures, and is ill-suited to the complex demands of modern power systems. While attempts have been made to introduce large language models, these methods cannot resolve the pervasive illusion problem and result in poor interpretability of the output. Summary of the Invention
[0004] To overcome the above-mentioned technical problems, the present invention provides an intelligent question-and-answer method and system for electrical safety, an electronic device, and a medium.
[0005] On one hand, the present invention provides an intelligent question-and-answer method for electricity safety, comprising: Receive multimodal electricity safety questions input by the user; invoke a large language model to perform intent parsing on the multimodal electricity safety questions and generate inference guidance instructions; The reasoning guidance instruction activates the reasoning and action thought chain to perform multiple rounds of reasoning loops, obtaining the reasoning state and corresponding reasoning evidence for each round; Based on the reasoning state and corresponding reasoning evidence in each round, an answer bound to the reasoning evidence is generated; Each round of reasoning loop includes a thinking phase, an action phase, an observation phase, a reflection phase, and a planning phase. The thinking phase includes generating a current tool scheduling strategy based on the current reasoning state and a preset tool registry. The action phase includes optimizing the current tool scheduling strategy with the goal of minimizing tool call costs and response latency, and calling multi-channel retrieval tools for parallel retrieval and evidence collection based on the optimization results. The observation phase includes obtaining the retrieval results returned by the tool calls and extracting multiple key pieces of evidence. The reflection phase includes fusing multiple key pieces of evidence and verifying the sufficiency of the evidence based on the data quality of the fused results. The planning phase includes planning and formulating subsequent reasoning strategies and determining the loop direction based on the sufficiency verification results. The retrieval results of each tool call serve as a new reasoning state, used to update the current reasoning state and participate in the next round of reasoning loop.
[0006] Optionally, the tools in the tool registry include at least two of the following: small model calling tools, relational database tools, speech recognition tools, remote storage tools, and knowledge graph tools; The small model invocation tool is used to invoke different domain-specific small models to perform corresponding tasks; The relational database tool is used to invoke the relational database to execute corresponding tasks; The speech recognition tool integrates a speech recognition interface from a third-party application programming interface service to recognize the user's voice input. The remote storage tool is used to invoke the remote document service to execute corresponding tasks; The knowledge graph tool is used to call upon knowledge graphs in the field of electrical safety to perform corresponding tasks.
[0007] Optionally, the multi-channel retrieval tool includes a relational database tool; the step of calling the multi-channel retrieval tool in parallel forensic retrieval based on the optimization results includes: The data schema of the relational database corresponding to the relational database tool is parsed, and based on the parsing results and the multimodal electricity safety problem, a large model prompt word of the relational database is constructed; Based on the large model prompts and read / write security constraints of the relational database, the large language model is guided to generate the corresponding target query statement; The relational database is searched and evidence is collected based on the target query statement; if the search fails, the target query statement is corrected based on the error type returned by the tool call, and a fuzzy matching query is performed based on the corrected result; The read-write security constraint is used to restrict the large language model's operations on the heterogeneous database to read-write operations.
[0008] Optionally, the multi-channel retrieval tool includes a knowledge graph tool, which includes a semantic retrieval tool and a keyword retrieval tool; the parallel retrieval of evidence based on the optimization results using the multi-channel retrieval tool includes: The semantic retrieval tool is invoked to convert the multimodal electricity safety issues into query vectors through an embedded language model; based on the similarity between the query vectors and the vector representations of each node in the electricity safety domain knowledge graph, evidence is retrieved from the electricity safety domain knowledge graph. The keyword retrieval tool is used to extract the problem keywords of the multimodal electricity safety issues; a knowledge graph retrieval query statement in the field of electricity safety is generated based on the preset retrieval matching conditions; and evidence is obtained by retrieving the knowledge graph in the field of electricity safety based on the knowledge graph retrieval query statement. The retrieval and evidence collection process based on the target query statement, the semantic retrieval tool, and the keyword retrieval tool is executed in parallel.
[0009] Optionally, the fusion of multiple key pieces of evidence, and the verification of the sufficiency of the evidence based on the data quality of the fusion result, includes: Multiple pieces of key evidence were integrated to form a key evidence set; Based on the number of pieces of evidence, their sources, their timeliness, and their credibility in the key evidence set, a sufficiency score for the evidence in the key evidence set is determined. Sufficiency verification is performed based on the sufficiency score and the preset sufficiency threshold; Several key pieces of evidence were extracted from the search results of relational database tools, semantic search tools, and keyword search tools.
[0010] Optionally, if the reasoning guidance instructions include analysis instructions for the user-uploaded file to be analyzed, the thinking phase further includes: The feature inspector of the large language model is invoked to parse and preprocess the user-uploaded file to be analyzed, and the data to be analyzed is obtained. The action phase also includes: calling multiple domain-specific small models in parallel to analyze and process the data to be analyzed, and obtaining the analysis results of each domain-specific small model; The planning phase also includes generating corresponding answer contexts based on the analysis results of the multimodal electricity safety issues and multiple domain-specific small models, and feeding them back to the user.
[0011] Optionally, the parallel retrieval and evidence collection process also includes: The execution indicators of each tool call are maintained in the tool registry; The performance metrics include at least one of the following: success rate of tool invocation, response latency, invocation error rate, and system load corresponding to tool invocation.
[0012] Optionally, optimizing the current tool scheduling strategy with the goal of minimizing tool invocation costs and response latency includes: Based on the tool call execution metrics corresponding to each candidate tool according to the current tool scheduling strategy, determine the routing weight of each candidate tool; The candidate tools are prioritized based on their routing weights to generate an optimized tool scheduling strategy.
[0013] Optionally, the step of invoking a large language model to perform intent parsing on the multimodal electricity safety issue and generating inference guidance instructions includes: The large language model is invoked to extract entities and identify keywords for the multimodal electricity safety issues. Based on the identified keywords and contextual information, the business domain and set of business tasks are determined. Based on the aforementioned business domain and set of business tasks, as well as pre-set prompt word engineering templates, guided reasoning instructions are generated.
[0014] Optionally, based on the reasoning state and corresponding reasoning evidence in each round, an answer bound to the reasoning evidence is generated, including: The reasoning conclusion is generated based on the reasoning state in each round; For each reasoning conclusion, the reasoning conclusion is bound to the reasoning evidence associated with the corresponding reasoning state; Reasoning conclusions without supporting evidence are marked as unreliable and blocked. The answer is generated based on a conclusion that is supported by reasoning.
[0015] Optionally, the action phase further includes: If service unavailability or authentication failure occurs during tool invocation, a retry mechanism will be automatically triggered, and a backup tool will be switched or a delayed retry will be performed according to the preset strategy.
[0016] On the other hand, the present invention provides an intelligent question-and-answer system for electricity safety, comprising: The user interaction layer is used to receive multimodal electricity safety questions input by users; it is also used to output answers that are linked to reasoning evidence. The proxy layer is used to call the large language model to perform intent parsing on the multimodal electricity safety issue and generate reasoning guidance instructions; the reasoning guidance instructions activate the reasoning and action thinking chain to perform multiple rounds of reasoning loops, and obtain the reasoning state and corresponding reasoning evidence for each round; The large language model layer is used to generate answers that are bound to the reasoning evidence based on the reasoning state and corresponding reasoning evidence in each round. Each round of reasoning loop includes a thinking phase, an action phase, an observation phase, a reflection phase, and a planning phase. The thinking phase includes generating a current tool scheduling strategy based on the current reasoning state and a preset tool registry. The action phase includes optimizing the current tool scheduling strategy with the goal of minimizing tool call costs and response latency, and calling multi-channel retrieval tools for parallel retrieval and evidence collection based on the optimization results. The observation phase includes obtaining the retrieval results returned by the tool calls and extracting multiple key pieces of evidence. The reflection phase includes fusing multiple key pieces of evidence and verifying the sufficiency of the evidence based on the data quality of the fused results. The planning phase includes planning and formulating subsequent reasoning strategies and determining the loop direction based on the sufficiency verification results. The retrieval results of each tool call serve as a new reasoning state, used to update the current reasoning state and participate in the next round of reasoning loop.
[0017] Optionally, it also includes: The tool layer is used for unified tool registration and metadata management through standardized tool interfaces; and generates tool scheduling strategies for the reasoning and action thought chain of the agent layer through intelligent routing. The tool layer includes at least two of the following: small model calling tools, relational database tools, speech recognition tools, remote storage tools, and knowledge graph tools.
[0018] Optionally, the feature is that it further includes: The knowledge storage layer is used to store professional knowledge in the field of electrical safety through a multimodal storage architecture; The knowledge storage layer includes a knowledge graph and a relational database in the field of electricity safety; the knowledge graph in the field of electricity safety is used to store the entity relationship network of various power equipment; the relational database is used to store electricity safety standards and historical electricity safety records of various power equipment.
[0019] Optionally, it also includes: The knowledge collection layer is used to automatically collect, preprocess, and manage multi-source knowledge data in the field of electrical safety through a distributed architecture. The knowledge collection layer includes a remote document processing service and a local data acquisition module; the remote document processing service is used to remotely transmit, remotely vectorize, and remotely store documents uploaded to the system. The local data acquisition module is used to collect local network content and local multi-source files.
[0020] On the other hand, the present invention also provides an electronic device, comprising: at least one processor and a memory; the memory and the processor are connected via a bus; The memory is used to store one or more programs; When the one or more programs are executed by the at least one processor, the method described in any of the foregoing is implemented.
[0021] On the other hand, the present invention also provides a readable storage medium having an executable program stored thereon, wherein when the executable program is executed, it implements the method described in any one of the above.
[0022] Compared with the prior art, the beneficial effects of the present invention are as follows: This invention provides an intelligent question-answering method and system for electricity safety. By dynamically using search results as input to the thought process chain, it achieves a multi-round reasoning process involving reasoning and action. Through a cyclical process of thinking-action-observation-reflection-planning, the system can dynamically adjust the reasoning strategy for the next round (planning phase) based on the results of the previous round, achieving adaptive adjustment of the search path. This allows for more refined and in-depth analysis of complex, multimodal electricity safety issues, improving the accuracy of answers. In each round, reasoning must be based on key evidence obtained from multi-channel search tools, and the sufficiency of the evidence is verified during the reflection phase. This evidence-driven mechanism forces the model to base its output on verified external knowledge, significantly reducing model illusion.
[0023] This invention, by binding the reasoning state of each round with the corresponding reasoning evidence, can clearly reconstruct the complete reasoning path and evidence chain from receiving the question to generating the answer, making the reasoning process no longer a "black box" operation and greatly enhancing the traceability and explainability of the reasoning process. Simultaneously, by introducing an optimization strategy in the action phase aimed at minimizing tool call costs and response latency, the system performance of the scheduling process is guaranteed. Attached Figure Description
[0024] Figure 1 This is a flowchart illustrating an intelligent question-and-answer method for electricity safety according to the present invention. Figure 2 This is a flowchart illustrating the reasoning process based on the ReAct thought chain, as an example of the present invention. Figure 3 This is an example of an interface displaying the output results of a file analysis using a small model according to the present invention. Figure 4 This is a diagram illustrating the text input interface of the user interaction layer, as an example of the present invention. Figure 5 This is a diagram illustrating the voice input interface of the user interaction layer, as an example of the present invention. Figure 6 A hierarchical diagram of an intelligent question-and-answer system for electricity safety according to the present invention; Figure 7 This is a block diagram of an electronic device according to the present invention. Detailed Implementation
[0025] The field of electrical safety involves multiple disciplines such as electrical engineering, data transmission, and artificial intelligence. While existing attempts have incorporated large language models, they still suffer from inaccurate responses, information silos, and the illusion problems common to large language model systems. This invention combines large language models with domain-specific small models, knowledge graphs, and edge computing to transform electrical safety policies, regulations, operational standards, and technical documents into auxiliary tools to support digital guidance for on-site inspections.
[0026] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0027] Example 1 The present invention provides an intelligent question-and-answer method for electrical safety, the schematic diagram of which is shown below. Figure 1 As shown, the method includes: Step S110: Receive multimodal electricity safety questions input by the user; call the large language model to perform intent parsing on the multimodal electricity safety questions and generate reasoning guidance instructions; Step S120: Activate the reasoning and action thinking chain through the reasoning guidance instruction to carry out multiple rounds of reasoning loops, and obtain the reasoning state and corresponding reasoning evidence for each round; Step S130: Based on the reasoning state and corresponding reasoning evidence in each round, generate an answer that is bound to the reasoning evidence; Each round of reasoning loop includes a thinking phase, an action phase, an observation phase, a reflection phase, and a planning phase. The thinking phase includes generating a current tool scheduling strategy based on the current reasoning state and a preset tool registry. The action phase includes optimizing the current tool scheduling strategy with the goal of minimizing tool call costs and response latency, and calling multi-channel retrieval tools for parallel retrieval and evidence collection based on the optimization results. The observation phase includes obtaining the retrieval results returned by the tool calls and extracting multiple key pieces of evidence. The reflection phase includes fusing multiple key pieces of evidence and verifying the sufficiency of the evidence based on the data quality of the fused results. The planning phase includes planning and formulating subsequent reasoning strategies and determining the loop direction based on the sufficiency verification results. The retrieval results of each tool call serve as a new reasoning state, used to update the current reasoning state and participate in the next round of reasoning loop.
[0028] In this example implementation, the solution can be executed in an electricity safety Q&A system, which can be deployed in electricity safety inspection equipment to assist frontline electricity safety inspectors. Users can input electricity safety questions through one or more formats such as text, voice, documents, data, and images on the system's main interface of the interaction layer, obtaining multimodal electricity safety questions. For example, a user can input the question of how to handle a high-temperature alarm on the casing of a 10kV transformer at Station A, and simultaneously upload a CSV file containing the transformer's temperature data for the past week. The system's interaction layer marks the user's question and instantly generates a corresponding question ID, timestamp, and session signature. For uploaded files to be analyzed, the interaction layer performs integrity checks on the file format, checks the file size, quickly desensitizes file information, and stores the file's metadata. The information subsequently uploaded by the user is integrated into a standardized format and asynchronously transmitted to the message bus of the proxy layer as a request for further processing. Intent parsing involves understanding the user's intent through a large language model to form a set of questions to be solved. Then, inference guidance instructions are generated based on a pre-set prompt word engineering template, which can have a mapping relationship between questions and inference guidance instructions. The ReAct (Reasoning and Action) agent's thought process chain, namely the think-action-observation-reflection-planning loop mechanism, is activated based on reasoning guidance instructions. This begins with initial reasoning budget planning, which includes constraints such as the total number of tool calls, knowledge graph retrieval depth, and SQL query range. The agent then filters the tools to be called and the types of evidence needed to answer user questions from the tool registry, forming a candidate toolset and a tool call priority sequence. Finally, a draft containing reasoning and tool scheduling strategies is generated. Based on the tool call priority sequence in the draft and the tool health, performance load profile, and authentication status in the tool registry, a multi-objective optimization problem is established with the goal of minimizing tool call costs and optimizing response latency (e.g., minimizing the weighted average of tool call unit cost, tool call latency, and tool call success probability). Actions are taken based on the optimization results of the draft. By calling tools at the tool layer, parallel retrieval and evidence collection from multiple data sources can be performed simultaneously, accelerating the problem-solving process. The entire task execution process is dynamically monitored and its status updated during tool calls. In this example, the ReAct mechanism decomposes the complex decision-making process into a five-step intelligent cycle of thinking, action, observation, reflection, and planning. In the thinking stage, internal reasoning logic is generated based on deep analysis. In the action stage, the optimal tool combination is dynamically selected through the intelligent routing mechanism of the tool registry. In the observation stage, the execution results of the tools are objectively analyzed and key information is extracted. In the reflection stage, critical thinking evaluation is carried out and confidence is calculated. In the planning stage, subsequent strategies are formulated and the direction of iteration is determined.This invention significantly improves the accuracy and traceability of electricity safety knowledge queries by integrating advanced Retrieval Enhanced Generation (RAG) technology, helping frontline operators obtain reliable professional knowledge guidance and data analysis services in equipment operation and maintenance scenarios. Compared to currently widely used conventional RAG systems that rely solely on single-retrieval generation, this invention, by incorporating an intelligent agent and introducing a ReAct chain mechanism, achieves iterative reasoning, intelligent tool invocation, and multi-step action planning. This enables the system to dynamically adapt to complex queries, handle uncertain content, and significantly reduce the risk of illusions through multiple verification loops.
[0029] For example, the invocation of a large language model to perform intent parsing on the multimodal electricity safety issue and generate inference guidance instructions includes: The large language model is invoked to extract entities and identify keywords for the multimodal electricity safety issues. Based on the identified keywords and contextual information, the business domain and set of business tasks are determined. Based on the aforementioned business domain and business task set, and a pre-set prompt word engineering template, guided reasoning instructions are generated.
[0030] In this example implementation, the agent executor invokes a large language model agent to extract entities and identify keywords from the user's question, such as "A-site," "10kV transformer," and "high temperature alarm." It then combines this with the context to determine the business domain of the user's request, such as equipment fault handling, electricity safety consultation, or data analysis requests, generating a set of business tasks. This set of tasks is then matched with a prompt word template to generate reasoning guidance instructions. The large language model interprets the intent of the input question to generate instructions that activate the reasoning and action thought chain, enabling the automatic parsing and triggering of multiple rounds of reasoning loops by the ReAct agent.
[0031] In some implementations, a bridging mechanism is established between the ReAct thought chain and the LangChain framework through a proxy executor. This, combined with event streaming and asynchronous mechanisms, enables real-time streaming of the inference steps, including crucial information such as model inference, proxy decision-making, and tool calls. Leveraging this streaming functionality, this example can output the agent's thought process, call status, execution results, and thought chain in real-time on the system front end. For example, such as... Figure 2As shown, when a user inputs "Introduce the safety hazards of water pumps," the ReAct thought process is as follows: The agent executor in the agent layer executes the thought phase (as shown in the diagram), parsing the user's intent and generating an internal analysis strategy. It then enters the action phase (as shown in the diagram), dynamically selecting and calling professional tools such as knowledge graph retrieval, database queries, data analysis small model API services, and embedded models through the metadata management system of the tool registry in the tool layer. Simultaneously, the inference tracker continuously tracks the tool calls. After the tool calls are completed, the observation phase begins, evaluating the relevance and completeness of the returned search results. Subsequently, in the reflection phase, confidence is calculated, and the sufficiency of the information is assessed. Finally, in the planning step, a decision is made on whether to continue iteration, switch strategies, or output the final result. Part of the inference process is as follows: Figure 2 As shown, this mechanism significantly improves the user experience, achieving complete transparency in the AI reasoning process. Compared to traditional black-box AI systems, the interpretability of reasoning is greatly enhanced.
[0032] In some implementations, the action phase further includes: If service unavailability or authentication failure occurs during tool invocation, a retry mechanism will be automatically triggered, and a backup tool will be switched or a delayed retry will be performed according to the preset strategy.
[0033] In this example implementation, when the proxy execution of the proxy layer encounters service unavailability or authentication failure when calling the tool layer tool, it will automatically trigger a retry mechanism and switch to a backup tool or delay the retry according to a preset strategy, in an effort to ensure that the current user's conversation and workflow are not interrupted, and to ensure that the intelligent agent can maintain a stable experience even in the event of service fluctuations or incomplete configuration.
[0034] In some implementations, the tools in the tool registry include at least two of the following: small model calling tools, relational database tools, speech recognition tools, remote storage tools, and knowledge graph tools. The small model invocation tool is used to invoke different domain-specific small models to perform corresponding tasks; The relational database tool is used to invoke the relational database to execute corresponding tasks; The speech recognition tool integrates a speech recognition interface from a third-party application programming interface service to recognize the user's voice input. The remote storage tool is used to invoke the remote document service to execute corresponding tasks; The knowledge graph tool is used to call upon knowledge graphs in the field of electrical safety to perform corresponding tasks.
[0035] In this example implementation, a tool registry is maintained at the tool layer. The tool layer is built on the LangChain tool framework and follows a custom protocol, encompassing various tools such as database tools, small model calls, speech processing, remote document services, and knowledge graphs. A unified tool registry dynamically discovers, categorizes, and selects tools. The tool registry proactively performs health checks and authentication verification by continuously monitoring description information, category tags, availability status, performance metrics, and usage statistics. This ensures that the system can maintain service continuity through functional degradation and placeholder strategies when tools fail. After a tool returns to normal availability, it performs a self-check and replacement, achieving seamless self-healing of the entire system, thereby ensuring high reliability and high availability. In the call path, the tool layer initializes instances according to the routing instructions in the registry, performing parallel and asynchronous execution to reduce latency. After initial result verification and error handling, it feeds back to the observation steps of the proxy layer. The tool call process balances adaptive execution optimization and resource management, dynamically allocating resources based on system load, supporting streaming responses and real-time logs and performance metric feedback, while also implementing loop suppression and usage constraints to prevent resource waste caused by invalid tool call iterations.
[0036] In some implementations, the multi-channel retrieval tool includes a relational database tool; the step of calling the multi-channel retrieval tool in parallel forensic retrieval based on the optimization results includes: The data schema of the relational database corresponding to the relational database tool is parsed, and based on the parsing results and the multimodal electricity safety problem, a large model prompt word of the relational database is constructed; Based on the large model prompts and read / write security constraints of the relational database, the large language model is guided to generate the corresponding target query statement; The relational database is searched and evidence is collected based on the target query statement; if the search fails, the target query statement is corrected based on the error type returned by the tool call, and a fuzzy matching query is performed based on the corrected result; The read-write security constraint is used to restrict the large language model's operations on the heterogeneous database to read-write operations.
[0037] In this example implementation, to achieve efficient retrieval of security indicator data and equipment specification parameter data in a relational database, this example designs a process that directly converts natural language into SQL retrieval statements. This process mainly transforms the user's natural language query into an SQL statement that can be executed by the system, coordinated and invoked by an intelligent agent within the system. This method has strong adaptability to relatively ambiguous or descriptive query statements. For example, the retrieval process based on this language conversion is as follows: Query Analysis and Prompt Construction: After receiving the user's query, the system analyzes the user's intent through reasoning and parses the data schema of the stored database to obtain the table names, field types, and functional descriptions currently stored in the MySQL database (parsing results). Subsequently, the database structure details, role descriptions, user query, and output requirements are concatenated to construct prompts for the Large Language Model (LLM). LLM (Large Language Model) Invocation: The concatenated prompts are sent to the Large Language Model, and the structure returned by the Large Language Model is syntactically validated. If the syntax is correct, the SQL statement (target query statement) is executed, and the execution result is obtained. Result Processing: If the SQL statement execution fails, an error message is returned to the agent. Based on the error message, the agent performs in-depth analysis of the previously generated SQL query and makes corresponding corrections, then executes the corrected SQL statement (e.g., a fuzzy matching query). This corrected query is repeated until the query succeeds or the pre-set maximum number of LLM large model calls is reached. During the generation of the target query statement, read / write security constraints need to be set to control that the large language model can only perform read and write operations on the relational database, prohibiting DDL (Data Definition Language) operations. For example, the conversion process between natural language and SQL statements based on MySQL is as follows:
[0038] In this example, a precise query of structured data using natural language is performed through the target SQL statement. If the retrieval fails or the response times out, a failure handling process is triggered. Based on the error type returned by the SQL database, such as syntax errors, insufficient permissions, or empty results, appropriate degradation strategies or retry mechanisms are executed. For example, when the SQL tool is called to query the table of power equipment containing "10kV transformers," and the result is empty, it will automatically switch to a fuzzy matching query in the database, and combine the timestamp range to narrow the search interval to improve recall. This example implements error-classification-driven closed-loop repair of SQL statements, stably converting the user's fuzzy semantics into executable SQL query statements, effectively improving the conventional single-step natural language conversion query process of "generation, execution, failure, abandonment, and return result." By combining the LLM large language model, semantic conversion is achieved, effectively solving the limitations of traditional SQL statements, such as the inability to understand user query intent and business logic. Simultaneously, a retry mechanism is added to the SQL statement execution through an intelligent agent, greatly improving the accuracy of the system's retrieval of user query knowledge.
[0039] In some example implementations, the multi-channel retrieval tool includes a knowledge graph tool, which in turn includes a semantic retrieval tool and a keyword retrieval tool; the parallel retrieval of evidence based on the optimization results using the multi-channel retrieval tool includes: The semantic retrieval tool is invoked to convert the multimodal electricity safety issues into query vectors through an embedded language model; based on the similarity between the query vectors and the vector representations of each node in the electricity safety domain knowledge graph, evidence is retrieved from the electricity safety domain knowledge graph. The keyword retrieval tool is used to extract the problem keywords of the multimodal electricity safety issues; a knowledge graph retrieval query statement in the field of electricity safety is generated based on the preset retrieval matching conditions; and evidence is obtained by retrieving the knowledge graph in the field of electricity safety based on the knowledge graph retrieval query statement. The retrieval and evidence collection process based on the target query statement, the semantic retrieval tool, and the keyword retrieval tool is executed in parallel.
[0040] In this example implementation, to achieve complete data retrieval in the knowledge base, two retrieval methods are designed for the knowledge graph (such as Neo4j): vector semantic retrieval and keyword exact matching retrieval. Vector semantic retrieval is a semantic similarity retrieval method based on an embedding model. It aims to understand the user's semantic intent by mapping text to higher-dimensional vectors, thereby using vectors to achieve deep semantic association mining and retrieving the semantically most similar nodes in the knowledge graph built on the Neo4j graph database. Exemplarily, the implementation steps of vector semantic retrieval using the semantic retrieval tool are as follows: (1) Query Embedding Generation: After receiving the text data string of the user's query question, the intelligent agent system calls the configured embedding model in the system to generate a representation of the query vector. In this example, the embedding model is the GTE-large-zh language model based on a deep learning neural network, which has a maximum context length of 1024 dimensions, enabling the generated vector to have strong clustering and discrimination capabilities in the semantic space. Through vector semantic retrieval, the model can ensure that the query vector is in the same embedding vector space as the graph nodes.
[0041] (2) Similarity Calculation: In the Neo4j graph database, this example supports multiple similarity calculation methods for the labels of each node, such as cosine similarity (representing the similarity of vectors in semantic space by calculating the cosine value of the angle between two vectors) and Euclidean distance (measuring the absolute difference between two vectors by calculating the straight-line distance between two vectors in high-dimensional space), thereby supporting the application of electricity safety questions and answers in different scenarios and electricity safety data analysis, effectively supporting the large-scale retrieval of knowledge functions for intelligent agents, and realizing intelligent retrieval with high relevance and high recall. The found nodes can be filtered by a preset similarity threshold, returning only nodes with similarity greater than the threshold, and limiting the maximum number of returned nodes to prevent the problem of excessively large input of the large model caused by returning a large number of irrelevant nodes. For example, the input of the vector semantic retrieval process based on Neo4j is: user query string, node label list, similarity threshold, result quantity limit, and similarity algorithm; The output is a formatted list of search results; the specific search process is shown below:
[0042] The above vector semantic retrieval can be applied to scenarios involving fuzzy queries and semantic reasoning.
[0043] For example, the keyword precise matching through the keyword retrieval tool includes: (1) Keyword extraction: Combined with the LLM large model, keywords are extracted from the query text data input by the user, and multiple keyword matching is performed on complex queries. (2) Attribute retrieval: For the tags and attributes of the nodes, the keyword Neo4j Cypher retrieval query statement is constructed. The matching conditions can be generated according to the configuration. For example, the exact matching condition is: toLower(n.prop) = toLower($keyword), that is, the search keyword is exactly the same as the node attribute; the inclusion matching condition is: toLower(n.prop) CONTAINS toLower($keyword), that is, the node attribute contains the search keyword; by combining the two matching, efficient retrieval of node data is achieved. (3) Execute retrieval operation: Execute the retrieval command in the Neo4j database, and perform corresponding formatted output processing according to the matching nodes in the retrieval results. For example, the input of the keyword precise matching retrieval process based on Neo4j is: user query string, node tag list, retrieval result quantity limit, optional exact matching flag, whether to distinguish between uppercase and lowercase; the output is: formatted retrieval result list; the specific execution process is as follows:
[0044] During execution, label, condition, prop, and limit need to be replaced with specific values. This example uses a basic text retrieval method based on keyword matching. This method is suitable for scenarios where users provide specific keywords or entity names in their input query text, such as when searching for information about a certain device, providing a faster match compared to vector semantic retrieval.
[0045] The above examples demonstrate how multi-channel retrieval tools can simultaneously perform parallel searches and evidence collection from multiple data sources, thereby accelerating the problem-solving process. For instance, in processing the entity "10kV transformer," the system can simultaneously invoke knowledge graph vector semantic retrieval tools, knowledge graph keyword retrieval tools, and structured SQL tools. The agent uses the embedded vector tool to calculate and obtain graph nodes related to "high temperature alarm," and extracts corresponding information using Cypher queries from the knowledge graph. Simultaneously, the system's agent executor initiates the natural language to SQL conversion process. Addressing the highly specialized nature of information in the field of electrical safety, a hybrid retrieval system combining Neo4J graph database and MySQL relational database is implemented, ensuring the reliability and accuracy of knowledge output.
[0046] In some example implementations, the fusion of multiple key pieces of evidence and the verification of the sufficiency of the evidence based on the data quality of the fusion result include: Multiple pieces of key evidence were integrated to form a key evidence set; Based on the number of pieces of evidence, their sources, their timeliness, and their credibility in the key evidence set, a sufficiency score for the evidence in the key evidence set is determined. Sufficiency verification is performed based on the sufficiency score and the preset sufficiency threshold; Several key pieces of evidence were extracted from the search results of relational database tools, semantic search tools, and keyword search tools.
[0047] In this example implementation, multiple key pieces of evidence extracted from the search results of relational database tools, semantic search tools, and keyword search tools can be verified through multi-source data fusion and sufficiency testing. Specifically, sufficiency testing can be performed using the following formula:
[0048] in, The number of pieces of evidence returned by the tool call. For the quantity of sources of evidence, As evidence of the current statute of limitations, The average confidence level of the data source. For the sake of sufficient evidence, , , as well as These are weights, respectively. When the system calls multiple tools for parallel evidence collection, if the fusion result is greater than or equal to the preset sufficiency threshold, the verification passes. The results returned by the called tools are then appended with an evidence ID and stored in the evidence pool for subsequent unified verification and aggregation by the inference module. If the fusion result is less than the preset sufficiency threshold, the verification fails, the tool call strategy is re-evaluated, and resources are reallocated, triggering a secondary tool scheduling evidence collection process. This example's multi-channel tool scheduling is a measurable parallel evidence collection mechanism based on a dynamic evaluation of the evidence requirements and pre-existing constraints for answering user questions, rather than a loose mechanism for blindly and concurrently calling tools.
[0049] In some example implementations, if the reasoning guidance instructions include analysis instructions for a user-uploaded file to be analyzed, the thinking phase further includes: The feature inspector of the large language model is invoked to parse and preprocess the user-uploaded file to be analyzed, and the data to be analyzed is obtained. The action phase also includes: calling multiple domain-specific small models in parallel to analyze and process the data to be analyzed, and obtaining the analysis results of each domain-specific small model; The planning phase also includes generating corresponding answer contexts based on the analysis results of the multimodal electricity safety issues and multiple domain-specific small models, and feeding them back to the user.
[0050] In this example implementation, if the inference guidance instruction includes an analysis instruction for a user-uploaded file to be analyzed, that is, when the model strategy generated by intent parsing indicates that the user-uploaded data file needs to be analyzed, the feature inspector is invoked to perform modality recognition, sampling interval, and missing rate evaluation on the uploaded file to be analyzed. Then, based on the intent parsing results, a corresponding domain-specific mini-model is matched, and concurrent mini-model calls are performed through the Octave gateway to achieve multi-dimensional data collaborative analysis. After completing their assigned tasks, each invoked domain-specific mini-model standardizes its results and returns them for evidence aggregation. For example, such as... Figure 3 As shown, the user uploads a CSV file containing temperature data from a transformer over the past week, and simultaneously inputs the question, "Please analyze the time series data in my uploaded CSV file and see if the analysis results indicate any potential electrical safety risks." This allows the system to invoke a small model based on Prophet time series trend analysis and a small model based on LSTM for anomaly detection, performing trend prediction and instantaneous abrupt change point identification in parallel. Finally, by performing spatiotemporal alignment and confidence-weighted fusion of the two analysis results, and combining this with the equipment's operating context, it is determined whether the temperature changes constitute a potential fault warning. The output results are as follows... Figure 3 As shown, it can include the results of safety risk assessment (risk level, cause, key indicators and trend prediction results) and risk identification results.
[0051] In some implementations, after a user uploads the file to be analyzed and submits relevant questions, a collaborative mechanism between a large model and a small model is used for problem analysis. First, the validity of the file to be analyzed is verified. Then, an intelligent model selection algorithm automatically calls a small model to perform data analysis based on the file's feature type. The small model can be deployed on a cloud virtual machine, using Python's FastAPI framework and combining it with Octave to run MATLAB models, achieving seamless connection with the large model system through an API interface. After extracting and formatting the data, it is uploaded and analyzed through the API service deployed with the small model. After analyzing the data, the small model API service returns the formatted analysis results to the system. The system combines the user's question with the small model's analysis results to construct a context, generates a data analysis report through an intelligent agent, and provides feedback to the user. This example supports the combination of large and small models and the large model calling the small model, enabling the analysis of user electricity safety-related data and the discovery of potential electricity hazards.
[0052] In some implementations, during tool invocation, the maximum number of tool invocations and the number of timeout retries can be set based on the conditions of satisfying authentication and minimum health thresholds. Before invoking a tool, degradation and rollback strategies for faulty tools are pre-set. For example, when an agent attempts to invoke a knowledge graph tool to retrieve data related to "10kV transformers," if a timeout occurs during the tool invocation, it switches to a backup database query tool according to a preset degradation strategy, and rolls back after the tool returns to a usable and healthy state to ensure task continuity and stability. Simultaneously, to suppress sudden loads, a quota strategy is implemented for tool invocations, limiting the frequency of tool invocations by a single agent per unit time to prevent resource congestion and ensure the execution efficiency of high-priority tasks.
[0053] In some example implementations, execution metrics for each tool call are maintained in the tool registry; The performance metrics include at least one of the following: success rate of tool invocation, response latency, invocation error rate, and system load corresponding to tool invocation.
[0054] In this example implementation, the performance metrics of each tool, such as the success rate of the tool call, response latency, call error rate, and system load corresponding to the tool call, can be maintained in the tool registry during the tool call process, which facilitates subsequent strategy formulation.
[0055] In some example implementations, optimizing the current tool scheduling strategy with the goal of minimizing tool invocation costs and response latency includes: Based on the tool call execution metrics corresponding to each candidate tool in the current tool scheduling strategy, determine the routing weight of each candidate tool; The candidate tools are prioritized based on their routing weights to generate an optimized tool scheduling strategy.
[0056] In this example implementation, based on the tool health, performance load profile, and authentication status of each tool in the tool registry within the current tool scheduling strategy, a multi-objective optimization problem is established with the goals of minimizing tool invocation costs and optimizing response latency. The specific formula is as follows:
[0057] in, The total cost of the tool invocation strategy. Let i be the unit cost of calling the i-th tool. For the delay of calling the i-th tool, Let be the probability of successfully calling the i-th tool. , , These are the weighting coefficients. , , The tool's historical call history can be maintained in the tool's registry. The current strategy can be optimized by solving a multi-objective optimization problem.
[0058] In some example implementations, an answer bound to the reasoning evidence is generated based on the reasoning state and corresponding reasoning evidence for each round, including: The reasoning conclusion is generated based on the reasoning state in each round; For each reasoning conclusion, the reasoning conclusion is bound to the reasoning evidence associated with the corresponding reasoning state; Reasoning conclusions without supporting evidence are marked as unreliable and blocked. The answer is generated based on a conclusion that is supported by reasoning.
[0059] In this example implementation, during the answer generation stage, a "no output without evidence" prompt principle can be set to force the LLM large model to generate answers using only the required type of evidence and reasoning evidence. This ensures that each conclusion originates from traceable evidence data, establishing a one-to-one binding mechanism between conclusion and evidence. Conclusions supported by evidence are intercepted and rejected. For example, for the conclusion "the temperature of 10kV transformers shows a continuous upward trend," it needs to be bound to the output results from the time series analysis small model tool and the timestamp range of the original data points. If either data source marker is missing, the conclusion will be marked as unreliable and intercepted. This mechanism effectively suppresses the illusionary output of the large model, ensuring the authenticity and verifiability of the generated content. Exemplarily, the final results are integrated and output to the user through an interactive layer in the form of text, charts, images, or voice. The output results explicitly indicate the evidence sources upon which each conclusion depends and their links. At the text level, a structured summary and list of key points are generated directly for the report, covering the final conclusion, influencing factors, and corresponding recommendations. At the chart level, the trend curves, outlier distributions, and prediction intervals generated by the small model tool are visualized to present the analysis results intuitively to users. At the audio level, the generated text content is read aloud to meet the needs of mobile scenarios. Furthermore, the output can be exported in multiple standard formats such as JSON, Excel, and PDF, facilitating data sharing and further analysis across different platforms.
[0060] This invention utilizes a deep fusion architecture of the RAG system and the ReAct reasoning mechanism. By using RAG retrieval results as input to the thought process, the ReAct mechanism combines multi-source information for multi-step reasoning. Through a cyclical process of thinking, tool invocation, observation, reflection, planning, and rethinking, the output of the large model at each tool invocation is used as a reasoning state variable, participating in the next round of reasoning. At the end of each round, the sufficiency and completeness of evidence determine whether to continue iteration or output results, significantly reducing illusions and improving traceability and interpretability. By deploying a hybrid retrieval strategy of graph databases and relational databases within the system, efficient fusion querying of structured and unstructured data is achieved. On the graph side, vector semantic retrieval and keyword precise matching strategies are switchable and fused, further enabling retrieval of complex entity relationships and fuzzy semantics. In the relational database, parsing and execution based on natural language to SQL are implemented, with the agent reflecting and retrying or rewriting the query in case of failure. By maintaining a unified tool registry, various tool interfaces are standardized and encapsulated, enabling dynamic scheduling and combination of tool invocations. Meanwhile, the tool registry maintenance tool's success rate, response latency, error rate, system load, and other metrics serve as routing weights during the agent planning phase. Furthermore, the system performs self-checks on connectivity, authentication, and functionality based on the tool table in the background. If a tool becomes unusable, it automatically switches to a backup tool or adjusts the invocation strategy to degrade, ensuring uninterrupted task execution.
[0061] Example 2 Based on the same inventive concept, the present invention also provides an intelligent question-and-answer system for electricity safety, comprising: The user interaction layer is used to receive multimodal electricity safety questions input by users; it is also used to output answers that are linked to reasoning evidence. The proxy layer is used to call the large language model to perform intent parsing on the multimodal electricity safety issue and generate reasoning guidance instructions; the reasoning guidance instructions activate the reasoning and action thinking chain to perform multiple rounds of reasoning loops, and obtain the reasoning state and corresponding reasoning evidence for each round; The large language model layer is used to generate answers that are bound to the reasoning evidence based on the reasoning state and corresponding reasoning evidence in each round. Each round of reasoning loop includes a thinking phase, an action phase, an observation phase, a reflection phase, and a planning phase. The thinking phase includes generating a current tool scheduling strategy based on the current reasoning state and a preset tool registry. The action phase includes optimizing the current tool scheduling strategy with the goal of minimizing tool call costs and response latency, and calling multi-channel retrieval tools for parallel retrieval and evidence collection based on the optimization results. The observation phase includes obtaining the retrieval results returned by the tool calls and extracting multiple key pieces of evidence. The reflection phase includes fusing multiple key pieces of evidence and verifying the sufficiency of the evidence based on the data quality of the fused results. The planning phase includes planning and formulating subsequent reasoning strategies and determining the loop direction based on the sufficiency verification results. The retrieval results of each tool call serve as a new reasoning state, used to update the current reasoning state and participate in the next round of reasoning loop. In this example implementation, the user interaction layer primarily serves as the user's interaction interface, responsible for handling multimodal input acquisition, event triggering, and feedback responses. This layer mainly consists of five core functional modules: a multimodal input processing module, a real-time dialogue interface, a file upload management system, a user authentication system, and a response display component. It collects various types of input, including text, voice, and structured data. Data sources may include user query input, natural language speech, real-time sensor monitoring data (such as device temperature and user power load), and structured files. For example, the text-based dialogue interaction process can be based on a modern chat interface mechanism. This mechanism uses the Grado framework to build a full-width chat container, supporting real-time streaming responses, Markdown rendering, and HTML content display, providing users with an intuitive experience of engaging in natural language dialogue with an AI agent. Figure 4 As shown, when a user inputs "Please explain the safety hazards of water pumps," the output identifies several potential safety hazards, such as mechanical and electrical safety hazards. For example, in the voice recognition interaction process, a deep learning model accurately recognizes the user's voice commands. Figure 5The image shows the system's voice interaction interface, including a voice input component and an input example. The agent executor is primarily responsible for orchestrating and connecting the agent with various tools and advancing the execution of the ReAct process. The agent layer is the core decision-making unit of the system. It builds an autonomous intelligent agent based on the LangChain open-source framework and the ReAct thought chain mechanism, used for user intent query analysis, action planning, and task coordination. The main components of this layer include core modules such as the agent executor and inference tracker. Through standardized LangChain tool interfaces deployed in the tool layer, it enables the selection and invocation of tools. Simultaneously, this layer enables the agent system to support streaming response, multi-round iterative processing, and adopts a layered asynchronous architecture design. It features connection pool optimization, automatic retry mechanisms, and a complete performance monitoring system, ensuring stable operation in high-concurrency scenarios. The large language model layer is the core unit for content generation. It is mainly built based on LangChain's Chat abstract model and the DeepSeek LLM large language model API interface, responsible for providing the agent layer with the necessary semantic understanding and natural language generation capabilities.
[0062] The large language model layer is the core unit for content generation. It is mainly built on LangChain's Chat abstract model and DeepSeek LLM large language model API interface. It is responsible for providing the agent layer with the semantic understanding and natural language generation capabilities it needs. The large language model layer has the following characteristics: (1) Multi-model compatibility: This layer has a common and unified model abstraction and adapter, which supports access to API service interfaces of LLM large language models from different vendors, including DeepSeek large language model, Qwen large language model or user enterprise's self-developed large language model. By switching the large model name, API address and API key, the configuration of the large language model of the whole system can be switched without modifying the agent program and tool layer code. (2) Content generation management: When the large language model layer generates content, it will use a unified prompt word template and rules to strengthen the execution standardization of ReAct thinking chain. When the agent calls the tools of the tool layer, the large language model layer injects tool usage rules, scenario-based strategies and corresponding role prompts into the prompt words to ensure that the electricity safety question answering agent can only generate the corresponding conclusion when there is clear evidence. At the same time, the user's past conversation records will also be injected into the model's context to ensure that the large model can associate with past content while generating new content, thus achieving multi-turn dialogue. (3) Large model parameter control: This layer can set commonly used parameters of large language models such as temperature, top_p, and max_tokens. It supports setting different model parameter templates for different scenarios and different types of problems to improve the model performance in different power safety scenarios.
[0063] In one possible implementation, it also includes: The tool layer is used for unified tool registration and metadata management through standardized tool interfaces; and generates tool scheduling strategies for the reasoning and action thought chain of the agent layer through intelligent routing. The tool layer includes at least two of the following: small model calling tools, relational database tools, speech recognition tools, remote storage tools, and knowledge graph tools.
[0064] In this example implementation, the tool layer serves as the infrastructure unit for task execution and capability orchestration. It is responsible for implementing standardized tool interfaces, performing unified tool registration and metadata management, conducting health checks to enable functional degradation, supporting self-healing replacement and managing the lifecycle, and providing an efficient and stable calling foundation for the ReAct loop of the agent layer through intelligent routing. This layer is built on the LangChain tool framework and follows a custom protocol, encompassing various tools such as database tools, small model invocation, speech processing, remote document services, and knowledge graphs. A unified tool registry dynamically discovers, categorizes, and selects tools. The small model invocation tool is used to invoke small models, which can be deployed on cloud virtual machines, using Python's FastAPI framework and combining it with Octave to run MatLab models, achieving seamless connection with the system through API interfaces. The speech recognition tool integrates the speech recognition interface of third-party API services and incorporates the Whisper deep learning speech recognition model, effectively supporting the needs of the user interaction layer. The knowledge graph tool responds to tool invocations from the agent layer, translating agent requests into specific Neo4j knowledge graph operation instructions and executing the required tasks. When the proxy executor triggers the knowledge graph tool call, the tool first performs a retrieval strategy selection step. Based on the characteristics of the input query, it automatically determines whether to call the vector semantic retrieval algorithm or the keyword exact matching algorithm provided by the knowledge storage layer. Then, it passes the query parameters from the proxy layer to the underlying retrieval engine of the knowledge storage layer. After returning the results, the knowledge graph tool deduplicates and formats the search results, finally returning the precisely matched knowledge graph data as the tool call result. The relational database tool is used to convert the natural language query from the proxy layer into SQL statements and execute the natural language SQL conversion algorithm of the knowledge storage layer. When the proxy executor triggers the relational database tool call, the tool first receives the user query parameters passed from the proxy layer, including the query text, target data table, query type, etc. Then, the tool calls the natural language SQL conversion service provided by the knowledge storage layer to convert the user's natural language query into a standard SQL statement. After the SQL statement is generated, the tool performs syntax validation and security checks, and executes the query operation to obtain the result data. Finally, the tool formats these query results, converting the relational data into a standardized format, and then returns it to the proxy layer. Remote Storage Tool: This tool coordinates communication with the AnythingLLM remote service in the knowledge collection layer, providing remote service support for document processing, vector retrieval, and knowledge management to the agent layer. When the agent executor triggers a call to the remote storage tool, the tool first receives operation parameters from the agent layer, including file path, query text, and retrieval mode. The tool then executes specific API calls and data transfer tasks based on the AnythingLLM remote document processing mechanism provided by the knowledge collection layer.Before executing the remote call, the tool validates and formats the request parameters to ensure compatibility with the remote service's interface. Then, it initiates the API request via an asynchronous HTTP client and monitors the transmission status and service response in real time. Finally, the tool parses and standardizes the results returned by the remote service, converts them into a structured format, and returns the execution result.
[0065] In one possible implementation, it also includes: The knowledge storage layer is used to store professional knowledge in the field of electrical safety through a multimodal storage architecture; The knowledge storage layer includes a knowledge graph and a relational database in the field of electricity safety; the knowledge graph in the field of electricity safety is used to store the entity relationship network of various power equipment; the relational database is used to store electricity safety standards and historical electricity safety records of various power equipment.
[0066] In this example implementation, the knowledge storage layer is responsible for the persistent storage, efficient retrieval, and dynamic management of professional knowledge in the field of electrical safety. This layer adopts a multimodal storage architecture, achieving unified management of structured data, semi-structured knowledge graphs, and unstructured semantic vectors through the collaborative work of a heterogeneous database cluster, providing a solid data foundation for upper-layer intelligent retrieval and reasoning. The knowledge storage layer mainly consists of the Neo4j graph database and the MySQL relational database storage engine. The Neo4j database is primarily responsible for storing the entity relationship network of power equipment, which mainly consists of six entities: equipment, faults, regions, etc., and their associated relationships. The MySQL database is responsible for managing structured knowledge data, mainly including safety standards and equipment history records.
[0067] In one possible implementation, it also includes: The knowledge collection layer is used to automatically collect, preprocess, and manage multi-source knowledge data in the field of electrical safety through a distributed architecture. The knowledge collection layer includes a remote document processing service and a local data acquisition module; the remote document processing service is used to remotely transmit, remotely vectorize, and remotely store documents uploaded to the system. The local data acquisition module is used to collect local network content and local multi-source files.
[0068] In this example implementation, the knowledge collection layer is used for the automated collection, preprocessing, and unified management of multi-source knowledge data, serving as the core infrastructure for building an electricity safety knowledge base. This layer adopts a distributed architecture design, integrating the AnythingLLM remote document processing framework and a local knowledge collector to achieve unified collection and processing of structured, semi-structured, and unstructured text data, providing a knowledge data foundation for upper-layer intelligent retrieval and reasoning. The AnythingLLM framework, as the core engine of remote document processing, is deployed on a cloud virtual machine and is responsible for handling the uploading, vectorization, and enhanced retrieval generation of large-scale documents. The local knowledge collector is responsible for collecting knowledge from various data sources, including web crawlers, file systems, and preset configurations.
[0069] Remote document processing service is a distributed document processing mechanism based on the AnythingLLM framework. This mechanism communicates with the AnythingLLM service deployed in the cloud through an API interface based on the HTTP protocol to realize remote uploading, vectorization, and enhanced retrieval generation of large-scale documents. At the same time, this mechanism has high concurrency processing capabilities, automatic retry mechanism, and automated error handling system mechanism, and can realize efficient processing of various document files such as PDF, Word, Excel, etc. The detailed workflow of this mechanism is as follows: (1) File verification and preprocessing: The system first verifies the file size, format, and integrity of the uploaded document. The file upload function supports multiple document formats, including PDF, TXT, DOCX, XLSX, etc., to ensure that the document meets the processing standards. Then the system performs preliminary preprocessing on the document, such as text extraction and format conversion. For each file, the system checks whether the file size exceeds the preset maximum limit and whether the file format is compliant. After the file verification is passed, the system assigns a unique file identifier to the file and extracts the basic metadata information of the file, including the file name, creation time, file type, etc. (2) File Transfer and Vectorization: Verified files are uploaded to the AnythingLLM remote service deployed on a cloud virtual machine. This step is completed by the aiohttp asynchronous HTTP dependency library built into the Python language, which supports parallel uploading of multiple files and breakpoint resume function, ensuring the efficiency and stability of the system in handling file uploads. After receiving the file, the AnythingLLM service will automatically use the embedding model to perform text extraction and vectorization processing, converting the content of the document uploaded by the user into a high-dimensional vector representation and storing it in the vector database. (3) File Collection Management: The AnythingLLM service supports the classification and tagging management of uploaded documents, which can realize the classification management of different types of documents in different fields. Different document collections are isolated from each other to ensure data security and privacy protection. During the retrieval process, the system supports multiple retrieval modes, including chat mode, streaming chat mode and vector search mode, and can select the optimal retrieval strategy according to different query needs.
[0070] The local data acquisition module integrates a local knowledge collector-based acquisition mechanism. This mechanism supports knowledge acquisition from various data sources such as website URLs and local file systems, and provides a unified data format and block data management. (1) Network content acquisition: The system uses an asynchronous HTTP client to acquire network content in batches. During the acquisition process, the system uses BeautifulSoup to parse HTML files, remove irrelevant scripts and navigation bars, and extract clean text information. Afterwards, the system cleans and structures the text data, converts it to JSON format, and ensures that the data is accurate and usable. (2) Local multi-source file acquisition: The system supports directly acquiring and reading files of various formats from the local machine as a supplement to AnythingLLM service. For PDF files, the system uses the PyPDF2 library to parse and extract text content. For Word documents, the python-docx library is used for processing. The system uses the openpyxl library to extract Excel table data and the pandas library to process the structured data of CSV files. Each file type has a dedicated parsing module to ensure the extraction of complete text content and structured data.
[0071] This invention combines the RAG system with the ReAct intelligent agent reasoning mechanism, enabling the system to progressively verify information and automatically correct errors for complex electrical safety issues. This significantly reduces the risk of safety misguidance caused by model illusions and greatly improves the accuracy of knowledge retrieval, ensuring users receive traceable and explainable answers. It supports uploading various types of abnormal data from different devices, identifying and analyzing abnormal patterns through built-in small models, proactively identifying trends in abnormal data, and performing correlation reasoning based on a knowledge base to match and warn of known risks. This improves the efficiency and speed of discovering and responding to electrical safety hazards, enhancing the ability to detect hazards and warn of risks. In the face of sudden electrical safety accidents, the system can quickly retrieve relevant emergency response plans and provide step-by-step emergency handling suggestions based on on-site equipment models, environmental conditions, and historical cases, guiding users to operate according to standardized procedures, effectively reducing the scope of the accident's impact, and strengthening emergency response and decision support.
[0072] For example, such as Figure 6As shown, the system's overall architecture adopts a modular design, mainly comprising six layers: user interaction layer, agent layer, tool support layer (tool layer), knowledge collection layer, knowledge storage layer, and large language model layer. These six layers are uniformly linearly scheduled through a chain mechanism based on the LangChain framework, ensuring streaming and intelligent processing of data from input to output. Simultaneously, asynchronous execution is supported between system layers, effectively improving the ability to handle concurrent tasks and ensuring low-latency response speed. Furthermore, the ReAct thinking chain is embedded as an innovative element into the agent layer, enabling autonomous decision-making within the intelligent agent system, and the database in the knowledge storage layer implements the RAG knowledge retrieval enhancement mechanism. By integrating advanced retrieval enhancement generation technologies, this system significantly improves the accuracy and traceability of electricity safety knowledge queries, helping frontline operators obtain reliable professional knowledge guidance and data analysis services in equipment operation and maintenance scenarios. This system integrates a large language model, a ReAct inference agent built using the LangChain framework, a knowledge graph based on the Neo4j graph database, a MySQL relational database, and multimodal fusion technology. It aims to provide users with real-time, accurate electricity safety consultation and hazard warning services. The core component of this system is the AI Agent module, which, relying on the LangChain framework, enables coordinated operation and multi-step processing between intelligent tools. Simultaneously, the system supports the ReAct mode, which can process complex queries and generate context-sensitive responses through the cyclical execution of a series of actions such as thinking, acting, observing, reflecting, and planning. Furthermore, the system integrates the Neo4j knowledge graph for retrieving entity relationships between electrical equipment and safety hazards, and the MySQL database for storing structured data such as equipment parameters and safety specifications. By combining this with the RAG mechanism, it effectively suppresses the illusion problem commonly found in large model systems. The system also possesses multimodal capabilities, effectively supporting text queries, tabular data file uploads and data parsing, and processing natural language voice commands, providing users with effective electricity safety support.
[0073] Example 3 like Figure 7 As shown, the present invention also provides an electronic device, which may be a computer device, a microcontroller device, a smart mobile device, etc. The electronic device in this embodiment may include a processor, a memory, a transceiver component, etc. The memory, processor, and transceiver component are connected via a bus; the memory can be used to store executable programs, and an exemplary executable program may include instructions; the processor is used to execute the instructions stored in the memory. The memory can also be used to store data, which can be accessed and / or modified when instructions are executed.
[0074] The processor may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing core and control core of the terminal, and it is suitable for implementing one or more instructions. Specifically, it is suitable for loading and executing one or more instructions in the storage medium to implement the corresponding method flow or corresponding function, so as to implement the steps of the intelligent question-and-answer method for electricity safety in the above embodiments.
[0075] Example 4 Based on the same inventive concept, this invention also provides a readable storage medium, specifically an electronic device readable storage medium (Memory). An electronic device readable storage medium is a memory device within an electronic device used to store programs and data. It is understood that the storage medium here can include both built-in storage media within the electronic device and extended storage media supported by the electronic device. The storage medium provides storage space, which stores the terminal's operating system. Furthermore, this storage space also stores one or more instructions suitable for loading and execution by a processor. These instructions can be one or more executable programs (including program code). It should be noted that the storage medium here can be high-speed RAM or non-volatile memory, such as at least one disk storage device. Loading and executing one or more instructions stored in the storage medium by the processor can implement the steps of the intelligent question-and-answer method for electrical safety described in the above embodiments.
[0076] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0077] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0078] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0079] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0080] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit its scope of protection. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that after reading the present invention, they can still make various changes, modifications or equivalent substitutions to the specific implementation methods of the application, but these changes, modifications or equivalent substitutions are all within the scope of protection of the claims pending approval.
Claims
1. A smart question-and-answer method for electricity safety, characterized in that, include: Receiving user input on multimodal power safety issues; The large language model is invoked to perform intent parsing on the multimodal electricity safety issues and generate inference guidance instructions; The reasoning guidance instruction activates the reasoning and action thought chain to perform multiple rounds of reasoning loops, obtaining the reasoning state and corresponding reasoning evidence for each round; Based on the reasoning state and corresponding reasoning evidence in each round, an answer bound to the reasoning evidence is generated; Each round of reasoning loop includes a thinking phase, an action phase, an observation phase, a reflection phase, and a planning phase. The thinking phase includes generating a current tool scheduling strategy based on the current reasoning state and a preset tool registry. The action phase includes optimizing the current tool scheduling strategy with the goal of minimizing tool call costs and response latency, and calling multi-channel retrieval tools for parallel retrieval and evidence collection based on the optimization results. The observation phase includes obtaining the retrieval results returned by the tool calls and extracting multiple key pieces of evidence. The reflection phase includes fusing multiple key pieces of evidence and verifying the sufficiency of the evidence based on the data quality of the fused results. The planning phase includes planning and formulating subsequent reasoning strategies and determining the loop direction based on the sufficiency verification results. The retrieval results of each tool call serve as a new reasoning state, used to update the current reasoning state and participate in the next round of reasoning loop.
2. The method according to claim 1, characterized in that, The tools in the tool registry include at least two of the following: small model calling tools, relational database tools, speech recognition tools, remote storage tools, and knowledge graph tools. The small model invocation tool is used to invoke different domain-specific small models to perform corresponding tasks; The relational database tool is used to invoke the relational database to execute corresponding tasks; The speech recognition tool integrates a speech recognition interface from a third-party application programming interface service to recognize the user's voice input. The remote storage tool is used to invoke the remote document service to execute corresponding tasks; The knowledge graph tool is used to call upon knowledge graphs in the field of electrical safety to perform corresponding tasks.
3. The method according to claim 2, characterized in that, The multi-channel retrieval tool includes relational database tools; the parallel retrieval and evidence collection based on the optimization results using the multi-channel retrieval tool includes: The data schema of the relational database corresponding to the relational database tool is parsed, and based on the parsing results and the multimodal electricity safety problem, a large model prompt word of the relational database is constructed; Based on the large model prompts and read / write security constraints of the relational database, the large language model is guided to generate the corresponding target query statement; The relational database is searched and evidence is collected based on the target query statement; if the search fails, the target query statement is corrected based on the error type returned by the tool call, and a fuzzy matching query is performed based on the corrected result; The read-write security constraint is used to restrict the large language model's operations on the heterogeneous database to read-write operations.
4. The method according to claim 3, characterized in that, The multi-channel retrieval tool includes a knowledge graph tool, which in turn includes a semantic retrieval tool and a keyword retrieval tool; the parallel retrieval and evidence collection based on the optimization results using the multi-channel retrieval tool includes: The semantic retrieval tool is invoked to convert the multimodal electricity safety issues into query vectors through an embedded language model; based on the similarity between the query vectors and the vector representations of each node in the electricity safety domain knowledge graph, evidence is retrieved from the electricity safety domain knowledge graph. The keyword retrieval tool is used to extract the problem keywords of the multimodal electricity safety issues; a knowledge graph retrieval query statement in the field of electricity safety is generated based on the preset retrieval matching conditions; and evidence is obtained by retrieving the knowledge graph in the field of electricity safety based on the knowledge graph retrieval query statement. The retrieval and evidence collection process based on the target query statement, the semantic retrieval tool, and the keyword retrieval tool is executed in parallel.
5. The method according to claim 4, characterized in that, The process of fusing multiple key pieces of evidence and verifying the sufficiency of the evidence based on the data quality of the fusion result includes: Multiple pieces of key evidence were integrated to form a key evidence set; Based on the number of pieces of evidence, their sources, their timeliness, and their credibility in the key evidence set, a sufficiency score for the evidence in the key evidence set is determined. Sufficiency verification is performed based on the sufficiency score and the preset sufficiency threshold; Several key pieces of evidence were extracted from the search results of relational database tools, semantic search tools, and keyword search tools.
6. The method according to claim 1, characterized in that, If the reasoning guidance instructions include analysis instructions for the user-uploaded file to be analyzed, the thinking phase further includes: The feature inspector of the large language model is invoked to parse and preprocess the user-uploaded file to be analyzed, and the data to be analyzed is obtained. The action phase also includes: calling multiple domain-specific mini-models in parallel to analyze and process the data to be analyzed, and obtaining the analysis results of each domain-specific mini-model; The planning phase also includes generating corresponding answer contexts based on the analysis results of the multimodal electricity safety issues and multiple domain-specific small models, and feeding them back to the user.
7. The method according to any one of claims 1-6, characterized in that, The parallel retrieval and evidence collection process also includes: The execution indicators of each tool call are maintained in the tool registry; The performance metrics include at least one of the following: success rate of tool invocation, response latency, invocation error rate, and system load corresponding to tool invocation.
8. The method according to claim 7, characterized in that, The optimization of the current tool scheduling strategy, with the goal of minimizing tool invocation costs and response latency, includes: Based on the tool call execution metrics corresponding to each candidate tool according to the current tool scheduling strategy, determine the routing weight of each candidate tool; The candidate tools are prioritized based on their routing weights to generate an optimized tool scheduling strategy.
9. The method according to claim 1, characterized in that, The process of calling a large language model to perform intent parsing on the multimodal electricity safety issue and generating inference guidance instructions includes: The large language model is invoked to extract entities and identify keywords for the multimodal electricity safety issues. Based on the identified keywords and contextual information, the business domain and set of business tasks are determined. Based on the aforementioned business domain and set of business tasks, as well as pre-set prompt word engineering templates, guided reasoning instructions are generated.
10. The method according to claim 1, characterized in that, Based on the reasoning state and corresponding reasoning evidence in each round, an answer bound to the reasoning evidence is generated, including: The reasoning conclusion is generated based on the reasoning state in each round; For each reasoning conclusion, the reasoning conclusion is bound to the reasoning evidence associated with the corresponding reasoning state; Reasoning conclusions without supporting evidence are marked as unreliable and blocked. The answer is generated based on a conclusion that is supported by reasoning.
11. The method according to claim 1, characterized in that, The action phase also includes: If service unavailability or authentication failure occurs during tool invocation, a retry mechanism will be automatically triggered, and a backup tool will be switched or a delayed retry will be performed according to the preset strategy.
12. An intelligent question-and-answer system for electricity safety, characterized in that, include: The user interaction layer is used to receive user input on multimodal power safety issues. It is also used to output answers that are linked to reasoning evidence; The proxy layer is used to call the large language model to perform intent parsing on the multimodal electricity safety issue and generate reasoning guidance instructions; the reasoning guidance instructions activate the reasoning and action thinking chain to perform multiple rounds of reasoning loops, and obtain the reasoning state and corresponding reasoning evidence for each round; The large language model layer is used to generate answers that are bound to the reasoning evidence based on the reasoning state and corresponding reasoning evidence in each round. Each round of reasoning loop includes a thinking phase, an action phase, an observation phase, a reflection phase, and a planning phase. The thinking phase includes generating a current tool scheduling strategy based on the current reasoning state and a preset tool registry. The action phase includes optimizing the current tool scheduling strategy with the goal of minimizing tool call costs and response latency, and calling multi-channel retrieval tools for parallel retrieval and evidence collection based on the optimization results. The observation phase includes obtaining the retrieval results returned by the tool calls and extracting multiple key pieces of evidence. The reflection phase includes fusing multiple key pieces of evidence and verifying the sufficiency of the evidence based on the data quality of the fused results. The planning phase includes planning and formulating subsequent reasoning strategies and determining the loop direction based on the sufficiency verification results. The retrieval results of each tool call serve as a new reasoning state, used to update the current reasoning state and participate in the next round of reasoning loop.
13. The system according to claim 12, characterized in that, Also includes: The tool layer is used for unified tool registration and metadata management through standardized tool interfaces; And through intelligent routing, a tool scheduling strategy is generated for the reasoning and action thought chain loop of the agent layer; The tool layer includes at least two of the following: small model calling tools, relational database tools, speech recognition tools, remote storage tools, and knowledge graph tools.
14. The system according to claim 12, characterized in that, Also includes: The knowledge storage layer is used to store professional knowledge in the field of electrical safety through a multimodal storage architecture; The knowledge storage layer includes a knowledge graph and a relational database in the field of electrical safety; The knowledge graph in the field of electricity safety is used to store the entity relationship network of various power equipment. The relational database is used to store electricity safety standards and historical electricity safety records of various power equipment.
15. The system according to claim 12, characterized in that, Also includes: The knowledge collection layer is used to automatically collect, preprocess, and manage multi-source knowledge data in the field of electrical safety through a distributed architecture. The knowledge collection layer includes a remote document processing service and a local data acquisition module; The remote document processing service is used to remotely transmit, remotely vectorize, and remotely store documents uploaded to the system. The local data acquisition module is used to collect local network content and local multi-source files.
16. An electronic device, characterized in that, include: At least one processor and memory; The memory and processor are connected via a bus; The memory is used to store one or more programs; When the one or more programs are executed by the at least one processor, the method as described in any one of claims 1 to 11 is implemented.
17. A readable storage medium, characterized in that, It contains an executable program, which, when executed, implements the method as described in any one of claims 1 to 11.
Citation Information
Cited By
Text generation method, legal instrument generation method and text generation system
CN121859859A