A data inquiry prompt construction method and system applied to a language model

By pre-building a semantic table and a query sample database, and using a multi-level mapping matching method to filter out relevant data tables and fields, model prompts are generated. This solves the problem of insufficient understanding ability of language models in data analysis in the field of public safety, and improves the accuracy of data query results and the accuracy of code generation.

CN118377858BActive Publication Date: 2026-03-03DACE INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-02-07
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

In data analysis in the public safety field, existing language models suffer from limited customized model parameters and insufficient analysis code generation capabilities, resulting in weak model comprehension and an inability to accurately filter relevant data tables and fields, thus affecting the accuracy of data query results.

Method used

A pre-built semantic table and query sample database are used to filter relevant data tables and fields through a multi-level mapping matching method, and model prompt information is generated to improve the data query accuracy of the language model.

Benefits of technology

It improves the accuracy of code generation by language models in data query scenarios, and solves the problem of insufficient professional knowledge understanding and complex code generation ability of domain-customized models when faced with data format mismatch. In particular, it avoids the decline in recognition accuracy caused by excessive interference in police data scenarios with non-public data sources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118377858B_ABST
    Figure CN118377858B_ABST
Patent Text Reader

Abstract

The application discloses a data inquiry prompt construction method and system applied to a language model, and the method comprises the following steps: preconstructing a database semantic table and an inquiry example database; receiving natural language inquiry information and converting the natural language inquiry information into an inquiry vector; performing database similarity matching on the inquiry vector and the database semantic table, and selecting a first target database semantic from a plurality of database semantics according to a first database similarity matching result; performing example similarity matching on the inquiry vector and the inquiry example database, and selecting a target inquiry example from a plurality of inquiry examples according to an example similarity matching result; generating model prompt information according to the natural language inquiry information, the first target database semantic and the target inquiry example; and inputting the model prompt information into the language model, so that the language model generates a data analysis result according to the model prompt information. The application can improve the data result generation precision of the language model in response to an inquiry scene, thereby improving user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of deep learning technology, and in particular to a data query prompting method and system for large language models applied to data analysis in the public safety field. Background Technology

[0002] As deep learning-based text generation technology matures, and given the diverse needs of data analysis and intelligence assessment in complex data scenarios in the public safety field, it is currently possible to deploy domain-customized models based on open-source large models. However, these domain-customized models have a small number of parameters, insufficient analysis code generation capabilities, and highly specialized data tables, resulting in weak model understanding capabilities.

[0003] Based on the above issues, there is a need for a data query prompt construction method applied to language models to improve the accuracy of data result generation in response to query scenarios and thus enhance user experience. Summary of the Invention

[0004] To address the technical problem of low accuracy in language model data query results, this invention provides a method and system for constructing data query prompts for language models. The specific technical solution is as follows:

[0005] This invention provides a method for constructing data query prompts applied to language models, comprising:

[0006] A pre-built database semantic table and a query sample database are provided. The database semantic table includes several database semantics, and the query sample database includes several query samples.

[0007] Receive natural language query information and convert it into query vectors;

[0008] The query vector is matched with the database semantic table for database similarity, and a first target database semantic is selected from several database semantics based on the first database similarity matching result;

[0009] Filter fields

[0010] The query vector is matched with the query sample database (sample question part) for sample similarity, and the target query sample is selected from several query samples based on the sample similarity matching result;

[0011] Model prompt information is generated based on the combination of the natural language query information, the semantics of the first target database, and the target query examples;

[0012] The model prompts are input into the language model, which then generates data analysis results based on the prompts.

[0013] The data query prompt construction method for language models provided by this invention pre-selects high-value data tables corresponding to the data query information based on a multi-level mapping matching method before performing a data query on the language model, and inputs the data tables into the language model for query information processing. This solves the problem that business domain databases usually involve a large number of data tables, each containing dozens or even hundreds of data fields. Domain-customized language models are limited in terms of text understanding and the number of input tokens, making it impossible to accurately filter out the data tables and data fields related to the question from a large number of data tables. This improves the accuracy of the data query result code generation of the language model.

