Data query method and device based on natural language and medium

By constructing task planning guidance information and DSL dimensional paradigm, combining it with a large language model to identify task types and generate structured intermediate representations, the problems of insufficient accuracy and flexibility in existing technologies are solved, and full-process automated data processing and analysis from natural language to executable code is achieved.

CN120705169APending Publication Date: 2025-09-26BEIJING KNOWLEDGE ATLAS TECHNOLOGY CO LTD
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202510875688.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-06-27
Publication Date
2025-09-26

AI Technical Summary

Technical Problem

Existing natural language to indicator generation technologies have problems such as low accuracy, poor interpretability and low flexibility. In particular, they are unable to generate SQL that meets the requirements when faced with complex or diverse natural language queries.

Method used

By constructing task planning guidance information, using a large language model to identify the target task type, and combining it with the predefined DSL dimension paradigm, the query target indicator is determined from the indicator library, semantically related dimension fields and enumeration values ​​are identified, and a structured intermediate representation is constructed. Finally, executable code is generated to obtain the query results.

Benefits of technology

It realizes the full process of automated data processing from natural language input to executable code, improves the accuracy, flexibility and interpretability of the system, supports more complex, ambiguous and diverse expressions, and enhances the versatility and generalization capabilities of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120705169A_ABST
    Figure CN120705169A_ABST
Patent Text Reader

Abstract

The invention relates to a data query method and device based on a natural language and a medium, and belongs to the technical field of data analysis. Receiving a natural language query input by a user; constructing task planning guide information based on the natural language query, and inputting the task planning guide information into the large language model to identify a target task type corresponding to the natural language query; when the target task type is a data query type task, determining a query target index corresponding to the natural language query from an index library; on the basis of a DSL dimension normal form corresponding to the query target index, dimension fields related to semantics of the natural language query and matched enumeration values are recognized from the multiple dimension fields and enumeration value sets; and constructing a structured intermediate representation, generating an executable code corresponding to the natural language query, and executing the executable code to obtain a corresponding structured query result from a data source. According to the method and the device, the accuracy and the interpretability are considered, and meanwhile, the SQL generation flexibility is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of data analysis technology, and specifically relates to a natural language-based data query method, device, and medium. Background Art

[0002] With the rapid development of business intelligence (BI) and data analytics tools, the demand for complex business metric analysis has increased significantly. Driven by the growth of big data and cloud computing, enterprises are increasingly looking to quickly generate complex data analytics metrics using natural language input, thereby improving analysis efficiency and lowering the barrier to entry. However, current technologies for natural language to metric generation (NL2Metric) still face challenges, such as the ambiguity and diversity of natural language expressions, as well as the complexity of business logic and analytical semantics.

[0003] Existing metric generation methods primarily rely on two approaches: templated metric generation based on rule configuration, and metric parsing through natural language understanding (NLU). However, existing technologies for converting natural language queries into SQL queries suffer from the following major issues: insufficient understanding of complex or diverse natural language queries leads to low SQL generation accuracy; and the SQL generation process from natural language in existing large models lacks business logic, making it difficult for users to determine the accuracy of the generated results and resulting in poor interpretability.

[0004] Currently, another new technical solution, NL2Metric, has been widely used due to its high accuracy and interpretability. However, this technical solution has low flexibility. When new problems exceed the scope of the defined template set, it is impossible to generate SQL that meets the requirements.

[0005] In view of this, it is very necessary to provide a technical solution that improves the flexibility of SQL generation while taking into account both accuracy and explainability. Summary of the Invention

[0006] In view of the above analysis, the embodiments of the present invention aim to provide a natural language-based data query method, device, and medium to enhance the flexibility of SQL generation while taking into account both accuracy and interpretability.

[0007] In a first aspect of the present application, a natural language-based data query method is provided, comprising: receiving a natural language query input by a user; Constructing task planning guidance information based on the natural language query, and inputting the task planning guidance information into a large language model to identify a target task type corresponding to the natural language query; When the target task type is a data query task, perform the following steps: Determining a query target indicator corresponding to the natural language query from an indicator library; Based on the DSL dimension paradigm corresponding to the query target indicator, identifying dimension fields and matching enumeration values ​​that are semantically relevant to the natural language query from a plurality of dimension fields and enumeration value sets; Building a structured intermediate representation based on the query target indicator, dimension fields, and matching enumeration values, wherein the intermediate representation is used to represent the structured intent of the natural language query; Based on the intermediate representation, an executable code corresponding to the natural language query is generated, and the executable code is executed to obtain a corresponding structured query result from a data source.

