Library query system, method and equipment based on information retrieval and large model and medium

Through the database query system based on information retrieval and large models, the problems of traditional database query complexity and low accuracy of SQL statements are solved, and efficient query and self-learning and self-correction capabilities in multiple database modes are realized, improving query efficiency. accuracy and ease of use.

CN118733611APending Publication Date: 2024-10-01CHINA TELECOM ARTIFICIAL INTELLIGENCE TECHNOLOGY (BEIJING) CO LTD
View PDF 0 Cites 13 Cited by

Patent Information

Application Number
CN202410906168.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-08
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

Traditional database queries are complex and difficult to implement efficient queries. The accuracy and executability of general SQL statements are low, and they cannot adapt to differences in different database modes and table field information.

Method used

Using a database query system based on information retrieval and large models, including table searchers, field searchers, SQL skeleton searchers, large model agents and intelligent error correction modules, the user input is transformed through the semantic coding model to generate targets with high similarity. Tables, fields and SQL statement skeletons are used for intelligent error correction to generate accurate SQL statements.

Benefits of technology

It provides good support in multiple database modes and complex data query scenarios. It has self-learning and self-correction capabilities, which improves the accuracy and ease of use of queries. It is suitable for multiple database modes and has achieved good verification results in practical applications. .

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733611A_ABST
    Figure CN118733611A_ABST
Patent Text Reader

Abstract

The invention discloses a library query system, method and equipment based on information retrieval and a large model and a medium. The system comprises a table retriever, a field retriever, an SQL (Structured Query Language) skeleton retriever, a large model agent and an intelligent error correction module, wherein the table retriever, the field retriever and the SQL skeleton retriever are respectively used for performing table retrieval, field retrieval and SQL statement skeleton query according to a question input by a user to obtain a target table, a target field and a target SQL statement skeleton; the large model agent is used for generating a target SQL statement corresponding to the question input by the user according to the target table, the target field and the target SQL statement skeleton; and the intelligent error correction module is used for performing intelligent error correction on the target SQL statement. Based on information retrieval, small sample learning and large model technologies, an intelligent access scheme for generating the SQL around the text is constructed, and good support can be provided under various database modes and complex data query scenes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database query, and in particular to a database query system, method, device and medium based on information retrieval and large model. Background Art

[0002] Traditional databases are usually complex structures composed of multiple tables, which require the design and management of relationships between multiple tables, including connections, indexes, data partitions, etc. This requires database query operations to take into account the associations and conditions between multiple tables, increasing the complexity of the query and placing higher demands on the professional level of the query personnel.

[0003] SQL (Structured Query Language) is a widely used database query language that uses a series of statements and commands to perform functions such as data definition, data query, data operation, and data control. However, different databases have specific modes, and the tables and field information involved in different library files are also different. Therefore, most common SQL statements have low accuracy and low executable rate, and cannot achieve efficient database query. Summary of the invention

[0004] In view of this, an embodiment of the present invention provides a library query system, method, device and medium based on information retrieval and large model.

[0005] The first aspect of the present invention provides a library query system based on information retrieval and large model agent, including a table retriever, a field retriever, an SQL skeleton retriever, a large model agent and an intelligent error correction module;

[0006] The table retriever is used to perform table retrieval in the database according to the question input by the user to obtain at least one target table;

[0007] The field retriever is used to perform field retrieval in the target table retrieved by the table retriever according to the question input by the user, and obtain at least one target field;

[0008] The SQL skeleton retriever is used to perform SQL statement skeleton query according to the question input by the user, and obtain at least one target SQL statement skeleton;

[0009] The large model agent is used to generate a target SQL statement corresponding to the question input by the user based on the target table, target field and target SQL statement skeleton;

[0010] The intelligent error correction module is used to perform intelligent error correction on the target SQL statement.

[0011] Furthermore, the table retriever performs table retrieval by the following steps:

[0012] Receive questions input by users and convert them into word vectors through the semantic encoding model;

[0013] Represent the tables involved in the database as dense vectors and store them in a structured manner in the vector library;

[0014] The dense vectors stored in the vector library are flattened and expanded to form a text description of the table with the project name and project type;

[0015] The similarity between the word vector and the dense vector is calculated, and the table corresponding to the dense vector whose similarity is higher than the preset table similarity threshold is determined as the target table.

[0016] Furthermore, the field searcher performs field search through the following steps:

[0017] Receive questions input by users and convert them into word vectors through the semantic encoding model;

[0018] For each item type in the target table, item description and item value are extracted to obtain multiple field vectors, which are stored in the field knowledge base;

[0019] The similarity between the word vector and the field vector is calculated, and the item type in the target table corresponding to the field vector whose similarity is higher than the preset field similarity threshold is determined as the target field.