[0014] In one embodiment, the data query prompt construction method for language models provided by the present invention includes a database semantic table comprising a database name, a database address, a database name, a database description, data field names, and data field descriptions; and a query example comprising a sample query, a sample database, sample data fields, and sample code.

[0015] In one embodiment, generating model prompt information based on the combination of the natural language query information, the semantics of the first target database, and the target query example specifically includes:

[0016] Invoke the sample database in the target query sample;

[0017] The model prompt information is generated by combining the semantics of the second target database corresponding to the sample database with the semantics of the first database.

[0018] The data query prompt construction method for language models provided by this invention performs multi-level semantic similarity calculation and filtering on data table descriptions and field descriptions, to the greatest extent possible to select data tables and data fields related to data queries, and to constrain the language model to perform data processing based on data tables and data fields with stronger relevance, thereby improving the accuracy of data analysis code generation.

[0019] In one embodiment, the query vector is matched with the database semantic table for database similarity, and a first target database semantic is selected from several database semantics based on the first database similarity matching result, specifically including:

[0020] Based on the first database similarity matching results, a first preset number of the first target database semantics are selected from a plurality of database semantics in descending order of similarity; (not necessarily one, but could be k_table numbers).

[0021] The step of performing sample similarity matching between the query vector and the query sample database, and selecting a target query sample from several query samples based on the sample similarity matching results, specifically includes:

[0022] Based on the sample similarity matching results, a second preset number of target query samples are selected from a plurality of query samples in descending order of similarity.

[0023] In one embodiment, generating model prompt information based on the combination of the natural language query information, the semantics of the first target database, and the target query example specifically includes:

[0024] Based on preset regular expressions and preset information combination schemes, the natural language query information, the semantics of the first target database, and the target query example are converted into the model prompt information.

[0025] The data query hint construction method for language models provided in this application addresses the problem that domain-customized language models have weak professional knowledge understanding and complex code generation capabilities when faced with data format mismatches, such as actual field formats, thereby improving the accuracy of code generation in query scenarios of dedicated domain language models.

[0026] In one embodiment, the database semantic table includes a police incident database, a police material database, a police incident handling database, and a police personnel database.

[0027] The data query prompt construction method for language models provided in this application is applied to police data scenarios from non-public data sources. It avoids the problem of excessive interference in conventional data tables making it impossible to filter out query-related data tables and fields, thus affecting the recognition accuracy of language models.

[0028] In some implementations, selecting the first target database semantics from a plurality of database semantics based on the first database similarity matching result specifically includes:

[0029] Based on the similarity matching results of the first database, at least one target database is selected from several databases;

[0030] The query vector is matched with at least one field of a data table in the target database based on field similarity.

[0031] Based on the field similarity matching results, the target data table fields are selected as the semantics of the first target database.

[0032] In some implementations, the query vector is matched with the query sample database for sample similarity, and a target query sample is selected from a plurality of query samples based on the sample similarity matching result, specifically including:

[0033] The query vector is matched with the semantics of each second target database using database similarity, and at least one third target database semantic is selected from several second target database semantics based on the second database similarity matching results;

[0034] The target query example is selected from a plurality of query examples based on at least one of the semantics of the third target database.

[0035] According to another aspect of the present invention, the present invention also provides a method for generating data query results of a language model, comprising the steps of:

[0036] Receive natural language query information and convert it into query vectors;

[0037] The query vector is matched with a pre-built database semantic table for database similarity, and a first target database semantic is selected from several database semantics based on the first database similarity matching result.

[0038] The query vector is matched with a pre-built query sample database for sample similarity, and the target query sample is selected from several query samples based on the sample similarity matching results.

[0039] Model prompt information is generated based on the combination of the natural language query information, the semantics of the first target database, and the target query examples;

[0040] Generate database analysis code based on the model prompts;

[0041] The database analysis code is used to query and generate data analysis results in the model's built-in database.

[0042] According to another aspect of the present invention, the present invention also provides a data query prompting construction system applied to a language model, comprising:

