Data query method based on natural language, related equipment and storage medium

By positioning and splitting the target business fields in natural language statements in the business system, recalling the corresponding field metadata from the document knowledge base, generating and executing database statements, the problem of mutual interference between knowledge base metadata is solved, and the accuracy of data query is improved.

CN119557325APending Publication Date: 2025-03-04KINGDEE SOFTWARE(CHINA) CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202411734534.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-27
Publication Date
2025-03-04

AI Technical Summary

Technical Problem

In the business system, the metadata of the data table corresponding to the multiple business scenarios stored in the knowledge base is easily interfering with each other, resulting in a low accuracy of recall, affecting the accuracy of generated SQL statements, and reducing the accuracy of data queries.

Method used

By obtaining the document knowledge base of natural language statements and pre-configured business documents, positioning the target business documents corresponding to the natural language statements and splitting the target business fields, recalling the field metadata of the target business fields from the document knowledge base corresponding to the target business documents, generating database statements based on these metadata, and querying them in the database.

Benefits of technology

It effectively avoids mutual interference of metadata, improves the accuracy of document knowledge base recall, improves the accuracy of database statements, and thus improves the accuracy of data query.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119557325A_ABST
    Figure CN119557325A_ABST
Patent Text Reader

Abstract

The embodiment of the invention discloses a data query method based on a natural language, related equipment and a storage medium, and is used for the field of language processing. In the method, based on a business scene to which a natural language statement belongs, a target business document corresponding to the natural language statement is positioned, and a target business field in the natural language statement is split; recalling field metadata of the target business field from a document knowledge base corresponding to the target business document; generating a database statement based on the field metadata of the target business field; the field metadata recalled from the receipt knowledge base is the field metadata of the business fields of the same business receipt in the business scene, mutual interference of the metadata is effectively avoided during receipt knowledge base recall, the accuracy of receipt knowledge base recall is improved, the accuracy of database statements is improved, and the accuracy of data query is improved. The method can be applied to various business systems, such as an enterprise resource planning (ERP) system, an enterprise management system, a manpower system and the like.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of natural language processing, and in particular to a natural language-based data query method, related equipment, and storage medium. Background Art

[0002] SQL (Structured Query Language) is a standardized programming language for managing and operating relational databases. SQL statements can be used to access and process data in the database. NL2SQL, also known as Text-to-SQL, is a technology that converts natural language statements entered by users into SQL statements that can be executed on relational databases; the goal is to generate SQL statements that accurately reflect user intentions and ensure that appropriate results are obtained after execution.

[0003] Currently, metadata of data tables in a database are often stored in a knowledge base, metadata associated with natural language sentences are found through knowledge base recall, SQL statements are generated based on the associated metadata, and data queries are performed using the SQL statements.

[0004] Various business systems, such as Enterprise Resource Planning (ERP) and enterprise management systems, involve a wide range of business scenarios, and the corresponding databases contain a large number of data tables corresponding to various business scenarios. At this time, the knowledge base stores metadata of data tables corresponding to multiple business scenarios. When recalling the knowledge base, the metadata are prone to interfere with each other, resulting in a low accuracy rate of knowledge base recall, affecting the accuracy of the generated SQL statements and reducing the accuracy of data queries. Summary of the invention

[0005] The embodiments of the present application provide a natural language-based data query method, related equipment, and storage medium, which can improve the accuracy of document knowledge base recall, improve the accuracy of database statements, and thus improve the accuracy of data query.

[0006] The present application provides a natural language-based data query method, including:

[0007] Acquire a natural language sentence and a document knowledge base of a pre-configured business document, wherein the document knowledge base includes: field metadata of a business field in the business document, and different document knowledge bases correspond to different business documents;

[0008] Based on the business scenario to which the natural language statement belongs, locating the target business document corresponding to the natural language statement, and splitting the target business fields in the natural language statement; there are multiple different business documents in the business scenario;

[0009] Recalling the field metadata of the target business field from the document knowledge base corresponding to the target business document;

[0010] Generate a database statement based on the field metadata of the target business field;

