A mode linking method and system in a large-scale database scenario
A multi-stage pattern linking algorithm addresses the complexity of querying large-scale databases by using problem parsing, semantic linking, and LLM locking to accurately identify relevant data tables, enhancing query accuracy and efficiency.
Patent Information
- Application Number
- CN202411974625.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2044-12-31
AI Technical Summary
Existing database query technologies face challenges in efficiently handling large-scale databases, where the complexity of identifying relevant data tables for user queries is high due to the vast number of tables, leading to inefficiencies in query accuracy and user experience.
A multi-stage collaborative algorithm for pattern linking in large-scale databases, utilizing problem parsing and disambiguation, semantic initial linking, and Large Language Model (LLM) locking to accurately retrieve relevant data tables from a vast number of tables, incorporating Few-shot learning and knowledge distillation techniques for enhanced accuracy.
The solution significantly improves query accuracy by reducing noise and complexity in pattern linking, enabling precise data table identification and enhancing the efficiency of database queries in large-scale environments.
Smart Images

Figure CN119377455B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of database intelligent query, and in particular, relates to a mode linking method and system in a large-scale database scenario. Background Art
[0002] Database query requires users to master professional SQL technology. The professionalism and complexity of this technology hinders ordinary users from querying data, which in turn affects the efficient application and promotion of data. Intelligent database query alleviates this problem. Existing intelligent query can be roughly divided into two categories. One is the template filling method, which predefines query templates and applies models or rules to fill slots. This type of method is simple and the query type is relatively fixed; the other type is to learn the mapping relationship between natural language and SQL query statements with the help of models, and generate SQL statements based on natural language. This type of method is more flexible and has higher requirements on model capabilities. These two types of methods have their own application scenarios, and the common point is that they both need to select data tables related to the problem. However, most of the existing research focuses more on the research of the SQL generation stage, assuming that the scenario is that the data table is known or there are only a few limited data tables. Open source test sets such as Spider, WikiSQL, Bird, etc. also focus on measuring the model's ability to generate SQL query statements, ignoring the model linking stage. However, real applications are queries for large-scale databases, which means that the number of data tables is huge, and it is inevitable that all data table schemas cannot be input into the model.
[0003] Schema Linking is a technology used in text-to-SQL generation. Its main purpose is to identify the data tables used for query from the database based on natural language, identify the elements in the database related to the user's question, and filter out irrelevant parts to reduce noise and input complexity. Specifically, before generating SQL, Schema Linking uses some methods to find the tables and columns related to the user's question in advance, and then inputs the simplified database schema of this information into a large language model, thereby improving the performance of SQL generation.
[0004] Existing methods of pattern linking can be divided into two categories: retrieval-recall based and model fine-tuning based. The retrieval-recall based solution is to use methods such as text retrieval, semantic retrieval or hybrid retrieval to recall relevant data tables from the database according to the question. This method is relatively simple to operate and has good effects in scenarios where the questions are professional and clear, the data tables have obvious characteristics and the differences between data tables are large. However, natural language queries are usually highly complex and may be ambiguous, and retrieval and recall are difficult. Another type of method based on model fine-tuning is to use data table related information such as schema, etc., so that the model can master the relevant knowledge of the data table in advance, and construct the user's natural language query and data table into a question-answer pair dataset for fine-tuning. This type of solution can significantly improve the accuracy of pattern linking with the help of the model's understanding and reasoning ability, but the dataset construction is very difficult, and all the dataset table information must be learned in advance. It may not achieve good results when the data table is expanded, and is more suitable for scenarios with fixed databases. Summary of the invention
[0005] In order to solve the above technical problems, the present invention provides a pattern linking method and system in a large-scale database scenario. Aiming at the pattern linking problems existing in the intelligent query process of database in the large-scale database scenario, a semantic-based step-by-step multi-path pattern linking algorithm is designed. Through multi-stage collaboration such as problem analysis and disambiguation reconstruction, semantic-based pattern initial linking, and LLM-based pattern locking, it can automatically recall data tables related to user problems from massive data tables, lock more accurate data table pattern information, and aim to improve the accuracy of intelligent query of database.
[0006] The technical solution provided by the present invention is as follows:
[0007] A schema linking method in a large-scale database scenario includes the following steps:
[0008] S1. Construct user queries into prompts and input them into LLM for query parsing and disambiguation reconstruction;
[0009] S2. Perform a model initial link based on the results of S1 and select data tables related to the user query from the database;
[0010] S3. While performing the initial linking of the patterns, recall the few shot learning examples according to the user query;
[0011] S4. Based on the initial pattern linking results and the recalled learning examples, the prompts are constructed and input into the LLM for pattern link locking, giving the final data table related to the user query.
[0012] Further, step S1 includes:
[0013] LLM classifies user queries and determines whether the user query exceeds the scope of the current database. If it exceeds the scope, LLM will give an answer based on the intrinsic knowledge of the model and explain that the query was not performed in the database;
[0014] If it does not exceed the current database range, LLM determines whether the user query is a complex query. If it is a complex query, it will be converted into an original query list containing multiple simple sub-queries, and each sub-query in the original query list will be disambiguated and reconstructed, and the corresponding transcribed query list will be returned; the complex query refers to a user query that involves nested query statements or a single query statement cannot complete the query requirements.
[0015] Further, step S2 includes:
[0016] The vector model is used to vectorize each sub-question in the original query list and the transcribed query list to obtain the corresponding question vector;
[0017] Semantically matching each question vector with a data table vector in a vector database, and recalling data tables whose matching degree is greater than a set degree threshold; the vector database stores vectorized data table annotation information and question-answering templates;
[0018] The recalled data tables are merged and deduplicated, and filtered and sorted according to the matching scores to obtain a list of initial links of the patterns.
[0019] Furthermore, in step S3, a vector model is used to recall examples highly relevant to the user query from the perspectives of semantic similarity and query similarity; the semantic similarity refers to the same queried data table and similar semantics of the query statements, and the query similarity refers to the low semantic similarity of the query statements but similar query types and the same queried data table;
[0020] The example recall process includes: filtering the question and answer templates in the question and answer template set that point to the same data table as the current query, vectorizing the user query statement and the filtered template set respectively and then calculating the semantic similarity, selecting the question and answer templates whose semantic similarity is higher than the set threshold as semantic similarity examples, selecting the question and answer templates whose semantic similarity is not higher than the set threshold but have similar query types as query similarity examples, and taking the semantic similarity examples with the highest semantic similarity and the query similarity examples with the highest query type similarity as learning examples.
[0021] Furthermore, in step S4, LLM first determines whether the input prompt is sufficient to support the user query. If it is sufficient to support the user query, the final data table related to the user query is returned in the form of a list; otherwise, the user is informed and asked to clarify the user's query intention, and the mode linking is continued according to the conversation record; the input of the prompt includes the user query statement, learning examples, transcribed query list, the data table corresponding to the query list and its interpretation.
[0022] Furthermore, the vector model adopts the fine-tuned BGM-M3 model. The process of constructing the fine-tuning data set for training the BGM-M3 model is as follows: focusing on the data tables in the current database, common query questions and expected answers are collected to preliminarily form a question set. By annotating the questions with positive examples and generating negative examples in batches based on scripts, a fine-tuning data set for the vector model is formed. The annotated objects of the positive examples include data tables related to the questions and template questions and answers related to the questions.
[0023] Furthermore, the knowledge distillation technology is used to train the vector model: corresponding teacher scores are added to the positive and negative samples in the fine-tuning dataset of the vector model, and the vector model is trained using the fine-tuning dataset with the teacher scores added, and the training loss is equal to the sum of the distillation loss and the model prediction loss; the distillation loss is the difference between the predicted value of the vector model and the teacher score, calculated using the KL divergence; the teacher score comes from the LLM's similarity score between the positive / negative samples and the query question.
[0024] Furthermore, the LLM adopts the Qwen2.5-32B-Instruct model fine-tuned by PiSSA. The process of constructing the fine-tuning dataset for training the Qwen2.5-32B-Instruct model is as follows: labeling question and answer pairs according to task requirements based on the question set, and the task requirements include question parsing and disambiguation reconstruction, and pattern link locking; labeling the answers to each question based on the question, and constructing the dataset in the form of "question-answer-idea"; adding critical logic, and constructing the dataset in the form of "question-wrong answer-error reminder-idea combined with correct answer".
[0025] A mode linking system based on the above method comprises:
[0026] Query interface module: used to receive the query input by the user and pass it to the subsequent query parsing module;
[0027] Query parsing module: used to parse and disambiguate user queries, determine whether the query exceeds the current database scope, and generate a simplified sub-query list for complex queries;
[0028] Model initial linking module: Based on the query list generated by the query parsing module, it performs preliminary screening and linking of data tables: vectorizes the query through the vectorization model and searches for data tables that match the query semantics;
[0029] Example recall module: recalls the most relevant examples to the query from the perspectives of semantics and query similarity through the vector model, including semantically similar examples and query similar examples;
[0030] Pattern locking module: Based on the initial pattern link results and recalled examples, the final query prompt is generated and input into LLM for final pattern link locking to obtain the data table most relevant to the query.
[0031] Compared with the prior art, the present invention has at least the following beneficial effects:
[0032] (1) The designed step-by-step multi-path pattern linking algorithm improves the accuracy of pattern linking through the collaboration of each stage, including question parsing and disambiguation reconstruction, pattern initial linking, and pattern link locking based on LLM. In the question parsing and disambiguation reconstruction stage, LLM is used to complete the user question classification routing, convert complex queries into subquery lists, and disambiguate and reconstruct each subquery, providing a richer and more multi-dimensional information description for the pattern linking stage and reducing the difficulty of pattern linking.
[0033] (2) For large-scale database scenarios with complex and diverse data tables, a parallel multi-dimensional semantic retrieval recall strategy is designed to achieve initial screening of data tables and narrow the scope of pattern links. The vector model is fine-tuned using knowledge distillation, and the initial recall of relevant data tables from massive databases is achieved through diversified data table pattern representation and optimized vector recall methods.
[0034] (3) In the pattern link locking stage, a logical progressive data fine-tuning strategy was designed, and the Qwen2.5-32B-Instruct model was efficiently fine-tuned in combination with PiSSA (Principal Singular Values and Singular Vectors Adaptation). In addition, the existing Few-shot strategy was improved to recall template examples in parallel from the perspectives of semantic similarity and query similarity. The model fine-tuning was combined with its contextual learning ability to efficiently lock the data tables related to the query. If the model determines that the user's expression is unclear or the query is vague, it will ask questions to obtain more specific information and re-lock the pattern link. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0036] Figure 1 It is a schematic diagram of a flow chart of a mode linking method provided by an embodiment of the present invention;
[0037] Figure 2 It is a schematic diagram of the framework of a mode linking system provided by an embodiment of the present invention;
[0038] Figure 3 It is a schematic diagram of the workflow of a mode linking system provided in one embodiment of the present invention. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, other embodiments obtained by ordinary technicians in this field without making creative work are all within the scope of protection of the present invention.
[0040] Embodiment 1
[0041] This embodiment provides a model linking method in a large-scale database scenario. Figure 1 As shown in the figure, the main process of this method is as follows: First, data is collected and labeled according to task requirements, and the data table information is annotated in detail to enrich the information interpretation level from a diversified perspective. The labeled data are used to construct data sets for fine-tuning the vector model BGE-M3 and the LLM model Qwen2.5-32B-Instruct. Next, the vector model is fine-tuned using knowledge distillation technology to improve the accuracy of its pattern initial linking task and dynamic multi-way Few-shot recall task. The fine-tuned vector model is used to vectorize the data table related knowledge and question and answer templates and enter them into the vector database. At the same time, a logical progressive fine-tuning data set is constructed according to the task and the LLM is fine-tuned to optimize the performance of the LLM in user question parsing, disambiguation reconstruction and pattern locking tasks, and the fine-tuned model is deployed for reasoning. Then, a step-by-step multi-path linking algorithm is used to parse and disambiguate the user's questions through LLM, and then a parallel multi-dimensional recall strategy is used based on the vector model to initially link the patterns to initially narrow the scope of the links. At the same time, a dynamic few-shot recall strategy is used to recall learning examples from the two paths of semantic similarity and query similarity. Finally, the context learning ability of the fine-tuned LLM is used to lock the pattern links.
[0042] Specifically, the method of this embodiment may include the following steps:
[0043] S1. Focusing on the data tables in the current database, we collect common query questions and expected answers to initially form a question set. By annotating positive examples of the questions and generating negative examples in batches based on scripts, we form a fine-tuning dataset for the vector model. The annotated objects of the positive examples include data tables related to the questions and template questions and answers related to the questions, which are used for data table initial screening and dynamic example recall tasks respectively. The large model fine-tuning dataset annotates question and answer pairs according to task requirements, involving two major tasks: question parsing and disambiguation reconstruction, and pattern link locking.
[0044] To improve the quality of the data set, low-quality data can be removed during the annotation process, and batch deduplication can be performed after the annotation is completed. In addition, in order to assist the model to better understand the data table information, each data table is interpreted from a variety of perspectives such as table name, column definitions, and common application scenarios.
[0045] S2. Fine-tune the BGE-M3 model based on the fine-tuning dataset. Since the designed dynamic few shot learning example screening strategy needs to recall two types of examples, semantic similarity and query similarity, respectively, it is difficult to distinguish between the two types of recall in a single model. Considering that these two recall tasks can be performed in parallel, this solution constructs and fine-tunes positive and negative examples for semantic similarity and query similarity, that is, trains two BGE-M3 models. For the dataset of the data table initial screening task, the fine-tuning datasets of the two models are added. Both models can implement the task call, which will be beneficial to GPU load balancing. The fine-tuned vector model is used to construct the vector database. The data table related information and question and answer templates annotated in S1 are vectorized and entered into the vector database for subsequent data table initial linking and few shot learning example recall.
[0046] In order to optimize the fine-tuning effect of the vector model, knowledge distillation technology is used for model training. In addition to positive samples and generated negative samples, the data also needs to include the teacher scores of each positive and negative sample, such as: {"query": str, "pos": List[str], "neg":List[str], "pos_scores": List[int], "neg_scores": List[int]}. The teacher score needs to come from a model with better performance than the current model to guide the current model. This solution uses LLM (such as Qwen2.5-72B-Instruct) to score positive and negative samples from 0 to 1 as the teacher score of each data. The distillation loss is the difference between the current model prediction value and the teacher model soft label. The distillation loss is calculated using KL divergence:
[0047] ,
[0048] in, p(x) is the model soft label value, that is, the teacher score, q(x) is the model prediction value, and the final loss function can be obtained by adding the distillation loss to the model prediction loss.
[0049] S3. The question-answering dataset is processed into a high-quality fine-tuning dataset using a logical progressive data construction strategy. The specific approach is as follows: First, the answers to each question are annotated with detailed solution ideas, in order to assist the model in learning its way of thinking and enhance the generalization ability of the model; then the dataset is constructed in the form of "question-answer-idea", such as: {"user": query, "assistant": answer, "user":"How did you get this result? Give a detailed process", "assistant": process}; Finally, critical logic is added to construct the dataset in the form of "question-wrong answer-wrong reminder-idea combined with correct answer", such as: {"user": query, "assistant": wrong answer,"user":"This answer is wrong, think again and give the correct answer", "assistant": "process, the correct answer should be: answer"}. For critical logic data, when fine-tuning the model, only the loss of the last round of dialogue is calculated, and the loss of the previous wrong answers is not calculated.
[0050] After the data set is built, the PiSSA fine-tuning method is used to efficiently fine-tune the Qwen2.5-32B-Instruct model, which is different from LORA, which uses a low-rank matrix to approximate the model weight matrix. W PiSSA uses singular value decomposition to split the original weights into primary singular values. and the residual is singular The value is divided into two parts, the residual singular value is frozen, and the singular value is split into two matrices A and B The product of . W The singular value decomposition of ,in, , , , , Initialize two trainable matrices using the principal singular values and singular vectors and ,in, for Since the main singular value part is much larger than the residual singular value part, the training You can fine-tune a small number of parameters to simulate fine-tuning Based on the above principles, LLM is trained with fine-tuning instructions, and the fine-tuned model is deployed using vLLM.
[0051] S4. Construct the user's natural language query into prompts and input them into the fine-tuned LLM for question parsing and disambiguation reconstruction. The specific steps are as follows:
[0052] Step 1. Let LLM classify the problem and determine whether it is a query problem supported by the system. The query scope should not exceed the current database scope. If it exceeds the scope, the answer is given directly based on the intrinsic knowledge of the model and it is stated that no query is performed in the database.
[0053] Step 2. If it is a system support query problem, LLM further determines whether the current query is a complex query. The definition of a complex query is that the query statement involves nesting or a single query statement cannot complete the query requirement. If it is a complex query, the user query is converted into a subquery list. There are many different methods in the prior art for decomposing a complex query into multiple simple subqueries, such as single-step decomposition (Measuring and Narrowing the Compositionality Gap in Language Models), multi-step decomposition (ReAct: Synergizing Reasoning and Acting in Language Models), etc., which will not be repeated here.
[0054] Step 3. LLM disambiguates and reconstructs each subquery in the query list. The user's expression is more like daily expression. Subsequent recall based directly on the user's natural language may cause ambiguity and increase the difficulty of query. Therefore, the user query is first expressed and optimized to facilitate model understanding, and the transcribed query list corresponding to the original query list is returned.
[0055] The above process is constructed into prompts, and a fine-tuned LLM is called once to complete question parsing and disambiguation reconstruction, and let the model output in the agreed format.
[0056] S5. Due to the large number of data tables in large-scale databases, it is difficult to directly select data tables for querying questions. Therefore, the parallel multi-dimensional semantic recall method is first used to perform pattern initial linking, that is, first select data tables that may be related to the question from the database. The specific approach is to first use the fine-tuned BGE-M3 model to vectorize each question in the query list. In order to avoid missing queries, each sub-question of the original query list is also vectorized. To reduce latency, the vector model is called in parallel to process the sub-questions in the list; then, the original and transcribed question vectors are semantically matched with the data table vector database constructed in S2 respectively. The matching principle is to recall all data tables greater than the threshold and add them to the candidate table list. If the number of recalled data tables is less than 3, the TOP3 data set tables are recalled. The reason for this design is that recalling redundant tables will not significantly affect the subsequent process, but omitting necessary data tables will directly lead to subsequent process errors; finally, post-processing is performed. The data tables recalled before and after the transcription of each sub-question are first merged and deduplicated, and then sorted according to the score. When the number of merged candidate tables exceeds 3, the data tables below the threshold can be deleted to obtain the final pattern initial link list.
[0057] S6. While performing the initial linking of the patterns, two fine-tuned BGE-M3 models are used to recall the few shot learning examples based on the user query. In addition to its strong understanding and reasoning capabilities, LLM also has excellent contextual learning capabilities. Few shot uses the contextual learning capabilities of LLM to improve the performance of the model, and the quality of the selected examples is crucial to the model learning effect. This solution improves the few shot example selection strategy, and recalls the most relevant examples to the question from the perspectives of semantic similarity and query similarity. Semantic similarity here refers to questions that query the same data table and have similar semantics. The semantic similarity recall process is: filter the question and answer templates in the question and answer template set that point to the same data table as the current query, vectorize the question and the filtered template set respectively, and calculate the semantic similarity, and select the question and answer template with the highest similarity as the example. Query similarity means that the semantic similarity between texts is low, but the query type, such as nesting and table association similarity, also needs to point to the same data table. Call two BEG-M3 models in parallel to recall the top 1 question and answer templates with semantic similarity and query similarity as examples.
[0058] S7. Based on the initial pattern linking results of S5 and the few shot learning examples recalled in S6, construct prompts and input them into the fine-tuned Qwen2.5-32B-Instruct model for final pattern linking. The input of the prompt includes the user's original natural language query, the transcribed sub-query list, the relevant data tables corresponding to the query list, the interpretation of these data tables, and two learning examples related to the question. The task of LLM is to judge whether the information is sufficient to support the user's query based on the above information. If there is insufficient or ambiguous information, the user needs to be informed and asked to further clarify the user's query intention, and the conversation record is used as the input LLM for pattern linking. If the information is sufficient to support the user's query, the final pattern linking result is returned in the form of a list. At this point, LLM has completed the pattern locking task under a large-scale database.
[0059] Embodiment 2
[0060] Based on the above method, this embodiment provides a model linking system in a large-scale database scenario. The system has functional modules corresponding to the above method and can achieve the technical effects of the above method.
[0061] Combination Figure 2 and Figure 3 ,The overall architecture of the system can be divided into the following main modules:
[0062] 1. User Query Interface Module: This module is used to receive the query input by the user and pass it to the subsequent query parsing module. The user can enter the question in natural language, and the system will be responsible for understanding and processing the question.
[0063] 2. Query parsing module: This module is responsible for parsing and disambiguating user queries, determining whether the query exceeds the current database scope, and generating a simplified subquery list for complex queries. Specifically, if the user query exceeds the database scope, LLM will provide an answer based on the knowledge in the model. If the query is within the database scope, LLM will disambiguate and reconstruct the query, and the complex query will be broken down into multiple simple subqueries. By accurately parsing user queries, this module ensures that the subsequent pattern linking process can correctly respond to user intent. For complex queries, it can provide more detailed disassembly and answers, improving the flexibility and accuracy of queries.
[0064] 3. Model initial linking module: Based on the query list generated by the query parsing module, this module performs preliminary screening and linking of data tables. The query is vectorized through the vectorization model to find data tables that match the query semantics. Specifically, the workflow of this module is as follows:
[0065] Vectorize the original query and its transcribed query to generate a question vector;
[0066] Match with the table vectors stored in the database and recall the database tables related to the query;
[0067] De-duplicate, sort, and filter the recalled data tables to generate a list of schema links.
[0068] Through vectorization and matching technology, the module can quickly filter out database tables related to the query and provide preliminary data support for subsequent pattern locking.
[0069] 4. Example recall module: The vector model is used to recall the most relevant examples to the query from the perspectives of semantics and query similarity, mainly including semantically similar examples and query similar examples. Specifically, the most semantically similar template is found by matching the vectorized question-and-answer template with the query. For queries with low semantic similarity, templates with similar query types are recalled. By recalling and filtering relevant examples, this module can help the system understand user intent more accurately during query processing and improve the accuracy of the final returned data table.
[0070] 5. Pattern locking module: Based on the preliminary linking results and recalled examples, the final query prompt is generated and input into LLM for final pattern link locking to obtain the database table most relevant to the query.
[0071] If the prompt is not sufficient to support the query, the system will ask the user questions to clarify the query intent and continue with the schema linking. Through further processing by LLM, the module ensures the relevance and accuracy of the final data table to the user's query and optimizes the user experience.
[0072] 6. Model fine-tuning module: By constructing corresponding fine-tuning datasets, the existing vector model and LLM model are fine-tuned to improve their performance in specific databases and query scenarios.
[0073] In summary, the pattern linking system has several innovative features, which give it a significant advantage in large-scale database query processing tasks. First, the system realizes an efficient pattern linking process by vectorizing user queries and semantically matching them with tables in the database. It can quickly find tables related to user queries in massive data, significantly improving the query response speed and accuracy. Secondly, the system can handle complex queries. By disambiguating, reconstructing and decomposing queries, it can convert nested queries or multi-condition queries into multiple simple sub-queries, and parse and match them one by one, which makes the system highly adaptable to a variety of complex query scenarios. In addition, the system adopts an example recall mechanism based on semantics and query similarity to enhance the accuracy of query processing from multiple dimensions. By recalling learning examples related to queries, the system can better understand user intent and provide accurate query results. More importantly, the system has good user interaction capabilities. When the system determines that the query is unclear, it can actively ask questions to the user to further clarify the query intent, so that it can still provide high-quality answers in complex situations. This interactive feedback mechanism not only improves the user experience, but also enables the system to perform query reasoning more intelligently.
[0074] In summary, this pattern linking system can achieve efficient, accurate and flexible database query processing through the collaboration of multiple modules, and is particularly suitable for tasks that require processing complex queries and large-scale database scenarios.
[0075] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them. Under the concept of the present invention, the technical features in the above embodiments or different embodiments may also be combined, the steps may be implemented in any order, and there are many other changes in different aspects of the present invention as described above, which are not provided in detail for the sake of simplicity. Although the present invention has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A pattern linking method in a large-scale database scenario, characterized in that: The following steps are involved: S1. Construct user queries into prompts and input them into LLM for query parsing and disambiguation reconstruction: LLM classifies user queries and determines whether the user queries exceed the scope of the current database. If they exceed the scope, LLM gives an answer based on the model's internal knowledge and explains that the query is not performed in the database. If they do not exceed the scope of the current database, LLM determines whether the user query is a complex query. If it is a complex query, it converts it into an original query list containing multiple simple subqueries, disambiguates and reconstructs each subquery in the original query list, and returns the corresponding transcribed query list. The complex query refers to a user query involving nested query statements or a single query statement cannot complete the query requirement. S2. Perform a model initial link based on the results of S1 and select data tables related to the user query from the database; S3. While performing the initial linking of the patterns, recall the few shot learning examples based on the user query: The vector model is used to recall examples highly relevant to the user query from the perspectives of semantic similarity and query similarity. The semantic similarity refers to the same query data table and similar semantics of the query statements. The query similarity refers to low semantic similarity of the query statements but similar query types and the same query data table. The example recall process includes: filtering the question-answering templates in the question-answering template set that point to the same data table as the current query, vectorizing the user query statement and the filtered template set respectively and calculating the semantic similarity, selecting the question-answering templates whose semantic similarity is higher than a set threshold as semantic similarity examples, selecting the question-answering templates whose semantic similarity is not higher than a set threshold but whose query types are similar as query similarity examples, and selecting the semantic similarity examples with the highest semantic similarity and the query similarity examples with the highest query type similarity as learning examples; S4. Based on the initial pattern linking results and the recalled learning examples, the prompts are constructed and input into the LLM for pattern link locking, giving the final data table related to the user query.
2. The mode linking method according to claim 1, characterized in that: Step S2 includes: The vector model is used to vectorize each sub-question in the original query list and the transcribed query list to obtain the corresponding question vector; Semantically matching each question vector with a data table vector in a vector database, and recalling data tables whose matching degree is greater than a set degree threshold; the vector database stores vectorized data table annotation information and question-answering templates; The recalled data tables are merged and deduplicated, and filtered and sorted according to the matching scores to obtain a list of initial links of the patterns.
3. The mode linking method according to claim 1, characterized in that: The semantically similar examples and query similar examples are recalled in parallel by separate vector models respectively.
4. The mode linking method according to claim 1, characterized in that: In step S4, LLM first determines whether the input prompt is sufficient to support the user's query. If it is sufficient to support the user's query, the final data table related to the user's query is returned in the form of a list; otherwise, the user is informed and asked to clarify the user's query intention, and the mode link is continued according to the dialogue record; The input of the prompt includes a user query statement, a learning example, a transcription query list, a data table corresponding to the query list and its interpretation.
5. The mode linking method according to claim 2, characterized in that: The vector model adopts the fine-tuned BGM-M3 model. The process of constructing the fine-tuning data set for training the BGM-M3 model is as follows: focusing on the data tables in the current database, common query questions and expected answers are collected to initially form a question set. By annotating the questions with positive examples and generating negative examples in batches based on scripts, a fine-tuning data set for the vector model is formed. The annotated objects of the positive examples include data tables related to the questions and template questions and answers related to the questions.
6. The mode linking method according to claim 5, characterized in that: The knowledge distillation technology is used to train the vector model: corresponding teacher scores are added to the positive and negative samples in the fine-tuning dataset of the vector model, and the vector model is trained using the fine-tuning dataset with the teacher scores added. The training loss is equal to the sum of the distillation loss and the model prediction loss. The distillation loss is the difference between the predicted value of the vector model and the teacher score, calculated using the KL divergence. The teacher score comes from the LLM's similarity score between the positive / negative samples and the query question.
7. The mode linking method according to claim 5, characterized in that: The LLM adopts the Qwen2.5-32B-Instruct model fine-tuned by PiSSA. The construction process of the fine-tuning dataset for training the Qwen2.5-32B-Instruct model is as follows: based on the question set, question and answer pairs are labeled according to task requirements, and the task requirements include question parsing and disambiguation reconstruction, and pattern link locking; starting from the question, the answer to each question is labeled with solution ideas, and the dataset is constructed in the form of "question-answer-idea"; critical logic is added to construct the dataset in the form of "question-wrong answer-error reminder-idea combined with correct answer".
8. A mode linking system based on the method according to any one of claims 1 to 7, characterized in that: include: Query interface module: used to receive the query input by the user and pass it to the subsequent query parsing module; Query parsing module: used to parse and disambiguate user queries, determine whether the query exceeds the current database scope, and generate a simplified sub-query list for complex queries; Model initial linking module: Based on the query list generated by the query parsing module, it performs preliminary screening and linking of data tables: vectorizes the query through the vectorization model and searches for data tables that match the query semantics; Example recall module: recalls the most relevant examples to the query from the perspectives of semantics and query similarity through the vector model, including semantically similar examples and query similar examples; Pattern locking module: Based on the initial pattern linking results and recalled examples, the final query prompt is generated and input into LLM for final pattern link locking to obtain the data table most relevant to the query.
Citation Information
Patent Citations
Government affair service field multi-strategy fusion dialogue method based on knowledge graph
CN116628172A
Method for improving questions and answers of context learning knowledge base based on thinking chain and visualization
CN117076653A