[0043] The database layer includes a pre-built database semantic table and a query sample database. The database semantic table includes several database semantics, and the query sample database includes several query samples.

[0044] The vector model layer is used to receive natural language query information and convert it into query vectors;

[0045] A semantic matching layer is used to perform database similarity matching between the query vector and the database semantic table, select a first target database semantic from several database semantics according to the first database similarity matching result, and perform sample similarity matching between the query vector and the query sample database, and select a target query sample from several query samples according to the sample similarity matching result.

[0046] A prompting construction layer is used to generate model prompting information based on the combination of the natural language query information, the semantics of the first target database, and the target query examples.

[0047] According to another aspect of the present invention, the present invention also provides a storage medium storing at least one instruction, which is loaded and executed by a processor to implement the operations performed by the above-described data query prompt construction method or the above-described data query result generation method.

[0048] According to another aspect of the present invention, the present invention also provides a computer product, including a computer program, which, when run by a computing device, performs the operations performed by the above-described data query prompt construction method or the above-described data query result generation method.

[0049] The data query prompt construction method and system for language models provided by this invention have at least one of the following technical effects:

[0050] (1) Before performing a data query on the language model, a solution is proposed to pre-select a data table with high reference value corresponding to the data query information based on a multi-level mapping matching method, and input the data table into the language model for query information processing. This solution addresses the problem that business domain databases typically involve a large number of data tables, each containing dozens or even hundreds of data fields. Domain-customized language models are limited in terms of text understanding and the number of input tokens, making it impossible to accurately filter out the data tables and data fields related to the question from a large number of data tables. This improves the accuracy of the code generation of the data query result from the language model.

[0051] (2) Perform multi-level semantic similarity calculation and filtering on the data table description and field description to filter out the data tables and data fields that are relevant to the data query to the greatest extent possible, and constrain the language model to perform data processing based on the data tables and data fields with stronger relevance to improve the generation accuracy of data analysis code;

[0052] (3) To address the problem that domain-customized language models have weak professional knowledge understanding and complex code generation capabilities when faced with data formats such as mismatched actual field formats, and to improve the accuracy of code generation in query scenarios of dedicated domain language models;

[0053] (4) Applied to police data scenarios with non-public data sources, it avoids the inability to filter out query-related data tables and data fields due to excessive interference in regular data tables, which affects the recognition accuracy of language models. Attached Figure Description

[0054] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0055] Figure 1 This is a flowchart of a data query prompt construction method applied to a language model according to the present invention;

[0056] Figure 2 This is a flowchart illustrating the process of calling the sample database in a data query suggestion construction method applied to a language model according to the present invention;

[0057] Figure 3 This is another flowchart of a data query prompt construction method applied to a language model according to the present invention;

[0058] Figure 4 This is a flowchart illustrating input regularization in a data query prompting construction method for language models according to the present invention;

[0059] Figure 5 This is a flowchart of a method for generating data query results using a language model according to the present invention. Detailed Implementation

[0060] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application can also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.

[0061] It should be understood that, when used in this specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or sets.

[0062] To keep the drawings concise, only the parts relevant to the invention are shown schematically in each figure, and they do not represent the actual structure of the product. Furthermore, for ease of understanding, in some figures, components with the same structure or function are shown only schematically, or only one is labeled. In this document, "a" not only means "only one," but can also mean "more than one."

[0063] It should also be further understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0064] Furthermore, in the description of this application, the terms "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.

[0065] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the specific implementation methods of the present invention will be described below with reference to the accompanying drawings. Obviously, the drawings described below are merely some embodiments of the present invention. For those skilled in the art, other drawings and other implementation methods can be obtained based on these drawings without any creative effort.

[0066] Existing data analysis code generation technologies based on large models mainly involve the following two steps: First, a basic large-scale code model is pre-trained using methods such as SFT supervision to train a basic large-scale code model with code completion and interpretation capabilities. Common models include Codegeex, Codellama, and Codegen. Second, to address the issue that the basic large-scale code model generally struggles to understand natural language, further fine-tuning is needed using a Text2Code mapping dataset to create a code model with dialogue capabilities. Common models include Codellama-Instuct and CodeQwen.

