Database query method, device, electronic device and non-volatile storage medium

By building a database knowledge graph and combining large-scale model technology, structured query language statements are generated, and poor accuracy of SQL statements caused by the numerous field information and complex relationships in the database are solved, achieving higher accuracy and reliability.

CN119226315BActive Publication Date: 2025-05-02CHINA TELECOM ARTIFICIAL INTELLIGENCE TECHNOLOGY (BEIJING) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411280879.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-12
Publication Date
2025-05-02
Estimated Expiration
2044-09-12

AI Technical Summary

Technical Problem

Due to the extensive field information and complex relationships in the database, the SQL statements generated using large language models have poor accuracy.

Method used

By building a knowledge graph of the database, the tables, fields, main foreign key relationships and other information in the database are represented in the form of a graph, and combined with large model technology, structured query language statements are generated based on user's problems.

Benefits of technology

It improves the accuracy and reliability of generating SQL statements, and solves the poor accuracy problems caused by the numerous field information and complex relationships in the database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119226315B_ABST
    Figure CN119226315B_ABST
Patent Text Reader

Abstract

The present application discloses a database query method, device, electronic device and non-volatile storage medium. The method includes: determining a knowledge graph corresponding to the database to be queried, wherein the knowledge graph is used to characterize the logical structure and association relationship of the data in the database to be queried; determining the similarity score between the user's question text and each graph node in the knowledge graph, and determining a target node in each graph node of the knowledge graph based on the similarity score, wherein the similarity score is used to characterize the degree of association between the graph node and the user's question text; based on the target node, generating database model information corresponding to the database to be queried, and using a large language model, generating a structured query language statement corresponding to the user's question text based on the database model information. The present application solves the technical problem of poor accuracy of query statements generated for a database using a large language model due to the large amount of field information and complex relationships in the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of artificial intelligence technology, and more specifically, to a database query method, device, electronic device and non-volatile storage medium. Background Art

[0002] Generative large language models are a powerful and popular technology in the field of natural language processing today. Based on massive data, Transformer-based deep attention networks, and reinforcement learning based on human feedback, generative large language models can learn rich latent semantics, thereby understanding natural language and generating corresponding responses.

[0003] At present, large language models have been widely used in the field of converting natural language text into database queries. In related technologies, the current mainstream technical methods usually input the schema information in the database (including table creation statements and primary and foreign keys, etc.) as context information into the large model, establish the association between the large model and database knowledge, and then use small sample learning to guide the large model to generate SQL (Structured Query Language) statements. However, since the field information in the database is usually relatively large, and the relationship between fields and fields, as well as between fields and values ​​is complex, there is a problem of poor accuracy of SQL statements generated using large language models.

[0004] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0005] The embodiments of the present application provide a database query method, device, electronic device and non-volatile storage medium to at least solve the technical problem of poor accuracy of query statements for the database generated using a large language model due to the large amount of field information and complex relationships in the database.

[0006] According to one aspect of an embodiment of the present application, a database query method is provided, including: determining a knowledge graph corresponding to a database to be queried, wherein the knowledge graph is used to characterize the logical structure and association relationship of data in the database to be queried; determining a similarity score between a user question text and each graph node in the knowledge graph, and determining a target node in each graph node of the knowledge graph based on the similarity score, wherein the similarity score is used to characterize the degree of association between the graph node and the user question text; generating database schema information corresponding to the database to be queried based on the target node, and using a large language model to generate a structured query language statement corresponding to the user question text based on the database schema information, wherein the structured query language statement is used to query data in the database to be queried.

[0007] Optionally, determining the knowledge graph corresponding to the database to be queried includes: generating a knowledge graph corresponding to the database to be queried by traversing the data tables in the database to be queried, wherein the knowledge graph is composed of multiple graph nodes and edges between graph nodes, each graph node corresponds to an entity, and the entities include: table entity and column entity, the attributes corresponding to the table entity include: table name, table description, the attributes corresponding to the column entity include: column name, column description, data type, example value, value meaning, each edge is used to represent the association relationship between the two graphs it connects, and the association relationship includes: relationship between tables, inclusion relationship between tables and columns, and foreign key relationship.

[0008] Optionally, after determining the knowledge graph corresponding to the database to be queried, the method also includes: obtaining a sample data set corresponding to the database to be queried, wherein the sample data set contains multiple historical structured query language statements and natural language question texts corresponding to the historical structured query language statements; using a large language model, based on the sample data set, determining target bigrams and target triples, wherein the target bigrams are used to characterize the correspondence between standard fields in the historical structured query language statements and the descriptive information in the natural language question text, each standard field corresponds to a column entity, and the target triples are used to characterize the dependency relationship between two standard fields; and adding the information corresponding to the target bigrams and target triples to the knowledge graph.

[0009] Optionally, obtaining a sample data set corresponding to the database to be queried includes: obtaining structured query language statements used for data query in historical interaction data of the database to be queried, and obtaining historical structured query language statements, wherein data query includes: multi-table query; using a large language model to generate natural language question texts corresponding to the historical structured query language statements, and verifying and correcting the natural language question texts generated by the large language model; and constructing a sample data set based on the historical structured query language statements and the corrected natural language question texts.

[0010] Optionally, based on the similarity score, determining the target node in each graph node of the knowledge graph includes: using a target model to convert the user question text into a first vector representation, and converting the graph node into a second vector representation, wherein the second vector representation is determined by the attribute corresponding to the graph node, and the target model is trained based on multiple training sample pairs, and the training sample pairs are determined by standard fields extracted from a sample data set, and graph nodes corresponding to the knowledge graph and the standard fields; determining the similarity score between the first vector representation and the second vector representation, and determining the graph node whose similarity score is greater than a preset similarity threshold as the target node.

