Data query method and device, electronic equipment and medium

By querying the business entity and attribute information corresponding to keywords in the query information entered by the user in the knowledge graph, and generating and executing the target SQL statements, the problem of low accuracy of SQL statements in the prior art is solved, and the accuracy of data query results is improved.

CN119848064APending Publication Date: 2025-04-18BEIJING DATA INTELLIGENCE INFORMATION TECH CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411783127.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-05
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

In the prior art, when data is obtained from a database, the generated SQL statements are less accurate, resulting in lower data accuracy of the final query.

Method used

By obtaining the query information entered by the user, determining the keywords, and querying the business entity and attribute information corresponding to the keywords in the pre-constructed knowledge graph. Based on the query information, business entity and attribute information, the target SQL statement is generated and executed to obtain the query result.

Benefits of technology

Improves the accuracy of SQL statements, thereby improving the accuracy of data query results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119848064A_ABST
    Figure CN119848064A_ABST
Patent Text Reader

Abstract

The invention provides a data query method and device, electronic equipment and a medium, and the specific implementation scheme comprises the steps: obtaining query information input by a user, and determining at least one keyword contained in the query information; service entities corresponding to the keywords and attribute information of the service entities are inquired in a pre-constructed knowledge graph, and the attribute information is used for indicating database table information associated with the service entities, association relationships between the service entities stored in the knowledge graph and association relationships between the service entities and corresponding database tables; obtaining a reference question and answer pair related to the query information according to the query information; generating a target SQL statement according to the queried service entity, the attribute information of the service entity, the query information and the reference question and answer pair; and executing the target SQL statement to obtain a query result corresponding to the query information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a data query method, device, electronic equipment and storage medium. Background Art

[0002] At present, when obtaining the required data from a database, the natural language query input by the user can be converted into a structured query language (SQL) statement that can interact with the database, and then the queried data can be obtained by running the SQL statement query. However, the accuracy of the SQL statement generated in the related art is low, resulting in low accuracy of the final queried data. Summary of the invention

[0003] The present invention provides a data query method, device, electronic equipment, storage medium and computer program product.

[0004] According to one aspect of the present invention, there is provided a data query method, comprising: obtaining query information input by a user, and determining at least one keyword contained in the query information; querying business entities and attribute information of the business entities corresponding to each keyword in a pre-constructed knowledge graph, wherein the attribute information is used to indicate database table information associated with the business entity, and the knowledge graph stores associations between business entities and associations between business entities and corresponding database tables; obtaining reference question-answer pairs related to the query information based on the query information; generating a target SQL statement based on the queried business entities and attribute information of the business entities, as well as the query information and the reference question-answer pairs; and executing the target SQL statement to obtain a query result corresponding to the query information.

[0005] According to another aspect of the present invention, there is provided a data query device, comprising: a first acquisition module, used to acquire query information input by a user and determine at least one keyword contained in the query information; a query module, used to query business entities and attribute information of business entities corresponding to each keyword in a pre-constructed knowledge graph, wherein the attribute information is used to indicate database table information associated with the business entity, and the knowledge graph stores associations between business entities and associations between business entities and corresponding database tables; a second acquisition module, used to acquire reference question-answer pairs related to the query information based on the query information; a generation module, used to generate a target SQL statement based on the queried business entities and attribute information of the business entities, as well as the query information and the reference question-answer pairs; and an execution module, used to execute the target SQL statement to obtain a query result corresponding to the query information.

[0006] According to another aspect of the present invention, an electronic device is provided, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors execute and implement the data query method as described above.

[0007] According to another aspect of the present invention, a computer-readable storage medium is provided, on which executable instructions are stored. When the instructions are executed by a processor, the processor executes the data query method as described above.

[0008] According to another aspect of the present invention, a computer program product is provided, comprising a computer program, which implements the data query method as described above when executed by a processor. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the embodiments. Obviously, the drawings described below are only some embodiments of the present invention, and for ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0010] Figure 1 is a flow chart of a data query method according to an embodiment of the present invention;

[0011] Figure 2A is a schematic diagram of a business entity extraction process according to an embodiment of the present invention;

[0012] Figure 2B is with Figure 2A A schematic diagram of the database tables associated with the business entities;