[0067] Because the public open-source large models that can be privately deployed are mostly quantitative versions with a small number of parameters, they exhibit bottlenecks in understanding and code generation capabilities when analyzing problems in a specific domain. For example, they may be unable to find the correct data table in a database with multiple tables, have difficulty finding the correct field when a table contains dozens of fields, experience data format mismatches such as actual field formats, and output that does not meet query requirements.

[0068] To solve the above problems, such as Figure 1 As shown, this invention provides a method for constructing data query prompts applied to language models, comprising:

[0069] S100 pre-built database semantic tables and query sample database.

[0070] Specifically, the database semantic table includes several database semantics, and the query sample database includes several query samples. The database semantic table includes, but is not limited to, database name, database address, database name, database description, data field name and data field description. The query samples include, but are not limited to, sample queries, sample databases, sample data fields and sample code.

[0071] For example, the database semantic tables are shown in Table 1 below, and query examples are shown in Table 2 below.

[0072]

[0073] Table 1

[0074]

[0075] Table 2

[0076] The S200 receives natural language query information and converts it into query vectors.

[0077] Specifically, the question text data of natural language query information is transformed into vector form through an embedding model. Vectorization models such as word2vec, GloVe or BERT can be used, and the vectorized natural language query information is denoted as v(query).

[0078] S300 performs database similarity matching between the query vector and the database semantic table, and selects the first target database semantic from several database semantics based on the first database similarity matching result.

[0079] Specifically, the vectorized natural language query information v(query) is matched with the vectorized data table descriptions v(table_describe) based on similarity, denoted as s_i(table) = similar(v(query), v_i(table_describe)), where i represents the number of the i-th data table. Based on the similarity calculation results, the k_table data tables with the highest similarity are selected, denoted as the data table set {table}.

[0080] Furthermore, the vectorized natural language query information v(query) can be matched with the vectorized data field descriptions v(col) in the k_table data tables above, and the k_col data fields with the highest similarity can be selected. Finally, k_table data tables and the filtered data fields of each data table are obtained.

[0081] For example, taking the database semantics of the following report data table and disposal data table as the first target database semantics, the report data table records report data for each district and type in Shanghai from 2014 to 2023, including the reporter and the reporting time. It includes fields such as Address, {report address: the district where the incident occurred, including Huangpu District, Changning District, Xuhui District, etc.}; Type, {report type: primary category including fire, rescue, other}; Time, {event time: data format 'yyyy-MM-dd hh24:mi:ss'}. The disposal data table records report data for each district and type in Shanghai from 2014 to 2023, including the disposal person and the reporting time. It also includes fields such as Address, {report address: the district where the incident occurred, including Huangpu District, Changning District, Xuhui District, etc.}; Type, {report type: primary category including fire, rescue, other}; Time, {event time: data format 'yyyy-MM-dd hh24:mi:ss'}.

[0082] S400 performs sample similarity matching between the query vector and the query sample database, and selects the target query sample from several query samples based on the sample similarity matching results.

[0083] Specifically, the vectorized natural language query information v(query) is matched with the vectorized data table description v(query_example) based on similarity. The sample data table must involve the data table set {table}. That is, s_j(example) = similar(v(query), v_j(query_example)) for(table_example_#j belongs to table_name in{table}), where j represents the #j-th sample number, and table_example_#j represents the data table set associated with sample #j (i.e., table_example in Table 2).

[0084] Calculate the overall similarity of each example, i.e., s(example) = E[s_i(table)] * s_j(example), where E[s_i(table)] represents the average similarity s_i(table) of the questions involving table #i in table_example_#j. Select the k_example (example query - example code) pairs with the largest similarity s(example) as example hints.

[0085] For example, the process of selecting a target query example is as follows:

[0086] Query: "Analyze the number of relief reports in Shanghai in the fourth quarter of 2022?"

[0087] Code: SELECT COUNT(*) FROM report data table.

[0088] WHERE Type='rescue'AND Time>=to_date('2022-10-0100:00:00','yyyy-MM-ddhh24:mi:ss')AND Time <to_date('2023-01-0100:00:00','yyyy-MM-dd hh24:mi:ss')。

[0089] Query: "Analyze the number of incidents handled in Huangpu District, Shanghai in 2022?"

[0090] Code:Time SELECT COUNT(*)FROM the data table to be processed.

[0091] WHERE Address = 'Huangpu District' AND

[0092] Time>=to_date('2022-01-0100:00:00','yyyy-MM-dd hh24:mi:ss')AND

[0093] Time <to_date('2023-01-0100:00:00','yyyy-MM-dd hh24:mi:ss')mi:ss’}。

