Large model decision-making method and device based on external knowledge base
By building a target vector database and using the vector database for joint search, enhancement prompts are generated to assist in decision-making large models, the problem of data security and question-and-answer effects in the prior art is solved, and the effect of generating accurate responses without leaking private domain data is achieved.
Patent Information
- Application Number
- CN202411623731.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-14
- Publication Date
- 2025-04-08
AI Technical Summary
The prior art is difficult to achieve the accuracy and effectiveness of large-model decisions while ensuring data security, especially when processing real-time, non-public or offline data.
By text segmentation, vectorization and hierarchical index generation of private domain data, a target vector database is built, and a common search is used to obtain the most similar result documents, and enhancement prompts are generated to assist decision-making big models to generate responses.
It realizes that more accurate and relevant responses are generated without leaking private domain data, and solves the problem of taking into account data security and Q&A effects.
Smart Images

Figure CN119783785A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a large model decision-making method and device based on an external knowledge base. Background Art
[0002] With the booming development of artificial intelligence, individuals, organizations, and enterprises have an increasingly strong demand to make more reasonable decisions based on artificial intelligence technology. With the rapid development of deep learning technology, especially the advancement of neural network models, the field of natural language processing has achieved remarkable results. Deep learning achieves efficient processing and learning of data by simulating the structure and function of the human brain neural network.
[0003] However, since the knowledge of the model itself comes entirely from its training data, traditional question-answering systems can often only give answers based on the data trained by the large model, and cannot meet the needs of users for question-answering in specific fields. For example, the training sets of existing mainstream large models (ChatGPT, Wenxin Yiyan, Tongyi Qianwen...) are basically built on public data on the Internet, and cannot obtain some real-time, non-public or offline data, and cannot effectively answer content related to real-time, non-public or offline data.
[0004] In addition, since the underlying principles of existing AI models are based on mathematical probability, the model output is essentially a series of numerical operations. In the case that the large model itself does not have knowledge in a certain area or is not good at a certain scenario, the output of the large model is very likely to have hallucination problems. The distinction between such hallucination problems requires the user to have knowledge in the corresponding field, and the threshold for implementation is relatively high.
[0005] In order to solve this problem, some studies have used the data needed for decision-making to train large models, such as FinGPT in the financial field and DeepSpeech in the speech recognition field. However, data security is of vital importance to enterprises, and no enterprise is willing to bear the risk of data leakage and upload its own private domain data to a third-party platform for training. This also leads to a trade-off between data security and effectiveness.
[0006] In summary, the existing technology has the problem of being unable to take into account both data security and question-answering effects at the same time. Summary of the invention
[0007] The present invention provides a large model decision method and device based on an external knowledge base, which are used to solve the defects of the prior art in taking both data security and model performance into consideration, and realize large model decision with data security and accurate results.
[0008] The present invention provides a large model decision method based on an external knowledge base, comprising the following steps: Input questions are fed into a pre-built decision-making model to obtain hypothetical responses; Vectorizing the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; Using the input question vector and the hypothetical response vector, a joint search is performed in a target vector database according to similarity, and the most similar result document is extracted from the target vector database according to the similarity; Generate an enhanced prompt according to the result document, input the enhanced prompt and the input question into the decision-making model, and obtain a target question response; The target vector database is obtained by performing text segmentation, vectorization, and hierarchical index generation on the private domain data and storing the data in a preset vector database.
[0009] According to a large model decision method based on an external knowledge base provided by the present invention, the enhanced prompt is generated according to the result document, the enhanced prompt and the input question are input into the decision large model to obtain a target question response, and then the following steps are further included: Obtaining user feedback on responses to the target question, and fine-tuning the decision-making model based on the feedback; And / or, the decision big model and the target vector database are privately deployed.
[0010] According to a large model decision method based on an external knowledge base provided by the present invention, the target vector database is obtained after text segmentation, vectorization, and hierarchical index generation are performed on the private domain data and stored in a preset vector database, specifically including: Obtain private domain data; Segmenting the private domain data according to titles to obtain text data corresponding to each title, and then segmenting the text data corresponding to each title according to process steps to obtain text data corresponding to the process steps, thereby obtaining a text segmentation result; The title and the process steps are used as metadata, and the text segmentation result is vectorized to obtain a title vector and a step vector; Constructing a title index for the title vector, constructing a step index for the step vector, and establishing an association relationship between the title index and the related step index; The title vector and the corresponding title index are stored in a first preset vector database to obtain a target title vector database, and the step vector and the corresponding step index are stored in a second preset vector database to obtain a target step vector database; A target vector database is obtained according to the target title vector database, the target step vector database and the association relationship.
[0011] According to a large model decision method based on an external knowledge base provided by the present invention, the input question vector and the hypothetical response vector are used to perform a joint search in a target vector database according to similarity, and the most similar result document is taken out from the target vector database according to the similarity, specifically including: Calculate a first similarity of the input question vector in the target title vector database, and calculate a second similarity of the hypothetical response vector in the target step vector database; Calculate a first angle of the input question vector in the target title vector database, and calculate a second angle of the hypothetical response vector in the target step vector database; A weighted calculation is performed according to the first similarity, the second similarity, the first angle, and the second angle, and the most similar result document is retrieved from the target vector database according to the result of the weighted calculation.
[0012] According to a large model decision method based on an external knowledge base provided by the present invention, when the input question includes multiple subtasks, the enhanced prompt is generated based on the most similar result documents of the multiple subtasks and the input question.
[0013] According to a large model decision method based on an external knowledge base provided by the present invention, the most similar result document is taken out from the target vector database according to the result of weighted calculation, specifically comprising: Retrieving text data from the target vector database according to the index corresponding to the result of the weighted calculation; Encoding the text data, and scoring and predicting the encoded text data using a cross encoder model to obtain a relevance score of the text data; Classification and clustering are performed according to the relevance scores, and reorganization is performed according to the classification and clustering results to obtain a result document.
[0014] According to a large model decision method based on an external knowledge base provided by the present invention, the result document includes a plurality of context blocks; Accordingly, the generating of enhanced prompts according to the result document, inputting the enhanced prompts and the input questions into the decision-making macro model, and obtaining a target question response specifically includes: Generate multiple enhanced prompts according to the multiple context blocks respectively, and generate and modify responses based on the decision model in combination with the input question and the context blocks corresponding to the enhanced prompts in sequence to obtain a target question response; Or, generating enhanced prompts according to all the context blocks, generating and generating strategies based on a plurality of the decision-making large models in combination with the input question and all the context blocks in the enhanced prompts, and obtaining a target question response; Or, summarize the context block, generate an enhanced prompt according to the summary result, generate a response based on the decision big model in combination with the input question and the enhanced prompt, and obtain a target question response; Alternatively, an enhanced prompt is generated based on all the context blocks, and a response is generated based on the large decision model in combination with the input question and the context blocks in the enhanced prompt to obtain multiple response outputs, and the response outputs are connected to obtain a target question response.
[0015] The present invention also provides a large model decision-making device based on an external knowledge base, comprising the following modules: A hypothetical response unit is used to input the input question into the pre-built decision-making model to obtain a hypothetical response; A vectorization unit, used to vectorize the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; A similarity retrieval unit, configured to use the input question vector and the hypothetical response vector to perform a joint search in a target vector database according to similarity, and retrieve the most similar result document from the target vector database according to the similarity; A response generation unit, used for generating an enhanced prompt according to the result document, inputting the enhanced prompt and the input question into the decision-making macro model, and obtaining a target question response; The target vector database is obtained by performing text segmentation, vectorization, and hierarchical index generation on the private domain data and storing the data in a preset vector database.
[0016] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, it implements any of the large model decision-making methods based on an external knowledge base as described above.
[0017] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements any of the large model decision-making methods based on an external knowledge base as described above.
[0018] The present invention also provides a computer program product, comprising a computer program, which, when executed by a processor, implements any of the large model decision-making methods based on an external knowledge base as described above.
[0019] The large model decision method and device based on the external knowledge base provided by the present invention obtains a hypothetical response by inputting an input question into a pre-built decision large model; vectorizing the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; using the input question vector and the hypothetical response vector, a joint search is performed in the target vector database according to the similarity, and the most similar result document is taken out from the target vector database according to the similarity; an enhanced prompt is generated according to the result document, and the enhanced prompt and the input question are input into the decision large model to obtain a target question response; wherein the target vector database is obtained after text segmentation, vectorization, hierarchical index generation and storage in a preset vector database for private domain data. The present invention places the private domain data in the external knowledge base into the target vector database, and in the process of generating the decision process, retrieves relevant knowledge from the target vector database according to the user's input, thereby assisting the decision large model to generate more accurate and relevant responses. The present invention not only expands the internal knowledge base of a specific field or organization, but also does not require retraining the model, and ensures the security of private domain data while ensuring the accuracy of the output results. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0021] Figure 1 This is one of the flow charts of the large model decision-making method based on the external knowledge base provided by the present invention.
[0022] Figure 2 This is the second flow chart of the large model decision-making method based on the external knowledge base provided by the present invention.
[0023] Figure 3 It is a structural schematic diagram of a large model decision-making device based on an external knowledge base provided by the present invention.
[0024] Figure 4 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0025] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings 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, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0026] Combine the following Figure 1-Figure 2 Describe the large model decision-making method based on external knowledge base of the present invention, Figure 1 This is one of the flow charts of the large model decision-making method based on the external knowledge base provided by the present invention, such as Figure 1 As shown, the method includes the following: Step 110: Input the input question into a pre-built decision-making model to obtain a hypothetical response.
[0027] The user inputs the input question (question) for query into the pre-built decision-making large model (LLM), and the model outputs a hypothetical response (answer).
[0028] It should be noted that before data retrieval, it is necessary to first construct a target vector database. The target vector database is obtained by performing text segmentation, vectorization, hierarchical index generation on the private domain data and storing it in a preset vector database. Specifically, the construction of the target vector database can also be understood as data preparation, which is generally an offline process, mainly the process of vectorizing the private domain data, building an index and storing it in the database. It mainly includes: data extraction, text segmentation, vectorization, generating hierarchical indexes, data warehousing and other links.
[0029] It is particularly important to point out that the large decision model referred to in step 110 is mainly a large language model that is obtained by training with data publicly available on the Internet and is in line with the application scenario, and the present invention is not limited to a specific model.
[0030] Step 120: vectorize the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector.
[0031] The input question and the hypothetical response are vectorized respectively. It should be noted that vectorization is a process of converting text data into a vector matrix, which directly affects the effect of subsequent retrieval. The present invention does not limit the specific method of vectorization.
[0032] Step 130: Utilize the input question vector and the hypothetical response vector to perform a joint search in a target vector database according to similarity, and extract the most similar result document from the target vector database according to the similarity.
[0033] In order to improve the quality of the search, the vector of the hypothetical response and the input question vector are used to perform a joint search in the target vector database, and the search quality is improved by enhancing the semantic similarity during the retrieval process to obtain the result document. The present invention does not limit the specific method of similarity calculation. In a specific embodiment, the BM25 algorithm and the cosine function are used for similarity calculation.
[0034] Step 140: Generate enhanced prompts according to the result document, input the enhanced prompts and the input questions into the decision-making model, and obtain a target question response.
[0035] That is to say, after obtaining the result document, an enhanced prompt is generated according to the result document, and the enhanced prompt is input into the LLM. The LLM combines the enhanced prompt and the input question for responsive generation to obtain the final target question response.
[0036] It is understandable that the prompt, as a direct input to the big model, is one of the key factors affecting the accuracy of the model output. Based on the user's question, through efficient retrieval methods, the most relevant knowledge to the question is recalled and integrated into the prompt. The big model refers to the current question and the relevant knowledge in the prompt to generate a more reliable answer.
[0037] In some embodiments, generating an enhanced prompt according to the result document specifically includes: generating an enhanced prompt through a prompt template. In order to further illustrate the enhanced prompt, a specific embodiment of a prompt template is given: template = """You are a question-answering robot assistant. Please use the following retrieved context to answer the question. If you don't know the answer, just say you don't know. The question is: {question}, Context: {context1,context2......}, The answer is: """ prompt = ChatPromptTemplate.from_template(template) .
[0038] It should be noted that the context is the context result (i.e., result document) obtained from the data retrieval step.
[0039] The present invention performs knowledge enhancement on input questions based on the retrieval of a target vector database, avoids model nonsense, and solves the problem of hallucination.
[0040] Further, the enhanced prompt is generated according to the result document, and the enhanced prompt and the input question are input into the decision model to obtain a target question response, and then the following is further included: Obtaining user feedback on responses to the target question, and fine-tuning the decision-making model based on the feedback; And / or, the decision big model and the target vector database are privately deployed.
[0041] Specifically, after the model is output, users can provide feedback on the results. The feedback provided by users is then systematically analyzed to identify repetitive problems, misunderstandings or deficiencies. The decision-making model is then fine-tuned as necessary to address these issues.
[0042] It should be noted that fine-tuning of the large model includes modifying the model architecture, adjusting parameters, selecting appropriate loss functions and optimization algorithms, etc. The present invention does not limit the specific adjustment method.
[0043] Afterwards, you can use the prepared data to train the adjusted model. Through iterative optimization algorithms, the model gradually fits the training data and improves performance. During this process, you can also monitor the performance of the large model on the validation set so that you can adjust the training strategy in a timely manner.
[0044] Furthermore, private deployment can be performed after step 140. Specifically, for the decision-making big model that needs to be adjusted, the fine-tuned decision-making big model and the target vector database are privately deployed. For the decision-making big model that does not need to be adjusted, it and the target vector database are directly privately deployed.
[0045] The construction of the target vector database is further described below. In some embodiments, the target vector database is obtained after the private domain data is subjected to text segmentation, vectorization, hierarchical index generation and stored in a preset vector database, specifically including: Get private domain data; Segmenting the private domain data according to titles to obtain text data corresponding to each title, and then segmenting the text data corresponding to each title according to process steps to obtain text data corresponding to the process steps, thereby obtaining a text segmentation result; The title and the process steps are used as metadata, and the text segmentation result is vectorized to obtain a title vector and a step vector; Constructing a title index for the title vector, constructing a step index for the step vector, and establishing an association relationship between the title index and the related step index; The title vector and the corresponding title index are stored in a first preset vector database to obtain a target title vector database, and the step vector and the corresponding step index are stored in a second preset vector database to obtain a target step vector database; A target vector database is obtained according to the target title vector database, the target step vector database and the association relationship.
[0046] Specifically, in the process of building the target vector database, Figure 2 As shown, private domain data needs to be collected first.
[0047] It can be understood that private domain data is the private data of the enterprise itself, including various forms of natural language data, such as pdf, txt, excel, mp3, etc. The present invention does not limit the specific form of private domain data, and it can be data in any format.
[0048] After that, the private domain data is segmented. It is understandable that text segmentation mainly considers two factors: 1) the token restrictions of the embedding model; 2) the impact of semantic integrity on the overall retrieval effect. The embodiment of the present invention segments the private domain data according to the title and process steps. Specifically, the title is first stripped out, and then the steps are stripped out to obtain the text segmentation result. It should be noted that in the text segmentation process, the title and steps need to be used as new metadata.
[0049] Afterwards, the text segmentation results are vectorized to obtain the title vector and step vector. In a specific embodiment, a personalized embedding model based on M3E-large is used for vectorization. By fine-tuning the original model, different weights are added to the title and step to facilitate subsequent classification and clustering tasks, while reducing the computational complexity and improving the efficiency of the model. It should be noted that Figure 2 As shown, step 120 may also be vectorized in the manner described in this embodiment.
[0050] After obtaining the title vector and the step vector, index construction is performed. Specifically, indexes are constructed according to the title and the step, and are written into the corresponding first preset vector database or the second preset vector database, respectively, so as to obtain the target title vector database and the target step vector database, respectively.
[0051] It should be further explained that the first preset vector database and the second preset vector database can be selected based on a comprehensive consideration of multiple factors such as business scenarios, hardware, performance requirements, etc. In some embodiments, the first preset vector database and the second preset vector database applicable to the scenario include: FAISS, Chromadb, ES, milvus, etc.
[0052] In addition, during the actual retrieval process, the private domain data can be updated using the input questions entered by the user and the hypothetical responses of the decision-making model, thereby updating the target vector database. This does not require fine-tuning of the entire model, greatly saving costs and budget.
[0053] The following is a further explanation of the index construction: two indexes are created corresponding to the title vector and the step vector, one consisting of the title index and the other consisting of the step index, and an association relationship is established between the two indexes, such as Figure 2 shown.
[0054] The target title vector database, the target step vector database and the association relationship together constitute the target vector database.
[0055] The target vector database mentioned in the embodiment of the present invention is a dedicated data set constructed for decision-making type problems, which enhances the model decision solution generation capability. In addition, due to the construction form of the target vector database in the embodiment of the present invention, the present invention is more friendly to process data support, simple to maintain, convenient for iteration, and the result response is more accurate and fast.
[0056] In addition, during the search process, the search is performed in two steps. First, the question is searched through the title index, and the steps associated with the title are brought out. Secondly, the answer is searched through the step index, and the title content is brought out in reverse.
[0057] The following further describes the joint search. In some embodiments, the use of the input question vector and the hypothetical response vector to perform a joint search in a target vector database according to similarity, and extracting the most similar result document from the target vector database according to the similarity, specifically includes: Calculate a first similarity of the input question vector in the target title vector database, and calculate a second similarity of the hypothetical response vector in the target step vector database; Calculate a first angle of the input question vector in the target title vector database, and calculate a second angle of the hypothetical response vector in the target step vector database; A weighted calculation is performed according to the first similarity, the second similarity, the first angle, and the second angle, and the most similar result document is retrieved from the target vector database according to the result of the weighted calculation.
[0058] Specifically, the input question vector is used to search in the target title vector database to calculate the first similarity of question in the target title vector database; at the same time, the hypothetical response vector is used to search in the target step vector database to calculate the second similarity of Answer in the target step vector database.
[0059] In order to further illustrate the similarity calculation, this embodiment uses the BM25 algorithm to calculate the similarity as an example, but it does not represent a limitation to the present invention.
[0060] The BM25 formula is as follows; .
[0061] in, Indicates the number of times the term appears in the requested field; Indicates the inverse document frequency (IDF) of the term; ; K represents control (word frequency) parameter factors; C represents the parameters that control the weight of the retrieval unit; B represents the parameters that control (Field length) parameters affected; express.
[0062] BM25 provides multiple functions to facilitate users to control various parameters in the calculation formula and customize BM25.
[0063] In the actual calculation process, the first similarity of question in the target title vector database is calculated, and the second similarity of answer in the target step vector database is calculated. Substituting into the BM25 formula, the two results are: First similarity: BMQT, second similarity: BMAD.
[0064] Furthermore, a first angle between the input question vector in the target title vector database and a second angle between the hypothetical response vector in the target step vector database are calculated.
[0065] In order to further illustrate the similarity calculation, this embodiment uses the cosine function to calculate the vector angle as an example for illustration, but it does not represent a limitation to the present invention.
[0066] The cosine formula is as follows: .
[0067] In the actual calculation process, the first angle of question in the target title vector database is calculated, and the second angle of answer in the target step vector database is calculated. Substituting into the above formula, we can get two results: the first angle cosQ = (question·T) / (|question||T|); the second angle cosA = (answer·D) / (|answer||D|); where T represents the title index and D represents the step index.
[0068] After obtaining the first similarity, the second similarity, the first angle and the second angle, the expanded prompt word is retrieved from the vector library according to the weighted formula based on the comprehensive calculation results.
[0069] The weighted formula is as follows: .
[0070] .
[0071] Among them, K1, K2, K3, and K4 are weights, which can balance the dimensions so that the two formulas maintain equivalent effectiveness. Finally, the most similar result document is taken out from the target vector database based on the result of the weighted calculation.
[0072] The following further describes the extraction of the result document. In some embodiments, the extracting of the most similar result document from the target vector database according to the result of the weighted calculation specifically includes: Retrieving text data from the target vector database according to the index corresponding to the result of the weighted calculation; Encoding the text data, and scoring and predicting the encoded text data using a cross encoder model to obtain a relevance score of the text data; Classification and clustering are performed according to the relevance scores, and reorganization is performed according to the classification and clustering results to obtain a result document.
[0073] Specifically, at the index corresponding to the result of the weighted calculation, text data is taken out from the target vector database and rearranged and filtered to obtain a result document. The present invention does not limit the specific manner of rearrangement and filtering.
[0074] In order to illustrate the rearrangement filtering, this embodiment uses a sentence-transformer cross encoder to perform the rearrangement filtering, but this does not represent a limitation to the present invention.
[0075] First, the sentence is encoded. In one embodiment, based on the loaded large language model, the sentence is encoded using the encode_plus method. For example, encoding a single sentence includes: sentence = "Your input sentence here" sentence_embedding = model.encode(sentence); Encoding multiple sentences involves: sentences = ["Your input sentence 1 here", "Your input sentence 2here"] sentence_embeddings = model.encode(sentences).
[0076] After that, the cross encoder is used to make predictions. For example, predicting the relevance score of a sentence pair includes: score = cross_encoder.predict([(sentence1, sentence2)]); Predicting the relevance scores for multiple sentence pairs involves: scores = cross_encoder.predict(list_of_sentence_pairs).
[0077] After obtaining the relevance scores of the sentences, classification and clustering are performed and the results are reorganized to obtain the result document.
[0078] Furthermore, the input question input by the user is likely to be a relatively complex query, on which basis the input question includes multiple subtasks. In the case where the input question includes multiple subtasks, the enhanced prompt is generated based on the most similar result documents of the multiple subtasks and the input question.
[0079] Specifically, for complex queries, the decision model can split them into multiple sub-queries. For example, if the input question is: "Shanghai commercial housing transaction transfer", if there is no direct hit in the target vector database, this question can be decomposed into several simpler, specific and reasonable sub-query tasks: "Shanghai commercial housing", "commercial housing transactions", "commercial housing transfers".
[0080] These sub-query tasks are respectively used as questions of the input decision model to execute steps 110 to 130 in parallel. The retrieved result documents are then summarized into an LLM prompt word (enhanced prompt), and a more general query is generated based on the LLM using the enhanced prompt, so as to retrieve a more general or high-level context to provide an answer to the original query.
[0081] Based on the above embodiments, in some embodiments, during the execution of the sub-query tasks respectively, the retrieval of the original input question can also be performed simultaneously to obtain the result document summarized by the sub-query tasks and the result document of the original input question respectively, and in the final answer generation step, the two contexts (result documents) are sent to the LLM, and the LLM is used to rephrase the initial query to improve the retrieval.
[0082] Further, in some embodiments, the result document includes a plurality of context blocks; Accordingly, the generating of enhanced prompts according to the result document, inputting the enhanced prompts and the input questions into the decision-making macro model, and obtaining a target question response specifically includes: Generate multiple enhanced prompts according to the multiple context blocks respectively, and generate and modify responses based on the decision model in combination with the input question and the context blocks corresponding to the enhanced prompts in sequence to obtain a target question response; Or, generating enhanced prompts according to all the context blocks, generating and generating strategies based on a plurality of the decision-making large models in combination with the input question and all the context blocks in the enhanced prompts, and obtaining a target question response; Or, summarize the context block, generate an enhanced prompt according to the summary result, generate a response based on the decision big model in combination with the input question and the enhanced prompt, and obtain a target question response; Alternatively, an enhanced prompt is generated based on all the context blocks, and a response is generated based on the large decision model in combination with the input question and the context blocks in the enhanced prompt to obtain multiple response outputs, and the response outputs are connected to obtain a target question response.
[0083] Specifically, answers are generated based on the retrieved result documents and the initial user input question. The LLM is enhanced with external data to improve the quality of the response. In the case where the result document includes multiple context blocks, the generation strategies for the target question response are mainly the following: 1): The same LLM model combines the relevant text of each retrieved context block in turn and corrects the generated text. In other words, multiple enhanced prompts are generated based on multiple context blocks. Based on the same decision model, the input question and the context blocks corresponding to the enhanced prompt are combined in turn to generate and correct the response, and finally the target question response is obtained.
[0084] 2): Multiple LLM models generate and generate strategies for the relevant text of all retrieved context blocks. That is, an enhanced prompt is generated based on all context blocks, and multiple decision-making large models are combined with all context blocks in the input question and enhanced prompts to generate and generate strategies to obtain the target question response. It needs to be explained that multiple decision-making large models include a generator and a discriminator. The generator generates possible strategies or answers based on all retrieved context blocks. The discriminator is used to distinguish between real strategies and fake strategies generated by the generator. The discriminator usually evaluates the quality of the generated strategies to determine whether they are real enough or meet specific standards. When judged by the discriminator, the target question response is obtained.
[0085] 3): Summarize the retrieved context to fit the prompt. That is, summarize the context block, generate an enhanced prompt based on the summary result, and generate a response based on the decision model by combining the input question and the enhanced prompt to obtain the target question response.
[0086] 4): Generate multiple answers based on different context blocks, and then connect or summarize them. That is, generate enhanced prompts based on all context blocks, generate responses based on the decision model by combining the input question and context blocks, obtain multiple response outputs, connect or summarize the response outputs, and obtain the target question response.
[0087] It is understandable that during the search process, because the user's input can be viewed from different perspectives, the result documents that can be obtained may include context blocks from different perspectives, and more diverse content fragments will appear in the target question response obtained accordingly. Compared with content paragraphs that focus on a single perspective, embodiments of the present invention are more likely to see content that can cover multiple aspects of a topic appear as top results.
[0088] In addition, embodiments of the present invention use LLM as a middleman between what a user enters in a text box and what is actually searched for in a database, which can automatically correct spelling errors, add contextual information related to the user's query (information about the user, time, their account status, etc.), and / or potentially filter specific types of content, thereby making the output response more accurate.
[0089] The large model decision method based on the external knowledge base provided by the present invention obtains a hypothetical response by inputting an input question into a pre-built decision large model; vectorizing the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; using the input question vector and the hypothetical response vector, a joint search is performed in the target vector database according to the similarity, and the most similar result document is taken out from the target vector database according to the similarity; an enhanced prompt is generated according to the result document, and the enhanced prompt and the input question are input into the decision large model to obtain a target question response; wherein the target vector database is obtained after text segmentation, vectorization, hierarchical index generation and storage in a preset vector database for private domain data. The present invention places the private domain data in the external knowledge base into the target vector database, and in the process of generating the decision process, retrieves relevant knowledge from the target vector database according to the user's input, thereby assisting the decision large model to generate more accurate and relevant responses. The present invention not only expands the internal knowledge base of a specific field or organization, but also does not require retraining the model, and ensures the security of private domain data while ensuring the accuracy of the output results.
[0090] The following is a description of the large model decision device based on an external knowledge base provided by the present invention. The large model decision device based on an external knowledge base described below and the large model decision method based on an external knowledge base described above can be referred to each other. Figure 3 As shown, the device includes the following modules: A hypothetical response unit 310 is used to input the input question into the pre-built decision-making model to obtain a hypothetical response; A vectorization unit 320, configured to vectorize the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; A similarity retrieval unit 330, configured to use the input question vector and the hypothetical response vector to perform a joint search in a target vector database according to similarity, and retrieve the most similar result document from the target vector database according to the similarity; A response generation unit 340 is used to generate an enhanced prompt according to the result document, and input the enhanced prompt and the input question into the decision model to obtain a target question response; The target vector database is obtained by performing text segmentation, vectorization, and hierarchical index generation on the private domain data and storing the data in a preset vector database.
[0091] According to a large model decision device based on an external knowledge base provided by the present invention, the enhanced prompt is generated according to the result document, the enhanced prompt and the input question are input into the decision large model to obtain a target question response, and then the following is further included: Obtaining user feedback on responses to the target question, and fine-tuning the decision-making model based on the feedback; And / or, the decision big model and the target vector database are privately deployed.
[0092] According to a large model decision device based on an external knowledge base provided by the present invention, the target vector database is obtained after text segmentation, vectorization, and hierarchical index generation are performed on the private domain data and stored in a preset vector database, specifically including: Get private domain data; Segmenting the private domain data according to titles to obtain text data corresponding to each title, and then segmenting the text data corresponding to each title according to process steps to obtain text data corresponding to the process steps, thereby obtaining a text segmentation result; The title and the process steps are used as metadata, and the text segmentation result is vectorized to obtain a title vector and a step vector; Constructing a title index for the title vector, constructing a step index for the step vector, and establishing an association relationship between the title index and the related step index; The title vector and the corresponding title index are stored in a first preset vector database to obtain a target title vector database, and the step vector and the corresponding step index are stored in a second preset vector database to obtain a target step vector database; A target vector database is obtained according to the target title vector database, the target step vector database and the association relationship.
[0093] According to a large model decision device based on an external knowledge base provided by the present invention, the input question vector and the hypothetical response vector are used to perform a joint search in a target vector database according to similarity, and the most similar result document is taken out from the target vector database according to the similarity, specifically including: Calculate a first similarity of the input question vector in the target title vector database, and calculate a second similarity of the hypothetical response vector in the target step vector database; Calculate a first angle of the input question vector in the target title vector database, and calculate a second angle of the hypothetical response vector in the target step vector database; A weighted calculation is performed according to the first similarity, the second similarity, the first angle, and the second angle, and the most similar result document is retrieved from the target vector database according to the result of the weighted calculation.
[0094] According to a large model decision device based on an external knowledge base provided by the present invention, when the input question includes multiple subtasks, the enhanced prompt is generated based on the most similar result documents of the multiple subtasks and the input question.
[0095] According to a large model decision device based on an external knowledge base provided by the present invention, the most similar result document is taken out from the target vector database according to the result of weighted calculation, specifically including: Retrieving text data from the target vector database according to the index corresponding to the result of the weighted calculation; Encoding the text data, and scoring and predicting the encoded text data using a cross encoder model to obtain a relevance score of the text data; Classification and clustering are performed according to the relevance scores, and reorganization is performed according to the classification and clustering results to obtain a result document.
[0096] According to a large model decision-making device based on an external knowledge base provided by the present invention, the result document includes a plurality of context blocks; Accordingly, the generating of enhanced prompts according to the result document, inputting the enhanced prompts and the input questions into the decision-making macro model, and obtaining a target question response specifically includes: Generate multiple enhanced prompts according to the multiple context blocks respectively, and generate and modify responses based on the decision model in combination with the input question and the context blocks corresponding to the enhanced prompts in sequence to obtain a target question response; Or, generating enhanced prompts according to all the context blocks, generating and generating strategies based on a plurality of the decision-making large models in combination with the input question and all the context blocks in the enhanced prompts, and obtaining a target question response; Or, summarize the context block, generate an enhanced prompt according to the summary result, generate a response based on the decision big model in combination with the input question and the enhanced prompt, and obtain a target question response; Alternatively, an enhanced prompt is generated based on all the context blocks, and a response is generated based on the large decision model in combination with the input question and the context blocks in the enhanced prompt to obtain multiple response outputs, and the response outputs are connected to obtain a target question response.
[0097] The large model decision device based on the external knowledge base provided by the present invention obtains a hypothetical response by inputting an input question into a pre-built decision large model; vectorizing the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; using the input question vector and the hypothetical response vector, a common search is performed in the target vector database according to the similarity, and the most similar result document is taken out from the target vector database according to the similarity; an enhanced prompt is generated according to the result document, and the enhanced prompt and the input question are input into the decision large model to obtain a target question response; wherein the target vector database is obtained after text segmentation, vectorization, hierarchical index generation and storage in a preset vector database for private domain data. The present invention places the private domain data in the external knowledge base into the target vector database, and in the process of generating the decision process, retrieves relevant knowledge from the target vector database according to the user's input, thereby assisting the decision large model to generate more accurate and relevant responses. The present invention not only expands the internal knowledge base of a specific field or organization, but also does not require retraining the model, and ensures the security of private domain data while ensuring the accuracy of the output results.
[0098] Figure 4 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 4 As shown, the electronic device may include: a processor 410, a communication interface 420, a memory 430 and a communication bus 440, wherein the processor 410, the communication interface 420 and the memory 430 communicate with each other through the communication bus 440. The processor 410 may call the logic instructions in the memory 430 to execute the large model decision method based on the external knowledge base, the method comprising: inputting the input question into the pre-built decision large model to obtain a hypothetical response; vectorizing the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; using the input question vector and the hypothetical response vector to jointly search in the target vector database according to the similarity, and taking out the most similar result document from the target vector database according to the similarity; generating an enhanced prompt according to the result document, inputting the enhanced prompt and the input question into the decision large model to obtain a target question response; wherein the target vector database is obtained after performing text segmentation, vectorization, hierarchical index generation and storing the private domain data in a preset vector database.
[0099] In addition, the logic instructions in the above-mentioned memory 430 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.
[0100] On the other hand, the present invention also provides a computer program product, which includes a computer program, which can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the large model decision method based on the external knowledge base provided by the above methods, and the method includes: inputting an input question into a pre-built decision large model to obtain a hypothetical response; vectorizing the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; using the input question vector and the hypothetical response vector to perform a joint search in a target vector database according to similarity, and extracting the most similar result document from the target vector database according to the similarity; generating an enhanced prompt based on the result document, and inputting the enhanced prompt and the input question into the decision large model to obtain a target question response; wherein, the target vector database is obtained after text segmentation, vectorization, and hierarchical index generation of private domain data and storing them in a preset vector database.
[0101] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the large model decision method based on an external knowledge base provided by the above-mentioned methods, the method comprising: inputting an input question into a pre-built decision large model to obtain a hypothetical response; vectorizing the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; using the input question vector and the hypothetical response vector to perform a joint search in a target vector database according to similarity, and extracting the most similar result document from the target vector database according to the similarity; generating an enhanced prompt based on the result document, and inputting the enhanced prompt and the input question into the decision large model to obtain a target question response; wherein the target vector database is obtained by performing text segmentation, vectorization, and hierarchical index generation on private domain data and storing them in a preset vector database.
[0102] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0103] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0104] 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 it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A large model decision-making method based on an external knowledge base, characterized in that: include: Input questions are fed into a pre-built decision-making model to obtain hypothetical responses; Vectorizing the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; Using the input question vector and the hypothetical response vector, perform a joint search in a target vector database according to similarity, and extract the most similar result document from the target vector database according to the similarity; Generate an enhanced prompt according to the result document, input the enhanced prompt and the input question into the decision-making model, and obtain a target question response; The target vector database is obtained by performing text segmentation, vectorization, and hierarchical index generation on the private domain data and storing the data in a preset vector database.
2. The large model decision-making method based on external knowledge base according to claim 1 is characterized in that: The step of generating an enhanced prompt according to the result document, inputting the enhanced prompt and the input question into the decision-making model to obtain a target question response, and then further comprising: Obtaining user feedback on responses to the target question, and fine-tuning the decision-making model based on the feedback; And / or, the decision big model and the target vector database are privately deployed.
3. The large model decision-making method based on external knowledge base according to claim 1 is characterized in that: The target vector database is obtained by performing text segmentation, vectorization, and hierarchical index generation on the private domain data and storing the data in a preset vector database, which specifically includes: Get private domain data; Segmenting the private domain data according to titles to obtain text data corresponding to each title, and then segmenting the text data corresponding to each title according to process steps to obtain text data corresponding to the process steps, thereby obtaining a text segmentation result; The title and the process steps are used as metadata, and the text segmentation result is vectorized to obtain a title vector and a step vector; Constructing a title index for the title vector, constructing a step index for the step vector, and establishing an association relationship between the title index and the related step index; The title vector and the corresponding title index are stored in a first preset vector database to obtain a target title vector database, and the step vector and the corresponding step index are stored in a second preset vector database to obtain a target step vector database; A target vector database is obtained according to the target title vector database, the target step vector database and the association relationship.
4. The large model decision-making method based on external knowledge base according to claim 3 is characterized in that: The using the input question vector and the hypothetical response vector to perform a joint search in a target vector database according to similarity, and extracting the most similar result document from the target vector database according to the similarity, specifically includes: Calculate a first similarity of the input question vector in the target title vector database, and calculate a second similarity of the hypothetical response vector in the target step vector database; Calculate a first angle of the input question vector in the target title vector database, and calculate a second angle of the hypothetical response vector in the target step vector database; A weighted calculation is performed according to the first similarity, the second similarity, the first angle, and the second angle, and the most similar result document is retrieved from the target vector database according to the result of the weighted calculation.
5. The large model decision-making method based on external knowledge base according to claim 1 is characterized in that: In the case that the input question includes multiple subtasks, the enhanced prompt is generated based on the most similar result documents of the multiple subtasks and the input question.
6. The large model decision-making method based on external knowledge base according to claim 4 is characterized in that: The extracting the most similar result document from the target vector database according to the result of the weighted calculation specifically includes: Retrieving text data from the target vector database according to the index corresponding to the result of the weighted calculation; Encoding the text data, and scoring and predicting the encoded text data using a cross encoder model to obtain a relevance score of the text data; Classification and clustering are performed according to the relevance scores, and reorganization is performed according to the classification and clustering results to obtain a result document.
7. The large model decision-making method based on external knowledge base according to claim 1 is characterized in that: The result document includes a plurality of context blocks; Accordingly, the generating of enhanced prompts according to the result document, inputting the enhanced prompts and the input questions into the decision-making macro model, and obtaining a target question response specifically includes: Generate multiple enhanced prompts according to the multiple context blocks respectively, and generate and modify responses based on the decision model in combination with the input question and the context blocks corresponding to the enhanced prompts in sequence to obtain a target question response; Or, generating enhanced prompts according to all the context blocks, generating and generating strategies based on a plurality of the decision-making large models in combination with the input question and all the context blocks in the enhanced prompts, and obtaining a target question response; Or, summarize the context block, generate an enhanced prompt according to the summary result, generate a response based on the decision big model in combination with the input question and the enhanced prompt, and obtain a target question response; Alternatively, an enhanced prompt is generated based on all the context blocks, and a response is generated based on the large decision model in combination with the input question and the context blocks in the enhanced prompt to obtain multiple response outputs, and the response outputs are connected to obtain a target question response.
8. A large model decision-making device based on an external knowledge base, characterized in that: include: A hypothetical response unit is used to input the input question into the pre-built decision-making model to obtain a hypothetical response; A vectorization unit, used to vectorize the input question and the hypothetical response respectively to obtain an input question vector and a hypothetical response vector; A similarity retrieval unit, configured to use the input question vector and the hypothetical response vector to perform a joint search in a target vector database according to similarity, and retrieve the most similar result document from the target vector database according to the similarity; A response generation unit, used for generating an enhanced prompt according to the result document, inputting the enhanced prompt and the input question into the decision-making macro model, and obtaining a target question response; The target vector database is obtained by performing text segmentation, vectorization, and hierarchical index generation on the private domain data and storing the data in a preset vector database.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, it implements the large model decision-making method based on the external knowledge base as described in any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the large model decision-making method based on an external knowledge base as described in any one of claims 1 to 7 is implemented.