Database statement generation method and device, storage medium and electronic equipment

By generating database statements through a vector database and a generative model, the problem of low database data search accuracy is solved, the conversion of natural language text to database statements is realized, and the accuracy of data search is improved.

CN120705173APending Publication Date: 2025-09-26BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410354315.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-03-26
Publication Date
2025-09-26

AI Technical Summary

Technical Problem

In the prior art, the accuracy of database data search is low. In particular, for personnel who are not familiar with database operations, they are unable to input accurate search statements, resulting in low accuracy of data search.

Method used

By obtaining the natural language text in the target instructions, the target database statements are generated using the vector database and the generation model, and the accurate database query statements are generated by combining the description information of the target library and table.

Benefits of technology

Improves the accuracy of database data search, allowing users to search for data through natural language text without having to master complex database statements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120705173A_ABST
    Figure CN120705173A_ABST
Patent Text Reader

Abstract

The invention relates to a database statement generation method and device, a storage medium and electronic equipment. The method comprises the steps that under the condition that a target text is obtained, the target text is input into a vector database, similar texts of the target text and first database statements of the similar texts are obtained, the vector database comprises a plurality of texts, each text corresponds to a database statement, and the first database statements correspond to the similar texts; the similar text is the text with the highest similarity with the target text; and inputting the target text, the library table description of the target library and the target table and the first database statement into a generative model to obtain a target database statement output by the generative model so as to query target data in the target library and the target table through the target database statement. The technical problem of low database data search accuracy is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of databases, and in particular to a method, device, storage medium, and electronic device for generating database statements. Background Art

[0002] In the prior art, data in a database can be searched using database statements. However, operators who are not familiar with the database may not be able to enter accurate search statements or determine the correct search fields, resulting in low accuracy in the data found when searching the database. Summary of the Invention

[0003] The present application provides a database statement generation method, device, storage medium and electronic device to solve the technical problem of low database data search accuracy.

[0004] In the first aspect, the present application provides a database statement generation method, comprising: when a target instruction is obtained, obtaining a target text from the target instruction, inputting the above target text into a vector database, obtaining similar text of the above target text and a first database statement of the above similar text, wherein the above target text is a natural language text, the above vector database includes multiple texts, each text corresponds to a database statement, and the above similar text is the text with the highest similarity to the above target text; inputting the above target text, the library and table description of the target library and target table and the above first database statement into a generation model, obtaining the target database statement output by the above generation model, so as to query the above target data in the above target library and target table through the above target database statement; returning the queried target data to the client that sent the target instruction.

[0005] In the second aspect, the present application provides a database statement generation device, including: an acquisition module, used to obtain a target text from the target instruction when a target instruction is obtained; a first input module, used to input the above-mentioned target text into a vector database, and obtain similar text of the above-mentioned target text and a first database statement of the above-mentioned similar text, wherein the above-mentioned target text is a natural language text, and the above-mentioned vector database includes multiple texts, each text corresponds to a database statement, and the above-mentioned similar text is the text with the highest similarity to the above-mentioned target text; a second input module, used to input the above-mentioned target text, the library and table description of the target library and target table, and the above-mentioned first database statement into a generation model, and obtain the target database statement output by the above-mentioned generation model, so as to query the above-mentioned target data in the above-mentioned target library and target table through the above-mentioned target database statement; a sending module, used to return the queried target data to the client that sent the target instruction.

[0006] As an optional example, the above-mentioned device also includes: an error correction module, which is used to delete n-1 symbols among the above-mentioned consecutive symbols according to the context of the above-mentioned consecutive symbols before inputting the above-mentioned target text into the vector database, where the above-mentioned target text includes multiple consecutive symbols, wherein the above-mentioned n is the number of the above-mentioned consecutive symbols; perform an error correction operation on the above-mentioned target text after the symbols are deleted to obtain the above-mentioned target text after error correction.

[0007] As an optional example, the error correction module includes: an error correction unit for identifying typos in the target text after deleting symbols; replacing the typos with words that have the same pinyin as the typos but different texts; and using the replaced target text as the target text after error correction.