[0013] Figure 2C is a schematic diagram of a knowledge graph constructed according to an embodiment of the present invention;

[0014] Figure 3 is a block diagram of a data query device according to an embodiment of the present invention;

[0015] Figure 4 is a block diagram of an electronic device suitable for implementing a data query method according to an embodiment of the present invention. DETAILED DESCRIPTION

[0016] The technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the embodiments of the present invention and the drawings in the embodiments. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field belong to the scope of protection of the present invention.

[0017] It should be noted that the sequence numbers of the operations in the following method are only used as representations of the operations for the purpose of description, and should not be regarded as representing the execution order of the operations. Unless explicitly stated, the method does not need to be executed completely in the order shown.

[0018] In addition, in the description of the present invention, the terms “first”, “second”, “third”, etc. (if any) are only used to distinguish the description and cannot be understood as indicating or implying relative importance.

[0019] In the technical solution of the present invention, the collection, storage, use, processing, transmission, provision, disclosure and application of the data involved (for example, including but not limited to user personal information) shall comply with the relevant laws and regulations of relevant countries and regions and shall not violate public order and good morals.

[0020] In the technical solution of the present invention, before obtaining or collecting relevant data, the authorization or consent of the data owner is obtained.

[0021] Figure 1 is a flow chart of a data query method according to an embodiment of the present invention.

[0022] like Figure 1 As shown, the data query method 100 includes operations S110 to S150.

[0023] In operation S110, query information input by a user is acquired, and at least one keyword included in the query information is determined.

[0024] In operation S120, the business entity and the attribute information of the business entity corresponding to each keyword are searched in the pre-constructed knowledge graph.

[0025] In operation S130, based on the query information, reference question-answer pairs related to the query information are acquired.

[0026] In operation S140, a target SQL statement is generated according to the queried business entity and the attribute information of the business entity, as well as the query information and the reference question-answer pair.

[0027] In operation S150, the target SQL statement is executed to obtain a query result corresponding to the query information.

[0028] According to an embodiment of the present invention, query information is natural language information used to characterize the user's information acquisition needs. The query information can be obtained based on the user's input operation on the information input box in the interactive interface, or can be obtained by recognizing the voice information input by the user based on voice recognition technology. The embodiment of the present invention does not limit the method of obtaining the query information.

[0029] For example, the query information may be, for example, "What is the cultivated land area in the xxX region in the first quarter of 2023?" It represents the user's intention to obtain the cultivated land area in the xxX region in the first quarter of 2023. By performing word segmentation on the query information, various keywords contained in the query information may be obtained, such as "the first quarter of 2023", "xxX region", and "cultivated land area".

[0030] According to an embodiment of the present invention, the knowledge graph is pre-constructed based on business data. Business data includes structured data and unstructured data related to business information, such as but not limited to database tables, text documents, images, videos, and other applicable data forms. The construction process of the knowledge graph is described below.

[0031] First, business data is obtained, and business entities, relationships between business entities, and relationships between business entities and corresponding database tables are extracted from the business data.

[0032] According to an embodiment of the present invention, a business entity is used to indicate an entity related to business information, and its attributes and relationships can be stored and managed. For example, entities "agricultural land", "cultivated land", "forest land" and the like extracted from business data can be used as business entities.

[0033] According to an embodiment of the present invention, the relationship between business entities is used to indicate a mapping relationship or a dependency relationship between business entities. For example, the business entity corresponding to the two business entities "arable land" and "forest land" is "agricultural land". It can be determined that there is a mapping relationship between the business entity "agricultural land" and the business entity "arable land", and between the business entity "agricultural land" and the business entity "forest land".

[0034] According to an embodiment of the present invention, the relationship between a business entity and a corresponding database table is used to indicate a mapping relationship between the business entity and the database table (or database table information). Based on this mapping relationship, data related to the business entity can be queried.

[0035] Next, a knowledge graph is constructed based on business entities, relationships between business entities, and relationships between business entities and corresponding database tables.

