Data query method and device based on large language model, program product and medium

By building a preset knowledge base and utilizing vector matching technology, the low accuracy problem of large language models when converting natural language queries into SQL is solved, achieving higher query accuracy and user experience.

CN120804298AActive Publication Date: 2025-10-17KOUBEI SHANGHAI INFORMATION TECH CO LTD

Patent Information

Application Number
CN202511300329.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-11
Publication Date
2025-10-17
Estimated Expiration
2045-09-11

AI Technical Summary

Technical Problem

When existing large language models convert users' natural language queries into structured query language (SQL), they suffer from low query accuracy and difficulty in accurately matching industry and internal corporate terminology, resulting in limited user experience and data result accuracy.

Method used

A preset knowledge base is constructed, and the mapping problem between natural language colloquial expressions and database structured fields is solved through vector matching. The preset knowledge base is designed to store standard descriptions, colloquial descriptions and corresponding relationships of query elements, and a large language model is used to identify query elements and generate query statements.

Benefits of technology

It significantly improves the convenience and accuracy of user queries, reduces query failures caused by non-standard user expressions, reduces semantic understanding errors, and improves the accuracy of NL2SQL.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120804298A_ABST
    Figure CN120804298A_ABST
Patent Text Reader

Abstract

The invention provides a data query method and device based on a large language model, a program product and a medium, and the method comprises the steps: obtaining a natural language query of a user, inputting the natural language query into a preset large language model, and recognizing query elements contained in the natural language query according to a recognition result of the large language model for the query elements contained in the natural language query; determining a description text of a current query element required for generating the current query statement; obtaining a current vector corresponding to the description text of the current query element; based on a preset knowledge base, determining standard description of the matched query elements and field information of the matched query elements in the data table by utilizing a matching vector matched with the current vector; the preset knowledge base stores a standard description of a preset query element, a spoken description of the preset query element, a vector of the spoken description and a relation of field information of the preset query element in the data table; and according to the standard description of the matched query element and the field information in the data table, generating a current query statement to perform data query.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present specification relates to the technical field of artificial intelligence, and in particular to a data query method based on a large language model, a device, a program product, and a medium. BACKGROUND

[0002] At present, large language models (LLMs) are becoming more and more popular. For example, in the field of data query, users can ask questions to a large language model, and the user's question can be converted into a structured query language (SQL) that can be executed in a database. However, the quality of the SQL generated by the current LLM is not high, resulting in a low data query accuracy. SUMMARY

[0003] To overcome the problems in the related art, the present specification provides a data query method, a device, a program product, and a storage medium.

[0004] According to a first aspect of an embodiment of the present specification, a data query method is provided, the method comprising: obtaining a natural language query of a user and inputting it to a preset large language model, and determining a description text of a current query element required for generating a current query statement according to a recognition result of a query element contained in the natural language query by the large language model; obtaining a current vector corresponding to the description text of the current query element; determining a standard description of a matching query element and field information of the matching query element in a data table based on a preset knowledge base using a matching vector matching the current vector, wherein the preset knowledge base stores a preset standard description of a query element, one or more colloquial descriptions of the preset query element, vectors of the colloquial descriptions, and a corresponding relationship between the field information of the preset query element in the data table; generating a current query statement for data query according to the standard description of the matching query element and the field information of the matching query element in the data table.

[0005] According to a second aspect of an embodiment of the present specification, a computer device is provided, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method embodiment of the first aspect when executing the computer program.

[0006] According to a third aspect of an embodiment of the present specification, a computer-readable storage medium is provided, having a computer program stored thereon, the computer program being executed by a processor to implement the steps of the method embodiment of the first aspect.

[0007] According to a fourth aspect of the embodiments of the present specification, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the steps of the method embodiment of the first aspect described above.

[0008] The technical solutions provided by the embodiments of the present specification can include the following beneficial effects: In the embodiments of the present specification, the preset knowledge base stores the following: a standard description of a preset query element, one or more colloquial descriptions of the preset query element, a vector of the colloquial description, a correspondence between the field information of the preset query element in the data table, and a large language model is designed to identify the query element of the user's natural language query, determine the description text of the current query element required to generate the current query statement, and perform vector matching between the current vector corresponding to the description text of the current query element and the vector of the colloquial description of the knowledge base, thereby associating the standard description of the matching query element and the field information of the matching query element in the data table, and generating the current query statement for data query. Therefore, the present embodiment can solve the semantic error between "user colloquial expression" and "database professional query", accurately identify industry slang, abbreviations, and ambiguous expressions in the user's natural language query, avoid query failure caused by non-standard user expression, and significantly reduce the semantic understanding error of NL2SQL.

[0009] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present specification. BRIEF DESCRIPTION OF DRAWINGS

[0010] Figure 1A is a schematic diagram of a data query system according to an exemplary embodiment of the present specification.

[0011] Figure 1B is a flowchart of a data query method according to an exemplary embodiment of the present specification.

[0012] Figure 1C is a schematic diagram of a client page according to an exemplary embodiment of the present specification.

[0013] Figure 2A is a flowchart of another data query method according to an exemplary embodiment of the present specification.

[0014] Figure 2B is a schematic diagram of an interaction flow according to an exemplary embodiment of the present specification.

[0015] Figure 2C is a schematic diagram of a data query system according to an exemplary embodiment of the present specification.

[0016] Figure 3 is a flowchart of another data query method according to an example embodiment of the present specification.

[0017] Figure 4 is a hardware structure diagram of a computer device in which a data query apparatus according to an example embodiment of the present specification is located.

[0018] Figure 5 is a block diagram of a data query apparatus according to an example embodiment of the present specification.

[0019] Figure 6 is a block diagram of another data query apparatus according to an example embodiment of the present specification. DETAILED DESCRIPTION

[0020] The example embodiments will be described in detail herein with reference to the attached drawings. In the following description, the same numbers are used to indicate the same components in different drawings. The embodiments described in the following example embodiments are not representative of all embodiments consistent with the present specification. Rather, they are merely examples of devices and methods consistent with some aspects of the present specification, as detailed in the appended claims.

[0021] The terminology used in the present specification is for the purpose of describing particular embodiments only and is not intended to limit the present specification. As used in the present specification and the appended claims, the singular forms "a," "an," and "the" are intended to include plural forms as well, unless the context clearly indicates otherwise. It will also be understood that the term "and / or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.

[0022] It should be understood that although the terms first, second, third, etc. can be used herein to describe various information, these terms are not intended to denote a particular order. These terms are used only to distinguish one type of information from another. For example, without departing from the scope of the present specification, first information can also be referred to as second information, and similarly, second information can also be referred to as first information. Depending on the context, the word "if" as used herein can be interpreted as "when" or "upon" or "in response to determining."

