Database question and answer method and device, equipment, storage medium and computer program product

By introducing large-scale language model and semantic layer analysis technology into the Chat2SQL system, zero-sample learning is achieved, the existing system's dependence on large amounts of labeled data is solved, the development cost and time is reduced, and the system's adaptability is improved.

CN120067129APending Publication Date: 2025-05-30SHANGHAI JINLING INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202510110730.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-01-23
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

The existing Chat2SQL system based on machine learning relies on a large amount of labeled data for training, which is time-consuming and expensive, and does not perform well in the face of new fields or unseen data table structures.

Method used

A zero-sample Chat2SQL question-and-answer method based on large-scale language model and semantic layer analysis is proposed. By receiving target questions input by users, key elements are extracted, and matching them based on the semantic configuration information of the database and the problem-guiding tags in the historical dialogue, we judge whether the problem is a data query task. If so, we generate the corresponding database query statement and execute it.

Benefits of technology

It realizes seamless conversion between natural language queries and SQL query statements, reduces dependence on a large amount of labeled data, significantly reduces the cost and time of system development, and improves the flexibility and adaptability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120067129A_ABST
    Figure CN120067129A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of natural language processing and database query, and discloses a database question and answer method, device and equipment, a storage medium and a computer program product.The method comprises the steps that a target question input by a request user is received, and key elements in the target question are extracted based on a preset language model; matching the key elements according to semantic configuration information of a database and question guide tags in historical dialogues, and judging whether the target question is a data query task or not; if the target problem is the data query task, generating a database query statement corresponding to the target problem; and executing the database query statement, and replying the target problem according to an execution result. On the basis of a large-scale language model and a fine semantic layer analysis technology, seamless conversion between natural language query and SQL query statements can be achieved without an additional training process, zero sample learning is achieved, dependence on a large amount of labeled data is reduced, and the cost and time of system development are remarkably reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical fields of natural language processing and database query, and particularly relates to a database question-answering method, apparatus, device, storage medium, and computer program product. Background Art

[0002] Most existing Chat2SQL systems based on machine learning rely on a large amount of labeled data for training, which is not only time-consuming and costly, but also often performs poorly when faced with new fields or unseen database table structures. Summary of the Invention

[0003] The main purpose of this application is to provide a database question-answering method, apparatus, device, storage medium, and computer program product, aiming to solve the technical problem of the dependence on a large amount of labeled data in the prior art.

[0004] To achieve the above objective, this application proposes a database question-answering method, which includes:

[0005] Receiving a target question input by a requesting user, and extracting key elements in the target question based on a preset language model;

[0006] Matching the key elements according to the semantic configuration information of the database and the question guidance tags in the historical conversation, and determining whether the target question is a data query task;

[0007] If the target question is a data query task, generating a database query statement corresponding to the target question;

[0008] Executing the database query statement, and replying to the target question according to the execution result.

[0009] Optionally, the step of matching the key elements according to the semantic configuration information of the database and the question guidance tags in the historical conversation, and determining whether the target question is a data query task includes:

[0010] Constructing a database semantic index based on the semantic configuration information of the database, where the semantic configuration information includes table function information, field explanations, value range information, and inter-table association information;

[0011] Retrieving the key elements based on the database semantic index to obtain a first matching result;

[0012] Calculating the text similarity between the question guidance tags in the historical conversation and the key elements, and determining a second matching result according to the text similarity;

[0013] Determine whether the target problem is a data query task according to the first matching result and the second matching result.

[0014] Optionally, the step of generating a database query statement corresponding to the target problem if the target problem is a data query task includes:

[0015] If the target problem is a data query task, determine the database structure elements corresponding to the key elements;

[0016] Construct the database structure elements into a database query statement through a preset database syntax set.

[0017] Optionally, the step of constructing the database structure elements into a database query statement through a preset database syntax set includes:

[0018] Extract the column information, reference information, and operator type related to the database structure from the database structure elements through a phrase-column link function;

[0019] Generate an inter-table connection path based on the column information and reference information;

[0020] Generate a database query statement according to the database syntax set with the operator type and the inter-table connection path.

[0021] Optionally, the step of executing the database query statement and replying to the target problem according to the execution result includes:

[0022] Execute the database query statement through a database connection interface to obtain an execution result;

[0023] If the execution result is successful, optimize the query result of the database query statement and display the optimized query result to the requesting user in a preset format;

[0024] If the execution result is a failure, return to the step of generating a database query statement corresponding to the target problem, and when the number of executions reaches a preset failure threshold, feedback an error prompt message to the requesting user.

[0025] Optionally, after the step of, if the execution result is successful, optimizing the query result of the database query statement and displaying the optimized query result to the requesting user in a preset format, further includes:

[0026] Receive the feedback information of the requesting user, and generate a target label corresponding to the target problem according to the feedback information and the key elements;

[0027] Update the question guiding tag according to the target tag.

[0028] In addition, to achieve the above object, the present application also provides a database question-answering device, which includes:

[0029] A question parsing module, configured to receive a target question input by a requesting user, and extract key elements in the target question based on a preset language model;

[0030] A semantic mapping module, configured to match the key elements according to the semantic configuration information of the database and the question guiding tag in the historical conversation, and determine whether the target question is a data query task;