[0020] Furthermore, the SQL skeleton retriever performs SQL statement skeleton query through the following steps:

[0021] Get a preset SQL skeleton candidate set, which contains multiple SQL statement skeletons;

[0022] Receive questions input by users and convert them into word vectors through the semantic encoding model;

[0023] Calculate the similarity between the word vector and the SQL skeleton candidate set, and select a preset number of SQL statement skeletons with the highest similarity as the target SQL statement skeletons.

[0024] Furthermore, the large model agent generates a target SQL statement corresponding to the question input by the user according to the target table, target field and target SQL statement skeleton, which specifically includes the following steps:

[0025] Break down the user input problem into multiple sub-problems;

[0026] Match a SQL statement skeleton in the target SQL statement skeleton based on each sub-question;

[0027] Fill in the SQL statement skeleton matched by each sub-question with information based on the target table and target field to obtain multiple SQL sub-statements;

[0028] Combine multiple SQL sub-statements to form a target SQL statement.

[0029] Furthermore, the intelligent error correction module specifically includes an SQL execution module, an error prompt word generation module and an error correction module;

[0030] The SQL execution module is used to execute the target SQL statement and determine whether there is error information in the target SQL statement according to the execution result; when there is error information, the SQL execution module is also used to determine the error information, error type and error SQL in the target SQL statement;

[0031] The error prompt word generation module is used to generate prompt words about error information, error type and error SQL when there is error information in the target SQL statement;

[0032] The error correction module is used to perform error correction on the target SQL statement according to the prompt words generated by the error prompt word generation module.

[0033] A second aspect of the present invention provides a library query method based on information retrieval and large model agent, comprising the following steps:

[0034] Perform table search in the database according to the question input by the user to obtain at least one target table;

[0035] Performing a field search in the target table retrieved by the table retriever according to the question input by the user to obtain at least one target field;

[0036] Perform SQL statement skeleton query according to the question input by the user to obtain at least one target SQL statement skeleton;

[0037] Generate a target SQL statement corresponding to the question input by the user according to the target table, target field and target SQL statement skeleton;

[0038] Perform intelligent error correction on the target SQL statement.

[0039] Further, according to the target table, target field and target SQL statement skeleton, a target SQL statement corresponding to the question input by the user is generated, which specifically includes the following steps:

[0040] Break down the user input problem into multiple sub-problems;

[0041] Match a SQL statement skeleton in the target SQL statement skeleton based on each sub-question;

[0042] Fill in the SQL statement skeleton matched by each sub-question with information based on the target table and target field to obtain multiple SQL sub-statements;

[0043] Combine multiple SQL sub-statements to form a target SQL statement.

[0044] A third aspect of the present invention provides an electronic device, including a processor and a memory;

[0045] The memory is used to store a library query system based on information retrieval and large model intelligent agents;

[0046] A library query method based on information retrieval and large model intelligent agent is implemented by a processor execution program.

[0047] A fourth aspect of the present invention provides a computer-readable storage medium, which stores a program of a library query system based on information retrieval and large model intelligent agents, and the program is executed by a processor to implement a library query method based on information retrieval and large model intelligent agents.

[0048] The embodiment of the present invention also discloses a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device can read the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the above method.

[0049] The embodiments of the present invention have the following beneficial effects: The present invention constructs an intelligent data acquisition agent that generates SQL around text based on information retrieval, small sample learning and large model technology. The agent can provide good support in various database modes and complex data query scenarios. It has the ability of self-learning and self-correction, which is smarter and easier to operate. The library query solution of the embodiment of the present invention has been put into actual intelligent data acquisition production scenarios, and has achieved good verification results in public data lists.

[0050] Additional aspects and advantages of the present invention will be given in part in the following description, and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0052] Figure 1The present invention is a schematic diagram of an SQL generation process of a library query system based on information retrieval and a large model.

[0053] Figure 2 The present invention is an implementation flow chart of a table retriever in a library query system based on information retrieval and a large model according to an embodiment of the present invention.

[0054] Figure 3 The present invention is an embodiment of a flow chart of the implementation of a field retriever in a library query system based on information retrieval and a large model.

[0055] Figure 4 It is a flowchart for implementing a SQL skeleton retriever in a library query system based on information retrieval and a large model according to an embodiment of the present invention.

[0056] Figure 5 It is a schematic diagram of database model information output by a table retriever and a field retriever of a library query system based on information retrieval and a large model in an embodiment of the present invention.

[0057] Figure 6 It is a schematic diagram of a large model agent data retrieval instruction in a library query system based on information retrieval and large models in an embodiment of the present invention.

[0058] Figure 7 It is a schematic diagram of the process of generating SQL statements by a large model agent in a library query system based on information retrieval and large models in an embodiment of the present invention.