[0036] According to an embodiment of the present invention, in the process of constructing a knowledge graph, business entities are used as nodes of the graph, and database table information (such as database name, table name or field name, value, etc.) of a database table associated with the business entity is used as attribute information of the node, and edges between each business entity node are constructed based on the relationship between the business entities. Among them, the edge between the business entity nodes can be a directed edge, and the direction of the edge is from the dependent business entity to the dependent business entity, that is, the dependent business entity is obtained by calculation, operation or connection based on the dependent business entity. The knowledge graph constructed as above can be used to store the association relationship between business entities and the association relationship between business entities and corresponding database table information (or database tables).

[0037] Figure 2A is a schematic diagram of a business entity extraction process according to an embodiment of the present invention, Figure 2B is with Figure 2A Schematic diagram of database table A associated with the business entity "farmland". Figure 2C is a schematic diagram of a knowledge graph constructed according to an embodiment of the present invention. It should be understood that FIG. 2A to FIG. 2C What is shown is merely exemplary and is not intended to limit the scope of the invention.

[0038] Please refer to Figure 2A , assuming that the business entities extracted from the business data include business entity "agricultural land", business entity "cultivated land", business entity "grassland", business entity "forest land", etc. Among them, the business entity "agricultural land" has association relationships with business entity "grassland", business entity "forest land", business entity "cultivated land", etc., business entity "cultivated land" is associated with database table A, and business entity "forest land" is associated with database table B. Figure 2B As shown, database table A includes the fields of farmland ID, time, farmland type, geographical location, area, land use status, etc. Database table B includes the fields of forestland ID, time, forestland type, geographical location, vegetation type, etc.

[0039] Based on the extracted business entities, the relationships between business entities, and the relationships between business entities and database tables, a knowledge graph can be constructed. For example, the business entity "agricultural land", the business entity "arable land", the business entity "grassland", the business entity "forest land", etc. are used as nodes in the knowledge graph, and the database table information of database table A associated with the business entity "arable land" (for example, including the field name, table name and corresponding values ​​contained in database table A) is used as the attribute information of the node "arable land", and the database table information of database table B associated with the business entity "forest land" (for example, including the field name, table name and corresponding values ​​contained in database table B) is used as the attribute information of the node "forest land". According to the association relationship between each business entity, each business entity node with a dependent relationship is connected, so that the following can be constructed. Figure 2C The knowledge graph shown in Figure 1 stores the associations between business entities and the associations between business entities and corresponding database table information.

[0040] After obtaining each keyword included in the query information, each keyword can be used to query the knowledge graph to determine the business entity corresponding to each keyword and the attribute information of the business entity.

[0041] For example, for the query information "What is the cultivated land area in the xxx region in the first quarter of 2023", the various keywords contained in the query information (such as "the first quarter of 2023", "xxx region" or "cultivated land area") can be used to query the knowledge graph to determine the business entities corresponding to the various keywords and the attribute information of the business entities. Exemplarily, it can be determined that the business entity matching the keyword "cultivated land area" is "cultivated land", and the attribute information is the attribute information corresponding to the business entity "cultivated land". The attribute information is used to indicate the database table information associated with the business entity "cultivated land".

[0042] According to an embodiment of the present invention, by utilizing a knowledge graph to store and manage the relationships between business entities and the relationships between business entities and database table information, it is possible to conveniently acquire and expand business entities and corresponding database table information, and then utilize query information to query the knowledge graph, so as to quickly acquire database table information and business entities related to the query information for subsequent data queries.

[0043] Return to reference Figure 1 ,Next, according to the query information, the reference question and answer pairs matching ,the query information are obtained.

[0044] According to an embodiment of the present invention, based on the query information, obtaining a reference question and answer pair that matches the query information includes: obtaining multiple first question and answer pairs, each first question and answer pair including first candidate query information and a first candidate SQL statement that matches the first candidate query information, screening K first question and answer pairs from the multiple first question and answer pairs based on the similarity between the query information and the first candidate query information in each first question and answer pair, and using the K first question and answer pairs as reference question and answer pairs, where K is a positive integer.

[0045] According to an embodiment of the present invention, multiple first question-answer pairs can be obtained from a pre-constructed corpus. The first candidate query information in each first question-answer pair is query information related to the business field expressed in natural language, and the first candidate SQL statement is an example of an SQL statement corresponding to the first candidate query information. Exemplarily, the first candidate query information is, for example, "What is the area of ​​lakes in region B in the third quarter of 2023", and the first candidate SQL statement corresponding to the first candidate query information is, for example, "SELECT AREA FromTABLE_A WHERE YEAR=2023AND MONTH IN(7,8,9)ANDREGION='B'AND LAND TYPE='HP'".