[0008] As an optional example, the above-mentioned first input module includes: a processing unit, used to convert the above-mentioned target text into a target vector; compare the above-mentioned target vector with the vectors in the above-mentioned vector database to determine the first vector with the highest similarity to the above-mentioned target vector from the above-mentioned vector database; determine the text corresponding to the above-mentioned first vector as the above-mentioned similar text, and determine the database statement corresponding to the above-mentioned first vector as the above-mentioned first database statement.

[0009] As an optional example, the above-mentioned second input module includes: an input unit, used to input the above-mentioned target text, the above-mentioned target library and the library table description of the above-mentioned target table, the above-mentioned first database statement and the additional statement into the above-mentioned generation model to obtain the target database statement output by the above-mentioned generation model, wherein the above-mentioned additional statement is a statement different from the above-mentioned first database statement.

[0010] As an optional example, the above-mentioned device also includes: a determination unit, which is used to determine the statement input by the above-mentioned user as the above-mentioned additional statement when providing an input interface to the user; or, to determine, from the additional statement library, a statement that matches the library table description of the above-mentioned target library and the above-mentioned target table as the above-mentioned additional statement.

[0011] As an optional example, the above-mentioned device also includes: a parsing module, which is used to parse the entities of the table name and column name in the above-mentioned target database statement after inputting the above-mentioned target text, the library and table descriptions of the target library and target table and the above-mentioned first database statement into the generation model to obtain the target database statement output by the above-mentioned generation model; when the name of the entity obtained by parsing is incorrect, find the target table name and target column name with the highest similarity to the above-mentioned table name and column name; and use the entities of the above-mentioned target table name and the above-mentioned target column name to replace the entities of the above-mentioned table name and column name.

[0012] As an optional example, the above-mentioned parsing module includes: a parsing unit, used to determine entities from all entities that have the same pinyin as the table name and the column name or contain the same text; and search for the target table name and target column name with the highest similarity to the table name and column name from the determined entities.

[0013] As an optional example, the above-mentioned device also includes: an acquisition module, used to obtain a selection instruction before obtaining the target text, wherein the above-mentioned selection instruction is used to select the above-mentioned target library and the above-mentioned target table to be queried for the above-mentioned target data; and determine the description information of the above-mentioned target library and the above-mentioned target table as the above-mentioned library table description.

[0014] In a third aspect, the present application provides an electronic device comprising: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor connected to the at least one bus; and at least one memory connected to the at least one bus, wherein the memory stores a computer program, and the processor is configured to implement any one of the above-mentioned database statement generation methods when executing the computer program.

[0015] In a fourth aspect, the present application further provides a computer storage medium storing computer executable instructions, wherein the computer executable instructions are used to execute any of the above-mentioned database statement generation methods of the present application.

[0016] The above-mentioned technical solution provided by the embodiment of the present application has the following advantages over the prior art: the solution provided by the embodiment of the present application can generate target database statements through natural language text, so that users can search for database data through natural language text without having to master complex database statements. By inputting the target text, similar text of the target text, and the first database statement of the similar text into the vector database, a database statement is obtained, and the database statement is used to query data, thereby improving the accuracy of database data search. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0018] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0019] One or more embodiments are exemplarily illustrated by pictures in the corresponding drawings. These exemplifications do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings are represented as similar elements. Unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0020] Figure 1 A flowchart of a method for generating a database statement provided in an embodiment of the present application;

[0021] Figure 2 A flowchart of another database statement generation method provided in an embodiment of the present application;

[0022] Figure 3 A flowchart of another database statement generation method provided in an embodiment of the present application;

[0023] Figure 4 A system framework diagram of a database statement generation method provided in an embodiment of the present application;

[0024] Figure 5 A generated SQL statement diagram for a database statement generation method provided in an embodiment of the present application;

[0025] Figure 6 An error correction diagram for a database statement generation method provided in an embodiment of the present application;

[0026] Figure 7 A schematic diagram of the structure of a database statement generation device provided in an embodiment of the present application;