[0031] A statement generation module, configured to generate a database query statement corresponding to the target question if the target question is a data query task;

[0032] A result display module, configured to execute the database query statement and reply to the target question according to the execution result.

[0033] In addition, to achieve the above object, the present application also provides a database question-answering device, which includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, where the computer program is configured to implement the steps of the database question-answering method as described above.

[0034] In addition, to achieve the above object, the present application also provides a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium, and when the computer program is executed by a processor, the steps of the database question-answering method as described above are implemented.

[0035] In addition, to achieve the above object, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the database question-answering method as described above are implemented.

[0036] This application discloses receiving a target question input by a requesting user and extracting key elements in the target question based on a preset language model; matching the key elements according to the semantic configuration information of the database and the question guiding tags in the historical conversation to determine whether the target question is a data query task; if the target question is a data query task, generating a database query statement corresponding to the target question; executing the database query statement, and replying to the target question according to the execution result. Based on the pre-trained large-scale language model and the refined semantic layer analysis technology, seamless conversion between natural language queries and SQL query statements can be achieved without an additional training process, zero-shot learning can be realized, the dependence on a large amount of labeled data is reduced, and the cost and time of system development are significantly reduced. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The accompanying drawings herein are incorporated into the specification and form a part of the specification, showing embodiments consistent with the present application, and are used together with the specification to explain the principles of the present application.

[0038] To more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0039] Figure 1 It is a schematic flowchart of the first embodiment of the database question-answering method of the present application;

[0040] Figure 2 It is an architecture diagram of the Chat2SQL question-answering system of the present application;

[0041] Figure 3 It is a schematic flowchart of the second embodiment of the database question-answering method of the present application;

[0042] Figure 4 It is a structural diagram of the semantic layer mapping module of the present application;

[0043] Figure 5 It is a schematic flowchart of the third embodiment of the database question-answering method of the present application;

[0044] Figure 6 It is a schematic flowchart of the fourth embodiment of the database question-answering method of the present application;

[0045] Figure 7 It is a schematic diagram of the graphical representation of the execution result of the database question-answering method of the present application;

[0046] Figure 8 It is a schematic diagram of the tabular representation of the execution result of the database question-answering method of the present application;

[0047] Figure 9 It is a schematic flowchart of a brief process of a database question-answering method;

[0048] Figure 10 It is a schematic diagram of the module structure of the database question-answering device according to the embodiment of the present application;

[0049] Figure 11 It is a schematic diagram of the device structure of the hardware operating environment involved in the database question-answering method according to the embodiment of the present application.

[0050] The implementation, functional features and advantages of the present application will be further described in conjunction with the embodiments with reference to the accompanying drawings. Specific embodiments

[0051] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0052] In order to better understand the technical solutions of the present application, the following will be described in detail in conjunction with the accompanying drawings of the specification and specific embodiments.

[0053] The main solution of the embodiment of the present application is: receiving a target question input by a requesting user, and extracting key elements in the target question based on a preset language model; matching the key elements according to the semantic configuration information of the database and the question guiding tags in the historical conversation to determine whether the target question is a data query task; if the target question is a data query task, generating a database query statement corresponding to the target question; executing the database query statement, and replying to the target question according to the execution result.

[0054] In the current data-driven era, it has become increasingly important to quickly obtain the required information from a vast dataset. Traditional methods usually require users to have certain SQL programming skills, which is a huge obstacle for users without a technical background. Although existing machine learning-based Chat2SQL systems can solve this problem to a certain extent, most of them rely on a large amount of labeled data for training, which is not only time-consuming but also costly. In addition, when faced with new domains or unseen table structures, these models often perform poorly. Zero-Shot Learning, as an emerging technology, can complete tasks by transferring existing knowledge without specific domain training data. Applying zero-shot learning to the Chat2SQL field can significantly reduce the cost and time of system development, while improving the flexibility and adaptability of the system.

[0055] Therefore, the present application provides a zero-shot Chat2SQL question-answering method based on a large language model (LLM) and semantic layer analysis, enabling users to interact with the database efficiently and accurately through natural language without any pre-training.

[0056] It should be noted that the execution subject of this embodiment can be a computing service device with data processing, network communication, and program running functions, such as a computer, or an electronic device capable of implementing the above functions. Hereinafter, the Chat2SQL question-answering system will be taken as an example to illustrate this embodiment and the following embodiments.

[0057] Based on this, an embodiment of the present application provides a database question-answering method, referring to Figure 1 , Figure 1 which is a schematic flowchart of the first embodiment of the database question-answering method of the present application.

[0058] In this embodiment, the database question-answering method includes:

[0059] Step S10, receiving the target question input by the requesting user, and extracting key elements from the target question based on a preset language model.

[0060] It should be noted that the requesting user refers to an individual or application program that inputs questions to seek information. These requesting users usually do not have professional database knowledge but expect to obtain relevant data in the database through natural language. The target question is the specific query statement or inquiry content input by the requesting user, usually expressed in natural language, covering the information needs that the user wants to understand, such as "Find the product names with the highest sales last year". The language model is a pre-set model for processing natural language. These models are trained with a large amount of text data and can analyze, understand, and extract features from the input text. The key elements are information units extracted from the target question that are crucial for constructing a database query statement, including but not limited to entity names, attributes, time ranges, operation types, and their logical relationships.