[0011] Data is queried in a corresponding database based on the database statement.

[0012] Furthermore, locating a target business document corresponding to the natural language statement based on the business scenario to which the natural language statement belongs includes:

[0013] Performing text retrieval on the natural language sentence based on a full-text search engine to determine relevant business scenarios of the natural language sentence;

[0014] The natural language sentence is semantically retrieved based on a large language model, the business scenario to which the natural language sentence belongs is determined from the relevant business scenarios, and a target business document corresponding to the natural language sentence is located from the business documents corresponding to the business scenario.

[0015] Furthermore, the splitting of the target business field in the natural language sentence includes:

[0016] The natural language sentence is split into business fields of the natural language in the target business document to obtain the target business fields.

[0017] Furthermore, obtaining a document knowledge base of pre-configured business documents includes:

[0018] Obtain database language information of business fields in business documents, natural language information of business fields, and database language information of data tables corresponding to business fields;

[0019] Assembling database language information of the business field, natural language information of the business field, and database language information of the data table corresponding to the business field into field metadata of the business field;

[0020] The field metadata of multiple business fields in the business document are stored in the same knowledge base to obtain the document knowledge base.

[0021] Furthermore, the field metadata of the business field in the document knowledge base also includes: a calculation method of a composite field;

[0022] After obtaining the pre-configured document knowledge base, it also includes:

[0023] Based on the business scenario to which the document knowledge base is applied, a calculation method of the composite field in the document knowledge base is maintained.

[0024] Furthermore, the field metadata of the target business field includes: database language information of the data table corresponding to the target business field;

[0025] The generating of SQL statements based on the field metadata of the target business field includes:

[0026] Based on the database language information of the data table corresponding to the target business field, querying the table relationship of the data table from the relational database;

[0027] A database statement is generated based on the field metadata of the target business field and the table relationship.

[0028] Furthermore, the generating of database statements based on the field metadata of the target business field and the table relationship includes:

[0029] Assembling the field metadata of the target business field, the natural language sentence and the table relationship into a prompt word;

[0030] The large language model is called to generate a database sentence based on the prompt word.

[0031] The embodiment of the present application discloses a data query device based on natural language, including:

[0032] An acquisition unit, used to acquire a natural language sentence and a document knowledge base of a pre-configured business document, wherein the document knowledge base includes: field metadata of a business field in the business document, and different document knowledge bases correspond to different business documents;

[0033] A positioning unit, configured to locate a target business document corresponding to the natural language statement based on the business scenario to which the natural language statement belongs, and split the target business field in the natural language statement; the business scenario has a plurality of different business documents;

[0034] A recall unit, used to recall the field metadata of the target business field from the document knowledge base corresponding to the target business document;

[0035] A generating unit, configured to generate a database statement based on the field metadata of the target business field;

[0036] A query unit is used to query data in a corresponding database based on the database statement.

[0037] The present application discloses an electronic device, including:

[0038] CPU, memory and input / output interface;

[0039] The memory is a short-term storage memory or a persistent storage memory;

[0040] The central processing unit is configured to communicate with the memory and execute instructions in the memory to perform the above method.

[0041] An embodiment of the present application discloses a computer-readable storage medium, including instructions. When the instructions are executed on a computer, the computer executes the method described above.

[0042] An embodiment of the present application discloses a computer program product including instructions or a computer program. When the computer program product is run on a computer, the computer is enabled to execute the method described above.

[0043] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:

[0044] In an embodiment of the present application, a natural language statement and a document knowledge base of a pre-configured business document are obtained, wherein the document knowledge base includes: field metadata of a business field in a business document, and different document knowledge bases correspond to different business documents; based on the business scenario to which the natural language statement belongs, a target business document corresponding to the natural language statement is located, and the target business field in the natural language statement is split; there are multiple different business documents in the business scenario; the field metadata of the target business field is recalled from the document knowledge base corresponding to the target business document; a database statement is generated based on the field metadata of the target business field; and data is queried in the corresponding database based on the database statement.