[0059] Figure 8 The present invention is a schematic diagram of the basic flow of a library query method based on information retrieval and large models.

[0060] Fig. 9 The figure is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention.

[0061] Fig.10 It is a schematic diagram of the structure of a computer-readable storage medium according to an embodiment of the present invention. DETAILED DESCRIPTION

[0062] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0063] A large-model agent is an intelligent entity that can perceive the environment, make decisions, and perform tasks. Unlike traditional artificial intelligence, a large-model agent has the ability to think independently and call tools to gradually complete a given goal. In the field of artificial intelligence, a large-model agent is usually composed of one or more modules and uses a large deep learning model as a core component. The agent can operate in a variety of environments. Its design and implementation depends on the requirements of the task. It usually includes a perception module, a decision module, a learning module, etc., and is suitable for a variety of complex scenarios.

[0064] Although the intelligent agent built by the large language model has the ability to perform SQL queries in general scenarios, different databases have specific modes, and the tables and field information involved in different library files are also different. If all the information obtained is directly injected into the intelligent agent for decision-making, it will cause information overload and it will be difficult to obtain the correct results.

[0065] On the other hand, existing SQL generation solutions often lack the ability to pre-learn table fields and table information. Due to the lack of table information, the big model cannot determine the data table that the current user query depends on based on existing knowledge, resulting in the generated fields not corresponding to the table and data retrieval failure. Similarly, if there is no field retrieval capability, the big model will be insensitive to the field information of the table and lack field type restriction knowledge, resulting in the inability to correctly execute the generated SQL. Therefore, in order to assist the big model in decision-making, an information retrieval system is very necessary.

[0066] The main goal of information retrieval is to help users obtain the information they need based on their input. Through intelligent analysis and calculation of the input, the results that best meet the user's needs will be returned. Through information retrieval capabilities, the tables and fields most relevant to the current problem can be selected from a large number of user databases, and the relevant knowledge can be provided to the large model, so that the large model can obtain more robust prompts and its output results are also implicitly constrained. In addition, through information retrieval capabilities, the most similar SQL strategy can be matched for user queries among a large number of samples. The small sample learning ability of the large model is organized through the decoding steps of similar SQL strategies to improve the domain characteristics of the large model.

[0067] Based on this, the present invention constructs an intelligent data acquisition agent that generates SQL around text based on information retrieval, small sample learning and large model technology. The agent can provide good support in various database modes and complex data query scenarios.

[0068] The first embodiment of the present invention provides a library query system based on information retrieval and large model intelligent agent. Figure 1 As shown, it includes a table retriever, a field retriever, an SQL skeleton retriever, a large model agent and an intelligent error correction module.

[0069] Table Retriever: In the embodiment of the present invention, the table retriever is used to perform table retrieval in the database according to the question input by the user to obtain at least one target table. In real business scenarios, the database involves tens of thousands of data tables, and different data tables often contain different fields. The table retriever can accurately match the most relevant table for the user query, effectively filter out the interference of irrelevant information, and improve the accuracy of the data acquisition results.

[0070] Specifically, the table retriever performs table retrieval through the following steps:

[0071] S101. Receive a question input by a user, and convert the question input by the user into a word vector through a semantic encoding model;

[0072] S102. Represent the tables involved in the database as dense vectors and store them in a structured manner in a vector library;

[0073] S103. Flatten the dense vector stored in the vector library to form a text description of the table with the project name and project type;

[0074] S104. Calculate the similarity between the word vector and the dense vector, and determine the table corresponding to the dense vector whose similarity is higher than a preset table similarity threshold as the target table.

[0075] In the table retriever of the embodiment of the present invention, all tables involved in the database are represented as dense vectors and stored in a vector library in a structured manner. After receiving the question Q input by the user, it is first converted into a word vector through a semantic encoding model; then the table retriever calculates the similarity between all table vectors T in the vector library and the question Q. According to the similarity score, a list of table IDs with similarities higher than a preset table similarity threshold is returned as the result of the table search.

[0076] The table retriever of the embodiment of the present invention is implemented based on the ColBERT (Contextualized Late Interaction over Bert) model. The training of the table retriever is implemented based on a data set consisting of query pairs of several user questions and SQL statements. Through each query pair, the table involved in the current user question can be clarified. Finally, query pairs of user questions and tables are constructed, which are expressed as <user question, table 1>, <user question, table 2>, <user question, table 3>... <user question, table n>. The table retrieval module converts the structured field information into a continuous text format in a field tiling manner, and the text will be used as a representation of table T. Then, the late interaction method MaxSim based on maximum similarity is used to calculate the similarity between the user question Q and the table T, and the degree of association between the table and the question is determined by the similarity score.