[0061] Specifically, the Chat2SQL question-answering system first receives the target question input by the requesting user, and then inputs the question into the preset language model. The language model will perform a series of processing operations on the target question, such as lexical analysis, syntactic analysis, and semantic understanding. By analyzing the vocabulary, part of speech, syntactic structure, and semantic relationships in the question text, the key information related to the database query is identified and extracted as key elements. For example, when processing the target question "Count the number of orders in different regions in the past three months", the language model will identify key elements such as "in the past three months", "different regions", "number of orders", and "count".

[0062] It is understandable that the pre-set language model can adopt an open-source large-scale language model as the basic framework. These models are trained on large-scale corpora and can effectively capture the deep semantic information in the text. For specific application scenarios, such as the financial and medical fields, the model can also be fine-tuned to improve the query accuracy in specific domains.

[0063] Step S20: Match the key elements according to the semantic configuration information of the database and the problem guiding tags in the historical conversation, and determine whether the target problem is a data query task.

[0064] It should be noted that the semantic configuration information defines the structure of the database and the semantics of the data, including the function information of the library tables (describing the role of each table in the database and the data topics stored, such as the "order table" for storing all order-related data), field explanations (explaining the meaning represented by each field, like the "order amount" field in the "order table" indicating the transaction amount of the order), value range information (defining the possible value range of the field, for example, the possible values of the "gender" field are "male" or "female"), and inter-table association information (indicating the logical connection relationship between different tables, such as the "customer table" and the "order table" are associated through the "customer ID", reflecting the relationship between customers and the orders they place), etc. The problem guiding tags are representative tags extracted and summarized from the user's questions during the previous interactions between the user and the database Q&A system. These tags can reflect common problem types, topics, or query intents, such as "product sales query", "customer information retrieval", etc., and are used to assist in understanding and classifying new target problems.

[0065] It is understandable that determining whether the target problem is a data query task can be based on constructing a database semantic index according to the semantic configuration information of the database. By processing information such as the function of the library tables and field explanations, it is transformed into an index structure that is convenient for rapid retrieval and matching. Then, use this semantic index to retrieve the key elements extracted from the target problem, find the relevant database structure elements and semantic information, and obtain the first matching result. Next, calculate the text similarity between the key elements and the problem guiding tags in the historical conversation, using algorithms such as cosine similarity, and determine the second matching result according to the similarity level. Finally, comprehensively consider the first matching result and the second matching result to determine whether the target problem is a data query task.

[0066] Step S30: If the target problem is a data query task, generate a database query statement corresponding to the target problem.

[0067] It should be noted that a database query statement is an instruction written in accordance with the specific syntax rules of a database, used to retrieve, filter, count, or manipulate data from the database. For example, "SELECT store_name FROM stores ORDER BY sales_amount DESC LIMIT 10" corresponds to an SQL query statement for querying the names of the top ten stores ranked by sales amount.

[0068] It should be understood that after determining that the target problem is a data query task, it is first necessary to determine the database structure elements corresponding to the key elements extracted from the target problem, including identifying the database tables involved, the fields in the tables, and the association relationships between the tables, etc. Then, based on the preset database syntax set, these determined database structure elements are combined according to the correct logic and syntax rules to construct a complete database query statement. During the construction process, various query keywords (such as SELECT, FROM, WHERE, ORDER BY, etc.), functions (such as SUM, AVG, etc. for statistical calculations), and join operators (such as JOIN for table joining) need to be accurately used to ensure that the query statement can accurately implement the functions required by the target problem.

[0069] Step S40: Execute the database query statement and reply to the target problem according to the execution result.

[0070] It can be understood that after generating the corresponding database query statement, the Chat2SQL Q&A system first sends the generated database query statement to the corresponding module for execution through the database connection interface. At the same time, it parses the query statement, retrieves and processes relevant data according to the storage structure and index information of the database, and returns the execution result. If the execution result indicates that the query is successful, the returned data will be further optimized and sorted, including operations such as data format conversion, duplicate data removal, and sorting in a specific order, to improve the readability and usability of the data. Then, according to the nature of the target problem and the user's needs, the optimized result is presented to the requesting user in a preset format (such as a table, chart, text paragraph, etc.). If the execution result is a failure, the reason for the failure will be judged, such as a syntax error, insufficient data permissions, or a database connection problem, etc. If the number of failures does not reach the preset failure threshold, an attempt will be made to regenerate and execute the query statement; if the threshold is reached, a detailed error prompt message will be fed back to the user to help the user understand the problem and try to solve it.

[0071] For ease of understanding, the following is an example, but it does not limit the present invention. In one example, refer to Figure 2 , Figure 2This is the architecture diagram of the Chat2SQL Q&A system of this application. The overall architecture analyzes and identifies the intent of the user's question and outputs the final result based on each framework. At the database layer, MySQL is used to store the company's core business data, such as customer information, order information, product information, etc. Hive mainly stores a large amount of historical transaction data and user behavior data for data analysis and data mining. ClickHouse is used to store real-time business metric data, such as the number of orders per minute, real-time inventory changes, etc.