[0094] The S500 generates model prompts based on a combination of natural language query information, semantics from the first target database, and target query examples.

[0095] Specifically, the model prompt information is a combination of natural language query information, semantics of the first target database, and target query examples. The combined data is then packaged and input into the language model for the language model to perform corresponding data analysis results.

[0096] For example, data is retrieved using the following analytical language based on the combined data:

[0097] SELECT COUNT(*) FROM report data table.

[0098] WHERE Type = 'Fire' AND Address = 'Xuhui District' AND

[0099] Time>=to_date('2023-01-0100:00:00','yyyy-MM-dd hh24:mi:ss')AND

[0100] Time <to_date('2023-04-0100:00:00','yyyy-MM-dd。

[0101] The S600 inputs model prompts into the language model, enabling the language model to generate data analysis results based on the model prompts.

[0102] For example, based on the language retrieval data model described above, the data analysis result "the number of fire reports in Xuhui District, Shanghai in the first quarter of 2023 was 36" can be obtained from the corresponding report data table.

[0103] The data query prompt construction method for language models provided in this embodiment pre-selects data tables with high reference value corresponding to the data query information based on a multi-level mapping matching method before performing the data query on the language model, and inputs the data tables into the language model for query information processing. This solves the problem that business domain databases usually involve a large number of data tables, each containing dozens or even hundreds of data fields. Domain-customized language models are limited in terms of text understanding and the number of input tokens, making it impossible to accurately filter out the data tables and data fields related to the question from a large number of data tables. This improves the accuracy of the data query result code generation of the language model.

[0104] In one embodiment, such as Figure 2 As shown, step S500 generates model prompt information based on a combination of natural language query information, semantics of the first target database, and target query examples, specifically including:

[0105] S510 invokes the target query sample database in the sample database.

[0106] S520 generates model prompt information by combining the semantics of the second target database corresponding to the sample database with the semantics of the first database.

[0107] In one implementation, the query vector is matched with the semantics of each second target database using database similarity, and at least one third target database semantic is selected from several second target database semantics based on the second database similarity matching results; a target query example is selected from several query examples based on at least one third target database semantic.

[0108] Specifically, after executing step S300, which selects the first target database semantics from several database semantics based on the first database similarity matching result, the third target database semantics are filtered based on the first target database semantics. For example, the first target database semantics include database A and database B, and the third target database semantics include database A corresponding to the first query sample, database B corresponding to the first query sample, database C corresponding to the second query sample, and database D corresponding to the third query sample. Then, the first query sample corresponding to the first target database semantics is filtered out from the second target database semantics and used as the target query sample.

[0109] In one implementation, after selecting several target query examples corresponding to the first target database semantics from the second target database semantics, the third target database semantics corresponding to each target query example are compared with the query vector for similarity. The similarity matching results between the third target database semantics corresponding to each target query example and the query vector are ranked from high to low, and a third preset number of fourth target database semantics are selected from the several third target database semantics. The query examples corresponding to the fourth target database semantics are used as target query examples. For example, the semantics of the first target database includes database A and database B, and the semantics of the third target database includes database A corresponding to the first query sample, database B corresponding to the second query sample, database C corresponding to the third query sample, and database D corresponding to the fourth query sample. Then, the first query sample and the second query sample corresponding to the semantics of the first target database are selected from the semantics of the second target database. The similarity of the first query sample and the second query sample is compared with the query vector. If the similarity comparison result of the first query sample and the query vector is less than the similarity comparison result of the second query sample and the query vector, then the second query sample is taken as the target query sample.

[0110] Example of sample selection process:

[0111] 1) In the previous data table similarity matching, I selected the two tables with the highest similarity, table #1 and #2, with similarity values ​​of s_table#1 and s_table#2 respectively.