[0077] For example, Figure 2 As shown in the figure, the database involved in the current user query is "california_schools", which has three tables. The table retriever flattens the structured information of each table (retains the field name, field type, and separates different fields with "|") to form a text description of the table information; the user query and table information are input into the model to calculate the similarity score. Finally, the score threshold θ is set, and the tables with a similarity score greater than θ with the user query will be retained, otherwise they will be discarded. Figure 2 In the example given in , the "frpm" table is kept, and the "schools" and "satscore" tables are filtered.

[0078] After the table retriever is screened, the database query table range can be accurately narrowed down, which can effectively improve the decision-making ability of the model. In the complete data acquisition solution, table screening is the first link of the entire system. The screened target table information will be used for subsequent field detection and large model decision modules.

[0079] Field retriever: In the embodiment of the present invention, the field retriever is used to perform field retrieval in the target table retrieved by the table retriever according to the question input by the user, and obtain at least one target field. Although the table retriever has filtered most irrelevant tables; in actual production scenarios, even in the same target table, many different fields are usually involved, and not all fields in the table are related to the user's question. Therefore, the field retriever of the embodiment of the present invention can filter the fields most relevant to the user's query and further filter irrelevant information in the target table.

[0080] Specifically, the field searcher performs field search through the following steps:

[0081] S201. Receive a question input by a user, and convert the question input by the user into a word vector through a semantic encoding model;

[0082] S202. Extract the project description and project value of each project type in the target table to obtain multiple field vectors, which are stored in the field knowledge base;

[0083] S203. Calculate the similarity between the word vector and the field vector, and determine the item type in the target table corresponding to the field vector whose similarity is higher than a preset field similarity threshold as the target field.

[0084] The field retriever of the embodiment of the present invention is also implemented based on the ColBERT model. Based on the query pair of user questions and SQL statements, the field information involved in different tables in the SQL statement is extracted through rules, and multiple triples are represented with the user questions: <user question, table 1, field 1>, <user question, table 1, field 2>. In addition, in order to make the semantic expression of the field richer, the embodiment of the present invention queries the high-frequency values ​​stored in the database for each field through the preset function in SQL, and then extracts the field type, field description, field value description, and field value in the table building file, and stores them as a six-tuple structure: <table, field, field type, field description, field value, field value description>, which will be injected into the field representation process as knowledge. In the actual reasoning stage, the field retriever first extracts the field vectors corresponding to the N target tables output by the table retriever from the field knowledge base, and then inputs the user query and the candidate fields into the field retriever to further filter out the field information with the greatest correlation under the corresponding table.

[0085] For example, Figure 3 As shown in the figure, the target table output by the table retriever is "frpm", which contains fields such as "CDSCode", "Academic Year", "IRC" and their corresponding field values. The field retriever first performs a field knowledge base query for each field to obtain the commonly used storage value of the field in the database. Then, the table information, field description, field value, etc. are spliced ​​by different fields to construct knowledge-based field features; finally, the field knowledge features are calculated with the user query for similarity; the score threshold μ is set, and the field features with a similarity score greater than μ with the user query will be retained, otherwise they will be discarded.

[0086] SQL skeleton retriever: In an embodiment of the present invention, the SQL skeleton retriever is used to perform SQL statement skeleton query according to the question input by the user to obtain at least one target SQL statement skeleton. For similar user queries, the generated SQL usually also has a certain similarity. For example, "query employee A's work number" and "query student B's student number", the corresponding SQL are: select employee_id from employees where employee_name='A' and select student_idfrom students where student_name='B'. In the given example, except for the different tables and fields involved, the generated SQL skeletons are also completely similar: select[MASK]from[MASK]where[MASK]='[MASK]'. Therefore, if there is an SQL strategy for the first question in the preset SQL skeleton candidate set, the large model can complete the decoding of the second question by learning the sample. The SQL skeleton retriever is used to retrieve the SQL skeleton through user questions to improve the accuracy of the large model output.

[0087] The construction of the SQL skeleton candidate set is based on a preset massive number of <user question, SQL statement> query pairs. First, (1) the SQL statements in the query pairs are input into the large model agent, and the large model agent performs machine labeling to generate the corresponding SQL skeleton. Secondly, the correctness of the generated SQL skeleton is manually verified for a second time, and the qualified SQL skeleton and the user question are combined into the SQL skeleton candidate set.

[0088] The SQL skeleton retriever performs SQL statement skeleton query through the following steps:

[0089] S301. Obtain a preset SQL skeleton candidate set, where the SQL skeleton candidate set includes multiple SQL statement skeletons;

[0090] S302. Receive a question input by a user, and convert the question input by the user into a word vector through a semantic encoding model;

[0091] S303. Calculate the similarity between the word vector and the SQL skeleton candidate set, and select a preset number of SQL statement skeletons with the highest similarity as target SQL statement skeletons.