[0008] Optionally, constructing task planning guidance information based on the natural language query includes: Recalling a plurality of task templates having semantic similarity to the natural language query from a preset task template library; The task template is combined with keywords extracted from the industry knowledge base to construct structured task planning guidance information to guide the large language model to identify the corresponding target task type.

[0009] Optionally, the DSL dimension paradigm is a predefined structured template corresponding to each query target indicator, and the structured template includes multiple dimension fields and a set of enumerated values ​​corresponding to each field.

[0010] Optionally, identifying dimension fields and matching enumeration values ​​that are semantically relevant to the natural language query includes: Concatenate the natural language query, dimension fields, and enumeration value sets to generate multiple candidate items; Each candidate item is input into the embedding model for semantic similarity calculation, and the most relevant dimension field and matching enumeration value are determined based on the similarity ranking.

[0011] Optionally, constructing a structured intermediate representation based on the query target indicator, dimension field, and matching enumeration value includes: Intermediate representation guidance information is generated through the DSL dimensional paradigm, and the intermediate representation guidance information is input into the large language model to generate the intermediate representation; wherein the intermediate representation guidance information includes the identified query target indicator name, dimension field, matching enumeration value and grouping intention.

[0012] Optionally, the structured intermediate representation includes a query field, a data source, a matching enumeration value, an optional grouping field, a sorting field, and an optional visualization parameter.

[0013] Optionally, generating executable code corresponding to the natural language query based on the intermediate representation includes: Code generation guidance information is generated based on the intermediate representation, and the code generation guidance information is input into a large language model to generate executable code corresponding to the natural language query.

[0014] Optionally, the executable code further includes instructions for generating a chart display or a natural language analysis and explanation to visualize or semantically output the structured query results.

[0015] In a second aspect of the present application, a natural language-based data query device is provided, comprising a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the natural language-based data query method according to any one of the above is implemented.

[0016] According to a third aspect of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the natural language-based data query method according to any one of the above-mentioned methods is implemented.

[0017] The natural language-based data query method provided by this application can realize the full-process automated data processing and analysis from natural language input to executable code. By constructing task planning guidance information and introducing a large language model to identify task types, it can accurately understand the semantic intentions in the user's natural language queries, support more complex, fuzzy, and diverse expressions, and improve the versatility and accuracy of the system. Combined with the predefined DSL dimension paradigm, it is no longer necessary to write a template for each specific SQL, but only to define a DSL dimension paradigm for an indicator, making it more generalizable and flexible. This application significantly improves the flexibility of the generation logic by constructing a natural language-based task identification mechanism, introducing a semantic recognition process guided by the DSL dimension paradigm, and generating key means of structured intermediate semantic representations, while maintaining the accuracy of semantic recognition, and improving the interpretation and post-processing capabilities through intermediate representations.

[0018] In addition, the present application also provides a natural language-based data query device and medium having the above-mentioned technical effects. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the embodiments of this specification. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.

[0020] Figure 1 A flowchart of a specific implementation of the natural language-based data query method provided in this application; Figure 2 A flowchart of another specific implementation of the natural language-based data query method provided in this application; Figure 3 This is a structural block diagram of the natural language-based data query device provided in this application. DETAILED DESCRIPTION

[0021] In order to make the purpose, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. It should be noted that, in the absence of conflict, the embodiments in this disclosure and the features in the embodiments can be combined, separated, interchanged and / or rearranged with each other. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0022] The terms used herein are for the purpose of describing specific embodiments and are not intended to be restrictive. As used herein, unless the context clearly indicates otherwise, the singular forms "one (kind, person)" and "said (the)" are also intended to include plural forms. In addition, when the terms "comprise" and / or "include" and their variations are used in this specification, the features, integral bodies, steps, operations, parts, assemblies and / or their groups stated are explained, but the presence or addition of one or more other features, integral bodies, steps, operations, parts, assemblies and / or their groups is not excluded. It should also be noted that, as used herein, the terms "substantially", "approximately" and other similar terms are used as approximate terms and not as degree terms, so that they are used to explain the inherent deviations of the measured values, calculated values ​​and / or the values ​​provided that will be recognized by those of ordinary skill in the art.