[0072] At the semantic library layer, a large pre-trained language model is deeply integrated with fine-grained semantic layer analysis technology. By parsing the metadata tables of the database in detail, including the database usage, table usage, field explanations, value ranges, and relationships between tables, this module can accurately parse and locate specific databases, data tables, fields, and related tables according to the user's question. Among them, the database name, database usage, data table name, and table usage are used to deeply analyze the description information about the database and tables in the metadata table, understand the overall architecture of the database and the functions of each table, including the main uses and application scenarios, etc., to provide background knowledge for the accurate understanding of the query intent. Field explanations (simple explanations and detailed explanations) and value ranges are used to interpret in detail the alias and meaning, data type, value range, and possible constraint conditions of each field, including the mapping details of the enumerated value dictionary table, related table fields, etc., to ensure that field information can be accurately used when generating SQL queries and help the model generate reasonable and accurate query conditions. The relationships between tables are used to identify and parse the relationships between different tables, and the related dictionary tables involved in a single column, including foreign key constraints, business logic associations, etc., to provide the necessary logical support for generating complex queries involving multiple tables.

[0073] In the LLM (Large Language Model) layer, Prompt engineering is used to convert the natural language question input by the user into a suitable prompt (Prompt). The LLM analyzes the possible tables involved, such as the product table and the order table, based on the prompt, searches for relevant data tables, and finally generates the corresponding SQL query statement (SQL expression generation) based on the understanding of the relevant data tables and the requirements of the user's question.

[0074] Include various mechanisms in other modules, such as the error retry mechanism: when the SQL query execution fails, the execution engine will automatically attempt to re-execute the query, with a maximum of three retries. During the retries, the execution engine will check for possible error causes, such as database connection problems, lock contention, etc., and attempt to fix them. If the retries still fail after multiple attempts, the system will record detailed error information and display a friendly error prompt to the user, guiding the user to check the query conditions or contact the administrator for resolution. Multi-round dialogue support: when the system cannot fully understand the user's query intention, the result feedback module will initiate the multi-round dialogue function. By asking questions, the module will guide the user to provide more information or clarify the query intention. For example, if the query conditions entered by the user are too vague or ambiguous, the module will ask the user for specific filtering conditions or demand details. Database connection tool and execution engine: responsible for establishing connections with different types of databases (MySQL, Hive, ClickHouse, etc.) and executing the generated SQL query statements. At the same time, according to the type and characteristics of the database, select appropriate connection methods and execution strategies to ensure the efficient execution of the query.

[0075] In the result feedback layer, the result feedback module is responsible for presenting the query results in a user-friendly and intuitive format. According to the type of query results (such as tables, charts, text, etc.), the module will adopt corresponding presentation methods. For example, streaming output, chart display, and json format download, etc.

[0076] In this embodiment, based on the pre-trained large-scale language model and the fine semantic layer analysis technology, seamless conversion between natural language queries and SQL query statements can be achieved without an additional training process, realizing zero-shot learning, reducing the dependence on a large amount of labeled data, and significantly reducing the cost and time of system development.

[0077] Refer to Figure 3 , Figure 3 FIG.

[0078] In the second embodiment, step S20 includes:

[0079] Step S201, construct a database semantic index based on the semantic configuration information of the database, where the semantic configuration information includes library table function information, field explanations, value range information, and inter-table association information.

[0080] It should be noted that the database semantic index is a data structure constructed based on the database semantic configuration information, which is used to quickly retrieve and match relevant content in the database, so as to better understand and process the user's query request and improve the accuracy and efficiency of database queries. The table function information is used to describe the main functions and uses of each table in the database. For example, "the order table is used to store the order details of all customers, including order numbers, order placement times, product information, customer information, etc.". The field explanation is used to explain the meaning of each field in the database table. For example, "the order amount field in the order table represents the total transaction amount of the order". The value range information is used to define the possible value range of the field. For example, "the value range of the gender field is male and female". The inter-table association information indicates the logical connection relationship between different database tables. For example, "the customer table and the order table are associated through the customer ID field to reflect the corresponding relationship between customers and orders".

[0081] It should be understood that when constructing indexes for the table function information and field explanations, word segmentation needs to be performed first to extract key words and key phrases as index terms. For fields with value ranges, each value in the value range can be used as an index term.

[0082] Step S202, retrieve the key elements based on the database semantic index to obtain a first matching result.

[0083] It can be understood that the first matching result can determine whether the user needs to process the information in the database. When retrieving the key elements based on the database semantic index, for each key element, a search is performed in the database semantic index. For entity-type key elements, search for the matching database table in the table function information index; for attribute-type key elements, find the corresponding field in the field explanation index; for key elements involving value ranges, locate the relevant information in the value range information index; for key elements involving inter-table associations, obtain the corresponding association relationship in the inter-table association information index. By further analyzing the syntactic structure to deeply understand the semantic information in the sentence, such as the subject, predicate, object, etc., the query intention can be understood more deeply.

[0084] In one example, the user enters a query request in the form of natural language through the front-end interface, such as: "Please list the top 10 products with the highest sales amount". After receiving the input, the natural language understanding module in the Chat2SQL Q&A system first preprocesses the text, including word segmentation, part-of-speech tagging, etc. Using pre-trained language models such as Qwen, Llama, Yi, Qwencode, etc., the key elements of the query are extracted. For example, the query object is "products", the sorting basis is "sales amount", and the limiting condition is "the top 10".

