Language conversion method and device based on retrieval enhancement and storage medium
Through the retrieval enhancement method, identifying intentions, recalling target data and performing language conversion, the problem of low accuracy in natural language to structured query language is solved, and more efficient and accurate language conversion is achieved.
Patent Information
- Application Number
- CN202411438944.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-15
- Publication Date
- 2025-02-14
AI Technical Summary
The prior art faces cross-domain and complexity problems in the process of natural language to structured query language, resulting in low conversion accuracy.
The language conversion method based on retrieval enhancement is adopted, and query information is determined by responding to query requests, intent recognition is performed, target data is recalled, and target data and prompt word templates are used for language conversion to generate a structured query language.
Through intent identification and problem recall, the problems of insufficient generalization and computing resource limitations are solved, and the efficiency and accuracy of language conversion are improved.
Smart Images

Figure CN119441261A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of language conversion, and in particular to a language conversion method, device and storage medium based on retrieval enhancement. Background Art
[0002] Data extraction and analysis are critical to organizations because they provide deep business insights, support evidence-based decision-making, and help optimize operations, manage risks, and enhance customer experience. They are key tools for modern enterprises to gain competitive advantage, ensure compliance, and drive innovation. Data extraction and analysis in the financial industry is a multi-dimensional, interdisciplinary, and complex field. It requires not only technical capabilities, but also a deep understanding of business content and regulatory requirements.
[0003] According to the technology type, natural language to structured query language solutions can be roughly divided into the following two types: rule-based natural language to structured query language solutions and large model-based natural language to structured language solutions. During the conversion process, they face cross-domain and complexity issues, resulting in low conversion accuracy. Summary of the invention
[0004] The main purpose of the present application is to provide a language conversion method, device and storage medium based on retrieval enhancement, aiming to solve the technical problem of low language conversion accuracy.
[0005] To achieve the above objectives, the present application proposes a language conversion method based on retrieval enhancement, the language conversion method based on retrieval enhancement comprising:
[0006] Responding to a query request and determining query information based on the query request;
[0007] Performing intent recognition on the query information, and determining a target prompt word template from a preset prompt word template library;
[0008] Perform question recall on the query information to obtain target data;
[0009] The target structured query language is generated by performing language conversion on the target data and the target prompt word template.
[0010] In one embodiment, the step of performing question recall on the query information to obtain target data includes:
[0011] Performing retrieval enhancement on the query information to obtain key fields;
[0012] Extract information from a preset metadata database based on the key fields to obtain target table information;
[0013] Extracting domain knowledge questions from the query information to obtain domain knowledge information;
[0014] Filter similar cases based on the key fields to obtain preset case information;
[0015] The target data is obtained through the target table information, the domain knowledge information and the preset case information.
[0016] In one embodiment, the step of screening similar cases based on the key fields to obtain preset case information includes:
[0017] Obtain historical case data from the structured query language case library;
[0018] Calculating semantic similarity and structural similarity between the query information and the historical case data according to the key fields to obtain a similarity calculation result;
[0019] Filtering a preset case from the historical case data according to the similarity calculation result, and obtaining a historical structured query language corresponding to the preset case;
[0020] Preset case information is obtained according to the preset case and the historical structured query language.
[0021] In one embodiment, the step of extracting information from a preset metadata database based on the key field to obtain target table information includes:
[0022] Based on the key fields, a matching strategy is used to filter and obtain an initial table from a preset metadata database;
[0023] Obtaining original field data in the initial table;
[0024] Based on the key fields, information is extracted from the original field data by using a field retention strategy to obtain target field data;
[0025] Build target table information according to the target field data.
[0026] In one embodiment, the step of performing intent recognition on the query information and determining a target prompt word template from a preset prompt word template library includes:
[0027] Analyze the query information to determine the query requirements;
[0028] Performing intent recognition on the query requirement through intent recognition rules to determine the query intent;
[0029] According to the query intent, a target prompt word template corresponding to the query intent is determined from a preset prompt word template library.
[0030] In one embodiment, the step of performing intent recognition on the query information and determining a target prompt word template from a preset prompt word template library includes:
[0031] Analyze the query information to determine the query requirements;
[0032] When the query intent of the query requirement is not identified by the intent identification rule, the query intent is identified by the intent identification model to determine the query intent;
[0033] According to the query intent, a target prompt word template corresponding to the query intent is determined from a preset prompt word template library.
[0034] In one embodiment, the step of performing language conversion on the target data and the target prompt word template to generate a target structured query language includes:
[0035] The target table information, domain knowledge information and preset case information in the target data are respectively filled into corresponding positions in the target prompt word template to complete the language conversion and generate the target structured query language.
[0036] In one embodiment, the method further comprises:
[0037] Analyze the target structured query language to determine the search path, index to be used, and operation type to be performed for the query information;
[0038] Generate an execution plan through the search path, the usage index and the operation type;
[0039] The execution plan is added to the target structured query language to perform structured query language interpretation.
[0040] In addition, to achieve the above-mentioned purpose, the present application also proposes a language conversion device based on retrieval enhancement, and the language conversion device based on retrieval enhancement includes:
[0041] A response module, configured to respond to the query request and determine query information based on the query request;
[0042] A recognition module, used to perform intent recognition on the query information and determine a target prompt word template from a preset prompt word template library;
[0043] A recall module, used to recall the query information to obtain target data;
[0044] The conversion module is used to perform language conversion through the target data and the target prompt word template to generate a target structured query language.
[0045] In addition, to achieve the above-mentioned purpose, the present application also proposes a retrieval-enhanced language conversion device, which includes: a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the computer program is configured to implement the steps of the retrieval-enhanced language conversion method as described above.
[0046] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the retrieval-enhanced language conversion method described above are implemented.
[0047] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, the steps of the language conversion method based on retrieval enhancement as described above are implemented.
[0048] One or more technical solutions proposed in this application respond to a query request and determine query information based on the query request; perform intent recognition on the query information and determine a target prompt word template from a preset prompt word template library; perform question recall on the query information to obtain target data; perform language conversion between the target data and the target prompt word template to generate a target structured query language. Through intent recognition, business knowledge and industry common sense related to the question are retrieved to solve the problem that the original technical solution is not general enough in a specific field, and through question recall, the problem that the model effect cannot be improved by fine-tuning in a specific field due to computing resource limitations is solved, thereby improving the efficiency and accuracy of language conversion. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0050] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0051] Figure 1 A flowchart of the first embodiment of the language conversion method based on retrieval enhancement provided in the present application;
[0052] Figure 2 A hierarchical diagram of the language conversion system based on retrieval enhancement for this application;
[0053] Figure 3 This is a schematic diagram of a specific process of intent recognition in an embodiment of a language conversion method based on retrieval enhancement of the present application;
[0054] Figure 4 A flowchart diagram of the second embodiment of the language conversion method based on retrieval enhancement provided in this application;
[0055] Figure 5 This is a schematic diagram of the process of extracting information from a preset metadata database to obtain target table information in an embodiment of the language conversion method based on retrieval enhancement of the present application;
[0056] Figure 6 This is a schematic diagram of the process of extracting domain knowledge questions in an embodiment of the language conversion method based on retrieval enhancement of the present application;
[0057] Figure 7 This is a schematic diagram of the process of similar case screening in an embodiment of the language conversion method based on retrieval enhancement of the present application;
[0058] Figure 8 This is a schematic diagram of the module structure of a language conversion device based on retrieval enhancement according to an embodiment of the present application;
[0059] Fig. 9 This is a schematic diagram of the device structure of the hardware operating environment involved in the retrieval-enhanced language conversion method in the embodiment of the present application.
[0060] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0061] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.
[0062] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.
[0063] The main solution of the embodiment of the present application is: responding to a query request and determining query information based on the query request; performing intent recognition on the query information and determining a target prompt word template from a preset prompt word template library; performing question recall on the query information to obtain target data; performing language conversion through the target data and the target prompt word template to generate a target structured query language.
[0064] The existing large-model-based natural language-to-SQL (Structured Query Language) solutions mainly convert natural language directly into structured language through the model, without the need for intermediate semantic parsing steps, which improves the generalization ability of the model and significantly improves performance. However, it still faces challenges such as generalization (cross-domain), complexity (SQL syntax), and correctness (alignment between questions and tables).
[0065] The present application provides a solution, which provides a natural language to SQL computing solution based on retrieval-augmented generation (RAG). The solution does not require fine-tuning or retraining, but retrieves business knowledge and industry common sense related to the problem through retrieval-augmented generation (RAG), thereby solving the problem that the original technical solution is not general enough in specific fields.
[0066] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or an electronic device capable of realizing the above functions, a language conversion system based on retrieval enhancement, etc. The following takes the language conversion system based on retrieval enhancement as an example to illustrate this embodiment and the following embodiments.
[0067] Based on this, the embodiment of the present application provides a language conversion method based on retrieval enhancement, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the language conversion method based on retrieval enhancement of the present application.
[0068] In this embodiment, the language conversion method based on retrieval enhancement includes steps S10 to S40:
[0069] Step S10: responding to the query request and determining query information based on the query request.
[0070] It should be noted that the query request is a query request that the user needs to make, and the query request includes the content that the user needs to query. The query request is the user's natural language. For example, the query request is: "Query [SCHEMA_DEV.BSTSUTINF] for records that meet the extraction date from 2023 to the present and the crime type is 009 or 001, and return the customer number, case number, and crime type". The specific information that the user needs to query can be determined based on the above query request.
[0071] In a specific implementation, this embodiment is applied to a language conversion system based on retrieval enhancement. The system includes three hierarchical structures, such as Figure 2 As shown, Figure 2The hierarchical structure diagram of the language conversion system based on retrieval enhancement includes the knowledge base layer, the preprocessing layer and the model layer. The knowledge base layer is equivalent to a large database and consists of two key components: the MySQL configuration library and the Milvus vector library. The MySQL configuration library is responsible for storing and managing the metadata of the database. Its content is extensive, covering key elements such as table structure, code value information, association relationship, caliber library, field attributes, index information, etc. The Milvus vector library plays a dual role: on the one hand, it converts the metadata in the MySQL configuration library into vector form to optimize retrieval efficiency; on the other hand, it also stores data caliber information customized according to different business scenarios and field requirements. There is a preset metadata library in the MySQL configuration library. In addition, the knowledge base layer further integrates the Prompt template library (preset prompt word template library) and the SQL case library (structured query language case library). The Prompt template library presets a variety of templates according to different business needs to adapt to diverse query scenarios and ensure that the instructions received by the language model are both accurate and consistent. The SQL case library contains many historical SQL query cases, providing valuable reference resources for the system and significantly improving the model's ability to identify and process specific query patterns. The prompt template library includes multi-table prompt word templates, single-table prompt word templates, data link prompt word templates, etc. The SQL case library includes single-table query structured language cases, aggregate query structured language cases, code value related structured language cases, etc. The preprocessing layer is mainly used to process the user's query information, which may include recall processing, template matching processing, similar case matching processing, etc. Recall processing may include vector similarity calculation, regular matching, high-frequency field retention, and may include recall fields, recall associations, recall code values, recall calibers, etc. Template matching processing can select appropriate templates according to the type of question and database type. Similar case matching includes querying appropriate similar cases based on the similarity of the query information and the problem of historical cases, structural similarity (schema_link), etc. CoT chain information extraction mainly establishes and maintains the link relationship of the database architecture through abstract information processing, provides the necessary context information for the language model, and filters out redundant data that may cause model misunderstanding.
[0072] The model layer is mainly used to receive information provided by the preprocessing layer, so as to use the open source Qwen72B model to understand complex natural language queries and convert them into structured SQL code. In addition, the model layer also integrates an SQL interpretation module, which can elaborate on the logic and reasoning process of the model-generated SQL statements. This function is crucial to improving users' understanding and trust in the results generated by the model, especially for business scenarios that require high accuracy and explainability, such as financial auditing and risk management.
[0073] Step S20: performing intent recognition on the query information and determining a target prompt word template from a preset prompt word template library.
[0074] It can be understood that intent recognition can use intent recognition rules or intent recognition models to identify query information. Intent recognition is to identify the intent of the user's query, and then determine the most appropriate prompt word template, that is, the target prompt word template, from the preset prompt word template library according to the identified intent.
[0075] In specific implementations, historical question-and-answer data can be used to summarize a set of intent recognition rules, thereby performing intent recognition on query information through the intent recognition rules.
[0076] In a feasible implementation, step S20 may include steps S21 to S23:
[0077] Step S21: Analyze the query information to determine the query requirements.
[0078] It should be noted that the query requirements can be determined by analyzing the query information. For example, the query information is: query [SCHEMA_DEV.BSTSUTINF] for records with an extraction date from 2023 to the present and a crime type of 009 or 001, and return the customer number, case number, and crime type. The query requirement is to query for records with an extraction date from 2023 to the present and a crime type of 009 or 001, and return the customer number, case number, and crime type.
[0079] Step S22: perform intent recognition on the query requirement through intent recognition rules to determine the query intent.
[0080] In a specific implementation, the query requirement can be identified through intent recognition rules to determine the specific query intent. For example, by identifying the intent of the above query requirement, it is determined that the query intent is a simple intent.
[0081] Step S23: determining a target prompt word template corresponding to the query intent from a preset prompt word template library according to the query intent.
[0082] In a specific implementation, a target prompt word template corresponding to the query intent can be determined from a preset prompt word template library according to the query intent. For example, if the query intent is a simple intent, the target prompt word template is a simple query prompt word template.
[0083] It is understandable that if the user's query requirements are numerous or complex, and there are situations where the intent recognition rules cannot recognize the query requirements, then in a feasible implementation, step S20 may include steps S21' to S23':
[0084] Step S21': Analyze the query information to determine the query requirement.
[0085] It should be noted that the query requirements can be determined by analyzing the query information.
[0086] For example, the query information is: filter out the records with a warning time greater than 2023-01-01 in [SCHEMA_DEV.BSTSUTINF], group by customer, calculate the number of warnings, the number of general suspicious reports, the number of key suspicious reports, and the number of reports to the public security for each group, and return all statistical results. According to the above query information, the query requirement is to query the number of warnings, the number of general suspicious reports, the number of key suspicious reports, and the number of reports to the public security for each group, and return all statistical results.
[0087] Step S22': when the query intent of the query requirement is not identified by the intent identification rule, the query requirement is subjected to intent identification by using the intent identification model to determine the query intent.
[0088] In a specific implementation, the query requirement can be first identified through the intent recognition rules. If the intent recognition rules fail to identify the query intent of the query requirement, the intent recognition model can be directly used to identify the query intent, thereby outputting the user's query intent. For example, based on the above query information, it can be determined that the query intent is a group query.
[0089] Step S23 ′: determining a target prompt word template corresponding to the query intent from a preset prompt word template library according to the query intent.
[0090] In a specific implementation, the corresponding target prompt word template can be determined from a preset prompt word template library according to the query intent. For example, if the query intent is a group query, the target prompt word template is a group query prompt word template.
[0091] like Figure 3 As shown, Figure 3 The figure is a schematic diagram of the specific process of intent recognition. By performing intent recognition on the user's query question, the intent recognition rules or intent recognition models can be used to recognize the query intent and obtain the query intent. For example, if the query intent is an associated query, the corresponding prompt word template can be queried in the prompt word template library through this query intent to obtain the associated query prompt word template.
[0092] Step S30: recall the query information to obtain target data.
[0093] In a specific implementation, question recall may include information extraction, domain knowledge question extraction, and similar case screening, so as to obtain target data. The target data may include data composed of the results of information extraction, the results of domain knowledge question extraction, and the results of similar case screening.
[0094] Step S40: performing language conversion on the target data and the target prompt word template to generate a target structured query language.
[0095] In a specific implementation, multiple data in the target data can be respectively filled into the target prompt word template, so as to perform language conversion to obtain the target structured query language, which is the SQL language obtained by accurately converting the user's natural language.
[0096] In a feasible implementation, step S40 may include step S41:
[0097] Step S41: Fill the target table information, domain knowledge information and preset case information in the target data into corresponding positions in the target prompt word template respectively, complete the language conversion, and generate the target structured query language.
[0098] It is understandable that the target table information, domain knowledge information and preset case information in the target data can be respectively filled into the corresponding positions in the target prompt word template, so that after filling in, the target structured query language is directly generated.
[0099] For example, if the query request is: Please find the customer numbers and names that traded at night in the first quarter of 2024 and whose risk level is marked as high risk, through the above language conversion, the generated SQL statement is as follows:
[0100] SELECT customer number, customer name
[0101] FROM customer transaction table
[0102] WHERE transaction time BETWEEN '02:00:00' AND '06:00:00'
[0103] AND risk level = 'A'
[0104] AND transaction date BETWEEN '2024-01-01' AND '2024-03-31';
[0105] In order to help users better understand the logic and reasoning process that large language models rely on when generating SQL statements and facilitate user review and verification, corresponding explanation information can be attached after the structured language is generated. After step S40, it also includes: analyzing the target structured query language to determine the retrieval path, usage index, and type of operation performed for the query information; generating an execution plan through the retrieval path, usage index, and operation type; adding the execution plan to the target structured query language to interpret the structured query language.
[0106] It should be noted that the interpretation function can be implemented specifically through the SQL interpretation module of the model layer in the language conversion system based on retrieval enhancement. The SQL interpretation module can display the execution plan of the SQL statement, so the target structured query language can be analyzed to determine the retrieval path of the query information, the index used, the type of operation performed (such as sorting, connection, etc.) and the estimated execution cost. The above content is used as the execution plan and added to the target structured query language, which can help users understand how the SQL statement is executed, including how it accesses and operates the data in the database. By analyzing the query plan, users can identify performance bottlenecks, such as unnecessary full table scans or complex connection operations, and then optimize the SQL statement or database structure. For complex queries, the interpretation module can help users understand the logical flow of the query, such as the execution order of nested queries, subqueries, and multi-table connections. When the SQL statement fails to execute, the interpretation module can provide the cause and location of the error to help users quickly locate the problem. In an environment with strict security and compliance requirements, the SQL interpretation module can help auditors check whether the SQL statement complies with security policies and specifications, such as financial auditing, risk management, etc.
[0107] In a feasible implementation, the generated target structured query language data may be subjected to model training to construct a language conversion model. When language conversion is subsequently performed, the language conversion model may be directly used to perform language conversion, thereby improving the efficiency and accuracy of language conversion.
[0108] This embodiment provides a language conversion method based on retrieval enhancement, which responds to a query request and determines query information based on the query request; performs intent recognition on the query information and determines a target prompt word template from a preset prompt word template library; performs question recall on the query information to obtain target data; performs language conversion through the target data and the target prompt word template to generate a target structured query language. Through intent recognition, business knowledge and industry common sense related to the problem are retrieved to solve the problem that the original technical solution is not general enough in a specific field, and through question recall, the problem that the model effect cannot be improved by fine-tuning in a specific field due to computing resource limitations is solved, thereby improving the efficiency and accuracy of language conversion.
[0109] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. Figure 4 , step S30 includes steps S301 to S305:
[0110] Step S301: performing search enhancement on the query information to obtain key fields.
[0111] It should be noted that the retrieval-augmented generation (RAG) technology retrieves the most relevant information from a large amount of data. Through RAG, the business knowledge and industry common sense related to the problem can be retrieved. Therefore, the query information can be retrieved and enhanced to obtain key fields. RAG can quickly integrate the latest information and improve the speed of knowledge update. It can analyze the user's data usage habits to determine the characteristics of data usage habits, which may include: periodicity, especially in periodic reports, the user's table and data extraction SQL are highly similar. The tables and fields used show a 28 effect, which is concentrated in a few tables and fields.
[0112] In a specific implementation, the key fields can be obtained by extracting keywords using the search enhancement technology on the query information. For example, if the query information is: the number of customers at each risk level under the latest statistical date, the key fields are: statistical date, risk level, customer.
[0113] Step S302: extracting information from a preset metadata database based on the key fields to obtain target table information.
[0114] It should be noted that the preset metadata database stores multiple metadata including key elements such as table structure, field attributes, index information, etc. Information is extracted from the preset metadata database through key fields to obtain the target table information most relevant to the query information. The target table information is the table structure containing the key fields.
[0115] In a feasible implementation, step S302 may include steps A11 to A14:
[0116] Step A11: Based on the key fields, an initial table is obtained by screening from a preset metadata database using a matching strategy.
[0117] It is understandable that the matching strategy may be regular matching or vectorized matching, through which the key field is matched with each table data in the preset metadata database, so that the table with the highest matching degree is used as the initial table.
[0118] Step A12: Acquire the original field data in the initial table.
[0119] In a specific implementation, the original field data refers to all field data in the initial table. A single initial table may contain up to 200 fields, while the corresponding query information in the actual question-and-answer or query process involves at most 20 of these fields. Therefore, in order to improve efficiency and reduce resource consumption, information extraction can be performed on the original field data.
[0120] Step A13: extract information from the original field data based on the key field through a field retention strategy to obtain target field data.
[0121] In the specific implementation, the field retention strategy is a high-frequency field retention strategy. Through the key field and high-frequency field retention strategy, a preset number of fields most relevant to the problem are screened out from a large number of redundant fields in the original field data to obtain the target field data. The preset number can be the top 10, top 20, etc.
[0122] Step A14: construct target table information according to the target field data.
[0123] In a specific implementation, after obtaining the target field data, the target table information can be constructed using the target field data. Figure 5 As shown, Figure 5 This is a schematic diagram of the process of extracting information from the preset metadata database to obtain the target table information. The metadata in the data table is retained by high-frequency fields, regular matching, vectorized matching, etc. to obtain the table information required for the query problem. The high-frequency fields are retained as follows: Figure 5As shown on the right, the initial table obtained includes data such as field serial number, field name, field Chinese name, field type, and whether it is used frequently. The initial table includes 83 fields, such as statistical date, customer UID, customer number, customer attribute, customer name, etc. By extracting information from the initial table, the target field data obtained are statistical date, customer UID, customer name, customer's highest card level, certificate issuance date, and customer risk level, as well as the field name, field type, and whether it is used frequently for each target field. Through intelligent extraction of table information, the number of fields is reduced from 83 to 6, achieving a 92.7% field reduction, significantly reducing token overhead while ensuring the relevance and integrity of the data.
[0124] Step S303: extracting domain knowledge questions from the query information to obtain domain knowledge information.
[0125] It should be noted that the extraction of domain knowledge questions is to quickly understand the corresponding domain knowledge when performing language conversion and improve the effect of language conversion. Compared with traditional SQL generation tasks, the application scenarios involved in this patent are more complex. It requires an in-depth understanding of rich background knowledge, compliance with strict data specifications, and adaptation to users' questioning habits.
[0126] Specifically, domain knowledge questions can be extracted from query information to obtain specific domain knowledge, such as Figure 6 As shown, Figure 6 Schematic diagram of the process of extracting domain knowledge questions. For example, a user may ask a query: "Please find the customer number and customer name who traded at night in the first quarter of 2024 and whose risk level was marked as high risk."
[0127] A standard SQL generation model may generate the following SQL statements:
[0128] SELECT customer number, customer name
[0129] FROM customer transaction table
[0130] WHERE trading time LIKE '% Nighttime %' AND risk level = 'high risk'
[0131] AND transaction date BETWEEN '2024-01-01' AND '2024-03-31';
[0132] But the correct query should be:
[0133] SELECT customer number, customer name
[0134] FROM customer transaction table
[0135] WHERE transaction time BETWEEN '02:00:00' AND '06:00:00'
[0136] AND risk level = 'A'
[0137] AND transaction date BETWEEN '2024-01-01' AND '2024-03-31';
[0138] There are two key implicit conditions here: first, "night trading" refers to trading that occurs between 2 a.m. and 6 a.m.; second, the actual code for "high risk level" in the system is "A". This patent builds a domain knowledge base that can accurately retrieve and integrate relevant knowledge involved in user questions, thereby ensuring that the generated SQL query statements can accurately meet the actual needs of users. Domain knowledge includes knowledge covered by caliber libraries, code value libraries, and PDF documents. Through regular matching, vectorized matching, and BM25 (Best Matching 25) ranking function processing, caliber code value and other information are obtained, and then specific domain knowledge information is obtained.
[0139] Step S304: Screen similar cases based on the key fields to obtain preset case information.
[0140] In the specific implementation, when designing prompt words, incorporating appropriate cases can significantly improve the performance of the model. Through the analysis of user question and answer records, we found that users' questions are often highly consistent, and highly relevant cases can provide contextual information for the model to help the model better understand the background and needs of the problem. Therefore, selecting cases that are highly relevant to the current question can significantly improve the accuracy and applicability of the answers generated by the model. Therefore, similar cases can be screened in historical cases based on key fields, so as to obtain cases that are highly similar to the key fields, and thus obtain preset case information, which includes the most similar cases and their corresponding SQL statements.
[0141] In a feasible implementation, step S304 may include steps B11 to B14:
[0142] Step B11: Obtain historical case data from the structured query language case library.
[0143] It can be understood that the structured query language case library, that is, the SQL case library, can obtain historical case data in the structured query language case library.
[0144] Step B12: Calculate the semantic similarity and structural similarity between the query information and the historical case data based on the key fields to obtain a similarity calculation result.
[0145] In specific implementations, the similarity between the query information and the historical case data can be calculated based on key fields, including semantic similarity and structural similarity. Semantic similarity is used to retrieve cases related to the field, and Jaccard similarity is used to identify structurally similar cases, thereby obtaining similarity calculation results. The similarity calculation results include the degree of similarity between each historical case and the query information, and the degree of similarity can be reflected through specific values.
[0146] Step B13: Filtering a preset case from the historical case data according to the similarity calculation result, and obtaining a historical structured query language corresponding to the preset case.
[0147] In a specific implementation, a preset case may be selected from the historical case data according to the similarity calculation result, that is, the case with the highest similarity to the query information. For example, Example 1 is:
[0148] 1. Please collect the basic information of customers who reported gambling problems in the first quarter of 2024, including customer number, customer name and account opening institution.
[0149] 2. Please count the number and total amount of inbound and outbound transactions in the past six months for customers who reported gambling problems in the second quarter of 2024.
[0150] From the above case one, we can see that the similarity of questions is mainly reflected in two aspects: first, the similarity of the question topics (semantic level). For example, case one revolves around the topic of "reporting gambling problems".
[0151] For example, Example 2 is:
[0152] 1. Please check the non-performing loan ratio of Hangzhou Branch in the first quarter of 2024.
[0153] 2. Please check the non-performing loan ratio of Shenzhen Branch in the second quarter of 2024.
[0154] From the above case 1, we can see that the similarity of questions is mainly reflected in two aspects: first, the similarity of the question topics (semantic level), for example, the questions in case 1 are all about the topic of "reporting gambling problems". Second, the similarity of the question structure (SQL level), such as the query pattern "xx time, xx branch's non-performing loan rate" in case 2.
[0155] After obtaining the preset case, you can get the historical structured query language corresponding to the preset case. The historical structured query language is the SQL language generated from the natural language of the user's historical queries. The preset case provides a specific usage scenario to help the model understand the context of the problem and the semantics behind it. It can more accurately understand the task requirements and expected output format, and reduce the possibility of generating invalid or erroneous output.
[0156] Step B14: Obtaining preset case information according to the preset case and the historical structured query language.
[0157] In a specific implementation, the preset case and the historical structured query language corresponding to the preset case may be used as the preset case information.
[0158] like Figure 7 As shown, Figure 7 Schematic diagram of the process of screening similar cases, by querying historical case data in the case library, and using semantic similarity and structural similarity (Jaccard similarity) to query highly related cases. For example, the query information is: query the non-performing loan rate of Bank A in the second quarter of 2024.
[0159] The historical case data obtained through the case library includes:
[0160] 1. Please help me count the total number of transactions and the amount involved in the last 6 months among customers whose bank cards were frozen for suspected transfer of funds on 2024-07-23?
[0161] 2. Help me count the total number of outgoing and incoming transactions and the amount involved in the past six months among customers whose bank cards were frozen due to suspected gambling on 2023-06-21?
[0162] 3....
[0163] 4. Query the non-performing loan ratio of Branch B in the first quarter of 2024.
[0164] Through semantic similarity and structural similarity screening, the preset case obtained is to query the non-performing loan rate of Branch B in the first quarter of 2024, thereby obtaining the historical structured query language corresponding to the preset case.
[0165] Step S305: Obtain target data through the target table information, the domain knowledge information and the preset case information.
[0166] In a specific implementation, the target table information, domain knowledge information and preset case information can be used as target data, so that the target data can be filled into the target prompt word template to generate a target structured query language.
[0167] This embodiment obtains key fields by performing retrieval enhancement on the query information; extracts information from a preset metadata database based on the key fields to obtain target table information; extracts domain knowledge questions from the query information to obtain domain knowledge information; screens similar cases based on the key fields to obtain preset case information; and obtains target data through the target table information, the domain knowledge information, and the preset case information. By performing information extraction, domain knowledge question extraction, and similar case screening, the relevance and integrity of the data are ensured, and the task requirements and expected output format can be accurately understood, reducing the possibility of generating invalid or erroneous outputs.
[0168] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the language conversion method based on retrieval enhancement of the present application. More forms of simple transformations based on this technical concept are all within the scope of protection of the present application.
[0169] This application also provides a language conversion device based on retrieval enhancement, please refer to Figure 8 , the language conversion device based on retrieval enhancement includes:
[0170] The response module 10 is used to respond to the query request and determine the query information based on the query request.
[0171] The recognition module 20 is used to perform intent recognition on the query information and determine a target prompt word template from a preset prompt word template library.
[0172] The recall module 30 is used to recall the query information to obtain target data.
[0173] The conversion module 40 is used to perform language conversion through the target data and the target prompt word template to generate a target structured query language.
[0174] The language conversion device based on retrieval enhancement provided by the present application adopts the language conversion method based on retrieval enhancement in the above embodiment, which can solve the technical problem of low accuracy of language conversion. Compared with the prior art, the beneficial effects of the language conversion device based on retrieval enhancement provided by the present application are the same as the beneficial effects of the language conversion method based on retrieval enhancement provided by the above embodiment, and other technical features in the language conversion device based on retrieval enhancement are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0175] In one embodiment, the recall module 30 is also used to perform retrieval enhancement on the query information to obtain key fields; extract information from a preset metadata database based on the key fields to obtain target table information; extract domain knowledge questions from the query information to obtain domain knowledge information; screen similar cases based on the key fields to obtain preset case information; and obtain target data through the target table information, the domain knowledge information and the preset case information.
[0176] In one embodiment, the recall module 30 is also used to obtain historical case data from a structured query language case library; calculate the semantic similarity and structural similarity between the query information and the historical case data based on the key fields to obtain a similarity calculation result; filter a preset case from the historical case data based on the similarity calculation result, and obtain the historical structured query language corresponding to the preset case; and obtain preset case information based on the preset case and the historical structured query language.
[0177] In one embodiment, the recall module 30 is also used to filter out an initial table from a preset metadata database using a matching strategy based on the key field; obtain original field data in the initial table; extract information from the original field data based on the key field using a field retention strategy to obtain target field data; and construct target table information based on the target field data.
[0178] In one embodiment, the identification module 20 is also used to analyze the query information to determine the query requirements; identify the query requirements through intention recognition rules to determine the query intent; and determine the target prompt word template corresponding to the query intent from a preset prompt word template library based on the query intent.
[0179] In one embodiment, the identification module 20 is also used to analyze the query information to determine the query requirements; when the query intent of the query requirement is not identified through the intent recognition rule, the query requirement is identified through the intent recognition model to determine the query intent; and according to the query intent, a target prompt word template corresponding to the query intent is determined from a preset prompt word template library.
[0180] In one embodiment, the conversion module 40 is further used to fill the target table information, domain knowledge information and preset case information in the target data into corresponding positions in the target prompt word template, complete language conversion, and generate a target structured query language.
[0181] In one embodiment, the conversion module 40 is further used to analyze the target structured query language to determine the retrieval path, usage index, and type of operation performed for the query information; generate an execution plan based on the retrieval path, usage index, and operation type; and add the execution plan to the target structured query language to interpret the structured query language.
[0182] The present application provides a language conversion device based on retrieval enhancement, and the language conversion device based on retrieval enhancement includes: at least one processor; and a memory connected to the at least one processor in communication; wherein the memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the language conversion method based on retrieval enhancement in the above-mentioned embodiment 1.
[0183] Reference below Fig. 9 , which shows a schematic diagram of the structure of a language conversion device based on retrieval enhancement suitable for implementing the embodiment of the present application. The language conversion device based on retrieval enhancement in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig. 9 The illustrated language conversion device based on retrieval enhancement is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0184] like Fig. 9As shown, the language conversion device based on retrieval enhancement may include a processing device 1001 (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In the RAM 1004, various programs and data required for the operation of the language conversion device based on retrieval enhancement are also stored. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: input devices 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 1003 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 1009. The communication device 1009 can allow the retrieval-enhanced language conversion device to communicate wirelessly or wired with other devices to exchange data. Although the retrieval-enhanced language conversion device based on various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0185] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.
[0186] The language conversion device based on retrieval enhancement provided by the present application adopts the language conversion method based on retrieval enhancement in the above embodiment, which can solve the technical problem of low accuracy of language conversion. Compared with the prior art, the beneficial effects of the language conversion device based on retrieval enhancement provided by the present application are the same as the beneficial effects of the language conversion method based on retrieval enhancement provided by the above embodiment, and other technical features in the language conversion device based on retrieval enhancement are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0187] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.
[0188] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0189] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the language conversion method based on retrieval enhancement in the above-mentioned embodiment.
[0190] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.
[0191] The computer-readable storage medium may be included in the retrieval-enhanced language conversion device; or may exist independently without being assembled into the retrieval-enhanced language conversion device.
[0192] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the retrieval-enhanced language conversion device, the retrieval-enhanced language conversion device: responds to a query request and determines query information based on the query request; performs intent recognition on the query information and determines a target prompt word template from a preset prompt word template library; performs question recall on the query information to obtain target data; and performs language conversion through the target data and the target prompt word template to generate a target structured query language.
[0193] Computer program code for performing the operations of the present application may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0194] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0195] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.
[0196] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned language conversion method based on retrieval enhancement, and can solve the technical problem of low accuracy of language conversion. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the language conversion method based on retrieval enhancement provided by the above-mentioned embodiment, and will not be repeated here.
[0197] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned language conversion method based on retrieval enhancement when executed by a processor.
[0198] The computer program product provided by the present application can solve the technical problem of low accuracy of language conversion. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the language conversion method based on retrieval enhancement provided by the above embodiment, which will not be repeated here.
[0199] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.
Claims
1. A language conversion method based on retrieval enhancement, characterized in that: The language conversion method based on retrieval enhancement includes: Responding to a query request and determining query information based on the query request; Performing intent recognition on the query information, and determining a target prompt word template from a preset prompt word template library; Perform question recall on the query information to obtain target data; The target structured query language is generated by performing language conversion on the target data and the target prompt word template.
2. The method according to claim 1, characterized in that The step of recalling the query information to obtain target data includes: Performing retrieval enhancement on the query information to obtain key fields; Extract information from a preset metadata database based on the key fields to obtain target table information; Extracting domain knowledge questions from the query information to obtain domain knowledge information; Filter similar cases based on the key fields to obtain preset case information; The target data is obtained through the target table information, the domain knowledge information and the preset case information.
3. The method according to claim 2, characterized in that The step of screening similar cases based on the key fields to obtain preset case information includes: Obtain historical case data from the structured query language case library; Calculating semantic similarity and structural similarity between the query information and the historical case data according to the key fields to obtain a similarity calculation result; Filtering a preset case from the historical case data according to the similarity calculation result, and obtaining a historical structured query language corresponding to the preset case; Preset case information is obtained according to the preset case and the historical structured query language.
4. The method according to claim 2, characterized in that The step of extracting information from a preset metadata database based on the key field to obtain target table information includes: Based on the key fields, a matching strategy is used to filter and obtain an initial table from a preset metadata database; Obtaining original field data in the initial table; Extracting information from the original field data using a field retention strategy based on the key field to obtain target field data; Build target table information according to the target field data.
5. The method according to claim 1, characterized in that The step of performing intent recognition on the query information and determining a target prompt word template from a preset prompt word template library comprises: Analyze the query information to determine the query requirements; Performing intent recognition on the query requirement through intent recognition rules to determine the query intent; According to the query intent, a target prompt word template corresponding to the query intent is determined from a preset prompt word template library.
6. The method according to claim 1, characterized in that The step of performing intent recognition on the query information and determining a target prompt word template from a preset prompt word template library comprises: Analyze the query information to determine the query requirements; When the query intent of the query requirement is not identified by the intent identification rule, the query intent is identified by the intent identification model to determine the query intent; According to the query intent, a target prompt word template corresponding to the query intent is determined from a preset prompt word template library.
7. The method according to any one of claims 1 to 6, characterized in that The step of performing language conversion through the target data and the target prompt word template to generate a target structured query language comprises: The target table information, domain knowledge information and preset case information in the target data are respectively filled into corresponding positions in the target prompt word template to complete the language conversion and generate the target structured query language.
8. The method according to any one of claims 1 to 6, characterized in that The method further comprises: Analyze the target structured query language to determine the search path, index to be used, and type of operation to be performed for the query information; Generate an execution plan according to the search path, the usage index and the operation type; The execution plan is added to the target structured query language to perform structured query language interpretation.
9. A language conversion device based on retrieval enhancement, characterized in that: The device comprises: A response module, configured to respond to the query request and determine query information based on the query request; A recognition module, used to perform intent recognition on the query information and determine a target prompt word template from a preset prompt word template library; A recall module, used to recall the query information to obtain target data; The conversion module is used to perform language conversion through the target data and the target prompt word template to generate a target structured query language.
10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the language conversion method based on retrieval enhancement according to any one of claims 1 to 8 are implemented.
Citation Information
Cited By
Method and device for realizing text SQL (Structured Query Language) based on cue words of large language model
CN120030041A
Question and answer mode data retrieval and large model summarization method and device, equipment and medium
CN120162425A
Data processing method and system, electronic equipment and storage medium
CN120371879A
Network traffic query processing method and device, equipment, storage medium and program product
CN121166986A
Data query method and system
CN121255828A