[0011] Optionally, using a large language model to generate a structured query language statement corresponding to the user question text based on database schema information includes: reconstructing the database schema information corresponding to the database to be queried based on the structural information and corresponding dependency relationship with the target node in the knowledge graph, wherein the database schema information is used to limit the scope of generation of the structured query language statement; using a large language model to determine knowledge based on the reconstructed database schema information, the user question text, and instruction information, wherein the knowledge is used to characterize the association relationship between the user question text and the database schema information, and the instruction information is used to indicate the task that the large language model needs to complete; using a large language model to generate a structured query language statement corresponding to the user question text based on the reconstructed database schema information, knowledge, and the user question text.

[0012] Optionally, the method also includes: determining a target historical user query text in the historical user query text of the database to be queried, whose semantic similarity with the user question text is greater than a preset threshold; obtaining decoding process data of a structured query language statement corresponding to the target historical user query text; and using a large language model to generate a structured query language statement corresponding to the user question text based on reconstructed database model information, knowledge, user question text, target historical user query text, and decoding process data.

[0013] According to another aspect of the embodiment of the present application, a database query device is also provided, including: a knowledge graph construction module, used to determine the knowledge graph corresponding to the database to be queried, wherein the knowledge graph is used to characterize the logical structure and association relationship of the data in the database to be queried; a knowledge selection module, used to determine the similarity score between the user question text and each graph node in the knowledge graph, and determine the target node in each graph node of the knowledge graph based on the similarity score, wherein the similarity score is used to characterize the degree of association between the graph node and the user question text; a large model decision module, used to generate database mode information corresponding to the database to be queried based on the target node, and use a large language model to generate a structured query language statement corresponding to the user question text based on the database mode information, wherein the structured query language statement is used to query data in the database to be queried.

[0014] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including: a memory and a processor, the processor being configured to run a program stored in the memory, wherein the database query method is executed when the program is run.

[0015] According to another aspect of the embodiments of the present application, a non-volatile storage medium is provided, the non-volatile storage medium includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the database query method by running the computer program.

[0016] According to another aspect of the embodiments of the present application, a computer program product is provided, including a computer program, which implements the steps of the database query method when the computer program is executed by a processor.

[0017] In an embodiment of the present application, a knowledge graph corresponding to the database to be queried is determined, wherein the knowledge graph is used to characterize the logical structure and association relationship of the data in the database to be queried; a similarity score between the user question text and each graph node in the knowledge graph is determined, and based on the similarity score, a target node is determined in each graph node of the knowledge graph, wherein the similarity score is used to characterize the degree of association between the graph node and the user question text; based on the target node, database schema information corresponding to the database to be queried is generated, and a large language model is used to generate a structured query language statement corresponding to the user question text based on the database schema information, wherein the structured query language statement is used to query the database to be queried. The method of querying data in the database is to structure the data content stored in the database and the defined database model into a knowledge graph, automatically establish the correlation between data, and then use the big model technology to automatically mine and update the hidden domain knowledge according to the system's interaction history, and update it to the knowledge graph, so as to build the correlation between the user's natural language query and the database knowledge. Finally, the knowledge in the knowledge graph is input into the big language model in the form of context, so as to achieve the purpose of converting the natural language proposed by the user into a general database query statement, thereby solving the technical problem of poor accuracy of using the big language model to generate database query statements due to the large amount of field information and complex relationships in the database. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0019] Figure 1 It is a hardware structure block diagram of a computer terminal (or electronic device) for implementing a method for database query provided in an embodiment of the present application;

[0020] Figure 2 It is a schematic diagram of a method flow of database query provided according to an embodiment of the present application;

[0021] Figure 3 It is a schematic diagram of a method flow of database query optimization based on scalable knowledge graph enhancement provided according to an embodiment of the present application;

[0022] Figure 4 It is a schematic diagram of a knowledge spectrum graph construction process provided according to an embodiment of the present application;

[0023] Figure 5 is a schematic diagram of a model structure of field retrieval provided according to an embodiment of the present application;

[0024] Figure 6 It is a schematic diagram of a knowledge generation and large model decision execution process provided according to an embodiment of the present application;

[0025] Figure 7 It is a structural diagram of a database query device provided according to an embodiment of the present application. DETAILED DESCRIPTION

[0026] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0027] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings 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 of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0028] In order to facilitate those skilled in the art to better understand the embodiments of the present application, some technical terms or nouns involved in the embodiments of the present application are explained as follows:

[0029] NLP (Natural Language Processing): is a subfield of artificial intelligence (AI) that is dedicated to enabling computers to understand, process, and generate human language.

[0030] LLM (Large Language Model): commonly known as large model, large language model, is an artificial intelligence model designed to understand and generate human language. It is usually trained on a large amount of text data and can perform a wide range of tasks, including text summarization, translation, sentiment analysis, etc., and contains billions of parameters.

[0031] Pipeline: It is a commonly used technical method to organize multiple tasks in a certain order to form a processing flow. Each task receives input data in turn, generates output results, and then passes the output to the next task as its input.

[0032] Knowledge Graph: It is a technical method in the field of artificial intelligence, which is used to represent the semantic network structure of the relationship between entities. It is a semantic graph containing a large number of entities (such as people, places, things, etc.) and the relationships between them. The goal of the knowledge graph is to capture and organize structured information about the world so that computers can better understand language and make inferences. It is often used in applications such as natural language understanding, question-answering systems, and information retrieval, which can help computers understand semantics more accurately and extract and organize knowledge from text.

[0033] TEXT-to-SQL (Natural Language Text to Database Structured Query): is a technology in the field of natural language processing, which is used to convert natural language questions or instructions into structured query language (SQL). The goal of this technology is to enable computers to understand database query requirements described by humans in natural language and convert them into SQL query statements that can be executed directly on the database. Usually, this requires a combination of language models, grammatical analysis, semantic parsing, and knowledge of database schemas. The application areas of TEXT-to-SQL technology include automatic question-answering systems, intelligent improvements to database query interfaces, and semantic search.