[0112] 2) During the sample selection phase, first examine the `table_example` field of the sample. It must involve one or more of the required data from `table#1`, `#2`, and `#3`. For example, if `query_example#1` involves `table#1`, `query_example#2` involves `table#2`, `query_example#3` involves both `table#1` and `table#2`, and `query_example#4` involves `table#3`, then `query_example#4` will be filtered out.

[0113] 3) Calculate the similarity values ​​of the original question and query_example#1, #2, and #3 respectively, which are s_example#1, s_example#2, and s_example#3.

[0114] 4) Calculate the combined similarity values ​​between the original question and query_example#1, #2, and #3, respectively, as s_example#1*s_table#1, s_example#2*s_table#2, and s_table#3.

[0115] s_example#3*(s_table#1+s_table#2) / 2.

[0116] 5) Find the examples with the highest overall similarity, such as example#1 and #3, as prompt examples.

[0117] The data query prompt construction method for language models provided in this embodiment performs multi-level semantic similarity calculation and filtering on data table descriptions and field descriptions to maximize the selection of data tables and data fields related to data queries. This constrains the language model to perform data processing based on data tables and data fields with stronger relevance, thereby improving the accuracy of data analysis code generation.

[0118] In one embodiment, such as Figure 3 As shown, step S300 involves performing database similarity matching between the query vector and the database semantic table, and selecting the first target database semantic from several database semantics based on the first database similarity matching result. Specifically, this includes:

[0119] S310 selects a first preset number of first target database semantics from several database semantics in descending order of the first database similarity matching results.

[0120] Step S400 involves performing sample similarity matching between the query vector and the query sample database, and selecting the target query sample from several query samples based on the sample similarity matching results. Specifically, this includes:

[0121] S410 selects a second preset number of target query samples from a number of query samples in descending order of sample similarity matching results.

[0122] In one embodiment, such as Figure 4 As shown, step S500 generates model prompt information based on the combination of natural language query information, the semantics of the first target database, and target query examples. Specifically, it also includes:

[0123] S530 converts natural language query information, semantics of the first target database, and target query examples into model prompt information based on preset regular expressions and preset information combination schemes.

[0124] The data query prompt construction method for language models provided in this embodiment addresses the problem that domain-customized language models have weak professional knowledge understanding and complex code generation capabilities when faced with data format mismatches, such as actual field formats, thereby improving the accuracy of code generation in query scenarios of dedicated domain language models.

[0125] In the above embodiments, due to the data confidentiality and limited computing resources in the public safety field, it is necessary to use a large model of less than 20B for private deployment and the data is limited to interaction within the local area network. The database semantic table in this application includes a police incident database, a police material database, a police incident handling database, and a police personnel database. The data query prompt construction method for language models provided in this application is applied to police data scenarios with non-public data sources to avoid the inability to filter out query-related data tables and data fields due to excessive interference in conventional data tables, which would affect the recognition accuracy of the language model.

[0126] According to another aspect of the present invention, when the data table with high reference value corresponding to the data query information is pre-selected based on a multi-level mapping matching method in this application, and the subsequent language model data processing is implemented by the language model, such as Figure 5 As shown, the present invention also provides a method for generating data query results of a language model, comprising the following steps:

[0127] S10 receives natural language query information and converts it into query vectors.

[0128] S20 performs database similarity matching between the query vector and the pre-built database semantic table, and selects the first target database semantic from several database semantics based on the first database similarity matching result.

[0129] S30 performs sample similarity matching between the query vector and the pre-built query sample database, and selects the target query sample from several query samples based on the sample similarity matching results.

[0130] S40 generates model prompts based on a combination of natural language query information, semantics from the first target database, and target query examples.

[0131] S50 generates database analysis code based on model prompts.