[0046] In some embodiments, based on semantic matching, the similarity between the semantic vector of the query information and the semantic vector of each first candidate query information can be calculated, and the first question-answer pairs corresponding to the K first candidate query information ranked first in similarity can be used as reference question-answer pairs.

[0047] In other embodiments, the reference question-answer pair may be determined by combining a semantic matching-based method and a keyword matching-based method. The keyword matching-based method refers to matching the fields contained in each first candidate query information by utilizing the keywords contained in the query information. If a relevant keyword is matched in a first candidate query information, the first question-answer pair corresponding to the first candidate query information is used as a candidate question-answer pair. In an embodiment of the present invention, the first question-answer pairs obtained by the semantic matching-based method and the keyword matching-based method can be sorted and optimized based on a multi-way re-ranking algorithm, and then the top K first question-answer pairs are selected from the optimized sorting results as reference question-answer pairs.

[0048] According to an embodiment of the present invention, since the reference question and answer pairs are related to the query information, accordingly, the reference question and answer pairs contain information related to the target SQL statement to a certain extent. Therefore, the reference question and answer pairs can be used as a priori to assist in generating the target SQL statement, which is beneficial to improving the accuracy of the target SQL statement, and further beneficial to improving the accuracy of the data query results.

[0049] It can be understood that the number and coverage of the first question-answer pairs stored in the corpus constructed above are usually limited, which makes the reference question-answer pairs obtained based on the corpus have certain limitations, thereby affecting the generation accuracy of the target SQL statement and further reducing the accuracy of the data query results.

[0050] Generally speaking, if two query information are similar, then their corresponding SQL statements are likely to be similar, and the corresponding SQL statement structures may also be similar. For example, for the query information "Which areas have cultivated land areas exceeding xxx square kilometers" and the query information "Which students have math scores exceeding 90 points", they are similar query questions, both of which filter information based on filtering conditions, and their semantics are similar. Accordingly, their corresponding SQL statements are similar, and the corresponding SQL statement structures may also be similar. Among them, the SQL statement structure refers to the basic structure or template of an SQL query, which contains the basic elements required to form a complete SQL query, but does not contain specific data or conditions.

[0051] In view of this, in order to solve the above problems, multiple historical query information-SQL statement structure pairs can be constructed based on the question-answer pairs stored in the external knowledge base to expand the search scope of the reference question-answer pairs. In this way, when constructing reference question-answer pairs, in addition to the K first question-answer pairs searched based on the corpus, the query information can also be used to filter the relevant historical query information-SQL statement structure pairs, and the filtered historical query information-SQL statement structure pairs and the K first question-answer pairs can be used to construct the reference question-answer pairs, so that the obtained reference question-answer pairs are richer, which is conducive to improving the generation accuracy of the target SQL statement, and then to improving the accuracy of the data query results.

[0052] The following is an explanation of the process of obtaining reference question-answer pairs according to another embodiment of the present invention: First, multiple second question-answer pairs are obtained, each of which includes second candidate query information and a candidate SQL statement structure matching the second candidate query information.

[0053] According to an embodiment of the present invention, the second candidate query information is query information expressed in natural language, which is different from the first candidate query information. The candidate SQL statement structure refers to the basic structure of the SQL statement corresponding to the second candidate query information, which contains the basic elements required to form a complete SQL query, but does not contain specific data or conditions. The candidate SQL statement structure can be regarded as a SQL statement template.

[0054] According to an embodiment of the present invention, the plurality of second question-answer pairs are obtained by processing the plurality of third question-answer pairs. The process of obtaining the plurality of second question-answer pairs is described below.

[0055] First, a plurality of third question-answer pairs are obtained, each of which includes third candidate query information and a third candidate SQL statement matching the third candidate query information.

[0056] According to an embodiment of the present invention, multiple third question-answer pairs can be obtained from a pre-built external knowledge base. The multiple third question-answer pairs are different from the multiple first question-answer pairs mentioned above, and they can include question-answer pairs related to the business field, and can also include question-answer pairs outside the business field.