[0045] It can be seen that in the embodiment of the present application, the field metadata recalled from the document knowledge base is the field metadata of the business field of the same business document under the business scenario, which effectively avoids mutual interference of metadata when recalling the document knowledge base, can improve the accuracy of document knowledge base recall, improve the accuracy of database statements, and thus improve the accuracy of data query. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0047] Figure 1 A system architecture diagram disclosed in an embodiment of the present application;

[0048] Figure 2 A natural language-based data query flow chart disclosed in an embodiment of the present application;

[0049] Figure 3Another data query flow chart based on natural language disclosed in an embodiment of the present application;

[0050] Figure 4 A natural language-based data query interaction diagram disclosed in an embodiment of the present application;

[0051] Figure 5 A diagram of a data query device based on natural language disclosed in an embodiment of the present application;

[0052] Figure 6 A structural diagram of an electronic device disclosed in an embodiment of the present application. DETAILED DESCRIPTION

[0053] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.

[0054] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims and drawings of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0055] In the following description, similar expressions such as "a specific implementation" or "a specific example" are involved, which describe a subset of all possible embodiments, but it is understood that "a specific implementation" or "a specific example" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict. In the following description, the term multiple refers to at least two. The numerical value mentioned in this application reaches a threshold value (if any), which may include the case where the former is greater than the latter in some specific examples.

[0056] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.

[0057] To facilitate understanding and explanation, before further describing the embodiments of the present application in detail, the application scenarios of the present application will be briefly described.

[0058] Existing methods often convert natural language statements into database statements, such as Figure 1 The NL2SQL technology shown in the figure, the executor of NL2SQL is connected to the knowledge base and the database respectively; the metadata of the data table in the database is stored in the knowledge base, and the executor finds the metadata associated with the natural language statement by recalling the knowledge base, and generates an SQL (Structured Query Language) statement based on the associated metadata. The SQL statement is a database statement, so as to access the database through the SQL statement to perform data query.

[0059] Various business systems, such as Enterprise Resource Planning (ERP) systems and enterprise management systems, involve a wide range of business scenarios (business fields), and the corresponding databases contain data tables corresponding to a variety of business scenarios; for example, the ERP system contains business scenarios such as finance, sales, and supply chain, and each business scenario has a corresponding data table (hundreds of tables). There are multiple business scenarios in the ERP system, and the corresponding databases contain tens of thousands of data tables. At this time, the knowledge base stores metadata for data tables corresponding to a variety of business scenarios, and the metadata are prone to interfere with each other when the knowledge base is recalled. For example, when the natural language statement input by the user is a sales question, there are sales-related data tables in business scenarios such as finance, sales, and supply chain. The metadata of these data tables are prone to interfere with each other, resulting in a low accuracy rate in the knowledge base recall, affecting the accuracy of the generated database statements, and reducing the accuracy of data queries. Therefore, the embodiment of the present application provides a data query method based on natural language, which can improve the accuracy rate of document knowledge base recall, improve the accuracy of database statements, and improve the accuracy of data queries, such as Figure 2 As shown, the specific steps include:

[0060] 201. Obtain a natural language statement and a document knowledge base of a pre-configured business document.

[0061] In the embodiment of the present application, the natural language conversion device can obtain natural language sentences and a document knowledge base of pre-configured business documents. The natural language sentence is a language used by humans in daily life, such as Chinese, English, French, etc., and can be a natural language sentence input by a user for query or a natural language sentence obtained through a network connection, which is not limited here.

[0062] The document knowledge base includes: field metadata of business fields in business documents, and different document knowledge bases correspond to different business documents. It can be understood that there are multiple business scenarios in the business system, each business scenario has multiple different business documents, and different fields in the business documents need to use different data tables in the database of the business system; the field metadata is data used to describe field information, including information about the business field and information about the data table corresponding to the business field. In an embodiment of the present application, the field metadata of the business fields in the same business document are stored in the same document knowledge base, and each field metadata is stored as a knowledge point in the document knowledge base. Each business document in the business system corresponds to a document knowledge base, and the knowledge base of the business system includes multiple document knowledge bases.