[0034] Schema: In the database field, a schema is a logical concept used to organize objects in a database. Objects in a schema usually include tables, indexes, data types, sequences, stored procedures, primary keys, and foreign keys.

[0035] In the related technology, the current mainstream technical method usually inputs the schema information in the database (including table creation statements and primary and foreign keys, etc.) as context information into the big model, establishes the association between the big model and the database knowledge, and then uses the small sample learning method to guide the big model to generate SQL statements. However, since the field information in the database is usually relatively large, and the relationship between fields and fields, as well as between fields and values ​​is complex, there is a problem of poor accuracy of SQL statements generated using the big language model.

[0036] In order to solve the above problems, a relevant solution is provided in the embodiment of the present application. By constructing a knowledge graph of the database, the information such as tables, fields, primary and foreign key relationships in the database can be represented in the form of a graph, making this information more intuitive and easy to understand. The knowledge graph can not only show the relationship between fields, but also capture the association between fields and specific values, thereby providing richer and more accurate context information for the large model. In specific applications, the knowledge graph is used in combination with the large model. First, the database model information is preprocessed through the knowledge graph to extract key structured information. Then, this information is provided to the large model as additional input to help it better understand the structure of the database and the relationship between fields. In the process of generating SQL, the large model can use the information in the knowledge graph for reasoning and verification, thereby improving the accuracy and reliability of the generated SQL.

[0037] In addition, knowledge graphs can also be used to enhance the learning process of large models. By adding more semantic information and rules to the knowledge graph, the large model can be guided to better understand the intent of natural language queries and generate SQL queries that better meet user needs. This combination can not only improve the performance of the large model, but also make it more efficient and accurate when processing complex database queries.

[0038] Knowledge graphs can provide important auxiliary functions in the process of converting natural language text into database queries. By combining knowledge graphs with large models and graph recall technology, we can effectively solve the problem of numerous field information and complex relationships, improve the accuracy and reliability of SQL generation, and provide users with a better query experience. The following is a detailed description of this application solution.

[0039] According to an embodiment of the present application, a method embodiment of a database query is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0040] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Figure 1 FIG. 1 shows a hardware structure block diagram of a computer terminal (or electronic device) for implementing a database query method. Figure 1As shown, the computer terminal 10 (or electronic device) may include one or more (102a, 102b, ..., 102n are used to illustrate) processors 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 104 for storing data, and a transmission device 106 for communication functions. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the BUS bus), a network interface, a power supply and / or a camera. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations shown.

[0041] It should be noted that the one or more processors 102 and / or other data processing circuits described above may generally be referred to herein as "data processing circuits". The data processing circuits may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated in whole or in part into any of the other components in the computer terminal 10 (or electronic device). As described in the embodiments of the present application, the data processing circuit acts as a processor control (e.g., selection of a variable resistor terminal path connected to an interface).

[0042] The memory 104 can be used to store software programs and modules of application software, such as program instructions / data storage devices corresponding to the database query method in the embodiment of the present application. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, that is, realizing the above-mentioned database query method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the computer terminal 10 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.

[0043] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the computer terminal 10. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0044] The display may be, for example, a touch screen liquid crystal display (LCD) that enables a user to interact with a user interface of the computer terminal 10 (or electronic device).

[0045] In the above operating environment, the embodiment of the present application provides a database query method. Figure 2 is a schematic diagram of a database query method flow provided according to an embodiment of the present application, such as Figure 2 As shown, the method comprises the following steps:

[0046] Step S202, determining a knowledge graph corresponding to the database to be queried, wherein the knowledge graph is used to represent the logical structure and association relationship of the data in the database to be queried;

[0047] Step S204, determining the similarity score between the user question text and each graph node in the knowledge graph, and determining the target node in each graph node of the knowledge graph based on the similarity score, wherein the similarity score is used to characterize the degree of association between the graph node and the user question text;

[0048] Step S206, based on the target node, database schema information corresponding to the database to be queried is generated, and a large language model is used to generate a structured query language statement corresponding to the user question text based on the database schema information, wherein the structured query language statement is used to query data in the database to be queried.

[0049] Through the above steps, the stored data content and the defined database model in the database are structured and represented as a knowledge graph, the correlation between data is automatically established, and then the big model technology is used to automatically mine and update the hidden domain knowledge according to the system's interaction history, and update it to the knowledge graph, so as to build the correlation between the user's natural language query and the database knowledge. Finally, the knowledge in the knowledge graph is input into the big language model in the form of context, so as to achieve the purpose of converting the natural language proposed by the user into a general database query statement, thereby solving the technical problem of poor accuracy of the query statement generated by the big language model for the database due to the large amount of field information and complex relationships in the database.

[0050] The following further introduces the database query method in steps S202 to S206 of the embodiment of the present application.

[0051] The embodiment of this application combines knowledge graph and big model technology to build a general knowledge understanding optimization method for generating SQL from text, converts the pattern information in the database into a knowledge graph, and redefines a general database model that is well adapted to the big model input. It can be applied to any relational database and has strong scalability. Through graph retrieval and dense retrieval technology, fields and tables that are highly relevant to user queries can be obtained from the knowledge graph, thereby filtering out the interference of irrelevant information on SQL generation, greatly reducing the length of the big model input context, effectively saving resources, and improving the accuracy and reliability of SQL generation. Figure 3 is a schematic diagram of a method flow for database query optimization based on scalable knowledge graph enhancement provided in an embodiment of the present application, such as Figure 3 As shown, first, the database model is combined to construct and complete the knowledge graph. Secondly, the dense retrieval model is used to select knowledge. Finally, the large model is used to complete the generation of knowledge and SQL. The details are introduced below.

[0052] First, construct a knowledge graph, that is, determine the knowledge graph corresponding to the database to be queried. In this embodiment, the data source for the knowledge graph construction is the original schema of the database and the stored data details. By constructing the knowledge graph, the correlation between different knowledge in the database can be established, which is helpful for the reconstruction and utilization of knowledge in subsequent stages. The specific steps are as follows.