[0027] Figure 8 A schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0028] To make the purpose, technical solutions, and advantages of the embodiments of this application more clear, the technical solutions in the embodiments of this application will be clearly and completely described below in conjunction with the drawings in the embodiments of this application. Obviously, the described embodiments are part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.

[0029] The disclosure below provides many different embodiments or examples for implementing different configurations of the present invention. To simplify the disclosure of the present invention, the components and configurations of specific examples are described below. Of course, these are merely examples and are not intended to limit the present invention. In addition, the present invention may repeat reference numerals and / or letters in different examples. Such repetition is for the purpose of simplicity and clarity and does not in itself indicate the relationship between the various embodiments and / or configurations discussed.

[0030] In order to solve the technical problem of low database data search accuracy in the prior art, the present application provides a database statement generation method that can achieve the effect of improving database data search accuracy.

[0031] Figure 1 A flowchart of a method for generating database statements provided in an embodiment of the present application.

[0032] like Figure 1 As shown, the above database statement generation method includes:

[0033] S102, when a target instruction is obtained, obtaining a target text from the target instruction;

[0034] S104: Input the target text into a vector database to obtain similar texts of the target text and a first database statement of the similar texts, wherein the target text is a natural language text, the vector database includes multiple texts, each of which corresponds to a database statement, and the similar text is the text with the highest similarity to the target text;

[0035] S106, inputting the target text, the target library and the target table's library and table descriptions, and the first database statement into the generation model to obtain a target database statement output by the generation model, so as to query the target data in the target library and the target table through the target database statement;

[0036] S108: Return the queried target data to the client that sent the target instruction.

[0037] In this embodiment, the database statement is a Structured Query Language (SQL) statement. The target text is a natural language text, and the language of the natural language text can be any existing language such as Chinese and English. Taking Chinese as an example, the natural language text can be "Find the class with the most boys whose hobbies include basketball." Then, the expected result of the search is a class whose attribute is that the most boys have a hobby that includes basketball. If you want to search for data in the database, the database statement is: Select class from student where gender = 1 and hobby like '% basketball%' groupby class order by count(*)desc limit 1. Therefore, by processing and converting the natural language text, you can obtain the database text without having to master complex database statements.

[0038] The target database and target table are the databases and tables where the target data is to be queried. Data queries have a scope, which specifies the database and table to be queried, and then the target data is queried within those databases and tables. Other databases and tables containing data with the same conditions are not queried. The vector database, which is different from the database and table where the target data is to be queried, stores language vectors and corresponding database statements. The language vectors stored in the vector database are natural language vectors, which can generate corresponding language vectors. The database statements corresponding to the language vectors are the natural language statements used in database statements.

[0039] The correspondence between language vectors and database statements in the vector database must be deployed or stored in advance. For example, when using database statements to query data in the database, natural language text with corresponding meaning can be added to the database statements. After converting the natural language text into language vectors, the language vectors and database statements are stored in the vector database. Alternatively, a staff member proficient in database statements can upload the language vectors and corresponding database statements. Other staff members can verify the accuracy of the language vectors and database statements uploaded by the staff member. If the verification passes, the language vectors and database statements are stored in the vector database. The vector database thus stores the correspondence between natural language language vectors and database statements.

[0040] It should be noted that since the target text may not necessarily have an identical language vector in the vector database, the first database statement corresponding to the closest language vector is selected. However, if this selected first database statement is used directly to query data, the resulting data will not be the data described by the target text. Therefore, the first database data, the target text, and the target library and table descriptions are input into the generation model to generate the target database statement.

[0041] The user can generate natural statements through the client and initiate instructions including natural statements. When the backend obtains the database instructions through the user's natural statements and finds the target data, it returns the target data to the user's client.

[0042] The solution provided in the embodiment of the present application can generate target database statements through natural language text, so that users can search for database data through natural language text without having to master complex database statements, thereby improving the accuracy of database data search.

[0043] As an optional example, before inputting the target text into the vector database, the above method also includes: in the case where the target text includes multiple consecutive symbols, deleting n-1 symbols among the multiple consecutive symbols according to the context of the multiple consecutive symbols, where n is the number of the multiple consecutive symbols; performing an error correction operation on the target text after the symbols are deleted to obtain the corrected target text.