[0057] Next, each third candidate SQL statement in the plurality of third question-answer pairs is preprocessed to delete non-critical information in the third candidate SQL statement, such as table names, field names, and values, so as to obtain a corresponding candidate SQL statement structure.

[0058] Next, multiple second question-answer pairs are obtained based on multiple third candidate query information and corresponding candidate SQL statement structures. For example, each third candidate query information and corresponding candidate SQL statement structure constitutes a second question-answer pair, thereby obtaining multiple second question-answer pairs.

[0059] In some embodiments, in addition to preprocessing the third candidate SQL statement in each third question-answer pair, the third candidate query information in each third question-answer pair may also be processed to delete non-critical information in each third candidate query information, such as field names, values, etc., so as to obtain a corresponding candidate query information structure. Then, each candidate query information structure and the corresponding candidate SQL statement structure constitute a second question-answer pair, thereby obtaining multiple second question-answer pairs.

[0060] Next, based on the similarity between the query information and the second candidate query information in each second question-answer pair, M second question-answer pairs are selected from the multiple second question-answer pairs, where M is a positive integer.

[0061] If each second question-answer pair is composed of second candidate query information and a corresponding candidate SQL statement structure, in the process of screening the second question-answer pairs, the similarity between the query information and the second candidate query information in each second question-answer pair can be calculated. Then, the second question-answer pairs corresponding to the M second candidate query information ranked first in similarity are selected to obtain M second question-answer pairs.

[0062] If each second question-answer pair is composed of a candidate query information structure and a corresponding candidate SQL statement structure, in the process of screening the second question-answer pairs, the query information can be processed to delete non-key information in the query information, such as field names, values, etc. Then, the similarity between the processed query information and the candidate SQL statement structure, or the similarity between the processed query information and the candidate query information structure is calculated. Then, based on the similarity sorting results, the top M second question-answer pairs are selected.

[0063] Next, a reference question-answer pair is obtained based on the K first question-answer pairs and the M second question-answer pairs. According to an embodiment of the present invention, multiple second question-answer pairs are constructed based on the third question-answer pairs stored in the external knowledge base, and then the query information is used to screen out the M second question-answer pairs related to the multiple second question-answer pairs, and a reference question-answer pair is generated based on the K first question-answer pairs and the M second question-answer pairs, so that the reference question-answer pair can be used to better guide the generation of a target SQL statement that matches the query information, thereby further improving the accuracy of the target SQL statement, and then improving the accuracy of the data query results.

[0064] According to an embodiment of the present invention, generating a target SQL statement based on the queried business entity and the attribute information of the business entity, the query information and the reference question-answer pair includes: generating target prompt information based on the business entity, the attribute information of the business entity, the query information and the reference question-answer pair. Then, processing the target prompt information using a large language model to obtain a target SQL statement corresponding to the query information.

[0065] According to an embodiment of the present invention, target prompt information can be generated based on prompt engineering according to business entities, attribute information of business entities, query information and reference question-answer pairs. The target prompt information is used to prompt the writing of corresponding SQL statements for query information according to business entities, attribute information of business entities and reference question-answer pairs. Among them, business entities and attribute information of business entities can be used to provide corresponding query field information or query conditions for the generation process of target SQL statements, and reference question-answer pairs are used to provide SQL statement examples for the generation process of target SQL statements, so as to guide the large language model to generate SQL statements with the same or similar semantics as it, so as to improve the accuracy of target SQL statements.

[0066] According to an embodiment of the present invention, the large language model can be a deep learning model trained using a large amount of training data, such as a language model based on a Transformer architecture. The large language model can understand and generate natural language text, and has strong logical reasoning and code generation capabilities, and can generate a target SQL statement corresponding to the query information based on the target prompt information.

[0067] According to an embodiment of the present invention, after obtaining the target SQL statement, data query can be performed in the database table based on the target SQL statement to obtain the query result. Afterwards, feedback information for the query information can be generated based on the query result, and the feedback information and the statement viewing entry corresponding to the target SQL statement can be displayed in the interactive interface. The statement viewing entry can be a hyperlink, or can be a control or component. When the statement viewing entry is triggered, the target SQL statement is displayed. For example, after the statement viewing entry is displayed in the interactive interface, the user can perform a trigger operation (such as a click operation, a touch operation) on the statement viewing entry to trigger the statement viewing entry, thereby displaying the target SQL statement on the interactive interface.