[0023] The embodiment of the present application provides a data query method based on natural language. The flowchart of a specific implementation method corresponding to the method is as follows: Figure 1 As shown, the method specifically includes the following steps: S101: Receive a natural language query input by a user.

[0024] A natural language query input by a user is received, for example, the user inputs the following natural language query: "Calculate the sales of each product line in Beijing this year." Specifically, the natural language query may include semantic information such as target analysis indicators, restrictions, and analysis dimensions.

[0025] S102: Constructing task planning guidance information based on the natural language query, and inputting the task planning guidance information into a large language model to identify a target task type corresponding to the natural language query.

[0026] Based on the natural language query input by the user, task planning guidance information is constructed. This process involves recalling multiple task templates with semantic similarity to the natural language query from a pre-set task template library. These task templates are then combined with keywords extracted from an industry knowledge base to form task planning guidance information for task identification. This task planning guidance information is used to guide the large language model in identifying the corresponding target task type. The industry knowledge base may include mappings between professional terminology, business jargon, and database fields.

[0027] This task planning guidance information is input into the large language model to identify the target task type of the current natural language query. Task types include but are not limited to: data query, chart generation, report generation, and trend analysis.

[0028] If the recognition result is a data query task, the next step is the structured analysis process.

[0029] S103: When the target task type is a data query task, perform the following steps.

[0030] S104: Determine a query target indicator corresponding to the natural language query from an indicator library.

[0031] From the metric library, based on the semantic content of the natural language query, the core metrics of the user's intended query are determined. For example, in the above example, "sales" is identified as the query target metric.

[0032] S105: Based on the DSL dimension paradigm corresponding to the query target indicator, identify dimension fields and matching enumeration values ​​related to the semantics of the natural language query from multiple dimension fields and enumeration value sets.

[0033] It will be appreciated that each metric in this embodiment of the present application is predefined with a set of DSL dimension paradigms, which are used to describe its corresponding analysis dimension and corresponding set of enumerated values. The DSL dimension paradigm is a predefined structured template corresponding to each query target metric, which includes multiple dimension fields and a set of enumerated values ​​corresponding to each field. Based on this DSL dimension paradigm, combined with the user's natural language query statement, semantic matching is performed on multiple possible dimension fields (such as region, product_line, year) and their enumerated values ​​(such as "Beijing" and "2024").

[0034] Specifically, multiple candidate items are generated by concatenating natural language queries, candidate dimension fields, and enumeration values. Each candidate item is then fed into a semantic embedding model to calculate a similarity score. Based on the score, the most relevant dimension fields and matching enumeration values ​​are selected.

[0035] For example, in this example, the dimension fields identified are "region" and "year", and the corresponding enumeration values ​​can be "Beijing" and "2024".

[0036] S106: Based on the query target indicator, dimension fields and matching enumeration values, a structured intermediate representation is constructed, where the intermediate representation is used to represent the structured intent of the natural language query.

[0037] Based on the identified target metrics, dimension fields, and matching enumeration values, a structured intermediate representation is constructed. This intermediate representation is used to represent the structured intent of the natural language query. The structured intermediate representation includes the query field, data source, matching enumeration values, optional grouping fields, sorting fields, and optional visualization parameters.

[0038] Specifically, intermediate representation guidance information can be generated using the DSL dimensional paradigm and input into the large language model to generate the intermediate representation. The intermediate representation guidance information includes the identified query target indicator name, dimension fields, matching enumeration values, and grouping intent. In this embodiment, the constructed DSL template is an abstract structure, including multiple replaceable dimension fields and enumeration value variables.

[0039] S107: Generate executable code corresponding to the natural language query based on the intermediate representation, and execute the executable code to obtain a corresponding structured query result from a data source.

[0040] Code generation guidance information is generated based on the intermediate representation, and the code generation guidance information is input into a large language model to generate executable code corresponding to the natural language query.

[0041] The executable code may be Python language code, including data query functions and data processing logic, and may further include instructions for generating chart displays or natural language analysis and interpretation to visualize or semantically output structured query results.

[0042] This code not only performs data queries but also supports data cleaning, aggregate calculations, charting, and natural language interpretation. Ultimately, after executing the code, structured query results are retrieved from the backend data source and fed back to the user in the form of tables, charts, or text. Furthermore, data analysis capabilities can be further enhanced by adding task planning, enabling not only data query but also end-to-end report generation and interpretation.

[0043] For example, the result generated in this example may be: "In 2024, the sales of each product line in Beijing are as follows: Product A is 1 million yuan, Product B is 800,000 yuan..." and is simultaneously displayed in the form of a bar chart.

