Multi-level domain knowledge question answering method and device based on large model
By building a multi-level knowledge question and answer system, using the big model for intent identification and data source calls, the problem of low security, update and retrieval efficiency of the big model in actual applications is solved, and more efficient and accurate knowledge question and answer is achieved.
Patent Information
- Application Number
- CN202411730453.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-29
- Publication Date
- 2025-03-07
- Estimated Expiration
- 2044-11-29
AI Technical Summary
Large models face hallucinations and security problems in actual applications, their knowledge updates are not timely, and they simply rely on the knowledge base Q&A API to have low retrieval efficiency.
A multi-level domain knowledge question and answer method based on big models is proposed. By obtaining user history question and answer sets, document sets and service sets, they build knowledge bases and tool libraries, and use open source big models to identify intentions and call data source to generate the optimal answer.
It improves the real-time and accuracy of private data Q&A, enhances the flexibility and reliability of model processing complex problems, and provides more comprehensive and accurate answers.
Smart Images

Figure CN119202213B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a multi-level domain knowledge question-answering method and device based on a large model. Background Art
[0002] Large models are one of the important advances in the field of artificial intelligence in recent years. They have powerful natural language processing and generation capabilities. These models have mastered a wide range of language knowledge by training on large amounts of text data, and are able to outperform traditional models in many tasks. However, despite the significant advantages of large models, there are still some problems and challenges in practical applications.
[0003] First, large models face hallucination and security issues. Since the training data may contain sensitive information, the model may inadvertently leak this information during the generation process. In addition, the output of the model is sometimes difficult to predict and may produce inappropriate or harmful content, posing security risks. Secondly, the problem of untimely knowledge updating is also a major challenge for large models. After the model is trained, its internal knowledge is no longer updated, which means that it cannot reflect the latest information and events. Therefore, in a rapidly changing environment, the effectiveness and practicality of the model will be limited.
[0004] In order to deal with these problems, combining external knowledge question and answer APIs is an effective method. The knowledge base question and answer API provides users with accurate and timely answers by building and maintaining knowledge bases in professional fields. However, relying solely on the knowledge base question and answer API also has its limitations. For example, when irrelevant knowledge is retrieved, it will slow down the process and reduce the effectiveness of use. Therefore, it is crucial to improve the performance of knowledge retrieval. At the same time, in order to further enhance the timeliness and flexibility of large models, tool libraries and intelligent agent modes can be introduced to provide large models with real-time information acquisition channels by integrating external API services, thereby improving the accuracy and timeliness of their responses and enhancing the flexibility and reliability of the model in handling complex problems. Summary of the invention
[0005] Purpose of the invention: To propose a multi-level domain knowledge question-answering method and device based on a large model, so as to further improve the real-time and accuracy of private data question-answering, and solve the above-mentioned problems existing in the prior art.
[0006] In a first aspect of the present invention, a multi-level domain knowledge question answering method based on a large model is proposed, and the steps are as follows:
[0007] Obtain the user's historical question and answer set, document set, and service set; the question and answer set records the user's question and answer information, the document set records the user's private domain document information, and the service set records the user's data service information;
[0008] Building a knowledge base based on the question and answer set and the document set, wherein the knowledge base includes a question and answer base and a document base;
[0009] Building a tool library based on the service set, the tool library is used for registration and calling of data services;
[0010] Select an open source big model, collect historical question and answer information of users from the question and answer set and mark their intentions, and use the historical question and answer information with marked intentions to fine-tune the open source big model to obtain an intention model;
[0011] Obtain a user question Q and a chat record H, use the intention model to identify the intention of the user question Q, and obtain the intention category;
[0012] According to different intent categories, the intent model is used to call different data sources to obtain the answer A corresponding to the user question Q;
[0013] The generated answer A is returned to the user, and the user question Q and answer A are saved in the chat history.
[0014] In a further embodiment of the first aspect, the process of constructing the question and answer library includes:
[0015] The question and answer set is vectorized through a vector model to obtain a question vector and an answer vector, and stored in a question vector library respectively. and answer vector library ; The vector model selects the open source BGE model;
[0016] The construction process of the document library includes:
[0017] Extract text content from various document formats, preprocess the text content, and obtain preprocessed text;
[0018] Segment the preprocessed text to obtain multiple text blocks;
[0019] The content of the text block is segmented and stored in the full-text search engine The text block content is vectorized through the vector model and stored in the document vector library middle.
[0020] In a further embodiment of the first aspect, the process of extracting text content in various document formats and preprocessing the text content specifically includes:
[0021] Detect and extract the table data part in the text, convert it into markdown format and restore it to the text;
[0022] Remove extra spaces, line breaks, and special characters from text;
[0023] The following rules are used to segment the preprocessed text:
[0024] The preprocessed text is segmented cyclically according to paragraphs and sentences until the text block length L is not exceeded, and the content of each text block is the segmented text;
[0025] For the table content in markdown format in the preprocessed text, it is treated as a separate text block and does not participate in segmentation. The open source big model is used to summarize the table content, and the summary result is used as the content of the current text block, and the original table content is stored in the metadata of the text block.
[0026] In a further embodiment of the first aspect, the tool library is used for registration and invocation of data services; wherein registration of data services includes:
[0027] Standardize various data service information and register them in the tool library; the standardized service information includes service name, service description, service category, service address, calling method, input parameter details, and output parameter details;
[0028] The call of data service includes pre-call processing and post-call processing; the pre-call processing includes the verification of input parameters, the throwing of corresponding exception information and the formatting of input parameters; the post-call processing includes the verification of response data, the throwing of corresponding exception information, the parsing of response data and the formatting of response data.
[0029] In a further embodiment of the first aspect, the open source large model is one of Qwen, GLM, and Llama.
[0030] The open source large model is fine-tuned using historical question-and-answer information with marked intent to obtain an intent model; the loss function of the intent model is as follows:
[0031]
[0032]
[0033] In the formula, is the weight of intent category i, The true intent category label is The label probability distribution predicted by the model, S is the total number of samples, C is the number of intent categories, is a sample of intent category i;
[0034] The intent categories include general knowledge question answering, domain knowledge question answering, and domain data question answering;
[0035] When the user intention category is general knowledge question and answer, the chat record H and the user question Q are directly input into the open source big model to generate the answer A;
[0036] When the user intention category is not general knowledge question answering, based on the chat record H, the question optimization prompt is introduced to optimize the user question Q to obtain the optimized user question .
[0037] In a further embodiment of the first aspect, when the user intention category includes a domain knowledge question and answer, calling data from the knowledge base specifically includes:
[0038] Use vector models to optimize user questions Vectorize to get the user question vector ;
[0039] Calculate the user question vector separately Vector Library with Questions and answer vector library Similarity of vectors in the weighted fusion as an optimization problem Similarity with the question-answer pairs in the question-answer database :
[0040]
[0041] In the formula, , is the problem vector Similarity with question vectors in the question vector library; , is the problem vector Similarity with the answer vector in the answer vector library; , 2 respectively correspond to the similarity , Similarity The weight of;
[0042] Get similarity Maximum value The corresponding question-answer pair is taken as a candidate question-answer pair. When it is greater than the threshold t1, the answer in the candidate question-answer pair is directly used as answer A;
[0043] when When it is less than the threshold t1, the user question vector is used Searching from the document library includes:
[0044] Calculate the user question vector With the document vector library Similarity of text block vectors in Chinese, get the top K text block sets in similarity ranking ;
[0045] Use the full-text search engine Computing User Problems The keyword matching degree with the text block, obtain the top K text blocks with the highest matching degree ;
[0046] Merge a collection of text blocks and , and remove duplicates to get a set of text blocks , using the rearrangement model to calculate user questions and Similarity of Chinese text blocks , get The set of text blocks greater than the threshold t2 ;
[0047] If the text block collection If there is table content in the metadata of the text block, the content of the text block is replaced with the table content, otherwise it remains unchanged.
[0048] In a further embodiment of the first aspect, when the user intent category includes a domain data question and answer, calling data from the tool library specifically includes:
[0049] Use the open source big model to target user problems Perform analysis and output the service name and parameter information that need to be called;
[0050] The service name and parameter information to be called are passed into the tool library to obtain the service call result S;
[0051] When the tool library throws an exception, the exception information is returned to the open source big model for re-analysis until the tool library throws no exception or the maximum number of analysis rounds is reached;
[0052] The chat record H and text block collection , service call result S, user question Q are input into the open source big model to generate answer A.
[0053] According to a second aspect of the present invention, a multi-level question-answering device is proposed, which includes a historical data acquisition unit, a library construction unit, a large model calling module, a question-answering execution module, and an answer generation module.
[0054] The historical data acquisition unit is used to obtain the user's historical question and answer set, document set, and service set.
[0055] The library construction unit is used to construct a knowledge base based on the question and answer set and the document set, and to construct a tool library based on the service set; the tool library is used for registration and calling of data services.
[0056] The large model calling module is used to call the open source large model, collect the user's historical question and answer information from the question and answer set and mark its intention, and use the historical question and answer information marked with intention to fine-tune the open source large model to obtain an intention model.
[0057] The question-and-answer execution module is used to obtain user questions Q and chat records H, use the intent model to identify the intent of the user question Q, and obtain the intent category; according to different intent categories, use the intent model to call different data sources to obtain the answer A corresponding to the user question Q.
[0058] The answer generation module is used to return the generated answer A to the user and save the user question Q and the answer A into the chat record.
[0059] According to a third aspect of the present invention, an electronic device is proposed, comprising a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the multi-level domain knowledge question and answer method based on a large model as described in the first aspect is implemented.
[0060] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, which stores at least one executable instruction. When the executable instruction is executed on an electronic device, the electronic device executes the multi-level domain knowledge question-answering method based on a large model as described in the first aspect.
[0061] Compared with the prior art, the present invention has the following beneficial effects:
[0062] (1) The multi-level question-answering method proposed in this invention deeply integrates the knowledge base and the tool library, covering multiple data sources, including question-answering data, document data, and service data. Using this method, we can first obtain relevant information from the knowledge base, and also call the service API in the tool library to obtain supplementary data. Finally, the large model generates the optimal answer, providing a more comprehensive and accurate answer.
[0063] (2) The multi-level question-answering method provided by the present invention has a flexible multi-level processing mechanism. Through intent recognition, it can dynamically call the knowledge base, tool library, or directly use the large model to generate answers, ensuring that user queries are responded to in a timely manner.
[0064] (3) The multi-level question-answering method provided by the present invention can be used not only for single-round dialogues, but also for multi-round dialogues. Through question optimization, the accuracy of calling data from the knowledge base and tool library can be improved, thereby ensuring the continuity of the dialogue and providing personalized answers that better meet user needs.
[0065] (4) During the text content extraction process, the present invention formats the table data and retains its integrity, thereby improving data readability and data quality, and can effectively improve the accuracy of the model question answering.
[0066] (5) In the process of retrieving text blocks in a document library, the present invention integrates the use of vector semantic matching and keyword matching methods to perform preliminary recall and then sorting, thereby improving the accuracy and recall rate of the retrieval results.
[0067] (6) The present invention implements special call exception processing in the tool library service call module to improve the fault tolerance of service calls, provide space and direction for the model to self-optimize, and effectively improve the stability of the model question and answer. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Figure 1 It is a flowchart of a multi-level domain knowledge question-answering method based on a large model in an embodiment of the present invention.
[0069] Figure 2 It is a flow chart of performing question and answer according to different intentions in an embodiment of the present invention.
[0070] Figure 3 Schematic diagram of the structure of a multi-level question-answering device in an embodiment of the present invention. DETAILED DESCRIPTION
[0071] In the following description, a large number of specific details are provided to provide a more thorough understanding of the present invention. However, it is apparent to those skilled in the art that the present invention can be implemented without one or more of these details. In other examples, in order to avoid confusion with the present invention, some technical features known in the art are not described.
[0072] Reference Figure 1 As shown, the present invention discloses a multi-level domain knowledge question-answering method based on a large model. This method combines retrieval enhancement and agent API calls, and calls different data sources to assist in answering user questions by identifying different user intentions, which significantly improves the accuracy of knowledge question-answering results and the real-time nature of knowledge acquisition. The specific steps of the multi-level knowledge question-answering method are as follows:
[0073] S10. Obtain historical question and answer sets, document sets, and service sets.
[0074] The question-answer set is a set of question-answer pairs {(Q1,A1),...,(Qn,An)}, where Qi is the question and Ai is the answer corresponding to Qi, such as the frequently asked questions (FAQ) for product or agent consultation.
[0075] The document set is the user's private domain document information {DOC1,...,DOCn}, such as some product description documents.
[0076] The service set is the user's data service information {API1,...,APIn}, such as passenger flow information query service, work order information query service, stock price query service, etc.
[0077] S20. Build a knowledge base based on the question and answer set and the document set, including a question and answer library and a document library.
[0078] The question and answer library is used to store the user's question and answer information, and the document library is used to store the user's private domain document information.
[0079] S201, the construction of the question and answer database includes vectorizing the questions and answers in all question and answer pairs through the vector model to obtain question vectors and answer vectors, and storing them in the question vector database respectively. and answer vector library .
[0080] The vector model in this embodiment is a BGE model.
[0081] S202. The steps for constructing the document library are as follows:
[0082] S2021. Use a document loader to extract text content from various document formats and perform preprocessing to obtain preprocessed text.
[0083] Document formats include PDF and Word documents. Word documents include .doc and .docx.
[0084] Preprocessing includes automatically detecting and extracting the table data part in the text, converting it into markdown format and restoring it to the text. Furthermore, preprocessing also includes removing extra spaces, line breaks and special characters.
[0085] Specifically, the extraction of text content from a PDF refers to extracting text information from a PDF document through a PDF parsing library and converting it into an editable text format to ensure the accuracy of subsequent processing.
[0086] Specifically, PDF preprocessing refers to automatically detecting and extracting table data from the table content in the PDF document by analyzing the table boundaries and cell information in the PDF elements, and converting it into Markdown format. This not only facilitates subsequent data processing and display, but also ensures that the structure and content of the table data are not distorted, including the following:
[0087] Table boundary detection: Analyze the element information in the PDF and accurately identify the table boundaries and cell positions.
[0088] Table content extraction: Extract the content of each cell and organize them in order of rows and columns.
[0089] Markdown conversion: Convert the extracted table data into Markdown format, preserving the structure and style of the table.
[0090] Specifically, the extraction of text content from WORD refers to directly reading the text content in DOC and DOCX documents, retaining the format and paragraph structure of the text, and ensuring the integrity and readability of the content.
[0091] Specifically, the preprocessing of WORD refers to directly reading the table in the document and converting it into Markdown format.
[0092] S2022. Segment the preprocessed text to obtain multiple text blocks.
[0093] The segmentation rule is to segment the preprocessed text cyclically according to paragraphs and sentences until the preset text block length L, such as 200, is not exceeded, and the content of each text block is the segmented text. Furthermore, for the table content in the markdown format in the preprocessed text, it is treated as a separate text block and does not participate in segmentation. The table content is summarized using a large model with summary prompts, and the summary result is used as the content of the current text block, and the original table content is stored in the metadata of the text block.
[0094] Normal text block = Document(content=text block content, metadata={})
[0095] Table text block = Document(content=table summary content, metadata={"table":table content in markdown format})
[0096] S2023. Segment the content of the text block and store it in the full-text search engine The text block content is vectorized through the vector model and stored in the document vector library middle.
[0097] In this embodiment, the word segmentation engine is Jieba, and the vector model is the BGE model.
[0098] S30. Build a tool library based on the service set, including the registration and calling of data services.
[0099] The tool library is used to store user data service information.
[0100] The registration of data services is to standardize various data service information and register them in the tool library. Furthermore, the standardized service information includes but is not limited to the service name, service description, service category, service address, calling method, input parameter details, and output parameter details.
[0101] Specifically, the service category is the service field, such as finance, transportation, etc.; the service address is the URL address; the calling method is post, get, etc., the input parameter details are the parameter requirements that need to be passed in to call the service, which may include parameter name, parameter type, parameter description, whether it is required, parameter example, etc.; the output parameter details are parameter name and parameter description.
[0102] The call of data service is used to execute the specified service request. Furthermore, the call of data service also includes pre-call processing and post-call processing. Pre-call processing includes the verification of input parameters, the throwing of corresponding exception information, and the formatting of input parameters; post-call processing includes the verification of response data, the throwing of corresponding exception information, the parsing of response data, and the formatting of response data.
[0103] Specifically, input parameter verification may include parameter type verification, required parameter verification, parameter range verification, etc.; input parameter formatting may include date and time formatting, specified format conversion, etc.; response data verification may include checking the service response status code; response data parsing may include data field extraction and filtering, null value processing; response data formatting may include conversion of specified data formats.
[0104] S40, obtaining user questions Q and historical chat records H, using the intent model to identify the intent of the user's questions, and obtaining intent categories.
[0105] The historical chat record H is the most recent N rounds of chat records of the user's current session, including the user's previous questions and answers.
[0106] Intent recognition refers to using the model's semantic analysis capabilities to identify the intent of user input information and output it in a formatted manner.
[0107] The intent model is a large model with intent hints. Furthermore, the large model can be fine-tuned after collecting user questions and annotating intents.
[0108] Intent categories include general knowledge question and answer, domain knowledge question and answer, and domain data question and answer. The domain can be further subdivided into specific fields.
[0109] S50. According to different intent categories, use the big model to call different data sources to obtain the answer A to the user's question Q.
[0110] like Figure 2 As shown:
[0111] When the user intent category is general knowledge question and answer, the historical chat record H and user question Q are directly input into the large model to generate the answer A.
[0112] When the user intent category is not general knowledge question answering, based on the historical chat records H, the user question Q is optimized using a large model with question optimization prompts to obtain the optimized user question .
[0113] An example of a question optimization tip is as follows:
[0114] "You are a question optimization expert. Please complete and reconstruct the user's question based on the conversation history. If the question contains pronouns or missing conditions, please replace or complete them based on the context to make the question clearer; if the question is complete, please keep the original question.
[0115] Historical dialogue:
[0116] {H}
[0117] User Question:
[0118] {Q}
[0119] Problems after optimization:
[0120] { }”
[0121] When the user intent category includes domain knowledge questions and answers, data is called from the question and answer library and the document library. The specific steps are as follows:
[0122] S5011. Use vector model to solve optimized user questions Vectorize to get the user question vector .
[0123] S5012, respectively calculate the user question vector Vector Library with Questions and answer vector library Similarity of vectors in the weighted fusion as an optimization problem Similarity with the question-answer pairs in the question-answer database .
[0124]
[0125] in , is the problem vector Similarity with question vectors in the question vector library; , is the problem vector Similarity with the answer vector in the answer vector library; , 2 respectively correspond to the similarity , Similarity The weight of .
[0126] S5013, Get Maximum value The corresponding question-answer pair is taken as a candidate question-answer pair. When it is greater than the threshold t1, the answer in the candidate question-answer pair is directly used as the answer A.
[0127] In this embodiment, the value of t1 is 0.9.
[0128] S5014, when When it is less than the threshold t1, the user question vector is used To search from the document library, follow these steps:
[0129] S5014_1. Calculate user question vector With Document Vector Library Similarity of text block vectors in Chinese, get the top K text block sets in similarity ranking .
[0130] In this embodiment, the vector similarity adopts cosine similarity, and K is 20.
[0131] S5014_2, Use full-text search engine Calculate the keyword matching degree between the user question and the text block, and obtain the top K text blocks with the highest matching degree. .
[0132] In this embodiment, the matching degree is calculated as BM25, and K is 20.
[0133] S5014_3, Merge text block collection and , and remove duplicates to get a set of text blocks , using the rearrangement model to calculate user questions and Similarity of Chinese text blocks , get The set of text blocks greater than the threshold t2 .
[0134] Furthermore, if If there is table content in the metadata of the text block, the content of the text block is replaced with the table content in the metadata, otherwise it remains unchanged.
[0135] The reranking model in this embodiment is BGE-rerank, and t2 is 0.6. Only documents with scores higher than the threshold will be retained to answer user questions. This process can filter out low-relevance and useless documents to ensure the accuracy and reliability of the final answer.
[0136] When the user intent category includes domain data question and answer, call data from the tool library. The specific steps are as follows:
[0137] S5021. Use large models with tooltips to target user questions Perform analysis and output the service name and parameter information that need to be called.
[0138] For example, user issues This is the subway passenger flow from May 1st to 5th. The analysis results are as follows:
[0139] Service name: PassengerFlow
[0140] Service parameters:
[0141] {
[0142] "start_time": "2024-05-01",
[0143] "end_time": "2024-05-05"
[0144] }
[0145] S5022. The service name and parameter information to be called are passed into the tool library calling module to obtain the service calling result S.
[0146] Furthermore, when the calling module throws an exception, the exception information will be returned to the large model with tooltips for reanalysis until the calling module throws no exception or the maximum number of analysis rounds is reached. In this embodiment, the maximum number of analysis rounds is 5. If the maximum number of analysis rounds is reached and there is still an exception, the service call result S is the exception information.
[0147] Set the historical chat records H and text blocks , service call result S, user question Q are input into the large model with question and answer prompts to generate answer A.
[0148] S60: Return the generated answer A to the user, and save the question Q and the answer A into the historical chat record.
[0149] like Figure 3As shown, this embodiment also discloses a multi-level question-and-answer device 700, which includes a historical data acquisition unit 701, a library construction unit 702, a large model calling module 703, a question-and-answer execution module 704, and an answer generation module 705. The historical data acquisition unit 701 is used to obtain the user's historical question-and-answer set, document set, and service set. The library construction unit 702 is used to build a knowledge base based on the question-and-answer set and the document set, and to build a tool library based on the service set; the tool library is used for registering and calling data services. The large model calling module 703 is used to call the open source large model, collect the user's historical question-and-answer information from the question-and-answer set and mark its intent, and use the historical question-and-answer information marked with intent to fine-tune the open source large model to obtain an intent model. The question-and-answer execution module 704 is used to obtain the user's question Q and chat record H, use the intent model to identify the intent of the user's question Q, and obtain the intent category; according to different intent categories, use the intent model to call different data sources to obtain the answer A corresponding to the user's question Q. The answer generation module 705 is used to return the generated answer A to the user and save the user question Q and the answer A to the chat record. When the multi-level question-answering device 700 is running, it can execute the multi-level domain knowledge question-answering method based on the large model disclosed in the above embodiment, which will not be described in detail here.
[0150] In addition, it should be noted that the multi-level domain knowledge question-answering method based on a large model disclosed in the above embodiment can be written into a program product in the actual application process, and the program product is written into a storage medium and runs on an electronic device. More specific examples of the computer-readable storage medium mentioned in this embodiment 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. The computer-readable storage medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a readable program code is carried. This propagated data signal can take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. The readable signal medium can also be any readable medium other than a readable storage medium, which can send, propagate or transmit a program for use by an instruction execution system, an apparatus or a device or used in combination with it.
[0151] As described above, although the present invention has been shown and described with reference to specific preferred embodiments, it should not be construed as limiting the present invention itself. Various changes may be made to it in form and detail without departing from the spirit and scope of the present invention as defined in the appended claims.
Claims
1. A multi-level domain knowledge question answering method based on a large model, characterized in that: The steps include: Obtain the user's historical question and answer set, document set, and service set; the question and answer set records the user's question and answer information, the document set records the user's private domain document information, and the service set records the user's data service information; Building a knowledge base based on the question and answer set and the document set, wherein the knowledge base includes a question and answer base and a document base; Building a tool library based on the service set, the tool library is used for registration and calling of data services; Select an open source big model, collect historical question and answer information of users from the question and answer set and mark their intentions, and use the historical question and answer information marked with intentions to fine-tune the open source big model to obtain an intention model; The open source large model is one of Qwen, GLM, and LlaMa; The loss function of the intent model is as follows: ; ; In the formula, is the weight of intent category i, is the true intent category label, is the label probability distribution predicted by the model, S is the total number of samples, C is the number of intent categories, is a sample of intent category i; Obtain a user question Q and a chat record H, use the intention model to identify the intention of the user question Q, and obtain the intention category; The intent categories include general knowledge question and answer, domain knowledge question and answer, and domain data question and answer; according to different intent categories, the intent model is used to call different data sources to obtain the answer A corresponding to the user question Q; When the user intention category is general knowledge question and answer, the chat record H and the user question Q are directly input into the open source big model to generate the answer A; When the user intention category is not general knowledge question answering, based on the chat record H, the question optimization prompt is introduced to optimize the user question Q to obtain the optimized user question ; The generated answer A is returned to the user, and the user question Q and answer A are saved in the chat history.
2. The multi-level domain knowledge question answering method based on a large model according to claim 1 is characterized in that: The process of constructing the question-answer database includes: The question and answer set is vectorized through a vector model to obtain a question vector and an answer vector, and stored in a question vector library respectively. and answer vector library ; The vector model selects the open source BGE model; The construction process of the document library includes: Extract text content from various document formats, preprocess the text content, and obtain preprocessed text; Segment the preprocessed text to obtain multiple text blocks; The content of the text block is segmented and stored in the full-text search engine The text block content is vectorized through the vector model and stored in the document vector library middle.
3. The multi-level domain knowledge question answering method based on a large model according to claim 2 is characterized in that: The extracting of text content in various document formats and preprocessing of the text content specifically include: Detect and extract the table data part in the text, convert it into markdown format and restore it to the text; Remove extra spaces, line breaks, and special characters from text; The following rules are used to segment the preprocessed text: The preprocessed text is segmented cyclically according to paragraphs and sentences until the text block length L is not exceeded, and the content of each text block is the segmented text; For the table content in markdown format in the preprocessed text, it is treated as a separate text block and does not participate in segmentation. The open source big model is used to summarize the table content, and the summary result is used as the content of the current text block, and the original table content is stored in the metadata of the text block.
4. The multi-level domain knowledge question answering method based on a large model according to claim 1 is characterized in that: The tool library is used for registering and calling data services; wherein the registration of data services includes: Standardize various data service information and register them in the tool library; the standardized service information includes service name, service description, service category, service address, calling method, input parameter details, and output parameter details; The call of data service includes pre-call processing and post-call processing; the pre-call processing includes the verification of input parameters, the throwing of corresponding exception information and the formatting of input parameters; the post-call processing includes the verification of response data, the throwing of corresponding exception information, the parsing of response data and the formatting of response data.
5. The multi-level domain knowledge question answering method based on a large model according to claim 1 is characterized in that: When the user intent category includes domain knowledge questions and answers, data is called from the knowledge base, including: Use vector models to optimize user questions Vectorize to get the user question vector ; Calculate the user question vector separately Question vector library and answer vector library Similarity of vectors in the weighted fusion as an optimization problem Similarity with the question-answer pairs in the question-answer database : ; In the formula, , is the problem vector Similarity with question vectors in the question vector library; , is the problem vector Similarity with the answer vector in the answer vector library; , Corresponding to the similarity , Similarity The weight of; Get similarity Maximum value The corresponding question-answer pair is taken as a candidate question-answer pair. When it is greater than the threshold t1, the answer in the candidate question-answer pair is directly used as answer A; when When it is less than the threshold t1, the user question vector is used Searching from the document library includes: Calculate the user question vector With the document vector library Similarity of text block vectors in Chinese, get the top K text block sets with similarity ranking ; Use full-text search engines Computing User Problems The keyword matching degree with the text block, obtain the top K text blocks with the highest matching degree ; Merge a collection of text blocks and , and remove duplicates to get a set of text blocks , using the rearrangement model to calculate user questions and Similarity of Chinese text blocks , get The set of text blocks greater than the threshold t2 ; If the text block collection If there is table content in the metadata of the text block, the content of the text block is replaced with the table content in the metadata, otherwise it remains unchanged.
6. The multi-level domain knowledge question answering method based on a large model according to claim 1 is characterized in that: When the user intent category includes domain data question and answer, data is called from the tool library, including: Use the open source big model to target user problems Perform analysis and output the service name and parameter information that need to be called; The service name and parameter information to be called are passed into the tool library to obtain the service call result S; When the tool library throws an exception, the exception information is returned to the open source big model for re-analysis until the tool library throws no exception or the maximum number of analysis rounds is reached; The chat record H and text block collection , service call result S, user question Q are input into the open source big model to generate answer A.
7. A multi-level question-answering device, which can automatically execute the multi-level domain knowledge question-answering method based on a large model as described in any one of claims 1 to 6 when running; characterized in that: The multi-level question-answering device comprises: A historical data acquisition unit, used to acquire a user's historical question and answer set, document set, and service set; A library construction unit, used to construct a knowledge base based on the question and answer set and the document set, and to construct a tool library based on the service set; the tool library is used for registration and calling of data services; A large model calling module is used to call the open source large model, collect the user's historical question and answer information from the question and answer set and mark its intention, and use the historical question and answer information marked with intention to fine-tune the open source large model to obtain an intention model; The question-answering execution module is used to obtain the user question Q and the chat record H, use the intention model to identify the intention of the user question Q, and obtain the intention category; according to different intention categories, use the intention model to call different data sources to obtain the answer A corresponding to the user question Q; The answer generation module is used to return the generated answer A to the user and save the user question Q and the answer A into the chat record.
8. An electronic device, characterized in that: The device comprises: a processor and a memory storing computer program instructions; when the processor executes the computer program instructions, the multi-level domain knowledge question-answering method based on a large model as described in any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium, characterized in that: The storage medium stores at least one executable instruction, and when the executable instruction is executed on the electronic device, the electronic device executes the multi-level domain knowledge question-answering method based on a large model as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Multi-engine intelligent question answering system for multi-type knowledge base
CN115238101A
Information processing method and device based on large language model, storage medium and equipment
CN118093813A