[0063] 202. Based on the business scenario to which the natural language sentence belongs, locate the target business document corresponding to the natural language sentence, and split the target business fields in the natural language sentence.

[0064] After obtaining the natural language statement, the target business document corresponding to the natural language statement can be located based on the business scenario to which the natural language statement belongs, and the target business field in the natural language statement can be split. It can be understood that if there are multiple business scenarios in the business system, it is necessary to first locate the business scenario to which the natural language statement belongs, that is, locate the business field to which the natural language statement belongs; and if there are multiple business documents in the business scenario, it is necessary to further locate the target business document corresponding to the natural language statement in the business document corresponding to the business scenario to which the natural language statement belongs.

[0065] Next, the business-related natural language words in the natural language sentence are split into target business fields, which are multiple target business fields; it can be understood that the split target business fields are natural language information of business fields, such as natural language field descriptions (date, cost, product name, etc.).

[0066] 203. Recall the field metadata of the target business field from the document knowledge base corresponding to the target business document.

[0067] After locating the target business document corresponding to the natural language statement, the field metadata of the target business field can be recalled one by one from the document knowledge base corresponding to the target business document. It can be understood that the business system contains multiple document knowledge bases, and the corresponding document knowledge base can be found from the multiple document knowledge bases based on the located target business document. Then, the target business field can be sent to the corresponding document knowledge base, and the field metadata corresponding to the target business field can be recalled in the document knowledge base, that is, the target business field is RAG recalled, and the field information of the target business field and the associated data table information are recalled.

[0068] It can be seen that in the embodiment of the present application, the metadata of the data table corresponding to the knowledge base in the business system is reduced from the metadata of the data table corresponding to multiple business scenarios to the metadata of the data table corresponding to the business document under a single business scenario. At this time, the metadata of the corresponding data table in the knowledge base will be greatly reduced, which can effectively avoid mutual interference of data in the document knowledge base when recalling the knowledge base. At the same time, the maintenance cost of the document knowledge base can be reduced.

[0069] 204. Generate a database statement based on the field metadata of the target business field.

[0070] After obtaining the field metadata of the target business field, a database statement can be generated based on the field metadata of the target business field. It can be understood that, in general, generating a database statement requires field information of the field, information of the data table corresponding to the field, and table relationships of the data table, and the recalled field metadata of the target business field includes: field information of the target business field and information of the data table corresponding to the target business field. At this time, the table relationship of the data table can be found based on the information of the data table, and then the field metadata of the target business field and the table relationship can be used to generate a database statement.

[0071] It can be understood that the database statement is a statement used to access and process the database, and the database statement includes but is not limited to: SQL statement, CQL (Common Query Language) statement, and JPQL (Java Persistence query language) statement, etc.

[0072] 205. Query data in a corresponding database based on the database statement.

[0073] After obtaining the database statement, data can be queried in the corresponding database based on the database statement. For example, when the database statement is an SQL statement, the SQL statement can be used to query data in the SQL database to obtain the query result of the natural language statement; when the database statement is a JPQL statement, the JPQL statement can be used to query data in the Java database to obtain the query result of the natural language statement.

[0074] It can be seen that in the embodiment of the present application, the field metadata recalled from the document knowledge base is the field metadata of the business field of the same business document in the business scenario, which effectively avoids mutual interference of metadata when recalling the document knowledge base, can improve the accuracy of document knowledge base recall, improve the accuracy of database statements, and improve the accuracy of data query. It can be understood that this method can be applied to various business systems, such as enterprise resource planning systems, enterprise management systems, human resources systems, etc.

[0075] Furthermore, the following will combine Figure 3 The process of converting natural language statements into database statements in this application is described in detail, and the specific steps are as follows:

[0076] 301. Obtain a natural language statement and a document knowledge base of a pre-configured business document.

[0077] In an embodiment of the present application, obtaining a document knowledge base of a pre-configured business document specifically involves obtaining database language information of business fields in the business document, natural language information of business fields, and database language information of data tables corresponding to business fields. The database language information is a programming language used for database query and program design, which can be recognized by a computer. It is understandable that, based on the difference in the database statements to be converted, the corresponding database language information in the field metadata is also different; for example, when the database statement is an SQL statement, the database language information of the business field and the database language information of the data table corresponding to the business field are structured language information; when the database statement is a JPQL statement, the database language information of the business field and the database language information of the data table corresponding to the business field are Java language information.

