Database question and answer method, system and equipment based on large language model and medium

Through the database question and answer method based on the large language model, user questions are rewritten and combined with human-computer interaction information to generate SQL statements and recall data tables and fields. This solves the accuracy and flexibility problems in complex business scenarios in the existing technology and achieves high efficiency. , accurate data recall and question and answer processing.

CN118733747AInactive Publication Date: 2024-10-01金现代信息产业股份有限公司

Patent Information

Application Number
CN202411223100.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-03
Publication Date
2024-10-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Existing database question-and-answer technology is difficult to achieve high accuracy and flexibility when dealing with complex business scenarios. In particular, it cannot effectively identify and process fields that are easily confused or repeated, resulting in a low accuracy of question-and-answer and cannot be effectively implemented in actual business. .

Method used

Using a database question-and-answer method based on a large language model, user questions are rewritten through preset strategies, and user interaction information is introduced in conjunction with human-computer interaction strategies to generate relevant SQL statements and recall data tables and fields using vector representation and similarity calculations. And make up for the lack of semantic recall through forced recall of the dictionary.

Benefits of technology

It improves the accuracy and flexibility of SQL statement generation, improves the efficiency of question and answer processing, can effectively respond to question requirements in different scenarios, and ensures the accuracy and completeness of data recall.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733747A_ABST
    Figure CN118733747A_ABST
Patent Text Reader

Abstract

The invention provides a database question-answering method, system and device based on a large language model and a medium, and belongs to the technical field of database access. According to the scheme, user questions are rewritten through a preset strategy, SQL statements corresponding to the user questions are generated on the basis of the rewritten user questions in combination with the large language model, and the SQL statements are used for questioning and answering the user questions. The accuracy and the flexibility of SQL statement generation are effectively ensured; meanwhile, according to the scheme, based on a man-machine interaction strategy, user interaction information is introduced in the SQL statement generation process, a user configures a data table and a field related to the current application scene, on one hand, the question and answer processing efficiency can be improved, and on the other hand, the question requirements in different scenes can be effectively met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of database access, and in particular, relates to a database question-answering method, system, device and medium based on a large language model. Background Art