[0085] Step S203: Calculate the text similarity between the problem guiding tags in the historical conversation and the key elements, and determine the second matching result based on the text similarity.

[0086] It should be understood that text similarity is an indicator used to measure the similarity degree between two text fragments at semantic, lexical and other levels, such as cosine similarity, edit distance, etc. By evaluating the similarity between the key elements and the problem guiding tags, the tightness of their association can be judged. The second matching result is a set of historical problem guiding tags that match the key elements of the current target problem, which is determined by calculating the text similarity and according to certain judgment rules (such as similarity threshold, etc.). Its function is to assist in judging whether the target problem belongs to the data query task and subsequent query statement construction and other operations.

[0087] Step S204: Judge whether the target problem is a data query task according to the first matching result and the second matching result.

[0088] It can be understood that to judge whether the target problem is a data query task, different weights can be assigned to the first matching result and the second matching result to obtain a comprehensive judgment threshold, and it is judged whether the target problem belongs to the data query task by judging the threshold.

[0089] It should be understood that for the query results submitted by the user, the system can also record the user's feedback opinions, such as whether the query needs are met, whether the query results are accurate, etc. Based on the user feedback, the system can dynamically adjust the mapping rules, such as adding new mapping rules, modifying the mapping methods or priorities of the existing rules, etc., to improve the accuracy and efficiency of the query. By continuously accumulating user query data and feedback results, these data are used to continuously optimize the semantic layer configuration, reduce fuzzy or unclear configuration information, and gradually improve the intelligent level and user experience of the system.

[0090] In an example, refer to Figure 4 , Figure 4This is the structure diagram of the semantic layer mapping module of the present application. The semantic layer parses the metadata table of the database in detail, including the library usage, table usage, field explanations, value ranges, and inter-table association relationships, and accurately parses and locates specific databases, data tables, fields, and associated tables according to the user's question. At the same time, this module also has the ability of dynamic adjustment and optimization, and can continuously adjust and optimize the mapping rules based on the user's feedback to improve the accuracy and efficiency of queries. Among them, the database information is initially read through the database connected by the user, and the database information includes basic structure information; the mapping rules can be to extract the field names, descriptions, types, etc. of the library tables, extract and organize the detailed information of the tables and fields in the database, and clarify the specific attributes and meanings of each field; it can also be a custom rule method to process the discrete column value enumeration values. For some discrete fields, custom rules are used to process their possible value enumeration situations to better understand and use this data. In the semantic layer mapping configuration, custom configuration is allowed, allowing users to make personalized settings and adjustments to the semantic mapping according to specific needs; it can also be automatically configured through sampling data depending on the large model. Using the large model and sampling data, part of the semantic mapping configuration work is automatically completed to improve the configuration efficiency and accuracy. Finally, it also includes dynamic adjustment and optimization, including user feedback collection, mapping rule adjustment, continuous optimization adjustment, and large model-assisted optimization, etc., to provide users with an efficient and intelligent query experience.

[0091] In this embodiment, a database semantic index is constructed based on the semantic configuration information of the database, where the semantic configuration information includes library table function information, field explanations, value range information, and inter-table association information; the key elements are retrieved based on the database semantic index to obtain a first matching result; the text similarity between the problem guiding tags in the historical conversation and the key elements is calculated, and a second matching result is determined according to the text similarity; it is judged whether the target problem is a data query task according to the first matching result and the second matching result. By comprehensively using the semantic configuration information of the database to construct a semantic index and combining the problem guiding tags in the historical conversation for key element matching, the semantics and potential intentions of the target problem can be comprehensively and deeply understood. The possibility of misjudgment is reduced, enabling the system to more accurately identify the problems that really require data query operations.

[0092] Refer to Figure 5 , Figure 5 This is the flowchart of the third embodiment of the database question and answer method of the present application. Based on the above second embodiment, the third embodiment of the database question and answer method of the present application is proposed.

[0093] In the third embodiment, the step S30 includes:

[0094] Step S301, if the target problem is a data query task, determine the database structure elements corresponding to the key elements.

[0095] It should be noted that database structure elements refer to various components in a database, such as database tables, fields in the tables, and the association relationships between tables. These elements are the basic frameworks for storing and organizing data and are also the key basis for implementing data queries.

[0096] Specifically, when the target problem is a data query task, carefully sort out the key elements extracted from the target problem and clarify the meaning and role of each element. According to the entity information in the key elements, search for the corresponding database tables in the semantic configuration information of the database. For example, "product name" may correspond to the "product table". If the key elements involve multiple entities, it may be necessary to search for multiple related database tables and determine the association relationships between them. After finding the corresponding database tables, determine the relevant fields in the tables according to the attribute information in the key elements. Based on the fields, determine the database structure elements.

[0097] Step S302, construct the database structure elements into a database query statement through a preset database syntax set.

[0098] It should be noted that the database syntax set is a set of rules and syntax specifications followed by a database system for writing query statements that can be understood and executed by the database. It includes some common elements, such as keywords like SELECT, FROM, WHERE, ORDER BY, as well as various functions, operators, and data types.

