Intelligent question and answer method and device, equipment, storage medium and program product
By introducing multi-scene knowledge base and vector coding model into the intelligent question and answer system, prompt words that are adapted to different BI scenarios are generated, and query codes are generated in combination with large language models, the problem that existing intelligent question and answer systems are difficult to adapt to different scenarios is solved, and the accuracy of query code and system adaptability are improved.
Patent Information
- Application Number
- CN202411631424.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-15
- Publication Date
- 2025-03-25
AI Technical Summary
The existing intelligent question-and-answer system is difficult to effectively adapt to different business intelligence (BI) scenarios, resulting in errors in the generated query code. When facing multi-table databases, the correlation between the propt prompt words and user problems is poor, affecting the accuracy of the query.
By receiving user input problems, use the preset multi-scene knowledge base to generate prompt words, generate multi-scene knowledge base based on knowledge configuration files, and search and decode through vector encoding models to generate relevant scene knowledge. Then, the generated prompt word is input into the large language model, obtain the query code, and query the target database through the code to get the answer.
It realizes the effective adaptation of the intelligent question-and-answer system to different BI scenarios, improves the accuracy and reliability of query code, reduces the user's need to manually write SQL code, and reduces the cost of commercial analysis.
Smart Images

Figure CN119691106A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of business intelligence technology, and in particular to an intelligent question-answering method, device, equipment, storage medium and program product. Background Art
[0002] In the field of BI (Business Intelligence), based on the entire table structure knowledge of a given database knowledge base, the large language model (LLM) is used to understand the relevant scenarios and infer the relevant query codes, and finally the codes are executed to obtain the query results of the database.
[0003] However, the intelligent question-answering technology in the prior art usually only provides the most basic knowledge of the database table structure and lacks adaptability to different BI scenarios. The query codes provided by the large language model often contain errors. At the same time, when there are a large number of database tables, the prompt words input into the large language model have a poor correlation with the user's questions, which affects the accuracy of database queries.
[0004] The above contents are only used to assist in understanding the technical solution of the present application and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of this application is to provide an intelligent question-answering method, device, equipment, storage medium and program product, aiming to solve the technical problem that existing intelligent question-answering cannot effectively adapt to different scenarios.
[0006] To achieve the above objectives, the present application proposes an intelligent question-answering method, which is applied to an intelligent question-answering platform and includes:
[0007] Receive user input questions;
[0008] According to the question, a prompt word is generated through a preset multi-scenario knowledge base, and the multi-scenario knowledge base is generated based on a preset knowledge configuration file;
[0009] Input the prompt word into a preset large language model to obtain a query code output by the large language model;
[0010] According to the query code, a data query is performed on the target database to obtain an answer to the question.
[0011] In one embodiment, before the step of generating prompt words through a preset multi-scenario knowledge base according to the question, the method further includes:
[0012] Obtaining a knowledge configuration file, wherein the knowledge configuration file includes at least one or more configuration items of pre-knowledge, post-knowledge, calculation method, time constraint, region constraint, query index constraint, special table query method, and scenario example;
[0013] Based on the knowledge configuration file, a multi-scenario knowledge base is generated.
[0014] In one embodiment, the step of generating a multi-scenario knowledge base based on the knowledge configuration file includes:
[0015] Parsing the knowledge configuration file to generate a knowledge configuration text;
[0016] The knowledge configuration text is divided into a plurality of text segments, and the plurality of text segments are encoded into a vector set by a preset vector encoding model;
[0017] Based on the vector set, a multi-scenario knowledge base is generated.
[0018] In one embodiment, the step of generating prompt words through a preset multi-scenario knowledge base according to the question includes:
[0019] According to the question, searching through the multi-scenario knowledge base to obtain relevant scenario knowledge;
[0020] Based on the preset prompt word template, prompt words are generated according to the relevant scene knowledge and questions.
[0021] In one embodiment, the step of searching the multi-scenario knowledge base according to the question to obtain relevant scenario knowledge includes:
[0022] Encoding the question into a question encoding vector through a preset vector encoding model;
[0023] Calculating the cosine similarity value between the problem encoding vector and each encoding vector in the multi-scenario knowledge base, and selecting a preset number of encoding vectors with the largest cosine similarity values in the multi-scenario knowledge base as knowledge base samples;
[0024] The knowledge base samples are decoded by a preset decoder model to obtain relevant scene knowledge.
[0025] In one embodiment, before the step of inputting the prompt word into a preset large language model to obtain a query code output by the large language model, the step further includes:
[0026] Obtaining a scenario standard question-answer pair, wherein the standard question-answer pair at least includes a standard prompt word and a standard response text;
[0027] Inputting the standard prompt words into the large language model to be trained for encoding and decoding to obtain a reply text;
[0028] The difference value between the reply text and the standard reply text is calculated, and the large language model to be trained is iteratively trained with minimizing the difference value as an optimization goal to obtain a trained large language model.
[0029] In addition, to achieve the above purpose, the present application also proposes an intelligent question-answering device, which includes:
[0030] A question receiving module, used for receiving questions input by users;
[0031] A prompt word generation module, used to generate prompt words according to the question through a preset multi-scenario knowledge base, wherein the multi-scenario knowledge base is generated based on a preset knowledge configuration file;
[0032] A model processing module, used for inputting the prompt word into a preset large language model to obtain a query code output by the large language model;
[0033] The data query module is used to perform data query on the target database according to the query code to obtain the answer to the question.
[0034] In addition, to achieve the above-mentioned purpose, the present application also proposes an intelligent question and answer device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and the computer program is configured to implement the steps of the intelligent question and answer method described above.
[0035] 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 the processor, the steps of the intelligent question and answer method described above are implemented.
[0036] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the steps of the intelligent question-answering method described above.
[0037] The present application provides an intelligent question-and-answer method, which receives questions input by users to determine the needs of users; processes the questions input by users through a multi-scenario knowledge base generated by a knowledge configuration file to generate prompt words that can be directly input into a large language model for reasoning, so as to inject knowledge of different scenarios; inputs the generated prompt words into the large language model for processing to obtain query codes output by the large language model, so as to generate query codes with higher reliability through retrieval enhancement generation technology; queries a target database by executing the query code to obtain data query results of the target database, and uses the data query results as answers to user questions, and combines knowledge configuration of different scenarios with retrieval enhancement generation technology to enable users to query and obtain specific content of the database by using natural language question-and-answer methods, thereby realizing intelligent question-and-answer with a configurable multi-scenario knowledge base, solving the problem that existing intelligent question-and-answer cannot effectively adapt to different scenarios, and improving the adaptability of intelligent question-and-answer to different scenarios. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] 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.
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application or 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.
[0040] Figure 1 A flowchart of the first embodiment of the intelligent question-answering method of this application is provided;
[0041] Figure 2 A flowchart of the second embodiment of the intelligent question-answering method of the present application is provided;
[0042] Figure 3 This is a schematic diagram of the module structure of the intelligent question-answering device according to an embodiment of the present application;
[0043] Figure 4 Schematic diagram of the device structure of the hardware operating environment involved in the intelligent question-answering method in the embodiment of the present application.
[0044] 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
[0045] 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.
[0046] 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.
[0047] The main solution of the embodiment of the present application is: receiving a question input by a user; generating a prompt word according to the question through a preset multi-scenario knowledge base, and the multi-scenario knowledge base is generated based on a preset knowledge configuration file; inputting the prompt word into a preset large language model to obtain a query code output by the large language model; and performing a data query on a target database according to the query code to obtain an answer to the question.
[0048] Since the existing technology is based on the knowledge enhancement (RAG) of the general large language model combined with database knowledge, it often only provides the most basic knowledge such as the table structure of the database, lacks the adaptability of query methods and query examples for different BI scenarios and tasks, and the query code given by the large language model often contains errors. Therefore, it is necessary to introduce user-configurable supplementary knowledge, such as query methods for special problems, calculations for special situation queries, table connections, etc.
[0049] At the same time, when there are many database tables, using only simple table structure knowledge and prompt knowledge will cause the prompt to be too long, affecting the model reasoning speed, and even exceeding the maximum length that the model can accommodate. Moreover, most tables in the database are not related to user questions, and introducing irrelevant knowledge will lead to poor model reasoning results. Therefore, it is necessary to introduce a knowledge base retrieval mechanism to only filter the most relevant knowledge.
[0050] Finally, when using a general large model, its logic and reasoning capabilities often cannot effectively adapt to BI specific scenarios. It is necessary to fine-tune the large language model for BI scenarios so that the model can better adapt to various BI tasks in terms of reasoning capabilities.
[0051] Technical terms involved in this application:
[0052] BI: Business Intelligence, which is the field of using artificial intelligence technology to assist business analysis.
[0053] LLM: Large Language Model, abbreviated as LLM. LLM is composed of an artificial neural network with large-scale parameters (usually more than billions of parameters), and is a language model obtained by pre-training and fine-tuning a large amount of unlabeled text using self-supervised learning or semi-supervised learning.
[0054] Prompt: Prompt or prompt word. Large language models are universal. In order to adapt to specific downstream tasks, it is necessary to design a specific format or template for the input of the large model to guide the large model to generate appropriate answers. This guiding prefix, format or template is called prompt. Prompt is essentially an instruction for downstream tasks and can be used as an information enhancement.
[0055] SFT: Supervised Fine-Tuning, supervised fine-tuning, based on the pre-trained large model, with manually annotated training sets, using supervised learning methods to fine-tune the parameters of the large model to obtain a large model for a specific domain. In supervised fine-tuning, there are methods of full parameter fine-tuning (FFT) and freezing some parameters, only fine-tuning one or several layers of parameters. The specific method needs to be flexibly selected based on practice.
[0056] RAG: Retrieval Augmented Generation, refers to a technology that uses an external knowledge base and retrieval system to obtain reliable knowledge in the knowledge base in advance and inject it into a large model to enhance the reliability of the large model's answers. A RAG system consists of a retriever and a reader. The retriever is designed to retrieve and recall documents related to the query to provide reference for subsequent generation models; the reader is designed to integrate the recalled document data, extract key information and output it.
[0057] LoRA: Low-Rank Adaptation, a parameter fine-tuning method that adds a low-rank matrix to the model weight matrix for fine-tuning, allowing the model to learn new task-specific patterns while retaining most of the pre-training knowledge, thereby reducing the risk of overfitting and improving training efficiency, which can effectively save training memory and computation.
[0058] This application combines knowledge configuration for different scenarios with retrieval enhancement generation technology to enable users to query and obtain specific content in the database using natural language question and answer methods, thereby realizing intelligent question and answering with a configurable multi-scenario knowledge base, solving the problem that existing intelligent question and answering cannot effectively adapt to different scenarios, and improving the adaptability of intelligent question and answering to different scenarios.
[0059] 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, an intelligent question-answering device, etc. The following takes the intelligent question-answering device as an example to illustrate this embodiment and the following embodiments.
[0060] Based on this, the present application embodiment provides an intelligent question-answering method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the intelligent question-answering method of the present application.
[0061] In this embodiment, the intelligent question-answering method includes steps S10 to S40:
[0062] Step S10, receiving a question input by a user;
[0063] It should be noted that user input refers to questions raised by users in text, voice or other forms, and is the direct object of system processing. Questions refer to the specific inquiries of users, which can be questions raised in the process of collecting, managing and analyzing information in different scenarios in a specific field, seeking answers to questions and helping users obtain information and make decisions.
[0064] It is understandable that in order to understand the user's needs, specific questions input by the user are received as the starting point of a single conversation with the user.
[0065] Step S20, generating prompt words according to the question through a preset multi-scenario knowledge base, wherein the multi-scenario knowledge base is generated based on a preset knowledge configuration file;
[0066] It should be noted that the multi-scenario knowledge base contains a database of relevant knowledge in different scenarios, which is used to generate prompt words related to user questions. The knowledge configuration file defines the structure and content of the knowledge base and guides the generation and update of the knowledge base. Prompt words refer to keywords or phrases extracted from user questions, which are used to describe the information, answers, text, etc. that users want to obtain from the large language model.
[0067] It can be understood that the system extracts key information from the knowledge base according to the user's question and generates prompt words in order to interact with the large language model more accurately, guide the large language model to generate more accurate query codes, and improve the accuracy and efficiency of the query.
[0068] Step S30, inputting the prompt word into a preset large language model to obtain a query code output by the large language model;
[0069] It should be noted that the big language model refers to an artificial intelligence model that can understand and generate natural language, and can perform natural language processing by inputting prompts into the big language model, guiding the big language model to generate specific output text or instructions. The query code refers to the code generated by the big language model to guide database queries. Different types of query codes can be generated according to the type of database to be queried. For example, when a SQL database needs to be queried, a question for querying the SQL database is input into the big language model, and the big language model will generate and output the SQL query code to provide the query code for direct execution by the user to query the SQL database.
[0070] It can be understood that the generated prompt words are input into a pre-set large language model for processing to generate codes that can be used for database queries. The natural language processing capabilities of the model are used to convert natural language questions into executable query codes, thereby realizing database queries based on retrieval enhancement generation technology.
[0071] Step S40: perform a data query on the target database according to the query code to obtain an answer to the question.
[0072] It should be noted that the target database refers to a database that stores relevant information or that users need to query in order to retrieve answers to questions.
[0073] It can be understood that, according to the query code, the data specified in the user's question is queried from the target database, and the result obtained from the data query is used as the answer to the question, providing the user with an accurate answer to the question.
[0074] In a feasible implementation manner, before the step of generating prompt words through a preset multi-scenario knowledge base according to the question, the step further includes:
[0075] Step S201, obtaining a knowledge configuration file, wherein the knowledge configuration file at least includes one or more configuration items of pre-knowledge, post-knowledge, calculation method, time constraint, region constraint, query index constraint, special table query method and scenario example;
[0076] It should be noted that the knowledge configuration file refers to a file containing the parameters and rules required to build a multi-scenario knowledge base, which can be set by the user according to the different scenario requirements of a specific field.
[0077] Prior knowledge refers to the configuration of the overall principles for generating code, which can provide a general knowledge overview for the large language model, ensure that the model follows certain overall principles and logic when generating query code, and help the model understand the background and context of the problem, thereby generating more accurate, more common-sense and user-expected code.
[0078] Post-knowledge refers to the configuration related to limiting the output format of the large language model, ensuring that the generated query code meets specific format requirements, and reminding the model again to pay attention to specific matters, improving the readability and usability of the query code, and ensuring that the generated code can be directly used for database queries.
[0079] The calculation method refers to the logic and steps for performing specific calculations (such as "month-on-month" and "year-on-year") on the database query results in the database query, and provides examples of database query statements corresponding to the calculation of each indicator.
[0080] Time constraints are used to limit the time range of queries to ensure that query results match the user's required time. For example, for the SQL clause corresponding to the query time constraint, for each query, you need to determine the query time and construct the corresponding WHERE condition statement according to the instructions.
[0081] Regional constraints are used to limit the regional scope of queries to ensure that the query results match the user's required regions. For example, to query the SQL clause corresponding to the regional constraints, for each query, you need to construct the corresponding WHERE condition clause according to the regional rules.
[0082] Query indicator constraints are used to limit specific indicators of the query to ensure that the query results match the business indicators that the user is concerned about.
[0083] Special table query methods refer to special tables that may require special query methods because the structure or data type of special tables may be different from other tables. For example, the result calculation and WHERE condition limitation methods may be different from those of other database tables and require special instructions.
[0084] Scenario examples refer to examples of each different type of query questions and their corresponding SQL statements in different scenarios to help the model learn and understand the types of queries that users may ask and improve the ability to generate accurate SQL statements. They are usually used to train or guide the model so that it can better extract key information from natural language questions and convert them into correct SQL queries.
[0085] It is understandable that before using the multi-scenario knowledge base to generate prompt words, the system needs to obtain a knowledge configuration file, which contains various configuration items required to generate the multi-scenario knowledge base, providing guidance and specifications for the generation of the knowledge base, ensuring that the knowledge base can cover multiple scenarios and meet specific needs.
[0086] Step S202: Generate a multi-scenario knowledge base based on the knowledge configuration file.
[0087] It can be understood that based on the acquired knowledge profile, the system builds a multi-scenario knowledge base, which can provide corresponding knowledge support according to different scenarios and needs, so that the system can flexibly respond to user problems in various scenarios in specific fields and improve the accuracy and efficiency of problem handling.
[0088] In this embodiment, a multi-scenario knowledge base configured with knowledge and rules for different scenarios is utilized so that when the system processes questions input by users, it can utilize the rich information in the multi-scenario knowledge base to generate more accurate query codes that meet user needs, and provide customized solutions for processing queries of specific types or scenarios, thereby improving the performance of the entire system and user experience.
[0089] In a feasible implementation manner, the step of generating a multi-scenario knowledge base based on the knowledge configuration file includes:
[0090] Step S2021, parsing the knowledge configuration file to generate a knowledge configuration text;
[0091] It can be understood that the content in the knowledge configuration file is parsed and converted into a readable text format to obtain the key knowledge configuration text in the file, in preparation for subsequent text segmentation and vector encoding.
[0092] Step S2022, dividing the knowledge configuration text into a plurality of text segments, and encoding the plurality of text segments into a vector set using a preset vector encoding model;
[0093] It is understandable that the knowledge configuration text is further segmented and divided into smaller text fragments according to specific rules (such as sentences, paragraphs or keywords), and these text fragments are converted into vector form using a vector encoding model to facilitate subsequent knowledge base construction.
[0094] Step S2023: Generate a multi-scenario knowledge base based on the vector set.
[0095] It can be understood that constructing a multi-scenario knowledge base through a vector set enables the knowledge base to store and retrieve knowledge in a vectorized form, which facilitates the system to perform efficient knowledge retrieval.
[0096] In this embodiment, a multi-scenario knowledge base is constructed based on a vector set, which realizes the transformation from structured data to quantifiable knowledge, greatly improving the ability of the intelligent question-answering system to process natural language queries. Through the vectorized knowledge base, the system can quickly identify and retrieve the knowledge fragments most relevant to the user's query, thereby providing more accurate and faster query responses. In addition, this vector-based technology also enhances the system's understanding and matching capabilities of semantics, allowing the system to not only process simple keyword matching queries, but also understand and respond to complex, semantically rich queries, so that the system can show higher efficiency, accuracy and adaptability when processing complex queries in multiple scenarios, providing users with a more intelligent service experience.
[0097] In a feasible implementation manner, the step of generating prompt words through a preset multi-scenario knowledge base according to the question includes:
[0098] Step S203, searching through the multi-scenario knowledge base according to the question to obtain relevant scenario knowledge;
[0099] It should be noted that the retrieval can be performed using search engine technology or database query technology to search in a multi-scenario knowledge base based on the keywords or semantic content of the question.
[0100] It is understandable that the multi-scenario knowledge base is used to find knowledge related to user questions in order to generate more accurate prompt words. By searching the multi-scenario knowledge base, the system can identify the specific scenarios and requirements behind the questions.
[0101] Step S204: Generate prompt words based on a preset prompt word template and according to the relevant scenario knowledge and questions.
[0102] It should be noted that the prompt word template refers to a preset prompt word template, which can dynamically fill in the variables in the template according to the retrieved knowledge fragments and user questions, and generate specific prompt words in a structured manner.
[0103] It can be understood that, based on the retrieved relevant scenario knowledge and the user's specific question, a preset template is used to generate targeted prompt words to guide the large language model to generate more accurate query codes.
[0104] In this implementation, a multi-scenario knowledge base is used to perform an in-depth search of questions raised by users, which can accurately identify and extract knowledge fragments related to the questions. The knowledge retrieval provides rich contextual information for subsequent steps, ensuring the system's in-depth understanding of user queries. Then, based on the retrieved relevant scenario knowledge and the user's specific questions, a preset prompt word template is used to generate targeted prompt words, so that the system can flexibly adapt to different query scenarios and dynamically generate prompt words that are highly relevant to user questions, thereby effectively guiding the large language model to generate accurate query codes, which not only improves the efficiency and accuracy of queries, but also enhances the system's adaptability to complex query requirements, so that the intelligent question-answering system can provide more accurate and efficient services when processing diverse user queries, greatly improving the user experience and the practicality of the system.
[0105] In a feasible implementation manner, the step of searching through the multi-scenario knowledge base according to the question to obtain relevant scenario knowledge includes:
[0106] Step S2031, encoding the question into a question coding vector using a preset vector coding model;
[0107] It should be noted that the vector encoding model can select a pre-trained vector encoding model, such as BERT, Word2Vec or GPT, which can convert text into vector representation.
[0108] It can be understood that converting the user's question into a vector can capture the semantic information of the question, so that the question can be analyzed and compared in a format suitable for machine processing.
[0109] Step S2032, calculating the cosine similarity value between the question encoding vector and each encoding vector in the multi-scenario knowledge base, and selecting a preset number of encoding vectors with the largest cosine similarity values in the multi-scenario knowledge base as knowledge base samples;
[0110] It should be noted that the cosine similarity value can be obtained by using the cosine similarity formula to calculate the similarity between the question encoding vector and each encoding vector in the knowledge base.
[0111] It can be understood that in order to find the knowledge base sample most relevant to the user's question, the similarity between the question encoding vector and each encoding vector in the knowledge base is quantified by calculating the cosine similarity value, and the most relevant multiple knowledge base samples are selected from the multi-scenario knowledge base.
[0112] Step S2033: decode the knowledge base sample through a preset decoder model to obtain relevant scene knowledge.
[0113] It should be noted that the decoder model is able to convert the vector back to its original text form.
[0114] It can be understood that the decoder model converts the selected knowledge base samples in the form of encoded vectors back into relevant scene knowledge in the form of readable text so that the system can further process and use this knowledge to generate prompt words.
[0115] In a feasible implementation, the user's question is first converted into a vector using a vector encoding model. The vector captures the semantic information and context of the question, so that the originally complex natural language question is converted into a mathematical representation that can be understood and processed by the machine; then the cosine similarity between the user question vector and all the encoding vectors in the multi-scenario knowledge base is calculated to find the most relevant knowledge base sample. Not only the direct correlation between the question and the information in the knowledge base is considered, but also the cosine similarity is used as a quantitative indicator to accurately measure the similarity between the question and each vector in the knowledge base, so as to select the most matching knowledge fragment; finally, these selected knowledge base sample vectors are decoded back into a readable text form through a decoder model, so as to obtain specific scenario knowledge directly related to the user's question. This achieves efficient conversion from natural language questions to relevant scenario knowledge, so that the intelligent question-answering system can quickly and accurately understand and respond to user queries.
[0116] This embodiment provides an intelligent question-answering method, which combines knowledge configuration for different scenarios with retrieval enhancement generation technology, allowing users to query and obtain specific content in a database using natural language question-answering methods, thereby realizing intelligent question-answering of a configurable multi-scenario knowledge base, solving the problem that existing intelligent question-answering cannot effectively adapt to different scenarios, and improving the adaptability of intelligent question-answering to different scenarios.
[0117] 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 first embodiment can refer to the above introduction, and will not be repeated in the following. Figure 2 , Figure 2 This is a flow chart of the second embodiment of the intelligent question-answering method of the present application.
[0118] In this embodiment, before the step of inputting the prompt word into a preset large language model to obtain a query code output by the large language model, the step further includes:
[0119] Step S301, obtaining a scene standard question-answer pair, wherein the standard question-answer pair at least includes a standard prompt word and a standard reply text;
[0120] It should be noted that the scenario standard question and answer pairs can be question and answer pairs of various scenarios collected from a knowledge base, historical question and answer records or expert knowledge, and can be obtained by performing data annotation processing on the various collected question and answer pairs.
[0121] It can be understood that one or more sets of scenario-related standard question-answer pairs are provided for training the large language model. Each set of question-answer pairs contains standard prompt words and corresponding standard response texts. These standard question-answer pairs serve as training data to help the model learn how to generate accurate responses based on the prompt words.
[0122] Step S302, inputting the standard prompt word into the large language model to be trained for encoding and decoding to obtain a reply text;
[0123] It is understandable that letting the large language model to be trained generate the reply text through the actual encoding and decoding process is a key step for the model to learn how to generate replies based on the prompt words.
[0124] Step S303, calculating the difference between the reply text and the standard reply text, and taking minimizing the difference as an optimization goal, iteratively training the large language model to be trained to obtain a trained large language model.
[0125] It should be noted that appropriate evaluation indicators (such as BLEU score, ROUGE score, etc.) can be used in combination to calculate the difference between the generated reply text and the standard reply text, so as to adjust the model parameters according to the difference value and optimize the model performance through iterative training.
[0126] It can be understood that by quantifying the differences between the response text generated by the model and the standard response text and iteratively training the model with the goal of minimizing these differences, the accuracy and reliability of the model can be improved.
[0127] In this embodiment, one or more groups of standard question-answer pairs containing standard prompt words and corresponding standard reply text scenarios are first obtained, providing a high-quality data basis for the training of the large language model; then these standard prompt words are input into the large language model to be trained, and the model generates reply texts through encoding and decoding processing to simulate the actual question-answer interaction process, so that the model can learn how to generate appropriate replies based on given prompt words; finally, the difference between the reply text generated by the model and the standard reply text is calculated, and the model is iteratively trained with the goal of minimizing these differences, so as to continuously optimize the parameters of the model through the iterative training process, so that the replies generated by it are closer and closer to the standard replies, thereby improving the accuracy and reliability of the model. After iterative training, the large language model will have a stronger ability to understand and generate accurate replies. It can not only learn the deep structure and semantics of the language, but also flexibly adapt to different scenarios in specific fields, ensuring that the model can provide more accurate and reliable services in practical applications.
[0128] Based on the first embodiment and / or the second embodiment of the present application, in the third embodiment of the present application, the same or similar contents as those of the first and second embodiments mentioned above can be referred to the above introduction and will not be repeated later.
[0129] Exemplarily, in order to help understand the implementation process of the intelligent question-answering method obtained by combining the first embodiment and the second embodiment, specifically:
[0130] Select a large language model and a multi-scenario knowledge base set in the BI domain; split the knowledge base set in each domain into several groups of segmented knowledge; for each group of segmented knowledge in the knowledge base, users can independently configure the corresponding background knowledge and usage examples; according to the configured knowledge information, use the encoding model to encode it into a vector knowledge base; then, establish a domain knowledge base and retrieval mechanism, design the corresponding prompt template and the combination form of retrieval knowledge; then, establish a training question set, for each question in the training set, combine the corresponding prompt based on the knowledge base retrieval results and the prompt combination mechanism as the input corpus for the large language model training; at the same time, mark the standard output answer corresponding to each question, and perform supervised fine-tuning (SFT) on the large language model. The fine-tuned large language model is deployed on the GPU server; in the application, the user enters the question in the specific BI scenario, and the system retrieves the most relevant knowledge base fragments and related code examples in the vector-encoded knowledge base based on vector similarity, and finally combines the corresponding prompt based on the retrieval results into the large language model to obtain the final reply code; finally, execute the code in the database or application interface to obtain the query result corresponding to the user's question. The specific steps include:
[0131] Step 1: Establish a user-configurable knowledge base and corresponding configuration mechanism, including:
[0132] 1.1 Read the table structure and corresponding comments of the target database as basic knowledge.
[0133] 1.2 Set the configuration file format and decompose the knowledge into several modules, such as "pre-knowledge", "post-knowledge", "calculation method", "time constraint", "geographic constraint", "query index constraint", "special table query method", "fewshot", etc. Corresponding examples need to be given for each corresponding module.
[0134] For example: In an Excel document, several module knowledge are put into several Sheet tables respectively. The Excel configuration file can be generated by the front-end page operation configuration item.
[0135] The following is an introduction to the functions of several knowledge modules:
[0136] 1.2.1 Pre-knowledge and post-knowledge: indicate the general knowledge overview and overall precautions. Pre-knowledge is at the front of the prompt, and post-knowledge is at the back of the prompt. Pre-knowledge mainly includes some overall principles for generating code, and post-knowledge mainly limits the output format, reminds precautions, etc.
[0137] Examples of prerequisite knowledge are as follows:
[0138] (1) When comparing data from different time periods, ensure that the definitions of the two time periods are clear and consistent to avoid miscalculations due to unclear time ranges.
[0139] (2) When joining multiple tables, ensure that all join conditions are correct to avoid Cartesian products that affect query performance and result accuracy.
[0140] (3) When making comparisons across years or quarters, special attention should be paid to the setting of the time range to ensure that the length of time for comparison is equal. For example, when comparing data from the first quarter of this year with data from the fourth quarter of last year, the time span of the two quarters should be the same.
[0141] Examples of post-knowledge are as follows:
[0142] (1) If the question contains "sort", please make sure to use the "order by" subquery at the end.
[0143] (2) If the subquery contains "same-level regions" or "lower-level regions", which include multiple provinces, cities and districts, please make sure to use "group by area_id" for grouping.
[0144] (3) If you want to get the top few or topN, make sure to use limit interception.
[0145] In this sheet, there is one column for each of pre-knowledge and post-knowledge. If not necessary, the content can be empty.
[0146] 1.2.2 Calculation method: indicates the calculation method of the SQL result, such as what indicators are needed for "month-on-month" and "year-on-year", how to calculate, and provide SQL statement examples corresponding to each indicator. This sheet consists of three columns: query (question), description (description) and sql (statement example). For example:
[0147]
[0148] 1.2.3 Time constraint: Indicates the SQL clause corresponding to the query time constraint. For each natural language query, you need to determine the query time and construct the corresponding WHERE condition statement according to the instructions. This sheet consists of three columns: query, description, and sql. For example:
[0149]
[0150] 1.2.4 Regional constraints: Indicates the SQL clause corresponding to the query regional constraints. For each query, you need to construct the corresponding WHERE clause according to the regional rules. This sheet consists of three columns: query, description, and sql. For example:
[0151]
[0152] 1.2.5 Query index constraint: The SQL clause representing the query index constraint consists of three columns: query, description, and sql. For example:
[0153]
[0154] 1.2.6 Special table query method: For special tables, the result calculation and WHERE condition limitation methods may be different from those of other database tables and require special instructions. It consists of three columns: query, description, and sql. For example:
[0155]
[0156] 1.2.7Fewshot: Give the fewshot corresponding to each type of query question frequently asked by users. Constructing fewshot examples of different types of questions in the scenario helps to enhance the accuracy of SQL generated by the model. It consists of two columns, question and SQL, which represent each specific query question and its corresponding complete SQL statement. For example:
[0157]
[0158] 1.3 After the user uploads the configured file, the system parses and generates a knowledge base in text form.
[0159] Step 2: Based on the first step, establish a vector knowledge base and corresponding retrieval mechanism, including:
[0160] 2.1 Divide the knowledge base text fragments, use the vector encoding model to encode each text fragment into a vector set, and save it as a vector database.
[0161] 2.2 For the user question, input the user question into the encoding model to obtain the encoding vector corresponding to the user question.
[0162] 2.3 Calculate the cosine similarity between the encoding vector corresponding to the user question and each encoding vector in the knowledge base set.
[0163] 2.4 Based on the cosine similarity, select k knowledge base samples with the largest cosine similarity. The recall k value of each type of knowledge is not necessarily the same, and can be set by the user and reflected in the configuration file of the first step.
[0164] 2.5 For each sample, decode it using the decoder model, restore it to text form, and obtain the output retrieval knowledge list.
[0165] Step 3: Based on the knowledge base retrieval mechanism and prompt template, generate the corresponding prompt for the query of the training data set, including:
[0166] 3.1 Design a prompt template, which includes placeholders for questions and corresponding knowledge, organized in a certain order and connecting statements.
[0167] 3.2 For each original query in the training set, through knowledge base retrieval and prompt combination mechanism, it is combined into a prompt with sufficient knowledge background that can be understood by the large language model. This prompt should contain all the table structures in 1.1 and all types of knowledge described in 1.2.
[0168] For example, a prompt template is as follows:
[0169] ###Task
[0170] Given a user question [QUESTION]{user_question}[ / QUESTION], please refer to the following DDL statements, related knowledge and examples, step by step analyze the question and related rule requirements, and finally generate a SQL query code for the user question.
[0171] ###DDL The following is the table structure that may be used {ddl_list_string}
[0172] ###Related Knowledge
[0173] {pre_knowledge}
[0174] Calculation method. The following are some SQL calculation method types and corresponding statements:
[0175] {compute_method}
[0176] Time constraints: You need to determine which of the following categories the query time belongs to, and construct the corresponding SQL statement according to the instructions:
[0177] {time_conditions}
[0178] Regional constraints: For each subquery, construct the corresponding SQL statement according to the following regional rules:
[0179] {area_conditions}
[0180] Query Metrics
[0181] {index_conditions}
[0182] Special table query
[0183] {special_tables}
[0184] {end_knowledge}
[0185] ###Reference Examples
[0186] {sql_fewshot}
[0187] ###User Questions
[0188] {user_question}
[0189] The template has several placeholders: {ddl_list_string} represents the DDL structure name, {pre_knowledge} represents the pre-knowledge, {compute_method}, {time_conditions}, {area_conditions}, {index_conditions}, {special_tables} represent the calculation method rules, time constraints, area constraints, index constraints, and special table processing methods, respectively. Multiple rules need to be spliced together, one line each. {end_knowledge} represents post-knowledge. {sql_fewshot} represents the fewshot example. As above, multiple data need to be spliced together. {user_question} represents the user question.
[0190] Step 4: Combine the prompt obtained in step 3 and the pre-annotated standard response into a question-answer pair. The question-answer pair includes two fields: one is the prompt input to the large language model, and the other is the standard response output that the model should output. The standard response here is obtained by the above prompt request using a commercial large model (such as gpt, kimi, qwen-max, etc.), and then obtained through manual review.
[0191] Step 5: Input the above question-answer pairs into the training module for supervised fine-tuning (SFT) training. The specific training methods include:
[0192] 5.1 Input the prompt in the above question-answer pair into the large language model to be trained for encoding and decoding, obtain the probability of generating a reply text based on the prompt, and select the reply text with the highest probability as the reply text output by the large language model.
[0193] 5.2 Calculate the difference between the large language model reply text and the standard reply text. Here, the cross entropy between the large language model reply text and the standard reply text (generated by a commercial large model + manual review, including the analysis process and the generated SQL code) is used as the difference value. (Note that this is the cross entropy between the text corresponding vectors, and does not involve the comparison of each module knowledge in 1.2)
[0194] 5.3 Taking minimizing the above difference value as the optimization goal, the parameters of the large language model are iteratively trained. The training method here adopts the LoRA method, that is, low-rank decomposition is used to simulate the change of parameters, and relatively small parameters are used to achieve indirect training of the large model. The fine-tuning method used to train the large language model is LoRA. Although it has effectively saved the number of computing cards and the amount of calculation, it is still possible to encounter insufficient computing power. At this time, qLoRA can be used, that is, the large language model is reduced in floating point precision through quantization technology, and then LoRA training is performed, which can further save memory.
[0195] 5.4 After iterating through the prescribed steps, a fine-tuned large language model is obtained. Compared with the general large language model, the large language model should have better performance in the problems and contexts in the field of the training set. In order to ensure that the model does not reduce the effect on general scenarios, some general corpus is usually mixed into the training corpus. If it is only for a specific field and the user is limited to asking questions in a specific field, there is no need to mix general corpus into the training set, and the large language model for the specific scenario can be directly trained.
[0196] Step 6: Based on the fine-tuned large language model and knowledge base retrieval system, the user's input question is retrieved through the knowledge base to obtain relevant knowledge, and then combined into input text for the large language model according to the prompt template. Then, the input text is input into the large language model for encoding and decoding to obtain the corresponding question analysis and reply code.
[0197] Step 7: Parse the query code output by the large language model and execute the request in the database or interface to obtain the data query results. Output the query results after formatting, and make charts based on the data query results.
[0198] This embodiment can cope with multiple scenarios in the BI field, showing strong adaptability and greatly improving the efficiency of business analysis, which is mainly reflected in the following advantages:
[0199] 1. Better understanding of user problems in BI scenarios and enhanced model reasoning capabilities in the field of SQL query code generation.
[0200] 2. By uploading and parsing user profiles, the knowledge base can be more flexible to adapt to specific application scenarios. At the same time, based on the knowledge base retrieval mechanism, it avoids introducing parts of the knowledge base that are less relevant to user questions.
[0201] 3. Combining the database environment and the code execution device, the generation results of the large language model are no longer empty text, but real data query results, making it possible to create intuitive display forms such as charts based on the returned data results.
[0202] 4. Users can configure the knowledge base independently and query specific knowledge in the database in natural language. This is user-friendly and saves users from complex operations such as writing SQL queries.
[0203] In this embodiment, in the specific field of BI, the system supports users to easily and independently configure the knowledge base, and can perform semantic understanding, query code generation, answer summarization and other links based on the user-configured knowledge and specific database table structure, in conjunction with a large language model that adapts to the logic of the field. Users can use natural language question and answer methods to query and obtain specific content in the database, solving the problem of frequent SQL code writing in the BI field, greatly reducing the cost of business analysis, and improving the efficiency of business analysis.
[0204] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the intelligent question-answering method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.
[0205] This application also provides an intelligent question-answering device, please refer to Figure 3 , the intelligent question-answering device comprises:
[0206] The question receiving module 10 is used to receive questions input by users;
[0207] A prompt word generation module 20, used to generate prompt words according to the question through a preset multi-scenario knowledge base, wherein the multi-scenario knowledge base is generated based on a preset knowledge configuration file;
[0208] A model processing module 30, used for inputting the prompt word into a preset large language model to obtain a query code output by the large language model;
[0209] The data query module 40 is used to perform data query on the target database according to the query code to obtain the answer to the question.
[0210] Optionally, the prompt word generating module 20 is further used for:
[0211] Obtaining a knowledge configuration file, wherein the knowledge configuration file includes at least one or more configuration items of pre-knowledge, post-knowledge, calculation method, time constraint, region constraint, query index constraint, special table query method, and scenario example;
[0212] Based on the knowledge configuration file, a multi-scenario knowledge base is generated.
[0213] Optionally, the prompt word generating module 20 is further used for:
[0214] Parsing the knowledge configuration file to generate a knowledge configuration text;
[0215] The knowledge configuration text is divided into a plurality of text segments, and the plurality of text segments are encoded into a vector set by a preset vector encoding model;
[0216] Based on the vector set, a multi-scenario knowledge base is generated.
[0217] Optionally, the prompt word generating module 20 is further used for:
[0218] According to the question, searching through the multi-scenario knowledge base to obtain relevant scenario knowledge;
[0219] Based on the preset prompt word template, prompt words are generated according to the relevant scene knowledge and questions.
[0220] Optionally, the prompt word generating module 20 is further used for:
[0221] Encoding the question into a question encoding vector through a preset vector encoding model;
[0222] Calculating the cosine similarity value between the problem encoding vector and each encoding vector in the multi-scenario knowledge base, and selecting a preset number of encoding vectors with the largest cosine similarity values in the multi-scenario knowledge base as knowledge base samples;
[0223] The knowledge base samples are decoded by a preset decoder model to obtain relevant scene knowledge.
[0224] Optionally, the model processing module 30 is further used for:
[0225] Obtaining a scenario standard question-answer pair, wherein the standard question-answer pair at least includes a standard prompt word and a standard response text;
[0226] Inputting the standard prompt words into the large language model to be trained for encoding and decoding to obtain a reply text;
[0227] The difference value between the reply text and the standard reply text is calculated, and the large language model to be trained is iteratively trained with minimizing the difference value as an optimization goal to obtain a trained large language model.
[0228] The intelligent question-answering device provided by the present application adopts the intelligent question-answering method in the above embodiment, which can solve the technical problem that the existing intelligent question-answering cannot effectively adapt to different scenarios. Compared with the prior art, the beneficial effects of the intelligent question-answering device provided by the present application are the same as the beneficial effects of the intelligent question-answering method provided by the above embodiment, and the other technical features in the intelligent question-answering device are the same as the features disclosed in the above embodiment method, which will not be repeated here.
[0229] The present application provides an intelligent question-and-answer device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable 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 intelligent question-and-answer method in the first embodiment described above.
[0230] Reference below Figure 4 , which shows a schematic diagram of the structure of an intelligent question-answering device suitable for implementing the embodiment of the present application. The intelligent question-answering device 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. Figure 4 The intelligent question-and-answer device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0231] like Figure 4 As shown, the intelligent question-answering device may include a processing device 1001 (e.g., a central processing unit, a graphics processor, 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 RAM1004, various programs and data required for the operation of the intelligent question-answering device are also stored. The processing device 1001, ROM1002, and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the intelligent question-answering device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows an intelligent question-answering device with various systems, 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 provided instead.
[0232] 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.
[0233] The intelligent question-answering device provided by this application adopts the intelligent question-answering method in the above embodiment, which can solve the technical problem that the existing intelligent question-answering cannot effectively adapt to different scenarios. Compared with the prior art, the beneficial effects of the intelligent question-answering device provided by this application are the same as the beneficial effects of the intelligent question-answering method provided by the above embodiment, and the other technical features in the intelligent question-answering device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.
[0234] 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.
[0235] 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.
[0236] 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 intelligent question-answering method in the above-mentioned embodiment.
[0237] 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.
[0238] The computer-readable storage medium may be included in the intelligent question-answering device; or may exist independently without being assembled into the intelligent question-answering device.
[0239] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the intelligent question-answering device, the intelligent question-answering device: receives a question input by a user; generates a prompt word based on the question through a preset multi-scenario knowledge base, and the multi-scenario knowledge base is generated based on a preset knowledge configuration file; inputs the prompt word into a preset large language model to obtain a query code output by the large language model; and performs a data query on a target database based on the query code to obtain an answer to the question.
[0240] 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).
[0241] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a 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 box can also occur in a different order from the order marked in the accompanying drawings. For example, two 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 box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart 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.
[0242] The modules involved in the embodiments of the present application may be implemented by software or hardware, wherein the name of the module does not limit the unit itself in some cases.
[0243] The readable storage medium provided in this application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned intelligent question-answering method, and can solve the technical problem that the existing intelligent question-answering cannot effectively adapt to different scenarios. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as the beneficial effects of the intelligent question-answering method provided in the above-mentioned embodiment, and will not be repeated here.
[0244] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned intelligent question-answering method when executed by a processor.
[0245] The computer program product provided by this application can solve the technical problem that the existing intelligent question answering cannot effectively adapt to different scenarios. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as the beneficial effects of the intelligent question answering method provided by the above embodiment, which will not be repeated here.
[0246] 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. An intelligent question-answering method, characterized in that: The method is applied to an intelligent question-answering platform, comprising: Receive user input questions; According to the question, a prompt word is generated through a preset multi-scenario knowledge base, and the multi-scenario knowledge base is generated based on a preset knowledge configuration file; Input the prompt word into a preset large language model to obtain a query code output by the large language model; According to the query code, a data query is performed on the target database to obtain an answer to the question.
2. The method according to claim 1, characterized in that: Before the step of generating prompt words through a preset multi-scenario knowledge base according to the problem, the method further includes: Obtaining a knowledge configuration file, wherein the knowledge configuration file includes at least one or more configuration items of pre-knowledge, post-knowledge, calculation method, time constraint, region constraint, query index constraint, special table query method, and scenario example; Based on the knowledge configuration file, a multi-scenario knowledge base is generated.
3. The method according to claim 2, characterized in that: The step of generating a multi-scenario knowledge base based on the knowledge configuration file includes: Parsing the knowledge configuration file to generate a knowledge configuration text; The knowledge configuration text is divided into a plurality of text segments, and the plurality of text segments are encoded into a vector set by a preset vector encoding model; Based on the vector set, a multi-scenario knowledge base is generated.
4. The method according to claim 1, characterized in that: The step of generating prompt words through a preset multi-scenario knowledge base according to the problem includes: According to the question, searching through the multi-scenario knowledge base to obtain relevant scenario knowledge; Based on the preset prompt word template, prompt words are generated according to the relevant scene knowledge and questions.
5. The method according to claim 4, characterized in that: The step of searching the multi-scenario knowledge base according to the problem to obtain relevant scenario knowledge includes: Encoding the question into a question encoding vector through a preset vector encoding model; Calculating the cosine similarity between the problem encoding vector and each encoding vector in the multi-scenario knowledge base, and selecting a preset number of encoding vectors with the largest cosine similarity values in the multi-scenario knowledge base as knowledge base samples; The knowledge base samples are decoded by a preset decoder model to obtain relevant scene knowledge.
6. The method according to claim 1, characterized in that: Before the step of inputting the prompt word into a preset large language model to obtain a query code output by the large language model, the step further includes: Obtaining a scenario standard question-answer pair, wherein the standard question-answer pair at least includes a standard prompt word and a standard response text; Inputting the standard prompt words into the large language model to be trained for encoding and decoding to obtain a reply text; The difference value between the reply text and the standard reply text is calculated, and the large language model to be trained is iteratively trained with minimizing the difference value as an optimization goal to obtain a trained large language model.
7. An intelligent question-answering device, characterized in that: The device comprises: A question receiving module, used for receiving questions input by users; A prompt word generation module, used to generate prompt words according to the question through a preset multi-scenario knowledge base, wherein the multi-scenario knowledge base is generated based on a preset knowledge configuration file; A model processing module, used for inputting the prompt word into a preset large language model to obtain a query code output by the large language model; The data query module is used to perform data query on the target database according to the query code to obtain the answer to the question.
8. An intelligent question-answering device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the intelligent question-answering method according to any one of claims 1 to 6.
9. 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 intelligent question-answering method according to any one of claims 1 to 6 are implemented.
10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the intelligent question-answering method according to any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Question and answer mode data retrieval and large model summarization method and device, equipment and medium
CN120162425A
Intelligent airport data processing method and device and electronic equipment
CN121031646A
Menu retrieval method, system and device based on artificial intelligence
CN121233219A
Information question-answering method for city updating field, electronic equipment and medium
CN121456112A
Interaction method and device based on large model, storage medium and program product
CN121658635A