[0068] According to the technical solution of the present invention, by pre-constructing a knowledge graph and using the knowledge graph to store and manage the relationship between business entities and the relationship between business entities and database table information, when the query information input by the user is obtained, the relevant business entities and attribute information can be quickly and accurately queried based on the query information to provide corresponding query field information or query conditions for the generation process of the target SQL statement. In addition, by constructing a corpus and knowledge base that stores a wealth of question-answer pairs, reference question-answer pairs can be searched within a larger search range, thereby improving the accuracy of the reference question-answer pairs, thereby using the reference question-answer pairs to provide SQL statement examples for the generation process of the target SQL statement, so as to guide the large language model to generate SQL statements with the same or similar semantics, thereby improving the accuracy of the target SQL statement, and further using the target SQL statement to obtain query results corresponding to the query information, thereby improving the accuracy of the query results.

[0069] Figure 3 is a block diagram of a data query device according to an embodiment of the present invention.

[0070] like Figure 3 As shown, the data query device 300 includes: a first acquisition module 310 , a query module 320 , a second acquisition module 330 , a generation module 340 and an execution module 350 .

[0071] The first acquisition module 310 is used to acquire query information input by a user and determine at least one keyword included in the query information.

[0072] The query module 320 is used to query the business entities and attribute information of the business entities corresponding to each keyword in the pre-constructed knowledge graph, wherein the attribute information is used to indicate the database table information associated with the business entity, and the knowledge graph stores the association relationship between the business entities and the association relationship between the business entities and the corresponding database tables.

[0073] The second acquisition module 330 is used to acquire reference question-answer pairs related to the query information according to the query information.

[0074] The generation module 340 is used to generate a target SQL statement according to the queried business entity and the attribute information of the business entity, as well as the query information and the reference question-answer pair.

[0075] The execution module 350 is used to execute the target SQL statement to obtain the query result corresponding to the query information.

[0076] According to an embodiment of the present invention, the data query device 300 also includes: a third acquisition module for acquiring business data before querying business entities and attribute information of business entities corresponding to each keyword in a pre-constructed knowledge graph, the business data including structured data and unstructured data related to the business information, the structured data at least including database tables; an extraction module for extracting business entities, the relationships between business entities, and the relationships between business entities and corresponding database tables from the business data; and a construction module for constructing a knowledge graph based on the extracted business entities, the relationships between business entities, and the relationships between business entities and corresponding database tables.

[0077] According to an embodiment of the present invention, the second acquisition module 330 includes: a first acquisition unit for acquiring multiple first question-answer pairs, each first question-answer pair including first candidate query information and a first candidate SQL statement matching the first candidate query information; a first screening unit for screening out K first question-answer pairs from the multiple first question-answer pairs based on the similarity between the query information and the first candidate query information in each first question-answer pair, where K is a positive integer; and a first determination unit for using the K first question-answer pairs as reference question-answer pairs.

[0078] According to an embodiment of the present invention, the second acquisition module 330 also includes: a second acquisition unit for acquiring multiple second question-answer pairs, each second question-answer pair including second candidate query information and a candidate SQL statement structure matching the second candidate query information; a second screening unit for screening out M second question-answer pairs from the multiple second question-answer pairs based on the similarity between the query information and the second candidate query information in each second question-answer pair, where M is a positive integer; and a second determination unit for obtaining a reference question-answer pair based on the K first question-answer pairs and the M second question-answer pairs.

[0079] According to an embodiment of the present invention, the second acquisition unit includes: an acquisition subunit for acquiring multiple third question-answer pairs, each third question-answer pair includes third candidate query information and a third candidate SQL statement matching the third candidate query information, and the multiple third question-answer pairs are different from the multiple first question-answer pairs; a preprocessing subunit for preprocessing each third candidate SQL statement in the multiple third question-answer pairs to obtain multiple candidate SQL statement structures; wherein the preprocessing includes deleting the table name, field name and numerical value in the third candidate SQL statement; a determination subunit for obtaining multiple second question-answer pairs based on the multiple third candidate query information and the corresponding candidate SQL statement structures.