[0078] Next, the database language information of the business field, the natural language information of the business field and the database language information of the data table corresponding to the business field can be assembled into the field metadata of the business field; the field metadata of multiple business fields in the business document are stored in the same knowledge base to obtain a document knowledge base.

[0079] The database language information of the business field may be the field name of the business field, the natural language information of the business field may be the field description of the business field, and the database language information of the data table corresponding to the business field may be the table alias of the data table. For example, when the database language information is structured language information, in the document knowledge base corresponding to the business document: sales delivery order, the structure of the field metadata of the business field is: table alias.field name, field description;

[0080] For example: SAL OUTSTOCKENTRY_F.FALLAMOUNT_LC, sales amount

[0081] SAL_OUTSTOCKENTRY_F.FCOSTAMOUNT_LC, cost

[0082] SAL_OUTSTOCKENTRY.FBASEUNITQTY, sales quantity

[0083] BD_MATERIAL_L.FNAME, product name

[0084] SAL_OUTSTOCK.FDATE, sales date

[0085] SAL_OUTSTOCKENTRY_F.FAMOUNT,amount;

[0086] Among them, SAL_OUTSTOCKENTRY_F is the table alias of the outbound order entry financial table, SAL_OUTSTOCKENTRY is the table alias of the outbound order detail table, BD_MATERIAL_L is the table alias of the material multilingual table, and SAL_OUTSTOCK is the table alias of the sales outbound table; the field metadata of each business field also has a corresponding field name and field description.

[0087] 302. Based on the business scenarios in which the document knowledge base is applied, maintain the calculation method of the composite fields in the document knowledge base.

[0088] It is understandable that the document knowledge base also includes: a calculation method for a composite field, which is obtained by calculating multiple business fields, such as sales profit = sales amount - sales cost, and the field metadata of the corresponding composite field is:

[0089] (SAL_OUTSTOCKENTRY_F.FALLAMOUNT_LC-SAL_UTSTOCKENTRY_F.FCOSTAMO UNT_LC), sales profit;

[0090] At this time, after obtaining the pre-configured document knowledge base, it is also possible to maintain the calculation method of the composite fields in the document knowledge base based on the business scenarios to which the document knowledge base is applied. That is, the document knowledge base configured in this application can be applied to a variety of business scenarios. When the business scenarios to which the document knowledge base is applied change, the calculation method of the composite fields can be maintained to adapt to the corresponding business scenarios; at this time, for complex business scenarios, the document knowledge base can be adapted to complex business scenarios by maintaining the calculation method of the composite fields; there is no need to re-acquire the field metadata of the business fields, effectively saving resource costs.

[0091] For example, when the composite field in the document knowledge base: Sales Profit is the total sales profit, the sales profit = (sales amount - sales cost) * sales quantity; the calculation method of the sales profit is maintained as follows:

[0092] (SAL_OUTSTOCKENTRY_F.FALLAMOUNT_LC-SAL_UTSTOCKENTRY_F.FCOSTAMO UNT_LC)*SAL_OUTSTOCKENTRY.FBASEUNITQTY, sales profit.

[0093] 303. Determine the business scenario to which the natural language sentence belongs from relevant business scenarios of the natural language sentence, and locate the target business document corresponding to the natural language sentence.

[0094] After obtaining the natural language sentence, the business scenario to which the natural language sentence belongs can be determined from the relevant business scenarios of the natural language sentence, and the target business document corresponding to the natural language sentence can be located. Specifically, the natural language sentence can be subjected to text retrieval based on the full-text search engine (ES, Elasticsearch) to determine the relevant business scenarios of the natural language sentence; the natural language sentence can be subjected to semantic retrieval based on the large language model (LLM, Large Language Model), the business scenario to which the natural language sentence belongs can be determined from the relevant business scenarios, and the target business document corresponding to the natural language sentence can be located from the business documents corresponding to the business scenarios. Among them, the full-text search engine is a system that can index and retrieve a large amount of text information on the Internet, and supports text search of natural language sentences; the full-text search engine can crawl web pages on the Internet, collect a large amount of text data, store the large amount of text data in the index library after processing, and build an index; when a query request is initiated, the index library is searched according to the keywords of the natural language sentence, and the relevant text information is found and returned.