[0023] The user information (including but not limited to user equipment information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the specification are information and data authorized by the user or authorized by all parties, and the collection, use and processing of related data need to comply with relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation portal for user to choose authorization or refusal.

[0024] The technical solutions of the application can be applied to transactions and distribution services of instant e-commerce platforms, such as Taobao flash shopping, Taofxian, Eleme takeout and retail, etc.

[0025] The rapid development of large language models (LLM), especially in natural language understanding and generation, has shown strong capabilities and provides new possibilities for realizing natural language-driven data queries. However, existing technical solutions for converting user-based natural language queries into structured query language (SQL) statements (Natural Language to SQL, NL2SQL) have problems such as low query accuracy, "big model illusion", and difficulty in accurately matching industry and enterprise internal professional terms, which limits user experience and data result accuracy. For example, colloquial expressions of users (such as "net G" and "direct meal") are difficult to accurately map to professional fields in data tables (such as "net_gmv" and "direct_food_sales").

[0026] Based on this, the embodiment of the specification provides a data query method, and a preset knowledge base is constructed in the embodiment to solve the mapping problem between natural language colloquial expressions and database structured fields through vector matching, thereby improving the convenience and accuracy of user queries. Next, the embodiment of the specification will be described in detail.

[0027] Figure 1A Fig. 1 is a schematic diagram of the architecture of a data query system provided by an exemplary embodiment. As shown in Figure 1A The system can include a server 11, a network 12, and a plurality of terminals, including but not limited to a personal computer (PC) 13, a mobile phone 14, etc.

[0028] The server 11 can be a physical server containing a standalone host, or the server 11 can be a virtual server carried by a host cluster. In the running process, the server 11 can run the server side program of an application to realize the related functions of the application, such as when the server 11 runs the program of the data query service, it can be realized as a corresponding data query server.

[0029] PC 13, mobile phone 14 are only part of the type of terminal that users can use. In fact, users can obviously also use terminals such as the following types: tablets, laptops, palmtop computers, wearable devices (such as smart glasses, smart watches, etc.), and the like, and one or more embodiments of the present specification do not limit this. During operation, the terminal can run a client-side program of an application to implement the related functions of the application, for example, the delivery capacity client of the present embodiment, for the application program installed on the terminal, or can be a small program, a fast application or other similar form. Of course, when using web technologies such as HTML5 or the like, the relevant functions can be implemented through a page displayed by a browser, and the browser here can be a standalone browser application or a browser module embedded in some application.

[0030] As for the network 12 between the terminal such as PC 13, mobile phone 14 and the server 11 for interaction, it can be based on the communication mode supported by the corresponding terminal to specifically select wired or wireless network to realize communication, and the present specification does not limit this. For example, PC 13 can support wired and wireless communication at the same time, so wired or wireless network can be used as needed to realize communication, while mobile phone 14 usually only supports wireless communication, so wireless network can be used to realize communication.

[0031] As shown in Figure 1B , Figure 1B is a flowchart of a dialogue method according to an exemplary embodiment of the present specification, comprising the following steps: In step 102, a natural language query of a user is obtained and input to a preset large language model, and according to the recognition result of a query element contained in the natural language query by the large language model, the description text of the current query element required to generate the current query sentence is determined; In step 104, the current vector corresponding to the description text of the current query element is obtained; In step 106, based on a preset knowledge base, a standard description of a matching query element and field information of the matching query element in a data table are determined by using a matching vector matched with the current vector; wherein the preset knowledge base stores: a preset standard description of a query element, one or more colloquial descriptions of the preset query element, vectors of the colloquial descriptions, and a corresponding relationship between the field information of the preset query element in the data table; In step 108, according to the standard description of the matching query element and the field information of the matching query element in the data table, a current query sentence is generated for data query.

[0032] As an example, the data query method of the present specification embodiment can be implemented byFigure 1A For example, the terminal can run a client to provide a user with a question input function, and the client can obtain the user's input; the question input function includes but is not limited to a voice input function, a text input function, a visual input function, etc.; one input of the user can include one or more of the voice, text, picture or video described above. Alternatively, the client can send the obtained user input to the server, and the server can execute the method of the present embodiment to generate SQL, query the data using the generated SQL, and return the data to the client to provide the user. Alternatively, in other scenarios, part of the data query method of the present embodiment can be executed on the client, and part of the data query method of the present embodiment can be executed on the server, which is not limited in the present embodiment.

[0033] As an example, the data query of the present embodiment can include a query operation (SELECT) for extracting data from a database, commonly known as "data taking".

[0034] In actual applications, it is difficult for the user's question to accurately match the professional terms (professional terms refer to indicators, dimensions and other information developed by technical research and development, which guarantee the characteristics of structure, certainty and uniqueness), resulting in the "invalidity" of some industry-recognized terms, abbreviations or slang (out-of-warehouse semantics), making it difficult to achieve accurate NL2SQL. The present embodiment pre-constructs a knowledge base, which stores a standard description of a preset query element, one or more colloquial descriptions of the preset query element, a vector of the colloquial description, and a corresponding relationship between the field information of the preset query element in a data table.

[0035] As an example, the colloquial description of each query element can be pre-collected and the above-mentioned corresponding relationship can be established; each query element can have one standard description, and the number of colloquial descriptions can be one or more. A vector generation model can be used to generate a corresponding vector for each colloquial description in advance; the way of generating a vector in step 104 can be consistent with the way of generating a vector for a colloquial description in advance. As an example, according to the need, a vector engine can be constructed for the vectors of the colloquial descriptions in the preset knowledge base to perform vector retrieval through the vector engine.

[0036] For example, taking the standard description of a certain indicator "net GMV" as an example, the colloquial description can include "net G", and the vector of "net G" can be generated in advance, and the knowledge entry of the indicator can be stored in the preset knowledge base: the standard description "net GMV", the colloquial description "net G", the vector of the colloquial description "net G", and the field information of the indicator in the data table.

[0037] As an example, the field information of the query element stored in the preset knowledge base in the data table includes but is not limited to: field name, data type of the field, table information (such as table name) of the data table where the field is located, and the like.

[0038] As an example, the query element of the embodiment includes but is not limited to: an index and a corresponding aggregation type, a dimension (including a dimension name and a dimension value), a filtering condition representing a dimension value required for filtering from a dimension in a data table, a time range, a same period comparison type, a custom comparison time period, a sorting field, a grouping dimension, and a quantity limit (such as limit), and the like. Among them: The index refers to a certain numerical value that a user wants to query, which corresponds to the target field of SELECT in SQL; in actual application, the index may need to be calculated by a certain calculation method (such as sales, the number of users, etc. which need to be obtained by summation). Optionally, the related information of the index can include an index name and an aggregation type; the index name refers to a business concept identifier, which is represented as a field name in SQL. The aggregation type is an index value calculation method, which is represented as an aggregation function in SQL, such as a summation function (SUM function), a mean function (AVG function), a function of returning the number of records satisfying a specified condition (such as a COUNT(DISTINCT) function), and the like.

[0039] The dimension refers to a field name in a data table, and the dimension value is a specific value of the dimension, which can be understood as a specific instance of the dimension, used to limit the analysis range; which can be used to generate a WHERE / HAVING clause of SQL, and the like; in actual application, the dimension value is not necessary in the natural language query of the user, and the dimension value can not be required when querying the overall value. The filtering condition refers to a condition for filtering the required dimension value from a certain dimension in the data table.

[0040] The time range refers to a time window of data, which can be a WHERE time filter of SQL, for example; it is a "time interval of data generation, which provides a time effectiveness constraint for the query. If there is no time range in the natural language query of the user, valid data cannot be located.

[0041] The same period comparison type (same period and period comparison) refers to a calculation method for comparison with a historical same period, which is a window function or a multi-table JOIN in SQL, representing a growth rate calculation rule of a period specified by the user and a reference period to be compared; for example, the query element can declare a calculation intention at the DSL layer to avoid errors of the LLM directly generating a complex SQL.

[0042] The custom comparison time period is an arbitrary comparison period specified by the user (a time comparison reference specified by the user), which is a subquery or a CTE expression of SQL.

[0043] Sort field, which is the basis for sorting the result set, is the ORDER BY clause in SQL, which can specify the order of the query results.

[0044] Grouping dimension, which is a high-level form of dimension (multi-level grouping), is the GROUP BY ROLLUP / CUBE in SQL, which can support multi-level aggregation of dimension combination.

[0045] Quantity limit, which is the upper limit of the number of returned result rows, is the LIMIT / TOP clause in SQL, which can control the data size of the query results.

[0046] Based on this, in the embodiment, the description text of the current query element required for generating the current query statement can be determined from the natural language query of the user; in the embodiment, the natural language query of the user can be obtained and input to a preset large language model, and the large language model is used to identify whether the natural language query of the user contains the description text of the query element. The large language model can output an identification result for the input natural language query. The identification result can indicate whether the natural language query of the user contains the query element, and in the case where it is determined that the query element is contained, the identification result can further contain information of the specific query element. In actual application, other information input to the large language model can be set as needed, such as a prompt word, which is not limited in the embodiment.

[0047] In some examples, the obtaining of the natural language query of the user and the inputting to the preset large language model comprises: recalling a similar historical case similar in semantics to the natural language query from a preset case library; inputting the similar historical case, knowledge in a preset knowledge manual, a preset structured query element template, and the natural language query to the preset large language model; The case library stores a plurality of historical query texts, and each historical query text has a corresponding historical structured query element. The preset knowledge manual contains a mapping relationship between the standard description and the colloquial description of the preset query element. The structured query element template defines each query element to be extracted.

[0048] As an example, in the process of extracting key information (description text of each query element) from the natural language query by the large language model, a plurality of prompt information are used.

[0049] As an example, a case library can be pre-constructed, the case library containing a plurality of historical query texts, each historical query text having a corresponding historical structured query element; in actual application, the similarity of the vector of the natural language query of the user with the vector of each historical query text in the case library can be used as a similarity judgment condition, and a similarity threshold can be set as needed.

[0050] For example, the natural language query of the user is: "What was the transaction volume in Shanghai yesterday?", which can be similar to the following two cases in the case library: "Yesterday, what was the transaction volume in Beijing?": "{ \"indicator\":[{ \"indicator name\": \"transaction volume\", \"aggregation type\": \"sum\"}], \"all dimensions\":[ \"city\" ], \"dimension values\":[ \"Shanghai\" ], \"filter conditions\":[ \"city = Beijing\" ], \"time period\":[ \"${Yesterday}\" ], \"comparison time period\":[ ], \"sorting fields\":[ ], \"grouping dimensions\":[ ], \"limit\": null}.".

[0051] "Yesterday, how many valid orders were there in Shanghai?": { \"indicator\":[{ \"indicator name\": \"valid order\", \"aggregation type\": \"sum\"}], \"all dimensions\":[ \"city\" ], \"dimension values\":[ \"Shanghai\" ], \"filter conditions\":[ \"city = Shanghai\" ], \"time period\":[ \"${Yesterday}\" ], \"comparison time period\":[ ], \"sorting fields\":[ ], \"grouping dimensions\":[ ], \"limit\": null}.".

[0052] In the above cases, "Yesterday, what was the transaction volume in Beijing?" is a historical query text, and the content after the colon is the corresponding historical structured query element.

[0053] As an example, the preset knowledge manual contains: a preset mapping relationship between the standard description and the colloquial description of the query element; for example, it can include: the colloquial description and the standard description of each indicator in the data table; the colloquial description and the standard description of each dimension in the data table; the colloquial description and the standard description of the dimension value under each dimension in the data table. According to the needs, the preset knowledge manual can also contain other information, which is not limited by the embodiment.

[0054] As an example, the knowledge contained in the knowledge manual of the embodiment can include: "Fixed terms: Direct dining: refers to direct sales and catering. Both "direct sales" and "catering" are dimension values. The dimension corresponding to "direct sales" is "direct agent," and the dimension corresponding to "catering" is "meal and snacks." ...... Dynamic knowledge base (indicators and dimensions that the user can query), including: Available indicators: Net GMV, number of valid orders, gross GMV, and average daily UE; Available dimensions and corresponding dimension values: Cities (Shanghai, Hangzhou, Beijing, Suzhou, Shenzhen...); Time period (breakfast, lunch, afternoon tea, dinner, supper); ......".

[0056] As an example, the structured query element template of this embodiment can be understood as a business intent description specification. By pre-defining field types and structures, the extraction scope and organization form of query elements can be constrained, thereby achieving reliable conversion from natural language to executable queries. As an example, the format of the structured query element template can be JSON, XML, etc., which is not limited in this embodiment. The historical structured query elements corresponding to the historical query text in the above embodiment are illustrated by taking JSON as an example.

[0057] Optionally, the structured query element template defines the query elements to be extracted, which can be set according to actual needs. For example, the query elements mentioned in the above embodiment can be defined. As an example, the structured query element template can declare the following query elements through predefined field types: Required elements: indicator information, time range; Optional elements: dimension category, dimension value, filtering conditions, time series comparison rules, result sorting rules, grouping rules, result quantity limit, etc.

[0058] As an example, a structured query feature template could be: "{\"Indicator\":[{\"Indicator Name\":\"???\",\"Aggregation Type\":\"???\"}],\"All Dimensions\":[\"???\"],\"Dimension Value\":[\"???\"],\"Filter Condition\":[\"???\"],\"Time Period\":[\"???\"],\"Comparison Time Period\":[???],\"Sort Field\":[???],\"Grouping Dimension\":[???],\"Limit\": ???}".

[0059] Wherein, the "???" character refers to the description text to be extracted; during extraction, the corresponding description text can be extracted from the natural language query of the user according to the above template and filled in; wherein, if the optional query element is not extracted, it can be left blank.

[0060] It can be understood that the template is essentially a container of structured query elements, which defines the following three types of elements to be extracted through predefined fields: ① Target definition element (indicator / aggregation type), which can determine what to select in SQL; ② Constraint element (dimension value / filter condition / time range), which can determine the WHERE condition in SQL; ③ Control element (sorting / grouping / limit), which can determine how to organize the query results in SQL.

[0061] As an example, the JSON fields contained in the structured query element template have the following functions:

[0062] As can be seen from the above embodiment, the retrieval augmented generation (RAG) technology is adopted, cases similar to the user query intention this time can be retrieved from the existing case library, and through cumulative learning, the precision extraction capability for diversified user intentions is improved.

[0063] Optionally, in actual application, the large language model can be obtained through fine-tuning or the like. For example, in fine-tuning, the training sample of the model is a natural language query sample, and the label of the sample can be a structured query element corresponding to the natural language query sample, for example, the above two cases can be used as a sample and a label, such as "Yesterday, how much was the transaction volume in Beijing?" as a natural language query sample, and the corresponding historical structured query element is the label. The difference between the structured query element recognized by the large language model for the input natural language query sample and the structured query element corresponding to the sample can be obtained, and the model is trained (i.e., the model parameter is updated) with the minimum difference as the optimization goal; wherein the structured query element has multiple, the above difference can be the difference between each item of the structured query element output by the large language model and each item of the structured query element corresponding to the sample, such as the difference between the "index name" in the structured query element output by the large language model and the "index name" in the structured query element corresponding to the sample. Similarly, the difference of the aggregation type and the difference of the dimension can also be obtained. Specifically, the difference can be represented by the similarity between the vector of the structured query element output by the large language model and the vector of the structured query element corresponding to the sample; the optimization goal can be the weighted average of each item of the structured query element, and the weight of each item of the structured query element can be the same or can be set according to the need, which is not limited in the embodiment.

[0064] Optionally, considering that there are multiple structured query elements, as indicated by the structured query element template described above, the structured query elements corresponding to different natural language query samples can be different; for example, some natural language query samples only contain indicators and time ranges, and do not contain other structured query elements, and some natural language query samples contain more or all structured query elements. For the training process, multiple batches of training samples are designed as needed, and different batches of training samples correspond to different structured query elements in the labels. The training samples of each batch can be used in turn according to the increasing order of the number of structured query elements contained in the labels corresponding to the samples. For example, the labels corresponding to the first batch of training samples contain the first category of structured query elements (such as indicators and time periods / time ranges, etc.), the labels corresponding to the second batch of training samples contain the second category of structured query elements in addition to the first category of structured query elements, the labels corresponding to the third batch of training samples contain the first category, the second category and the third category of structured query elements, and so on. Among them, the batch containing important structured query elements (such as indicators and time ranges) is ranked higher than the batch containing other structured query elements. In this way, the extraction accuracy of the large language model for important structured query elements can be prioritized, and the extraction accuracy of the large language model for other structured query elements can be gradually improved by gradually increasing other structured query elements. The important structured query elements are included in each batch of training samples, so that the large language model can continuously ensure the recognition accuracy of important structured query elements.

[0065] At the same time, considering that dimensions and dimension values have strong scene dependence, the embodiment organizes them into a knowledge manual for the large model to refer to, further improving the extraction accuracy of key information such as "indicators" and "dimensions".

[0066] As an example, for the obtained description text of the current query element, a vector can be generated, which is referred to as a current vector in the embodiment. The matching vector in the preset knowledge base that matches the current vector can be determined, and after the matching vector is determined, based on the corresponding relationship stored in the preset knowledge base, the standard description of the query element corresponding to the matching vector and the field information in the data table can be determined, and then the current query statement corresponding to the natural language query of the user can be generated to perform data query.

[0067] As an example, the way to determine whether the vectors match can be set according to actual needs, for example, the similarity between the vectors can be calculated to determine, and the embodiment does not limit this.

[0068] As an example, the query elements include at least an index and a time range; the determination of the description text of the current query element required for generating the current query statement can include: determining whether the index description text representing the index to be queried and the time description text representing the time range to be queried can be obtained from the natural language query; if the index description text is not included, outputting prompt information prompting the user to supplement the index to be queried to obtain the index description text of the index to be queried; if the time description text is not included, outputting prompt information prompting the user to supplement the time range to be queried to obtain the time description text of the time range to be queried; taking the obtained index description text and time description text as the description text of the current query element.

[0069] In view of the requirements of the data retrieval scene, the embodiment designs integrity verification of key information in the natural language query. Specifically, the embodiment designs judgment of whether the index description text representing the index to be queried and the time description text representing the time range to be queried can be obtained from the natural language query. If any of them cannot be obtained, corresponding prompt information is outputted, for example: In the case where the index description text is not included, prompt information prompting the user to supplement the index to be queried can be outputted. The specific prompt information can be configured according to actual needs. For example, the prompt information can specifically be “no index to be queried is detected. Please supplement” and the like. The embodiment does not limit this. In this way, the user can input information representing the index to be queried (if any) under the prompt, and obtain the index description text of the index to be queried from the new input of the user.

[0070] In the case where the time description text is not included, prompt information prompting the user to supplement the time range to be queried can be outputted. The specific prompt information can be configured according to actual needs. For example, the prompt information can specifically be “no time range to be queried is detected. Please supplement” and the like. The embodiment does not limit this. In this way, the user can input information representing the time range to be queried (if any) under the prompt, and obtain the time description text of the time range to be queried from the new input of the user.

[0071] In actual application, in the case where the index description text and the time description text are not detected, a prompt information can be outputted. The prompt information can prompt the user to supplement the index to be queried and also can prompt the user to supplement the time range to be queried.

[0072] In some examples, the query elements further include a dimension; the determination of the description text of the current query element required for generating the current query statement further includes: Determine whether a dimension description text representing the current query dimension can be obtained from the natural language query, and if so, use the obtained dimension description text as the description text of the current query element; If not, when it is determined that dimension information is involved in the natural language query, prompt information is output to prompt the user to supplement the current query dimension, so as to obtain the dimension description text of the current query dimension and use it as the description text of the current query element.

[0073] In this embodiment, if the query does not involve dimension information (e.g., a query only for "total sales"), dimension description text is not required and can be skipped. If the natural language query explicitly involves dimension information (e.g., "region" in "sales by region"), dimension description text must be extracted. If no clear dimension information is obtained (e.g., a user asks "find sales by region" but does not specify which region "region" refers to), the user can be prompted to provide additional dimension information details. In this way, this embodiment can obtain semantically clear dimension description text.

[0074] In some examples, using the matching vector that matches the current vector to determine the standard description of the matching query element and the field information of the matching query element in the data table may include: Recalling a set of candidate vectors similar to the current vector based on the vectors stored in the preset knowledge base; Determining whether there is a candidate vector in the candidate vector set whose similarity to the current vector is higher than a preset threshold; If so, the determined candidate vector is used as the matching vector, and the standard description of the matching query element corresponding to the matching vector and the field information of the matching query element in the data table are determined.

[0075] To ensure the accuracy of data queries, this embodiment can recall a set of candidate vectors similar to the current vector based on the vectors stored in the knowledge base. The candidate vector set can include one or more candidate vectors. In practical applications, such as implementations using a vector engine, when recalling candidate vectors, the similarity between the candidate vector and the current vector can be obtained. This embodiment can set a threshold as needed, which is used to indicate that the candidate vector has a high similarity to the current vector. Therefore, for candidate vectors whose similarity to the current vector exceeds the preset threshold, it indicates clear semantics. This embodiment can determine them as matching vectors that match the current vector, determine the standard description of the matching query element corresponding to the matching vector, and determine the field information of the matching query element in the data table.

[0076] In the case where there is no candidate vector in the candidate vector set whose similarity with the current vector is higher than a preset threshold, that is, the semantics are unclear, a specific processing method can be set as needed in actual applications, and this embodiment does not limit this.

[0077] In practical applications, query elements can be of various categories, such as indicators and dimensions. This embodiment also allows for categorical recall. Vector libraries for query elements of different categories are set up. For example, for the indicator description text representing the current query indicator in a natural language query, the corresponding candidate vector set is recalled from the indicator vector library (which stores vectors of colloquial descriptions of each indicator). For the dimension description text representing the current query dimension in a natural language query, the corresponding candidate vector set is recalled from the dimension vector library (which stores vectors of colloquial descriptions of each dimension). Optionally, after extracting the indicator description text and the dimension description text, the above two recall steps can be performed in parallel to improve processing efficiency.

[0078] In some examples, determining the standard description of the matching query element and the field information of the matching query element in the data table using the matching vector that matches the current vector may also include: If there is no vector in the candidate vector set with a similarity higher than a preset threshold, obtaining a standard description corresponding to each candidate vector in the candidate vector set using the preset knowledge base; Output prompt information to prompt the user to select a standard description from the standard descriptions corresponding to the candidate vectors, use the standard description selected by the user as the standard description of the matching query element, and determine the corresponding field information of the matching query element in the data table.

[0079] As an example, Figure 1C , which is a schematic diagram of a client page according to an exemplary embodiment of the present specification; in this embodiment, the user's natural language query takes "GMV of Hangzhou last week" as an example, and the query elements (i.e., key information) obtained by extracting key information from the natural language query are as follows: Figure 1C As shown in , taking JSON format as an example, it can include the following: {"Indicator":[{"Indicator Name":"GMV","Aggregation Type":"Sum"],"All Dimensions":["City"],"Dimension Value":["Hangzhou"],"Filter Condition":["City=Hangzhou"],"Time Period":["20250711","20250717"],"YoY / YoY Type":[],"Custom Comparison Time Period":[],"Sort Field":[],"Grouping Dimension":[],"Limit":null}.

[0080] The description text of each query element extracted above can be as followsFigure 1C The page shown in the client is displayed to the user for the user to review the extraction result.

[0081] According to the extracted information, the embodiment can recall through the preset knowledge base; for example, recall the index name "GMV", recall the dimension name "city", and recall the dimension value "Hangzhou". According to the recall result, it can be determined that the standard description of the query element dimension is: dimension value "Hangzhou City" and dimension "city". However, the colloquial description of the index "GMV" is difficult to recall a reliable standard description, and the three candidate index standard descriptions "net GMV", "gross GMV", and "gross profit" recalled can be displayed in the client page. The prompt information is as follows: Figure 1C As shown in the middle, the prompt information can be "No GMV-related index is recalled. Please select the index you want to query", and the three candidate index standard descriptions recalled are also displayed through the drop-down box for the user to select.

[0082] Optionally, after the user selects, the standard description selected by the user can be obtained as the standard description of the matching query element. For example, if the user selects "net GMV", it can be used as the standard description of the index. Optionally, the extracted key information can also be updated, for example, the index "index name: GMV" in the JSON format key information described above is updated to "index name: net GMV", and the DSL can be generated according to the updated key information in the future.

[0083] In addition to the index, the foregoing dimension information can also use the manner of the embodiment; for example, if the vector of the dimension description text (including the description text of the dimension name and / or the description text of the dimension value) is difficult to recall a vector with a similarity higher than a preset threshold, the user can also be prompted to select according to the standard description corresponding to each candidate vector recalled.

[0084] Therefore, by introducing the clarification interaction mechanism described above, the embodiment can ensure that the user's intention is clear, and significantly reduce the query error and user understanding cost.

[0085] In some examples, the method can further include: In the case where the preset knowledge base does not store the description text of the current query element, storing and associating the description text of the current query element and the standard description selected by the user to update the preset knowledge base.

[0086] As an example, assuming that the indicator description text extracted from the natural language query of the user is "net G", the standard descriptions of the indicators of the two candidates recalled are "net GMV" and "gross GMV", and the user selects "net GMV" after the prompt information is displayed in the client page; since the colloquial description of "net G" is not stored in the preset knowledge base, the colloquial description of "net G" can be associated and stored with the standard description "net GMV", and the preset knowledge base can be updated subsequently, so that the standard description "net GMV" in the knowledge base can increase the corresponding colloquial description "net G", and when "net G" is included in a subsequent natural language query, the standard description "net GMV" can be recalled without interrupting the user to clarify, thereby improving the data query efficiency.

[0087] As can be seen, in the embodiment, the data cleaning and processing of user behavior tracking can continuously update the out-of-warehouse semantics and optimize the accuracy of vector calculation, achieving the effect that the knowledge base becomes more and more accurate with use.

[0088] In some examples, the generating the current query statement for data query can include: After the structured domain-specific language is generated, a structured query language statement SQL is generated using the structured domain-specific language, so as to perform data query using the structured query language statement.

[0089] In the embodiment, by introducing "structured domain-specific language (DSL)" as an intermediate layer, the generation process from natural language to SQL is optimized, which can reduce the difficulty of generating complex queries and improve the accuracy of SQL.

[0090] As an example, the query intent can be declared in a structured format based on the standard description of the matched query element in step 108 and the field information of the matched query element in the data table; for example, the structured query element template described above can be used. The above DSL can be converted into executable SQL through predefined DSL-to-SQL mapping rules (such as template engine, syntax parser). Among them, the DSL rule is independent of the SQL syntax, when the database table structure changes (such as field name modification) or the business indicator definition is updated, only the mapping rule of DSL-to-SQL needs to be adjusted, without modifying the upstream natural language understanding module.

[0091] The "two-step data retrieval" scheme of the semantic intermediate layer is introduced in the embodiment, which significantly improves the complex query capability. By introducing this semantic intermediate layer (standard semantics), the understanding and expression ability of the system for complex query intent is effectively improved, and the accuracy, stability and scalability of the query are significantly enhanced, overcoming the limitations of NL2SQL scheme in business variability and semantic parsing.

[0092] As can be seen from the above embodiments, the embodiments design the preset knowledge base to store: a standard description of a preset query element, one or more colloquial descriptions of the preset query element, a vector of the colloquial description, a correspondence between field information of the preset query element in a data table, and determine the description text of the current query element required for generating the current query statement according to the natural language query of the user, and perform vector matching between the current vector corresponding to the description text of the current query element and the vector of the colloquial description of the knowledge base, thereby associating the standard description of the matching query element and the field information of the matching query element in the data table, generating the current query statement for data query. Therefore, the embodiments can solve the semantic error between "user colloquial expression" and "database professional query", realize accurate identification of industry slang, abbreviation and ambiguous expression in the natural language query of the user, avoid query failure caused by non-standard user expression, and significantly reduce the semantic understanding error of NL2SQL.

[0093] As Figure 2A shown is another data query flowchart according to an exemplary embodiment of the present specification, the data query flow in the embodiments can include: If the natural language query input by the user is obtained, the key semantic information can be extracted; specifically, the index description text representing the current query index, the time description text representing the current query time range, and the dimension description text representing the current query dimension can be extracted from the natural language query.

[0094] Then, the completeness of the key information can be verified according to the extraction result, that is, whether the key information is complete is determined; specifically, whether the index description text representing the current query index, the time description text representing the current query time range, and the dimension description text representing the current query dimension in the natural language query are extracted.

[0095] If the key information is not complete, the embodiments design a breaking node to prompt the user to complete the information; specifically, if the index description text is not obtained, prompt information is output to prompt the user to supplement the current query index to obtain the index description text of the current query index; if the time description text is not obtained, prompt information is output to prompt the user to supplement the current query time range to obtain the time description text of the current query time range; in the case where it is determined that the dimension information in the natural language query is involved, prompt information is output to prompt the user to supplement the current query dimension. If it is determined that the user terminates the flow, the processing can be ended.

[0096] After the prompt information is output, the step of "extracting key semantic information" and the judgment step of "whether the key information is complete" can be performed again according to the natural language query input by the user again.

[0097] If the key information is complete, the step of recalling the standard semantics from the out-of-warehouse semantics can be performed; specifically, the current vector corresponding to the description text of the current query element can be obtained, and a set of candidate vectors similar to the current vector can be recalled.

[0098] Then, it can be determined whether the recall semantics are clear; for example, it can be determined whether there is a candidate vector in the candidate vector set whose similarity with the current vector is higher than a preset threshold.

[0099] If the recall semantics are determined to be unclear, for example, if there is no candidate vector in the candidate vector set whose similarity with the current vector exceeds a preset threshold, this embodiment designs an interrupt node to prompt the user to clarify. For example, a drop-down selection box can be provided on the front-end interaction, and the user can clarify by selecting it. In addition, the standard semantics can be directly hit based on the user's selection, avoiding the repetition of multiple steps such as extraction and recall.

[0100] If the recall semantics are clear, the steps of the standard semantic assembly query DSL (NL2DSL) can be executed. For example, using the matching vector that matches the current vector, the standard description of the matching query element and the field information of the matching query element in the data table are determined, and the DSL is generated based on the standard semantics.

[0101] Then, the standard DSL data retrieval (DSL2SQL) steps may be performed, for example, SQL may be generated based on the generated DSL, and the SQL may be executed to query the data required by the user from the database.

[0102] Finally, result visualization processing can be performed, for example, the query results are displayed in the client for user review.

[0103] like Figure 2B FIG. 1 is a schematic diagram of an interaction process according to an exemplary embodiment of the present specification. Figure 2B It is shown that the natural language query input by the user is "Hangzhou GMV last week", and steps such as key semantic extraction (such as extracting query elements such as indicators, dimensions, time range, and filtering conditions) can be performed; if the semantics are incomplete, the aforementioned step of prompting the user for information to be supplemented can be performed; if it is complete, the step of recalling standard semantics from off-warehouse semantics can be performed; if the semantics are ambiguous, multiple rounds of clarification can be performed, and ambiguous semantics can be filtered through a drop-down box; for details, please refer to the description of the aforementioned embodiment.

[0104] In the example of this embodiment where the natural language query is "last week's GMV in Hangzhou", the key information extracted may be the following information as shown in 2B: Indicator: Transaction volume Dimension: City Time range: 20250602-20250608 Filter condition: city = Hangzhou After performing the step of retrieving the standard semantics according to the above information, the obtained standard semantics are as follows: Indicator: net GMV Dimension: city Time range: 20250602-20250608 Filter condition: city = Hangzhou Then, according to the above-mentioned standard semantics, the data query DSL (NL2DSL) can be assembled, and the generated DSL is shown in the following table:

[0105] The above DSL contains the following functions: Field selection: The select part specifies to extract the "net GMV" field in the data table.

[0106] Filter condition: The filter part combines the conditions by logical "and": filter the "city" field value "in" (contains) ["Hangzhou City"].

[0107] Time range: The ds part limits the data time range to 2025-06-02 to 2025-06-08 (format: YYYYMMDD).

[0108] According to the above DSL, the DSL2SQL and data query steps can be performed using the preset standard semantic data retrieval tool.

[0109] As an example, the analysis result of the natural language query "Hangzhou transaction volume last week" can be displayed in the page of the client, for example, as shown in the following table:

[0110] Finally, by executing the above SQL, the query result can be obtained, and the step of displaying the queried net GMV in the page of the client can be performed.

[0111] As Figure 2C shown in the schematic diagram of the data query system according to an exemplary embodiment of the present specification, the method of the present embodiment can be implemented as a data query intelligent agent Data Search Agent, Figure 2CAn intelligent data analysis framework based on a Data Search Agent is constructed in the data query system, and end-to-end Agent integration and business self-orchestration can be realized. The Agent can include a knowledge base, a large language model, a tool set, and a memory module. The knowledge base can include extraction specifications for prompting the large language model to extract query elements from a user's natural language query, colloquial semantics containing a colloquial description of the query elements, standard semantics containing a standard description of the query elements, index caliber containing various indexes, etc. Efficient retrieval can be supported by combining multi-dimensional semantics and retrieval-enhanced RAG technology. The process generated by the DSL and the process of standard semantic data retrieval can be integrated into a tool for Agent autonomous calling. The memory module can include a short-term memory module and a long-term memory module. The short-term memory module can be implemented through a graph state, which is a snapshot of "entity-relation-context" temporarily saved by the Agent when solving the current task in a graph structure. The long-term memory module can be processed through the aforementioned burying point and recording. User behavior burying points such as result adoption rate, multi-round clarification results, question and query memory relationship, etc. can be obtained through data cleaning, and vector storage can be further updated. Therefore, the continuity of the context and the history tracking can be ensured.

[0112] The system of the embodiment provides an atomized service interface, facilitating the rapid construction and iteration of business Agents. The user behavior burying point and data cleaning module collects multi-round interaction data, updates the vector library, and continuously optimizes the knowledge representation. The underlying supports multiple models, multiple data sources, and semantic management, ensuring the flexibility and scalability of semantic understanding and data access. The log and monitoring system realizes real-time monitoring and fault diagnosis, ensuring stable and efficient operation of the system.

[0113] As can be seen from the above embodiment, the embodiment innovatively splits the term into two parts, colloquial semantics and standard semantics, and introduces a vector engine to calculate the similarity between the two kinds of semantics. On the basis of ensuring the semantic professionalism of the data production scene, the user is provided with a friendly business term interaction, and the extraction accuracy of key semantics is further improved.

[0114] The embodiment splits NL2SQL into NL2DSL+DSL2SQL two-step data retrieval. By introducing this scheme, the understanding and expression ability of the system for complex query intentions is effectively improved, the accuracy, stability, and scalability of the query are significantly enhanced, and the limitations of the NL2SQL scheme in business variability and semantic analysis are overcome.

[0115] As shown in Figure 3 FIG. 1 is a flowchart of a data query method according to an example embodiment of the present specification, which can include the following steps: In step 302, after obtaining the natural language query of the user, the query result is obtained based on the steps of the foregoing data query method embodiments.

[0116] In step 304, the query result is displayed in the client.

[0117] As an example, the embodiment can be applied to a client, which can run on a terminal as shown. Figure 1A After obtaining the natural language query of the user, the client can send the natural language query to the server, and the server executes the foregoing method embodiments and the like to obtain the query result and return it to the client, which displays the query result. The specific acquisition method of the query result can refer to the description of the foregoing embodiments, and will not be described here. Figure 1B

[0118] Corresponding to the foregoing data query method embodiments, the present specification also provides data query apparatuses and computer devices to which the data query apparatuses are applied.

[0119] The embodiment of the data query apparatus of the present specification can be applied to a computer device, such as a server or a terminal device. The apparatus embodiment can be implemented by software, or by hardware or a combination of software and hardware. Taking the software implementation as an example, as a logically meaningful apparatus, it is formed by the processor of the computer device reading the corresponding computer program instructions in the non-volatile memory into the memory for execution. From the hardware level, as shown in the figure, it is a hardware structure diagram of the computer device to which the data query apparatus of the present specification is applied. In addition to the processor, network interface, memory, and non-volatile memory shown in the figure, the computer device to which the data query apparatus of the embodiment is applied usually includes other hardware according to the actual function of the computer device, which will not be described here. Figure 4 Figure 4

[0120] As shown in the figure, Figure 5 Figure 5 is a block diagram of a data query apparatus according to an exemplary embodiment of the present specification, which includes: The first determination module is configured to obtain a natural language query of a user and input it to a preset large language model, and determine the description text of the current query element required for generating the current query statement according to the recognition result of the query element contained in the natural language query in the large language model. The acquisition module is configured to acquire the current vector corresponding to the description text of the current query element. ​​​​The second determining module is configured to determine the standard description of the matching query element and field information of the matching query element in a data table based on a preset knowledge base and using a matching vector matched with the current vector, wherein the preset knowledge base stores a preset standard description of a query element, one or more colloquial descriptions of the preset query element, vectors of the colloquial descriptions, and a corresponding relationship between the field information of the preset query element in a data table and the vectors of the colloquial descriptions. The query module is configured to generate a current query statement for data query according to the standard description of the matching query element and the field information of the matching query element in a data table.

[0121] In some examples, the query element includes at least an index and a time range, and the first determining module determines the description text of the current query element required for generating the current query statement, including: determining whether an index description text representing a current query index and a time description text representing a current query time range can be obtained from the natural language query; if the index description text is not obtained, outputting prompt information prompting a user to supplement the current query index to obtain the index description text of the current query index; if the time description text is not obtained, outputting prompt information prompting the user to supplement the current query time range to obtain the time description text of the current query time range; obtaining the index description text and the time description text as the description text of the current query element.

[0122] In some examples, the query element further includes a dimension, and the first determining module determines the description text of the current query element required for generating the current query statement, further including: determining whether a dimension description text representing a current query dimension can be obtained from the natural language query, and if yes, obtaining the dimension description text as the description text of the current query element; if no, in a case where it is determined that the natural language query involves dimension information, outputting prompt information prompting the user to supplement the current query dimension to obtain the dimension description text of the current query dimension as the description text of the current query element.

[0123] In some examples, the second determining module determines the standard description of the matching query element and the field information of the matching query element in a data table using a matching vector matched with the current vector, including: recalling a candidate vector set similar to the current vector according to vectors stored in the preset knowledge base; determining whether there is a candidate vector in the candidate vector set that has a similarity higher than a preset threshold with the current vector; If yes, the determined candidate vector is taken as the matching vector, and a standard description of the matching query element corresponding to the matching vector and field information of the matching query element in the data table are determined.

[0124] In some examples, the second determining module determines the standard description of the matching query element and the field information of the matching query element in the data table by using the matching vector matched with the current vector, and further includes: If there is no candidate vector in the candidate vector set that has a similarity higher than a preset threshold, the standard description corresponding to each candidate vector in the candidate vector set is obtained by using the preset knowledge base; prompt information is outputted to prompt the user to select a standard description from the standard descriptions corresponding to the candidate vectors, so that the selected standard description is taken as the standard description of the matching query element, and the field information of the corresponding matching query element in the data table is determined.

[0125] In some examples, the apparatus further includes an updating module configured to: In a case where the preset knowledge base does not store the description text of the current query element, the description text of the current query element and the selected standard description are stored and associated to update the preset knowledge base.

[0126] In some examples, the query module generates a current query statement for data query, and includes: After the structured domain-specific language is generated, a structured query statement is generated by using the structured domain-specific language, so that the structured query statement is used for data query.

[0127] In some examples, the first determining module obtains a natural language query of a user and inputs the natural language query to a preset large language model, and includes: similar historical query texts semantically similar to the natural language query are recalled from a preset case base; the similar historical query texts, knowledge in a preset knowledge manual, a preset structured query element template and the natural language query are inputted to a preset large language model; The case base stores a plurality of historical query texts, and each historical query text has a corresponding historical structured query element. The preset knowledge manual includes a mapping relationship between a standard description and a colloquial description of a preset query element. The structured query element template defines each query element to be extracted.

[0128] As Figure 6 shown, Figure 6 is a block diagram of another data query device according to an exemplary embodiment of the present specification, and the device comprises: The acquisition module is configured to, after obtaining the natural language query of the user, obtain the query result based on the steps of the foregoing data query method embodiments. The display module is configured to display the query result in the client.

[0129] The implementation process of the functions and roles of each module in the data query device is specifically described in the implementation process of the corresponding steps in the foregoing data query method, and will not be repeated here.

[0130] Correspondingly, the present specification also provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the foregoing data query method embodiments.

[0131] Correspondingly, the present specification also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the data query method embodiments when executing the program.

[0132] Correspondingly, the present specification also provides a computer-readable storage medium, which stores a computer program, and the computer program, when executed by a processor, implements the steps of the data query method embodiments.

[0133] For the device embodiments, since they basically correspond to the method embodiments, the related parts are described with reference to the parts of the method embodiments. The device embodiments described above are merely illustrative, wherein the modules described as separate components can or can not be physically separated, and the components displayed as modules can or can not be physical modules, i.e., they can be located in one place or distributed on multiple network modules. According to actual needs, some or all of the modules can be selected to achieve the purpose of the present specification. Those skilled in the art can understand and implement without creative labor.

[0134] The above embodiments can be applied to one or more computer devices, which are devices capable of automatically performing numerical calculation and / or information processing according to pre-set or stored instructions. The hardware of the computer devices includes, but is not limited to, microprocessors, Application Specific Integrated Circuits (ASICs), Field-Programmable Gate Arrays (FPGAs), Digital Signal Processors (DSPs), embedded devices, and the like.

[0135] The computer devices can be any electronic product capable of human-computer interaction with users, such as personal computers, tablet computers, smart phones, Personal Digital Assistants (PDAs), game consoles, Interactive Internet Protocol Televisions (IPTVs), smart wearable devices, and the like.

[0136] The computer devices can also include network devices and / or user devices. The network devices include, but are not limited to, single network servers, server groups composed of multiple network servers, or clouds composed of a large number of hosts or network servers based on Cloud Computing.

[0137] The network in which the computer devices are located includes, but is not limited to, the Internet, a wide area network, a metropolitan area network, a local area network, a Virtual Private Network (VPN), and the like.

[0138] The above describes specific embodiments of the present specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in a different order than the order in which they are recited in the embodiments and still achieve desirable results. In addition, the processes depicted in the accompanying drawings do not necessarily require the particular order shown or sequential order to achieve the desired results. In certain implementations, multitasking and parallel processing are also permissible or advantageous.

[0139] The division of steps in the above methods is only for the purpose of clear description. When implemented, a step can be combined into one or some steps can be split into multiple steps, as long as the same logical relationship is included, which is within the protection scope of the present patent; adding insignificant modifications or introducing insignificant designs in the algorithm or process, but not changing the core design of the algorithm and process, are within the protection scope of the present application.

[0140] While this specification contains many specifics, these should not be construed as limitations on the scope of any invention, but merely as descriptions of particular implementations of certain embodiments. Certain features described in this specification in the context of separate embodiments can also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment can also be implemented separately or in any suitable subcombination. Moreover, although features can be described above as acting in certain combinations and even initially claimed as such, one or more features from a claimed combination can in some cases be excised from the combination and the claimed combination can be directed to a subcombination or variation of a subcombination.

[0141] described in connection with the described embodiments or examples. Moreover, the illustrative language recited herein does not preclude the use of other variants or alternatives unless expressly indicated to do so. The term "comprising," used in the description and in the following claims, is not to be construed as a limitation on any feature described herein. Rather, the term "comprising" is intended to be a broad term that encompasses the presence of that feature, but does not preclude the presence or addition of one or more other features, whether or not such other features are specifically disclosed herein. Additionally, where the description indicates that devices or apparatuses, or portions thereof, are "configured" to perform certain operations, such configuration can be accomplished, for example, by designing the devices or apparatuses, or portions thereof, to perform the

[0142] Other embodiments of this specification are possible. The scope of the specification is intended to cover any variation, use, or adaptation of the specification following, in general, the principles of the specification and including such departures from the present disclosure as come within known or customary practice in the art to which the specification pertains or the like. The specification is intended to cover at least those options, modifications, and equivalents falling within the scope of the specification. The specification and examples, while indicating certain embodiments of the specification, are to be construed as merely illustrative of preferred methods of practicing the specification and not limiting of the scope of the specification as defined by the claims.

[0143] It is to be understood that the specification is not limited to the precise construction described in the specification and as shown in the attached figures, and that changes in the precise construction can be made without departing from the scope of the specification. The scope of the specification is limited only by the claims appended hereto.

[0144] The above description is intended to be illustrative and not restrictive. Many other modifications within the scope of the specification will be apparent to those of skill in the art upon reviewing the above description. The scope of the specification should, therefore, be determined not with reference to the above description, but instead with reference to the appended claims.

Claims

1. A data query method based on a large language model, the method comprising: Obtaining a user's natural language query and inputting it into a preset large language model, and determining, based on the large language model's recognition results of query elements contained in the natural language query, a description text of the current query element required to generate the current query statement; Obtaining a current vector corresponding to the description text of the current query element; Based on a preset knowledge base, using a matching vector that matches the current vector, a standard description of a matching query element and field information of the matching query element in a data table are determined; wherein the preset knowledge base stores: a correspondence between the standard description of a preset query element, one or more colloquial descriptions of the preset query element, vectors of the colloquial descriptions, and field information of the preset query element in the data table; According to the standard description of the matching query element and the field information of the matching query element in the data table, a current query statement is generated to perform data query.

2. The method according to claim 1, wherein the query elements include at least an indicator and a time range; and the step of determining the description text of the current query elements required to generate the current query statement comprises: Determining whether an indicator description text representing the current query indicator and a time description text representing the current query time range can be obtained from the natural language query; If the indicator description text is not obtained, output prompt information to prompt the user to supplement the current query indicator to obtain the indicator description text of the current query indicator; If the time description text is not obtained, output prompt information to prompt the user to supplement the current query time range to obtain the time description text of the current query time range; The obtained indicator description text and time description text are used as the description text of the current query element.

3. The method according to claim 2, wherein the query element further comprises a dimension; and the determining of the description text of the current query element required to generate the current query statement further comprises: Determine whether a dimension description text representing the current query dimension can be obtained from the natural language query, and if so, use the obtained dimension description text as the description text of the current query element; If not, when it is determined that dimension information is involved in the natural language query, prompt information is output to prompt the user to supplement the current query dimension, so as to obtain the dimension description text of the current query dimension and use it as the description text of the current query element.

4. The method according to claim 1, wherein the determining, using a matching vector that matches the current vector, a standard description of a matching query element and field information of the matching query element in a data table comprises: Recalling a set of candidate vectors similar to the current vector based on the vectors stored in the preset knowledge base; Determining whether there is a candidate vector in the candidate vector set whose similarity to the current vector is higher than a preset threshold; If so, the determined candidate vector is used as the matching vector, and the standard description of the matching query element corresponding to the matching vector and the field information of the matching query element in the data table are determined.

5. The method according to claim 4, wherein the determining the standard description of the matching query element and the field information of the matching query element in the data table by using the matching vector that matches the current vector further comprises: If there is no candidate vector in the candidate vector set whose similarity is higher than the preset threshold, obtaining a standard description corresponding to each candidate vector in the candidate vector set by using the preset knowledge base; Output prompt information to prompt the user to select a standard description from the standard descriptions corresponding to the candidate vectors, so as to use the standard description selected by the user as the standard description of the matching query element, and determine the corresponding field information of the matching query element in the data table.

6. The method according to claim 5, further comprising: In the case that the preset knowledge base does not store the description text of the current query element, the description text of the current query element and the standard description selected by the user are stored and associated to update the preset knowledge base.

7. The method according to claim 1, wherein generating a current query statement for performing a data query comprises: After the structured domain-specific language is generated, a structured query statement is generated using the structured domain-specific language, and data query is performed using the structured query statement.

8. The method according to claim 1, wherein obtaining the user's natural language query and inputting it into a preset large language model comprises: Recalling similar historical query texts that are semantically similar to the natural language query from a preset case library; Inputting the similar historical query text, the knowledge in the preset knowledge manual, the preset structured query element template and the natural language query into a preset large language model; The case library stores a plurality of historical query texts, each of which has a corresponding historical structured query element; The preset knowledge manual includes: a mapping relationship between a preset standard description of a query element and a colloquial description; The structured query element template defines various query elements to be extracted.

9. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.

10. A computer program product comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the steps of the method according to any one of claims 1 to 8.

11. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Application method and system of NER entity recognition algorithm in report query

    CN114238370A

  • Data query method and device, computer equipment and storage medium

    CN116842036A

  • SQL (Structured Query Language) statement generation method and system, medium and equipment

    CN117251469A

  • Data analysis method and system based on natural language, electronic equipment and storage medium

    CN118132587A

  • Natural language intelligent number asking method and device and storage medium

    CN119025552A

Cited By

  • Business data query method and device, electronic equipment and storage medium

    CN121350040A

  • ODRL strategy generation method and device, equipment, medium and program product

    CN121903000A