[0053] In some embodiments of the present application, determining the knowledge graph corresponding to the database to be queried includes the following steps: generating a knowledge graph corresponding to the database to be queried by traversing the data tables in the database to be queried, wherein the knowledge graph is composed of multiple graph nodes and edges between graph nodes, each graph node corresponds to an entity, and the entities include: table entity and column entity, the attributes corresponding to the table entity include: table name, table description, the attributes corresponding to the column entity include: column name, column description, data type, example value, value meaning, each edge is used to represent the association relationship between the two graphs it connects, and the association relationship includes: relationship between tables, inclusion relationship between tables and columns, and foreign key relationship.

[0054] Specifically, a knowledge graph can be constructed based on the table structure and column information. In the embodiment of the present application, the constructed knowledge graph is mainly composed of two key entity types, namely table entity (Table) and column entity (Column). The former is composed of "Table Name" and "Table Description" as table entity attributes, and the latter is composed of "Column Name" (Column Name), "Column Description" (Column Description), "Data Type" (Data Type), "Example Value" (Example Value) and "Value Explanation / Value Meaning" (Value Explanation) as column entity attributes.

[0055] In addition, the associations between entities include but are not limited to: relationships between tables, inclusion relationships between tables and columns, and foreign key relationships. Metadata (i.e., the above-mentioned entity types and relationship categories) can be extracted by using different database operations to obtain structured database information to build a knowledge graph.

[0056] At the same time, in order to effectively store and query the constructed knowledge graph, in this embodiment, graph database technology can be used (for example, Neo4j can be used as an implementation tool for the graph database) to convert the extracted metadata into nodes and edges of the graph database, where table entities and column entities are stored as nodes respectively, and the attributes of the nodes correspond to the attributes of the tables and columns; the relationships between tables, the inclusion relationships between tables and columns, and the foreign key relationships are stored as edges, and the types and attributes of the edges are used to reflect the specific content of the relationships. The graph database can naturally represent entities and their relationships, and is efficient in processing complex queries, and can conveniently perform graph data storage, update, and query operations.

[0057] The embodiment of the present application constructs a knowledge graph to structure the table knowledge, field knowledge and dependency relationships in the database. In subsequent solutions, the key knowledge obtained from the knowledge base based on user questions can be reorganized into a common database model to assist in SQL generation.

[0058] In actual implementation scenarios, due to the different scenarios involved, the entire content describing the database model information is not always fully provided when the database is manually constructed, which may cause the knowledge graph constructed by the above steps to be very sparse, and some functional dependencies between fields (such as formula calculations, numerical dependencies, etc.) cannot be provided. However, when people use databases to interact, the correlation between user questions and SQL usually requires high-quality associations of these dependencies. In view of this, in the embodiment of the present application, a large model can also be used to assist manual methods to complete the dynamic completion of the database, and the specific steps are as follows.

[0059] In some embodiments of the present application, after determining the knowledge graph corresponding to the database to be queried, the method also includes the following steps: obtaining a sample data set corresponding to the database to be queried, wherein the sample data set contains multiple historical structured query language statements and natural language question texts corresponding to the historical structured query language statements; using a large language model, based on the sample data set, determining target bigrams and target triples, wherein the target bigrams are used to characterize the correspondence between standard fields in the historical structured query language statements and the descriptive information in the natural language question text, each standard field corresponds to a column entity, and the target triples are used to characterize the dependency relationship between two standard fields; adding the information corresponding to the target bigrams and target triples to the knowledge graph.

[0060] Specifically, the construction process of the above sample data set is introduced, and the specific steps are as follows.

[0061] In some embodiments of the present application, obtaining a sample data set corresponding to a database to be queried includes the following steps: obtaining structured query language statements used for data query in historical interaction data of the database to be queried, and obtaining historical structured query language statements, wherein data query includes: multi-table query; using a large language model to generate a natural language question text corresponding to the historical structured query language statement, and verifying and correcting the natural language question text generated by the large language model; constructing a sample data set based on the historical structured query language statement and the corrected natural language question text.

[0062] Specifically, 10,000 SQL statements involving multi-table queries and responsible queries (i.e., the above-mentioned historical structured query language statements) can be filtered out from the historical interaction data of the database to be queried through rule functions, and then the historical SQL statements and database model information are input into a large language model (e.g., GPT4) as context, and the large language model is guided to output the user's natural language questions that the historical SQL statements may correspond to (i.e., the above-mentioned natural language question text), wherein the output of the large language model will correspond one-to-one to the input historical SQL statements, and then professional database operators can manually verify the output pre-labeled data (i.e., the natural language question text corresponding to the historical structured query language statements), re-modify the natural language expression, and finally the modified natural language text and SQL statements will be used as the initial information to complete the data knowledge graph (i.e., the above-mentioned sample data set).

[0063] After obtaining the sample data set, the large language model can be used to determine the target bigrams and target triples based on the sample data set. Specifically, the simulated user question question (i.e. the above-mentioned natural language question text), historical SQL statements, and the original database schema are input into the large model together, and the large model is allowed to extract the attribute description of the field: the standard field in the historical SQL statement is matched with the natural language question text to form a bigram attribute = {columnname, desc}, where desc represents the description information about the field corresponding to column name extracted from the natural language question text; and the large model can also extract the triple relationship = {column name1, dependency, column name2}, which defines the specific dependency definition between two fields with a dependency relationship. Finally, column name and relationship will be updated as completed information to the knowledge graph and the large model. Through knowledge graph completion, more field dependencies are established, and the attribute information of the field is enriched, which is helpful for the subsequent use of the retrieval model for semantic matching and provides richer knowledge.