[0044] This embodiment involves correcting the target text. Since the target text is user-provided, it may not conform to natural language descriptions and may contain grammatical errors, text errors, or symbol errors, thus requiring correction. During correction, the punctuation marks in the target text can be corrected first. If the target text contains consecutive punctuation marks, only one will be deleted. The decision on which punctuation mark to retain is based on the context of the consecutive punctuation marks.

[0045] After removing unnecessary punctuation, the remaining text is corrected for both textual errors and grammatical errors. Textual errors are corrected by replacing typos based on the context. Grammar errors are corrected by adjusting the position of words based on the context.

[0046] As an optional example, the error correction operation is performed on the target text after the symbol is deleted to obtain the target text after error correction, including: identifying typos in the target text after the symbol is deleted; replacing the typos with words that have the same pinyin but different text as the typos; and using the replaced target text as the target text after error correction.

[0047] In this embodiment, typos in the target text can be identified and corrected. Typos can be identified by identifying each word in the target text and identifying the relationship between the word and the surrounding context. If the word is found to have a poor correlation with the surrounding context, it can be replaced with a word with the same pinyin. The replaced word is then identified in terms of its relationship with the surrounding context. If the correlation is high, it is retained. If the correlation is poor, it is replaced again, retaining the word with the highest correlation.

[0048] As an alternative example, Figure 2 As shown, the target text is input into the vector database, and similar texts of the target text are obtained and the first database statement of the similar text includes:

[0049] S202, converting the target text into a target vector;

[0050] S204, comparing the target vector with vectors in the vector database to determine a first vector having the highest similarity to the target vector from the vector database;

[0051] S206 : Determine the text corresponding to the first vector as a similar text, and determine the database sentence corresponding to the first vector as a first database sentence.

[0052] In this embodiment, the target text conversion target vector can be to convert the nouns and adjectives in the text into points in the vector, and use verbs, conjunctions, prepositions, etc. as edges in the vector. The vector direction is from the point corresponding to the word that appears first in the target text to the point corresponding to the word that appears later.

[0053] After determining the target vector for the target text, the first vector with the highest similarity to the target vector can be found by comparing the target vector with vectors in the vector database. The text corresponding to the first vector is then considered similar to the target text. The database statement corresponding to the similar text is the first database statement.

[0054] As an alternative example, Figure 3 As shown, the target text, the target library and the target table description and the first database statement are input into the generation model, and the target database statement output by the generation model includes:

[0055] S302: Input the target text, the target library and target table descriptions, the first database statement, and the additional statement into the generation model to obtain the target database statement output by the generation model, wherein the additional statement is a statement different from the first database statement.

[0056] In this embodiment, the target text, the target library and target table descriptions, and the first database statement can be input into the generation model to generate the target database statement. Furthermore, to further improve generation accuracy, additional statements can be added. These additional statements are statements other than the first database statement that assist in generating the target database statement.

[0057] As an optional example, obtaining the additional statement includes: when providing an input interface to the user, determining the statement input by the user as the additional statement; or, determining, from the additional statement library, a statement that matches the library table description of the target library and target table as the additional statement.

[0058] In this embodiment, additional statements can be obtained in different ways. One method involves user input, where the user can input additional statements based on the first database statement, thereby making the generated target database statement more accurate. Another method involves pre-setting an additional statement library containing multiple additional statements. The additional statements are then matched based on the target database and target table descriptions where the data to be searched resides.

[0059] As an optional example, after inputting the target text, the target library and target table's library and table descriptions, and the first database statement into the generation model to obtain the target database statement output by the generation model, the above method also includes: parsing the entities of the table name and column name in the target database statement; when the names of the parsed entities are incorrect, searching for the target table name and target column name that are most similar to the table name and column name; and replacing the entities of the table name and column name with the entities of the target table name and target column name.

[0060] In this embodiment, after obtaining the target database statement, the target database statement can be used to query the target data. However, because the table names and column names used in different database tables may have the same meaning but may be written differently, the table names and column names in the target database statement must be corrected and replaced. First, determine whether the entity names of the table and column names are correct. If not, replace the entity names. Find the target table name and target column name that are most similar to the table name and column name, and replace the entity names of the table and column names with the entity names of the target table name and column name.