[0092] For example, Figure 4As shown in the figure, after receiving the user query, the SQL skeleton retriever converts the user input question into a word vector, and all SQL skeletons in the SQL skeleton candidate set are input into the SQL skeleton retriever together with the user query to calculate the similarity score. The higher the score of the SQL skeleton, the higher the similarity between the user query and the decoding process involved and the current user query. Then select the top 3 training samples with the highest correlation for the next large model decision.

[0093] Big model agent: The big model agent of the embodiment of the present invention is used to generate a target SQL statement corresponding to the question input by the user based on the target table, target field and target SQL statement skeleton. In real business scenarios, the SQL involved usually involves multi-table queries, multi-condition associations and complex function applications. If SQL is generated directly from the user's original query, it will be difficult for the big model to understand the complex process, resulting in a low accuracy rate of generated SQL. Therefore, the big model agent designed in the embodiment of the present invention can automatically call the pre-placed table screening, field screening and small sample screening for prompt construction, use the generative semantic big model to make decisions on the user's query, and generate SQL.

[0094] Specifically, the large model agent generates a target SQL statement corresponding to the question input by the user according to the target table, target field and target SQL statement skeleton, which specifically includes the following steps:

[0095] S401. Decompose the user input question into multiple sub-questions;

[0096] S402. Matching a SQL statement skeleton in the target SQL statement skeleton based on each sub-question;

[0097] S403. Fill in the SQL statement skeleton matching each sub-question with information based on the target table and the target field to obtain multiple SQL sub-statements;

[0098] S404. Combine multiple SQL sub-statements to form a target SQL statement.

[0099] In the embodiment of the present invention, the large model agent adopts a thinking chain mode to automatically split the SQL generation process into multiple sub-problems, and the sub-problems are gradually divided from simple to complex to gradually generate the final SQL.

[0100] In terms of prompt construction, the prompt used by the big model agent for decision-making consists of five parts: instructions, database schema, knowledge, small samples, and user queries. Instructions are used to indicate the tasks and precautions that the big model currently needs to complete; database schema refers to the structured representation of high-value tables and fields screened out through table retrieval and field retrieval, which is used to limit the scope of SQL generation; knowledge is used to establish a text description associated with the database in the user query, or the interpretation of the field, which can assist users in understanding the meaning of the fields in the big model; small samples are multiple historical user queries with similar semantics to the current user query screened out by the SQL skeleton retriever and their SQL decoding process; user query and indicate the user's current query problem.

