Data query method and device based on large language model and medium
Through the data query method based on the large language model, the problems of low data processing efficiency and difficulty in data integration in traditional industries are solved, and more efficient data query and analysis are achieved, improving user experience and satisfaction.
Patent Information
- Application Number
- CN202411973432.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-04-11
- Estimated Expiration
- 2044-12-30
AI Technical Summary
In the workflow of traditional industries, data processing, statistics and analysis are inefficient, and statistical data is difficult to obtain project report statistical results through simple conditional screening logic, and multiple data reports or databases cannot be integrated, resulting in increased user workload and low efficiency.
The data query method based on the large language model is adopted. By obtaining the user's questions and prompt words entered by the user, the trained large language model converts the user's questions into SQL query statements, and obtains data from the specified database, and finally generates the question answer and returns it to the user.
It significantly improves the model's understanding of field tables within a specific database scope, reduces query failures or inaccurate results caused by comprehension errors, and improves user satisfaction and interactiveness and friendliness of data queries.
Smart Images

Figure CN119807233A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a data query method, device and medium based on a large language model. Background Art
[0002] In the current workflow of traditional industries, with the deepening of digital transformation, the workflow of traditional industries faces a lot of challenges in data processing, statistics and analysis, as well as improving labor efficiency. In the workflow of traditional industries, it is difficult to obtain the statistical results of project reports through simple conditional screening logic for data and statistical data of each process of the project. In addition, enterprises generally have multiple data reports or databases, and the data field storage methods and format standards are different, which makes it impossible to integrate and coordinate data. This problem leads to increased workload and low efficiency for users. In addition, when the data screening logic is fixed in the data platform, users cannot adjust the display method of required data and statistical charts according to their needs. At present, data platforms that rely solely on basic visualization technology can no longer meet the needs of complex businesses. It is necessary to combine new generation artificial intelligence products and technologies to improve the availability and effectiveness of digital platforms. Summary of the invention
[0003] In order to overcome the problems of low manual efficiency in data processing, statistics and analysis in the workflow of traditional industries, and the difficulty in obtaining project report statistical results through simple conditional screening logic, the present invention utilizes large language model technology to analyze user natural language processing and provides a data query method, device and medium based on a large language model.
[0004] In order to achieve the above-mentioned object of the invention, the present invention provides the following technical solutions:
[0005] In a first aspect, the present invention provides a data query method based on a large language model, the method comprising:
[0006] Obtaining a user question and a prompt word input by a user; wherein the prompt word includes a restriction condition and a query scenario, the restriction condition is used to instruct the large language model to convert the natural language into an SQL query statement, and the query scenario is used to instruct the large language model to match the corresponding database;
[0007] Use the trained large language model to match the user question with the predefined query template, and dynamically generate the SQL query statement of the corresponding database according to the matching result;
[0008] Acquire original data matching the user question from a database based on the SQL query statement;
[0009] Generate an answer to the question by combining the trained large language model with the user question, the original data and the context, and return it to the user;
[0010] The training process of the large language model includes:
[0011] A mapping relationship between database fields and natural language is constructed, prompt words are set using prompt engineering technology, and a large language model is trained based on the mapping relationship and the prompt words to obtain a trained large language model.
[0012] According to a specific implementation, in the above data query method, the user question and the predefined query template are matched using a trained large language model, specifically including:
[0013] Using the trained large language model to semantically understand and analyze the user questions, and extracting data fields from the analyzed user questions to generate main data and screening data;
[0014] The screened data is matched with a predefined query template through a trained large language model to generate a SQL query statement.
[0015] According to a specific implementation, in the above data query method, the query template includes a task command, task requirements, answer examples, and database field descriptions;
[0016] The task command is used to indicate the recognition content and recognition position of the large language model;
[0017] The task requires conditions for indicating SQL query statements generated by a large language model;
[0018] The answer example is used to indicate the form of the SQL query statement generated by the large language model;
[0019] The database field description is used to instruct the large language model to match the screening data in the user question with the database field description.
[0020] According to a specific implementation, in the above data query method, the conditions of the generated SQL query statement include:
[0021] If there is no SQL statement for the user question, return null;
[0022] Specifies the target address of the SQL query statement.
[0023] According to a specific implementation, in the above data query method, the method further includes:
[0024] After the user receives the original data, the user's satisfaction and suggestions for the answer to the question are obtained, and the task command, task requirements, answer examples and database field descriptions are optimized based on the satisfaction and suggestions.
[0025] According to a specific implementation, in the above data query method, the method further includes:
[0026] After the user receives the original data, the user's satisfaction and suggestions for the answer to the question are obtained, and the prompt words are optimized according to the satisfaction and suggestions.
[0027] According to a specific implementation, in the above data query method, building a mapping relationship between database fields and natural language includes:
[0028] A corresponding SQL language is constructed based on the data type in the natural language and the field type of the database field, and a mapping relationship is generated according to the SQL language.
[0029] According to a specific implementation, in the above data query method, the method further includes:
[0030] The answers to the questions are presented in a chart or table using a visualization tool.
[0031] In a second aspect, the present invention provides a data query device based on a large language model, the device comprising:
[0032] A dialogue module, used to create a user dialogue interface and obtain user questions and prompt words input by the user according to the user dialogue interface;
[0033] A processing module is used to implement a data query method based on a large language model as described in any of the above items to generate a question answer.
[0034] In a third aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the computer executes a data query method based on a large language model as described in any one of the above items.
[0035] Compared with the prior art, the present invention has the following beneficial effects:
[0036] By training a large language model in advance, the present invention can better guide the large language model to accurately generate language expressions that meet user needs within the scope of a database field table, significantly improve the model's ability to understand field tables within a specific database, and avoid training internal data in terms of data query. The purpose is to use a large language model to generate SQL statements, effectively considering the data privacy of different companies in different scenarios. In addition, the present invention allows the large language model to query in a specified database through prompt words, so that it can be applied to a predetermined field, understand and generate language expressions that meet specific contexts, and can also be assembled into personalized answers suitable for users based on user questions and context information, which not only improves user satisfaction, but also enhances interactivity and friendliness in the data query process. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 A flowchart of a data query method based on a large language model provided by an embodiment of the present invention;
[0038] Figure 2 A schematic diagram of the structure of a data query device based on a large language model provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0039] The present invention is further described in detail below in conjunction with test examples and specific implementation methods. However, this should not be understood as the scope of the above subject matter of the present invention being limited to the following embodiments, and all technologies realized based on the content of the present invention belong to the scope of the present invention.
[0040] With the rapid development of artificial intelligence technology, especially the widespread application of generative large language models (such as GPT series, BERT, etc.), the present invention aims to build an intelligent data query system that can deeply understand the user's natural language questions, automatically convert them into accurate database query statements, and extract relevant information from the specified database. Ultimately, the system will present the query results in the form of intuitive and easy-to-understand tables or statistical charts. At the same time, in the present invention, a user feedback mechanism is specially designed to continuously optimize the accuracy and understanding ability of the prompt word engineering and large language models.
[0041] The vertical application of big models has shown great potential and value in all walks of life. Especially in the field of contract data management, combined with the intelligent analysis and processing capabilities of big models, it can greatly improve the efficiency of contract data search, statistics and management. Traditional contract data management often relies on manual operations, which is not only time-consuming and labor-intensive, but also prone to errors. The vertical application of big models can automatically identify and understand keywords, screening conditions and details in the user's natural language through deep learning and natural language processing technology, and realize fast and accurate information extraction. This not only greatly improves the search speed of contract data, but also reduces the error rate caused by human factors. In terms of contract data statistics, big models can deeply mine and analyze massive contract data to discover potential rules and trends. By statistically analyzing multi-dimensional data such as contract type, amount, and signing time, enterprises can have a more comprehensive understanding of their business status and market dynamics, providing strong support for decision-making.
[0042] Specifically, the technical problems to be solved by the present invention include: designing effective prompt word engineering and query templates, so that the large language model can accurately understand natural language queries and convert them into valid SQL statements in the face of complex requirements such as multi-table associations, nested queries, and aggregate analysis; constructing a prompt word engineering for the large language model in a data query statistical scenario, and setting a prompt word engineering feedback optimization mechanism after returning the answer, using user correction to continuously optimize the prompt word engineering, and deepening the large language model's ability to understand and accuracy of database fields.
[0043] The technical solution provided by the embodiment of the present invention is further introduced below.
[0044] An embodiment of the present invention provides a data query method based on a large language model, including building a large language model based on a prompt word project.
[0045] Specifically, in the field of artificial intelligence, AI to SQL and the construction of a large language model based on prompt word engineering are two key technical directions. AI to SQL technology aims to convert natural language into SQL query statements, thereby realizing automated query of the database. The implementation of this technology requires solving multiple technical problems such as natural language understanding, grammatical parsing, and semantic mapping. Through deep learning and natural language processing technology, AI can identify keywords and intentions in the natural language input by users and convert them into corresponding SQL query statements. The application of this technology can greatly improve the efficiency and accuracy of database queries and reduce the cost and error rate of manual operations.
[0046] On the other hand, the construction of a large language model based on prompt word engineering is to train a large-scale language model so that it can understand and generate language expressions that conform to specific contexts. The implementation of this technology requires a large amount of data and computing resources, and it is also necessary to solve problems such as model overfitting and insufficient generalization ability. By introducing prompt word engineering, the model can be better guided to generate language expressions that meet user needs, improving the accuracy and usability of the model.
[0047] (1) User problem handling and initial data acquisition
[0048] Starting from the perspective of natural language understanding, we first use advanced natural language processing technology, including word segmentation, part-of-speech tagging, syntactic analysis, etc., to deeply analyze the questions input by users and extract key information such as query objects, conditions, sorting requirements, etc.
[0049] (2) Prompt word engineering enhances database field understanding
[0050] Build a mapping relationship between database fields and natural language descriptions, use prompting engineering technology, design a series of highly targeted and semantically rich prompt words, set fixed scenarios, and enable the large language model to better understand the meaning and purpose of database fields. When the model processes user questions, introduce database table names, field types and other structural information to enhance the model's ability to understand specific database environments.
[0051] (3) Conversion from natural language to database query statements
[0052] Match the parsed user question semantics with the predefined query template, dynamically fill in the placeholders in the template according to the matching results, and generate a complete SQL query statement.
[0053] (4) Database query and result integration
[0054] Submit the generated SQL statement to the database for execution to obtain the original data. Use appropriate data processing technology according to the data dimension (time, location, category, etc.) and quantity (single row, multiple rows, aggregation) to organize the data into structured tables or statistical charts. Specifically, you can use table technology: JDK1.8, apache.poi-ooxml, alibaba.easyexcel; and chart technology: JDK1.8, jfree.jfreechart. Among them, JDK1.8 converts elements into other forms or extracts information; accepts a function as a parameter, which is applied to each element and maps it into a new element. Receive a function as a parameter, replace each value in the stream with another stream, and then reconnect all the streams into one stream. apache.poi-ooxml can define the data model and create a Java class whose properties correspond to the columns in the Excel table, so that EasyExcel can automatically convert the data in the table into Java objects. Start the reading process through the EasyExcel.read() method, specify the Excel file path, data model class (Employee.class), and a custom listener (EmployeeListener). The invoke method in the listener will be called when each row of data is read, allowing immediate processing of the data. The doAfterAllAnalysed method is executed after all the data has been read. jfree.jfreechart is used to generate charts, usually using the ChartFactory class. Its main methods are: public void draw(Graphics2D g2, Rectang2D area) This method is used to draw in a specific area of the graphics device. The parameter g2 represents a graphic, and area is a rectangular container that contains this graphic. The graphics devices provided in java are: screen, printer, and graphics buffer. JFreeChart drawing is implemented by abstract classes in different java.awt.Graphics2D packages. Only by using them can JFreeChart output graphics to different graphics devices.
[0055] (5) Results presentation and user feedback
[0056] Use visualization tools (Matplotlib, Echarts) to convert the integrated data into charts or tables to improve the readability and intuitiveness of the information. Based on the context of the user's original question and the query results, the large language model generates natural and fluent answers to ensure the accuracy and friendliness of information transmission. At the same time, it provides a user evaluation function to collect user satisfaction with the query results and specific suggestions for subsequent query template adjustments and prompt word optimization.
[0057] (6) Optimization of the feedback mechanism of model prompt word engineering
[0058] Supervise the closed-loop mechanism of user feedback and model adjustment, regularly analyze user feedback data, identify weak links in model understanding, and continuously improve the accuracy of the system and user experience through iterative optimization of prompt word engineering and query templates.
[0059] Specifically, please refer to Figure 1 , which shows a flow chart of a data query method based on a large language model provided by an embodiment of the present invention, the method comprising:
[0060] Step 1: Get the user question and prompt word entered by the user.
[0061] The prompt words include restriction conditions and query scenarios, wherein the restriction conditions are used to instruct the large language model to convert natural language into SQL query statements, and the query scenarios are used to instruct the large language model to match the corresponding database.
[0062] For example, in the prompt word, you can set it like this:
[0063] prompt="'You are a Text2SQL robot, used to query specific contract data, and can convert users' natural language questions into SQL query statements.
[0064] Or, prompt="'You are a Text2SQL robot, which is used to query the specific data of the bidding market and can convert the user's natural language questions into SQL query statements.
[0065] Users only need to use their most frequently used questions to ask the contract-related data statistics they want to know. The role of the prompt word is to constrain the scenario of a large language model to the current scenario, and the database fields constrained to be queried can only be within the database field range given by the current prompt word.
[0066] Step 2: Use the trained large language model to match the user question with the predefined query template, and dynamically generate the SQL query statement of the corresponding database according to the matching result.
[0067] Among them, the query template includes a task command, a task requirement, an answer example and a database field description; the task command is used to indicate the recognition content and recognition position of the large language model; the task requirement is used to indicate the conditions of the SQL query statement generated by the large language model; the answer example is used to indicate the form of the SQL query statement generated by the large language model; the database field description is used to instruct the large language model to match the filtered data in the user question with the database field description.
[0068] For example, the query template is as follows:
[0069] prompt="'You are a Text2SQL robot, used to query specific contract data, and can convert users' natural language questions into SQL query statements.
[0070] Task command: Based on the field description and data examples of the database table enclosed in ---, think about which field the user is querying and what fields the query conditions are.
[0071] Then convert the user questions in {} into SQL query statements.
[0072] Task requirements:
[0073] 1. Please directly return the SQL statement for your answer, starting with SELECT, and do not include any analysis process.
[0074] 2. Make sure your SQL statements are directly executable and do not contain syntax errors.
[0075] 3. If there is no SQL statement for this problem, it returns empty.
[0076] 4. Only query the database table "ai_product_main_contract" and do not query non-existent fields.
[0077] Example answer: "SELECT contract_name FROM ai_product_main_contract WHERE city = 'Guangzhou';"
[0078] Database field description:
[0079] Contract namecontract_name
[0080] Contract numbercontract_number
[0081] Completion schedule completion_schedule
[0082] undertake_type
[0083] Contract typecontract_country
[0084] Contract belongs to contract_biz_type
[0085] Contract Categorycontract_category
[0086] The main unit is primary_unit.
[0087] Among them, the prompt words and database field descriptions can be replaced according to different scenarios.
[0088] The user question is matched with the predefined query template using the trained large language model, specifically including:
[0089] Using the trained large language model to semantically understand and analyze the user questions, and extracting data fields from the analyzed user questions to generate main data and screening data;
[0090] The screened data is matched with a predefined query template through a trained large language model to generate a SQL query statement.
[0091] Step 3: Acquire original data matching the user question from the database based on the SQL query statement.
[0092] Step 4: Generate an answer to the question by combining the user question, the original data and the context through the large language model, and return it to the user.
[0093] The training process of the large language model includes:
[0094] A mapping relationship between database fields and natural language is constructed, prompt words are set using prompt engineering technology, and a large language model is trained based on the mapping relationship and the prompt words to obtain a trained large language model.
[0095] Construct the mapping relationship between database fields and natural language, including:
[0096] A corresponding SQL language is constructed based on the data type in the natural language and the field type of the database field, and a mapping relationship is generated according to the SQL language.
[0097] Generally speaking, data types in natural language refer to non-standard terms used by users when making queries, and large language models are prone to understanding deviations. The field type of a database field is a pre-set data table header, and is also the basis for querying through SQL query statements. Therefore, it is necessary to build the corresponding SQL language in advance. For example, take some contract fields as an example, as shown in Table 1.
[0098] Table 1 Mapping relationship example table
[0099]
[0100]
[0101] Furthermore, in this embodiment, it also includes:
[0102] After the user receives the original data, the user's satisfaction and suggestions for the answer to the question are obtained, and the task command, task requirements, answer examples and database field descriptions are optimized based on the satisfaction and suggestions.
[0103] For example, the user asked what kind of contract the Xi'an Xihu Road Engineering PPP Project Cooperation Agreement Contract belongs to? The analyzed SQL is SELECT contract_country FROM ai_product_main_contract WHEREcontract_name='Xi'an Xihu Road Engineering PPP Project Cooperation Agreement Contract'. However, in this SQL, the large language model misunderstood the contract type field as the commitment type field, which is wrong. The user can feedback that he wants to find the contract type; the commitment type in the original database field description is: contract_type commitment type; contract_country contract type. The reason for the misunderstanding is that the English words of the two fields are very similar, so after correction, it becomes: commitment type
[0104] undertake_type; contract_country. Since the meanings of the English words are no longer similar, there will be no misunderstanding.
[0105] Similarly, in this embodiment, the method further includes obtaining the user's satisfaction and suggestions for answering the question after the user receives the original data, and optimizing the prompt words according to the satisfaction and suggestions.
[0106] For example, when you first start to query data, the prompt word starts with: prompt="'You are a Text2SQL robot that can convert the user's natural language questions into SQL query statements.
[0107] In subsequent data queries, it was found that the prompt word was not sufficiently constrained for the scenario of the large language model and would lead to misunderstanding, so the prompt word was added with "You are a Text2SQL robot, used to query specific contract data, and can convert users' natural language questions into SQL query statements."
[0108] Specifically, take the data statistical analysis scenario of a major enterprise engineering project as an example.
[0109] Taking a specific business scenario as an example, the company's operations management department needs to manage and count the projects of each department every quarter. If the question sentence entered by the user is: What is the operating income of the company's investment division in the four quarters of 2023? The data subject to be queried is operating income, the main unit is the investment division, and the time is data from January to December 2023. The operating income data for every three months is added up, as shown in Table 2.
[0110] Table 2 Schematic diagram of user questions converted into data samples to be integrated
[0111] Subject data time Main unit Operation method Operating income January-December 2024 Investment Division Quarterly sum
[0112] In addition, when a company applies for national major engineering qualifications or projects, it is necessary to count the qualified personnel in the company. If the user enters the question sentence as: Who are the personnel in the company who have senior professional titles in road construction and are also first-level registered cost engineers? The main body of the query data is the list of cadres, whose major is road construction, whose professional title is senior engineer, and whose qualification certificate is first-level registered cost engineer, as shown in Table 3.
[0113] Table 3 Schematic diagram of data samples for converting user questions into conditional statistics
[0114] Subject data major job title Certifications List of cadres Road professional Senior Engineer First-class registered cost engineer
[0115] The prompt word engineering model is a model that can guide the large language model to generate the expected output through specific input. The large language model based on the prompt word engineering can decompose the user's natural language into data screening conditions and assemble and reconstruct the data. However, simple prompt word engineering may also bring a series of different problems, such as misunderstanding of data fields and deviation in field selection, which leads to deviations between the query data results and the user's original intention. Therefore, the present invention focuses on adding a feedback mechanism for prompt words, analyzing data according to user feedback, identifying weak links in model understanding, and improving system accuracy by continuously iterating and modifying keywords, modifying database field mapping relationships and query templates. The present invention focuses on designing a user feedback prompt word engineering optimization mechanism, which greatly improves the accuracy and user experience of the system by continuously optimizing the prompt word function, as shown in Table 4.
[0116] Table 4 Schematic diagram of question and answer situations after users use the large language model of the present invention
[0117]
[0118]
[0119] Based on the above technical solution, the present invention can enhance the ability to understand the database field table. Specifically, the construction of a large language model based on the prompt word engineering is to add the prompt word engineering to the trained large language model so that it can be applied to a predetermined field, understand and generate language expressions that conform to a specific context. The implementation of this technology does not require a large amount of data and computing resources. By introducing the prompt word engineering and continuously iterating and optimizing the prompt words according to user feedback, the model can be better guided to more accurately generate language expressions that meet user needs within the scope of the database field table, thereby improving the accuracy and usability of the model. The method significantly improves the model's ability to understand the field table within a specific database range. This means that the model can more accurately parse the user's natural language query for the database field, thereby reducing the query failure or inaccurate results caused by misunderstanding. In addition, the present invention can be assembled into a question mode suitable for the user to answer based only on the user's question and context information. This personalized answering method not only improves user satisfaction, but also enhances the interactivity and friendliness of the system. At the same time, in terms of data query, the training of internal data is avoided, aiming to use the large model to generate SQL statements, effectively considering the data privacy of different scenarios and different enterprises.
[0120] On the other hand, please refer to Figure 2 , which shows a schematic diagram of the structure of a data query device based on a large language model provided by an embodiment of the present invention, the device comprising:
[0121] The dialogue module is used to create a user dialogue interface and obtain user questions and prompt words input by the user according to the user dialogue interface.
[0122] The processing module is used to implement a data query method based on a large language model as described in any one of the above items to generate a question answer. Specifically comprising:
[0123] The extraction and conversion module is used to match the user question with the predefined query template using the trained large language model, and dynamically generate the SQL query statement of the corresponding database according to the matching result;
[0124] A retrieval module is used to obtain the original data matching the user question from the database based on the SQL query statement; including constructing a transmission channel between the output of a large language model and the database, passing the SQL query statement to the database for data retrieval, and obtaining the original data that meets the screening conditions;
[0125] An integration module is used to generate an answer to a question by combining the large language model with the user's question, the original data and the context, and return the answer to the user; including putting the filtered data into the large language model for assembly, assembling it into a natural and fluent dialogue answer based on the user's question and the context using the large model, and constructing a suitable statistical chart form presentation using a graphic table tool;
[0126] The feedback optimization module is used to obtain the user's satisfaction and suggestions on the query results after the user receives the original data, and optimize the prompt words and the query template according to the satisfaction and suggestions.
[0127] Furthermore, an embodiment of the present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the computer executes a data query method based on a large language model as described in any one of the above items.
[0128] In the embodiments of the present invention, the processor may be an integrated circuit chip having the ability to process signals. The processor may 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 gate or transistor logic devices, or discrete hardware components.
[0129] The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or can be executed by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The processor reads the information in the storage medium and completes the steps of the above method in combination with its hardware.
[0130] The storage medium may be a memory, which may be, for example, a volatile memory or a nonvolatile memory, or may include both volatile and nonvolatile memory.
[0131] Among them, the non-volatile memory can be a read-only memory (ROM), a programmable ROM (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory.
[0132] The volatile memory may be a random access memory (RAM) which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), sync link DRAM (SLDRAM), and direct rambus RAM (DRRAM).
[0133] The storage media described in the embodiments of the present invention are intended to include, but are not limited to, these and any other suitable types of memory.
[0134] It should be understood that the device disclosed in the embodiment of the present invention can be implemented in other ways. For example, the division of the modules is only a logical function division, and there may be other division methods in actual implementation, such as 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 communication connection between modules can be through some interfaces, indirect coupling or communication connection of servers or units, which can be electrical or other forms.
[0135] In addition, each functional module in each embodiment of the present invention may be integrated into one processing unit, each module may exist physically separately, or two or more modules may be integrated into one processing unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional unit.
[0136] 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 invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk and other media that can store program codes.
[0137] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A data query method based on a large language model, characterized in that: The method comprises: Obtaining a user question and a prompt word input by a user; wherein the prompt word includes a restriction condition and a query scenario, the restriction condition is used to instruct the large language model to convert the natural language into an SQL query statement, and the query scenario is used to instruct the large language model to match the corresponding database; Use the trained large language model to match the user question with the predefined query template, and dynamically generate the SQL query statement of the corresponding database according to the matching result; Acquire original data matching the user question from a database based on the SQL query statement; Generate an answer to the question by combining the trained large language model with the user question, the original data and the context, and return it to the user; The training process of the large language model includes: A mapping relationship between database fields and natural language is constructed, prompt words are set using prompt engineering technology, and a large language model is trained based on the mapping relationship and the prompt words to obtain a trained large language model.
2. A data query method based on a large language model according to claim 1, characterized in that: The user question is matched with the predefined query template using the trained large language model, specifically including: Using the trained large language model to semantically understand and analyze the user questions, and extracting data fields from the analyzed user questions to generate main data and screening data; The screened data is matched with a predefined query template through a trained large language model to generate an SQL query statement.
3. A data query method based on a large language model according to claim 2, characterized in that: The query template includes a task command, task requirements, answer examples and database field descriptions; The task command is used to indicate the recognition content and recognition position of the large language model; The task requires conditions for indicating SQL query statements generated by a large language model; The answer example is used to indicate the form of the SQL query statement generated by the large language model; The database field description is used to instruct the large language model to match the screening data in the user question with the database field description.
4. The data query method based on a large language model according to claim 3, characterized in that: The conditions of the generated SQL query statement include: If there is no SQL statement for the user question, return null; Specifies the target address of the SQL query statement.
5. The data query method based on a large language model according to claim 3, characterized in that: The method further comprises: After the user receives the original data, the user's satisfaction and suggestions for the answer to the question are obtained, and the task command, task requirements, answer examples and database field descriptions are optimized based on the satisfaction and suggestions.
6. The data query method based on a large language model according to claim 1, characterized in that: The method further comprises: After the user receives the original data, the user's satisfaction and suggestions for the answer to the question are obtained, and the prompt words are optimized according to the satisfaction and suggestions.
7. The data query method based on a large language model according to claim 1, characterized in that: Construct the mapping relationship between database fields and natural language, including: A corresponding SQL language is constructed based on the data type in the natural language and the field type of the database field, and a mapping relationship is generated according to the SQL language.
8. The data query method based on a large language model according to claim 1, characterized in that: The method further comprises: The answers to the questions are presented in a chart or table using a visualization tool.
9. A data query device based on a large language model, characterized in that: The device comprises: A dialogue module, used to create a user dialogue interface and obtain user questions and prompt words input by the user according to the user dialogue interface; A processing module, used to implement a data query method based on a large language model as described in any one of claims 1 to 8 to generate a question answer.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the computer executes a data query method based on a large language model as described in any one of claims 1 to 8.
Citation Information
Patent Citations
Medical insurance intelligent query method and system based on NL2SQL
CN118132579A
Method for converting full-link natural language into structured query language
CN118227653A
Metadata feature and thinking chain-based multi-table associated large language model question and answer method
CN118245591A
Large language model Text2SQL single-table query statement generation method
CN118643039A
Generating a large language model prompt based on collaboration activities of a user
US20240362476A1
Cited By
Table establishment method and device based on cooperation of large language model and speculation algorithm
CN120725022A
Enterprise data processing method and device, electronic equipment and storage medium
CN120763194A
Intelligent number asking method and system based on large language model
CN121117053A
Question and answer method, device and equipment based on large language model and storage medium
CN121256003A
Intelligent number asking method, device and system based on semantic data model and large model
CN121365080A