[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.

[0003] With the development of deep learning technology and large language model technology, it has gradually become possible to convert natural language descriptions into SQL (Structured Query Language). However, the inventors have found that actual business scenarios often involve rich business knowledge, and existing database question-answering technical solutions often cannot achieve a high question-answering accuracy and cannot be implemented in actual business. For example, traditional methods usually match questions with SQL based on rule matching methods, which have low accuracy and are inflexible, and cannot perform database question-answering in unconstrained application scenarios; secondly, patent CN115408506A proposes a NL2SQL (Natural Language to SQL) method that combines semantic parsing and semantic component matching. However, this method only makes matching predictions for aggregate function types, operator types, and column fields, and does not comprehensively analyze semantic information to identify the target table, so it is difficult to handle confusing or repeated fields that exist in actual production. Summary of the invention

[0004] In order to solve the above problems, the present invention provides a database question and answer method, system, device and medium based on a large language model. The scheme rewrites user questions through a preset strategy, and generates SQL statements corresponding to user questions based on the rewritten user questions in combination with a large language model, thereby effectively ensuring the accuracy and flexibility of SQL statement generation. At the same time, the scheme is based on a human-computer interaction strategy, and introduces user interaction information in the process of SQL statement generation. The user configures data tables and fields related to the current application scenario, which can improve the efficiency of question and answer processing on the one hand, and effectively respond to problem requirements in different scenarios on the other hand.

[0005] According to a first aspect of an embodiment of the present invention, a database question answering method based on a large language model is provided, comprising: Receive user questions; Based on the business vocabulary in the user's question and in combination with the pre-built parameter configuration table, the extended question recall field information is obtained, and the user's question is rewritten based on the obtained extended question recall field information; Based on the vector representation of the rewritten user question, combined with the table description vector and field description vector related to the current application scenario in the database, the data table and corresponding fields are recalled according to the similarity calculation results; Generate a database schema corresponding to the user question based on the recalled data tables and fields; use the rewritten user question and its corresponding database schema as input to the pre-trained large language model to obtain the corresponding SQL statement; Perform a database query based on the SQL statement, obtain the query result, and implement database question and answer.

[0006] Furthermore, the acquisition of the table description vector and the field description vector related to the current application scenario is specifically as follows: for the data tables and fields in the database, through a human-computer interactive strategy, the user selects the required data tables and related fields according to the current application scenario; and, a text description of the purpose of the selected data tables and related fields is configured, and the text description of the data tables and related fields is vectorized to obtain the table description vector and the field description vector.

[0007] Furthermore, the recall of data tables and corresponding fields based on similarity calculation results is specifically as follows: multiplying the vector representation of the rewritten user question with the table description vector to obtain the data table similarity calculation result, and obtaining the required data table name based on the obtained similarity calculation result; and multiplying the vector representation of the rewritten user question with the field description vector to obtain the field similarity result, and obtaining the required field name based on the obtained similarity calculation result; based on the obtained data table name and field name, recalling the data table and corresponding fields.

[0008] Furthermore, the recall of data tables and corresponding fields also includes the forced recall of data tables and fields, specifically: for the rewritten user questions, query whether there are words in the preset forced recall table dictionary or the preset forced recall field dictionary in the user questions. If so, recall the data tables or fields corresponding to the words in the forced recall table dictionary or the forced recall field dictionary; and recall the primary key of the data table.

[0009] Furthermore, the large language model adopts ChatGLM or Qwen model.

[0010] Furthermore, the parameter configuration table is pre-constructed by the user based on the current application scenario, and the parameter configuration table stores the extended question recall field information corresponding to the relevant business vocabulary in the current application scenario.

[0011] Furthermore, the user question is rewritten based on the obtained extended question recall field information, specifically: the obtained extended question recall field information is appended after the user question.

[0012] According to a second aspect of an embodiment of the present invention, a database question answering system based on a large language model is provided, comprising: A question receiving unit, which is used to receive questions raised by users; A question rewriting unit, which is used to obtain extended question recall field information based on the business vocabulary in the user question and in combination with a pre-built parameter configuration table, and rewrite the user question based on the obtained extended question recall field information; A recall unit is used to recall data tables and corresponding fields based on the vector representation of the rewritten user question and the table description vector and field description vector related to the current application scenario in the database according to the similarity calculation result; An SQL statement generation unit is used to generate a database model corresponding to the user question based on the recalled data tables and fields; the rewritten user question and its corresponding database model are used as inputs of the pre-trained large language model to obtain the corresponding SQL statement; The result query unit is used to perform a database query based on the SQL statement, obtain the query result, and implement database question and answer.

[0013] According to a third aspect of an embodiment of the present disclosure, there is provided an electronic device, comprising a memory, a processor, and a computer program stored and running on the memory, wherein when the processor executes the program, the database question-answering method based on a large language model is implemented.

[0014] According to a fourth aspect of an embodiment of the present disclosure, a non-transitory computer-readable storage medium is provided, on which a computer program is stored, and when the program is executed by a processor, the database question-answering method based on a large language model is implemented.

[0015] One or more of the above technical solutions have the following beneficial effects: The present invention provides a database question-answering method, system, device and medium based on a large language model. The scheme rewrites user questions through a preset strategy, generates SQL statements corresponding to the user questions based on the rewritten user questions and in combination with the large language model, and effectively ensures the accuracy and flexibility of SQL statement generation; at the same time, the scheme introduces user interaction information in the process of SQL statement generation based on a human-computer interaction strategy, and the user configures the data tables and fields related to the current application scenario, which can improve the efficiency of question-answering processing on the one hand, and effectively respond to the problem requirements in different scenarios on the other hand. (2) Considering that in the process of data query and processing, for complex business scenarios, the recall of tables and fields based solely on semantic similarity may not be fully covered, resulting in missed recalls; based on the above problem, the scheme of the present invention proposes a method for constructing a mandatory recall table dictionary and a mandatory recall field dictionary to make up for the shortcomings of semantic recall, that is, by flexibly configuring the mandatory recall parameter file, to adapt to different scenario business requirements and achieve efficient and accurate data recall.

[0016] Advantages of additional aspects of the present invention will be given in part in the following description, and in part will become obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.

[0018] Figure 1 The present invention is a flowchart of a database question-answering method based on a large language model described in an embodiment of the present invention. DETAILED DESCRIPTION

[0019] It should be noted that the following detailed descriptions are exemplary and are intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.

[0020] It should be noted that the terms used herein are for describing specific embodiments only and are not intended to be limiting of exemplary embodiments according to the present invention.

[0021] In the absence of conflict, the embodiments of the present invention and the features of the embodiments may be combined with each other.

[0022] Terminology explanation: LLM: Large Language Model.

[0023] NL2SQL: Convert natural language to SQL statements.

[0024] NLP: Abbreviation for Natural Language Processing.

[0025] Code table: A table in a database that explains the meaning of character codes, similar to a data dictionary. For example, a gender code table uses a mapping relationship such as "1" for "male" and "2" for "female".

[0026] Prompt: Give the large language model the context of the input information to help the model better understand the task and generate corresponding output results.

[0027] Bert model: A Transformer-based deep bidirectional encoding representation model that learns language representation by pre-training on a large amount of text data and demonstrates excellent performance in various natural language processing tasks.

[0028] Embodiment 1: The purpose of this embodiment is to provide a database question answering method based on a large language model.

[0029] First, before executing the method described in this embodiment, it is necessary to perform table data management in the database in advance, specifically: In the database table structure of different scenarios, there are often many redundant tables and fields. Therefore, for the tables exported from the database, it is necessary to remove useless tables and fields according to the actual intelligent question-answering application scenario; at the same time, in order to clearly understand the purpose of each table and field, they need to be described and explained in natural language.

[0030] In addition, it is necessary to construct a code table in advance to correspond the meaning of the field with the actual code stored in the database field. Finally, use the semantic vector module to construct useful tables and fields into word vectors for storage.

[0031] This step mainly performs the following processing: 1) Delete useless tables and fields: After exporting the tables related to the application scenario in the database, delete the useless fields in each table. In other words, the fields that will not be used in the questions asked in the question-and-answer scenario need to be deleted.

