Multi-label generation matching RAG intelligent question-answering method, device and equipment and medium
By constructing a vector database of document text label data and combining it with large language model analysis, the problem that intelligent question-and-answer system is difficult to accurately understand user intentions in specific scenarios is solved, and more accurate and fine-grained search results are achieved, expanding the application scope of the system.
Patent Information
- Application Number
- CN202510240231.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-03
- Publication Date
- 2025-04-01
- Estimated Expiration
- 2045-03-03
AI Technical Summary
The existing intelligent question-and-answer system is difficult to accurately understand user intentions in specific application scenarios, resulting in the generated answers being inaccurate or relevant enough, limiting the application scope and effect of the system.
By building a vector database of document text label data, we can quickly find information related to user needs and analyze and summarize using a large language model to return answers to user questions. At the same time, data sources and data labels are customized according to business scenarios, and vector search functions are combined to improve the fine-grainedness and accuracy of search results.
It significantly improves the fine-grainedness and accuracy of the search results of the intelligent question-and-answer system, can understand user intentions more accurately and generate relevant answers, expanding the application scope and effect of the system.
Smart Images

Figure CN119739838A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a RAG intelligent question-answering method, device, equipment and medium for multi-label generation and matching. Background Art
[0002] Intelligent question-answering recognizes the intent in the user's input text, performs efficient retrieval in the vector library built from large-scale data sets, and uses a large language model to comprehensively analyze and summarize user queries and retrieval results, ultimately generating answers that conform to natural language habits. The existing question-answering process includes source data acquisition, data parsing and segmentation, vectorization processing, vector library construction, user query vectorization, vector search, result processing and ranking, and answer generation and output.
[0003] However, because the accuracy and relevance of vector retrieval are often limited by the quality and quantity of training data, and it is difficult to flexibly adjust or customize, traditional question-answering solutions mainly rely on vector retrieval technology, which makes it impossible to accurately understand user intentions in specific application scenarios, resulting in the generated answers being not accurate or relevant enough, which in turn limits the application scope and effectiveness of existing intelligent question-answering systems. Summary of the invention
[0004] The present invention provides a RAG intelligent question-answering method, device, equipment and medium for multi-label generation and matching. By constructing a vector database of document text label data, information related to user needs can be quickly found, and a large language model is used for analysis and summary, so as to return answers to user questions. By customizing data sources and data labels according to business scenarios and combining vector retrieval functions, the granularity and accuracy of retrieval results can be improved.
[0005] According to one aspect of the present invention, a RAG intelligent question answering method for generating and matching multiple labels is provided, which includes:
[0006] Acquire original text data corresponding to the target business scenario, and perform vectorization processing on the original text data to determine a text data set to be processed;
[0007] Determine a text tag set corresponding to the text data set to be processed, and establish a text vector database based on the text tag set and the text data set to be processed;
[0008] When receiving a question to be processed, determining a question text label and a question text vector corresponding to the question to be processed;
[0009] Determine the text to be applied from the text vector database based on the question text to be processed, the question text label and the question text vector;
[0010] An answer to a target question corresponding to the question to be processed is generated according to the text to be applied and a preset prompt word template.
[0011] According to another aspect of the present invention, a RAG intelligent question-answering device for generating and matching multiple labels is provided, comprising:
[0012] A text data processing module is used to obtain original text data corresponding to the target business scenario, and perform vectorization processing on the original text data to determine a text data set to be processed;
[0013] A vector database establishment module, used for determining a text tag set corresponding to the text data set to be processed, and establishing a text vector database based on the text tag set and the text data set to be processed;
[0014] A question text processing module, configured to determine a question text label and a question text vector corresponding to the question to be processed when receiving the question to be processed;
[0015] A module for determining text to be applied, used for determining text to be applied from the text vector database based on the question text to be processed, the question text label and the question text vector;
[0016] The question answer generation module is used to generate a target question answer corresponding to the question to be processed according to the text to be applied and a preset prompt word template.
[0017] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0018] at least one processor; and
[0019] a memory communicatively connected to the at least one processor; wherein,
[0020] The memory stores a computer program that can be executed by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the RAG intelligent question-answering method for multi-label generation and matching described in any embodiment of the present invention.
[0021] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the RAG intelligent question-answering method for multi-label generation and matching described in any embodiment of the present invention when executed.
[0022] The technical solution of the embodiment of the present invention obtains the original text data corresponding to the target business scenario, and vectorizes the original text data to determine the text data set to be processed, and determines the text tag set corresponding to the text data set to be processed. Based on the text tag set and the text data set to be processed, a text vector database is established, and then when a problem to be processed is received, the problem text tag and the problem text vector corresponding to the problem to be processed are determined. Based on the problem text to be processed, the problem text tag and the problem text vector, the text to be applied is retrieved from the text vector database, and the target question answer corresponding to the problem to be processed is generated according to the text to be applied and a preset prompt word template. Based on the above technical solution, by constructing a vector library of document text tag data, information related to user needs can be quickly found, and a large language model is used for analysis and summary, so as to return the answer to the user's question. In addition, by customizing the data source and data tag according to the business scenario, and combining the vector retrieval function, the granularity and accuracy of the retrieval results are improved.
[0023] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0025] Figure 1 It is a flowchart of a RAG intelligent question-answering method for generating and matching multiple labels according to an embodiment of the present invention;
[0026] Figure 2 is a flowchart of determining a text tag set of text data provided according to an embodiment of the present invention;
[0027] Figure 3 is a flowchart of a RAG intelligent question-answering method for generating and matching multiple labels according to an embodiment of the present invention;
[0028] Figure 4 It is a flowchart of a RAG intelligent question-answering method for generating and matching multiple labels according to an embodiment of the present invention;
[0029] Figure 5 It is a structural schematic diagram of a RAG intelligent question-answering device for generating and matching multiple labels according to an embodiment of the present invention;
[0030] Figure 6 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0031] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0032] It should be noted that in the specification and claims of the present invention and the above-mentioned drawings, the terms "first", "second", etc. are only used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0033] Embodiment 1
[0034] Figure 1 A flowchart of a multi-label generation and matching RAG intelligent question-answering method provided in an embodiment of the present invention. This embodiment is suitable for constructing a vector library of document text tag data, quickly finding information related to user needs, and using a large language model for analysis and summary, thereby returning answers to user questions. The method can be executed by a multi-label generation and matching RAG intelligent question-answering device, which can be implemented in the form of hardware and / or software, and can be configured in an electronic device. Figure 1 As shown, the method includes:
[0035] S110 , obtaining original text data corresponding to a target business scenario, and performing vectorization processing on the original text data to determine a text data set to be processed.
[0036] Among them, the target business scenario can be understood as a business scenario associated with user needs. The user can determine the business scenario for which a text vector database needs to be constructed according to the needs, such as a financial question and answer assistant, a company regulations assistant and other business scenarios. The original text data can be unprocessed text data, such as a company reimbursement system document, a company recruitment system document, etc. The text data set to be processed can be understood as a data set consisting of text vectors of multiple text blocks obtained after processing the original text data. It should be noted that the retrieval-augmented generation (RAG) is a retrieval-augmented generation model that combines language models and information retrieval technology. That is, when the model needs to generate text or answer questions, it will first retrieve relevant information from the document collection, and then use the retrieved information to guide the generation of text, thereby improving the quality and accuracy of the prediction. The technical solution of the present invention improves the accuracy of retrieval by combining RAG technology.
[0037] Specifically, according to the usage scenarios and user needs, relevant business data and label data are collected and integrated in a targeted manner. According to different usage scenarios, the question and answer data files and classification labels required in the current scenario (such as business trip reimbursement, invoice management, etc.) are collected, and specific label information (such as user permissions, access levels, etc.) can also be collected according to user needs. It should be noted that the original text data can include different data types, including but not limited to structured data and unstructured data. The file format may involve TXT, Doc, Docx and other types, and then the extracted original text data is vectorized to obtain the text data set to be processed corresponding to the original text data.
[0038] On the basis of the above technical solution, the vectorization processing of the original text data to determine the text data set to be processed includes: determining the text format corresponding to the original text data, and extracting text content from the original text data according to the text format; segmenting the text content according to the segmentation identifier, determining each text block corresponding to the text content, and assigning a text block identifier to each text block; determining the text data set to be processed based on the each text block and the text block identifier assigned to each text block.
[0039] Among them, the text format can be the file format of the original text data, which can include DOCX, PDF, XLSX and other formats. The text content can be understood as the text information in the original text data. The segmentation identifier can be a pre-set identifier for segmenting the text, and can be a segmentation identifier using a variety of text symbols, such as punctuation marks such as periods and question marks. The text block can be a text fragment that is marked as a whole for processing. The text block identifier can be understood as an identifier for uniquely identifying a text block, for example, it can be a digital ID.
[0040] Specifically, after the collected data is subjected to text parsing, text segmentation, vectorization, and label extraction and annotation, the text blocks, semantic vectors, and label sets are stored in the vector database for subsequent multi-way recall based on user questions, as knowledge input when the large language model generates answers. For example, the format of the text material is first identified, and different tools are used to identify and extract the text content according to different formats. For example, for PDF documents, PDFMiner or PyPDF2 libraries can be used for text extraction; and for Word documents, the python-docx library can be used to complete content reading. It is also necessary to process the text information in the images and tables that may exist in the document, and then use a variety of text symbols (such as punctuation marks such as periods and question marks) as segmentation marks, and subdivide the text content into smaller text blocks through recursive loops and dynamic block strategies until the preset block requirements are met. It should be noted that each segmented text block will be assigned a unique identifier (ID) for subsequent processing and tracing. The final structured data is in the form of [{"id":id_1,"data":textblock_1},{"id":id_2,"data":textblock_2},...,{"id":id_n,"data":textblock_n}], where each element is a dictionary containing a text block ID and its content. The text data after segmentation is vectorized using a pre-trained word vector embedding model based on supervised learning and contrastive learning (such as BERT, RoBERTa, etc.). Each text block can be input into the embedding model to generate a corresponding high-dimensional vector representation. The above process can capture the semantic information in the text. Subsequently, the generated vector is stored in the vector database together with the text identifier and the original text block to ensure that relevant information can be efficiently retrieved and matched in subsequent searches. The processed data structure becomes [{"id":id_1,"data":textblock_1,"vector":vector_1},{"id":id_2,"data":textblock_2,"vector":vector_2},...,{"id":id_n,"data":textblock_n,"vector":vector_n}].
[0041] S120, determining a text tag set corresponding to the text data set to be processed, and establishing a text vector database based on the text tag set and the text data set to be processed.
[0042] The text tag set may be a data set consisting of tags corresponding to text data. The text vector database is a database for storing text blocks, semantic vectors and tag sets, and supports efficient query and retrieval.
[0043] Specifically, after extracting and annotating the labels of the divided text, the text block data is bound to its corresponding label set based on the unique ID of the text block, thereby adding an additional information dimension to each data entry, which helps to improve the query efficiency and accuracy. The final data format is as follows: [{"id":id_1,"data":textblock_1,"vector":vector_1,"label":[label_1,label_2,...,label_n]},{"id":id_2,"data":textblock_2,"vector":vector_2,"label":[label_1,label_2,...,label_n]},...,{"id":id_n,"data":textblock_n,"vector":vector_n,"label":[label_1,label_2,...,label_n]}]. Then, according to the project requirements, select a suitable vector database, such as PostgreSQL, Elasticsearch or a dedicated vector search engine (such as Faiss). Store the processed data entries in the selected vector database. Use the index structure and query algorithm in the vector database or vector search engine to ensure that the system can quickly respond to user retrieval requests and provide accurate result matching.
[0044] On the basis of the above technical solution, the method of determining the text tag set corresponding to the text data set to be processed includes: when there is a preset text tag set corresponding to the original text data, inputting the text data set to be processed and the preset text tag set into a preset semantic retrieval model to obtain a candidate text tag set; inputting the candidate text tag set and the text data set to be processed into a large language model to determine the text tag set corresponding to the text data set to be processed.
[0045] The preset text tag set may be a pre-established tag set corresponding to the original text, and the preset text tag set may be obtained by manually annotating the original text, or may be a set of text tags obtained by processing the original text with a pre-trained semantic recognition model. The preset semantic retrieval model may be a pre-trained large language model used for retrieval based on text semantics.
[0046] Specifically, when there is a preset text tag set corresponding to the original text data, the text data set to be processed and the preset text tag set are input into the preset semantic retrieval model together. The preset semantic retrieval model is based on the semantic similarity between the text contents, and retrieves the tags most relevant to the text data set to be processed from the preset tag set, and then generates a candidate text tag set, which contains tags that are highly relevant to the text data set to be processed. Next, the candidate text tag set and the text data set to be processed are input into a large language model, such as GPT-4, BERT, etc., and the most accurate text tags are determined. Exemplary, such as Figure 2 As shown in the figure, with a preset candidate tag library, the pre-trained semantic retrieval model is used to perform preliminary screening of question text or knowledge text fragments. The candidate prompt words most relevant to the question text or knowledge text are recalled from a large number of preset candidate tags. Subsequently, a special tag screening prompt word is constructed, and the recalled candidate tag set and the question text or knowledge text are input into the large language model together, so as to accurately locate the correct tag that needs to be used in the end, and also support the generation of hierarchical multi-level tag structure to ensure that each tag can accurately reflect the core content of the document or sentence.
[0047] On the basis of the above technical solution, the determining of the text tag set corresponding to the text data set to be processed includes: when there is no preset text tag set corresponding to the original text data, constructing a tag extraction prompt word corresponding to the text data set to be processed; inputting the tag extraction prompt word and the text data set to be processed into a large language model to determine the text tag set corresponding to the text data set to be processed.
[0048] The tag extraction prompt word is a prompt word used to instruct the large language model to extract tags, and the tag extraction prompt word may be a prompt word corresponding to the target business scenario.
[0049] Specifically, in the absence of a preset text tag set, by constructing a tag extraction prompt word, the tag extraction prompt word is a phrase or question related to the content of the text data set to be processed and can guide the large language model to generate relevant tags. For example, if the text data set to be processed is about science and technology news, then the tag extraction prompt word can include "What is the theme of this news?", "What are the technical fields involved?", etc., and then the constructed tag extraction prompt word and the text data set to be processed are input into the large language model together, and the large language model will generate candidate tags based on the input prompt words and text content. Exemplarily, in the absence of a preset text tag set corresponding to the original text data, a specific tag extraction prompt word is constructed and input into the large language model in combination with the question text or knowledge text fragment provided by the user. The large language model will extract the most relevant category and content tags based on the above information. The above process supports the generation of a hierarchical and multi-level tag system based on documents, text blocks, and even single sentences. The tags finally extracted will be bound to the original question text or knowledge text block for further processing operations.
[0050] It should be noted that when it is detected that a specific document has a custom tag, custom annotation of the document data can be implemented based on the custom tag. For example, when processing data containing sensitive information, relevant tags such as permission management can be automatically generated and these tags can be accurately attached to the corresponding question text or knowledge text block ID.
[0051] S130. When a question to be processed is received, determine a question text label and a question text vector corresponding to the question to be processed.
[0052] The problem to be processed may be a problem associated with the target business scenario input by the user. The problem text label may be understood as a text label obtained by extracting a label from the problem text to be processed. Correspondingly, the problem text vector may be a text vector corresponding to the problem text obtained after vectorization processing of the problem text.
[0053] Specifically, when receiving a pending question, we can deeply understand and analyze the pending question, identify the topic, key information and question type of the question, and then extract the most representative keywords or phrases from the question, match the extracted keywords with the existing tag library, select the most suitable tag, and clean the question (such as removing stop words, punctuation marks, etc.), segment, stem or restore the word form, etc., and use the bag of words model, TF-IDF, word embedding (such as Word2Vec, GloVe, BERT, etc.) to convert the text into a feature vector, and finally integrate the determined question text label and the generated question text vector to form a complete question representation, which contains both the semantic information of the question and the numerical characteristics of the question. It should be noted that the above-mentioned processing method for question text is also applicable to the processing of document data.
[0054] S140: Determine the text to be applied from the text vector database based on the question text to be processed, the question text label and the question text vector.
[0055] The question text to be processed may be text data of the question to be processed, and the text to be applied is text used to construct an answer corresponding to the question.
[0056] Specifically, similarity measurement methods such as cosine similarity, Euclidean distance, Manhattan distance and other algorithms can be used to calculate the similarity between the text vector of the problem to be processed and the text vector in the database, and the text most similar to the problem to be processed can be screened out according to the similarity threshold that should be set in advance, and the question text label can be further used to filter the results based on the similarity calculation. For example, if the label of the problem to be processed is "machine learning algorithm", only the text in the database that is also labeled "machine learning algorithm" can be considered, and the results can be filtered according to the similarity score and label, the text in the database is sorted, and the text that best meets the needs of the problem to be processed is selected as the text to be applied.
[0057] S150: Generate a target question answer corresponding to the question to be processed according to the text to be applied and a preset prompt word template.
[0058] The preset prompt word template may be a preset prompt word corresponding to a business scenario.
[0059] Specifically, according to different usage scenarios, a preset prompt word template is used to combine the user question with the text to be applied to generate the corresponding answer. The text to be applied is formatted using the preset prompt word template to generate the target question answer corresponding to the problem to be processed. It should be noted that the answer generation prompt word template, as a basic framework, needs to be written in advance according to the specific application scenario. The template is designed to accommodate user questions and related text blocks recalled from the knowledge base. By reasonably filling in these contents, a complete and structured prompt word is formed to ensure that the large language model can accurately understand and respond to the user's query needs. After the constructed answer generation prompt word is input into the large language model, it is comprehensively analyzed and generated based on the user's question and its related background knowledge, and an accurate and comprehensive answer is generated.
[0060] On the basis of the above technical solution, the method of generating a target question answer corresponding to the problem to be processed according to the text to be applied and a preset prompt word template includes: obtaining a preset prompt word template corresponding to a target business scenario, generating answer generation prompt words according to the preset prompt word template and the text to be applied; and inputting the answer generation prompt words into a large language model to generate a target question answer corresponding to the problem to be processed.
[0061] Specifically, according to the target business scenario, select or construct an appropriate preset prompt word template. The template is usually designed based on business logic, common problem types or historical data analysis, and is used to guide the large language model to generate answers that conform to a specific format or style. For example, for a customer consultation scenario, the template may include "Based on the information provided, your answer is...", "Regarding your problem, the solution is...", etc. Then combine the text to be applied with the preset prompt word template to generate answer generation prompt words. The key information in the text to be applied can be inserted into the corresponding position of the template, or the text to be applied can be appropriately rewritten according to the structure and style of the template, and the generated answer generation prompt words are input into the pre-trained large language model. Large language models, such as the GPT series (GPT-3, GPT-4, etc.), will generate the target question answer corresponding to the problem to be processed based on the answer generation prompt words.
[0062] Can be combined Figure 3 The technical solution provided by the embodiment of the present invention is further described as follows: Figure 3 As shown in the figure, firstly, business data is obtained based on the current usage scenario, and the business data is analyzed for text parsing, document segmentation, text label extraction and annotation, and text block vectorization, and the final text block, vector block, and label set are stored together in the vector database. Then the user enters the question, the question is segmented, the label is extracted and marked, and vectorized, and then a multi-way search is performed in the vector database to recall the relevant text blocks, and finally combined with the preset prompt words, it is sent to the large language model to generate the final answer.
[0063] The technical solution of the embodiment of the present invention obtains the original text data corresponding to the target business scenario, and performs vectorization processing on the original text data to determine the text data set to be processed, and determines the text tag set corresponding to the text data set to be processed, and establishes a text vector database based on the text tag set and the text data set to be processed, and then, when receiving the problem to be processed, determines the question text tag and question text vector corresponding to the problem to be processed, determines the text to be applied from the text vector database based on the problem text to be processed, the question text tag and the question text vector, and generates the target question answer corresponding to the problem to be processed according to the text to be applied and the preset prompt word template. Based on the above technical solution, by constructing a vector library of document text tag data, information related to user needs can be quickly found, and a large language model is used for analysis and summary, so as to return the answer to the user's question, and by customizing the data source and data tag according to the business scenario, and combining the vector retrieval function, the granularity and accuracy of the retrieval results can be improved.
[0064] Embodiment 2
[0065] Figure 4 The flowchart of a multi-label matching RAG intelligent question-answering method provided in an embodiment of the present invention further refines the technical solution of determining the text to be applied from the text vector database based on the question text to be processed, the question text label and the question text vector on the basis of the above technical solution. Figure 4 As shown, the method includes:
[0066] S210. Calculate the correlation scores between the problem text to be processed and each text block in the text vector database based on a preset text matching algorithm, and determine a set of text blocks to be processed corresponding to the problem text to be processed from the text vector database according to the correlation scores.
[0067] The preset text matching algorithm may be a pre-set algorithm for calculating text similarity, for example, cosine similarity, Jaccard similarity, edit distance (such as Levenshtein distance), BM25 algorithm, or the like.
[0068] Specifically, the selected text matching algorithm is used to calculate the relevance score between the question text to be processed and each text block in the text vector database. The relevance score is a value between 0 and 1, which indicates the similarity or matching degree between two text blocks. According to specific needs, a threshold for the relevance score can be set, and only text blocks with scores higher than this threshold will be selected. All text blocks can also be sorted according to the relevance score, and then the top N text blocks with the highest scores are selected as the set of text blocks to be processed. Exemplarily and specifically, text block data is retrieved in the vector database based on user questions. The BM25 algorithm can be used for retrieval: ; Where: -(Q) represents the query statement; -(D) represents the document; -(q_i) represents the i-th word in the query statement; -(n) is the total number of words in the query statement; -(|D|) is the document length; -(text{avgdl}) is the average length of the documents in the document collection; -(IDF(q_i)) is the inverse document frequency, which is used to measure the importance of a word in a document collection. The calculation formula of (IDF(q_i)) is: [IDF(q_i)=logleft(frac{N}{text{df}(q_i)}+1right)] where (N) is the total number of documents, (text{df}(q_i)) is the number of documents containing the word (q_i); -(f(q,D)) is the term frequency (TF), which indicates the number of occurrences of the i-th word in the document, and is used to measure the importance of a word in the document; -(k_1) and (b) are adjustment parameters, which control the number of individual words in the document and the influence of the document length respectively: Sort the text blocks according to the retrieval score calculated by the above formula, and obtain the text block ID ranking. These text blocks will serve as the basic data for generating answers later.
[0069] S220, based on the question text label, filter out the text blocks to be verified that match the question text label from the text vector database, and calculate the correlation score between the question text to be processed and the text blocks to be verified according to the preset text matching algorithm, and determine the set of text blocks to be processed corresponding to the question text to be processed from the text blocks to be verified based on the correlation score.
[0070] The text block to be verified may be a text block that matches the question text label and is obtained by screening from a text vector database in a label matching manner.
[0071] Specifically, based on the question text label, a text block matching the question text label is screened out in the text vector database and used as the text block to be verified. The correlation score between the question text to be processed and the text block to be verified is calculated according to a preset text matching algorithm. Then, based on the correlation score, a set of text blocks to be processed with higher correlation scores is further screened out from the text blocks to be verified. Exemplarily, the text blocks to be verified can be sorted in descending order according to the calculated correlation scores, and a set of text blocks to be processed can be selected according to the sorting result based on a preset number of text blocks to be selected, and the text block ID of each text block in the set of text blocks to be processed is obtained.
[0072] It should be noted that, in another possible implementation, the number of label matches between each text block in the text vector database and the question text label can be determined, and a set of to-be-processed text blocks corresponding to the question text label can be determined from the text vector database based on the number of label matches.
[0073] The number of label matches may be the number of label matches between the label of the text block and the label of the question.
[0074] Specifically, for each text block in the text vector database, the number of label matches between it and the question text label is calculated, for example, the text block is compared with the label set carried by the question, the number of common labels is found, and according to the determined screening criteria, the text block with the highest number of label matches with the question text is screened out from the text vector database to form a set of text blocks to be processed. Exemplarily, based on the label of the user question, matching label data is retrieved in the vector database. The text blocks are sorted according to the number of matches between each text block and the user question label, and their ID rankings are obtained.
[0075] S230, calculating the vector similarity between each text block in the text vector database and the question text vector based on a vector search engine, and determining a set of to-be-processed text blocks corresponding to the question text vector from the text vector database according to the vector similarity.
[0076] Among them, vector similarity can be understood as the score of the similarity between the question text vector and the text block vector.
[0077] Specifically, the similarity calculation function provided by the vector search engine, such as cosine similarity, Euclidean distance, dot product, etc., is used to calculate the similarity between the question text vector and each text block vector in the text vector database, and the text block most relevant to the question text vector is screened out from the text vector database according to the determined screening threshold or sorting result to form a set of text blocks to be processed. Exemplarily, the vector representation of the user's question is used to search the vector database for the most semantically similar text block vector. The vector retrieval engine in the database is used to calculate the similarity between the vectors, and the results are sorted from high to low according to the similarity score, and finally the text block ID ranking is obtained.
[0078] S240: Determine the text to be applied based on the text block set to be processed.
[0079] On the basis of the above technical solution, the method of determining the text to be applied based on the text block set to be processed includes: determining a text block identifier corresponding to each text block in the text block set to be processed, and deduplicating the text block set to be processed according to the text block identifier; determining a comprehensive score of each text block in the text block set to be processed after deduplication according to a comprehensive scoring algorithm, and determining a target text block from the text block set to be processed according to the comprehensive score; and acquiring the text to be applied from the text vector database based on the text block identifier of the target text block.
[0080] The text block identifier may be a digital identifier corresponding to each text block in the vector database, and the comprehensive scoring algorithm may be an algorithm for determining a comprehensive matching score corresponding to each text block.
[0081] Specifically, the text block set to be processed of the multi-path retrieval results obtained in the above steps is first deduplicated for all the text block IDs in the text block set to be processed. Then the RFF algorithm is used to comprehensively rank the text blocks in the retrieval results of each path. The formula of the RFF algorithm is as follows: ; Where: -(RRF_w(d)) represents the weighted multi-path retrieval score. -(sum_{rinR}) represents the sum of all retrieval paths (r). -(w_r) is the weight given to the (r)th retrieval, which is used to adjust the importance of different retrieval paths in the final result. -(frac{1}{k+r(d)}) is the reciprocal ranking score of each retrieval path in the original RFF algorithm, where (k) is a constant and (r(d)) represents the ranking of document (d) in the (r)th retrieval. -(k_1in[1.2,2.0]) adjusts the text frequency scale of the feature word. The larger the (k_1) value, the greater the impact of the original word frequency on relevance; -(b) is called the document length normalization factor. The larger the (b) value, the greater the impact of the document length on relevance. The comprehensive score of each text block is calculated by this formula, and the top K text block IDs are selected according to the preset TOP_K number, and the corresponding text content is recalled as the final retrieval result.
[0082] It should be noted that, on the basis of the above technical solution, in order to further optimize the quality and response speed of the retrieval results, Reranker can be selected to work before or after the RFF algorithm according to needs. When Reranker is before RFF, Reranker can be used to re-arrange the retrieval results in each retrieval path first, and the re-arranged results of each path are sent to the RFF algorithm for comprehensive ranking. It should be noted that the configuration of Reranker before RFF is suitable for situations where users want to obtain more content. By applying Reranker independently on each retrieval path, the result quality of each retrieval path can be more finely adjusted.
[0083] When Reranker is after RFF, the RFF algorithm is used to comprehensively rank the search results of all paths. After the comprehensive ranking, Reranker is used to re-rank the results after the RFF comprehensive ranking. It should be noted that the configuration of Reranker after RFF is suitable for situations where users want to obtain high-quality results faster. By reducing the amount of data processed by Reranker, the response speed of the system can be significantly improved.
[0084] On the basis of the above technical solution, the Reranker used in the above technical solution is further explained, including: Statistical-based Reranker (RFF), which recalculates the scores for all results by aggregating candidate result lists from multiple sources and using a multi-way recall weighted score or a reciprocal ranking fusion (RRF) algorithm. The formula is: [\text{NewScore}(d)=\sum_{r\inR}w_r' \cdot \frac{1}{k'+r'(d)} ] Where: - (w_r') is the weight assigned to the (r)th retrieval. -(k') is a constant, and (r'(d)) represents the ranking of document (d) after Reranker processing. It should be noted that the calculation of the statistical-based Reranker is not complicated and efficient, and is suitable for traditional search systems that are sensitive to latency.
[0085] Furthermore, it can also include a Reranker (Cross-encoder Reranker) based on a deep learning model, which uses a specially trained neural network to analyze the correlation between questions and documents and score the semantic similarity between questions and documents. The formula is: [\text{NewScore}(d)=f(\text{Query},d)] Where: -(f) is a trained deep learning model, the input is the query ((\text{Query})) and the document ((d)), and the output is a score representing the correlation. It should be noted that the score generally depends only on the text content of the question and the document, not on the score or relative position of the document in the recall result. It is applicable to both single-way recall and multi-way recall. Through the selection and configuration of the above two Reranker modules, users can flexibly adjust the performance and quality of the retrieval system according to actual needs.
[0086] The technical solution provided by the embodiment of the present invention significantly improves the accuracy and adaptability of the system by combining traditional vector retrieval technology and a diversified text labeling mechanism. First, by introducing a multi-level text labeling system, the system can classify and label data more finely, covering not only explicit features such as keywords and field identifiers, but also implicit information such as authority levels and semantic categories. This multi-dimensional labeling mechanism enables the system to more accurately identify user intent when processing queries in specific fields, and quickly retrieve highly relevant answer candidate sets from massive data. In addition, by introducing a variety of text labels, more accurate retrieval and matching can be achieved on limited data sets, thereby alleviating the dependence on a large amount of high-quality training data to a certain extent. Based on the above technical solution, the stability and scalability of the question-and-answer system are improved, and the search for internal data is faster and more accurate, and it is easy to expand to different application scenarios.
[0087] Embodiment 3
[0088] Figure 5 A schematic diagram of the structure of a RAG intelligent question-answering device for generating and matching multiple labels provided by an embodiment of the present invention. Figure 5 As shown, the device includes: a text data processing module 510, a vector database building module 520, a question text processing module 530, a to-be-applied text determination module 540 and a question answer generation module 550, wherein:
[0089] The text data processing module 510 is used to obtain original text data corresponding to the target business scenario, and perform vectorization processing on the original text data to determine a text data set to be processed;
[0090] A vector database establishing module 520, used to determine a text tag set corresponding to the text data set to be processed, and establish a text vector database based on the text tag set and the text data set to be processed;
[0091] The question text processing module 530 is used to determine the question text label and question text vector corresponding to the question to be processed when receiving the question to be processed;
[0092] A to-be-applied text determination module 540, configured to determine the to-be-applied text from the text vector database based on the to-be-processed question text, the question text label and the question text vector;
[0093] The question answer generating module 550 is used to generate a target question answer corresponding to the question to be processed according to the text to be applied and a preset prompt word template.
[0094] On the basis of the above technical solution, the vector database establishment module is used to, when there is a preset text tag set corresponding to the original text data, input the text data set to be processed and the preset text tag set into a preset semantic retrieval model to obtain a candidate text tag set; input the candidate text tag set and the text data set to be processed into a large language model to determine the text tag set corresponding to the text data set to be processed.
[0095] On the basis of the above technical solution, the vector database establishment module is used to construct a label extraction prompt word corresponding to the text data set to be processed in the absence of a preset text label set corresponding to the original text data; the label extraction prompt word and the text data set to be processed are input into a large language model to determine the text label set corresponding to the text data set to be processed.
[0096] On the basis of the above technical scheme, the module for determining the text to be applied is used to calculate the correlation score corresponding to the problem text to be processed and each text block in the text vector database based on a preset text matching algorithm, and determine the set of text blocks to be processed corresponding to the problem text to be processed from the text vector database according to the correlation score; screen out the text blocks to be verified that match the problem text label from the text vector database based on the problem text label, and calculate the correlation score between the problem text to be processed and the text block to be verified according to the preset text matching algorithm, and determine the set of text blocks to be processed corresponding to the problem text to be processed from the text blocks to be verified based on the correlation score; calculate the vector similarity between each text block in the text vector database and the problem text vector based on a vector search engine, and determine the set of text blocks to be processed corresponding to the problem text vector from the text vector database according to the vector similarity; determine the text to be applied based on the set of text blocks to be processed.
[0097] On the basis of the above technical solution, the module for determining the text to be applied is used to determine the text block identifier corresponding to each text block in the text block set to be processed, and perform deduplication processing on the text block set to be processed according to the text block identifier; determine the comprehensive score of each text block in the text block set to be processed after deduplication processing according to a comprehensive scoring algorithm, and determine the target text block from the text block set to be processed according to the comprehensive score; and obtain the text to be applied from the text vector database based on the text block identifier of the target text block.
[0098] On the basis of the above technical solution, the text data processing module is used to determine the text format corresponding to the original text data, extract text content from the original text data according to the text format; segment the text content according to the segmentation identifier, determine the text blocks corresponding to the text content, and assign a text block identifier to each text block; determine the text data set to be processed based on the text blocks and the text block identifiers assigned to the text blocks.
[0099] On the basis of the above technical solution, the question answer generation module is used to obtain a preset prompt word template corresponding to the target business scenario, generate answer generation prompt words according to the preset prompt word template and the determined text to be applied; input the answer generation prompt words into the large language model to generate a target question answer corresponding to the problem to be processed.
[0100] The technical solution of the embodiment of the present invention obtains the original text data corresponding to the target business scenario, and vectorizes the original text data to determine the text data set to be processed, and determines the text tag set corresponding to the text data set to be processed, and establishes a text vector database based on the text tag set and the text data set to be processed, and then when receiving the problem to be processed, determines the problem text tag and the problem text vector corresponding to the problem to be processed, determines the text to be applied from the text vector database based on the problem text to be processed, the problem text tag and the problem text vector, and generates the target question answer corresponding to the problem to be processed according to the determined text to be applied and the preset prompt word template. Based on the above technical solution, by constructing a vector database of document text tag data, information related to user needs can be quickly found, and a large language model is used for analysis and summary, so as to return the answer to the user's question, and by customizing the data source and data tag according to the business scenario, and combining the vector retrieval function, the granularity and accuracy of the retrieval results can be improved, and the present invention also supports the customization of data sources and data tags according to different business scenarios, and combines the efficient vector retrieval function, which significantly improves the granularity and accuracy of the retrieval results.
[0101] The RAG intelligent question-answering device for generating and matching multiple labels provided in an embodiment of the present invention can execute the RAG intelligent question-answering method for generating and matching multiple labels provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0102] Embodiment 4
[0103] Figure 6 A schematic diagram of the structure of an electronic device 10 that can be used to implement an embodiment of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0104] like Figure 6As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11 in communication, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, ROM 12 and RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0105] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0106] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 executes the various methods and processes described above, such as the RAG intelligent question-answering method for multi-label generation matching.
[0107] In some embodiments, the RAG intelligent question-answering method for generating matches with multiple labels may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the RAG intelligent question-answering method for generating matches with multiple labels described above may be executed. Alternatively, in other embodiments, the processor 11 may be configured to execute the RAG intelligent question-answering method for generating matches with multiple labels in any other appropriate manner (e.g., by means of firmware).
[0108] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0109] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0110] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, 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 foregoing.
[0111] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0112] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0113] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0114] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0115] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A multi-label generation and matching RAG intelligent question answering method, characterized in that: include: Acquire original text data corresponding to the target business scenario, and perform vectorization processing on the original text data to determine a text data set to be processed; Determine a text tag set corresponding to the text data set to be processed, and establish a text vector database based on the text tag set and the text data set to be processed; When receiving a question to be processed, determining a question text label and a question text vector corresponding to the question to be processed; Determine the text to be applied from the text vector database based on the question text to be processed, the question text label and the question text vector; An answer to a target question corresponding to the question to be processed is generated according to the text to be applied and a preset prompt word template.
2. The method according to claim 1, characterized in that The step of determining a text tag set corresponding to the text data set to be processed includes: When there is a preset text tag set corresponding to the original text data, inputting the to-be-processed text data set and the preset text tag set into a preset semantic retrieval model to obtain a candidate text tag set; The candidate text tag set and the to-be-processed text data set are input into a large language model to determine a text tag set corresponding to the to-be-processed text data set.
3. The method according to claim 1, characterized in that The step of determining a text tag set corresponding to the text data set to be processed includes: In the absence of a preset text tag set corresponding to the original text data, constructing a tag extraction prompt word corresponding to the text data set to be processed; The tag extraction prompt words and the to-be-processed text data set are input into a large language model to determine a text tag set corresponding to the to-be-processed text data set.
4. The method according to claim 1, characterized in that: Determining the text to be applied from the text vector database based on the question text to be processed, the question text label and the question text vector includes: Calculating the relevance scores of the problem text to be processed and each text block in the text vector database based on a preset text matching algorithm, and determining a set of text blocks to be processed corresponding to the problem text to be processed from the text vector database according to the relevance scores; Based on the question text label, a text block to be verified that matches the question text label is screened out from the text vector database, and a correlation score between the question text to be processed and the text block to be verified is calculated according to the preset text matching algorithm, and a set of text blocks to be processed corresponding to the question text to be processed is determined from the text blocks to be verified based on the correlation score; Calculate the vector similarity between each text block in the text vector database and the question text vector based on a vector search engine, and determine a set of to-be-processed text blocks corresponding to the question text vector from the text vector database according to the vector similarity; The text to be applied is determined based on the text block set to be processed.
5. The method according to claim 4, characterized in that The determining the text to be applied based on the text block set to be processed includes: Determine a text block identifier corresponding to each text block in the text block set to be processed, and perform deduplication processing on the text block set to be processed according to the text block identifier; Determine the comprehensive score of each text block in the to-be-processed text block set after deduplication processing according to the comprehensive scoring algorithm, and determine the target text block from the to-be-processed text block set according to the comprehensive score; The text to be applied is obtained from the text vector database based on the text block identifier of the target text block.
6. The method according to claim 1, characterized in that The vectorization processing of the original text data to determine the text data set to be processed includes: Determining a text format corresponding to the original text data, and extracting text content from the original text data according to the text format; Segment the text content according to the segmentation identifier, determine each text block corresponding to the text content, and assign a text block identifier to each text block; The text data set to be processed is determined based on the text blocks and the text block identifiers assigned to the text blocks.
7. The method according to claim 1, characterized in that The step of generating a target question answer corresponding to the problem to be processed according to the text to be applied and the preset prompt word template includes: Acquire a preset prompt word template corresponding to the target business scenario, and generate prompt words for an answer based on the preset prompt word template and the text to be applied; The answer generation prompt words are input into the large language model to generate a target question answer corresponding to the question to be processed.
8. A multi-label generation and matching RAG intelligent question-answering device, characterized in that: include: A text data processing module is used to obtain original text data corresponding to the target business scenario, and perform vectorization processing on the original text data to determine a text data set to be processed; A vector database establishment module, used for determining a text tag set corresponding to the text data set to be processed, and establishing a text vector database based on the text tag set and the text data set to be processed; A question text processing module, configured to determine a question text label and a question text vector corresponding to the question to be processed when receiving the question to be processed; A module for determining text to be applied, used for determining text to be applied from the text vector database based on the question text to be processed, the question text label and the question text vector; The question answer generation module is used to generate a target question answer corresponding to the question to be processed according to the text to be applied and a preset prompt word template.
9. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the RAG intelligent question-answering method for multi-label generation and matching as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the RAG intelligent question-answering method for multi-label generation and matching according to any one of claims 1 to 7 when executed.
Citation Information
Patent Citations
Vector knowledge base-based large-model question-answer dialogue method and system and storage medium
CN118484526A
Intelligent customer service implementation method and device, equipment and storage medium
CN119047573A
Large language model government affair intelligent question and answer method, system and device and medium
CN119537529A
Cited By
Label generation method, device, equipment and product based on large model and configuration
CN120508659A
Hybrid retrieval method, system and equipment based on multi-algorithm fusion and storage medium
CN120653728A
Document marking method and system based on entity enhancement and multi-granularity fusion
CN121071146A
Data storage processing method and system, data retrieval method and system and related equipment
CN121233544A
Data processing method and product
CN121636719A