[0044] It is understood that this application involves three types of guidance information, namely: Task planning guidance information: used to determine user intent, such as whether it is for basic data query, chart requirement, or report generation.

[0045] Intermediate representation guidance information: used to identify indicators and dimension fields, extract and construct intermediate representations, such as the representation of DSL structures.

[0046] Code generation guidance information: Convert the extraction results into actual code to achieve final execution.

[0047] It's understandable that task planning guidance, intermediate representation guidance, and code generation guidance can be sequentially linked to form a prompt chain, guiding the large language model through the entire process from task identification to code generation. This approach is suitable for business intelligence (BI) platforms and supports self-service natural language queries for multiple metric types.

[0048] The original NL2Metric solution heavily relied on manually constructed DSL templates. This application uses a similarity and enumeration value selection mechanism to automatically identify dimension and indicator fields, flexibly generate personalized DSL templates, improve fault tolerance and generalization capabilities for non-template coverage issues, and can dynamically adapt to newly added fields and business logic.

[0049] By setting up task planning guidance information, queries are no longer processed individually. Instead, they are first classified into number lookup / trend analysis / report generation tasks to achieve task-oriented processing; this enhances the ability to handle complex multi-target tasks and improves business explainability and expansion capabilities.

[0050] In addition, traditional systems only generate SQL results, while this application can further generate Python code for post-processing (such as charts and analytical summaries); this can form an end-to-end process from data acquisition to processing, further visualization, and finally the formation of reports, thereby improving the degree of automation.

[0051] The natural language-based data query method provided by this application is different from the existing NL2SQL / NL2Metric solution. It can realize full-process automated data processing and analysis from natural language input to executable code. By constructing task planning guidance information and introducing a large language model to identify task types, it can accurately understand the semantic intentions in users' natural language queries, support more complex, fuzzy, and diverse expressions, and improve the versatility and accuracy of the system. Combined with the predefined DSL dimension paradigm, it is no longer necessary to write a template for each specific SQL, but only to define a DSL dimension paradigm for an indicator, making it more generalizable and flexible. This application significantly improves the flexibility of the generation logic by constructing a natural language-based task identification mechanism, introducing a semantic recognition process guided by the DSL dimension paradigm, and generating key means of structured intermediate semantic representations, while maintaining the accuracy of semantic recognition, and improving the interpretation and post-processing capabilities through intermediate representations.

[0052] Figure 2 A flowchart of another specific implementation of the natural language-based data query method provided by the present application is shown. The process specifically includes the following steps: S201: receiving a natural language query input by a user Users enter a natural language query (Query) through the natural language interface, such as "Comparative sales of various product lines in Beijing over the past three years." The semantics of this natural language query sentence contains multiple potential structural elements, such as time range, region, product line, and query indicators.

[0053] S202: Constructing mission planning guidance information Conduct a structured understanding of the query above, build task planning guidance information, and guide the large language model to identify the task type.

[0054] The process specifically includes: recalling the top three task templates from the task planning template library based on semantic similarity; at the same time, extracting industry keywords and jargon related to the query from the business knowledge base (such as "sales" → revenue, "the past three years" → year ∈ [2023,2025]); fusing the above templates with knowledge vocabulary to construct task planning guidance information (Prompt), guiding the large language model to output the target task type.

[0055] S203: Identify target task type The task planning guidance information is parsed by a large language model, and this task is identified as a data query task.

[0056] S204: Semantic identification and matching of indicators and dimensions After confirming the task type, enter the indicator and dimension analysis phase and perform the following sub-steps: a. Indicator recall Based on the query content and the business indicators defined in the indicator library, the top three indicator candidates are retrieved through semantic matching. For example, sales, number of orders, and gross profit.

[0057] The final query indicator is determined to be "revenue" based on semantic relevance and contextual priority.

[0058] b. Enumeration value matching and dimension filtering For dimension fields related to the indicator (such as region, product_line, year, etc.), use query semantics to recall the top 3 enumeration values ​​for each field. For example: region → Beijing, Shanghai, Guangzhou year → 2023, 2024, 2025 product_line → Line A, Line B, Line C c. Similarity judgment and field screening Combine the query, field name (in Chinese and English), and enumeration value into a composite statement, such as: Beijing Sales Comparison "Sales by region: region=Beijing" The similarity scores of the above combinations are calculated using the semantic embedding model, and the most relevant field and enumeration value combinations are selected. Target dimension fields: region, year, product_line Match enumeration value: region=Beijing, year ∈ [2023,2025] Select M mandatory dimensions (such as time) and N optional dimensions based on business rules to ensure that the generated query structure is complete and semantically matched.