[0095] like Figure 4 As shown, the data query device executes: step 401, obtains the natural language sentence input by the user: the top ten products in terms of sales cost this month; step 402, sends the natural language sentence to the full-text search engine; step 403, receives the relevant business scenarios that may be associated with the natural language sentence, which are initially screened and returned by the full-text search engine: financial scenarios, sales scenarios, and supply chain scenarios; step 404, sends the prompt words assembled from the natural language sentence and the relevant business scenarios to the large language model; it can be understood that the large language model can determine the business scenario to which the natural language sentence belongs from the relevant business scenarios: sales scenario, and the business documents of the sales scenario include: sales delivery order, sales order, etc.; the large language model can determine the target business document corresponding to the natural language sentence in the sales scenario: sales delivery order. Then, the natural language conversion device executes: step 405, receives the target business document corresponding to the natural language sentence returned by the large language model: sales delivery order, and the target business fields obtained by the large language model splitting the natural language sentence: date, sales cost, and product name.

[0096] 304. Split the natural language sentence into business fields of the natural language in the target business document to obtain the target business fields.

[0097] After determining the target business document corresponding to the natural language sentence, the natural language sentence can be split into business fields of the natural language in the target business document to obtain the target business fields. That is, the natural language words in the natural language sentence can be matched with the business fields of the natural language in the target business document to obtain the target business fields.

[0098] It can be understood that since the document knowledge base of the target business document is used when performing knowledge base recall, splitting the natural language sentences into natural language business fields in the target business document can make the obtained target business fields match the document knowledge base of the target business document, thereby facilitating the recall of field metadata of the target business field from the document knowledge base of the target business document.

[0099] 305. Recall the field metadata of the target business field from the document knowledge base corresponding to the target business document.

[0100] like Figure 4 As shown, the data query device executes: step 406, sending the target business field to the document knowledge base; step 407, receiving the field metadata of the target business field recalled from the document knowledge base; wherein the field metadata of the recalled target business field includes: database language information of the target business field, natural language information of the target business field, and database language information of the data table corresponding to the target business field. For example, when the target business field is: date, sales cost, and product name; the corresponding field metadata of the recalled target business field is: SAL_OUTSTOCK.FDATE, sales date

[0101] SAL_OUTSTOCKENTRY_F.FCOSTAMOUNT_LC, cost

[0102] BD_MATERIAL_L.FNAME, product name.

[0103] 306. Generate a database statement based on the field metadata of the target business field and the table relationship of the data table corresponding to the target business field.

[0104] After obtaining the field metadata of the target business field, a database statement can be generated based on the field metadata of the target business field and the table relationship of the data table corresponding to the target business field. It can be understood that the data table corresponding to the target business field is the data table involved in the natural language statement.

[0105] like Figure 4As shown, the data query device executes: step 408, sending the field metadata of the target business field to a relational database (such as a Mysql database); step 409, receiving the table relationship of the data table corresponding to the target business field returned by the relational database; step 410, sending the prompt word (prompt) assembled by the field metadata and the table relationship to the large language model; step 411, receiving the database statement returned by the large language model.

[0106] The field metadata of the target business field includes: database language information of the data table corresponding to the target business field; table relationships between data tables are pre-stored in the relational database (which can be understood as aggregation relationships or association relationships); based on the database language information of the data table corresponding to the target business field, the table relationship of the data table can be queried from the relational database; wherein the table relationship can be: one-to-one relationship, one-to-many relationship or many-to-many relationship, which is not limited here; the corresponding connection can be an inner join or an outer join, which is not limited here. For example, the table relationship of the outer join is: a left join f on a.id=f.dataid, that is, the left table a is left-joined to the right table f, and [a.id=f.dataid] is the corresponding table connection condition.