[0061] As an optional example, when the name of the entity obtained by parsing is incorrect, finding the target table name and target column name that are most similar to the table name and column name includes: determining entities that have the same pinyin as the table name and the column name or contain the same text from all entities; and finding the target table name and target column name that are most similar to the table name and column name from the determined entities.

[0062] In this embodiment, the table name and column name in the database statement can be checked first. If the entity name of the table name or column name is incorrect, the target table name or target column name is searched for in all replaceable entities of the table name or column name. Taking the incorrect entity of the table name as an example, the target table name with the highest similarity to the incorrect table name is searched for among all replaceable table names. First, entities with the same pinyin or containing the same text are searched from all replaceable entities of the table name, and then the target table name with the highest similarity is determined from these entities. Since the similarity of the content with the same pinyin or containing the same text may be higher, this method can reduce the amount of partial comparison and improve the search efficiency.

[0063] As an optional example, before obtaining the target text, the above method also includes: obtaining a selection instruction, wherein the selection instruction is used to select a target library and a target table for querying target data; and determining the description information of the target library and the target table as a library table description.

[0064] In this embodiment, the target library and target table for data search may be determined from all libraries and tables according to the selection instruction. The description information of the target library and target table is the library and table description used in the process of generating the target database statement.

[0065] Figure 4 This is the system framework diagram of this embodiment. The user selects the library table to be queried. After the library table is determined, a library table description is generated. For the question input by the user, that is, the natural language text, it is first input into the error correction model (Large Language Model, LLM) for error correction. After the error correction, the natural language text searches for similar text in the vector database, and the first SQL statement and library table description of the similar text are obtained and stored. The first SQL statement, library table description and natural language text are combined into a combined text Prompt, which is input into the code language model Code LLM to generate the target SQL statement. The target SQL statement is corrected, and the corrected SQL statement is returned to the user.

[0066] For example, let's use the school_test database and the student table as an example. The target SQL query statement is generated using the natural language text "What are the classes with the most boys whose hobbies include basketball?" First, select the corresponding database table, namely the school_test database and its student table. The backend generates a corresponding table description based on the selected database table, facilitating the use of the large model. The user then enters their own question: "What is the class with the most boys whose hobbies include basketball?" ("Class" here indicates an error in the user input). Errors may include grammatical, semantic, or spelling errors. The user's question is not used directly. Instead, it is first corrected by the error correction large model. The corrected question becomes: "What is the class with the most boys whose hobbies include basketball?" Typos have been corrected. To improve the SQL writing quality of the large model, the question is entered into the vector database Milvus to query previously saved similar question records. As an example for the large model, the vector database is queried to obtain the question with the highest similarity to the natural language text, along with the database description and the first SQL statement for that question. Combine the natural language text, the table description and the first SQL statement into a combined text prompt, add some additional statements, and input it into Code LLM. The processing process of the Code LLM large model is as follows: Figure 5 As shown, enter the prompt into Code LLM and finally get the generated SQL: Select class from student where gender=1 and hobby like'% basketball%' group by class order by count(*)desc limit1.

[0067] Due to the problems of non-standard naming of Chinese and English columns, many column names, such as name, na, xingming, xm, etc., often have column name errors. Therefore, column matching error correction is used to process the generated SQL, such as Figure 6 As shown, the entity of the table and column name is checked. If the entity is incorrect, the most similar table and column name is found and the entity is replaced. To facilitate subsequent similar question queries, the relationship between the question, vector, SQL statement, and library table description is stored in the vector database Milvus. The final SQL is output to the user.

[0068] Figure 7 This is a schematic diagram of the structure of a database statement generation device provided in an embodiment of the present application. Figure 7 As shown, the above-mentioned database statement generating device includes:

[0069] The acquisition module 702 is used to acquire the target text from the target instruction when the target instruction is acquired.