[0101] The database schema information generated by the table searcher and the field searcher in the embodiment of the present invention is as follows: Figure 4 As shown in the figure, "Table" indicates a target table, "(……)" indicates a specific field, and the '……' in the field is the field value. Figure 5 As shown in the figure, given the database module, knowledge and user query information, the large model agent will use the effective SQLite to understand the database model and knowledge and decompose the user query problem into sub-problems. The instruction information may contain certain constraints. Figure 5 The constraints shown in the table include: (1) In “SElECT <column>" statement, only the columns required in the user query are selected, without any unnecessary columns or values; (2) in the 'FROM ' or 'J0IN' Do not include unnecessary tables; (3) If you use the max or min function, use 'JOIN <column>)' statement or 'SELECT MIN( <column>)' statement; (4) if [field value] <column> If it has "None" or null value, try to use "J0IN< / column> < / column> < / column> 'statement, and then use 'SELECT MAX( <column>is NOT NULL" statement; (5) If you use `ORDER BY <column>Asc|DESC` statement, add `GROUP BY in front <column>` to select a different field value.

[0102] The SQL decoding process is as follows Figure 6 As shown in the figure, the large model agent decomposes the problem into sub-objects under the premise of considering the constraints, generates the SQL skeleton for each sub-problem and fills in the corresponding field values, and generates the final SQL statement after thinking step by step.

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

[0104] Intelligent error correction module: The intelligent error correction module of the embodiment of the present invention is used to perform intelligent error correction on the target SQL statement. Through the previous model retrieval and the decision of the large model agent, the system of the embodiment of the present invention has been able to obtain a preliminary generated SQL statement, but due to the illusion of the large model agent, the error of the large model in understanding the database knowledge, or the error propagation caused by the front retrieval module, some of the generated SQL statements have some errors. In the actual operation scenario, the errors are mainly divided into five categories: syntax errors, pattern link errors, internal errors, empty results, and mismatched results. In the actual operation scenario, it is difficult for the large model agent to judge whether the current result meets the user's expectations through its own knowledge. Therefore, the embodiment of the present invention mainly corrects syntax errors, pattern link errors, internal errors, and empty results.

[0105] The intelligent error correction module in the embodiment of the present invention specifically includes an SQL execution module, an error prompt word generation module and an error correction module.

[0106] The SQL execution module is used to execute the target SQL statement and determine whether there is error information in the target SQL statement (such as syntax errors or schema link errors such as forged table fields) based on the execution results; when there is error information, the SQL execution module is also used to determine the error information, error type and error SQL in the target SQL statement.

[0107] The error prompt word generation module is used to generate prompt words about error information, error type and error SQL when there is error information in the target SQL statement.

[0108] The error correction module is used to perform error correction on the target SQL statement according to the prompt words generated by the error prompt word generation module.

[0109] In the embodiment of the present invention, when the large model agent obtains the error correction prompt of SQL, the large model agent will automatically correct the error according to the current error information and generate the corrected SQL. The corrected SQL will repeatedly execute the error type determination module and automatically execute error correction in a loop until the current SQL no longer has errors or reaches the maximum error correction limit. Figure 6 The error correction module determines that there is no need to correct the SQL generated in the error correction module. The SQL currently generated by the large model is used as the final SQL, and the result is: SELECT MAX(CAST(`FRPM Count(K-12)`AS REAL) / `Enrollment(K-12)`)AS`highest_eligible_free_rate`FROM frpm WHERE`CDSCode`IN(SELECT`CDSCode`FROM schools WHERE`County`='Alameda').

[0110] The present invention proposes an intelligent data acquisition system that combines information retrieval, intelligent agents and large model technologies. Focusing on the problem of inaccurate SQL generation in database intelligent data acquisition scenarios, a set of intelligent data acquisition SQL generation solutions with strong versatility and ease of operation is proposed, and it is actually put into intelligent data acquisition production scenarios. The SQL data acquisition of the embodiment of the present invention involves multiple links such as database model understanding, SQL generation and post-error correction. The designed database intelligent query system based on information retrieval and large model intelligent agents can enable multiple links to complete intelligent collaboration. The large model intelligent agent makes automatic decisions based on the execution status of the link and the generation quality of SQL. It has low resource cost, high reusability, strong practicability and high accuracy.

[0111] The embodiment of the present invention selects a small sample of SQL skeletons based on the similarity between the user query and the SQL skeleton. The influence of the field name and function name is effectively excluded through the construction of the SQL skeleton. The similarity is considered from the overall structure of SQL, which is more conducive to finding samples with similar decoding processes to the current user query, thereby improving the efficiency of large model learning.

[0112] The generative data acquisition method based on the large model provided by the embodiment of the present invention can intelligently complete SQL generation according to the user's input. Due to the prompt information of the large model, the background knowledge can be integrated into the learning and generation process of the model, reducing the information loss caused by indirect knowledge transfer. The generative data acquisition process can dynamically and intelligently generate query statements according to the user's input. Through the table retriever, the characteristics of its table data can be learned for different business scenarios, helping the model to understand the table information and effectively filter redundant information. Through the field retriever, the key elements in the user query are extracted. This optimization effectively helps the model to obtain key information and understand the field constraints of the business data, and improves the correctness of the SQL statement. Through the SQL skeleton monitor, the decoding process most similar to the current user query can be screened out and input into the large model as a small sample, so that the large model can fully understand the domain knowledge and draw on similar SQL decoding processes, enrich the input information of the model, and obtain predictable output.

[0113] The second embodiment of the present invention discloses a library query method based on information retrieval and large model agent, such as Figure 8 As shown, the following steps are included:

[0114] S501. Perform a table search in the database based on the question entered by the user to obtain at least one target table;

[0115] S502. Perform a field search in the retrieved target table according to the question input by the user to obtain at least one target field;

[0116] S503. Perform a SQL statement skeleton query based on the question input by the user to obtain at least one target SQL statement skeleton;

[0117] S504. Generate a target SQL statement corresponding to the question input by the user according to the target table, target field and target SQL statement skeleton;

[0118] S505. Perform intelligent error correction on the target SQL statement.

[0119] Specifically, in step S504, a target SQL statement corresponding to the question input by the user is generated according to the target table, the target field and the target SQL statement skeleton, which specifically includes the following steps:

[0120] S504-1. Decompose the user input question into multiple sub-questions;

[0121] S504-2. Match a SQL statement skeleton in the target SQL statement skeleton based on each sub-question;

[0122] S504-3. Fill in the SQL statement skeleton matching each sub-question based on the target table and target field to obtain multiple SQL sub-statements;

[0123] S504-4. Combine multiple SQL sub-statements to form a target SQL statement.

[0124] The contents of the system in the first embodiment of the present invention are all applicable to the present method embodiment. The functions specifically implemented by the present method embodiment are the same as those of the above system embodiment, and the beneficial effects achieved are also the same as those achieved by the above system.

[0125] The embodiment of the present invention can effectively extract database model knowledge in user queries through table retrieval and field retrieval; SQL skeleton retrieval enables the large model to learn the domain knowledge of the database, greatly improving the accuracy of SQL statement generation; the intelligent error correction step can make corrections in real time according to the execution of SQL, alleviating the error cascading problem in multi-link links. The embodiment of the present invention provides a new solution for database data acquisition.

[0126] Fig. 9 : is a schematic diagram of the structure of the electronic device proposed in the third embodiment of the present invention. The memory of this embodiment stores program instructions for implementing the library query system based on information retrieval and large model intelligent agent of any of the above embodiments. The processor is used to execute the program instructions stored in the memory to perform database query based on information retrieval and large model intelligent agent. Among them, the processor can also be called CPU (Central Processing Unit). The processor may be an integrated circuit chip with signal processing capabilities. The processor can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.

[0127] The contents of the systems and methods in the first and second embodiments of the present invention are applicable to the electronic device embodiment. The functions specifically implemented by the electronic device embodiment are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method.

[0128] Fig.10 Schematic diagram of the structure of the computer-readable storage medium of the fourth embodiment of the present invention. The computer-readable storage medium of the fourth embodiment of the present invention stores program instructions that can implement the above-mentioned library query system and method based on information retrieval and large model intelligent agents, wherein the program instructions can be stored in the above-mentioned storage medium in the form of a software product, including a number of instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of the various implementation methods of the present invention. The aforementioned computer-readable storage medium includes: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), magnetic disks or optical disks, or terminal devices such as computers, servers, mobile phones, and tablets.