[0064] The embodiment of the present application adopts a paradigm combining knowledge graph and big model, reconstructing the isolated data content and structural information in the database into a graph storage form, which can effectively mine the dependencies in the pattern. Using big model technology, the knowledge graph can be automatically completed according to the system interaction history, and it can automatically adapt to the changes in the database model, reducing the need for manual intervention. Through the self-learning ability of the big model, the system can continuously optimize and update the knowledge graph and maintain efficient support for the latest data and patterns.

[0065] The following is an example to illustrate the process of constructing and completing the above knowledge graph.

[0066] like Figure 4 As shown, the database structure and data details involved in the embodiment of the present application are all stored in files ending with ".sqlite". First, use the program to traverse all the database and its subordinate table names in the library file, and then use the standard database operation statements corresponding to SQLite to extract the field names and related attribute values ​​involved to form a candidate set. Finally, use Neo4j to convert it into a knowledge graph structure.

[0067] After constructing and completing the knowledge graph, the knowledge based on the general knowledge base can be easily managed and maintained, but the database information closely related to the user's question has not been identified. Therefore, in an embodiment of the present application, a dense retrieval model can be used to recall knowledge closely related to the user's question text from a large number of knowledge graph nodes to construct a new general database model, that is, to determine the target node in each graph node of the knowledge graph. The specific steps are as follows.

[0068] In some embodiments of the present application, determining a target node in each graph node of a knowledge graph based on a similarity score includes the following steps: using a target model to convert a user question text into a first vector representation, and converting a graph node into a second vector representation, wherein the second vector representation is determined by an attribute corresponding to the graph node, and the target model is trained based on multiple training sample pairs, and the training sample pairs are determined by standard fields extracted from a sample data set, and graph nodes corresponding to the knowledge graph and the standard fields; determining a similarity score between the first vector representation and the second vector representation, and determining a graph node having a similarity score greater than a preset similarity threshold as a target node.

[0069] Specifically, knowledge retrieval training data is first constructed: the 10,000 user questions and SQL statement question-answer pairs collected in the early stage (that is, the data in the above sample data set) can be used as the initial data, and the tables and field names involved in the historical SQL statements (that is, the above standard fields) are extracted through rule functions, and then the corresponding node n (including node information and attribute values: field name, field description, value sample, value description, related information, etc.) is queried from the database or knowledge graph, and then the user question q and the extracted multiple nodes are respectively used to form multiple training sample pairs {(q, n1), (q, n2)...} for training.

[0070] After that, the knowledge retrieval model (i.e., the target model mentioned above) can be constructed. Specifically, the pre-trained language model (BERT) can be selected as the underlying semantic encoder to represent the user question text and graph nodes, and then the post-interaction method MaxSim based on maximum similarity is used to calculate the similarity score between the user question q and the graph node c, and the degree of association between the table and the node is determined by the similarity score. The specific calculation formula is as follows:

[0071] O q =Normalize(CNN(BERT Q (q))

[0072] O c =Normalize(CNN(BERT C (c))

[0073]

[0074] Among them, O q and O c It is the vector representation encoded by the dual-tower model, corresponding to the first vector representation and the second vector representation mentioned above respectively. Score represents the similarity score between the user question text and the current graph node. By setting the similarity threshold, the target node can be screened.

[0075] Afterwards, new database schema information can be redefined based on the filtered knowledge graph nodes (i.e., target nodes) and provided as context to the large model for SQL generation.

[0076] The embodiment of the present application adopts dense retrieval technology, which can efficiently find fields and tables related to user queries on large-scale complex knowledge graphs. By calculating the similarity in the vector space, irrelevant information can be quickly filtered out, thereby improving the accuracy and efficiency of SQL generation.

[0077] The following is an example to illustrate the above knowledge selection process.

[0078] like Figure 5 As shown, in the embodiment of the present application, the dual-tower model can be used to retrieve the fields most relevant to the current question from the knowledge graph, and then the graph tool can be used to determine the table to which the current field belongs. The knowledge retriever is trained based on ColBERT. First, according to all the field names in the database table, the entity links in the knowledge graph and converts the corresponding representation of the entity into: {n = n name ||n description ||c example ||c explanation}, and finally, the knowledge representations of the user query and the field entity are input into the field retriever to calculate the similarity. By setting the score threshold μ, the field entity with a similarity score greater than μ to the user query will be retained as a disambiguated entity, otherwise it will be discarded.

[0079] After selecting the target nodes with high relevance to the user's question text from the knowledge graph, the big model decision can be made. When making a big model decision, the relevant fields, tables and dependencies can be retrieved from the knowledge graph first, a new database model can be constructed, and knowledge associations can be generated. This information is input into the big model as context, and the thinking chain model is used to automatically split the SQL generation process into multiple sub-problems. These sub-problems are gradually generated from the simple to the complex, that is, based on the target node, the database model information corresponding to the database to be queried is generated, and the big language model is used to generate the structured query language statement corresponding to the user's question text based on the database model information. The specific steps are as follows.

[0080] In some embodiments of the present application, a large language model is used to generate a structured query language statement corresponding to a user question text based on database schema information, including the following steps: reconstructing the database schema information corresponding to the database to be queried based on the structural information and corresponding dependency relationship with the target node in the knowledge graph, wherein the database schema information is used to limit the scope of generation of the structured query language statement; using a large language model, based on the reconstructed database schema information, the user question text, and instruction information, determining knowledge, wherein the knowledge is used to characterize the association relationship between the user question text and the database schema information, and the instruction information is used to indicate the task that the large language model needs to complete; using a large language model, based on the reconstructed database schema information, knowledge, and the user question text, generating a structured query language statement corresponding to the user question text.

[0081] In some embodiments of the present application, the method also includes: determining a target historical user query text in the historical user query text of the database to be queried, whose semantic similarity with the user question text is greater than a preset threshold; obtaining decoding process data of a structured query language statement corresponding to the target historical user query text; and using a large language model to generate a structured query language statement corresponding to the user question text based on reconstructed database model information, knowledge, user question text, target historical user query text, and decoding process data.

[0082] Specifically, a knowledge generation prompt can be designed to guide the big model to output the knowledge description between the current user question and the new database model. In this embodiment, the prompt of the big model decision consists of five parts, including: instruction information, database model information, knowledge, small sample (i.e., the decoding process data of the structured query language statement corresponding to the above-mentioned target historical user query text) and user query (i.e., the above-mentioned user question text).

[0083] Among them, the instruction information is used to clarify the tasks and precautions that the big model currently needs to complete; the database schema information part uses the knowledge graph to screen out high-value tables and fields, and expresses them in a structured form to limit the scope of SQL generation; the knowledge part is used to establish an association between the user query (user question text) and the database (database schema information), and provide a definition of the field to help the big model understand the meaning of the field; the small sample part uses the small sample screening module to screen out multiple historical user queries and their SQL decoding processes that are semantically similar to the current user query, that is, to determine the target historical user query text in the historical user query text of the database to be queried, whose semantic similarity with the user question text is greater than the preset threshold, and obtain the decoding process data of the structured query language statement corresponding to the target historical user query text; the user query (user question text) part is used to clarify the user's current query problem.

[0084] In the embodiment of the present application, the big model module is flexible and universal, and there is no restriction on the construction form and model structure of the big model. If there are corresponding machine resources, the model can be fine-tuned by constructing the input prompt of the big model and the correct SQL output to form a training sample, or it can be directly generated by directly inputting the user's prompt through the online service of the big model or using the form of open source big model reasoning. By learning the database model, knowledge and small samples, the big model divides the user query into multiple sub-questions, and generates the SQL of the complete question in the last sub-step.

[0085] The following is an example to illustrate the above process of knowledge generation and large model decision-making.

[0086] Take the user question "Please provide the names of schools that meet the following conditions: the number of candidates with free meal eligibility in K-12 stage exceeding 0.1 and scores exceeding 1500 points" as an example. Figure 6 As shown, in this embodiment, the recalled fields in the knowledge graph and their related tables and dependencies in the graph can first be reorganized into a "schema reconstructed based on the knowledge graph" through knowledge selection; then, the user's question and the reconstructed schema are used as input information, and the instruction information is spliced ​​together as prompt words to input into the large model.

[0087] The big model understands and executes the above instruction information, and outputs the knowledge that associates the user question with the schema to obtain the generated knowledge clues. Finally, the reconstructed schema, knowledge, user question and other information are used as context, and the big model is prompted: "Please understand the knowledge of the data based on the provided information, and divide the user's question into multiple sub-questions, solve the sub-questions in turn, and finally generate SQL." Finally, through the output of the big model, the SQL query "SELECT T2.`School Name`FROM satscores AS T1 INNER JOIN frpm AS T2 ON T1.cds=T2.CDSCode WHERE CAST(T2.`Free Meal Count(K-12)`AS REAL) / T2.`Enrollment(K-12)`>0.1AND T1.NumGE1500>0" is parsed.

[0088] In addition, after generating the SQL statement corresponding to the user's question text, the generated SQL statement and the corresponding user question text will be stored as historical information, and the correctness of the SQL will be verified by database professionals. If the SQL matches the user's question and is executed correctly, it will be stored in the historical dependency library. Then, the <question, SQL> pair is traversed regularly from it to extract knowledge using the large model, thereby updating the knowledge graph.

[0089] This application proposes an SQL data retrieval optimization solution that combines knowledge graph, dense retrieval and large model technology. Focusing on the problem that data knowledge acquisition in database intelligent data retrieval scenarios is difficult, it is difficult to provide effective knowledge understanding for large models, resulting in inaccurate SQL generation, and provides a pluggable and easy-to-operate intelligent data retrieval SQL generation solution, and actually puts it into intelligent data retrieval production scenarios.

[0090] By constructing a knowledge graph based on the database, the structural information and value information of the database are used as edges, nodes and attribute values ​​in the knowledge graph. Through the graph structure, the relationship between various knowledge is cleverly established, and knowledge is easy to maintain and select. By constructing a knowledge graph, the characteristics of table data can be learned for different business scenarios to help the model understand the table information, and useful information can be mined from historical conversations in the database to further improve the adaptability of business scenarios.

[0091] Based on dense retrieval technology, the fields and user questions in the knowledge graph are represented as high-dimensional vectors. The similarity between vectors can be used to retrieve tables and fields that are highly relevant to user questions from the perspective of semantic space, which can quickly realize the recall and disambiguation of graph knowledge. Before generating SQL, the table field information that may be involved is extracted from the knowledge graph, and the potential knowledge content is retrieved through the association relationship between different nodes in the graph. The fields and table content related to user questions can be effectively obtained, thereby greatly reducing the interference of redundant fields on subsequent model decisions and improving the accuracy of SQL generation;

[0092] By combining the powerful semantic understanding ability of the big model, the association between data patterns and user questions can be automatically extracted based on the database interaction history, which greatly enriches the completeness of the knowledge graph and can provide more knowledge sources for SQL generation; based on the generation method of the big model, SQL generation can be completed intelligently based on user input. Due to the prompt information of the big model, background knowledge can be integrated into the learning and generation process of the model, reducing the information loss caused by indirect knowledge transfer. The generative process can dynamically and intelligently generate query statements based on user input.

[0093] In addition, the present application solution is based on a general database data retrieval process, and can flexibly choose whether to add a knowledge expansion module according to different application scenarios and database settings, and has high scalability.

[0094] According to an embodiment of the present application, an embodiment of a database query device is also provided. Figure 7 Schematic diagram of a database query device provided according to an embodiment of the present application. Figure 7 As shown, the device comprises:

[0095] A knowledge graph construction module 70 is used to determine the knowledge graph corresponding to the database to be queried, wherein the knowledge graph is used to represent the logical structure and association relationship of the data in the database to be queried;

[0096] The knowledge selection module 72 is used to determine the similarity score between the user question text and each graph node in the knowledge graph, and determine the target node in each graph node of the knowledge graph according to the similarity score, wherein the similarity score is used to characterize the degree of association between the graph node and the user question text;

[0097] The large model decision module 74 is used to generate database model information corresponding to the database to be queried based on the target node, and use the large language model to generate a structured query language statement corresponding to the user question text based on the database model information, wherein the structured query language statement is used to query data in the database to be queried.

[0098] Optionally, determining the knowledge graph corresponding to the database to be queried includes: generating a knowledge graph corresponding to the database to be queried by traversing the data tables in the database to be queried, wherein the knowledge graph is composed of multiple graph nodes and edges between graph nodes, each graph node corresponds to an entity, and the entities include: table entity and column entity, the attributes corresponding to the table entity include: table name, table description, the attributes corresponding to the column entity include: column name, column description, data type, example value, value meaning, each edge is used to represent the association relationship between the two graphs it connects, and the association relationship includes: relationship between tables, inclusion relationship between tables and columns, and foreign key relationship.

[0099] Optionally, after determining the knowledge graph corresponding to the database to be queried, the knowledge graph construction module 70 is also used to: obtain a sample data set corresponding to the database to be queried, wherein the sample data set contains multiple historical structured query language statements, and natural language question texts corresponding to the historical structured query language statements; use a large language model to determine target bigrams and target triples based on the sample data set, wherein the target bigrams are used to characterize the correspondence between standard fields in the historical structured query language statements and the descriptive information in the natural language question text, each standard field corresponds to a column entity, and the target triples are used to characterize the dependency relationship between two standard fields; and add the information corresponding to the target bigrams and target triples to the knowledge graph.

[0100] Optionally, obtaining a sample data set corresponding to the database to be queried includes: obtaining structured query language statements used for data query in historical interaction data of the database to be queried, and obtaining historical structured query language statements, wherein data query includes: multi-table query; using a large language model to generate natural language question texts corresponding to the historical structured query language statements, and verifying and correcting the natural language question texts generated by the large language model; and constructing a sample data set based on the historical structured query language statements and the corrected natural language question texts.

[0101] Optionally, based on the similarity score, determining the target node in each graph node of the knowledge graph includes: using a target model to convert the user question text into a first vector representation, and converting the graph node into a second vector representation, wherein the second vector representation is determined by the attribute corresponding to the graph node, and the target model is trained based on multiple training sample pairs, and the training sample pairs are determined by standard fields extracted from a sample data set, and graph nodes corresponding to the knowledge graph and the standard fields; determining the similarity score between the first vector representation and the second vector representation, and determining the graph node whose similarity score is greater than a preset similarity threshold as the target node.

[0102] Optionally, using a large language model to generate a structured query language statement corresponding to the user question text based on database schema information includes: reconstructing the database schema information corresponding to the database to be queried based on the structural information and corresponding dependency relationship with the target node in the knowledge graph, wherein the database schema information is used to limit the scope of generation of the structured query language statement; using a large language model to determine knowledge based on the reconstructed database schema information, the user question text, and instruction information, wherein the knowledge is used to characterize the association relationship between the user question text and the database schema information, and the instruction information is used to indicate the task that the large language model needs to complete; using a large language model to generate a structured query language statement corresponding to the user question text based on the reconstructed database schema information, knowledge, and the user question text.

[0103] Optionally, the large model decision module 74 is also used to: determine a target historical user query text in the historical user query text of the database to be queried, whose semantic similarity with the user question text is greater than a preset threshold; obtain decoding process data of a structured query language statement corresponding to the target historical user query text; and use a large language model to generate a structured query language statement corresponding to the user question text based on reconstructed database model information, knowledge, user question text, target historical user query text, and decoding process data.

[0104] It should be noted that the various modules in the above-mentioned database query device can be program modules (for example, a set of program instructions that implement a certain specific function) or hardware modules. For the latter, it can be expressed in the following forms, but is not limited to this: the expression form of each of the above-mentioned modules is a processor, or the functions of each of the above-mentioned modules are implemented by a processor.

[0105] It should be noted that the database query device provided in this embodiment can be used to execute Figure 2 The database query method shown, therefore, the relevant explanations and instructions on the above database query method are also applicable to the embodiments of the present application and will not be repeated here.

[0106] An embodiment of the present application also provides a non-volatile storage medium, the non-volatile storage medium includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the following database query method by running the computer program: determining a knowledge graph corresponding to the database to be queried, wherein the knowledge graph is used to characterize the logical structure and association relationship of the data in the database to be queried; determining a similarity score between a user question text and each graph node in the knowledge graph, and determining a target node in each graph node of the knowledge graph based on the similarity score, wherein the similarity score is used to characterize the degree of association between the graph node and the user question text; generating database model information corresponding to the database to be queried based on the target node, and using a large language model, generating a structured query language statement corresponding to the user question text based on the database model information, wherein the structured query language statement is used to query data in the database to be queried.

[0107] The embodiments of the present application also provide a computer program product, including a computer program, which, when executed by a processor, implements the steps of the database query method described in each embodiment of the present application: determining a knowledge graph corresponding to the database to be queried, wherein the knowledge graph is used to characterize the logical structure and association relationship of the data in the database to be queried; determining a similarity score between the user question text and each graph node in the knowledge graph, and based on the similarity score, determining a target node in each graph node of the knowledge graph, wherein the similarity score is used to characterize the degree of association between the graph node and the user question text; based on the target node, generating database model information corresponding to the database to be queried, and using a large language model, generating a structured query language statement corresponding to the user question text based on the database model information, wherein the structured query language statement is used to query data in the database to be queried.

[0108] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0109] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0110] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units can be a logical function division. There may be other division methods in actual implementation. For example, 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 through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0111] 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 units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0112] 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.