[0059] S205: Building a DSL Template Based on the selected indicators, fields, and enumeration values, a standardized DSL template is constructed. The DSL represents guidance information, guiding the language model to generate a structured DSL template that describes the abstract semantic structure of the query logic.

[0060] S206: Generation and execution of executable code Based on the intermediate representation, code generation guidance information is generated to guide the large language model to generate executable code that meets the execution requirements. This code may specifically include: data extraction and cleaning logic, SQL construction or Pandas operations, grouping and aggregation logic, charting function calls, and text result interpretation statement generation (optional).

[0061] S207: Result display and output Execute the above code to output the user's desired results through the chart component and the explanation component. This can include visual charts (such as bar charts and line charts) or natural language descriptions: "From 2023 to 2025, the product line with the fastest sales growth in Beijing is Line A."

[0062] The natural language-based data query method provided in this embodiment achieves accurate parsing and structured execution of complex natural language query semantics through a combination mechanism of task planning, DSL-driven structured recognition, multi-stage guidance information generation, and automatic code generation, effectively improving the intelligent capabilities of the natural language interface, the flexibility of the query, and the scalability of the system.

[0063] In addition, this application also provides a data query device based on natural language, such as Figure 3 As shown in the structural block diagram of the natural language-based data query device provided in this application, the device specifically includes a memory 31 and a processor 32. The memory 31 stores a computer program, and when the computer program is executed by the processor 32, it implements the natural language-based data query method described above.

[0064] The memory 31 stores a data processing program for implementing any of the above method embodiments, wherein the computer program includes: receiving a natural language query input by a user; Constructing task planning guidance information based on the natural language query, and inputting the task planning guidance information into a large language model to identify a target task type corresponding to the natural language query; When the target task type is a data query task, perform the following steps: Determining a query target indicator corresponding to the natural language query from an indicator library; Based on the DSL dimension paradigm corresponding to the query target indicator, identifying dimension fields and matching enumeration values ​​that are semantically relevant to the natural language query from a plurality of dimension fields and enumeration value sets; Building a structured intermediate representation based on the query target indicator, dimension fields, and matching enumeration values, wherein the intermediate representation is used to represent the structured intent of the natural language query; Based on the intermediate representation, an executable code corresponding to the natural language query is generated, and the executable code is executed to obtain a corresponding structured query result from a data source.

[0065] The processor 32 implements the complete process of natural language to structured query semantics parsing, field matching, logical construction, code generation and execution by executing the above program instructions, and finally outputs the required structured data results, charts or natural language descriptions.

[0066] In some specific embodiments, the memory 31 stores a data processing program for implementing any of the above method embodiments, wherein the computer program includes a computer program for: Recalling a plurality of task templates having semantic similarity to the natural language query from a preset task template library; The task template is combined with keywords extracted from the industry knowledge base to construct structured task planning guidance information to guide the large language model to identify the corresponding target task type.

[0067] In some specific embodiments, the memory 31 stores a data processing program for implementing any of the above method embodiments, wherein the computer program includes a computer program for: Concatenate the natural language query, dimension fields, and enumeration value sets to generate multiple candidate items; Each candidate item is input into the embedding model for semantic similarity calculation, and the most relevant dimension field and matching enumeration value are determined based on the similarity ranking.

[0068] In some specific embodiments, the memory 31 stores a data processing program for implementing any of the above method embodiments, wherein the computer program includes a computer program for: Intermediate representation guidance information is generated through the DSL dimensional paradigm, and the intermediate representation guidance information is input into the large language model to generate the intermediate representation; wherein the intermediate representation guidance information includes the identified query target indicator name, dimension field, matching enumeration value and grouping intention.

[0069] In some specific embodiments, the memory 31 stores a data processing program for implementing any of the above method embodiments, wherein the computer program includes a computer program for: Code generation guidance information is generated based on the intermediate representation, and the code generation guidance information is input into a large language model to generate executable code corresponding to the natural language query.

[0070] Optionally, the executable code further includes instructions for generating a chart display or a natural language analysis and explanation to visualize or semantically output the structured query results.

