Intelligent question-answering method, system, device and medium based on context information aggregation
By building a vector knowledge base and rewriting user problems using large language models, the problem of intelligent question-and-answer system ignoring context when dealing with continuous questions is solved, and more accurate and personalized question-and-answer services are achieved, reducing manual maintenance costs.
Patent Information
- Application Number
- CN202411273471.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2025-02-28
- Estimated Expiration
- 2044-09-12
AI Technical Summary
When handling user continuous questions, the existing intelligent question-and-answer system ignores the front and back context, resulting in the answers that are inconsistent with the user's intention or lack accuracy, and the traditional context information aggregation method lacks general utility and high manual maintenance costs.
By constructing a vector knowledge base, storing and managing users' historical dialogue records, calculating the similarity, distance weight, keyword overlap and semantic importance of user questions and answers in historical dialogue records, and rewriting and answering current user questions using a large language model.
It significantly improves the context understanding ability and answer accuracy of the Q&A system, provides users with a richer and considerate Q&A experience, reduces manual maintenance costs and improves the general use of the system.
Smart Images

Figure 00000000_0000_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of natural language processing, and in particular to an intelligent question-answering method, system, device and medium based on context information aggregation. Background Art
[0002] An Intelligent Question Answering System is a natural language processing system based on artificial intelligence technology that can automatically acquire, understand and process human language, and give corresponding answers based on the user's questions. It is not limited to simple query responses, but can also handle complex questions and provide detailed explanations and reasoning processes. Existing intelligent question answering systems usually rely on pre-trained large-scale corpora combined with deep learning algorithms to achieve deep understanding and reasoning of natural language. With the diversification of user needs and the increase in the complexity of questions, intelligent question answering systems face many challenges, such as: how to better understand the context, how to accurately match user intent, and how to provide personalized answers.
[0003] The context information aggregation method aims to utilize the historical information in the user dialogue to enhance the system's understanding and response capabilities to the current question. Traditional intelligent question-answering systems often only deal with isolated questions, ignoring the continuity of the dialogue, resulting in the mismatch between the answer and the actual needs of the user. The context information aggregation method generally obtains historical context information and then rewrites the current user question based on it. However, the traditional method of obtaining historical context usually uses a rule-based approach. For example, in the technical solution of the patent document with patent number CN113673256A, the context is obtained by "counting the number of reply information with preset semantic features in the dialogue information of the dialogue data set" and "counting the number of inquiry information and corresponding reply information in the dialogue information of the dialogue data set". In addition, the traditional method of rewriting the current question based on the historical context usually uses the method of first determining the missing part of the current question and then filling it in from the historical context. In the traditional context information aggregation method, whether it is the method of obtaining the historical context or the method of rewriting the current question based on the historical context information, both tend to be grammatical analysis, statistics and rules, lack of versatility, and high manual maintenance costs. Summary of the invention
[0004] The technical task of the present invention is to provide an intelligent question-answering method, system, device and medium based on context information aggregation to solve the problem that the existing intelligent question-answering system often ignores the previous and following contexts when processing continuous questions from users, resulting in answers that are inconsistent with user intentions or lack accuracy, as well as the lack of versatility in traditional context information aggregation methods and high manual maintenance costs.
[0005] The technical task of the present invention is achieved in the following way: an intelligent question-answering method based on context information aggregation, the method is specifically as follows:
[0006] Knowledge base construction: Collect domain knowledge data offline, preprocess the knowledge data, vectorize the preprocessed data, and store the vectorized data in the vector knowledge base;
[0007] User interaction: receiving questions input by users and displaying answers;
[0008] Context management: Store all historical conversation records of the user in the current conversation into the vector knowledge base, calculate the similarity, distance weight, keyword overlap and semantic importance between the user's questions and answers in the historical conversation records and the current user's questions; when the weighted similarity exceeds the preset threshold, the corresponding historical question or answer is considered to be related to the current question, and the question-answer pair is recorded;
[0009] Context information aggregation: Based on the relevant context passed in the context management process, prompt words are constructed using prompt engineering, and the current user question is rewritten with the help of a large language model;
[0010] Smart Q&A: Based on the relevant context and the current user question, determine whether the rewritten user question can be directly answered:
[0011] If the judgment result is yes, the large language model is called, and the historical dialogue and the current question are used as input to generate a direct answer;
[0012] If the judgment result is no, the rewritten user question is converted into a vector, and a vector search is performed from the vector knowledge base constructed offline to obtain relevant knowledge information. Then, the prompt word is constructed using the rewritten user question and the search results through the prompt project and input into the large language model to obtain the model answer.
[0013] As a preferred embodiment, the knowledge data is preprocessed as follows:
[0014] Data cleaning: remove garbled characters and meaningless hyperlinks, and perform deduplication processing on text data;
[0015] Chunking: Cut long text into pieces of fixed length (for example, 250 characters).
[0016] Preferably, the bge-m3 model is used for vectorization, and the bge-m3 model converts text into vector representation containing semantics; the vector knowledge base adopts the Milvus knowledge base, and the data storage format of the vectorized data is in the form of (embedding, text); wherein embedding is vector data; and text is the corresponding text data.
[0017] As a preferred method, all historical conversation records of the user in the current conversation are stored in the vector knowledge base as follows:
[0018] The questions raised by the user and the answers to the corresponding questions are vectorized respectively and stored in the vector library in the form of (embedding, question, answer) triples;
[0019] When storing user questions, embedding is the vector data of the corresponding question; question is the text data of the corresponding question; answer is the text data of the answer to the corresponding question;
[0020] When storing the answer to the corresponding question, embedding is the vector data of the corresponding answer; question is the question text data corresponding to the corresponding answer; answer is the text data of the corresponding answer.
[0021] Preferably, weighted similarity is the weighted sum of similarity, distance weight, words overlap and semantic importance. The calculation formula of weighted similarity is as follows:
[0022] ;
[0023] Among them, Ws represents weighted similarity; S represents similarity; Wd represents distance weight; Wo represents keyword overlap; Si represents semantic importance.
[0024] Preferably, the similarity refers to the vector similarity between the current user question text and the question or answer text in the historical conversation record; the vector similarity is calculated using cosine similarity, and the cosine similarity calculation formula is as follows:
[0025] ;
[0026] in, Represents the inner product of vector A and vector B, that is, the result of multiplying and adding corresponding elements; The modulus of vector A, that is, the length of vector A, is obtained by summing the squares of each element in vector A and taking the square root; The modulus of vector B, that is, the length of vector B, is obtained by summing the squares of each element in vector B and taking the square root;
[0027] Distance weight refers to the distance ratio between the current user question and the question-answer pairs in the historical conversation records. Specifically, the closer the distance between the current question and the question-answer pairs in the historical conversation records, the higher the distance ratio. Distance weight is expressed as a quantity inversely proportional to the distance. The formula is as follows:
[0028] ;
[0029] in, Indicates the distance between the current user question and the i-th question-answer pair in the historical conversation record; represents the distance weight associated with the i-th question-answer pair;
[0030] To ensure that the sum of all weights is 1 (i.e. normalized), define the normalized distance weight , The formula is as follows:
[0031] ;
[0032] Where n represents the total number of question-answer pairs in the historical conversation records.
[0033] Preferably, word overlap refers to the degree of character overlap between the current user's question text and the questions or answers in the historical conversation record; the word overlap formula Wo is as follows:
[0034] ;
[0035] in, Represents the question text of the current user; Represents a question text in the historical conversation record; Represents an answer text in the historical conversation record; Indicates the length of the overlapping characters between the current question text and the historical question text; Indicates the total length of the current question text and the historical question text in characters; Indicates the length of the overlapping characters between the current question text and the historical answer text; Indicates the total length of the current question text and the historical answer text in characters;
[0036] Semantic importance refers to the number of predefined keywords in the historical conversation records. The formula for semantic importance Si is as follows:
[0037] ;
[0038] in, Represents a question text in the historical conversation record; Represents any answer text in the historical conversation record; Represents a predefined set of keywords; Indicates the number of predefined keywords contained in the text X.
[0039] An intelligent question-answering system based on context information aggregation, the system is used to implement the intelligent question-answering method based on context information aggregation as described above; the system comprises:
[0040] The knowledge base construction module is used to collect knowledge data in the field offline, preprocess the knowledge data, vectorize the preprocessed data, and store the vectorized data in the vector knowledge base;
[0041] User interaction module, used to receive questions input by users and display answer results;
[0042] The context management module is used to store all historical conversation records of the user in the current conversation into the vector knowledge base, and calculate the similarity, distance weight, keyword overlap and semantic importance between the user's questions and answers in the historical conversation records and the current user's questions; when the weighted similarity exceeds the preset threshold, the corresponding historical question or answer is considered to be related to the current question, and the question-answer pair is recorded;
[0043] The context information aggregation module is used to construct prompt words based on the relevant context passed in the context management process using the prompt engineering, and rewrite the current user question with the help of the large language model;
[0044] The intelligent question-answering module is used to determine whether the rewritten user question can be directly answered based on the relevant context and the current user question:
[0045] If the judgment result is yes, the large language model is called, and the historical dialogue and the current question are used as input to generate a direct answer;
[0046] If the judgment result is no, the rewritten user question is converted into a vector, and a vector search is performed from the vector knowledge base constructed offline to obtain relevant knowledge information. Then, the prompt word is constructed using the rewritten user question and the search results through the prompt project and input into the large language model to obtain the model answer.
[0047] An electronic device comprising: a memory and at least one processor;
[0048] Wherein, the memory stores a computer program;
[0049] The at least one processor executes the computer program stored in the memory, so that the at least one processor performs the intelligent question-answering method based on context information aggregation as described above.
[0050] A computer-readable storage medium stores a computer program, which can be executed by a processor to implement the intelligent question-answering method based on context information aggregation as described above.
[0051] The intelligent question-answering method, system, device and medium based on context information aggregation of the present invention have the following advantages:
[0052] (i) The present invention significantly improves the context understanding ability and answer accuracy of the question-answering system, provides users with a richer and more intimate question-answering experience, and improves user experience and the accuracy of system answers;
[0053] (ii) The present invention realizes the storage of user historical conversations, the extraction of relevant contexts, the rewriting of user questions and intelligent answers through knowledge base construction, user interaction, context management, context information aggregation and intelligent question and answer, which can effectively improve the accuracy and response speed of the question and answer system and provide users with more accurate and personalized question and answer services;
[0054] (iii) The present invention utilizes multiple features including semantic vectors, distance weights, word overlap, and semantic importance to obtain relevant historical context. Compared with traditional methods for obtaining relevant context, the present invention utilizes deeper semantic relationships and has a higher accuracy rate;
[0055] (IV) In the context information aggregation method of the present invention, the large language model is used to integrate the relevant historical context information into the user's current question through prompt engineering. Compared with the traditional rewriting method, the present invention generates the rewritten question through the integration of the large language model. The rewritten question text is more natural and logical, which not only improves the accuracy of the question statement, but also optimizes the subsequent answer generation process, and innovatively solves the problem of insufficient context utilization in the traditional method.
[0056] (V) The present invention integrates multiple modules such as knowledge base construction, user interaction, context management, question rewriting, and question and answer generation, and can optimize the process of question understanding and answer generation in multiple steps to form a complete intelligent question and answer workflow. BRIEF DESCRIPTION OF THE DRAWINGS
[0057] The present invention is further described below in conjunction with the accompanying drawings.
[0058] Attached Figure 1 It is a structural diagram of an intelligent question-answering system based on context information aggregation;
[0059] Attached Figure 2 Schematic diagram of the process of building modules for the knowledge base. DETAILED DESCRIPTION
[0060] The intelligent question-answering method, system, device and medium based on context information aggregation of the present invention are described in detail below with reference to the accompanying drawings and specific embodiments of the specification.
[0061] Embodiment 1: This embodiment provides an intelligent question-answering method based on context information aggregation, and the method is specifically as follows:
[0062] S1. Knowledge base construction: collect domain knowledge data offline, preprocess the knowledge data, vectorize the preprocessed data, and store the vectorized data in the vector knowledge base;
[0063] S2, user interaction: receiving questions input by users and displaying answers;
[0064] S3, context management: store all historical conversation records of the user in the current conversation into the vector knowledge base, calculate the similarity, distance weight, keyword overlap and semantic importance between the user's questions and answers in the historical conversation records and the current user's questions; when the weighted similarity exceeds the preset threshold, the corresponding historical question or answer is considered to be related to the current question, and the question-answer pair is recorded;
[0065] S4. Context information aggregation: Based on the relevant context passed in the context management process, the prompt project is used to build prompt words, and the current user question is rewritten with the help of a large language model; for example: the relevant context is "question: Help me come up with a name, answer: Zhang San, question: Not fancy enough", and the rewritten user question is "Please help me come up with a fancy name."
[0066] The reference build prompts are as follows:
[0067] Role Definition:
[0068] - **Role**: You are an information integration assistant.
[0069] - **Responsibilities**: Your responsibility is to reframe the user's question so that it can be understood without relying on previous chat records, while ensuring that the original meaning of the question remains unchanged.
[0070] Mission Statement:
[0071] - **Task**: Given a chat log and the user's latest question, you need to rephrase the question. If the question itself is clear and does not need to be rephrased, return it as is. Please do not answer the question.
[0072] Operating Instructions:
[0073] 1. Read and understand the given chat log and the user’s latest question.
[0074] 2. Identify the context and key content in users’ latest questions.
[0075] 3. Re-phrase the question so that it can be understood accurately without being taken off the chat record.
[0076] 4. Make sure that the reframed question retains the original meaning and does not introduce new information or change the original meaning.
[0077] 5. If the question itself is clear and does not need to be rephrased, please only output the original question.
[0078] 6. If the question itself is incomprehensible and it is impossible to form a reconstructed question, please output "incomprehensible".
[0079] Output format:
[0080] Example:
[0081] **Example 1**:
[0082] - **Chat history**:
[0083] user: What will the weather be like tomorrow?
[0084] assistant: It will be cloudy with light rain tomorrow.
[0085] - **Query**: Do I need to bring an umbrella?
[0086] - **Output**: Do I need to bring an umbrella tomorrow?
[0087] **Example 2**:
[0088] - Chat history:
[0089] user: Do you know some of the latest research on quantum computing?
[0090] assistant: The basic principle of quantum computing is to use quantum mechanical phenomena, such as superposition and entanglement, to perform calculations.
[0091] - **Query**: What is its impact on cryptography?
[0092] - **Output**: What is the impact of quantum computing on cryptography?
[0093] **Example 3**:
[0094] - Chat history:
[0095] user: Please give me some tips on saving water
[0096] assistant: The following are some tips for saving water in daily life, which can help you develop good habits of saving water and establish a new green trend: turn off the faucet, use the washing machine reasonably, etc.
[0097] - **Query**: Please simulate 50mm rainfall in 3 hours in the selected range.
[0098] - **Output**: Please simulate 50mm rainfall in the selected area for 3 hours.
[0099] **Example 4**:
[0100] - Chat history:
[0101] user: what day of the week is today
[0102] assistant: Today is Tuesday. If you have any questions about water conservancy, please feel free to ask.
[0103] - **Query**: Today is August 6 and
[0104] - **Output**: Unable to understand
[0105] Notice:
[0106] - Please do not answer the question.
[0107] - Return only the refactored questions, no extra output.
[0108] Actual tasks:
[0109] - Chat history:
[0110] %s
[0111] - **Query**: %s
[0112] - **Output**: ```.
[0113] S5. Intelligent Question and Answer: Based on the relevant context and the current user question, determine whether the rewritten user question can be directly answered:
[0114] If the result is yes, the large language model is called, and the historical dialogue and the current question are used as input to generate a direct answer. The reference constructed prompt words are as follows:
[0115] Role Definition:
[0116] - **Role**: You are a professional big model assistant, responsible for accurately judging and responding to user queries based on context and current time information.
[0117] Mission Statement:
[0118] - **Task**: Analyze the user query and combine the context information to decide whether a direct answer can be given. If the query content is not mentioned in the context or there is insufficient information, "No" should be output.
[0119] Judgment criteria:
[0120] - **Judge**: Based on the context `context`, evaluate whether the user's query can be accurately answered. If the context provides enough information to directly answer the query, output "Yes"; if the context does not mention the query content or the information is insufficient, output "No". The current time `current_datestr` is only used for time-related queries.
[0121] Output format:
[0122] - **Output**: For queries that can be answered directly, output "Yes"; for queries that cannot be answered directly, output "No".
[0123] **Example 1**:
[0124] - **Content**:
[0125] - user: What are the design standards for water conservancy projects?
[0126] - assistant: The design standards for water conservancy projects generally include hydrological standards, structural standards, environmental standards, operational standards and other aspects.
[0127] - **Query**: Are hydrological standards included in the design standards for water conservancy projects?
[0128] - Current time: 2024-07-13 8:10:06
[0129] - **Output**:Yes
[0130] **Example 2**:
[0131] - **Content**:
[0132] - user: network security related issues.
[0133] - assistant: The user asks if you are a professional cybersecurity assistant and is ready to ask cybersecurity-related questions.
[0134] - **Query**: How to configure network security?
[0135] - Current time: 2024-04-26 21:42:14
[0136] - **Output**: No
[0137] **Example 3**:
[0138] - **Content**:
[0139] - user:Hello.
[0140] - assistant: Hello! I am Shangshan Water Conservancy Model, a professional assistant focusing on the field of water conservancy. If you have any questions about water conservancy, such as water level and flow query, water conservancy construction market supervision, weather query, rainfall forecast, etc., you can ask me. Please tell me what help you need.
[0141] - **Query**: What time is it now?
[0142] - Current time: 2024-08-06 10:00:26
[0143] - **Output**:Yes
[0144] Actual tasks:
[0145] - **Context**:
[0146] {context}
[0147] - **Query**: {query}
[0148] - Current time: {current_datestr}
[0149] - **Output**: ```.
[0150] If the judgment result is no, the rewritten user question is converted into a vector, and a vector search is performed from the vector knowledge base constructed offline to obtain relevant knowledge information. Then, the prompt word is constructed using the rewritten user question and the search results through the prompt project and input into the large language model to obtain the model answer.
[0151] The reference build prompts are as follows:
[0152] Please answer the user's questions based on the relevant information given:
[0153] Related information:
[0154] {related_infomation}
[0155] User question: {query}
[0156] Answer: ```.
[0157] The preprocessing of knowledge data in step S1 of this embodiment is specifically as follows:
[0158] S101, data cleaning: remove garbled characters and meaningless hyperlinks, and perform deduplication processing on text data;
[0159] S102, cutting into pieces: cutting the long text into pieces according to a fixed length (for example, 250 characters).
[0160] The vectorization in step S1 of this embodiment adopts the bge-m3 model, which converts text into vector representation containing semantics; the vector knowledge base adopts the Milvus knowledge base, and the data storage format of the vectorized data is in the form of (embedding, text); wherein embedding is vector data; and text is the corresponding text data.
[0161] In this embodiment, step S3 of storing all historical conversation records of the user in the current conversation into the vector knowledge base is specifically as follows:
[0162] The questions raised by the user and the answers to the corresponding questions are vectorized respectively and stored in the vector library in the form of (embedding, question, answer) triples;
[0163] When storing user questions, embedding is the vector data of the corresponding question; question is the text data of the corresponding question; answer is the text data of the answer to the corresponding question;
[0164] When storing the answer to the corresponding question, embedding is the vector data of the corresponding answer; question is the question text data corresponding to the corresponding answer; answer is the text data of the corresponding answer.
[0165] The weighted similarity in this embodiment is the result of weighted summation of similarity, distance weight, word overlap, and semantic importance. The calculation formula of the weighted similarity is as follows:
[0166] ;
[0167] Among them, Ws represents weighted similarity; S represents similarity; Wd represents distance weight; Wo represents keyword overlap; Si represents semantic importance.
[0168] The similarity in this embodiment refers to the vector similarity between the current user question text and the question or answer text in the historical conversation record; the vector similarity is calculated using cosine similarity, and the cosine similarity calculation formula is as follows:
[0169] ;
[0170] in, Represents the inner product of vector A and vector B, that is, the result of multiplying and adding corresponding elements; The modulus of vector A, that is, the length of vector A, is obtained by summing the squares of each element in vector A and taking the square root; The modulus of vector B, that is, the length of vector B, is obtained by summing the squares of each element in vector B and taking the square root;
[0171] Distance weight refers to the distance ratio between the current user question and the question-answer pairs in the historical conversation records. Specifically, the closer the distance between the current question and the question-answer pairs in the historical conversation records, the higher the distance ratio. Distance weight is expressed as a quantity inversely proportional to the distance. The formula is as follows:
[0172] ;
[0173] in, Indicates the distance between the current user question and the i-th question-answer pair in the historical conversation record; represents the distance weight associated with the i-th question-answer pair;
[0174] To ensure that the sum of all weights is 1 (i.e. normalized), define the normalized distance weight , The formula is as follows:
[0175] ;
[0176] Where n represents the total number of question-answer pairs in the historical conversation records.
[0177] The word overlap in this embodiment refers to the degree of character overlap between the current user question text and the questions or answers in the historical conversation record; the word overlap formula Wo is as follows:
[0178] ;
[0179] in, Represents the question text of the current user; Represents a question text in the historical conversation record; Represents an answer text in the historical conversation record; Indicates the length of the overlapping characters between the current question text and the historical question text; Indicates the total length of the current question text and the historical question text in characters; Indicates the length of the overlapping characters between the current question text and the historical answer text; Indicates the total length in characters of the current question text and the historical answer text.
[0180] The semantic importance in this embodiment refers to the number of predefined keywords in the historical conversation records. The formula of semantic importance Si is as follows:
[0181] ;
[0182] in, Represents a question text in the historical conversation record; Represents any answer text in the historical conversation record; Represents a predefined set of keywords; Indicates the number of predefined keywords contained in the text X.
[0183] Embodiment 2: This embodiment provides an intelligent question-answering system based on context information aggregation, which is used to implement the intelligent question-answering method based on context information aggregation in Embodiment 1; the system includes:
[0184] The knowledge base construction module is used to collect knowledge data in the field offline, preprocess the knowledge data, vectorize the preprocessed data, and store the vectorized data in the vector knowledge base;
[0185] User interaction module, used to receive questions input by users and display answer results;
[0186] The context management module is used to store all historical conversation records of the user in the current conversation into the vector knowledge base, and calculate the similarity, distance weight, keyword overlap and semantic importance between the user's questions and answers in the historical conversation records and the current user's questions; when the weighted similarity exceeds the preset threshold, the corresponding historical question or answer is considered to be related to the current question, and the question-answer pair is recorded;
[0187] The context information aggregation module is used to construct prompt words based on the relevant context passed in the context management process using the prompt engineering, and rewrite the current user question with the help of the large language model;
[0188] The intelligent question-answering module is used to determine whether the rewritten user question can be directly answered based on the relevant context and the current user question:
[0189] If the judgment result is yes, the large language model is called, and the historical dialogue and the current question are used as input to generate a direct answer;
[0190] If the judgment result is no, the rewritten user question is converted into a vector, and a vector search is performed from the vector knowledge base constructed offline to obtain relevant knowledge information. Then, the prompt word is constructed using the rewritten user question and the search results through the prompt project and input into the large language model to obtain the model answer.
[0191] As attached Figure 2 As shown in the figure, the working process of the knowledge base construction module is as follows:
[0192] ① Collect domain knowledge data offline;
[0193] ② Clean and cut the knowledge data into text blocks;
[0194] ③Use the vectorization model to convert the text block into a vector;
[0195] ④Stored in the vector knowledge base in the form of (vector, text block).
[0196] Example 3: The following is an example of an example using a medical intelligent question-answering assistant, including background and implementation steps:
[0197] background:
[0198] In modern medical consultations, patients usually ask multiple related questions involving diagnosis, treatment plans, drug use, and other aspects. However, when dealing with multiple rounds of continuous conversations, traditional intelligent question-and-answer systems often find it difficult to fully utilize previous conversation information, resulting in inaccurate answers. To solve this problem, this embodiment proposes a medical intelligent question-and-answer assistant based on context information aggregation, which uses context management and vectorization models to improve the system's question-and-answer effect and help patients obtain more accurate medical advice.
[0199] Implementation steps:
[0200] (1) Knowledge base construction: First, a large amount of knowledge data in the medical field is collected offline, including pathology, pharmacology, and treatment plans for common diseases. Then, this data is preprocessed, including data cleaning and slicing operations, and then the processed data is vectorized. Finally, the vectorized knowledge is stored in the medical knowledge base as the basis for subsequent intelligent question and answer.
[0201] (2) User interaction: When a patient uses the medical intelligent question-and-answer assistant, the system receives questions input by the patient through the user interaction module. For example, the patient may ask: "I have a slight cough and sore throat, what should I do?" The system records the patient's question and prepares to proceed to the next step of the processing process.
[0202] (3) Context management: All conversation records of the patient are stored in the context management module. Each question and system answer are vectorized to form a triple of (embedding, question, answer) and stored in the vector library. When the patient continues to ask questions, such as "I still feel a little feverish. Could this be a precursor to pneumonia?" The system calculates the similarity between the current question and the historical conversation records, keyword overlap, semantic importance, etc., and extracts the context content related to the current question.
[0203] (4) Contextual information aggregation: Based on the relevant contextual information provided by the context management module, the patient’s current question is rewritten through prompt engineering technology. For example, if the relevant context is “cough, sore throat”, the system may rewrite the current question to “cough, sore throat and fever, will this cause pneumonia?”
[0204] (5) Intelligent question and answer, as follows:
[0205] 1) Direct answer: First, determine whether the patient's question can be answered directly based on the current context information. If the system believes that it can give a direct answer, it calls the large language model to generate an answer, such as "Based on the symptoms you described, a mild cough, sore throat, and fever may be related to the common cold. It is recommended that you get more rest, drink more water, and use cold medicine if necessary."
[0206] 2) Retrieval generation: If a direct answer is not possible, the rewritten question will be converted into a vector, and the vector will be retrieved from the knowledge base to obtain relevant medical knowledge. Then, the system combines the retrieved knowledge and the rewritten question to generate prompt words, and calls the large language model again to generate more detailed answers, such as "Symptoms of cough, sore throat and fever may be related to viral infections, such as influenza. It is recommended that you isolate yourself at home and observe the symptoms. If the condition worsens, please seek medical attention in time."
[0207] (6) User interaction: The generated answers are fed back to the patient through the user interaction module, completing a complete question-and-answer process.
[0208] Embodiment 4: This embodiment also provides an electronic device, including: a memory and a processor;
[0209] Wherein, the memory stores computer-executable instructions;
[0210] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the intelligent question-answering method based on context information aggregation in any embodiment of the present invention.
[0211] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor may be a microprocessor or any conventional processor, etc.
[0212] The memory can be used to store computer programs and / or modules. The processor realizes various functions of the electronic device by running or executing the computer programs and / or modules stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application required for a function, etc.; the data storage area can store data created according to the use of the terminal, etc. In addition, the memory can also include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (SMC), a secure digital (SD) card, a flash memory card, at least one disk storage period, a flash memory device, or other volatile solid-state storage devices.
[0213] Embodiment 5: This embodiment also provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions are loaded by a processor, so that the processor executes the intelligent question-answering method based on context information aggregation in any embodiment of the present invention. Specifically, a system or device equipped with a storage medium can be provided, on which a software program code for implementing the functions of any of the above embodiments is stored, and a computer (or CPU or MPU) of the system or device reads out and executes the program code stored in the storage medium.
[0214] In this case, the program code itself read from the storage medium can realize the function of any one of the above-mentioned embodiments, and thus the program code and the storage medium storing the program code constitute a part of the present invention.
[0215] Examples of storage media for providing program code include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RYM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, program code may be downloaded from a server computer via a communication network.
[0216] In addition, it should be clear that the functions of any of the above embodiments can be implemented not only by executing the program code read by the computer, but also by enabling an operating system operating on the computer to complete part or all of the actual operations based on instructions from the program code.
[0217] In addition, it can be understood that the program code read from the storage medium is written to a memory provided in an expansion board inserted into the computer or written to a memory provided in an expansion unit connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or the expansion unit is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above-mentioned embodiments.
[0218] 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 replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. An intelligent question-answering method based on context information aggregation, characterized in that: The method is as follows: Knowledge base construction: Collect knowledge data in the field offline, preprocess the knowledge data, vectorize the preprocessed data, and store the vectorized data in the vector knowledge base; User interaction: receiving questions input by users and displaying answers; Context management: Store all historical conversation records of the user in the current conversation into the vector knowledge base, calculate the similarity, distance weight, keyword overlap and semantic importance between the user's questions and answers in the historical conversation records and the current user's questions; when the weighted similarity exceeds the preset threshold, the corresponding historical question or answer is considered to be related to the current question, and the question-answer pair is recorded; Context information aggregation: Based on the relevant context passed in the context management process, prompt words are constructed using prompt engineering, and the current user question is rewritten with the help of a large language model; Smart Q&A: Based on the relevant context and the current user question, determine whether the rewritten user question can be directly answered: If the judgment result is yes, the large language model is called, and the historical dialogue and the current question are used as input to generate a direct answer; If the judgment result is no, the rewritten user question is converted into a vector, and the vector is searched from the vector knowledge base built offline to obtain relevant knowledge information. Then, the prompt word is constructed by using the rewritten user question and the search result through the prompt engineering and input into the large language model to obtain the model answer; Among them, weighted similarity is the result of weighted summation of similarity, distance weight, keyword overlap and semantic importance; the calculation formula of weighted similarity is as follows: ; Among them, Ws represents weighted similarity; S represents similarity; Wd represents distance weight; Wo represents keyword overlap; Si represents semantic importance; Semantic importance refers to the number of predefined keywords in the historical conversation records. The formula for semantic importance Si is as follows: ; in, Represents any question text in the historical conversation record; Represents any answer text in the historical conversation record; Represents a predefined set of keywords; Indicates the number of predefined keywords contained in the text X.
2. The intelligent question-answering method based on context information aggregation according to claim 1 is characterized in that: The preprocessing of knowledge data is as follows: Data cleaning: remove garbled characters and meaningless hyperlinks, and perform deduplication on text data; Cut into pieces: Cut long text into pieces of fixed length.
3. The intelligent question-answering method based on context information aggregation according to claim 1 is characterized in that: The bge-m3 model is used for vectorization, which converts text into vector representations containing semantics. The vector knowledge base uses the Milvus knowledge base, and the data storage format of vectorized data is in the form of (embedding, text). Among them, embedding is vector data; text is the corresponding text data.
4. The intelligent question-answering method based on context information aggregation according to claim 1 is characterized in that: Storing all historical conversation records of the user in the current conversation into the vector knowledge base is as follows: The questions raised by the user and the answers to the corresponding questions are vectorized respectively and stored in the vector library in the form of (embedding, question, answer) triples; When storing user questions, embedding is the vector data of the corresponding question; question is the text data of the corresponding question; answer is the text data of the answer to the corresponding question; When storing the answer to the corresponding question, embedding is the vector data of the corresponding answer; question is the question text data corresponding to the corresponding answer; answer is the text data of the corresponding answer.
5. The intelligent question-answering method based on context information aggregation according to claim 1 is characterized in that: Similarity refers to the vector similarity between the current user's question text and the question or answer text in the historical conversation record; vector similarity is calculated using cosine similarity, and the cosine similarity calculation formula is as follows: ; in, Represents the inner product of vector A and vector B, that is, the result of multiplying and adding corresponding elements; The modulus of vector A, that is, the length of vector A, is obtained by summing the squares of each element in vector A and taking the square root; The modulus of vector B, that is, the length of vector B, is obtained by summing the squares of each element in vector B and taking the square root; Distance weight refers to the distance ratio between the current user question and the question-answer pairs in the historical conversation records. Specifically, the closer the distance between the current question and the question-answer pairs in the historical conversation records, the higher the distance ratio. Distance weight is expressed as a quantity inversely proportional to the distance. The formula is as follows: ; in, Indicates the distance between the current user question and the i-th question-answer pair in the historical conversation record; represents the distance weight associated with the i-th question-answer pair; Define normalized distance weights , The formula is as follows: ; Where n represents the total number of question-answer pairs in the historical conversation records.
6. The intelligent question-answering method based on context information aggregation according to claim 1, characterized in that: Word overlap refers to the degree of character overlap between the current user's question text and the questions or answers in the historical conversation records; the word overlap formula Wo is as follows: ; in, Represents the question text of the current user; Represents any question text in the historical conversation record; Represents any answer text in the historical conversation record; Indicates the length of the overlapping characters between the current question text and the historical question text; Indicates the total length of the current question text and the historical question text in characters; Indicates the length of the overlapping characters between the current question text and the historical answer text; Indicates the total length in characters of the current question text and the historical answer text.
7. An intelligent question-answering system based on context information aggregation, characterized in that: The system is used to implement the intelligent question-answering method based on context information aggregation as described in any one of claims 1 to 6; The system includes: The knowledge base construction module is used to collect knowledge data in the field offline, preprocess the knowledge data, vectorize the preprocessed data, and store the vectorized data in the vector knowledge base; User interaction module, used to receive questions input by users and display answer results; The context management module is used to store all historical conversation records of the user in the current conversation into the vector knowledge base, and calculate the similarity, distance weight, keyword overlap and semantic importance between the user's questions and answers in the historical conversation records and the current user's questions; when the weighted similarity exceeds the preset threshold, the corresponding historical question or answer is considered to be related to the current question, and the question-answer pair is recorded; The context information aggregation module is used to construct prompt words based on the relevant context passed in the context management process using the prompt engineering, and rewrite the current user question with the help of the large language model; The intelligent question-answering module is used to determine whether the rewritten user question can be directly answered based on the relevant context and the current user question: If the judgment result is yes, the large language model is called, and the historical dialogue and the current question are used as input to generate a direct answer; If the judgment result is no, the rewritten user question is converted into a vector, and the vector is searched from the vector knowledge base built offline to obtain relevant knowledge information. Then, the prompt word is constructed by using the rewritten user question and the search result through the prompt engineering and input into the large language model to obtain the model answer; Among them, weighted similarity is the result of weighted summation of similarity, distance weight, keyword overlap and semantic importance; the calculation formula of weighted similarity is as follows: ; Among them, Ws represents weighted similarity; S represents similarity; Wd represents distance weight; Wo represents keyword overlap; Si represents semantic importance; Semantic importance refers to the number of predefined keywords in the historical conversation records. The formula for semantic importance Si is as follows: ; in, Represents any question text in the historical conversation record; Represents any answer text in the historical conversation record; Represents a predefined set of keywords; Indicates the number of predefined keywords contained in the text X.
8. An electronic device, characterized in that: include: memory and at least one processor; Wherein, the memory stores a computer program; The at least one processor executes the computer program stored in the memory, so that the at least one processor executes the intelligent question-answering method based on context information aggregation as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which can be executed by a processor to implement the intelligent question-answering method based on context information aggregation as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Inquiry statement rewriting method and device
CN113673256A
Large model question and answer method and system based on historical dialogue record optimization and storage medium
CN118070908A
Intelligent customer service question and answer method based on large language model technology
CN118364084A