[0132] S60 queries the model's built-in database based on the database analysis code and generates data analysis results.

[0133] According to another aspect of the present invention, the present invention also provides a data query prompting construction system applied to a language model, comprising a database layer, a vector model layer, a semantic matching layer, and a prompting construction layer.

[0134] The language model architecture comprises the following layers: a database layer, a pre-built database semantic table, and a query sample database. The database semantic table contains several database semantics, and the query sample database contains several query samples. A vector model layer receives natural language query information and converts it into query vectors. A semantic matching layer performs database similarity matching between the query vectors and the database semantic table, selects a first target database semantic from several database semantics based on the first database similarity matching result, and performs sample similarity matching between the query vectors and the query sample database, selects a target query sample from several query samples based on the sample similarity matching result. A prompting construction layer generates model prompting information based on the natural language query information, the first target database semantic, and the target query sample. These layers—database layer, vector model layer, semantic matching layer, and prompting construction layer—together constitute the language model architecture in this application.

[0135] According to another aspect of the present invention, this embodiment also provides a storage medium storing at least one instruction, which is loaded and executed by a processor to implement the operations performed by the above-described data query prompt construction method or the above-described data query result generation method.

[0136] According to another aspect of the present invention, this embodiment also provides a computer product, including a computer program, which, when run by a computing device, performs the operations performed by the above-described data query prompt construction method or the above-described data query result generation method.

[0137] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0138] Those skilled in the art will recognize that the units and steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0139] In the embodiments provided in this application, it should be understood that the disclosed method and system for constructing data query prompts for language models can be implemented in other ways. For example, the above-described embodiment of a method and system for constructing data query prompts for language models is merely illustrative. For instance, the division of modules or units is merely a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or modules may be combined or integrated into another system, or some features may be ignored or not executed.

[0140] Furthermore, the functional units in the various embodiments of this application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The integrated unit described above can be implemented in hardware or as a software functional unit.

[0141] It should be noted that the above description is only a preferred embodiment of the present invention. It should be pointed out that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for constructing a data query prompt applied to a language model, characterized in that, The method comprises the following steps: pre-constructing a database semantic table and a query sample database, wherein the database semantic table comprises a plurality of database semantics, and the query sample database comprises a plurality of query samples, and each query sample comprises a sample query, a sample database, a sample data field and a sample code; receiving natural language query information and converting the natural language query information into a query vector; performing database similarity matching between the query vector and the database semantic table, and selecting a first target database semantic from the plurality of database semantics according to a first database similarity matching result; performing sample similarity matching between the query vector and the query sample database, and selecting a target query sample from the plurality of query samples according to a sample similarity matching result; generating model prompt information according to the natural language query information, the first target database semantic and the target query sample; inputting the model prompt information into a language model, and enabling the language model to generate a data analysis result according to the model prompt information. The database similarity matching between the query vector and the database semantic table, and the selection of the first target database semantic from the plurality of database semantics according to the first database similarity matching result specifically comprise the following steps: performing similarity matching between the query vector and each vectorized data table description, and selecting k_table data tables with the largest similarity according to the similarity matching result; performing similarity matching between the query vector and vectorized data field names and descriptions of the k_table data tables, and selecting k_col data fields with the largest similarity according to the similarity matching result.