[0071] In some preferred implementations, the device may also include an input module (such as voice recognition or text input unit) and an output module (such as a display screen, a chart engine, voice broadcast, etc.) for human-computer interaction to provide a complete user interaction experience.

[0072] By integrating language model reasoning capabilities, industry knowledge base, task template library, code generation module and execution engine, the device forms an efficient bridge between natural language and structured queries. It not only significantly lowers the threshold for users to use data query tools, but also improves the adaptability to ambiguous and complex language expressions and the interpretability of query results.

[0073] In addition, the present application also provides a computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the natural language-based data query method according to any one of the above-mentioned methods is implemented.

[0074] Computer-readable storage media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0075] Professionals should also be further aware that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the above description has generally described the components and steps of each example according to their functions. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0076] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0077] The specific implementation methods described above further illustrate the purpose, technical solutions and beneficial effects of this application. It should be understood that the above description is only the specific implementation methods of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of this application should be included in the scope of protection of this application.

Claims

1. A data query method based on natural language, characterized in that: include: receiving a natural language query input by a user; Constructing task planning guidance information based on the natural language query, and inputting the task planning guidance information into a large language model to identify a target task type corresponding to the natural language query; When the target task type is a data query task, perform the following steps: Determining a query target indicator corresponding to the natural language query from an indicator library; Based on the DSL dimension paradigm corresponding to the query target indicator, identifying dimension fields and matching enumeration values ​​that are semantically relevant to the natural language query from a plurality of dimension fields and enumeration value sets; Building a structured intermediate representation based on the query target indicator, dimension fields, and matching enumeration values, wherein the intermediate representation is used to represent the structured intent of the natural language query; Based on the intermediate representation, an executable code corresponding to the natural language query is generated, and the executable code is executed to obtain a corresponding structured query result from a data source.

2. The data query method based on natural language according to claim 1, characterized in that: The constructing of task planning guidance information based on the natural language query includes: Recalling a plurality of task templates having semantic similarity to the natural language query from a preset task template library; The task template is combined with keywords extracted from the industry knowledge base to construct structured task planning guidance information to guide the large language model to identify the corresponding target task type.

3. The data query method based on natural language according to claim 1, characterized in that: The DSL dimension paradigm is a predefined structured template corresponding to each query target indicator. The structured template includes multiple dimension fields and a set of enumerated values ​​corresponding to each field.

4. The data query method based on natural language according to claim 3, characterized in that: The identifying dimension fields and matching enumeration values ​​related to the semantics of the natural language query includes: Concatenate the natural language query, dimension fields, and enumeration value sets to generate multiple candidate items; Each candidate item is input into the embedding model for semantic similarity calculation, and the most relevant dimension field and matching enumeration value are determined based on the similarity ranking.

5. The natural language-based data query method according to any one of claims 1 to 4, characterized in that: The constructing of a structured intermediate representation based on the query target indicator, dimension field, and matching enumeration value includes: Intermediate representation guidance information is generated through the DSL dimensional paradigm, and the intermediate representation guidance information is input into the large language model to generate the intermediate representation; wherein the intermediate representation guidance information includes the identified query target indicator name, dimension field, matching enumeration value and grouping intention.

6. The data query method based on natural language according to claim 5, characterized in that: The structured intermediate representation includes query fields, data sources, matching enumeration values, optional grouping fields, sorting fields, and optional visualization parameters.

7. The natural language-based data query method according to any one of claims 1 to 4, characterized in that: Generating executable code corresponding to the natural language query based on the intermediate representation includes: Code generation guidance information is generated based on the intermediate representation, and the code generation guidance information is input into a large language model to generate executable code corresponding to the natural language query.

8. The natural language-based data query method according to claim 7, characterized in that: The executable code also includes instructions for generating a chart display or a natural language analysis explanation to visualize or semantically output the structured query results.

9. A data query device based on natural language, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the natural language-based data query method according to any one of claims 1 to 8 is implemented.

10. A computer-readable storage medium, characterized in that A computer program is stored thereon, and when the computer program is executed by a processor, the natural language-based data query method according to any one of claims 1 to 8 is implemented.

Citation Information

Cited By

  • Data extraction method and device based on natural language and electronic equipment

    CN121301368A

  • SQL query statement generation method, data query method and related products

    CN121326960A

  • Analysis method and system for natural language time description

    CN121390037A

  • Data query method and system based on ontology semantic data network and ABC normal form

    CN122173689A