[0032] This process is implemented through a human-computer interactive strategy. Specifically, after the database is linked through the front-end interface, the user selects the tables and fields actually used to export the tables and fields related to the application scenario.

[0033] 2) Table description and field description: Provide a textual description and explanation of the purpose of each table and field. For example, the description of the "Student_Infor" table is "student information table, mainly including basic student information, family relationships, etc."; similarly, the description of the "Name" field in the table is "student's name", and the description of the "Sex" field in the table is "student's gender". If the "Sex" column in the database stores "0" and "1", then a code table needs to be constructed, such as {0: male, 1: female}, in order to associate the gender in the user's question with the actual content stored in the table.

[0034] 3) Vectorized representation of table and field descriptions: Use the SentenceTransformers library to represent table descriptions and fields described in natural language as 1024-dimensional feature vectors.

[0035] Finally, suppose there is a table called "Student_Infor" with 10 fields, namely [ID, student number, name, gender, date of birth, ID number, home address, parents' names, class, contact information]; and a table called "Student_score" with 5 fields, namely [ID, total score, Chinese score, math score, English score]. Then the description vectors V_table of the two tables will be obtained, with a size of [2×1024], and the field description vectors V_field of the two tables will be of sizes [10×1024] and [5×1024] respectively.

[0036] Based on the above processed database, a database question answering method based on a large language model proposed in this embodiment is executed, such as Figure 1 As shown, the specific process includes the following: Step 1: Receive user questions; Step 2: Based on the business vocabulary in the user's question and the pre-built parameter configuration table, obtain the extended question recall field information; In a specific implementation, the parameter configuration table is pre-constructed by a user based on a current application scenario, and the parameter configuration table stores extended question recall field information corresponding to relevant business vocabulary in the current application scenario.

[0037] Step 3: Rewrite the user question based on the obtained extended question recall field information; In a specific implementation, the user question is rewritten based on the obtained extended question recall field information, specifically: the obtained extended question recall field information is appended after the user question.

[0038] Specifically, the problem is rewritten, and specifically includes the following processing procedures: Since the question may contain overly complex business scenario vocabulary or business scenarios, the original question cannot accurately recall the required fields based on similarity, so the question needs to be rewritten and expanded to accurately recall the required fields.

[0039] For the business vocabulary in the question, based on the pre-built parameter configuration table, the extended question recall field information corresponding to the business vocabulary is obtained, and the question is rewritten based on the obtained extended question recall field information; For example, in question Q1 = "How many students are from other provinces this year?", the word "other provinces" is a business vocabulary, and the required "ID number" field cannot be recalled. Therefore, it is necessary to read the extended question recall field information in the parameter configuration table, construct a business dictionary such as {"Recall the candidate's ID number and home address.": [province, city, county, district]}, and rewrite the question according to the business dictionary to Q1_e = "How many students' home addresses are from other provinces this year? Recall the candidate's home address and ID number.". Note that the parameter configuration table is manually constructed and needs to be maintained during the early research and testing, and is no longer maintained when it is officially used later.

[0040] Problem vector representation: Vectorize the rewritten problem Q1_e to obtain V_Q1e, whose size is [1×1024].

[0041] Step 4: Based on the vector representation of the rewritten user question, combined with the table description vector and field description vector related to the current application scenario in the database, the data table and corresponding fields are recalled according to the similarity calculation results; Among them, the acquisition of the table description vector and field description vector related to the current application scenario is specifically as follows: for the data tables and fields in the database, through a human-computer interactive strategy, the user selects the required data tables and related fields according to the current application scenario; and, a text description of the purpose of the selected data tables and related fields is configured, and the text description of the data tables and related fields is vectorized to obtain the table description vector and the field description vector.

[0042] The recalling of the data table and the corresponding fields according to the similarity calculation result is specifically as follows: multiplying the vector representation of the rewritten user question with the table description vector to obtain the data table similarity calculation result, and obtaining the required data table name based on the obtained similarity calculation result; and multiplying the vector representation of the rewritten user question with the field description vector to obtain the field similarity result, and obtaining the required field name based on the obtained similarity calculation result; based on the obtained data table name and field name, recalling the data table and the corresponding fields.

[0043] The recall of data tables and corresponding fields also includes the forced recall of data tables and fields, specifically: for the rewritten user questions, check whether there are words in the preset forced recall table dictionary or the preset forced recall field dictionary in the user questions. If so, recall the data tables or fields corresponding to the words in the forced recall table dictionary or the forced recall field dictionary; and recall the primary key of the data table.

[0044] Specifically, the recall of data tables and corresponding fields includes the following processing: Similarity recall of tables and fields: Using the cosine similarity algorithm, multiply the transposed matrix of the rewritten question vector V_Q1e and the table description vector V_table to obtain the similarity result Sim_QT, whose size is [1×2]. Delete the results less than the threshold T from Sim_QT, and finally get the table name RSim_table = ["Student_score"] similar to question Q1. Similarly, multiply the rewritten question vector V_Q1e and the field description vector V_field in the "Student_score" table to get the field similarity result, and finally get the qualified field RSim_field = [home address, ID number].

[0045] Mandatory recall of tables and fields: During data query and processing, for complex business scenarios, simply relying on semantic similarity to recall tables and fields may not be able to fully cover them, resulting in missed recalls.

[0046] Based on the above problems, the solution described in this embodiment proposes a method for constructing a forced recall table dictionary and a forced recall field dictionary to make up for the shortcomings of semantic recall, that is, by flexibly configuring the forced recall parameter file, it can adapt to different scenario business needs and achieve efficient and accurate data recall.

[0047] Specifically, when processing a query request, if the query statement contains specific keywords, even if the semantic similarity between these keywords and the table and field is not high, the system will recall them according to the preset forced recall dictionary. For example, when querying question Q1 = "How many students are from other provinces this year?", as long as the keyword "student" appears, the "Student_score" table will be recalled, and the forced recall dictionary is as follows {"student_score": ["student"]}. Similarly, the forced recall field dictionary is as follows {"home address": ["outside province"]}, which means that as long as the keyword "outside province" appears in the question, the "home address" field will be recalled.

[0048] In addition, considering the importance of the primary key field in the data table, this embodiment also sets the primary key fields of all tables to be forced to be recalled to ensure the integrity of key information. Through this step, a table F_table = ["Student_score"] and a field F_field = ["ID", "Home Address"] containing all the tables that need to be forced to be recalled can be obtained, and the ID field is the primary key, providing accurate and comprehensive information for subsequent data query and processing.

[0049] Table and field merging: Finally, the similarity recall table RSim_table and field RSim_field are merged with the mandatory recall table F_table and field F_field, and duplicate values ​​are removed to obtain the final recalled table name R_table = ["Student_score"] and field R_field = [ID, gender, ID number, home address].

[0050] Step 5: Generate the database schema corresponding to the user question based on the recalled data tables and fields; Specifically, generating a database schema includes the following processing steps: According to the recalled tables and fields, rewrite the table name, table description, field name, field type, and code table dictionary into: format, where CREATE is the create command in SQL, TABLE is the data table in SQL, and tabel_name is the table name. " indicates a line break, description is the table description, and field_str is the field string.

[0051] For example: The database schema Database_schema for generating Q1 question is as follows: CREATE TABLE Student_Infor (-- Student information table, mainly including student basic information, family relationships, etc. ID VARCHAR2(46), --Primary key ID; Sex VARCHAR2(1), --gender code dictionary: {0: male, 1: female}; IdCard VARCHAR2(46), -- student ID number; HomeAddress VARCHAR2(100), -- student home address); Step 6: Use the rewritten user question and its corresponding database schema as input to the pre-trained large language model to obtain the corresponding SQL statement; The large language model may be a model such as ChatGLM or Qwen, or other existing large language models.

[0052] Specifically, the generation of SQL statements includes the following processing: This process mainly involves passing the rewritten questions and recalled table and field results into a large language model (such as SQLCoder, StarCoder), parsing and replacing the SQL statements returned by the large language model to adapt to the database type actually used in the business scenario.

[0053] This step mainly performs the following processing: 1) Synonym replacement: Replace different words in the question with more standard words in business scenarios that are easier for computers to understand. The purpose is to avoid the large model being unable to understand relatively professional or uncommon business words. Specifically, read the synonym table and construct a synonym dictionary, such as {"not Shandong Province": ["is another province", "is not from this province"]}, and then check whether there is a synonym that needs to be replaced in the question. If so, replace it with a synonym. Taking question Q1 as an example, replace the statement "is another province" with "is not from Shandong Province", so as to obtain a clearer question Q2 that is easier for computers to understand: "How many students are not from Shandong Province this year?".