2. The data query prompt construction method applied to a language model according to claim 1, wherein the database semantic table comprises a database name, a database address, a database description, a data field name and a data field description. The generation of model prompt information according to the natural language query information, the first target database semantic and the target query sample specifically comprises the following steps: 3.The method for constructing data query prompts applied to a language model according to claim 2, wherein, calling the sample database in the target query sample; combining the second target database semantic corresponding to the sample database with the first database semantic to generate the model prompt information. The database similarity matching between the query vector and the database semantic table, and the selection of the first target database semantic from the plurality of database semantics according to the first database similarity matching result specifically comprise the following steps: 4.The method for constructing data query prompts applied to a language model according to claim 1, wherein, selecting a first preset number of the first target database semantics from the plurality of database semantics from high to low according to the first database similarity matching result; The sample similarity matching between the query vector and the query sample database, and the selection of the target query sample from the plurality of query samples according to the sample similarity matching result specifically comprise the following steps: selecting a second preset number of the target query samples from the plurality of query samples from high to low according to the sample similarity matching result. The generation of model prompt information according to the natural language query information, the first target database semantic and the target query sample specifically comprises the following steps: 5.The method for constructing data query prompts applied to a language model according to claim 1, wherein, ​ According to a preset regular expression and a preset information combination scheme, the natural language inquiry information, the first target database semantic, and the target inquiry example are converted into the model prompt information. 6.The method for constructing data query prompts applied to a language model according to claim 1, wherein, The database semantic table comprises a police case event database, a police case material database, a police case disposal database, and a police case personnel database. 7.The method for constructing data query prompts applied to a language model according to claim 1, wherein, The first target database semantic is selected from the database semantics according to the first database similarity matching result, and specifically comprises: At least one target database is selected from the databases according to the first database similarity matching result; The inquiry vector is subjected to field similarity matching with the data table fields in the at least one target database; The target data table field is selected as the first target database semantic according to the field similarity matching result. 8.The method for constructing data query prompts applied to a language model according to claim 3, wherein, The inquiry vector is subjected to example similarity matching with the inquiry example database, and the target inquiry example is selected from the inquiry examples according to the example similarity matching result, and specifically comprises: The inquiry vector is subjected to database similarity matching with each second target database semantic, and at least one third target database semantic is selected from the second target database semantics according to the second database similarity matching result; The target inquiry example is selected from the inquiry examples according to the at least one third target database semantic.

9. A method of generating a data query result of a language model, the method comprising: The steps comprise: Receiving natural language inquiry information and converting it into an inquiry vector; The inquiry vector is subjected to database similarity matching with a pre-constructed database semantic table, and a first target database semantic is selected from the database semantics according to a first database similarity matching result; The inquiry vector is subjected to example similarity matching with a pre-constructed inquiry example database, and a target inquiry example is selected from inquiry examples according to an example similarity matching result, wherein the inquiry example comprises an example inquiry, an example database, an example data field, and an example code; Model prompt information is generated according to the natural language inquiry information, the first target database semantic, and the target inquiry example; Database analysis code is generated according to the model prompt information; Data analysis results are queried and generated in a model built-in database according to the database analysis code; The inquiry vector is subjected to database similarity matching with the database semantic table, and a first target database semantic is selected from the database semantics according to a first database similarity matching result, and specifically comprises: The inquiry vector is subjected to similarity matching with each vectorized data table description, and the k_table data tables with the largest similarity are selected according to the similarity matching result; The inquiry vector is subjected to similarity matching with the vectorized data field names and descriptions of the k_table data tables, and the k_col data fields with the largest similarity are selected according to the similarity matching result.

10. A data query prompting construction system applied to language models, characterized in that, The steps comprise: A database layer, comprising a pre-constructed database semantic table and a query example database, the database semantic table comprising a plurality of database semantics, the query example database comprising a plurality of query examples, the query examples comprising example queries, example databases, example data fields and example codes; A vector model layer, configured to receive natural language query information and convert the natural language query information into a query vector; A semantic matching layer, configured to perform database similarity matching between the query vector and the database semantic table, select a first target database semantic from the plurality of database semantics according to a first database similarity matching result, perform example similarity matching between the query vector and the query example database, and select a target query example from the plurality of query examples according to an example similarity matching result; A prompt construction layer, configured to generate model prompt information according to the natural language query information, the first target database semantic and the target query example; The semantic matching layer is further configured to perform similarity matching between the query vector and each vectorized data table description, and select k_table data tables with the largest similarity according to a similarity matching result; perform similarity matching between the query vector and vectorized data field names and descriptions of the k_table data tables, and select k_col data fields with the largest similarity according to a similarity matching result.

Citation Information

Patent Citations

  • Database natural language query method and device, electronic equipment and storage medium

    CN114328823A

  • Database joint query method, device and equipment based on large language model

    CN117076719A