[0107] Next, a database statement can be generated based on the field metadata and table relationship of the target business field. Specifically, the field metadata, natural language statement and table relationship of the target business field can be assembled into prompt words; the large language model is called to generate a database statement based on the prompt words, so as to use the database statement to perform data query.

[0108] The present application also provides a data query device based on natural language, such as Figure 5 As shown, including:

[0109] The acquisition unit 501 is used to acquire a natural language sentence and a document knowledge base of a pre-configured business document, wherein the document knowledge base includes: field metadata of a business field in the business document, and different document knowledge bases correspond to different business documents;

[0110] A positioning unit 502 is used to locate a target business document corresponding to the natural language sentence based on the business scenario to which the natural language sentence belongs, and split the target business field in the natural language sentence; there are multiple different business documents in the business scenario;

[0111] A recall unit 503, configured to recall the field metadata of the target business field from the document knowledge base corresponding to the target business document;

[0112] A generating unit 504, configured to generate a database statement based on the field metadata of the target business field;

[0113] The query unit 505 is used to query data in the corresponding database based on the database statement.

[0114] Furthermore, the positioning unit 502 is specifically used to perform text retrieval on the natural language sentence based on a full-text search engine to determine the relevant business scenarios of the natural language sentence; perform semantic retrieval on the natural language sentence based on a large language model to determine the business scenario to which the natural language sentence belongs from the relevant business scenarios, and locate the target business document corresponding to the natural language sentence from the business documents corresponding to the business scenario.

[0115] Furthermore, the positioning unit 502 is specifically configured to split the natural language sentence into natural language business fields in the target business document to obtain the target business fields.

[0116] Furthermore, the acquisition unit 501 is specifically used to acquire database language information of business fields in the business document, natural language information of business fields, and database language information of data tables corresponding to business fields; assemble the database language information of business fields, natural language information of business fields, and database language information of data tables corresponding to business fields into field metadata of business fields; store the field metadata of multiple business fields in the business document in the same knowledge base to obtain the document knowledge base.

[0117] Furthermore, the field metadata of the business field in the document knowledge base also includes: a calculation method for a composite field; the acquisition unit 501 is also used to maintain the calculation method for the composite field in the document knowledge base based on the business scenario applied by the document knowledge base.

[0118] Furthermore, the generation unit 504 is specifically used to: the field metadata of the target business field includes: database language information of the data table corresponding to the target business field; based on the database language information of the data table corresponding to the target business field, query the table relationship of the data table from a relational database; generate a database statement based on the field metadata of the target business field and the table relationship.

[0119] Furthermore, the generating of database statements based on the field metadata of the target business field and the table relationship includes: assembling the field metadata of the target business field, the natural language statement and the table relationship into prompt words; and calling a large language model to generate database statements based on the prompt words.

[0120] The present application also provides an electronic device. Figure 6 The electronic device 600 of the embodiment of the present application may include one or more central processing units (CPU) 601 and a memory 602 , in which one or more application programs or data are stored.

[0121] The memory 602 may be a volatile storage or a persistent storage. The program stored in the memory 602 may include one or more modules, each of which may include a series of instruction operations in the electronic device. Furthermore, the central processor 601 may be configured to communicate with the memory 602 and execute a series of instruction operations in the memory 602 on the electronic device 600.

[0122] The electronic device 600 may also include one or more power supplies 605, one or more wired or wireless network interfaces 604, one or more input and output interfaces 603, and / or one or more operating systems, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.

[0123] The central processor 601 can execute the operations performed by the aforementioned first aspect or any specific method embodiment of the first aspect, and the details will not be repeated here.

[0124] The present application provides a computer-readable storage medium, comprising instructions, which, when executed on a computer, enable the computer to execute the method described in the first aspect or any specific implementation of the first aspect.

[0125] The present application provides a computer program product comprising instructions or a computer program. When the computer program product is run on a computer, the computer is enabled to execute the method described in the first aspect or any specific implementation of the first aspect.