[0054] 2) Question reasoning rewriting: SQL statements that are prone to reasoning errors in questions can be prompted by question rewriting. For words in questions that are prone to errors, the large language model is provided with clear and correct SQL writing methods, thereby improving the accuracy of its conversion into SQL statements.

[0055] Read the error-prone SQL vocabulary and construct an error-prone SQL dictionary, such as {"this year": "TO_CHAR(SYSDATE, 'yyyy')"}. In question Q2 = "Question: How many students this year are not from Shandong Province?", "this year" matches "this year" in the error-prone SQL dictionary, and "TO_CHAR(SYSDATE, 'yyyy')" and other information are appended to the question. By rewriting, question Q2 is rewritten as Q3 = "How many students this year are not from Shandong Province? Tip: The SQL writing of "this year" is TO_CHAR(SYSDATE, 'yyyy')". This rewriting not only retains the core information of the question, but also provides clear SQL writing guidance for the large model, which helps to improve the accuracy of the query results. Note that constructing an error-prone vocabulary requires manually configuring the error-prone parameter table information.

[0056] 3) Data encoding expansion in questions: In order to save storage space and improve data processing efficiency, databases are often designed using data mapping or data encoding. Therefore, when answering questions intelligently, the mapping relationship implicit in the question needs to be passed to the large model by rewriting the question.