[0070] A first input module 704 is configured to input a target text into a vector database to obtain similar texts of the target text and a first database statement of the similar texts, wherein the target text is a natural language text, the vector database includes multiple texts, each of which corresponds to a database statement, and the similar text is the text with the highest similarity to the target text;

[0071] The second input module 706 is used to input the target text, the library and table descriptions of the target library and target table, and the first database statement into the generation model to obtain the target database statement output by the generation model, so as to query the target data in the target library and target table through the target database statement;

[0072] The sending module 708 is configured to return the queried target data to the client that sent the target instruction.

[0073] In this embodiment, the database statement is a Structured Query Language (SQL) statement. The target text is a natural language text, and the language of the natural language text can be any existing language such as Chinese and English. Taking Chinese as an example, the natural language text can be "Find the class with the most boys whose hobbies include basketball." Then, the expected result of the search is a class whose attribute is that the most boys have a hobby that includes basketball. If you want to search for data in the database, the database statement is: Select class from student where gender = 1 and hobby like '% basketball%' groupby class order by count(*)desc limit 1. Therefore, by processing and converting the natural language text, you can obtain the database text without having to master complex database statements.

[0074] The target database and target table are the databases and tables where the target data is to be queried. Data queries have a scope, which specifies the database and table to be queried, and then the target data is queried within those databases and tables. Other databases and tables containing data with the same conditions are not queried. The vector database, which is different from the database and table where the target data is to be queried, stores language vectors and corresponding database statements. The language vectors stored in the vector database are natural language vectors, which can generate corresponding language vectors. The database statements corresponding to the language vectors are the natural language statements used in database statements.

[0075] The correspondence between language vectors and database statements in the vector database must be deployed or stored in advance. For example, when using database statements to query data in the database, natural language text with corresponding meaning can be added to the database statements. After converting the natural language text into language vectors, the language vectors and database statements are stored in the vector database. Alternatively, a staff member proficient in database statements can upload the language vectors and corresponding database statements. Other staff members can verify the accuracy of the language vectors and database statements uploaded by the staff member. If the verification passes, the language vectors and database statements are stored in the vector database. The vector database thus stores the correspondence between natural language language vectors and database statements.

[0076] It should be noted that since the target text may not necessarily have an identical language vector in the vector database, the first database statement corresponding to the closest language vector is selected. However, if this selected first database statement is used directly to query data, the resulting data will not be the data described by the target text. Therefore, the first database data, the target text, and the target library and table descriptions are input into the generation model to generate the target database statement.

[0077] The solution provided in the embodiment of the present application can generate target database statements through natural language text, so that users can search for database data through natural language text without having to master complex database statements, thereby improving the accuracy of database data search.

[0078] For other examples of this embodiment, please refer to the above examples and will not be repeated here.

[0079] like Figure 8 As shown, an embodiment of the present application provides an electronic device, including a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other through the communication bus 114.

[0080] Memory 113, for storing computer programs;

[0081] In one embodiment of the present application, the processor 111 is configured to implement the database statement generation method provided by any one of the aforementioned method embodiments when executing the program stored in the memory 113 .

[0082] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the database statement generation method provided in any of the aforementioned method embodiments is implemented.

[0083] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules may be selected based on actual needs to achieve the objectives of this embodiment.

[0084] Through the description of the above embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus a general hardware platform, or of course, by hardware. Based on this understanding, the above technical solution, in essence, or the part that contributes to the relevant technology, can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or certain parts of the embodiment.

[0085] It should be understood that the terms used herein are for the purpose of describing specific example embodiments only and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "comprise", "include", "contain" and "have" are inclusive and therefore specify the presence of stated features, steps, operations, elements and / or parts, but do not exclude the presence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not to be construed as necessarily requiring them to be performed in the specific order described or illustrated, unless the order of execution is clearly indicated. It should also be understood that additional or alternative steps may be used.