[0099] It can be understood that constructing into a database query statement can be generated through a generator. The generator internally implements comprehensive support for various SQL syntax structures, including but not limited to: supporting basic single-table queries, being able to handle various filtering conditions, sorting requirements, and operations to limit the number of returned records; supporting multiple multi-table join query methods, being able to handle cross-table queries to obtain related data; supporting aggregate functions, being able to perform statistics and summaries on data; as well as subqueries and nested queries, conditional expressions, and functions. Based on these syntaxes, the system can implement more complex query logics, enhancing the flexibility and expressiveness of queries.

[0100] Furthermore, in order to improve the quality of the query statement, reduce the query failure cases caused by syntax errors or unclear logic, and enhance the stability and reliability of the system. The step S302 may include:

[0101] Extract column information, reference information, and operator types related to the database structure from the database structure elements through a phrase-column linking function; generate an inter-table connection path based on the column information and reference information; generate a database query statement according to the database syntax set with the operator type and the inter-table connection path.

[0102] It should be understood that the phrase-column linking function is a function for establishing a mapping relationship between natural language phrases and database columns, and can extract content such as column information, reference information, and operator types related to natural language expressions from database structure elements. Column information refers to the content related to columns (fields) in a database table, including column names, data types of columns, etc. Reference information involves the association relationship information between tables. The inter-table connection path is the connection order and method determined according to the reference information between tables, and describes the association path from one table to another.

[0103] Specifically, for the input target question or related natural language description, the phrase-column linking function analyzes the database structure elements. For example, for "query the customer names and order amounts of customers who have purchased electronic products", the function will identify that "customer name" is the column information in the "customer table", "order amount" is the column information in the "order table", "have purchased" may involve the association relationship (reference information) between tables, "electronic products" may be related to a certain column (such as "product category") in the "product table", and at the same time, it will also determine the possible operator types, such as "=" (used to determine that the product category is equal to electronic products), "AND" (used to connect multiple conditions), etc. Based on the extracted reference information, determine the connection order and method between tables, generate an inter-table connection path, such as customer table - order table - product table (connected through customer ID and product ID). Finally, according to the database syntax set, combine the extracted operator type and the generated inter-table connection path to construct a query statement.

[0104] In this embodiment, if the target question is a data query task, determine the database structure elements corresponding to the key elements; construct the database structure elements into a database query statement through a preset database syntax set. By parsing the metadata table of the database, including library usage, table usage, field explanations, value ranges, and inter-table association relationships, accurately parse and locate specific databases, data tables, fields, and associated tables according to the user's question, realizing seamless conversion between natural language queries and SQL query statements, and providing users with an efficient and intelligent query experience.

[0105] Refer to Figure 6 , Figure 6 FIG.

[0106] In the fourth embodiment, step S40 includes:

[0107] Step S401: Execute the database query statement through the database connection interface to obtain an execution result.

[0108] It can be understood that the execution result can be a result set containing multi-row and multi-column data (such as the result of querying customer information), or a simple success or failure status information (such as the feedback after performing an update operation).

[0109] Step S402: If the execution result is successful, optimize the query result of the database query statement, and display the optimized query result to the requesting user in a preset format.

[0110] It can be understood that optimizing the query result of the database query statement can include data format processing, duplicate data processing, sorting adjustment, etc. The preset format can include tables, charts, text paragraphs, etc.

[0111] In one example, referring to Figure 7 and Figure 8 , Figure 7 is a schematic diagram of the graphical representation of the execution result of the database Q&A method of the present application, Figure 8 is a schematic diagram of the table of the execution result of the database Q&A method of the present application. For the target question "Count how many devices there are for different control methods" input by the user, the system counts and displays the number of devices for different control methods. By parsing the target question through semantic mapping, the target data table (TABLE: ['equipment_info']) and the corresponding data query statement (SQL: SELECT control_mode, COUNT(*) AS 'number of devices' FROM equipment_info GROUP BY control_mode;) are given. The statement means that from the 'equipment_info' table, grouping is performed according to the 'control_mode' field (GROUP BY control_mode), and the COUNT() function is used to count the number of records in each group, and the statistical result is named 'number of devices' (AS number of devices). Finally, it is displayed in different ways, and the display methods include images, tables, and JSON. Figure 7 Display through a chart, Figure 8 Count the devices with different control methods through a table. The data shows that there are 3 main control methods. Among them, there are 2 devices with button control, 3 devices with group control, and 246 devices with collective selective control.

[0112] Further, in order to gradually improve the understanding and processing capabilities of user questions and make subsequent question judgment and query statement generation more accurate and efficient. After step S402, the following steps are further included:

[0113] Receiving the feedback information of the requesting user, and generating a target label corresponding to the target question according to the feedback information and the key elements; updating the question guiding label according to the target label.

[0114] It should be understood that when updating the question guiding label according to the target label, the newly generated target label is compared and integrated with the existing question guiding label. If the target label is very similar to an existing question guiding label, the existing label can be updated and improved to make it more general and accurate; if the target label is a new type of question and there is no similar question guiding label before, it is added to the question guiding label set. The update process can be carried out regularly or in batches after accumulating a certain number of new target labels to ensure that the question guiding label can timely reflect the changes in user needs and common question patterns.

[0115] Step S403, if the execution result is a failure, return to the step of generating the database query statement corresponding to the target question, and when the number of executions reaches the preset failure threshold, feedback the error prompt information to the requesting user.