[0113] 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, in essence, 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, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, disk or optical disk and other media that can store program codes.

[0114] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A database query method, characterized in that: include: Determine a knowledge graph corresponding to the database to be queried, wherein the knowledge graph is used to represent the logical structure and association relationship of the data in the database to be queried; Determine a similarity score between the user question text and each graph node in the knowledge graph, and determine a target node in each graph node in the knowledge graph based on the similarity score, wherein the similarity score is used to characterize the degree of association between the graph node and the user question text; According to the target node, database schema information corresponding to the database to be queried is generated, and a large language model is used to generate a structured query language statement corresponding to the user question text according to the database schema information, including: reconstructing the database schema information corresponding to the database to be queried according to the structural information and the corresponding dependency relationship with the target node in the knowledge graph, wherein the database schema information is used to limit the scope of generation of the structured query language statement; using a large language model, based on the reconstructed database schema information, the user question text, and instruction information, determining knowledge, wherein the knowledge is used to characterize the association relationship between the user question text and the database schema information, and the instruction information is used to indicate the task that the large language model needs to complete; using a large language model, based on the reconstructed database schema information, the knowledge, and the user question text, generating the structured query language statement corresponding to the user question text, wherein the structured query language statement is used to query data in the database to be queried.

2. The database query method according to claim 1, characterized in that: Determine the knowledge graph corresponding to the database to be queried including: By traversing the data tables in the database to be queried, the knowledge graph corresponding to the database to be queried is generated, wherein the knowledge graph is composed of a plurality of graph nodes and edges between the graph nodes, each of the graph nodes corresponds to an entity, and the entities include: table entity and column entity, the attributes corresponding to the table entity include: table name, table description, the attributes corresponding to the column entity include: column name, column description, data type, example value, value meaning, each edge is used to represent the association relationship between the two graphs it connects, and the association relationship includes: relationship between tables, inclusion relationship between tables and columns, and foreign key relationship.