[0057] Specifically, taking the question obtained in the previous step as an example, Q3 = "Hint: The SQL writing of "this year" is TO_CHAR(SYSDATE, 'yyyy'); Question: How many students are not from Shandong Province this year?", you can traverse the pre-constructed region code table, rewrite and prompt the "Shandong Province" in the question and the corresponding relationship "37" in the database, and get the rewritten question Q4 = "How many students are not from Shandong Province this year? Hint: The SQL writing of "this year" is TO_CHAR(SYSDATE, 'yyyy'), Hint: The region code of "Shandong Province" is "37", Question: How many students are not from Shandong Province this year?" 4) Entity rewriting: Identify the entity information in the question and tell the big model the entity information in the question to further improve the model accuracy. When identifying entities, use the fine-tuned Bert model as the entity recognition model, which can identify entities such as "date", "time", "place", "name", "amount", etc., and list the entity names and append them to the question.

[0058] Specifically, take question Q4 = "How many students are not from Shandong Province this year? Hint: The SQL writing of "this year" is TO_CHAR(SYSDATE, 'yyyy'), Hint: The region code of "Shandong Province" is "37", Question: How many students are not from Shandong Province this year?" as an example. In the question, "this year" is a time entity. Question Q4 can be rewritten to add entity information to obtain Q5 = "Hint: The SQL writing of "this year" is TO_CHAR(SYSDATE, 'yyyy'), Hint: The region code of "Shandong Province" is "37", Note: The time is "this year"; Question: How many students are not from Shandong Province this year?" 5) SQL statement generation and replacement: Finally, the rewritten question Q5 and the corresponding database schema Database_schema are combined into a prompt and passed into the large language model to obtain the SQL statement. According to the database type actually used in the business scenario (Oracle, MySql, SqlSever), the SQL statement is replaced according to the differences between different database syntaxes.

