Data query method, device and storage medium based on large language model
By using a large language model to perform intent analysis and word optimization on query data, a target structured query statement is generated, which solves the problem that the data query system in the existing technology cannot meet personalized needs and realizes efficient and accurate data query.
Patent Information
- Application Number
- CN202511023927.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-24
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2045-07-24
AI Technical Summary
Existing data query systems cannot perform efficient queries based on users' personalized needs, and when relying on large language models, there are problems of low query accuracy and high computational complexity.
The query data is analyzed for intent through a large language model to generate initial sentence prompt words, which are then replaced with target sentence prompt words through word optimization to generate a target structured query statement, and finally the query is executed to obtain the results.
It improves the efficiency and accuracy of data queries, reduces user waiting time, and optimizes the computing load of large language models.
Smart Images

Figure CN120508640B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data query technology, and in particular to a data query method, device, and storage medium based on a large language model. Background Art
[0002] In the current environment of explosive data growth, how to quickly query data is a problem that must be solved.
[0003] Currently, the construction and design of various data query systems often rely on fixed query and analysis conditions included in product design, resulting in users being unable to query data content based on their actual needs. Therefore, generative big models are gradually being introduced into data query scenarios, allowing users to perform data queries based on personalized needs.
[0004] However, such methods are highly dependent on the capabilities and computing resources of large models. Not only will the query accuracy be low due to the insufficient understanding ability of the large model, but the query efficiency will also be affected due to the excessive computational complexity of the large model. Summary of the Invention
[0005] This application at least provides a data query method, apparatus, device, and computer-readable storage medium based on a large language model.
[0006] In a first aspect, the present application provides a data query method based on a large language model, comprising: inputting received data to be queried into the large language model, performing word optimization processing on initial sentence prompt words of the data to be queried using the large language model to obtain target sentence prompt words; generating a target structured query statement corresponding to the target sentence prompt word using the large language model; and executing the target structured query statement to obtain a target query result.
[0007] In one embodiment, the word optimization processing of the initial sentence prompt words of the data to be queried using the large language model to obtain the target sentence prompt words includes: determining the target sentence content in the initial sentence prompt words that matches the preset sentence content; and replacing the target sentence content according to the preset content placeholder to obtain the target sentence prompt words.
[0008] In one embodiment, generating a target structured query statement corresponding to the target sentence prompt word through the large language model includes: generating an initial structured query statement based on the target sentence prompt word; and restoring content placeholders in the initial structured query statement based on the target sentence content to obtain the target structured query statement.
[0009] In one embodiment, before performing word optimization processing on the initial sentence prompt words of the data to be queried using the large language model to obtain target sentence prompt words, the method further includes: performing intent analysis on the data to be queried using the large language model to obtain the intent to be queried corresponding to the data to be queried; and generating initial sentence prompt words based on the intent to be queried.
[0010] In one embodiment, the intention to be queried includes a time period to be queried, and executing the target structured query statement to obtain a target query result includes: executing the target structured query statement to obtain an initial query result; determining whether the first time granularity of the time period to be queried is consistent with the second time granularity of the initial query result; in response to the first time granularity being consistent with the second time granularity, determining the initial query result as the target query result.
[0011] In one embodiment, after determining whether the first time granularity of the time period to be queried is consistent with the second time granularity of the initial query result, the method further includes: in response to the first time granularity being inconsistent with the second time granularity, and the first time granularity being larger than the second time granularity, obtaining the time granularity difference between the first time granularity and the second time granularity; and aggregating the initial query result according to the time granularity difference to obtain the target query result.
[0012] In one embodiment, the intention to be queried includes a name to be queried, and generating an initial statement prompt word based on the intention to be queried includes: performing a search process based on the name to be queried to obtain an initial search result set; in response to the initial search result set being empty, performing a segmentation process on the name to be queried to obtain a sub-name to be queried; performing a search process based on the sub-name to be queried to obtain a target search result set, the target search result set including a target search result; and generating the initial statement prompt word based on the target search result.
[0013] In one embodiment, the intention to be queried includes a type to be queried and a name to be queried. After performing intent analysis on the data to be queried through the large language model to obtain the intention to be queried corresponding to the data to be queried, the method includes: determining a corresponding target query algorithm from a preset query algorithm according to the type to be queried, the preset query algorithm includes a first query algorithm, and the first query algorithm is used to query a target object passing through a specified detection device; in response to the target query algorithm being the first query algorithm, determining the specified detection device from a preset device set according to the name to be queried; obtaining knowledge information corresponding to the specified detection device in a preset knowledge base; generating the initial sentence prompt word according to the knowledge information; performing word optimization processing on the initial sentence prompt word to obtain the target sentence prompt word; generating the target structured query statement according to the target sentence prompt word; executing the target structured query statement to obtain the target query result.
[0014] In a second aspect, the present application provides a data query device based on a large language model, comprising: a word optimization module for inputting received data to be queried into the large language model, so as to perform word optimization processing on initial sentence prompt words of the data to be queried using the large language model to obtain target sentence prompt words; a sentence generation module for generating a target structured query sentence corresponding to the target sentence prompt word using the large language model; and a target query module for executing the target structured query sentence to obtain a target query result.
[0015] A third aspect of the present application provides an electronic device, including a memory and a processor, wherein the processor is configured to execute program instructions stored in the memory to implement the above-mentioned data query method based on a large language model.
[0016] In a fourth aspect, the present application provides a computer-readable storage medium having program instructions stored thereon. When the program instructions are executed by a processor, the above-mentioned data query method based on a large language model is implemented.
[0017] The above scheme, by inputting the data to be queried into the large language model, enables the large language model to fully understand and analyze the relationship between the data to be queried and the database table, and then can construct initial sentence prompt words for the data to be queried for the generation of structured query statements. Among them, the large language model can optimize the words of the initial sentence prompt words by replacing placeholders, so that some variable parameters can be replaced to obtain the target sentence prompt words, thereby enabling the large language model to reduce the amount of data that needs to be analyzed and processed in the process of generating the target structured query statement based on the target sentence prompt words, in order to speed up the output speed of the large language model for the target structured query statement and reduce the actual waiting time of the user. Then, the target query result can be obtained by executing the target structured query statement. Therefore, the method of the present application can improve the generation speed of the query statement and thus achieve the improvement of data query efficiency.
[0018] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The drawings herein are incorporated into and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and, together with the specification, are used to illustrate the technical solutions of the present application.
[0020] Figure 1 This is a flowchart of an exemplary embodiment of the data query method based on a large language model of the present application;
[0021] Figure 2 This is a flowchart of an exemplary vehicle query scenario in the data query method based on a large language model of the present application;
[0022] Figure 3 is a block diagram of a data query device based on a large language model, shown as an exemplary embodiment of the present application;
[0023] Figure 4 This is a structural diagram of an embodiment of an electronic device of the present application;
[0024] Figure 5 It is a structural diagram of an embodiment of a computer-readable storage medium of the present application. DETAILED DESCRIPTION
[0025] The following describes the embodiments of the present application in detail with reference to the accompanying drawings.
[0026] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.
[0027] The term "and / or" in this article is simply a description of the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent three situations: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects are in an "or" relationship. In addition, "many" in this article means two or more than two. In addition, the term "at least one" in this article means any combination of at least two of any one or more of a plurality of. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0028] See also Figure 1 , Figure 1 This is a flowchart of an exemplary embodiment of the data query method based on a large language model of the present application. Specifically, it may include the following steps:
[0029] In step S110 , the received data to be queried is input into the large language model, so as to optimize the initial sentence prompt words of the data to be queried by the large language model to obtain target sentence prompt words.
[0030] The data to be queried may include, but is not limited to, natural language, machine language, and / or programming language. In the embodiments of this application, the example of text data in natural language input by a user is used for illustration. For example, the data to be queried may be a query question input by the user. The method for obtaining the data to be queried may be multimodal, for example, including but not limited to receiving natural language text input by the user; receiving an image input by the user and generating text describing the image content based on the image to obtain the data to be queried; receiving audio input by the user and generating text describing the audio content based on the audio to obtain the data to be queried, etc. It may also be implemented through data fusion of multiple modalities, such as receiving natural language text and an image input by the user, generating image description text describing the image content, and combining the natural language text with the image description text (which may be a simple word-by-word concatenation and / or semantic understanding of the two texts followed by regeneration of text) to obtain the data to be queried. Similarly, the method may also be implemented in scenarios involving both text and voice, both image and voice, or a combination of text, image, and voice, which will not be elaborated here.
[0031] A Large Language Model (LLM) is a deep learning model trained using large amounts of text data, enabling it to understand the meaning of text. The LLM in this application can be a standalone model or built into a query application or query system (and may include additional functional modules), without limitation here.
[0032] For example, a business table knowledge base can be constructed based on the specific needs of an actual application scenario. For example, for a vehicle counting application scenario (counting vehicles passing through one or more detection devices), the business table knowledge base may include, but is not limited to, all business table names, library names, table descriptions, field names, field descriptions, DDL statements, and other information required for the vehicle counting application scenario. The information included in the business table knowledge base can be referred to as knowledge information.
[0033] When the large language model receives a user-entered query related to vehicle statistics, it triggers a query process. Using techniques such as semantic analysis, the large language model determines whether the user's input is a vehicle statistics query. If so, it executes the corresponding query process. If not, it can execute other operations or not respond, etc. (This section is not detailed here).
[0034] Furthermore, the large language model can understand and analyze received queries and derive the corresponding question intent. Question intent represents the user's intent in the query, representing a type of semantic information. LLM can then construct prompt words (such as initial statement prompt words) based on knowledge information from the business table knowledge base and question intent. LLM's SQL-generating capabilities can then be leveraged to generate SQL statements (target structured query statements) that can be used for database queries.
[0035] The query may be performed by using the initial statement prompt words to generate an SQL statement; or the query may be performed by optimizing the initial statement prompt words to obtain optimized initial statement prompt words (target statement prompt words), and then generating an SQL statement based on the target statement prompt words.
[0036] Exemplarily, the word optimization processing of the present application may include but is not limited to word replacement processing of some specified content (such as the channel coding list of the detection device, the query address and / or other specified query content, etc.), which will not be elaborated here.
[0037] Through word optimization processing, initial sentence prompts with long, complex content can be replaced with concise and clear target sentence prompts. This can reduce the amount of word data that the large language model needs to understand and analyze, and also reduce the difficulty of the large language model in understanding and analyzing words, thereby speeding up the SQL generation and output of LLM and reducing the actual waiting time of users.
[0038] Step S120 : Generate a target structured query sentence corresponding to the target sentence prompt word using the large language model.
[0039] For example, after obtaining the target sentence prompt words, LLM can use the target sentence prompt words to generate SQL statements to obtain the target structured query statement. Compared with the traditional method of directly using the initial sentence prompt words constructed by LLM to generate the initial structured query statement, this is more efficient.
[0040] It should be noted that common LLMs already have the ability to generate corresponding SQL statements based on prompt words. Therefore, this application does not elaborate on the specific principles of LLM generation of SQL statements. You can refer to existing LLM technology implementations for generating SQL statements, or you can adapt and flexibly adjust it according to actual needs.
[0041] Step S130: execute the target structured query statement to obtain the target query result.
[0042] The target query result may be presented in one or more forms, which are not limited here. For example, the target query result may be text, chart, image, audio or video, etc.
[0043] The specific principles and methods for executing SQL statements are well-known in the art and will not be elaborated on here. However, the present application can adapt the SQL statement execution process to different application scenarios. For example, after the LLM outputs the SQL statement, the SQL statement can be executed locally or sent to another computer connected to the target database for execution, without limitation here.
[0044] For another example, when querying the target object passing through a specified detection device, and when querying the detection device that the target object passed through, the two application scenarios are different, and it is necessary to execute SQL statements according to different query algorithms to obtain the corresponding target query results. Here, we will not go into details. Among them, the detection equipment of this application may include but is not limited to cameras, radars, infrared sensors, radio frequency sensors, etc. The target objects of this application may include but are not limited to people, cars or other animals and plants, commodities, etc.
[0045] It can be seen that the present application inputs the data to be queried into the large language model, so that the large language model fully understands and analyzes the relationship between the data to be queried and the database table, and then can construct initial statement prompt words for the data to be queried for the generation of structured query statements. Among them, the large language model can optimize the words of the initial statement prompt words by replacing placeholders, so that some variable parameters can be replaced to obtain the target statement prompt words, and then the large language model reduces the amount of data that needs to be analyzed and processed in the process of generating the target structured query statement based on the target statement prompt words, in order to speed up the output speed of the large language model for the target structured query statement and reduce the actual waiting time of the user. Then, the target query result can be obtained by executing the target structured query statement. Therefore, the method of the present application can improve the generation speed of the query statement and thus achieve the improvement of data query efficiency.
[0046] Based on the above embodiment, the present embodiment describes the steps of optimizing the initial sentence prompt words of the query data using a large language model to obtain the target sentence prompt words. Specifically, the method of this embodiment includes the following steps:
[0047] Determine the target sentence content in the initial sentence prompt word that matches the preset sentence content; replace the target sentence content according to the preset content placeholder to obtain the target sentence prompt word.
[0048] The preset sentence content refers to the sentence content that needs to be replaced. By matching the initial sentence prompt word with the preset sentence content, the target sentence content that needs to be replaced in the initial sentence prompt word can be determined.
[0049] It should be noted that the process of matching the initial sentence prompt word with the preset sentence content may include but is not limited to semantic matching and / or word matching. Semantic matching refers to matching the initial sentence prompt word with the preset sentence content from a semantic level. The initial sentence prompt word and the preset sentence content do not have to be exactly the same word for word (for example, the initial sentence prompt word can be "Telephone number: xxxxxxxxxxx", and the preset sentence content can be "Contact information"). Word matching refers to matching the initial sentence prompt word with the preset sentence content from a word level. The initial sentence prompt word and the preset sentence content need to be exactly the same word for word, or the proportion of the same words in the initial sentence prompt word and the preset sentence content must be greater than a preset proportion threshold, etc., in order for the two to be considered a match.
[0050] For example, after determining the target sentence content that needs to be replaced, the preset content placeholder can be used to replace the target sentence content to obtain the target sentence prompt word. The form of the content placeholder can be set as needed, which can be various and will not be described here. For example, the content placeholder of this application can be some keywords. The role of the content placeholder is mainly to replace some content that has little or no effect on the semantic understanding and analysis of LLM, so as to avoid LLM consuming too much time and resources on such content for understanding and analysis, thereby affecting the speed of generating SQL statements. In addition, such content is also prone to cause semantic misunderstanding problems of LLM, thereby affecting the accuracy of generating SQL statements.
[0051] In another exemplary embodiment, the content placeholders of the present application can be preset or generated in real time. For example, LLM can combine the context information of the query question and / or the knowledge information of the business table knowledge base and other related data to perform semantic generalization and extraction on the target sentence content, obtain the real-time generated content placeholders and perform replacement processing in the same way to obtain the target sentence prompt words. For example, for the phone number "xxxxxxxxxxx", after the LLM model understands that this string of numbers is a phone number, it can generate <tel>Placeholder (or <telephone>Placeholders, etc., which can be set as needed) are replaced, thereby shortening the word length without losing its semantics.
[0052] As another example, let's take the application scenario of counting passing vehicles as an example. The detection equipment (e.g., a camera) typically used to detect target vehicles (target objects) exists in a certain organizational structure. Therefore, during the execution of the present method, an organizational tree of the detection equipment can also be obtained (the execution sequence of this process is not limited; for example, it can be before or after step S110, depending on actual needs).
[0053] Subsequently, based on the received list of organization names, device names, and organization tree for the testing devices, the organization name and device name can be searched in the organization tree, recording an organization search result set A and a device search result set B. If A and B are not empty, the organization name can be searched and filtered in the organization tree to obtain a device search result set B0 in A. Then, based on the device name, the results in B0 can be searched and filtered for device names in B to obtain the corresponding testing devices, thus forming a query device list C. Furthermore, based on the device information recorded in the organization tree, the testing devices in C can be converted into a list of channel codes (channel list). The channel code is equivalent to the unique identifier of the testing device, and the corresponding device ID can be used to search for the corresponding device in the database. However, the content of the channel list is often lengthy and lacks significant semantic meaning (it can be equivalent to a query address). Therefore, when the LLM identifies the channel list in the query data, it can be replaced with a content placeholder. This allows the LLM to avoid excessive attention to the replaced words when generating SQL statements based on the prompt word, thereby speeding up the LLM's SQL output.
[0054] In addition to replacing content such as the channel list, you can also set other specified content for replacement. Optionally, you can also set a word length threshold and replace content greater than the word length threshold (determined to be redundant content) with a content placeholder using the method described in the previous embodiment. The details are not repeated here.
[0055] Based on the above embodiment, the present embodiment of the application describes the steps of generating a target structured query sentence corresponding to the target sentence prompt word through a large language model. Specifically, the method of this embodiment includes the following steps:
[0056] An initial structured query statement is generated according to the target sentence prompt word; and a content placeholder in the initial structured query statement is restored according to the target sentence content to obtain a target structured query statement.
[0057] With reference to the above embodiment, after obtaining the target sentence prompt words, an initial structured query sentence can be generated according to the target sentence prompt words through LLM.
[0058] It should be noted that the target sentence prompt includes content placeholders. Therefore, the initial structured query generated based on the target sentence prompt also includes content placeholders. Therefore, directly executing the initial structured query typically does not yield the corresponding query results. Therefore, the content placeholders in the initial structured query can be restored (e.g., by regular expression replacement) based on the replaced target sentence content, restoring the content placeholders to the target sentence content before replacement, thereby yielding the target structured query. Furthermore, the target query results can be obtained by executing the target structured query normally.
[0059] Based on the above embodiment, the present embodiment of the application describes the steps before optimizing the initial sentence prompt words of the query data using a large language model to obtain the target sentence prompt words. Specifically, the method of this embodiment includes the following steps:
[0060] The query data is analyzed through a large language model to obtain the query intent corresponding to the query data; and the initial sentence prompt words are generated based on the query intent.
[0061] With reference to the above embodiment, after the LLM recognizes the query question input by the user, it may trigger a corresponding query process.
[0062] For example, using vehicle passing statistics as an example, when implementing the present method, current time information can be obtained for subsequent processing of the query time range during the query process. Device information and organization information of associated detection devices on the video cloud platform can also be obtained. Each organization and the detection devices within the organization, as well as the detection devices within each organization's subordinate organizations, can be associated with the organization, thereby assembling an organization tree.
[0063] After receiving the query data (query question), LLM can be used to perform intent analysis on the query data to obtain the corresponding query intent, thereby reflecting the user's needs for raising query questions.
[0064] For example, the query intent may include but is not limited to:
[0065] 1. Query Type: User queries for vehicle statistics can generally be categorized into two types: querying passing vehicles by device or querying passing devices by vehicle. Querying passing vehicles by device refers to searching for corresponding vehicle records based on a specified range of detection devices (other query conditions may be added) for subsequent statistical analysis. Querying passing devices by vehicle refers to searching for vehicle records based on query conditions (such as a specified license plate or vehicle model) without specifying a device range, and then performing statistics and analysis based on the detection device.
[0066] 2. Query Conditions: Identify basic query dictionary conditions in the query data, which can be used to obtain dictionary content corresponding to the conditions, including vehicle color dictionaries, vehicle type dictionaries, license plate color dictionaries, license plate type dictionaries, and other possible query conditions, which are not limited here. This allows the user to determine the vehicle color, vehicle type, license plate color, license plate type, etc. from the query data.
[0067] 3. Query Time Range: Identify the time range of the query data, such as fuzzy time ranges like the past week or the last month. Then, combine it with the current system time to determine the exact time range the user actually wants to query. If the user already enters a precise time range (e.g., year, month, day, hour, etc.), the precise time range can be used directly as one of the query intents.
[0068] 4. Device name: Identify whether the query data mentions one or more specific testing devices; if so, these device names can be combined into a device list and returned.
[0069] 5. Organization Name: Identify whether the query data mentions one or more specific device organizations; if so, group these organization names into an organization list and return it.
[0070] 6. Output Type: Identify the desired output type for the query data. This typically defaults to text. Optionally, some statistical analysis results may require charting. Based on the query data, you can then generate and return corresponding line charts, bar charts, pie charts, and other types of charts.
[0071] Furthermore, after determining the user's query intent based on the query data, an initial sentence prompt word can be generated based on the query intent. The specific principle can refer to the principle of using LLM to generate SQL in the existing method, which will not be elaborated here.
[0072] For example, the LLM can construct prompt words based on relevant information obtained from the aforementioned embodiments (e.g., the overall goal of filtering the data tables to be queried (equivalent to analyzing the target objects to be queried), optional descriptions and explanations of all data tables, the user's query question, the query conditions in the user's identified query intent, and the required output format). The required output format may include, but is not limited to, a list of filtered data tables.
[0073] Based on the filtered data table list, the knowledge information for the corresponding data table can be retrieved from the established data table knowledge base. The query conditions extracted from the knowledge information, query question (data to be queried), and intent to be identified are combined with commonly used terminology and knowledge interpretations in specific application scenarios (such as vehicle inquiries and statistics) to assemble prompt words. Leveraging the LLM's native SQL capabilities, SQL statements can be generated for database queries. The prompt word assembly process can refer to the methods of the previous embodiment, using content placeholders to replace channel lists or other specified content.
[0074] Based on the above embodiment, the present embodiment of the application describes the steps of executing the target structured query statement and obtaining the target query result. Among them, the query intent includes the query time period. Specifically, the method of this embodiment includes the following steps:
[0075] Execute the target structured query statement to obtain an initial query result; determine whether the first time granularity of the query period is consistent with the second time granularity of the initial query result; in response to the first time granularity and the second time granularity being consistent, determine the initial query result as the target query result.
[0076] In conjunction with the aforementioned embodiments, the query process of this application can be based on a time range. That is, if the query intent includes a query period, the target query result should also be within that query period. Therefore, by comparing whether the query period in the query intent is the same as the query period represented by the query result, it can be determined whether the query result meets the requirements and whether the target query result is obtained.
[0077] For example, the target structured query statement can be executed to obtain initial query results. A first time granularity for the query period is then determined. The first time granularity represents the time period within which the user needs to query, or the time period within which the user needs to output query results. A second time granularity for the initial query results is determined. The second time granularity represents the actual time period within which the initial query results fall.
[0078] The first time granularity is compared with the second time granularity; in response to the first time granularity being consistent with the second time granularity, it indicates that the initial query result meets the query intention, and the initial query result can be determined as the target query result.
[0079] Based on the above embodiment, the embodiment of the present application describes the steps after determining whether the first time granularity of the query period is consistent with the second time granularity of the initial query result. Specifically, the method of this embodiment includes the following steps:
[0080] In response to the first time granularity being inconsistent with the second time granularity and the first time granularity being larger than the second time granularity, a time granularity difference between the first time granularity and the second time granularity is obtained; and the initial query result is aggregated according to the time granularity difference to obtain a target query result.
[0081] With reference to the above-mentioned embodiment, after comparing the first time granularity with the second time granularity, if the first time granularity is inconsistent with the second time granularity, the initial query results need to be sorted according to the difference between the first time granularity and the second time granularity in order to obtain the target query results that meet the query intention.
[0082] For example, when the first time granularity is inconsistent with the second time granularity, and the first time granularity is larger than the second time granularity (for example, if the user needs to perform data query statistics every 5 minutes, the first time granularity is 5 minutes; and the query result is a data query output in a 1 minute period, the second time granularity is 1 minute), it is necessary to perform time dimension-based aggregation processing on the initial query result according to the time granularity difference to obtain the target query result.
[0083] Specifically, after the LLM determines that aggregation processing is required, it can execute a preset aggregation script, using the second time granularity as the aggregation input granularity, the initial query result (which can be adjusted to JSON format) as the aggregation input data, and the first time granularity as the aggregation output granularity. This allows time-based aggregation to be performed at the first time granularity (for example, aggregating five 1-minute initial query results to obtain a single 5-minute target query result). The aggregated JSON can then overwrite the original initial query result, thus obtaining the target query result. During the aggregation process, you can also set the aggregation time field or more conditions to limit the scope of data participating in the aggregation process, which will not be detailed here.
[0084] LLM's summary output capabilities can also be used to organize the aggregated JSON and, based on the user's query and desired output type, produce the final target query result. For example, if the user desires text output, the target query result is summarized and returned as text data; if the user desires table or chart output, the target query result is converted into the output table or chart's JSON format, along with the chart title and type, and the corresponding display script is invoked to draw the corresponding table or chart content.
[0085] Based on the above embodiment, the present embodiment of the application describes the steps of generating an initial sentence prompt word based on the query intent. The query intent includes the query name. Specifically, the method of this embodiment includes the following steps:
[0086] Perform retrieval processing based on the name to be queried to obtain an initial retrieval result set; in response to the initial retrieval result set being empty, perform segmentation processing on the name to be queried to obtain sub-names to be queried; perform retrieval processing based on the sub-names to be queried to obtain a target retrieval result set, the target retrieval result set including the target retrieval result; generate an initial sentence prompt word based on the target retrieval result.
[0087] In combination with the above embodiment, the application scenario of counting passing vehicles is still used for explanation, and it is necessary to query the passing vehicles based on the detection equipment.
[0088] The name to be retrieved may include but is not limited to the name of the organization where the detection device is located, the device name of the detection device, etc., which can be set as needed according to the actual application scenario and will not be elaborated here.
[0089] For example, after obtaining the organization name list, device name list, and organization tree information for the testing devices, a search can be performed within the organization tree based on the organization name and device name in the received query data. The organization name can be searched first to obtain a search result set A, and then the device name can be searched based on A to obtain a search result set B. If A and B are not empty sets, the method described in the previous embodiment can be used to obtain the final testing device list C. The testing devices in C are used as the specified testing devices to obtain knowledge information from the corresponding data table in the data table knowledge base, and prompt words are constructed based on the query question and query conditions.
[0090] If A and / or B are empty sets, for example, if A is an empty set, the organization name to be queried can be segmented to obtain sub-names to be queried (for example, if the organization name is "name", it can be segmented to obtain "nam", "na", etc.). Then, the search process is repeated based on the sub-name to be queried until the corresponding organization name can be retrieved in the organization tree so that A is not an empty set, or the preset number of searches is reached, or the sub-name to be queried has been segmented into the smallest word unit, or the length of the input string to be searched (the sub-name to be queried) is ≤ 1 / 2 of the length of the original string (the name to be queried), etc. Similarly, if B is an empty set, for example, the device name to be queried can be segmented until the corresponding device name is retrieved so that B is not an empty set, or other conditions are met, etc., which are not detailed here.
[0091] If A and B are still empty sets after the name split and re-search, the result of retrieving the corresponding organization or the corresponding device can be returned.
[0092] Based on the above embodiment, the present embodiment of the application describes the steps after performing intent analysis on the query data through a large language model to obtain the query intent corresponding to the query data. The query intent includes the query type and the query name. Specifically, the method of this embodiment includes the following steps:
[0093] A corresponding target query algorithm is determined from a preset query algorithm according to the type to be queried, and the preset query algorithm includes a first query algorithm, and the first query algorithm is used to query the target object passing through the specified detection device; in response to the target query algorithm being the first query algorithm, the specified detection device is determined from a preset device set according to the name to be queried; knowledge information corresponding to the specified detection device in a preset knowledge base is obtained; an initial sentence prompt word is generated according to the knowledge information; the initial sentence prompt word is optimized to obtain a target sentence prompt word; a target structured query statement is generated according to the target sentence prompt word; and the target structured query statement is executed to obtain a target query result.
[0094] With reference to the above embodiments, the query process of the present application may involve one or more query algorithms for different application scenarios, and the specific query algorithm used may be determined based on the type of query to be obtained from the intent analysis.
[0095] For example, before this, LLM can also determine whether the queried intent is correctly understood; if so, continue to execute subsequent steps; if not, it can output relevant prompt information indicating that "intent is not understood" and suspend execution of subsequent steps.
[0096] If the query intent is correctly understood, the target query algorithm to be used can be determined based on the query type. For example, in a vehicle counting scenario, pre-defined query algorithms may include, but are not limited to, querying passing vehicles based on a specified detection device (the first query algorithm, referred to as "device check") and querying the detection devices that the target vehicle has passed (the second query algorithm, referred to as "vehicle check") based on the target vehicle. After executing the corresponding query algorithm, the target query result, formatted as JSON, is obtained. The query result is checked to see if it is empty. If so, a "no results found" message may be displayed. If not, the query result may be output in the desired format. Furthermore, it may be determined whether the query result requires aggregation.
[0097] In the process of executing the first query algorithm, the specified detection device can be determined from the preset device set according to the name to be queried; the knowledge information corresponding to the specified detection device in the preset knowledge base can be obtained; the initial sentence prompt words can be generated according to the knowledge information; the initial sentence prompt words can be optimized to obtain the target sentence prompt words; the target structured query statement can be generated according to the target sentence prompt words; the target structured query statement can be executed to obtain the target query result.
[0098] During the execution of the second query algorithm, the LLM's understanding capabilities can similarly be used to construct prompts. These can include: determining the overall goal of the vehicle query (equivalent to determining the target vehicle), the description of the vehicle data table in the knowledge base and its field explanations, the user's query question, the query conditions from the identified user intent, and common terminology and knowledge interpretations within the vehicle query and statistics business. The LLM's SQL-generated SQL capabilities then output SQL statements for querying the vehicle data table. Executing this SQL statement yields the vehicle query results. The vehicle query results, query question, query conditions extracted from intent identification, and common terminology and knowledge interpretations within the vehicle query and statistics business are then assembled into prompts. LLM's SQL-generated SQL capabilities then generate SQL statements for the inspection equipment results the user actually wants to query based on the user's query question and vehicle query results. Executing this SQL statement yields the equipment query results. Optionally, the equipment query results can be returned as the target query result for the second query algorithm. Alternatively, the vehicle query results and equipment query results from the second query algorithm can be combined to yield the target query result and returned.
[0099] In summary, the specific implementation process of this embodiment can be referred to as an example. Figure 2 As shown, Figure 2 This is a flowchart of an exemplary vehicle query scenario in the data query method based on a large language model of this application. This flowchart can be understood in conjunction with the aforementioned embodiments and will not be described in detail here.
[0100] Through the data query method provided in this application, it can be seen that the use of prior knowledge to perform intent analysis and workflow segmentation design for areas where data queries are required (such as the vehicle passing query area) reduces the difficulty of large models in understanding the business, avoids blind understanding of large models and leads to generation errors, and can improve the accuracy of generation conditions by decomposing the problem.
[0101] Moreover, when generating SQL, this method replaces information used for query, such as channel lists, with content placeholders and keywords, thereby greatly reducing the time wasted when the large model outputs the list as is when the information to be queried is long, and significantly reducing the SQL output waiting time.
[0102] In addition, due to model capacity limitations, complex time aggregation calculations in SQL queries are usually difficult to implement. This method uses a large model to compare and analyze the time granularity of database query results and the time granularity of user query questions, to determine whether the query results require further time aggregation calculations, as well as the fields and granularity of the aggregation. Aggregation calculations can be combined with Python scripts, greatly improving the accuracy of aggregation calculations at different time granularities.
[0103] Finally, when outputting the target query results, we can also analyze the user's intention for result display and process the query result data according to the data requirements of different output formats such as line charts, bar charts, pie charts, tables, etc., to obtain result output that meets user expectations.
[0104] It should be further explained that the execution entity of the data query method based on a large language model may be a data query device based on a large language model. For example, the data query method based on a large language model may be executed by a terminal device, a server, or other processing device, wherein the terminal device may be a user equipment (UE), a computer, a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, an in-vehicle device, a wearable device, etc. In some possible implementations, the data query method based on a large language model may be implemented by a processor calling computer-readable instructions stored in a memory.
[0105] Figure 3 FIG is a block diagram of a data query device based on a large language model, shown as an exemplary embodiment of the present application. Figure 3 As shown, the exemplary data query device 300 based on a large language model includes: a word optimization module 310, a sentence generation module 320 and a target query module 330. Specifically:
[0106] The word optimization module 310 is used to input the received query data into the large language model, so as to optimize the initial sentence prompt words of the query data through the large language model to obtain the target sentence prompt words.
[0107] The sentence generation module 320 is used to generate a target structured query sentence corresponding to the target sentence prompt word through the large language model.
[0108] The target query module 330 is used to execute the target structured query statement to obtain the target query result.
[0109] In this exemplary data query device based on a large language model, by inputting the data to be queried into the large language model, the large language model fully understands and analyzes the relationship between the data to be queried and the database table, and then can construct an initial sentence prompt word for the data to be queried for the generation of a structured query statement. Among them, the large language model can optimize the words of the initial sentence prompt word by replacing the placeholder, so that some variable parameters can be replaced to obtain the target sentence prompt word, thereby reducing the amount of data that needs to be analyzed and processed in the process of generating the target structured query statement based on the target sentence prompt word. In order to speed up the output speed of the large language model for the target structured query statement, the actual waiting time of the user is reduced. Then, the target query result can be obtained by executing the target structured query statement. Therefore, the method of the present application can improve the generation speed of the query statement and thus achieve the improvement of data query efficiency.
[0110] It should be noted that the apparatus provided in the above embodiments and the methods provided in the above embodiments are based on the same concept. The specific manner in which the various modules and units perform their operations has been described in detail in the method embodiments and will not be repeated here. In actual applications, the apparatus provided in the above embodiments can, as needed, allocate the above functions to different functional modules, i.e., divide the internal structure of the apparatus into different functional modules to perform all or part of the functions described above. This is not a limitation herein.
[0111] Among them, the functions of each module can be found in the embodiment of the data query method based on the large language model, and will not be repeated here.
[0112] See also Figure 4 , Figure 4 1 is a schematic diagram of the structure of an embodiment of an electronic device of the present application. Electronic device 100 includes memory 101 and processor 102. Processor 102 is configured to execute program instructions stored in memory 101 to implement the steps of any of the above-mentioned embodiments of the data query method based on a large language model. In a specific implementation scenario, electronic device 100 may include, but is not limited to, a microcomputer and a server. In addition, electronic device 100 may also include mobile devices such as laptops and tablet computers, which are not limited here.
[0113] Specifically, the processor 102 is used to control itself and the memory 101 to implement the steps in any of the above-mentioned embodiments of the data query method based on the large language model. The processor 102 can also be called a CPU (Central Processing Unit). The processor 102 may be an integrated circuit chip with signal processing capabilities. The processor 102 can also be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 102 can be implemented by an integrated circuit chip.
[0114] In this exemplary electronic device, by inputting the data to be queried into the large language model, the large language model fully understands and analyzes the relationship between the data to be queried and the database table, and then can construct an initial sentence prompt word for the data to be queried for the generation of a structured query statement. Among them, the large language model can optimize the words of the initial sentence prompt word by replacing the placeholder, so that some variable parameters can be replaced to obtain the target sentence prompt word, thereby reducing the amount of data that needs to be analyzed and processed in the process of generating the target structured query statement based on the target sentence prompt word. In order to speed up the output speed of the large language model for the target structured query statement, the actual waiting time of the user is reduced. Then, the target query result can be obtained by executing the target structured query statement. Therefore, the method of the present application can improve the generation speed of the query statement and thus achieve the improvement of data query efficiency.
[0115] See also Figure 5 , Figure 5 The computer-readable storage medium 110 stores program instructions 111 that can be executed by a processor, and the program instructions 111 are used to implement the steps of any of the above-mentioned data query method embodiments based on a large language model.
[0116] In this exemplary storage medium, by running the program instructions in the storage medium, the data to be queried is input into the large language model, so that the large language model fully understands and analyzes the relationship between the data to be queried and the database table, and then can construct an initial statement prompt word for the data to be queried for the generation of a structured query statement. Among them, the large language model can optimize the words of the initial statement prompt word by replacing the placeholder, so that some variable parameters can be replaced to obtain the target statement prompt word, thereby reducing the amount of data that needs to be analyzed and processed in the process of generating the target structured query statement based on the target statement prompt word, in order to speed up the output speed of the large language model for the target structured query statement and reduce the actual waiting time of the user. Then, the target query result can be obtained by executing the target structured query statement. Therefore, the method of the present application can improve the generation speed of the query statement and thus achieve the improvement of data query efficiency.
[0117] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments. For the sake of brevity, it will not be repeated here.
[0118] The above description of the various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced with each other and will not be repeated herein for the sake of brevity.
[0119] In the several embodiments provided in this application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation methods described above are only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation. For example, units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0120] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in either hardware or software functional units. If the integrated units are implemented as software functional units and sold or used as standalone products, they may be stored on a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the portion that contributes to the prior art, or all or part of the technical solution, may be embodied in the form of a software product. This computer software product, stored on a storage medium, includes instructions for causing a computer device (such as a personal computer, server, or network device) or processor to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage media include various media capable of storing program code, such as USB flash drives, removable hard drives, read-only memories (ROMs), random access memories (RAMs), magnetic disks, or optical disks.< / telephone> < / tel>
Claims
1. A data query method based on a large language model, characterized in that: The method comprises: Inputting the received data to be queried into the large language model, performing intent analysis on the data to be queried using the large language model to obtain the intent to be queried corresponding to the data to be queried; generating an initial sentence prompt word based on the intent to be queried; the intent to be queried includes the type to be queried and the name to be queried; The step of generating an initial statement prompt word according to the intention to be queried includes: determining a corresponding target query algorithm from a preset query algorithm according to the type to be queried, the preset query algorithm including a first query algorithm, the first query algorithm being used to query a target object that has passed through a designated detection device; in response to the target query algorithm being the first query algorithm, determining the designated detection device from a preset device set according to the name to be queried; obtaining knowledge information corresponding to the designated detection device from a preset knowledge base; and generating the initial statement prompt word according to the knowledge information; Performing word optimization processing on the initial sentence prompt words of the data to be queried using the large language model to obtain target sentence prompt words; The step of performing word optimization processing on the initial sentence prompt words of the query data using the large language model to obtain the target sentence prompt words includes: determining target sentence content in the initial sentence prompt words that matches preset sentence content; replacing the target sentence content according to preset content placeholders to obtain the target sentence prompt words; Generate a target structured query sentence corresponding to the target sentence prompt word through the large language model; The step of generating a target structured query statement corresponding to the target sentence prompt word using the large language model includes: generating an initial structured query statement based on the target sentence prompt word; restoring content placeholders in the initial structured query statement based on the target sentence content to obtain the target structured query statement; Execute the target structured query statement to obtain a target query result.
2. The method according to claim 1, characterized in that The query intent includes a query period, and executing the target structured query statement to obtain a target query result includes: Executing the target structured query statement to obtain an initial query result; Determining whether the first time granularity of the time period to be queried is consistent with the second time granularity of the initial query result; In response to the first time granularity being consistent with the second time granularity, the initial query result is determined as the target query result.
3. The method according to claim 2, characterized in that After determining whether the first time granularity of the to-be-queried time period is consistent with the second time granularity of the initial query result, the method further includes: In response to the first time granularity being inconsistent with the second time granularity, and the first time granularity being greater than the second time granularity, obtaining a time granularity difference between the first time granularity and the second time granularity; The initial query results are aggregated according to the time granularity difference to obtain the target query result.
4. The method according to claim 1, wherein Generating an initial sentence prompt word according to the query intention includes: Performing a search process based on the name to be queried to obtain an initial search result set; In response to the initial search result set being empty, segmenting the name to be queried to obtain sub-names to be queried; Performing a search process according to the sub-name to be queried to obtain a target search result set, wherein the target search result set includes a target search result; The initial sentence prompt word is generated according to the target search result.
5. The method according to claim 1, wherein After generating the initial sentence prompt word according to the knowledge information, the method includes: Performing word optimization processing on the initial sentence prompt words to obtain the target sentence prompt words; Generating the target structured query sentence according to the target sentence prompt word; Execute the target structured query statement to obtain the target query result.
6. An electronic device, characterized in that: The method comprises a memory and a processor, wherein the processor is configured to execute program instructions stored in the memory to implement the method according to any one of claims 1 to 5.
7. A computer-readable storage medium having program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Database query method and device based on natural language and electronic equipment
CN118535679A
Intelligent interaction method, device and system based on large model, medium and equipment
CN119782484A
Method and device for compressing cue words of large language model and medium
CN119940540A