[0116] It can be understood that when the SQL query execution fails or the query intention of the user cannot be fully understood, the result feedback module will start the multi-round dialogue function. By asking questions, the module will guide the user to provide more information or clarify the query intention. For example, if the query conditions input by the user are too vague or ambiguous, the module will ask the user for specific filtering conditions or requirement details. Through the interactive method of multi-round dialogue, the module can gradually clarify the user's query requirements and generate an accurate SQL query statement.

[0117] In this embodiment, the database query statement is executed through the database connection interface to obtain the execution result; if the execution result is a success, the query result of the database query statement is optimized, and the optimized query result is displayed to the requesting user in a preset format; if the execution result is a failure, return to the step of generating the database query statement corresponding to the target question, and when the number of executions reaches the preset failure threshold, feedback the error prompt information to the requesting user. By executing the query statement through the database connection interface and processing the result, a complete data query and feedback process is realized. For the cases of successful execution and failed execution, corresponding responses are made to improve the user experience.

[0118] Exemplarily, to facilitate understanding of the implementation process of the database question-answering method obtained by combining the above-described Embodiment 1 with this embodiment, please refer to Figure 9 , Figure 9 which is a schematic diagram of the brief process of a database question-answering method. Specifically: for a user question, first, intention recognition is performed through the semantic layer configuration information of the database data source and the question guiding tags in the historical conversation to determine whether it is a data processing task. If not, the result is directly fed back; otherwise, the data table is searched according to the user question to determine whether there is a relevant data source. If not, the result is fed back. If so, a corresponding SQL statement is generated. Then the SQL statement is executed. When the SQL query execution fails, the execution engine will automatically attempt to re-execute the query, with a maximum of three retries (retry <= 3). If it still fails after three retries, the process ends, and relevant information such as query failure may need to be fed back to the user. If the SQL execution is successful and the returned result can be visualized (for example, the data is suitable for display in a chart), a chart configuration (such as echart) is generated for display to present the data to the user in a more intuitive way. If the result is not suitable for visualization, it directly enters the "result feedback" link. Finally, the query result is fed back to the user in a suitable form (which may be a table, text, or other form) to complete the entire process, enabling the user to obtain the information they need.

[0119] It should be noted that the above example is only for understanding this application and does not constitute a limitation on the database question-answering method of this application. Based on this technical concept, more forms of simple transformations are within the protection scope of this application.

[0120] This application also provides a database question-answering device. Please refer to Figure 10 , and the database question-answering device includes:

[0121] A question parsing module 10, configured to receive the target question input by the requesting user and extract the key elements in the target question based on a preset language model;

[0122] A semantic mapping module 20, configured to match the key elements according to the semantic configuration information of the database and the question guiding tags in the historical conversation to determine whether the target question is a data query task;

[0123] A statement generation module 30, configured to generate a database query statement corresponding to the target question if the target question is a data query task;

[0124] A result display module 40, configured to execute the database query statement and reply to the target question according to the execution result.

[0125] The database question-answering device provided by this application adopts the database question-answering method in the above embodiment, and can solve the technical problem of relying on a large amount of labeled data in the prior art. Compared with the prior art, the beneficial effects of the database question-answering device provided by this application are the same as those of the database question-answering method provided by the above embodiment, and other technical features in the database question-answering device are the same as those disclosed in the method of the above embodiment, which will not be elaborated here.

[0126] This application provides a database question-answering device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein, the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the database question-answering method in the first embodiment above.

[0127] Refer to the following Figure 11 , which shows a schematic structural diagram of a database question-answering device suitable for implementing the embodiments of this application. The database question-answering device in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 11 The database question-answering device shown is only an example, and should not impose any limitations on the functions and usage scope of the embodiments of this application.

[0128] As shown in Figure 11As shown, the database Q&A device may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM: Read Only Memory) 1002 or the program loaded from the storage device 1003 into the random access memory (RAM: Random Access Memory) 1004. In the RAM 1004, various programs and data required for the operation of the database Q&A device are also stored. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. The input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the database Q&A device to communicate with other devices wirelessly or wiredly to exchange data. Although the figure shows a database Q&A device having various systems, it should be understood that it is not required to implement or have all the systems shown. Instead, more or fewer systems can be implemented or had.

[0129] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program codes for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device, or installed from the storage device 1003, or installed from the ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the methods of the embodiments disclosed in the present application are executed.

[0130] The database Q&A device provided by the present application adopts the database Q&A method in the above-mentioned embodiments, and can solve the technical problem of the dependence on a large amount of labeled data in the prior art. Compared with the prior art, the beneficial effects of the database Q&A device provided by the present application are the same as those of the database Q&A method provided by the above-mentioned embodiments, and the other technical features in this database Q&A device are the same as the features disclosed in the method of the previous embodiment, and will not be elaborated here.

[0131] It should be understood that each part disclosed in this application can be implemented by hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in a suitable manner in any one or more embodiments or examples.

[0132] As described above, the above is only the specific implementation manner of this application, but the protection scope of this application is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed in this application, and all should be covered by the protection scope of this application. Therefore, the protection scope of this application should be subject to the protection scope of the claims.

[0133] This application provides a computer-readable storage medium with computer-readable program instructions (i.e., computer programs) stored thereon, and the computer-readable program instructions are used to execute the database Q&A method in the above embodiments.