[0080] According to an embodiment of the present invention, the generation module 340 is also used to: generate target prompt information based on business entities, attribute information of business entities, query information and reference question and answer pairs, the target prompt information is used to prompt to write corresponding SQL statements for the query information based on business entities, attribute information of business entities and reference question and answer pairs; and use a large language model to process the target prompt information to obtain a target SQL statement corresponding to the query information.

[0081] It should be noted that the implementation methods, technical problems solved, functions realized, and technical effects achieved of each module in the device part embodiment are the same or similar to the implementation methods, technical problems solved, functions realized, and technical effects achieved of each corresponding step in the method part embodiment, and will not be repeated here.

[0082] Figure 4 A block diagram of an electronic device suitable for implementing a data query method according to an embodiment of the present invention is schematically shown.

[0083] like Figure 4 As shown, the electronic device 400 according to an embodiment of the present invention includes a processor 401, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 402 or a program loaded from a storage part 408 into a random access memory (RAM) 403. The processor 401 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 401 may also include an onboard memory for caching purposes. The processor 401 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.

[0084] In RAM 403, various programs and data required for the operation of electronic device 400 are stored. Processor 401, ROM 402 and RAM 403 are connected to each other via bus 404. Processor 401 performs various operations of the method flow according to the embodiment of the present invention by executing the programs in ROM 402 and / or RAM 403. It should be noted that the program can also be stored in one or more memories other than ROM 402 and RAM 403. Processor 401 can also perform various operations of the method flow according to the embodiment of the present invention by executing the programs stored in the one or more memories.

[0085] According to an embodiment of the present invention, the electronic device 400 may further include an input / output (I / O) interface 405, which is also connected to the bus 404. The electronic device 400 may further include one or more of the following components connected to the I / O interface 405: an input portion 406 including a keyboard, a mouse, etc.; an output portion 407 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 408 including a hard disk, etc.; and a communication portion 409 including a network interface card such as a LAN card, a modem, etc. The communication portion 409 performs communication processing via a network such as the Internet. A drive 410 is also connected to the I / O interface 405 as needed. A removable medium 411, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 410 as needed, so that a computer program read therefrom is installed into the storage portion 408 as needed.

[0086] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiment; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the data query method according to the embodiment of the present invention is implemented.

[0087] According to an embodiment of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device. For example, according to an embodiment of the present invention, the computer-readable storage medium may include the ROM 402 and / or RAM 403 described above and / or one or more memories other than ROM 402 and RAM 403.

[0088] The embodiment of the present invention also includes a computer program product, which includes a computer program, and the computer program contains program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the data query method provided by the embodiment of the present invention.

[0089] The computer program executes the above functions defined in the system / device of the embodiment of the present invention when the processor 401 executes the computer program. According to the embodiment of the present invention, the system, device, module, unit, etc. described above can be implemented by a computer program module.

[0090] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 409, and / or installed from the removable medium 411. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.

[0091] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 409, and / or installed from the removable medium 411. When the computer program is executed by the processor 401, the above functions defined in the system of the embodiment of the present invention are performed. According to the embodiment of the present invention, the system, device, means, module, unit, etc. described above can be implemented by a computer program module.

[0092] According to an embodiment of the present invention, the program code for executing the computer program provided by the embodiment of the present invention can be written in any combination of one or more programming languages, specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, such as Java, C++, python, "C" language or similar programming languages. The program code can be executed completely on the user computing device, partially on the user device, partially on the remote computing device, or completely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).

[0093] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0094] It will be appreciated by those skilled in the art that the features described in the various embodiments of the present invention may be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in the present invention. In particular, without departing from the spirit and teachings of the present invention, the features described in the various embodiments of the present invention may be combined and / or combined in various ways. All of these combinations and / or combinations fall within the scope of the present invention.

[0095] The embodiments of the present invention are described above. However, these embodiments are only for the purpose of illustration, and are not intended to limit the scope of the present invention. Although each embodiment is described above, it does not mean that the measures in each embodiment cannot be used in combination advantageously. Without departing from the scope of the present invention, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present invention.

Claims

