Data query method, device and medium based on large language model
Through large language model technology, the problem of low data processing and statistical efficiency in traditional industries has been solved, efficient and personalized data query and statistics have been achieved, and user experience and data privacy protection have been improved.
Patent Information
- Application Number
- CN202411973432.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-30
- Publication Date
- 2025-10-24
- Estimated Expiration
- 2044-12-30
AI Technical Summary
In the workflow of traditional industries, data processing and statistical efficiency are low, statistical results of data reports are difficult to obtain through simple conditional screening logic, inconsistent data formats increase user workload, and existing data platforms cannot meet complex business needs.
Utilizing large language model technology, we obtain user questions and prompt words through a trained model, build a mapping relationship between database fields and natural language, dynamically generate SQL query statements, optimize the prompt word project based on user feedback, and generate personalized answers.
It improves the accuracy and interactivity of data queries, reduces manual operation costs, enhances user satisfaction, and adapts to the data privacy needs of different enterprises.
Smart Images

Figure CN119807233B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and in particular to a data query method and device based on a large language model and a medium. BACKGROUND
[0002] In the current workflow of traditional industries, with the deepening of digital transformation, the workflow of traditional industries is facing the challenges of a large amount of data processing, statistics and analysis, and improvement of artificial efficiency. In the workflow of traditional industries, project process data and statistical data are difficult to obtain project report statistical results through simple condition filtering logic. Moreover, an enterprise generally has multiple data reports or databases, and the data field saving mode and format standard are not the same, so data integration and overall planning cannot be performed. This problem leads to an increase in user workload and low efficiency. Moreover, in the case of fixed data filtering logic in a data platform, the user cannot adjust the display mode of the required data and statistical chart according to his own needs. At present, only relying on a data platform combined with basic visualization technology cannot meet the needs of complex businesses, and a new generation of artificial intelligence products and technologies need to be combined to improve the usability and effectiveness of the digital platform. SUMMARY
[0003] In order to overcome the problems of low artificial efficiency, difficulty in obtaining project report statistical results through simple condition filtering logic, and the like in the workflow of traditional industries, the present application uses a 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 application purposes, the present application provides the following technical solutions:
[0005] In a first aspect, the present application provides a data query method based on a large language model, which comprises:
[0006] obtaining a user question and a prompt word input by a user; wherein the prompt word comprises a restriction condition and a query scene, the restriction condition is used to instruct the large language model to convert natural language into a SQL query statement, and the query scene is used to instruct the large language model to match a corresponding database;
[0007] matching the user question and a pre-defined query template by using a trained large language model, and dynamically generating a SQL query statement of a corresponding database according to a matching result;
[0008] obtaining original data matched with the user question from the database based on the SQL query statement;
[0009] The trained large language model generates a question answer in combination with the user question, the original data, and the context, and returns the question answer to the user.
[0010] The training process of the large language model includes:
[0011] A mapping relationship between a database field and a natural language is constructed, a prompt word is set by using a number of engineering techniques, and a large language model is trained based on the mapping relationship and the prompt word to obtain the trained large language model.
[0012] According to a specific embodiment, in the data query method, the user question and a predefined query template are matched by using the trained large language model, and specifically, the matching includes:
[0013] The user question is subjected to semantic understanding and analysis by using the trained large language model, and a data field in the analyzed user question is extracted to generate subject data and screening data;
[0014] The screening data and the predefined query template are matched by using the trained large language model to generate a SQL query statement.
[0015] According to a specific embodiment, in the data query method, the query template includes a task command, a task requirement, an answer example, and a database field description.
[0016] The task command is used to indicate the recognition content and the recognition position of the large language model.
[0017] The task requirement is used to indicate the condition of the SQL query statement generated by the 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 indicate that the screening data in the user question is matched with the database field description by the large language model.
[0020] According to a specific embodiment, in the data query method, the condition of the generated SQL query statement includes:
[0021] If there is no SQL statement of the user question, an empty result is returned.
[0022] A target address of the SQL query statement is specified.
[0023] According to a specific embodiment, in the data query method, the method further includes:
[0024] Based on the user receiving the original data, the satisfaction and suggestions of the user to the question answer are obtained, and the task command, task requirement, answer example and database field description are optimized according to the satisfaction and suggestions.
[0025] According to a specific embodiment, the data query method further comprises:
[0026] Based on the user receiving the original data, the satisfaction and suggestions of the user to the question answer are obtained, and the task command, task requirement, answer example and database field description are optimized according to the satisfaction and suggestions.
[0027] According to a specific embodiment, the data query method further comprises:
[0028] Based on the user receiving the original data, the satisfaction and suggestions of the user to the question answer are obtained, and the task command, task requirement, answer example and database field description are optimized according to the satisfaction and suggestions.
[0029] According to a specific embodiment, the data query method further comprises:
[0030] The question answer is presented in a chart or table through a visualization tool.
[0031] In a second aspect, the present application provides a data query device based on a large language model, comprising:
[0032] A dialogue module is configured to create a user dialogue interface and obtain a user question and a prompt word input by a user according to the user dialogue interface.
[0033] A processing module is configured to implement a data query method based on a large language model according to any one of the above aspects to generate a question answer.
[0034] In a third aspect, the present application provides a computer readable storage medium having a computer program stored thereon, wherein the computer program is executed by a processor to make the computer execute a data query method based on a large language model according to any one of the above aspects.
[0035] Compared with the prior art, the present application has the following advantages:
[0036] By training the 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 the database field table, significantly improve the model's ability to understand the field table within a specific database range, and at the same time avoid internal data training in data query. It aims to use the large language model to generate SQL statements, effectively considering the data privacy of different scenarios and different enterprises. 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 contextual 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 will be further described in detail below in conjunction with test examples and specific embodiments. However, this should not be understood as limiting the scope of the present invention to the following embodiments, and all technologies implemented based on the present invention fall within the scope of the present invention.
[0040] With the rapid development of artificial intelligence technology, particularly the widespread application of generative large language models (such as the GPT series and BERT), this invention aims to build an intelligent data query system that can deeply understand users' natural language questions, automatically convert them into precise database query statements, and extract relevant information from a specified database. Ultimately, the system will present query results in intuitive and easy-to-understand tables or statistical charts. Furthermore, this invention specifically designs a user feedback mechanism to continuously optimize the accuracy and comprehension capabilities of the prompt word engineering and large language model.
[0041] Large model vertical application has shown great potential and value in various industries. In particular, in the field of contract data management, combined with the intelligent analysis and processing capabilities of large models, the efficiency of contract data searching, statistics, and management can be greatly improved. Traditional contract data management often relies on manual operation, which not only consumes time and effort, but also is prone to errors. Large model vertical application, through deep learning and natural language processing technology, can automatically identify and understand key words, filtering conditions, and details in user natural language, and achieve fast and accurate information extraction. This not only greatly improves the speed of contract data searching, but also reduces the error rate caused by human factors. In terms of contract data statistics, large models can deeply mine and analyze massive contract data to discover potential patterns and trends. By statistically analyzing contract types, amounts, signing times, and other multi-dimensional data, enterprises can more comprehensively understand their business status and market dynamics, providing strong support for decision-making.
[0042] Specifically, the technical problems to be solved by the present application include: designing effective prompt word engineering and query templates, facing complex requirements such as multi-table association, nested queries, and aggregation analysis, enabling large language models to accurately understand natural language queries and convert them into effective SQL statements; constructing prompt word engineering for large language models in data query and statistics scenarios, and setting up 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 understanding and accuracy of database fields.
[0043] The technical solutions provided by the embodiments of the present application are further described below.
[0044] The data query method based on a large language model provided by the embodiments of the present application includes large language model construction based on prompt word engineering.
[0045] Specifically, in the field of artificial intelligence, AI to SQL and large language model construction 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 automatic querying of databases. The implementation of this technology needs to solve multiple technical difficulties such as natural language understanding, syntax analysis, and semantic mapping. Through deep learning and natural language processing technology, AI can identify the key words and intentions in user input natural language and convert them into corresponding SQL query statements. The application of this technology can greatly improve the efficiency and accuracy of database queries, reduce the cost and error rate of manual operation.
[0046] On the other hand, the construction of large language models based on prompt engineering is to train large-scale language models to understand and generate language expressions that conform to specific contexts. This technology requires a large amount of data and computing resources, and also needs to solve problems such as model overfitting and insufficient generalization ability. By introducing prompt 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 question processing and initial data acquisition
[0048] From the perspective of natural language understanding, first use advanced natural language processing techniques, including word segmentation, part-of-speech tagging, and syntax analysis, to deeply analyze the user's input question and extract key information such as query objects, conditions, and sorting requirements.
[0049] (2) Prompt engineering enhances database field understanding
[0050] Construct the mapping relationship between database fields and natural language descriptions, use prompt engineering technology to design a series of targeted and semantically rich prompts, and set fixed scenarios so that large language models can 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 understanding of specific database environments.
[0051] (3) Natural language to database query statement conversion
[0052] Match the parsed user question semantics with the predefined query template, and dynamically fill in the placeholders in the template according to the matching results to generate a complete SQL query statement.
[0053] (4) Database query and result integration
[0054] The generated SQL statements are submitted to the database for execution to obtain the raw data. According to the data dimensions (time, location, category, etc.) and quantities (single row, multiple rows, aggregation), appropriate data processing techniques are used to organize the data into structured tables or statistical charts. Specifically, table technologies such as JDK1.8, apache.poi-ooxml, and alibaba.easyexcel can be used, as well as chart technologies such as JDK1.8 and 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, change each value in the stream into another stream, and then reconnect all streams into a stream. apache.poi-ooxml can define a data model, 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 data is read. jfree.jfreechart is used to generate charts, usually using the ChartFactory class. Its main methods include: publicvoid draw(Graphics2D g2,Rectang2D area) This method is used to draw a graph in a specific area of a graphics device. Parameter g2 represents a graph, and area is a rectangular container that contains this graph. The graphics devices provided in Java include: screen, printer, graphics buffer. JFreeChart drawing is implemented by different abstract classes in the java.awt.Graphics2D package. Only by using them can JFreeChart output graphics to different graphics devices.
[0055] (5) Results presentation and user feedback
[0056] The integrated data is converted into charts or tables using visualization tools (Matplotlib, Echarts) to improve the readability and intuitiveness of the information. According to 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, a user evaluation function is provided to collect user satisfaction and specific suggestions for the query results, which can be used for subsequent adjustment of the query template and optimization of the prompt words.
[0057] (6) Feedback mechanism optimization of model prompt word engineering
[0058] Supervisor user feedback and model adjustment closed-loop mechanism, regularly analyze user feedback data, identify weak links in model understanding, and continuously improve the accuracy and user experience of the system by iteratively optimizing prompt word engineering and query templates.
[0059] Specifically, refer to Figure 1 which shows a flowchart of a data query method based on a large language model provided by an embodiment of the application, the method comprising:
[0060] Step 1: Obtain the user question and prompt word input by the user.
[0061] 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 natural language into a SQL query statement, and the query scenario is used to instruct the large language model to match the corresponding database.
[0062] For example, in the prompt word, it can be set as:
[0063] prompt = "'You are a Text2SQL robot, used to query specific contract data, and can convert user natural language questions into SQL query statements.
[0064] Or, prompt = "'You are a Text2SQL robot, used to query specific data of the bidding market, and can convert user natural language questions into SQL query statements.
[0065] The user only needs to ask the most commonly used questions to know the contract-related data statistics, and the role of the prompt word is to constrain the scene of a large language model to the current scene, and the database field of the query can only be within the range of the database field given by the current prompt word.
[0066] Step 2: Use the trained large language model to match the user question and the pre-defined query template, and dynamically generate a SQL query statement for the corresponding database according to the matching result.
[0067] Wherein, 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 position of the large language model; the task requirement is used to indicate the condition 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; and the database field description is used to indicate the large language model to match the filtered data in the user question with the database field description.
[0068] An example of a query template is as follows:
[0069] prompt="You are a Text2SQL robot for querying contract-specific data. You can convert the user's natural language question into a SQL query statement.
[0070] Task command: According to the field descriptions and data examples of the database table enclosed in ---, think about which field the user's question is querying and which fields are the query conditions.
[0071] Then convert the user's question in {} into a SQL query statement.
[0072] Task requirements:
[0073] 1. Your answer should directly return a SQL statement starting with SELECT, without including any analysis process.
[0074] 2. Ensure that your SQL statement can be directly executed and does not contain syntax errors.
[0075] 3. If there is no SQL statement for this question, return empty.
[0076] 4. Only query the "ai_product_main_contract" table, do not query non-existent fields.
[0077] Example of answer: "SELECT contract_name FROM ai_product_main_contract WHERE city='Guangzhou';"
[0078] Database field description:
[0079] Contract Name contract_name
[0080] Contract Number contract_number
[0081] Completion Schedule completion_schedule
[0082] Undertaking Type undertake_type
[0083] Contract Type contract_country
[0084] Contract Ownership contract_biz_type
[0085] Contract Category contract_category
[0086] Primary unit
[0087] Among them, the prompt word and the database field description can be replaced according to different scenes.
[0088] The trained large language model is used to match the user question and the predefined query template, specifically including:
[0089] The trained large language model is used for semantic understanding and analysis of the user question, and extracts the data field in the analyzed user question to generate subject data and screening data;
[0090] The trained large language model is used to match the screening data and the predefined query template to generate an SQL query statement.
[0091] Step 3: Based on the SQL query statement, the original data matched with the user question is obtained from the database.
[0092] Step 4: The large language model is used to generate a question answer based on the user question, the original data and the context, and return to the user.
[0093] Among them, the training process of the large language model includes:
[0094] The mapping relationship between the database field and the natural language is constructed, the prompt word is set by using the data engineering technology, and the large language model is trained based on the mapping relationship and the prompt word to obtain the trained large language model.
[0095] The mapping relationship between the database field and the natural language is constructed, including:
[0096] Based on the data type in the natural language and the field type of the database field, the corresponding SQL language is constructed, and the mapping relationship is generated according to the SQL language.
[0097] Generally speaking, the data type in the natural language refers to the non-standard language used by the user when making a query, and the large language model is easy to understand the deviation, and the field type of the database field is the data table header set in advance, which is also the basis for querying by the SQL query statement. Therefore, the corresponding SQL language needs to be constructed in advance. For example, some contract fields are taken as an example, as shown in Table 1.
[0098] Table 1 Mapping relationship example table
[0099]
[0100]
[0101] Further, in the embodiment, it also includes:
[0102] Based on the user receiving the original data, the user's satisfaction and suggestions for answering the question are obtained, and the task command, task requirement, answer example and database field description are optimized according to the satisfaction and suggestions.
[0103] For example, the user asks what kind of contract is the Xi'an Xihu Road Engineering PPP Project Cooperation Agreement Contract? The analyzed SQL is SELECT contract_country FROM ai_product_main_contract WHERE contract_name = 'Xi'an Xihu Road Engineering PPP Project Cooperation Agreement Contract', but in this SQL, the large language model misunderstands the contract type field as the undertaking type field, which is wrong. The user can feedback that he hopes to find the contract type; The original database field description of undertaking type is: contract_type undertaking type; contract_country contract type. The reason for misunderstanding is that the English words of the two fields are similar, so after correction, it becomes: undertaking type
[0104] contract_country. Since the English words are no longer similar in meaning, misunderstanding will not occur.
[0105] Similarly, in this embodiment, it also includes obtaining the user's satisfaction and suggestions for answering the question based on the user receiving the original data, and optimizing the prompt word according to the satisfaction and suggestions.
[0106] For example, at the beginning of data query, the beginning of the prompt word is: prompt = "'You are a Text2SQL robot that can convert user natural language questions into SQL query statements.
[0107] In subsequent data queries, it is found that the prompt word is not enough for the scene constraint of the large language model, and there will be understanding deviation, so "You are a Text2SQL robot that can convert user natural language questions into SQL query statements" is added to the prompt word.
[0108] Specifically, taking the enterprise major engineering project data statistical analysis scene as an example.
[0109] Taking a specific business scenario as an example, the company operation management department needs to manage and count the projects of each department every quarter. If the user input question sentence is: How is the operating income of the company investment department in the four quarters of 2023? The data subject of the query is operating income, the subject unit is the investment department, and the time is the data from January to December 2023. The operating income data of each three-month period is summed up, as shown in Table 2.
[0110] Table 2 User question converted into data sample table to be integrated
[0111] Subject data Time Subject unit Operation mode Operating income January-December 2024 Investment department Quarterly addition
[0112] In addition, when the company applies for national major engineering qualification or project, it needs to count the personnel who meet the conditions of the company. If the user input question sentence is: Who are the personnel in the company with senior professional title in road specialty and also with first-class registered cost engineer? The data subject of the query is the cadre personnel list, the specialty is road specialty, the title is senior engineer, and the qualification certificate is first-class registered cost engineer, as shown in Table 3.
[0113] Table 3 User question converted into condition statistics data sample table
[0114] Subject data Professional Title Qualification certificate Cadre list Road professional Senior engineer First-class registered cost engineer
[0115] The prompt word engineering model can guide the large language model to generate the expected output through specific input. Based on the prompt word engineering of the large language model, the user's natural language can be disassembled into data filtering conditions, and the data can be assembled and reconstructed. However, simple prompt word engineering may also bring a series of different problems, such as understanding errors of data fields, selection bias of fields, resulting in deviation of the query data results from the original intention of the user. Therefore, in the present application, the feedback mechanism of the prompt word is mainly increased, the data is analyzed according to the user feedback, the weak links of the model understanding are identified, and the key words are modified, the database field mapping relationship and the query template are modified, and the system accuracy is improved. In the present application, the user feedback prompt word engineering optimization mechanism is mainly designed, the prompt word function is continuously optimized, and finally the accuracy and user experience of the system are greatly improved, as shown in Table 4.
[0116] Table 4 User question and answer situation after using the large language model of the present application
[0117]
[0118]
[0119] Based on the above technical solution, the application can enhance the understanding ability of the database field table. Specifically, the large language model construction based on prompt word engineering is to add prompt word engineering to the trained large language model, so that it can be applied to a certain predetermined field, understand and generate language expressions conforming to a specific context. The implementation of this technology does not require a large amount of data and computing resources. By introducing prompt word engineering and continuously iterating and optimizing the prompt word according to user feedback, the model can be better guided to generate more accurate language expressions within the scope of the database field table that meet the user's needs, improving the accuracy and usability of the model. This method significantly improves the model's understanding ability of 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 understanding errors. In addition, the application can assemble the user's question and context information into a suitable way for the user to answer. 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 internal data training is avoided, aiming to generate SQL statements using large models, effectively considering the data privacy of different scenarios and different enterprises.
[0120] On the other hand, please refer to Figure 2 which shows a structure diagram of a data query device based on a large language model provided by an embodiment of the application, the device comprising:
[0121] A dialogue module for creating a user dialogue interface and obtaining a user question and a prompt word input by the user according to the user dialogue interface.
[0122] A processing module for implementing a data query method based on a large language model as described in any one of the above embodiments to generate a question answer. Specifically, it includes:
[0123] An extraction and conversion module for matching the user question and a predefined query template using a trained large language model, and dynamically generating a SQL query statement for the corresponding database according to the matching result;
[0124] A retrieval module for obtaining original data matching the user question from the database based on the SQL query statement; including constructing a transmission channel of the output of a large language model and the database, and delivering the SQL query statement to the database for data retrieval to obtain original data meeting the filtering conditions;
[0125] The integration module is configured to generate a question answer by combining the user question, the original data and context through the large language model, and return the question answer to the user; the integration module comprises the following steps: putting the screened data into the large language model for assembly, assembling a natural and fluent dialogue answer according to the user question and context by using the large model, and constructing a suitable statistical chart by using a graphical table tool to present a situation.
[0126] The feedback optimization module is configured to obtain the satisfaction and suggestions of the user for the query result based on the user receiving the original data, and optimize the prompt word and the query template according to the satisfaction and suggestions.
[0127] Further, the embodiment of the present application also provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to make the computer execute the data query method based on the large language model.
[0128] In the embodiment of the present application, the processor can be an integrated circuit chip with a signal processing capability. The processor can 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, discrete hardware components.
[0129] The disclosed methods, steps and logic block diagrams in the embodiments of the present application can be implemented or executed. The general purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as a hardware code processor for execution, or a combination of hardware and software modules in the code processor for execution. The software module can be located in a random access memory, a flash memory, a read only memory, a programmable read only memory or an electrically erasable programmable memory, a register or other mature storage medium in the art. The processor reads the information in the storage medium, and combines the hardware to complete the steps of the above method.
[0130] The storage medium can be a memory, for example, can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories.
[0131] The non-volatile memory can be a Read-Only Memory (ROM), a Programmable ROM (PROM), an Erasable PROM (EPROM), an Electrically EPROM (EEPROM), or a flash memory.
[0132] The volatile memory can be a Random Access Memory (RAM) used as an external cache. By way of example, and not limitation, many forms of RAM can be used, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced SDRAM (ESDRAM), Sync Link DRAM (SLDRAM), and Direct Rambus RAM (DRRAM).
[0133] The storage media described in the embodiments of the present application are intended to include, but are not limited to these and any other suitable types of memory.
[0134] It should be understood that the disclosed apparatuses in the embodiments of the present application can be implemented in other manners. For example, the division of the modules is merely logical function division, and there can be another division manner in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the communication connection between the modules can be indirect communication connection through some interfaces, or there can be a direct communication connection between the modules, which can be electrical or other forms.
[0135] In addition, each function module in the various embodiments of the present application can be integrated in a processing unit, or each module can exist alone physically, or two or more modules can be integrated in a processing unit. The integrated unit can be implemented in the form of hardware, or in the form of software function units.
[0136] The integrated unit, if implemented in the form of a software function unit and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application, essentially or in other words, the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a number of instructions to make a computer device (which can be a personal computer, a server, or a network device, etc.) execute all or part of the steps of the methods described in various embodiments of the present application. The aforementioned storage medium includes: a U disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store program codes.
[0137] The above merely describes preferred embodiments of the present application and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A data query method based on a large language model, characterized in that, The method comprises: acquiring a user question and a prompt word input by a user; wherein the prompt word comprises a restriction condition and a query scene, the restriction condition is used to instruct a large language model to convert natural language into an SQL query statement, and the query scene is used to instruct the large language model to match a corresponding database; matching the user question and a predefined query template by using a trained large language model, and dynamically generating an SQL query statement of the corresponding database according to a matching result; acquiring original data matched with the user question from the database based on the SQL query statement; generating a question answer by combining the user question, the original data and a context by using the trained large language model, and returning the question answer to the user; wherein a training process of the large language model comprises: constructing a mapping relationship between database fields and natural language, setting a prompt word by using a prompt word engineering technology, training a large language model based on the mapping relationship and the prompt word, and obtaining a trained large language model; the query template comprises a task command, a task requirement, an answer example and a database field description; the task command is used to instruct a recognition content and a recognition position of the large language model; the task requirement is used to instruct a condition of an SQL query statement generated by the large language model; the answer example is used to instruct a 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 filtered data in the user question with the database field description.
2. The data query method based on a large language model according to claim 1, characterized in that, The matching of the user question and the predefined query template by using the trained large language model specifically comprises: performing semantic understanding and analysis on the user question by using the trained large language model, and extracting data fields in the analyzed user question to generate main data and filtered data; matching the filtered data and the predefined query template by using the trained large language model to generate an SQL query statement.
3. The data query method based on a large language model according to claim 1, characterized in that, The condition of the generated SQL query statement comprises: returning empty if there is no SQL statement of the user question; and specifying a target address of the SQL query statement.
4. The data query method based on a large language model according to claim 1, characterized in that, The method further comprises: acquiring a satisfaction degree and a suggestion of a question answer of the user based on that the user receives the original data, and optimizing the task command, the task requirement, the answer example and the database field description according to the satisfaction degree and the suggestion.
5. The data query method based on a large language model according to claim 1, characterized in that, The method further comprises: acquiring a satisfaction degree and a suggestion of a question answer of the user based on that the user receives the original data, and optimizing the prompt word according to the satisfaction degree and the suggestion.
6. The data query method based on a large language model according to claim 1, characterized in that, The construction of the mapping relationship between the database fields and the natural language comprises: constructing a corresponding SQL language based on a data type in the natural language and a field type of the database field, and generating the mapping relationship according to the SQL language.
7. The data query method based on a large language model according to claim 1, characterized in that, The method further comprises: presenting a chart or a table of the question answer by using a visualization tool.
8. A data query device based on a large language model, characterized by, The device comprises: a dialogue module configured to create a user dialogue interface, and acquire a user question and a prompt word input by a user according to the user dialogue interface. A processing module is configured to implement the data query method based on the large language model according to any one of claims 1 to 7, and generate a question answer.
9. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor, so that the computer executes the data query method based on the large language model according to any one of claims 1 to 7.