[0134] The computer-readable storage medium provided by this application can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination of the above. More specific examples of computer-readable storage media can include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM) or flash memory, optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the above. In this embodiment, the computer-readable storage medium can be any tangible medium that contains or stores a program, and this program can be used by or combined with an instruction execution system, device, or device. The program code contained on the computer-readable storage medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0135] The above computer-readable storage medium can be included in the database Q&A device; it can also exist separately without being assembled into the database Q&A device.

[0136] The above computer-readable storage medium carries one or more programs. When the above one or more programs are executed by the database Q&A device, the database Q&A device is caused to execute the database Q&A method described above.

[0137] Computer program code for performing the operations of this application can be written in one or more programming languages or combinations thereof. The above-mentioned programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also include conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, executed as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computer (for example, by using an Internet service provider to connect through the Internet).

[0138] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and this module, program segment, or part of the code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks can occur in a different order than that marked in the accompanying drawings. For example, two consecutively represented blocks can actually be executed substantially in parallel, and they can sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, as well as the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for performing the specified functions or operations, or can be implemented by a combination of dedicated hardware and computer instructions.

[0139] The modules involved in the embodiments described in this application can be implemented in software or in hardware. Among them, the name of the module does not constitute a limitation to the unit itself in some cases.

[0140] The readable storage medium provided in this application is a computer-readable storage medium. The computer-readable storage medium stores computer-readable program instructions (i.e., computer programs) for performing the above-mentioned database Q&A method, and can solve the technical problem of relying on a large amount of labeled data in the prior art. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the database Q&A method provided in the above embodiments, and will not be elaborated here.

[0141] The present application also provides a computer program product, including a computer program which, when executed by a processor, implements the steps of the database question-answering method as described above.

[0142] The computer program product provided by the present application can solve the technical problem of the dependence on a large amount of labeled data in the prior art. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as those of the database question-answering method provided by the above embodiments, and will not be elaborated herein.

[0143] The above are only partial embodiments of the present application, and thus do not limit the patent scope of the present application. Any equivalent structural transformation made by using the content of the specification and drawings of the present application under the technical concept of the present application, or any direct / indirect application in other related technical fields is included in the patent protection scope of the present application.

Claims

1. A database question-answering method, characterized in that: The database question-answering method comprises: Receive a target question input by a requesting user, and extract key elements of the target question based on a preset language model; Matching the key elements according to the semantic configuration information of the database and the question guidance tags in the historical dialogue to determine whether the target question is a data query task; If the target problem is a data query task, then generate a database query statement corresponding to the target problem; Execute the database query statement and respond to the target question based on the execution result.

2. The database question-answering method according to claim 1, characterized in that: The step of matching the key elements according to the semantic configuration information of the database and the question guidance tags in the historical dialogue to determine whether the target question is a data query task includes: Building a database semantic index based on the semantic configuration information of the database, wherein the semantic configuration information includes library table function information, field explanation, value range information and inter-table association information; Retrieving the key element based on the database semantic index to obtain a first matching result; Calculating the text similarity between the question guide tag in the historical conversation and the key element, and determining a second matching result according to the text similarity; It is determined whether the target question is a data query task according to the first matching result and the second matching result.

3. The database question-answering method according to claim 1, characterized in that: If the target problem is a data query task, the step of generating a database query statement corresponding to the target problem includes: If the target problem is a data query task, determining a database structure element corresponding to the key element; The database structure elements are constructed into database query statements through a preset database grammar set.

4. The database question-answering method according to claim 3, characterized in that: The step of constructing the database structure elements into database query statements by using a preset database grammar set includes: Extracting column information, reference information and operator type related to the database structure in the database structure element through a phrase-column link function; Generate a connection path between tables based on the column information and the reference information; Generate a database query statement based on the operator type and the inter-table connection path according to a database syntax set.

5. The database question-answering method according to claim 1, characterized in that: The step of executing the database query statement and responding to the target question according to the execution result includes: Execute the database query statement through the database connection interface to obtain the execution result; If the execution result is successful, the query result of the database query statement is optimized, and the optimized query result is displayed to the requesting user in a preset format; If the execution result is an execution failure, the process returns to the step of generating a database query statement corresponding to the target question, and when the number of executions reaches a preset failure threshold, an error prompt message is fed back to the requesting user.

6. The database question-answering method according to claim 5, characterized in that: If the execution result is successful, the query result of the database query statement is optimized, and the optimized query result is displayed to the requesting user in a preset format, and further includes: Receive feedback information from the requesting user, and generate a target tag corresponding to the target question according to the feedback information and the key elements; The question guidance tag is updated according to the target tag.

7. A database question-answering device, characterized in that: The device comprises: A question parsing module, used to receive a target question input by a requesting user, and extract key elements of the target question based on a preset language model; A semantic mapping module is used to match the key elements according to the semantic configuration information of the database and the question guidance tags in the historical dialogue to determine whether the target question is a data query task; A statement generation module, used for generating a database query statement corresponding to the target problem if the target problem is a data query task; The result display module is used to execute the database query statement and respond to the target question according to the execution result.

8. A database question-answering device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the database question-answering method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the database question-and-answer method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the database question-answering method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • LLM-driven data query dependency retrieval method and device, equipment and medium

    CN121327192A