[0129] The contents of the system and method in the first and second embodiments of the present invention are applicable to the computer-readable storage medium embodiment. The functions specifically implemented by the computer-readable storage medium embodiment are the same as those of the above method embodiment, and the beneficial effects achieved are also the same as those achieved by the above method.

[0130] This embodiment also provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the above-mentioned related steps to implement the library query system based on information retrieval and large model intelligent agent provided by the above embodiment.

[0131] Those skilled in the art will appreciate that the modules in the devices in the embodiments of the present invention may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments of the present invention may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including corresponding claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including corresponding claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.

[0132] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0133] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or otherwise processing in a suitable manner if necessary, and then stored in a computer memory.

[0134] In addition, each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other. In particular, for embodiments such as devices and equipment, since they are basically similar to method embodiments, the relevant parts can refer to the partial description of the method embodiments. The embodiments of the devices and equipment described above are merely schematic, wherein the modules, units, etc. described as separate components may or may not be physically separated, that is, they may be located in one place, or they may be distributed in multiple places, such as nodes of a system network. Specifically, some or all of the modules and units may be selected according to actual needs to achieve the purpose of the above-mentioned embodiment scheme. Those skilled in the art can understand and implement it without paying creative labor.

[0135] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0136] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described can be combined in any one or more embodiments or examples in a suitable manner.

[0137] In addition, the terms "first", "second", etc. used in the embodiments of the present invention are only used for descriptive purposes and should not be understood as indicating or implying relative importance, or implicitly indicating the number of technical features indicated in the present embodiment. Therefore, the features defined by the terms "first", "second", etc. in the embodiments of the present invention may explicitly or implicitly indicate that the embodiment includes at least one of the features. In the description of the present invention, the word "plurality" means at least two or two or more, such as two, three, four, etc., unless otherwise clearly and specifically defined in the embodiments.

[0138] In the embodiments of the present invention, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element. In addition, components, features, and elements with the same name in different embodiments of the present invention may have the same meaning or different meanings, and their specific meanings need to be determined by their explanation in the specific embodiment or further combined with the context in the specific embodiment.

[0139] Although embodiments of the present invention have been shown and described above, it is to be understood that the above embodiments are exemplary and cannot be construed as limitations of the present invention, and those of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present invention. Those skilled in the art will readily come to think of other embodiments of the present invention after considering the specification and practicing the present invention. This application is intended to cover any variations, uses or adaptations of the present invention, which follow the general principles of the present invention and include common knowledge or customary technical means in the art that are not disclosed in the present invention. The specification and embodiments are intended to be exemplary only, and the true scope and spirit of the present invention are indicated by the following claims.< / column> < / column> < / column> "statement or "WHERE < / column>

Claims

1. A library query system based on information retrieval and large model agent, characterized in that: Including table searcher, field searcher, SQL skeleton searcher, large model agent and intelligent error correction module; The table retriever is used to perform table retrieval in the database according to the question input by the user to obtain at least one target table; The field retriever is used to perform field retrieval in the target table retrieved by the table retriever according to the question input by the user, and obtain at least one target field; The SQL skeleton retriever is used to perform SQL statement skeleton query according to the question input by the user, and obtain at least one target SQL statement skeleton; The large model agent is used to generate a target SQL statement corresponding to the question input by the user based on the target table, target field and target SQL statement skeleton; The intelligent error correction module is used to perform intelligent error correction on the target SQL statement.