[0059] Step 7: Perform a database query based on the SQL statement, obtain the query result, and implement database question and answer.

[0060] In one or more implementations, the solution described in this embodiment also includes a result polishing processing step. This step is mainly to polish the result of the SQL query generated in the previous step to ensure that the answer result is more fluent and colloquial. Specifically, this step only polishes the query result that is a numerical value or a simple table. If a complex table is returned (i.e., a table with a number of rows greater than a preset threshold is considered a complex table), it is directly displayed without polishing or rewriting.

[0061] The main process of this step is as follows: 1) Determine the complexity of the answer result: Use the SQL generated in the previous step to query the database and return the query result. Determine the complexity of the answer result based on the rows and columns of the returned fields. If the query result is greater than 3 rows, the result is considered complex (i.e., a complex table); if the query result is less than 3 rows, the result is considered simple (i.e., a simple table); if there is no return value, it returns that no result was found; if the query statement reports an error, it returns a query error.

[0062] 2) Result polishing: If the query result is simple, then answer polishing is required. If it is not, then no polishing is required. Specifically, the question, query result number, query result, SQL statement, table field description, SQL execution, and notes are constructed into prompts and passed into the polishing model, and the polished result of the model is returned. The specific prompt construction paradigm is: "My question is: {question}, number of query results: {number of query results}, query result: {query result}, the table and field used in this question are: {schema}, the sql executed for the question is {sql}, note: {please carefully analyze the meaning of sql and related table fields, and explain the results and query conditions of this question in concise words! Do not repeat the question!}", If the query result is a table, the number of query results is the number of rows in the table, and the table is converted to json format. The schema is the database schema obtained above, and the content of the note can be modified according to the actual situation. The above prompt is passed to the polishing model (such as ChatGLM, Qwen, etc.), and the result returned is the polished answer.

[0063] Embodiment 2 The purpose of this embodiment is to provide a database question answering system based on a large language model.

[0064] A database question answering system based on a large language model, comprising: A question receiving unit, which is used to receive questions raised by users; A question rewriting unit is used to obtain extended question recall field information based on the business vocabulary in the user question and in combination with a pre-built parameter configuration table; and rewrite the user question based on the obtained extended question recall field information; A recall unit is used to recall data tables and corresponding fields based on the vector representation of the rewritten user question and the table description vector and field description vector related to the current application scenario in the database according to the similarity calculation result; An SQL statement generation unit is used to generate a database model corresponding to the user question based on the recalled data tables and fields; the rewritten user question and its corresponding database model are used as inputs of the pre-trained large language model to obtain the corresponding SQL statement; The result query unit is used to perform a database query based on the SQL statement, obtain the query result, and implement database question and answer.

[0065] Furthermore, the system described in this embodiment corresponds to the method described in Embodiment 1, and its technical details have been described in detail in Embodiment 1, so they will not be repeated here.

[0066] In more embodiments, there is also provided: An electronic device comprises a memory, a processor and a computer program stored and running on the memory, wherein the processor implements the database question-answering method based on a large language model when executing the program.

[0067] A non-transitory computer-readable storage medium stores a computer program, which, when executed by a processor, implements the database question-answering method based on a large language model.

[0068] Although the above describes the specific implementation mode of the present invention in conjunction with the accompanying drawings, it is not intended to limit the scope of protection of the present invention. Those skilled in the art should understand that various modifications or variations that can be made by those skilled in the art on the basis of the technical solution of the present invention without creative work are still within the scope of protection of the present invention.

Claims

