Intelligent query method and system based on large model and retrieval enhancement technology
By combining large models and search enhancement technology, non-professionals can query databases through natural language, solving the problem that non-professionals in the existing technology is difficult to obtain database data, and optimizing query efficiency and performance through system automation and fine-tuning .
Patent Information
- Application Number
- CN202411473863.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-22
- Publication Date
- 2024-11-22
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, intelligent query solutions combining large models and search enhancement technologies are lacking, making it difficult for non-professional personnel to obtain data from complex database systems and it is difficult to continuously fine-tune the training of large models to optimize system performance.
Using intelligent query methods based on big model and search enhancement technology, through similar problems, the steps of retrieving, generating SQL, data verification and display, recording and collecting data, fine-tuning and updating big models are established, including data storage, user interaction, data processing, The system of data display and backend management modules realizes reliable query of non-professional personnel and optimizes system performance.
It realizes that non-professional personnel can query databases through natural language, lower the threshold for data use, automate data source access and table structure learning, improve data usage efficiency, and optimize system performance by continuously collecting data and fine-tuning large models.
Smart Images

Figure CN119003743A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of natural language processing big model technology and data analysis, and in particular to an intelligent query method and system based on big model and retrieval enhancement technology. Background Art
[0002] With the continuous development of artificial intelligence technology, NL2SQL, which automatically generates SQL based on large models, has become an important research direction in natural language processing, and the intelligent query system already has a reliable technical foundation. Traditional database queries often require users to manually write SQL statements, which may be very difficult for non-professionals. The intelligent query system based on large models can automatically learn the user's query intentions and the structure of the database through deep learning technology, and automatically generate SQL statements that meet user needs. This system can better understand the user's query intentions, reduce the complexity of the user's operations, and improve query efficiency. At the same time, the intelligent query system based on large models can also gradually improve its query capabilities and accuracy through continuous learning and optimization. Therefore, the intelligent query system based on large models that automatically generates SQL is of great significance in the field of database queries, providing users with a smarter and more efficient query experience.
[0003] The intelligent query system that automatically generates SQL based on large models is the product of the integration of artificial intelligence and data science technology in recent years. The Seq2Seq model is an important architecture in natural language processing. It was originally used for machine translation, but later it was also widely used to convert natural language instructions into SQL queries. In particular, large-scale language models based on the Transformer architecture, such as chatGPT, have made breakthrough progress in natural language understanding. This model can map input sequences to output sequences through the encoder-decoder architecture, which is very suitable for converting free text into structured query statements. These models can understand complex human language structures and contexts, thus providing a solid foundation for converting natural language into SQL queries.
[0004] The intelligent query system needs to accurately parse the intent in natural language and convert it into SQL statements with correct syntax and logic. In order to improve the accuracy and efficiency of SQL generation, it is also necessary to adopt retrieval enhancement (RAG) technology. First, the questions and answers most similar to the user's questions are retrieved from the existing knowledge base through language vector similarity and rearrangement algorithm, and then handed over to the large model to generate the best SQL results. Finally, data can be continuously collected during system use for fine-tuning training, so that the model can learn which strategies are more effective in the process of generating SQL, thereby continuously optimizing the query SQL generation process. The intelligent query system establishes a complete back-end architecture to support real-time query, data collection and model reasoning to ensure that the system can run stably and respond quickly to user requests.
[0005] However, at present, there are few solutions that combine large models and retrieval enhancement technologies to complete intelligent query and retrieval enhancement. This means that queries still require users to manually write SQL statements. It is difficult for non-professionals to obtain data from complex database systems, and it is difficult to continuously fine-tune and train large models, and it is difficult to continuously optimize system performance during use. Summary of the invention
[0006] The purpose of the present invention is to overcome the shortcomings of the prior art and to provide an intelligent query method and system based on a large model and retrieval enhancement technology. It does not require professionals to write SQL statements, but only to ask questions in natural language to query the target data from the database, so that non-professionals can obtain professional data from complex database systems. At the same time, it combines RAG retrieval enhancement to improve the performance of the large model, and records historical data to continuously fine-tune and train the large model.
[0007] The object of the present invention is achieved through the following technical solution: an intelligent query method based on a large model and retrieval enhancement technology, comprising the following steps: S1. Similar question retrieval: retrieve similar questions and answers raised by users in the vector knowledge base; S2. The big model generates SQL using the search results, and passes the retrieved answers and user questions to the big model to generate database query SQL; S3. Data verification and display: Verify the SQL generated by the large model in the database and use charts and graphic tools to display the SQL query result data; S4. Record and collect data, record user questions and SQL generated by the big model and correctly executed, and store them in the vector database; S5. Fine-tune and update the big model. Regularly use the collected data to fine-tune the SQL big model and update and publish the big model.
[0008] An intelligent query method and system based on a large model and retrieval enhancement technology includes a data storage module, a user interaction module, a data processing module, a data display module, and a background management, wherein: Data storage module, including business database, vector database, system file storage, etc.; User interaction module, collects user data, and users determine whether the query returned data is valid; The data processing module uses the big model to convert the user's questions into database query SQL, which is then executed in the database and returns the data query results; The data display module displays the user query results in data charts and graphics according to the situation; Backend management module, corrects SQL that cannot be executed or has incorrect query results, regularly organizes collected data, and fine-tunes and updates large models.
[0009] The beneficial effects of the present invention are as follows: (1) the present invention realizes a new "you ask me answer" query statistics mode, which provides a reliable way for non-professionals to query professional databases and lowers the threshold for data use; (2) The present invention automatically connects to data sources, automatically learns table structures and table relationships, and automatically converts questions to generate SQL and query, thereby improving the efficiency of data use.
[0010] (3) The present invention can collect user questions during the use of the system, which can be used for RAG retrieval enhancement and continuous fine-tuning of the large model, and can continuously optimize and improve the performance of the system during use. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Figure 1 The overall flow chart constructed for the system of the present invention; Figure 2 The system operation flow chart of the present invention is Figure 3 Generate SQL flow chart for similar question retrieval and retrieval enhancement of the present invention; Figure 4 Verify SQL and data display and collection dialogue data flow diagram; Figure 5 A flowchart for fine-tuning and updating a large model for the system of the present invention; Figure 6 It is a system architecture diagram of the present invention. DETAILED DESCRIPTION
[0012] The technical solution of the present invention is further described in detail below in conjunction with the accompanying drawings, but the protection scope of the present invention is not limited to the following.
[0013] The present invention first converts the user's natural language query requirements into SQL query statements that can be executed by the database and executes them based on the SQL big model. If the query is executed correctly, the query result is directly returned. If the query is executed incorrectly or the query result is incorrect, the natural language of the query and the generated SQL statement are recorded, and the backend operation and maintenance perform manual corrections; the SQL that can be correctly executed corresponding to the natural language question will be stored in the vector library as a knowledge base data set for RAG retrieval enhancement. When the data accumulates to a certain amount (more than one thousand items), the data set can be fine-tuned to improve the SQL big model to improve the model's capabilities. Through the above steps, not only is the engineering solution from natural language to SQL query realized, but also a system for continuously iterating and optimizing the SQL big model can be formed.
[0014] The natural language refers to a language that humans use for natural communication, such as Chinese and English, which is the main tool for human communication and thought description.
[0015] The SQL big models are an important type of models in the field of natural language processing. They can convert natural language queries into SQL statements, thereby helping users interact with the database through natural language.
[0016] The RAG retrieval enhancement is a method that combines information retrieval and natural language generation, aiming to improve the efficiency and quality of text processing tasks. This method effectively handles information retrieval and generation problems in natural language processing tasks by combining retrieval methods and generation methods.
[0017] The large model fine-tuning refers to the process of further training a pre-trained large language model using a specific data set to adapt the model to a specific task or field. This method allows the model to be optimized for specific application scenarios while maintaining its versatility, thereby improving the performance and accuracy of the model. Specifically, large model fine-tuning involves adjusting the parameters of the pre-trained model to adapt to the new data distribution and task requirements. Through fine-tuning, large language models can better handle text data in specific fields, such as news reports, scientific research papers, etc., thereby improving performance in related fields.
[0018] like Figure 1 As shown in the figure, an overall flow chart of intelligent query method and system construction based on large model and retrieval enhancement technology is as follows: First, we select the sqlcoder large model and bge-large-zh word embedding model with professional SQL transcription capabilities, then collect the SQL corresponding to the commonly used query targets of the target database, and perform initial fine-tuning training based on the collected data and the sqlcoder large model to make the model have better performance on the target database; the user inputs the query question, and the query SQL is generated using the large model and RAG enhancement technology. Then the system verifies whether the SQL can be executed correctly. If it is incorrect, it is manually corrected and executed again by the backend administrator; the system records all correctly executed questions and SQL, the system regularly evaluates the performance of the large model, and continuously fine-tunes and optimizes the large model based on the accumulated data.
[0019] Combined with Figure 2 , an intelligent query method based on large model and retrieval enhancement technology and system operation flow chart: After the user registers and logs in, he / she selects the query mode. The query mode is for the user to enter SQL query by himself / herself, and the conversation mode is for the user to enter natural language query. The system retrieves the most similar questions and answers from the RAG vector library based on the user input question, and then passes them together to the big model to generate the query SQL; After the SQL is generated, the system will automatically verify it in the target database. If the SQL can be executed correctly, the query results will be returned for display. If the execution fails, the system will return and record the user's problem and the generated SQL. The backend administrator will correct the SQL. All problems and the correct SQL matching them will be recorded and saved and added to the RAG vector library. Regularly evaluate whether the SQL big model can correctly answer customers' questions in different directions. For questions that cannot be covered by understanding, collect relevant data and continue to fine-tune the training of the big model until it meets the requirements.
[0020] RAG search enhancement technology process: First, commonly used query questions and corresponding SQL statements are collected to form a vector knowledge base. Then, when the user inputs a question, the system first uses a word embedding model to vectorize the question. Then, based on semantic calculations, the most similar questions and answers are retrieved from the vector knowledge base. The user's question and the search results are then sorted together and given to the big model. The big model outputs the answer, and the system extracts the SQL statement from the answer of the big model. If the SQL statement generated by the big model can be correctly executed in the database, the corresponding data is saved and added to the vector library to continuously enhance the performance of RAG.
[0021] Combined with Figure 3 , an intelligent query method and system based on large model and retrieval enhancement technology, similar question retrieval and retrieval enhancement generation SQL flow chart: The pre-collected common questions and corresponding SQL are sorted into csv format, and the sorted data is vectorized using the bge-large word embedding model and stored in the vector knowledge base database; the questions raised by the user are then vectorized using the word embedding model, and the answers are retrieved and sorted in the vector knowledge base through vector calculation, and the top n answers are taken; then the user questions and the vector library retrieval results are sorted into new questions according to the template, and the template is: Given: {vector library retrieval results}, please answer the question: {question raised by the user}; the above sorted questions are sent to the large model as prompts, and finally the large model engine answer results are judged and processed for abnormalities to obtain the generated SQL.
[0022] Combined with Figure 4 , an intelligent query method and system based on large model and retrieval enhancement technology, verification SQL and data display and collection dialogue data flow chart: The SQL generated by the large model is executed in the business database. For those that can be executed correctly and return query results, the SQL query result data is displayed using charts and graphic tools; for SQL that cannot be executed correctly, it is recorded and notified to professional operation and maintenance personnel; after the operation and maintenance personnel manually correct the SQL and execute it again, the user is notified in the system when the correct result is generated. Finally, all user problems and correctly executed SQL are recorded in the system and added to the vector library.
[0023] Combined with Figure 5 , an intelligent query method based on big model and retrieval enhancement technology and a flowchart of system fine-tuning and updating big model: This system has dual optimization measures of RAG retrieval enhancement and continuous model fine-tuning to improve the accuracy of SQL generated by the large model. The system first vectorizes the user's questions using the word embedding model, and then generates SQL using the large model and RAG retrieval enhancement. After the SQL is verified and corrected, the relevant data is recorded, and the recorded data is regularly used to fine-tune the large model and release newer and better large models.
[0024] Combined with Figure 6 , an intelligent query method and system framework diagram based on large models and retrieval enhancement technology: The underlying foundation of the system is the infrastructure layer, which can use virtualized private cloud service resources or servers with GPU accelerator cards, with sufficient storage and computing resources. Domestic CPUs and GPUs need to be adapted according to actual conditions. Above the infrastructure layer is the data layer, which can connect to and match a variety of structured databases, vector databases, and graph databases, and store data sources and RAG vector knowledge base data; Above the data layer is the operation layer, which can provide structured data development and processing capabilities for various industries through standardized capabilities. Among them, SqlCoder realizes in-depth business learning and analysis and automatically converts problems into SQL capabilities, LLM-API provides unified scheduling of all large models (including parameter configuration, unified large model API), and DB-Manager implements access management of various databases (such as DM, mysql, doris, etc.). User-Center is the user center, providing user management capabilities. Sql-proo is to complete the proofreading of automatically generated SQL. The full range of technical capabilities is based on the unified hosting of K8S to provide external service capabilities, combined with Prometheus+Grafana to realize resource operation data monitoring and display.
[0025] Above the operation layer is the business layer, which provides internal and external interfaces such as user management, model management, data management, SQL proofreading, process scheduling, and resource monitoring; The top layer of the system is the interface layer. The interactive page of the customer application system can select a mode to implement database dialogue query, and finally display the query data in tables, views and advanced views.
[0026] The above is a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in other combinations, modifications and environments, and can be modified within the scope of the concept described herein through the above teachings or the technology or knowledge of the relevant field. The changes and modifications made by those skilled in the art do not depart from the spirit and scope of the present invention, and should be within the scope of protection of the claims attached to the present invention.
Claims
1. An intelligent query method based on large models and retrieval enhancement technology, Features: The following steps are involved: S1. Similar question retrieval: retrieve similar questions and answers raised by users in the vector knowledge base; S2. The big model generates SQL using the search results, and passes the retrieved answers and user questions to the big model to generate database query SQL; S3. Data verification and display: Verify the SQL generated by the large model in the database and use charts and graphic tools to display the SQL query result data; S4. Record and collect data, record user questions and SQL generated by the big model and correctly executed, and store them in the vector database; S5. Fine-tune and update the big model. Regularly use the collected data to fine-tune the SQL big model and update and publish the big model.
2. According to claim 1, an intelligent query method based on a large model and retrieval enhancement technology, Features: The step S1 comprises: S101. Organize the pre-collected FAQs and corresponding SQL statements into csv format; S102. Vectorize the sorted data using the word embedding model and store it in the vector knowledge base database; S103. vectorize the question raised by the user using a word embedding model; S104. Using the semantic similarity calculation method, the user's questions are compared with the historical questions in the vector knowledge base one by one, and the number of historical questions and answers is sorted according to the similarity value.
3. According to claim 1, an intelligent query method based on a large model and retrieval enhancement technology, Features: The step S2 comprises: S201. The user question is vectorized by the word embedding model and then the similarity is calculated with the knowledge in the vector knowledge base. The answer is retrieved from the vector knowledge base and the search results are re-ranked using the reranking model bge-reranker-large to take the top n answers; S202. Arrange the user question and the vector library search results into a new question according to a template, where the template is: Given: {vector library search results}, please answer the question: {question raised by the user}; S203. Send the sorted questions as prompts to the large model; S204. The answer result of the big model engine is judged by code encoding exception, the returned conversation content string is intercepted for JSON processing, the answer content that does not conform to the expected format is re-conversed, the result is regenerated using the big model self-check and verification function, and only the generated SQL is intercepted from the big model answer result.
4. According to claim 1, an intelligent query method based on a large model and retrieval enhancement technology, Features: The step S3 comprises: S301. Execute the SQL generated by the large model in the database, and return the query results if it can be executed correctly; S302. For SQL that cannot be executed correctly, record and send a notification to professional operation and maintenance personnel; S303. The operation and maintenance personnel manually correct the SQL and execute it again. If the correct result is generated, the user is notified in the system. S304. Use charts and graphic tools to display SQL query result data.
5. According to claim 1, an intelligent query method based on a large model and retrieval enhancement technology, Features: The step S4 comprises: S401. Record the user's question and the SQL that is ultimately correctly executed, and query the user question database to see if it is a new question; S402. Store the new question and the corresponding SQL in the user question database for later fine-tuning of the large model; S403. Vectorize the new question and the corresponding SQL and store them in the vector knowledge base for RAG enhancement.
6. According to claim 1, an intelligent query method based on a large model and retrieval enhancement technology, Features: The step S5 comprises: S501. Periodically or when the data of S4 accumulates to a set amount, organize the user question data and the corresponding SQL into a large model fine-tuning training data format; S502. Use the training tools provided by the system to configure resource paths and training parameters, and use the QLORA algorithm to fine-tune the training model; S503. After the training is completed, the same verification data set is used to regenerate SQL for the fine-tuned large model, and the accuracy of the fine-tuned large model is tested and compared to verify whether the performance is improved; S504. Release the updated and optimized large model after training.
7. An intelligent query system based on a large model and retrieval enhancement technology, using the method described in any one of claims 1 to 6, Features: Including data storage module, user interaction module, data processing module, data display module, and background management; The data storage module includes a business database, a vector database, and a system file storage; The user interaction module collects user data and the user determines whether the query returned data is valid; The data processing module converts the user's question into a database query SQL using the big model, then executes it in the database and returns the data query result; The data display module displays the user query results in data charts and graphics according to the situation; The background management module corrects SQL that cannot be executed or has incorrect query results, regularly organizes collected data, and fine-tunes and updates the large model.
Citation Information
Patent Citations
Method for improving response speed of large-scale language model based on similarity retrieval
CN116910221A
Method and system for automatically generating sql and replying questions
CN118093634A
Underground coal mine early warning data query method and system based on language large model
CN118733608A
Cited By
Equipment intelligent operation and maintenance system and method based on RAG model
CN119293199A
Power field Text2SQL data analysis method based on LLM and RAG
CN119646170A
Intelligent number asking method and system for license system based on NL2SQL large model
CN120407602A
Data processing method and device, electronic equipment, storage medium and program product
CN120492507A
Dynamic RAG-NL2SQL system based on real-time data blood map
CN121278003A