2. A library query system based on information retrieval and large model agent according to claim 1, characterized in that: The table searcher performs a table search through the following steps: Receive questions input by users and convert them into word vectors through the semantic encoding model; Represent the tables involved in the database as dense vectors and store them in a structured manner in the vector library; The dense vectors stored in the vector library are flattened and expanded to form a text description of the table with the project name and project type; The similarity between the word vector and the dense vector is calculated, and the table corresponding to the dense vector whose similarity is higher than the preset table similarity threshold is determined as the target table.

3. A library query system based on information retrieval and large model agent according to claim 1, characterized in that: The field searcher performs a field search through the following steps: Receive questions input by users and convert them into word vectors through the semantic encoding model; For each item type in the target table, item description and item value are extracted to obtain multiple field vectors, which are stored in the field knowledge base; The similarity between the word vector and the field vector is calculated, and the item type in the target table corresponding to the field vector whose similarity is higher than the preset field similarity threshold is determined as the target field.

4. A library query system based on information retrieval and large model agent according to claim 1, characterized in that: The SQL skeleton retriever performs SQL statement skeleton query through the following steps: Get a preset SQL skeleton candidate set, which contains multiple SQL statement skeletons; Receive questions input by users and convert them into word vectors through the semantic encoding model; Calculate the similarity between the word vector and the SQL skeleton candidate set, and select a preset number of SQL statement skeletons with the highest similarity as the target SQL statement skeletons.

5. A library query system based on information retrieval and large model agent according to claim 1, characterized in that: The large model agent generates a target SQL statement corresponding to the question input by the user based on the target table, target field and target SQL statement skeleton, which specifically includes the following steps: Break down the user input problem into multiple sub-problems; Match a SQL statement skeleton in the target SQL statement skeleton based on each sub-question; Fill in the SQL statement skeleton matched by each sub-question based on the target table and target field to obtain multiple SQL sub-statements; Combine multiple SQL sub-statements to form a target SQL statement.

6. A library query system based on information retrieval and large model agent according to claim 1, characterized in that: Intelligent error correction module, specifically including SQL execution module, error prompt word generation module and error correction module; The SQL execution module is used to execute the target SQL statement and determine whether there is error information in the target SQL statement based on the execution result; When there is error information, the SQL execution module is also used to determine the error information, error type and error SQL in the target SQL statement; The error prompt word generation module is used to generate prompt words about error information, error type and error SQL when there is error information in the target SQL statement; The error correction module is used to perform error correction on the target SQL statement according to the prompt words generated by the error prompt word generation module.

7. A library query method based on information retrieval and large model agent, characterized in that: The following steps are involved: Perform table search in the database according to the question input by the user to obtain at least one target table; Performing a field search in the retrieved target table according to the question input by the user to obtain at least one target field; Perform SQL statement skeleton query according to the question input by the user to obtain at least one target SQL statement skeleton; Generate a target SQL statement corresponding to the question input by the user based on the target table, target field and target SQL statement skeleton; Perform intelligent error correction on the target SQL statement.

8. A library query method based on information retrieval and large model agent according to claim 7, characterized in that: According to the target table, target field and target SQL statement skeleton, a target SQL statement corresponding to the question input by the user is generated, which specifically includes the following steps: Break down the user input problem into multiple sub-problems; Match a SQL statement skeleton in the target SQL statement skeleton based on each sub-question; Fill in the SQL statement skeleton matched by each sub-question based on the target table and target field to obtain multiple SQL sub-statements; Combine multiple SQL sub-statements to form a target SQL statement.

9. An electronic device, characterized in that: including a processor and a memory; The memory is used to store a library query system based on information retrieval and large model intelligent agent as claimed in any one of claims 1 to 6; The processor executes the program to implement a library query method based on information retrieval and large model intelligent agent as described in any one of claims 7-8.

10. A computer-readable storage medium, characterized in that: The storage medium stores a program of a library query system based on information retrieval and large model intelligent agent as described in any one of claims 1-6, and the program is executed by a processor to implement a library query method based on information retrieval and large model intelligent agent as described in any one of claims 7-8.

Citation Information

Cited By

  • Multi-agent-based SQL statement end-to-end batch generation method

    CN119179711A

  • Large model-based data query and interaction method and program product

    CN119322821A

  • Information query method and device, terminal equipment and storage medium

    CN119357216A

  • Method and device for generating SQL (Structured Query Language) based on semantic alignment and hierarchical Agent

    CN119377255A

  • Automatic Excel analysis result visualization method based on LLM natural language processing

    CN119513160A