Data table information query method and device
By vectorizing the character-type conditional fields of user natural language query in NL2SQL technology and semantic matching, the problem of inaccurate SQL statements caused by user input errors or inaccuracies is solved, and a more accurate database query result is achieved.
Patent Information
- Application Number
- CN202411836533.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-12
- Publication Date
- 2025-04-04
AI Technical Summary
In NL2SQL technology, natural language queries entered by users may contain incorrect or inaccurate character-type information, resulting in the generated SQL statements that cannot accurately match the data in the database, affecting the accuracy of the query results.
By obtaining the query text, the initial SQL statement is generated using the pre-trained large language model, and the condition values of the character-type condition fields are vectorized. Then, the matching target vector and metadata are retrieved from the preset vector database, and the SQL statement is corrected based on these metadata, and finally the corrected SQL statement is used to query the database.
Through vectorization processing and semantic matching, the accuracy of SQL statements during execution is improved, query failure caused by inaccurate correction of character-type condition information is reduced, and the problem of inaccurate query results is solved in the information query scenario because the character-type fields in SQL statements cannot be checked, resulting in inaccurate query results.
Smart Images

Figure CN119759937A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of database query, and in particular to a method and device for querying data table information. Background Art
[0002] With the emergence of large language models, NL2SQL (Natural Language to Structured Query Language) technology has developed rapidly. NL2SQL technology can directly convert users' natural language queries into SQL (Structured Query Language) query statements, thereby greatly reducing the difficulty of database queries. This technology allows non-technical personnel to easily perform database queries, greatly improving the convenience and efficiency of data access. Although NL2SQL technology has brought significant convenience, it still faces some challenges in practical applications. In practical applications, the queries entered by users may contain errors or inaccuracies, so it is necessary to use the SQL correction module to improve the accuracy of the overall SQL generation. The conditional information correction often determines whether the entire SQL statement can be executed correctly. Traditional methods often only check and correct numeric or time fields, and lack correction of character fields.
[0003] In actual project practice, the above problems are particularly evident: in the scenario of converting natural language queries into SQL queries, natural language input generally cannot provide completely consistent character-based information, and the same meaning may be expressed in multiple ways, which causes the generated SQL statement to fail to accurately match the data in the database, affecting the accuracy of the query results. Character-based condition information is usually more complex and diverse, and traditional relational databases are less efficient in processing character retrieval and cannot perform approximate matches based on semantics, which means that even if the generated SQL statement is logically correct, it cannot be used directly and the expected query results cannot be obtained.
[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 data table information query method and device to at least solve the technical problem of inaccurate query results caused by the inability to verify character fields in SQL statements in information query scenarios.
[0006] According to one aspect of an embodiment of the present application, a data table information query method is provided, including: obtaining a query text, and analyzing the query text using a pre-trained large language model to obtain a first SQL statement corresponding to the query text; when a condition field in the first SQL statement is a character field, vectorizing the condition value in the first SQL statement to obtain a first vector; determining a target data set corresponding to a table name and a condition field in the first SQL statement from a preset vector database, determining a target vector matching the first vector from the target data set, and determining target metadata corresponding to the target vector, wherein a plurality of data sets are stored in the vector database, each of which includes: metadata in a character field in a data table in a metadata database, vectors corresponding to each metadata, a table name of the data table, and a field name of the character field; correcting the first SQL statement according to the target metadata to obtain a second SQL statement; and querying the metadata database using the second SQL statement to obtain a query result.
[0007] Optionally, the process of constructing a vector database includes: obtaining multiple data tables in the metadata database; for each data table, determining each character field in the data table; for each character field, performing data deduplication processing on all metadata in the character field, and combining the obtained multiple metadata into a metadata subset; using a pre-trained vector conversion model to vectorize each metadata in the metadata subset, and combining the obtained multiple vectors into a vector subset; constructing a data set based on the table name of the data table, the field name of the character field, the metadata subset and the vector subset; and combining the obtained multiple data sets into a vector database.
[0008] Optionally, for any data table, when the data table is updated, determine each newly added first character field, existing and changed second character field, and deleted third character field in the data table; for each first character field, perform data deduplication processing on all metadata in the first character field, and form a newly added metadata subset with the obtained multiple metadata; use a vector conversion model to vectorize each metadata in the newly added metadata subset, and form a newly added vector subset with the obtained multiple vectors; construct a first data set based on the table name of the data table, the field name of the first character field, the newly added metadata subset and the newly added vector subset; add the first data set to the vector database; for each second character field, determine the second data set corresponding to the second character field from the vector database; determine each The newly added first metadata, the modified second metadata, the third metadata before modification corresponding to the second metadata, and the deleted fourth metadata; for each first metadata or second metadata, detect whether there is metadata identical to the first metadata or second metadata in the second data set, if so, do not process the first metadata or second metadata, if not, use the vector conversion model to vectorize the first metadata or second metadata to obtain a newly added vector, and add the first metadata or second metadata and the corresponding newly added vector to the second data set; for each third metadata or fourth metadata, delete the third metadata or fourth metadata and the vector corresponding to the third metadata or fourth metadata from the second data set; for each third character field, delete the third data set corresponding to the third character field from the vector database.
[0009] Optionally, vectorizing the conditional value in the first SQL statement to obtain the first vector includes: determining the conditional value in the first SQL statement; and vectorizing the conditional value using a vector conversion model to obtain the first vector.
[0010] Optionally, the training process of the vector conversion model includes: constructing an initial model, wherein the initial model is a supervised learning model with an attention mechanism; obtaining multiple groups of SQL statements as training samples, and determining the vectorized representation of each group of SQL statements as sample labels; and iteratively training the initial model using the training samples and sample labels to obtain the vector conversion model.
[0011] Optionally, a target data set corresponding to the table name and condition field in the first SQL statement is determined from a preset vector database, and a target vector matching the first vector is determined from the target data set, including: determining the target data set from the vector database, wherein the table name of the data table in the target data set is the same as the table name in the first SQL statement, and the field name of the character field in the target data set is the same as the condition field in the first SQL statement; respectively calculating the similarity between each vector in the target data set and the first vector, and determining the vector with the greatest similarity to the first vector as the target vector.
[0012] Optionally, the first SQL statement is corrected according to the target metadata to obtain the second SQL statement, including: when the condition values in the target metadata and the first SQL statement are the same, directly using the first SQL statement as the second SQL statement; when the condition values in the target metadata and the first SQL statement are different, using the target metadata to replace the condition value in the first SQL statement, and using the adjusted first SQL statement as the second SQL statement.
[0013] According to another aspect of an embodiment of the present application, a data table information query device is also provided, including: an analysis module, used to obtain a query text, and use a pre-trained large language model to analyze the query text to obtain a first SQL statement corresponding to the query text; a vectorization module, used to vectorize the condition value in the first SQL statement when the condition field in the first SQL statement is a character field, to obtain a first vector; a retrieval module, used to determine a target data set corresponding to the table name and the condition field in the first SQL statement from a preset vector database, determine a target vector matching the first vector from the target data set, and determine target metadata corresponding to the target vector, wherein the vector database stores multiple data sets, each data set includes: metadata in a character field in a data table in a metadata database, vectors corresponding to each metadata, a table name of the data table, and a field name of the character field; a correction module, used to correct the first SQL statement according to the target metadata to obtain a second SQL statement; a query module, used to query the metadata database using the second SQL statement to obtain a query result.
[0014] According to another aspect of an embodiment of the present application, a computer program product is further provided, the computer program product comprising: a computer program, wherein the computer program implements the above-mentioned data table information query method when executed by a processor.
[0015] According to another aspect of an embodiment of the present application, an electronic device is further provided, comprising: a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the above-mentioned data table information query method through the computer program.
[0016] In an embodiment of the present application, a query text is obtained, and the query text is analyzed using a pre-trained large language model to obtain a first SQL statement corresponding to the query text; when the condition field in the first SQL statement is a character field, the condition value in the first SQL statement is vectorized to obtain a first vector; a target data set corresponding to the table name and the condition field in the first SQL statement is determined from a preset vector database, a target vector matching the first vector is determined from the target data set, and target metadata corresponding to the target vector is determined, wherein a plurality of data sets are stored in the vector database, each data set including: metadata in a character field in a data table in a metadata database, vectors corresponding to each metadata, a table name of the data table, and a field name of the character field; the first SQL statement is corrected according to the target metadata to obtain a second SQL statement; the metadata database is queried using the second SQL statement to obtain a query result. In this way, by converting the character field condition values in the user query into vectors and finding the most matching metadata in the vector database, the expression differences of the condition values can be corrected and the accuracy of the SQL statement during execution can be improved. In addition, the vectorized method matches the condition values based on semantic relevance rather than just literal exact matching. This method reduces query failures caused by inaccurate correction of character condition information, and thus solves the technical problem of inaccurate query results in information query scenarios due to the inability to verify the character fields in the SQL statement. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] 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:
[0018] Figure 1 is a flow chart of an optional data table information query method according to an embodiment of the present application;
[0019] Figure 2 is a schematic structural diagram of an optional data table information query device according to an embodiment of the present application;
[0020] Figure 3 It is a schematic diagram of the structure of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0021] 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.
[0022] It should be noted that the terms "first", "second", etc. in the specification, claims and drawings of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments 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.
[0023] Example 1
[0024] According to an embodiment of the present application, a data table information query method 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 the 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.
[0025] Figure 1 is a flow chart of a data table information query method provided according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:
[0026] Step S102, obtaining a query text, and analyzing the query text using a pre-trained large language model to obtain a first SQL statement corresponding to the query text;
[0027] Step S104, when the condition field in the first SQL statement is a character field, vectorize the condition value in the first SQL statement to obtain a first vector;
[0028] Step S106, determining a target data set corresponding to the table name and the condition field in the first SQL statement from a preset vector database, determining a target vector matching the first vector from the target data set, and determining target metadata corresponding to the target vector, wherein the vector database stores a plurality of data sets, each of which includes: metadata in a character field in a data table in the metadata database, vectors corresponding to each metadata, a table name of the data table, and a field name of the character field;
[0029] Step S108, correcting the first SQL statement according to the target metadata to obtain a second SQL statement;
[0030] Step S110: query the metadata database using the second SQL statement to obtain a query result.
[0031] The following describes each step of the data table information query method in conjunction with a specific implementation process.
[0032] First, the query text input by the user can be obtained, and the query text can be analyzed using a pre-trained large language model to obtain a first SQL statement corresponding to the query text; when the condition field in the first SQL statement is a character field, the condition value in the first SQL statement is vectorized to obtain a first vector.
[0033] It should be noted that the embodiment of the present application mainly solves the correction of character-type information, so only the character-type conditional fields are processed, and the correction of numerical or time-type fields can be implemented using existing solutions.
[0034] As an optional implementation, when the condition value in the first SQL statement is vectorized, it can be performed in the following manner: determining the condition value in the first SQL statement; and vectorizing the condition value using a vector conversion model to obtain a first vector.
[0035] For example, suppose there is a user query system that integrates a pre-trained large language model. First, the system receives a query text from the user: "Query all user information registered in the Pudong District Bureau in 2023". Next, the system will use the pre-trained large language model to analyze and process this query text. The model can identify key information in the query text, such as time (2023), location (Pudong District Bureau) and query target (user information), and generate the corresponding first SQL statement. The system further checks the condition field in the SQL statement, confirms that the condition field is a character field, vectorizes the condition value "Pudong District Bureau", and generates the first vector using the pre-trained vector conversion model. This vectorization process aims to capture the semantic features of the character field value and convert it into a representation in the vector space for subsequent vector retrieval.
[0036] As an optional implementation, the training process of the vector conversion model can be carried out in the following manner: construct an initial model, wherein the initial model is a supervised learning model with an attention mechanism; obtain multiple groups of SQL statements as training samples, and determine the vectorized representation of each group of SQL statements as sample labels; use the training samples and sample labels to iteratively train the initial model to obtain the vector conversion model.
[0037] For example, a supervised learning model with an attention mechanism, such as a Transformer model, is constructed as the initial model. The attention mechanism allows the model to give different weights according to importance when processing input data. Supervised learning means that the model uses labeled data during training, that is, both the input and the expected output are known. After the initial model is constructed, multiple sets of SQL statements are obtained as training samples and sample labels. Each set of SQL statements can be a separate SQL query or a set of related SQL queries. The SQL statements are converted into numerical vectors so that the model can understand and process them. This usually involves natural language processing techniques such as word embedding and TF-IDF (Term Frequency-Inverse Document Frequency). The initial model is iteratively trained using training samples and sample labels: each set of SQL statements is used as input, and the vectorized representation of each set of SQL statements is used as output. The model will try to predict the vectorized representation of each set of SQL statements, and adjust the model parameters based on the difference between the predicted results and the actual labels to minimize the loss function. This process will be repeated many times until the performance of the model reaches the expected level.
[0038] After obtaining the first vector, a target data set corresponding to the table name and the condition field in the first SQL statement is determined from a preset vector database, a target vector matching the first vector is determined from the target data set, and target metadata corresponding to the target vector is determined, wherein the vector database stores multiple data sets, each of which includes: metadata in a character field in a data table in the metadata database, vectors corresponding to each metadata, the table name of the data table, and the field name of the character field.
[0039] As an optional implementation, the construction process of a vector database may include the following steps: obtaining multiple data tables in a metadata database; for each data table, determining each character field in the data table; for each character field, performing data deduplication processing on all metadata in the character field, and combining the obtained multiple metadata into a metadata subset; using a pre-trained vector conversion model to vectorize each metadata in the metadata subset, and combining the obtained multiple vectors into a vector subset; constructing a data set based on the table name of the data table, the field name of the character field, the metadata subset and the vector subset; and combining the obtained multiple data sets into a vector database.
[0040] For example, check all the columns in the database table T, find the character fields (such as name, address, etc.), record these fields as C, deduplicate the values in each character field C, that is, metadata, and ensure that each value is unique, and obtain a set of information values, that is, metadata subsets {A1, A2, ..., Ai}. Use a vector transformation model such as BERT (Bidirectional Encoder Representation from Transformers) to convert these values into vector form, and obtain a set of vector subsets {a1, a2, ..., ai}. Save this information (table name, field name, information value (metadata subset), vector subset) in a special database (vector database) for subsequent query. The bidirectional training mechanism of the BERT model enables it to better understand the contextual information of natural language, so that character fields can be processed more accurately when generating SQL statements. Through the BERT model, different expressions can be mapped to the same meaning, reducing errors caused by inconsistent expressions.
[0041] As an optional implementation, when the data table is updated, the process of synchronizing the vector database and updating information can be performed in the following manner:
[0042] For any data table, when the data table is updated, each newly added character field in the data table is determined to be the first character field, the existing and changed character field is determined to be the second character field, and the deleted character field is determined to be the third character field, wherein the existing and changed character field refers to the field that originally existed in the data table, but its content (that is, the data in the field) is updated or modified at a certain moment, which may include adding new records or updating the values of existing records or deleting certain records;
[0043] For each first character field, perform data deduplication processing on all metadata in the first character field to ensure that the same metadata is not stored repeatedly. The obtained multiple metadata are combined into a new metadata subset; the vector conversion model is used to vectorize each metadata in the new metadata subset, and the obtained multiple vectors are combined into a new vector subset; the first data set is constructed based on the table name of the data table, the field name of the first character field, the new metadata subset and the new vector subset; the first data set is added to the vector database;
[0044] For each second character field, determine the second data set corresponding to the second character field from the vector database, which usually includes the previously stored field name, table name, metadata value and the vectorized representation of these values; determine each newly added first metadata, modified second metadata, third metadata before modification corresponding to the second metadata, and deleted fourth metadata in the second character field, and obtain these change information by analyzing the update log of the data table or through the change event of the database; for each first metadata or second metadata, detect whether there is metadata identical to the first metadata or second metadata in the second data set; if so, it means that the metadata has been processed before, and there is no need to repeat the operation, and the first metadata or second metadata is not processed; if not, use the vector conversion model to vectorize the first metadata or second metadata to obtain a newly added vector, and add the first metadata or second metadata and the corresponding newly added vector to the second data set; for each third metadata or fourth metadata, delete the third metadata or fourth metadata and the vector corresponding to the third metadata or fourth metadata from the second data set;
[0045] For each third character field, the third data set corresponding to the third character field is deleted from the vector database to ensure that the field information of the vector database is consistent with the data table.
[0046] Through the above steps, the field information in the vector database can be dynamically maintained and synchronized. Even if the character field data in the data table changes frequently, the accuracy and effectiveness of the SQL statement generation and correction process can be guaranteed.
[0047] As an optional implementation, a target data set corresponding to the table name and condition field in the first SQL statement is determined from a preset vector database, and a target vector matching the first vector is determined from the target data set. This can be done in the following manner: determine the target data set from the vector database, wherein the table name of the data table in the target data set is the same as the table name in the first SQL statement, and the field name of the character field in the target data set is the same as the condition field in the first SQL statement; then calculate the similarity between each vector in the target data set and the first vector, and determine the vector with the greatest similarity to the first vector as the target vector. Common similarity algorithms include cosine similarity, Euclidean distance, etc.
[0048] For example, the user enters the query: "Find all students living in Beijing", and the big model generates SQL: SELECT * FROM students WHERE address = 'Beijing'. The parsing result is: table name students, condition field address, condition value 'Beijing'. Find the data set corresponding to the table name and condition field in the SQL statement from the vector database, find the data set of the address field of the students table, vectorize the condition value in the SQL statement, and generate the first vector. Then, calculate the similarity between each vector in the target data set and the first vector, and find the vector most similar to the condition value in the SQL statement. Among them, convert 'Beijing' into vector v4, calculate the similarity between v4 and each vector in the data set {v4, v5, v6}, and select the vector with the highest similarity from the target data set as the target vector. The vector with the highest similarity is v4. Get the original value corresponding to the target vector (i.e., target metadata) from the target data set, find the original value corresponding to the target vector, and the original value corresponding to the target vector v4 is 'Beijing'.
[0049] After obtaining the target metadata, the first SQL statement is corrected according to the target metadata to obtain the second SQL statement. The process of obtaining the second SQL statement is a key step to ensure that the SQL query statement can be accurately executed. This process can be specifically as follows:
[0050] When the condition value in the target metadata is the same as that in the first SQL statement, this indicates that the condition information in the SQL statement generated by the large model is accurate and matches the actual field value in the database. At this time, there is no need to make any adjustments to the first SQL statement, and the first SQL statement can be directly used as the second SQL statement. When the condition value in the target metadata is different from that in the first SQL statement, this may be due to the diversity of natural language expressions, resulting in differences between the condition information in the generated SQL statement and the actual field value in the database. The target metadata is used to replace the condition value in the first SQL statement, and the adjusted first SQL statement is used as the second SQL statement. The metadata database is queried using the second SQL statement to obtain the query result.
[0051] For example, when the vector approximate retrieval shows that "Pudong District Bureau" is not completely consistent with "Pudong New Area Bureau", the target metadata is used to replace the condition value in the first SQL statement to generate a more accurate second SQL statement. Finally, the second SQL statement is used to query the metadata database to obtain the final query result, ensuring the accuracy and completeness of the query result.
[0052] In an embodiment of the present application, a query text is obtained, and the query text is analyzed using a pre-trained large language model to obtain a first SQL statement corresponding to the query text; when the condition field in the first SQL statement is a character field, the condition value in the first SQL statement is vectorized to obtain a first vector; a target data set corresponding to the table name and the condition field in the first SQL statement is determined from a preset vector database, a target vector matching the first vector is determined from the target data set, and target metadata corresponding to the target vector is determined, wherein a plurality of data sets are stored in the vector database, each data set including: metadata in a character field in a data table in a metadata database, vectors corresponding to each metadata, a table name of the data table, and a field name of the character field; the first SQL statement is corrected according to the target metadata to obtain a second SQL statement; the metadata database is queried using the second SQL statement to obtain a query result. In this way, by converting the character field condition values in the user query into vectors and finding the most matching metadata in the vector database, the expression differences of the condition values can be corrected and the accuracy of the SQL statement during execution can be improved. In addition, the vectorized method matches the condition values based on semantic relevance rather than just literal exact matching. This method reduces query failures caused by inaccurate correction of character condition information, and thus solves the technical problem of inaccurate query results in information query scenarios due to the inability to verify the character fields in the SQL statement.
[0053] Example 2
[0054] According to an embodiment of the present application, a data table information query device for implementing the data table information query method in embodiment 1 is also provided. Figure 2 As shown, the data table information query device at least includes: an analysis module 21, a vectorization module 22, a retrieval module 23, a correction module 24 and a query module 25, wherein:
[0055] An analysis module 21 is used to obtain a query text and analyze the query text using a pre-trained large language model to obtain a first SQL statement corresponding to the query text;
[0056] A vectorization module 22, configured to perform vectorization processing on the condition value in the first SQL statement to obtain a first vector when the condition field in the first SQL statement is a character field;
[0057] A retrieval module 23 is used to determine a target data set corresponding to the table name and the condition field in the first SQL statement from a preset vector database, determine a target vector matching the first vector from the target data set, and determine target metadata corresponding to the target vector, wherein the vector database stores multiple data sets, each of which includes: metadata in a character field in a data table in the metadata database, vectors corresponding to each metadata, a table name of the data table, and a field name of the character field;
[0058] A correction module 24, configured to correct the first SQL statement according to the target metadata to obtain a second SQL statement;
[0059] The query module 25 is used to query the metadata database using the second SQL statement to obtain the query result.
[0060] The functions of each module of the data table information query device are described below in conjunction with a specific implementation process.
[0061] The analysis module obtains the query text, and uses the pre-trained large language model to analyze the query text to obtain the first SQL statement corresponding to the query text.
[0062] When the condition field in the first SQL statement is a character field, the vectorization module performs vectorization processing on the condition value in the first SQL statement to obtain a first vector. The specific steps may be performed as follows:
[0063] Determine a condition value in the first SQL statement; and vectorize the condition value using a vector conversion model to obtain a first vector.
[0064] The retrieval module determines a target data set corresponding to a table name and a condition field in a first SQL statement from a preset vector database, determines a target vector matching the first vector from the target data set, and determines target metadata corresponding to the target vector, wherein the vector database stores multiple data sets, each of which includes: metadata in a character field in a data table in the metadata database, vectors corresponding to each metadata, a table name of the data table, and a field name of the character field.
[0065] As an optional implementation, the construction process of a vector database may include the following steps: obtaining multiple data tables in a metadata database; for each data table, determining each character field in the data table; for each character field, performing data deduplication processing on all metadata in the character field, and combining the obtained multiple metadata into a metadata subset; using a pre-trained vector conversion model to vectorize each metadata in the metadata subset, and combining the obtained multiple vectors into a vector subset; constructing a data set based on the table name of the data table, the field name of the character field, the metadata subset and the vector subset; and combining the obtained multiple data sets into a vector database.
[0066] As an optional implementation, for any data table, when the data table is updated, a newly added first character field and an existing and changed second character field in the data table are determined; for the first character field, all newly added metadata in the first character field are deduplicated, and the multiple newly added metadata obtained are combined into a newly added metadata subset; each newly added metadata in the newly added metadata subset is vectorized using a vector conversion model, and the multiple newly added vectors obtained are combined into a new vector subset; a first data set is constructed based on the table name of the data table, the field name of the first character field, the newly added metadata subset and the newly added vector subset; the first data set is added to a vector database; for the second character field, the changed metadata in the second character field is determined; a second data set corresponding to the second character field is determined from the vector database; if there is changed metadata in the second data set, the changed metadata is not processed; if there is no changed metadata in the second data set, the changed metadata is vectorized using a vector conversion model to obtain a changed vector, and the changed metadata and the changed vector are added to the second data set.
[0067] As an optional implementation, the training process of the vector conversion model may include the following steps: constructing an initial model, wherein the initial model is a supervised learning model with an attention mechanism; obtaining multiple groups of SQL statements as training samples, and determining the vectorized representation of each group of SQL statements as sample labels; and iteratively training the initial model using the training samples and sample labels to obtain a vector conversion model.
[0068] As an optional implementation, a target data set corresponding to the table name and condition field in the first SQL statement is determined from a preset vector database, and a target vector matching the first vector is determined from the target data set, including: determining the target data set from the vector database, wherein the table name of the data table in the target data set is the same as the table name in the first SQL statement, and the field name of the character field in the target data set is the same as the condition field in the first SQL statement; respectively calculating the similarity between each vector in the target data set and the first vector, and determining the vector with the greatest similarity to the first vector as the target vector.
[0069] The correction module corrects the first SQL statement according to the target metadata to obtain a second SQL statement, which can be performed through the following steps:
[0070] When the condition value in the target metadata is the same as that in the first SQL statement, the first SQL statement is directly used as the second SQL statement; when the condition value in the target metadata is different from that in the first SQL statement, the condition value in the first SQL statement is replaced by the target metadata, and the adjusted first SQL statement is used as the second SQL statement.
[0071] The query module uses the second SQL statement to query the metadata database to obtain the query result.
[0072] It should be noted that each module in the data table information query device in the embodiment of the present application corresponds one by one to each implementation step of the data table information query method in Example 1. Since a detailed description has been given in Example 1, some details not reflected in this embodiment can be referred to Example 1 and will not be repeated here.
[0073] Example 3
[0074] According to an embodiment of the present application, a computer program product is also provided, which includes a computer program, wherein when the computer program is executed by a processor, the data table information query method in Example 1 is implemented.
[0075] According to an embodiment of the present application, a non-volatile storage medium is also provided, which includes a stored computer program, wherein the device where the non-volatile storage medium is located executes the data table information query method in Example 1 by running the computer program.
[0076] According to an embodiment of the present application, a processor is further provided, which is used to run a computer program, wherein the data table information query method in Example 1 is executed when the computer program is running.
[0077] According to an embodiment of the present application, an electronic device is also provided, which includes: a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to execute the data table information query method in Example 1 through the computer program.
[0078] Specifically, the computer program executes the following steps when it is running: obtaining a query text, and analyzing the query text using a pre-trained large language model to obtain a first SQL statement corresponding to the query text; when the condition field in the first SQL statement is a character field, vectorizing the condition value in the first SQL statement to obtain a first vector; determining a target data set corresponding to the table name and the condition field in the first SQL statement from a preset vector database, determining a target vector matching the first vector from the target data set, and determining target metadata corresponding to the target vector, wherein the vector database stores multiple data sets, each of which includes: metadata in a character field in a data table in the metadata database, vectors corresponding to each metadata, a table name of the data table, and a field name of the character field; correcting the first SQL statement according to the target metadata to obtain a second SQL statement; and querying the metadata database using the second SQL statement to obtain a query result.
[0079] As an optional implementation, the electronic device may be in the form of a mobile terminal, a computer terminal or a similar computing device. Figure 3 FIG. 1 shows a hardware structure block diagram of an electronic device for implementing a data table information query method. Figure 3 As shown, the electronic device 30 may include one or more (302a, 302b, ..., 302n are used to illustrate) processors 302 (the processor 302 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA), a memory 304 for storing data, and a transmission device 306 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 3 The structure shown is only for illustration and does not limit the structure of the above electronic device. Figure 3 More or fewer components as shown, or with Figure 3 Different configurations shown.
[0080] It should be noted that the one or more processors 302 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 electronic device 30. 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).
[0081] The memory 304 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the data table information query method in the embodiment of the present application. The processor 302 executes various functional applications and data processing by running the software programs and modules stored in the memory 304, that is, realizing the vulnerability detection method of the above-mentioned application. The memory 304 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 304 may further include a memory remotely arranged relative to the processor 302, and these remote memories may be connected to the electronic device 30 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 a combination thereof.
[0082] The transmission device 306 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 electronic device 30. In one example, the transmission device 306 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 306 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0083] 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 electronic device 30 .
[0084] The serial numbers of the above embodiments are only for description and do not represent the advantages or disadvantages of the embodiments.
[0085] 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.
[0086] 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 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.
[0087] 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 over multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.
[0088] 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.
[0089] 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, 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, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of each embodiment method 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, etc. Various media that can store program codes.
[0090] The above are only preferred implementations 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 data table information query method, characterized in that: include: Acquire a query text, and analyze the query text using a pre-trained large language model to obtain a first structured query language SQL statement corresponding to the query text; When the condition field in the first SQL statement is a character field, vectorizing the condition value in the first SQL statement to obtain a first vector; Determine a target data set corresponding to the table name and condition field in the first SQL statement from a preset vector database, determine a target vector matching the first vector from the target data set, and determine target metadata corresponding to the target vector, wherein the vector database stores a plurality of data sets, each of which includes: metadata in a character field in a data table in the metadata database, vectors corresponding to each of the metadata, the table name of the data table, and the field name of the character field; Correcting the first SQL statement according to the target metadata to obtain a second SQL statement; The metadata database is queried using the second SQL statement to obtain a query result.
2. The method according to claim 1, characterized in that: The process of constructing the vector database includes: Acquire multiple data tables in the metadata database; For each data table, determine each character field in the data table; For each character field, perform data deduplication processing on all metadata in the character field, and form a metadata subset with the obtained multiple metadata; Using a pre-trained vector conversion model to vectorize each metadata in the metadata subset, and combining the obtained multiple vectors into a vector subset; Constructing the data set according to the table name of the data table, the field name of the character field, the metadata subset and the vector subset; The obtained multiple data sets are combined into the vector database.
3. The method according to claim 2, characterized in that The method further comprises: for any data table, when the data table is updated, determining each newly added first character field, the existing and changed second character field, and the deleted third character field in the data table; For each of the first character type fields, perform data deduplication processing on all metadata in the first character type field, and form a newly added metadata subset with the obtained multiple metadata; perform vectorization processing on each metadata in the newly added metadata subset using the vector conversion model, and form a newly added vector subset with the obtained multiple vectors; construct a first data set according to the table name of the data table, the field name of the first character type field, the newly added metadata subset and the newly added vector subset; and add the first data set to the vector database; For each second character field, determine the second data set corresponding to the second character field from the vector database; determine each newly added first metadata, modified second metadata, third metadata before modification corresponding to the second metadata, and deleted fourth metadata in the second character field; for each first metadata or second metadata, detect whether there is metadata identical to the first metadata or the second metadata in the second data set; if so, do not process the first metadata or the second metadata; if not, vectorize the first metadata or the second metadata using the vector conversion model to obtain a newly added vector, and add the first metadata or the second metadata and the corresponding newly added vector to the second data set; for each third metadata or the fourth metadata, delete the third metadata or the fourth metadata and the vector corresponding to the third metadata or the fourth metadata from the second data set; For each of the third character fields, the third data set corresponding to the third character field is deleted from the vector database.
4. The method according to claim 2, characterized in that: Vectorizing the conditional value in the first SQL statement to obtain a first vector includes: Determine the condition value in the first SQL statement; The conditional value is vectorized using the vector conversion model to obtain the first vector.
5. The method according to any one of claims 2 to 4, characterized in that The training process of the vector conversion model includes: Constructing an initial model, wherein the initial model is a supervised learning model with an attention mechanism; Acquire multiple groups of SQL statements as training samples, and determine a vectorized representation of each group of SQL statements as a sample label; The initial model is iteratively trained using the training samples and the sample labels to obtain the vector conversion model.
6. The method according to claim 1, characterized in that Determining a target data set corresponding to the table name and the condition field in the first SQL statement from a preset vector database, and determining a target vector matching the first vector from the target data set, including: Determine the target data set from the vector database, wherein the table name of the data table in the target data set is the same as the table name in the first SQL statement, and the field name of the character field in the target data set is the same as the condition field in the first SQL statement; The similarities between each vector in the target data set and the first vector are calculated respectively, and the vector having the greatest similarity to the first vector is determined as the target vector.
7. The method according to claim 1, characterized in that Correcting the first SQL statement according to the target metadata to obtain a second SQL statement includes: When the target metadata and the condition value in the first SQL statement are the same, directly use the first SQL statement as the second SQL statement; When the target metadata is different from the condition value in the first SQL statement, the condition value in the first SQL statement is replaced by the target metadata, and the adjusted first SQL statement is used as the second SQL statement.
8. A data table information query device, characterized in that: include: An analysis module is used to obtain a query text and analyze the query text using a pre-trained large language model to obtain a first SQL statement corresponding to the query text; a vectorization module, configured to perform vectorization processing on the condition value in the first SQL statement to obtain a first vector when the condition field in the first SQL statement is a character field; A retrieval module is used to determine a target data set corresponding to the table name and condition field in the first SQL statement from a preset vector database, determine a target vector matching the first vector from the target data set, and determine target metadata corresponding to the target vector, wherein the vector database stores a plurality of data sets, each of which includes: metadata in a character field in a data table in the metadata database, vectors corresponding to each of the metadata, the table name of the data table, and the field name of the character field; A correction module, used for correcting the first SQL statement according to the target metadata to obtain a second SQL statement; The query module is used to query the metadata database using the second SQL statement to obtain a query result.
9. A computer program product, characterized in that include: A computer program, wherein when the computer program is executed by a processor, the data table information query method described in any one of claims 1 to 7 is implemented.
10. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the data table information query method according to any one of claims 1 to 7 through the computer program.
Citation Information
Cited By
Enterprise-level database field semantic confirmation method and system based on active probe
CN122262220A