[0126] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0127] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0128] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0129] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0130] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program code.

Claims

1. A data query method based on natural language, characterized in that: include: Acquire a natural language sentence and a document knowledge base of a pre-configured business document, wherein the document knowledge base includes: field metadata of a business field in the business document, and different document knowledge bases correspond to different business documents; Based on the business scenario to which the natural language statement belongs, locating the target business document corresponding to the natural language statement, and splitting the target business fields in the natural language statement; there are multiple different business documents in the business scenario; Recalling the field metadata of the target business field from the document knowledge base corresponding to the target business document; Generate a database statement based on the field metadata of the target business field; Data is queried in a corresponding database based on the database statement.

2. The data query method according to claim 1, characterized in that: The locating the target business document corresponding to the natural language statement based on the business scenario to which the natural language statement belongs includes: Performing text retrieval on the natural language sentence based on a full-text search engine to determine relevant business scenarios of the natural language sentence; The natural language sentence is semantically retrieved based on a large language model, the business scenario to which the natural language sentence belongs is determined from the relevant business scenarios, and a target business document corresponding to the natural language sentence is located from the business documents corresponding to the business scenario.

3. The data query method according to claim 1, characterized in that: The target business field in the splitting of the natural language sentence includes: The natural language sentence is split into business fields of the natural language in the target business document to obtain the target business fields.

4. The data query method according to claim 1, characterized in that: Get a document knowledge base of pre-configured business documents including: Obtain database language information of business fields in business documents, natural language information of business fields, and database language information of data tables corresponding to business fields; Assembling database language information of the business field, natural language information of the business field, and database language information of the data table corresponding to the business field into field metadata of the business field; The field metadata of multiple business fields in the business document are stored in the same knowledge base to obtain the document knowledge base.

5. The data query method according to claim 1, characterized in that: The field metadata of the business fields in the document knowledge base also includes: the calculation method of the composite field; After obtaining the pre-configured document knowledge base, it also includes: Based on the business scenario to which the document knowledge base is applied, a calculation method of the composite field in the document knowledge base is maintained.

6. The data query method according to claim 1, characterized in that: The field metadata of the target business field includes: database language information of the data table corresponding to the target business field; The generating of a database statement based on the field metadata of the target business field includes: Based on the database language information of the data table corresponding to the target business field, querying the table relationship of the data table from the relational database; A database statement is generated based on the field metadata of the target business field and the table relationship.

7. The data query method according to claim 6, characterized in that: The generating of database statements based on the field metadata of the target business field and the table relationship includes: Assembling the field metadata of the target business field, the natural language sentence and the table relationship into a prompt word; The large language model is called to generate a database sentence based on the prompt word.

8. A data query device based on natural language, characterized in that: include: An acquisition unit, used to acquire a natural language sentence and a document knowledge base of a pre-configured business document, wherein the document knowledge base includes: field metadata of a business field in the business document, and different document knowledge bases correspond to different business documents; A positioning unit, configured to locate a target business document corresponding to the natural language statement based on the business scenario to which the natural language statement belongs, and split the target business field in the natural language statement; the business scenario has a plurality of different business documents; A recall unit, used to recall the field metadata of the target business field from the document knowledge base corresponding to the target business document; A generating unit, configured to generate a database statement based on the field metadata of the target business field; A query unit is used to query data in a corresponding database based on the database statement.

9. An electronic device, characterized in that: include: CPU, memory and input / output interface; The memory is a short-term storage memory or a persistent storage memory; The central processing unit is configured to communicate with the memory and execute instructions in the memory to perform the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The method comprises instructions, which, when executed on a computer, cause the computer to execute the method according to any one of claims 1 to 7.

11. A computer program product comprising instructions or a computer program, characterized in that When the computer program product is run on a computer, the computer is caused to execute the method according to any one of claims 1 to 7.

Citation Information

Cited By

  • Business data exporting method, computer equipment and computer storage medium

    CN121116986A

  • Multi-source heterogeneous database-oriented spatio-temporal data natural language query method and system

    CN121597708A