1. A data query method, characterized in that: include: Acquire query information input by a user, and determine at least one keyword contained in the query information; Querying the business entities corresponding to each keyword and the attribute information of the business entities in the pre-built knowledge graph, wherein the attribute information is used to indicate the database table information associated with the business entity, and the knowledge graph stores the association relationship between the business entities and the association relationship between the business entities and the corresponding database tables; According to the query information, obtaining reference question-answer pairs related to the query information; Generate a target SQL statement according to the queried business entity and the attribute information of the business entity, as well as the query information and the reference question-answer pair; Execute the target SQL statement to obtain a query result corresponding to the query information.

2. The method according to claim 1, characterized in that: Before searching the pre-built knowledge graph for business entities corresponding to each keyword and attribute information of the business entities, the method further includes: Acquire business data, wherein the business data includes structured data and unstructured data related to business information, and the structured data includes at least a database table; Extracting business entities, relationships between business entities, and relationships between business entities and corresponding database tables from the business data; The knowledge graph is constructed based on the extracted business entities, the relationships between the business entities, and the relationships between business entities and corresponding database tables.

3. The method according to claim 1 or 2, characterized in that: The acquiring, according to the query information, reference question-answer pairs related to the query information comprises: Acquire multiple first question-answer pairs, each of the first question-answer pairs including first candidate query information and a first candidate SQL statement matching the first candidate query information; Filtering K first question-answer pairs from the multiple first question-answer pairs according to the similarity between the query information and the first candidate query information in each first question-answer pair, where K is a positive integer; The K first question-answer pairs are used as the reference question-answer pairs.

4. The method according to claim 3, characterized in that The acquiring, according to the query information, reference question-answer pairs related to the query information further comprises: Acquire multiple second question-answer pairs, each of the second question-answer pairs including second candidate query information and a candidate SQL statement structure matching the second candidate query information; Filtering M second question-answer pairs from the plurality of second question-answer pairs according to the similarity between the query information and the second candidate query information in each second question-answer pair, where M is a positive integer; The reference question-answer pairs are obtained according to the K first question-answer pairs and the M second question-answer pairs.

5. The method according to claim 4, characterized in that The obtaining of a plurality of second question-answer pairs comprises: Acquire a plurality of third question-answer pairs, each of the third question-answer pairs comprising third candidate query information and a third candidate SQL statement matching the third candidate query information, the plurality of third question-answer pairs being different from the plurality of first question-answer pairs; Preprocessing each third candidate SQL statement in the plurality of third question-answer pairs to obtain a plurality of candidate SQL statement structures; wherein the preprocessing includes deleting table names, field names, and values ​​in the third candidate SQL statements; The plurality of second question-answer pairs are obtained according to the plurality of third candidate query information and the corresponding candidate SQL statement structures.

6. The method according to claim 1, characterized in that Generating a target SQL statement according to the queried business entity and the attribute information of the business entity, the query information and the reference question-answer pair includes: Generate target prompt information according to the business entity, the attribute information of the business entity, the query information and the reference question-answer pair, wherein the target prompt information is used to prompt to write a corresponding SQL statement for the query information according to the business entity, the attribute information of the business entity and the reference question-answer pair; The target prompt information is processed using a large language model to obtain a target SQL statement corresponding to the query information.

7. A data query device, characterized in that: include: A first acquisition module, used to acquire query information input by a user and determine at least one keyword contained in the query information; A query module, used to query the business entities corresponding to each keyword and the attribute information of the business entities in the pre-built knowledge graph, wherein the attribute information is used to indicate the database table information associated with the business entity, and the knowledge graph stores the association relationship between the business entities and the association relationship between the business entities and the corresponding database tables; A second acquisition module, configured to acquire reference question-answer pairs related to the query information according to the query information; A generation module, used to generate a target SQL statement according to the queried business entity and the attribute information of the business entity, as well as the query information and the reference question-answer pair; The execution module is used to execute the target SQL statement to obtain the query result corresponding to the query information.

8. An electronic device, characterized in that: include: one or more processors; a memory for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors are enabled to execute the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: Executable instructions are stored thereon, and when the instructions are executed by a processor, the processor is caused to execute the method according to any one of claims 1 to 6.

10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.

Citation Information

Cited By

  • Question and answer method and device, computer equipment and program product

    CN120429412A