1. A database question answering method based on a large language model, characterized in that: include: Receive user questions; Based on the business vocabulary in the user's question and in combination with the pre-built parameter configuration table, the extended question recall field information is obtained, and the user's question is rewritten based on the obtained extended question recall field information; Based on the vector representation of the rewritten user question, combined with the table description vector and field description vector related to the current application scenario in the database, the data table and corresponding fields are recalled according to the similarity calculation results; Generate a database schema corresponding to the user question based on the recalled data tables and fields; use the rewritten user question and its corresponding database schema as input to the pre-trained large language model to obtain the corresponding SQL statement; Perform a database query based on the SQL statement, obtain the query result, and implement database question and answer.

2. A database question answering method based on a large language model as claimed in claim 1, characterized in that: The acquisition of the table description vector and the field description vector related to the current application scenario is specifically as follows: for the data tables and fields in the database, through a human-computer interactive strategy, the user selects the required data tables and related fields according to the current application scenario; and, a text description is configured for the purpose of the selected data tables and related fields, and the text description of the data tables and related fields is vectorized to obtain the table description vector and the field description vector.

3. A database question answering method based on a large language model as claimed in claim 1, characterized in that: The recalling of the data table and the corresponding fields according to the similarity calculation result is specifically as follows: multiplying the vector representation of the rewritten user question with the table description vector to obtain the data table similarity calculation result, and obtaining the required data table name based on the obtained similarity calculation result; Furthermore, the vector representation of the rewritten user question is multiplied by the field description vector to obtain the field similarity result, and the required field name is obtained based on the obtained similarity calculation result; based on the obtained data table name and field name, the data table and the corresponding field are recalled.

4. A database question answering method based on a large language model as claimed in claim 1, characterized in that: The recall of data tables and corresponding fields also includes the forced recall of data tables and fields, specifically: for the rewritten user questions, check whether there are words in the preset forced recall table dictionary or the preset forced recall field dictionary in the user questions. If so, recall the data tables or fields corresponding to the words in the forced recall table dictionary or the forced recall field dictionary; and recall the primary key of the data table.

5. The database question answering method based on a large language model as claimed in claim 1, characterized in that: The large language model adopts ChatGLM or Qwen model.

6. A database question answering method based on a large language model as claimed in claim 1, characterized in that: The parameter configuration table is pre-constructed by a user based on the current application scenario, and the parameter configuration table stores extended question recall field information corresponding to relevant business vocabulary in the current application scenario.

7. A database question answering method based on a large language model as claimed in claim 1, characterized in that: The rewriting of the user question based on the obtained extended question recall field information is specifically: appending the obtained extended question recall field information after the user question.

8. A database question answering system based on a large language model, characterized in that: include: A question receiving unit, which is used to receive questions raised by users; A question rewriting unit, which is used to obtain extended question recall field information based on the business vocabulary in the user question and in combination with a pre-built parameter configuration table, and rewrite the user question based on the obtained extended question recall field information; A recall unit is used to recall data tables and corresponding fields based on the vector representation of the rewritten user question and the table description vector and field description vector related to the current application scenario in the database according to the similarity calculation result; An SQL statement generation unit is used to generate a database model corresponding to the user question based on the recalled data tables and fields; the rewritten user question and its corresponding database model are used as inputs of the pre-trained large language model to obtain the corresponding SQL statement; The result query unit is used to perform a database query based on the SQL statement, obtain the query result, and implement database question and answer.

9. An electronic device, characterized in that: It comprises a memory, a processor and a computer program stored and running on the memory, wherein the processor implements the database question-answering method based on a large language model when executing the program as described in any one of claims 1 to 7.

10. A non-transitory computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the program is executed by a processor, a database question-answering method based on a large language model as described in any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • NL2SQL method combining semantic analysis and semantic component matching

    CN115408506A

  • Database query statement generation method and device, equipment and storage medium

    CN118227655A

Cited By

  • Method for reducing natural language to generate complex SQL (Structured Query Language) by constructing table mode and converting SQL

    CN119271697A

  • Method to reduce complex SQL generated by natural language by building table mode and SQL conversion

    CN119271697B

  • Policy question and answer method, device and equipment based on large model and medium

    CN119513331A

  • Data analysis method and device, server and readable storage medium

    CN119903080A

  • Data intelligent interaction enhanced query method and system based on large model

    CN120162344A