3. The database query method according to claim 2, characterized in that: After determining the knowledge graph corresponding to the database to be queried, the method further includes: Acquire a sample data set corresponding to the database to be queried, wherein the sample data set includes a plurality of historical structured query language statements and natural language question texts corresponding to the historical structured query language statements; Using a large language model, according to the sample data set, a target bigram and a target triple are determined, wherein the target bigram is used to characterize the corresponding relationship between the standard field in the historical structured query language statement and the description information in the natural language question text, each of the standard fields corresponds to one of the column entities, and the target triple is used to characterize the dependency relationship between two of the standard fields; The information corresponding to the target bigram and the target triplet is added to the knowledge graph.

4. The database query method according to claim 3, characterized in that: Acquiring a sample data set corresponding to the database to be queried includes: Acquire a structured query language statement for data query in the historical interaction data of the database to be queried, and obtain the historical structured query language statement, wherein the data query includes: multi-table query; Using a large language model, generating the natural language question text corresponding to the historical structured query language statement, and verifying and correcting the natural language question text generated by the large language model; The sample data set is constructed based on the historical structured query language statements and the corrected natural language question text.

5. The database query method according to claim 4, characterized in that: Determining a target node in each graph node of the knowledge graph according to the similarity score includes: Using a target model, converting the user question text into a first vector representation, and converting the graph node into a second vector representation, wherein the second vector representation is determined by an attribute corresponding to the graph node, and the target model is trained based on a plurality of training sample pairs, wherein the training sample pairs are determined by the standard field extracted from the sample data set, and the graph node corresponding to the knowledge graph and the standard field; The similarity score between the first vector representation and the second vector representation is determined, and the graph node whose similarity score is greater than a preset similarity threshold is determined as the target node.

6. The database query method according to claim 1, characterized in that: The method further comprises: Determine a target historical user query text whose semantic similarity with the user question text is greater than a preset threshold among the historical user query texts in the to-be-queried database; Obtaining decoding process data of the structured query language sentence corresponding to the target historical user query text; A large language model is adopted to generate the structured query language statement corresponding to the user question text according to the reconstructed database schema information, the knowledge, the user question text, the target historical user query text, and the decoding process data.

7. A database query device, characterized in that: include: A knowledge graph construction module, used to determine the knowledge graph corresponding to the database to be queried, wherein the knowledge graph is used to characterize the logical structure and association relationship of the data in the database to be queried; A knowledge selection module, used to determine a similarity score between the user question text and each graph node in the knowledge graph, and determine a target node in each graph node of the knowledge graph according to the similarity score, wherein the similarity score is used to characterize the degree of association between the graph node and the user question text; A large model decision module is used to generate database mode information corresponding to the database to be queried based on the target node, and to use a large language model to generate a structured query language statement corresponding to the user question text based on the database mode information, including: reconstructing the database mode information corresponding to the database to be queried based on the structural information and corresponding dependency relationship with the target node in the knowledge graph, wherein the database mode information is used to limit the scope of generation of the structured query language statement; using a large language model to determine knowledge based on the reconstructed database mode information, the user question text, and instruction information, wherein the knowledge is used to characterize the association relationship between the user question text and the database mode information, and the instruction information is used to indicate the task that the large language model needs to complete; using a large language model to generate the structured query language statement corresponding to the user question text based on the reconstructed database mode information, the knowledge, and the user question text, wherein the structured query language statement is used to query data in the database to be queried.

8. An electronic device, characterized in that: include: A memory and a processor, wherein the processor is used to run a program stored in the memory, wherein the program executes the database query method described in any one of claims 1 to 6 when running.

9. A non-volatile storage medium, characterized in that: The non-volatile storage medium includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the database query method according to any one of claims 1 to 6 by running the computer program.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the database query method described in any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Question answering system based on large language model and knowledge graph, construction method of question answering system and intelligent data governance platform

    CN117609470A

  • Method for converting full-link natural language into structured query language

    CN118227653A