MDSplus access code generation method based on large language model
Patent Information
- Application Number
- CN202611088069.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-22
- Publication Date
- 2026-10-13
- Estimated Expiration
- 2046-07-22
AI Technical Summary
现有面向关系型数据库的自然语言到结构化查询语言转换(Text2SQL)方案难以直接解决自然语言物理变量与真实节点路径之间的映射、实验炮号对应访问对象的可用性判断以及MDSplus访问代码生成等问题
[0019]采用上述技术方案具有以下优点:
Smart Images

Figure CN122614890B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of scientific experimental database access and computer code generation technology, and in particular to the MDSplus access code generation method based on a large language model. Background Technology
[0002] MDSplus is a scientific experimental data management system that can be used for the storage, organization, and access of experimental data in tokamak devices and other experimental apparatuses. MDSplus organizes experimental data using a hierarchical tree structure and manages the data through access objects such as experimental trees, experimental gun numbers, signal nodes, and node paths. The data access process also involves reading the corresponding time dimension.
[0003] Current MDSplus data access typically requires a client program to connect to the MDSplus server and write corresponding access code based on the data access task type and output format. During access, information such as the server address, experimental tree name, experimental launcher number, and node path needs to be determined, and operations such as opening the experimental tree, reading node data, reading time dimension data, and releasing resources must be completed according to the corresponding data access logic. Since different experimental trees, experimental launcher numbers, and physical signals may correspond to different access objects, users usually need to understand the specific data organization structure and node paths. Furthermore, there is a mapping relationship between physical variable names in natural language and actual node paths; therefore, manually determining the access object and writing the access code is easily affected by the user's understanding of data structures and programming experience.
[0004] Chinese patent document CN119415546A, published on February 11, 2025, discloses a scheme for converting natural language to structured query language (SQL). This scheme trims the database outline using relevance scoring and database table relationships, and filters contextual examples relevant to the current natural language query. Subsequently, the trimmed database table column information and the filtered contextual examples are combined into a prompt message, and a large language model generates the SQL query statement. This type of scheme primarily handles tables, columns, and inter-table relationships in relational databases, with the goal of generating SQL query statements.
[0005] Chinese patent document CN122196034A, published on June 12, 2026, discloses a scheme for constructing an enhanced database schema knowledge set and semantic index for a specific business database. This technology performs semantic retrieval on natural language queries, obtains candidate tables and fields, and expands necessary join tables and join paths based on inter-table relationships to form a query context. Subsequently, a large language model generates a structured intermediate representation, which is then translated into SQL using rule-based compilation. This technology can also perform validity checks, access control, and correction processing for failed checks on the SQL.
[0006] However, MDSplus's data organization and access process differ from relational databases, which primarily access tables, fields, and inter-table relationships. MDSplus data access requires processing objects such as experimental trees, experimental gun numbers, signal nodes, node paths, and time dimensions, and generating data access code according to the corresponding MDSplus access logic. Existing Natural Language to Structured Query Language (Text2SQL) solutions for relational databases struggle to directly address issues such as the mapping between natural language physical variables and real node paths, availability assessment of the access objects corresponding to experimental gun numbers, and MDSplus access code generation. Directly generating MDSplus access code based on natural language requests by calling a large language model may result in inconsistencies between the experimental tree, experimental gun number, or node path and the actual metadata, affecting code execution and experimental data retrieval.
[0007] Therefore, how to reduce the risk of inconsistency between natural language data access requests and the actual access objects in MDSplus, and how to generate MDSplus data access code that conforms to the actual access objects and data access logic, has become an urgent technical problem to be solved. Summary of the Invention
[0008] The main objective of this invention is to provide an MDSplus access code generation method based on a large language model, which aims to reduce the risk of inconsistency between natural language data access requests and the actual access objects in MDSplus, and to generate MDSplus data access codes that conform to the actual access objects and data access logic.
[0009] To achieve the above objectives, this invention proposes an MDSplus access code generation method based on a large language model, comprising the following steps: Receive natural language data access requests, parse the natural language data access requests, and extract the key access elements required for MDSplus data access, including access object retrieval elements. Based on the access object retrieval elements, a search is performed in the metadata source to recall candidate access objects related to the natural language data access request; The candidate access objects are filtered to determine the final access object; The natural language data access request, the key access elements, the final access object, and the code generation constraints are combined to construct a metadata-constrained code generation context; The metadata-constrained code generation context is input into the large language model, and the large language model generates MDSplus data access code. The metadata source is the MDSplus metadata source; the filtering of the candidate access objects includes filtering the candidate access objects based on at least one of the experimental gun number availability and signal alias mapping relationship; the code generation constraint is the MDSplus code generation constraint, which is used to limit the MDSplus data access code to access the final access object according to the MDSplus access logic.
[0010] Preferably, the access object retrieval elements include at least one of the following: experimental gun number, experimental tree name, signal name, node path, physical variable, and time window; when the natural language data access request includes code generation control requirements, the key access elements also include code generation control elements, which include at least one of the following: data access task type and output format.
[0011] Preferably, the step of parsing the natural language data access request and extracting the key access elements required for MDSplus data access includes: For the key access elements explicitly given in the natural language data access request, extract them directly and form structured fields; For access object retrieval elements not explicitly given in the natural language data access request, they are marked as fields to be completed, and the fields to be completed are completed by searching in the MDSplus metadata source.
[0012] Preferably, the metadata contained in the MDSplus metadata source includes at least the experimental tree name, the range of firing ranges, the signal name, the signal alias, the node path, the data dimension, and the time dimension.
[0013] Preferably, the step of filtering the candidate access objects based on at least one of experimental gun number availability and signal alias mapping to determine the final access object includes: When filtering candidate access objects using the availability of experimental cannon numbers, it is determined whether the candidate access object is available within the corresponding cannon number range based on the experimental cannon number or cannon number range in the natural language data access request; when retaining candidate access objects that are unavailable within the corresponding cannon number range for subsequent semantic matching, their priority in the candidate access object ranking is reduced, making them ranked lower than candidate access objects available within the corresponding cannon number range; when not retaining the unavailable candidate access objects, they are removed from the candidate access object set. When filtering the candidate access objects using signal alias mapping, semantic matching is performed on the candidate access objects based on the signal alias mapping between natural language signal names and node paths; A consistency judgment is made based on the data dimension of the candidate access object and the data access task type and output format of the natural language data access request.
[0014] Preferably, the consistency judgment includes: When the natural language data access request requires drawing a waveform, it is determined whether the candidate access object has a time dimension; When the natural language data access request requires statistics on the results of multiple cannon numbers, it is determined whether the candidate access object supports range access or batch reading of cannon numbers.
[0015] Preferably, the MDSplus code generation constraints include at least the following rules: establishing an MDSplus server connection, opening a specified experimental tree, using a specified experimental cannon number, reading a specified node path, reading the corresponding time dimension when the data access task type or output format of the natural language data access request requires a time dimension and the final access object has a time dimension, and closing the experimental tree or releasing connection resources after the access is completed.
[0016] Preferably, the construction of the metadata-constrained code generation context further includes setting code generation control requirements based on the natural language data access request: When the data access task type of the natural language data access request is to draw a waveform, the large language model is required to generate code that includes data reading and plotting. When the output of the natural language data access request is a data array, the large language model is required to generate code that includes connection, reading, and return of data; When the data access task type of the natural language data access request is to count multiple cannon numbers, the large language model is required to generate code that includes loop reading and statistical calculation.
[0017] Preferably, after generating the MDSplus data access code from the large language model, the method further includes: The generated MDSplus data access code is submitted to the execution module for trial operation. The execution module connects to the MDSplus test environment or a specified data server to verify whether the MDSplus data access code can complete the server connection, open the experimental tree, and read the node path.
[0018] Preferably, after the trial run is completed: When the verification is successful, the system returns the access result, data summary, or visualization result. When the verification fails, basic error information is returned, which includes at least one of the following: connection failure, experimental tree not found, cannon number not found, node path not found, data is empty, and code execution error.
[0019] The above technical solution has the following advantages: This application parses natural language data access requests and extracts key access elements, enabling data access requirements in natural language form to be converted into input information usable in subsequent metadata retrieval and code generation processes. Retrieving MDSplus metadata sources based on key access elements allows for the acquisition of candidate access objects related to the user request before code generation. Filtering candidate access objects based on the availability of experimental weapon numbers reduces the risk that candidate access objects are unavailable within the requested weapon number range; filtering based on signal alias mapping reduces the matching deviation between natural language signal names and actual access objects. Employing at least one of the above filtering methods reduces the risk of inconsistency between the final access object and the user request. Combining the user request, key access elements, final access object, and MDSplus code generation constraints into a metadata-constrained code generation context allows the large language model to generate data access code under the constraints of real access objects and access rules. This helps reduce the risk of fabricating experimental trees or node paths, improves the executability of the generated code, and reduces the work of manually searching for node paths and repeatedly writing MDSplus data access code. Attached Figure Description
[0020] The present invention will now be described in detail with reference to specific embodiments and accompanying drawings, wherein: Figure 1 A flowchart of the MDSplus access code generation method based on a large language model provided in this application embodiment. Detailed Implementation
[0021] The present application will be further described in detail below with reference to specific embodiments. It should be noted that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not intended to limit the scope of protection of the present application.
[0022] Example 1 This embodiment provides a method for generating MDSplus access codes based on a large language model. This method primarily addresses the high barrier to entry for MDSplus data access in nuclear fusion experiment data management, the difficulty in semantic mapping between signal names and node paths, and the repetitive and error-prone process of traditional manual code writing. By introducing a large language model and combining it with a metadata retrieval mechanism, it achieves automatic conversion from user natural language requirements to MDSplus data access codes. Figure 1 As shown, the method specifically includes the following steps.
[0023] Step S1: Receive natural language data access request, parse the natural language data access request, and extract the key access elements required for MDSplus data access.
[0024] Specifically, the system can receive natural language data access requests from users through conventional interfaces such as the front-end interactive interface, command-line interface, network service interface, or integrated scientific research data access platform. These requests can address data access needs within the MDSplus database, including single signals, multiple signal sets, a specific experimental shot number, a range of shot numbers, an experimental tree, a node path, or a specific time interval. For example, a user could input a request to query the plasma current signal of shot number 147001.
[0025] Upon receiving a request, the system performs semantic analysis to identify the data access task type it belongs to. Common data access task types include single signal reading, multiple signal reading, time series access, artillery number range access, node path query, statistical analysis, data preprocessing, or waveform plotting.
[0026] After completing intent recognition, the system further extracts key access elements from the natural language data access request. These key access elements include access object retrieval elements, which include at least one of the following: experimental gun number, experimental tree name, signal name, node path, physical variable, and time window. When the natural language data access request includes code generation control requirements, the key access elements also include code generation control elements, which include at least one of the following: data access task type and output format. For key access elements explicitly given in the request, the system directly extracts and converts them into structured fields. For access object retrieval elements not explicitly given in the request, the system marks them as fields to be completed and completes them in subsequent processes by searching the MDSplus metadata source.
[0027] Step S2: Based on the key access elements, search the MDSplus metadata source to recall candidate access objects related to the natural language data access request.
[0028] To prevent the large language model from fabricating non-existent experimental trees or node paths during code generation, this embodiment first accesses a metadata source related to MDSplus data organization before calling the model. The MDSplus metadata source includes at least the experimental tree name, gun number range, signal name, signal alias, node path, data dimension, and time dimension. Depending on the actual scenario requirements, the metadata can also include the diagnostic system name, storage location, access interface, and data source description. The access interface provides connection information such as the server address required to establish an MDSplus server connection. When the MDSplus metadata source does not provide this connection information, the system receives the data server information specified by the user and provides the connection information to the access context construction step. The system performs a matching search in the MDSplus metadata source based on the previously parsed keywords such as signal name, physical variable, experimental gun number, or time range, thereby recalling corresponding candidate experimental trees, candidate gun numbers, candidate signals, candidate node paths, and candidate data dimensions as candidate access objects.
[0029] Step S3: Filter candidate access objects based on at least one of the experimental gun number availability and signal alias mapping relationship to determine the final access object.
[0030] After obtaining the candidate access object set, further filtering is required to ensure the accuracy of data access. When filtering candidate access objects using the availability of experimental cannon numbers, it is determined whether the candidate access object is available within the corresponding cannon number range based on the experimental cannon number or cannon number range in the natural language data access request. If a candidate node exists only in a specific experimental stage or a specific cannon number range, and the experimental cannon number in the user request is not within that available range, if the unavailable candidate access object is retained in the candidate access object set for subsequent semantic matching, its priority in the candidate access object ranking is reduced, making it ranked lower than candidate access objects available within the corresponding cannon number range; if the unavailable candidate access object is not retained in the candidate access object set, it is removed.
[0031] When filtering candidate access objects using signal alias mapping, the system performs semantic matching on the candidate access objects based on the signal alias mapping relationship between natural language signal names and node paths, thereby mapping the user's natural language expression to the actual existing MDSplus node path. For example, "plasma current" in the user's request is preferentially mapped to the actual MDSplus node path \ip, rather than being freely generated by the large language model to other node paths.
[0032] Furthermore, the system can also perform consistency judgment based on the data dimensions of the candidate access object and the data access task type and output format of the natural language data access request. Specifically, when the data access task type of the natural language data access request includes the requirement to draw waveforms, it determines whether the candidate access object has the necessary time dimension. When the data access task type of the natural language data access request includes the requirement to statistically analyze the results of multiple artillery numbers, it determines whether the candidate access object supports artillery number range access or batch reading functions. After the above filtering and confirmation, the system forms a final access object containing a defined experimental tree name, experimental artillery number or artillery number range, signal name, signal alias, node path, and data dimensions. When the data access task type or output format requires a time dimension and the candidate access object has a time dimension, the corresponding time dimension is included in the final access object.
[0033] Step S4: Combine the natural language data access request, key access elements, final access object, and MDSplus code generation constraints to construct a metadata-constrained code generation context.
[0034] The system organizes the user's original natural language data access request, the parsed key access elements, and the final access object after filtering and confirmation into a structured context. This structured context also includes connection information provided by the access interface in the MDSplus metadata source, or, if the MDSplus metadata source does not provide connection information, user-specified data server information. This process forcibly binds ambiguous physical concepts to objectively real experimental trees, experimental numbers, and node paths. Based on this structured context, the system adds MDSplus code generation constraints. These constraints include at least the following mandatory rules: establishing an MDSplus server connection based on the connection information, opening a specified experimental tree, using a specified experimental number, reading a specified node path, reading the corresponding time dimension when the data access task type or output format of the natural language data access request requires a time dimension and the final access object has a time dimension, and closing the experimental tree or releasing the corresponding connection resources after data access is completed. The system further restricts the large language model from generating fictitious node paths that do not appear in the metadata candidate set.
[0035] The construction process can also set code generation control requirements based on the natural language data access request. When the data access task type of the natural language data access request is to draw a waveform graph, the large language model is required to generate code that includes data reading and plotting. When the output form of the natural language data access request is a data array, the large language model is required to generate code that only includes join, read, and return data operations. When the data access task type of the natural language data access request is to count multiple gun numbers, the large language model is required to generate code that includes loop reading and statistical calculation processes.
[0036] Step S5: Input the metadata-constrained code generation context into the large language model, and the large language model generates MDSplus data access code.
[0037] The system invokes the large language model and generates corresponding data access code based on the previously constructed metadata-constrained code generation context. The code generated by the large language model can reference the final access object and establish an MDSplus server connection based on the connection information, while adhering to the specified programming language specifications. This implementation utilizes metadata constraints to limit the generation scope of the large language model, helping to reduce the risk of node path fabrication and improving the executability and data access efficiency of the generated code.
[0038] As an optimized and optional implementation, after generating the MDSplus data access code from the large language model, this embodiment also includes a step of verifying the generated code. Specifically, the system submits the generated MDSplus data access code to the execution module for trial operation. The execution module connects to the MDSplus test environment or a user-specified data server through a conventional network communication interface to verify whether the generated MDSplus data access code can successfully complete server connection, open the experimental tree, and read node paths.
[0039] After the trial run is completed, if the verification is successful, the system returns the access results, data summary, or visualization results to the user. If the verification fails, the system returns basic error information to the user. This basic error information includes at least one of the following: connection failure, experimental tree not found, cannon number not found, node path not found, data empty, and code execution exception. This verification feedback mechanism helps to identify runtime errors related to server connection, opening the experimental tree, and reading node paths.
[0040] Example 2 Based on the same inventive concept as Embodiment 1, this embodiment describes an exemplary system implementation architecture for the method described in Embodiment 1. This system is used to execute the MDSplus access code generation method based on a large language model as described in Embodiment 1, and specifically includes corresponding module components.
[0041] The user request input module receives natural language data access requests. The request parsing module interacts with the user request input module to parse the natural language data access requests, thereby extracting the key access elements required for MDSplus data access.
[0042] The MDSplus metadata retrieval module connects to both the request parsing module and the MDSplus metadata source. It retrieves access objects from the MDSplus metadata source based on key access elements, recalling candidate access objects related to the natural language data access request. The MDSplus metadata source stores necessary reference information, including the experimental tree name, shot number range, signal name, signal alias, node path, data dimension, and time dimension. It may also include connection information for establishing a connection to the MDSplus server.
[0043] The access object identification module is connected to the MDSplus metadata retrieval module and is used to filter candidate access objects based on at least one of the following: experimental gun number availability and signal alias mapping relationship, to determine the final access object.
[0044] The access context construction module is connected to the access object identification module. It is used to combine natural language data access requests, key access elements, final access objects, and MDSplus code generation constraints and connection information to construct a metadata-constrained code generation context.
[0045] The large language model code generation module connects with the access context construction module. It submits the metadata-constrained code generation context as input to the preset large language model, which then generates the corresponding MDSplus data access code. This generated code can be written in common programming languages such as Python, C, or MATLAB. For multi-signal joint access requests, the large language model code generation module can generate read codes for multiple node paths while maintaining the data correspondence between the signals.
[0046] The code output and execution module connects to the large language model code generation module to output the generated MDSplus data access code. Under system configuration constraints, the code output and execution module can perform trial runs to verify the generated code. In this case, the module establishes regular network communication with the MDSplus data server to verify whether the code can successfully complete server connection, open the experimental tree, and read node paths, and returns the access results or error messages to the user.
[0047] To further illustrate the practical application of this application, a specific example is given of the EAST device MDSplus data access scenario. The user inputs a natural language command through the user request input module, specifically requesting a query for the plasma current signal of shot number 147001 and requesting waveform plotting. The request parsing module parses the command, extracting the experimental shot number as 147001, the signal name as plasma current, and the data access task type as waveform plotting. Subsequently, the MDSplus metadata retrieval module searches for the aforementioned keywords in the MDSplus metadata source. The access object identification module filters and confirms the search results, identifying the experimental tree name as "east" and the node path as \\ip, where EAST is the device name and "east" is the experimental tree name. The user-specified MDSplus data server information serves as the connection information. The access context construction module constructs a structured code generation context based on this. The large language model code generation module generates Python access code based on this context. This code contains complete execution logic for connecting to the MDSplus data server, opening the "east" experimental tree, reading the \\ip node and its time dimension, and plotting the waveform. Finally, the code output and execution module outputs the code and can connect to the MDSplus data server for execution and verification.
[0048] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A method for generating access codes based on a large language model using MDSplus, characterized in that, Includes the following steps: Receive natural language data access requests, parse the natural language data access requests, and extract the key access elements required for MDSplus data access, including access object retrieval elements. Based on the access object retrieval elements, a search is performed in the metadata source to recall candidate access objects related to the natural language data access request; The candidate access objects are filtered to determine the final access object; The natural language data access request, the key access elements, the final access object, and the code generation constraints are combined to construct a metadata-constrained code generation context; The metadata-constrained code generation context is input into the large language model, and the large language model generates MDSplus data access code. The metadata source is the MDSplus metadata source; the filtering of the candidate access objects includes filtering the candidate access objects based on at least one of experimental gun number availability and signal alias mapping relationship; the code generation constraint is the MDSplus code generation constraint, used to limit the MDSplus data access code to access the final access object according to the MDSplus access logic; The step of filtering the candidate access objects based on at least one of experimental gun number availability and signal alias mapping relationship to determine the final access object includes: When filtering candidate access objects using the availability of experimental cannon numbers, it is determined whether the candidate access object is available within the corresponding cannon number range based on the experimental cannon number or cannon number range in the natural language data access request; when retaining candidate access objects that are unavailable within the corresponding cannon number range for subsequent semantic matching, their priority in the candidate access object ranking is reduced, making them ranked lower than candidate access objects available within the corresponding cannon number range; when not retaining the unavailable candidate access objects, they are removed from the candidate access object set. When filtering the candidate access objects using signal alias mapping, semantic matching is performed on the candidate access objects based on the signal alias mapping between natural language signal names and node paths; A consistency judgment is made based on the data dimensions of the candidate access objects and the data access task type and output format of the natural language data access request. The MDSplus code generation constraints include at least the following rules: establishing an MDSplus server connection, opening a specified experimental tree, using a specified experimental cannon number, reading a specified node path, reading the corresponding time dimension when the data access task type or output format of the natural language data access request requires a time dimension and the final access object has a time dimension, and closing the experimental tree or releasing connection resources after the access is completed.
2. The MDSplus access code generation method based on a large language model according to claim 1, characterized in that, The access object retrieval elements include at least one of the following: experimental gun number, experimental tree name, signal name, node path, physical variable, and time window; when the natural language data access request includes code generation control requirements, the key access elements also include code generation control elements, which include at least one of the following: data access task type and output format.
3. The MDSplus access code generation method based on a large language model according to claim 1, characterized in that, The process of parsing the natural language data access request and extracting the key access elements required for MDSplus data access includes: For the key access elements explicitly given in the natural language data access request, extract them directly and form structured fields; For access object retrieval elements not explicitly given in the natural language data access request, they are marked as fields to be completed, and the fields to be completed are completed by searching in the MDSplus metadata source.
4. The MDSplus access code generation method based on a large language model according to claim 1, characterized in that, The metadata source of the MDSplus includes at least the experimental tree name, the range of the firing range, the signal name, the signal alias, the node path, the data dimension, and the time dimension.
5. The MDSplus access code generation method based on a large language model according to claim 1, characterized in that, The consistency judgment includes: When the natural language data access request requires drawing a waveform, it is determined whether the candidate access object has a time dimension; When the natural language data access request requires statistics on the results of multiple cannon numbers, it is determined whether the candidate access object supports range access or batch reading of cannon numbers.
6. The MDSplus access code generation method based on a large language model according to claim 1, characterized in that, The construction of the metadata-constrained code generation context also includes setting code generation control requirements based on the natural language data access request: When the data access task type of the natural language data access request is to draw a waveform, the large language model is required to generate code that includes data reading and plotting. When the output of the natural language data access request is a data array, the large language model is required to generate code that includes connection, reading, and return of data; When the data access task type of the natural language data access request is to count multiple cannon numbers, the large language model is required to generate code that includes loop reading and statistical calculation.
7. The MDSplus access code generation method based on a large language model according to claim 1, characterized in that, After generating the MDSplus data access code from the large language model, the following is also included: The generated MDSplus data access code is submitted to the execution module for trial operation. The execution module connects to the MDSplus test environment or a specified data server to verify whether the MDSplus data access code can complete the server connection, open the experimental tree, and read the node path.
8. The MDSplus access code generation method based on a large language model according to claim 7, characterized in that, After the trial run is completed: When the verification is successful, the system returns the access result, data summary, or visualization result. When the verification fails, basic error information is returned, which includes at least one of the following: connection failure, experimental tree not found, cannon number not found, node path not found, data is empty, and code execution error.
Citation Information
Patent Citations
Intelligent query method for power business data based on large language model and Text2SQL (Structured Query Language)
CN122196034A
SQL (Structured Query Language) statement generation method and device based on large language model, equipment and medium
CN119201966A
Text-to-structured query language conversion method based on large language model
CN119415546A