[0086] The foregoing description is intended only to provide specific embodiments of the present invention, which will enable those skilled in the art to understand and implement the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention is not intended to be limited to the embodiments shown herein, but is intended to be accorded the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A method for generating a database statement, characterized in that: include: When the target instruction is obtained, obtaining the target text from the target instruction; Inputting the target text into a vector database to obtain a similar text of the target text and a first database statement of the similar text, wherein the target text is a natural language text, the vector database includes a plurality of texts, each text corresponds to a database statement, and the similar text is the text with the highest similarity to the target text; Inputting the target text, the target library and the library table description of the target table, and the first database statement into a generation model to obtain a target database statement output by the generation model, so as to query the target data in the target library and the target table through the target database statement; The queried target data is returned to the client that sent the target instruction.

2. The method according to claim 1, characterized in that Before inputting the target text into the vector database, the method further includes: When the target text includes a plurality of consecutive symbols, deleting n-1 symbols from the plurality of consecutive symbols according to the context of the plurality of consecutive symbols, wherein n is the number of the plurality of consecutive symbols; An error correction operation is performed on the target text after the symbols are deleted to obtain the target text after error correction.

3. The method according to claim 2, characterized in that The performing of an error correction operation on the target text after the deletion symbol to obtain the target text after the error correction comprises: identifying typos in the target text after the deletion symbol; Replace the misspelled character with a character that has the same pinyin as the misspelled character but a different text; The target text after replacement is used as the target text after error correction.

4. The method according to claim 1, wherein After inputting the target text, the target library and the library table description of the target table, and the first database statement into the generation model to obtain the target database statement output by the generation model, the method further includes: Parsing entities of table names and column names in the target database statement; If the name of the parsed entity is incorrect, searching for a target table name and a target column name that are most similar to the table name and the column name; The entities of the target table name and the target column name are used to replace the entities of the target table name and the target column name.

5. The method according to claim 4, characterized in that When the name of the entity obtained by parsing is incorrect, searching for the target table name and target column name that are most similar to the table name and column name includes: Determine from all entities the entity that has the same pinyin as the table name and the column name or contains the same text; Search the determined entities for a target table name and a target column name that are most similar to the table name and the column name.

6. The method according to claim 1, wherein Inputting the target text into a vector database to obtain similar texts of the target text and a first database statement of the similar texts includes: Converting the target text into a target vector; Comparing the target vector with vectors in the vector database to determine a first vector having the highest similarity to the target vector from the vector database; The text corresponding to the first vector is determined as the similar text, and the database sentence corresponding to the first vector is determined as the first database sentence.

7. The method according to claim 1, characterized in that The step of inputting the target text, the target library and the target table descriptions, and the first database statement into the generation model to obtain the target database statement output by the generation model comprises: The target text, the target library and the library table description of the target table, the first database statement and the additional statement are input into the generation model to obtain the target database statement output by the generation model, wherein the additional statement is a statement different from the first database statement.

8. The method according to claim 7, characterized in that Obtaining the additional statement includes: In the case of providing an input interface to the user, determining the sentence input by the user as the additional sentence; or, From the additional statement library, a statement matching the library table description of the target library and the target table is determined as the additional statement.

9. The method according to claim 1, characterized in that Before acquiring the target text, the method further includes: Obtain a selection instruction, wherein the selection instruction is used to select the target library and the target table for querying the target data; The description information of the target library and the target table is determined as the library-table description.

10. A database statement generating device, characterized in that: include: An acquisition module, configured to acquire a target text from the target instruction when the target instruction is acquired; a first input module, configured to input the target text into a vector database to obtain a similar text of the target text and a first database statement of the similar text, wherein the target text is a natural language text, the vector database includes a plurality of texts, each of which corresponds to a database statement, and the similar text is the text with the highest similarity to the target text; A second input module is configured to input the target text, the target library and the library table description of the target table, and the first database statement into a generation model to obtain a target database statement output by the generation model, so as to query the target data in the target library and the target table through the target database statement; The sending module is used to return the queried target data to the client that sent the target instruction.

11. An electronic device, characterized in that: include: at least one communication interface; at least one bus connected to the at least one communication interface; at least one processor coupled to the at least one bus; At least one memory connected to the at least one bus, wherein the memory stores a computer program, and when the processor executes the computer program, the database statement generation method described in any one of claims 1 to 9 is implemented.

12. A computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are used to execute the database statement generation method according to any one of claims 1 to 9 of the present application.