Question answering method and device based on RAG, equipment and medium
By employing a hybrid retrieval strategy and adaptive selection, the issues of retrieval recall and precision in the RAG question-answering system were resolved, resulting in efficient and logically sound retrieval results generation, and improving the system's versatility and resource utilization efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEISEN CLOUD COMPUTING CO LTD
- Filing Date
- 2026-01-16
- Publication Date
- 2026-05-01
AI Technical Summary
Existing RAG-based question answering systems struggle to balance retrieval recall and precision. Hybrid retrieval strategies fail to effectively correlate score calculations, leading to information redundancy and contextual fragmentation. Furthermore, they fail to consider query requirements and system resource constraints, resulting in low generation efficiency or resource waste.
A hybrid retrieval strategy is adopted, which uses semantic parsing and entity recognition to obtain the core requirements of the query statement, calculates the relevance score between the candidate retrieval results and the query statement, performs document aggregation, and adaptively selects the target retrieval results based on the query budget.
It improves the accuracy and recall of search results, reduces information redundancy, enhances the logic and efficiency of answer generation, balances resource consumption and answer quality, and strengthens the system's versatility and robustness.
Smart Images

Figure CN121958489A_ABST
Abstract
Description
A RAG-based question-answering method, apparatus, device, and medium Technical Field
[0001] This application relates to the field of artificial intelligence technology, and more specifically, to a question-answering method, apparatus, device, and medium based on RAG. Background Technology
[0002] With the development of natural language processing and information retrieval technologies, the Retrieval Enhancement Generation (RAG) framework has become a core solution for solving the illusion problem of Large Language Models (LLM) and improving the accuracy of question answering. It is widely used in scenarios such as enterprise knowledge base querying, policy consultation, and compliance question answering.
[0003] Existing RAG-based question-answering systems often employ a single retrieval strategy, making it difficult to balance recall and precision. Furthermore, some hybrid retrieval strategies simply overlay multiple search results without calculating correlation scores or differentiating results from different retrieval channels. Moreover, the candidate results obtained are often fragmented, with different fragments potentially originating from the same document. Directly inputting these fragments into the generation model can lead to information redundancy and contextual fragmentation, affecting the logic and consistency of the generated answers. Further, when filtering search results, the specific needs of the query and system resource constraints (such as query budget) are often not considered. Either a fixed number of results are selected indiscriminately, or the pursuit of a large number of results exceeds the computational resource capacity, resulting in low generation efficiency or resource waste. Summary of the Invention
[0004] The purpose of this application is to provide a RAG-based question-answering method, apparatus, device, and medium to solve the above-mentioned problems existing in the prior art, improve the retrieval accuracy of the RAG question-answering system, and obtain retrieval results with strong logic and high relevance.
[0005] Firstly, a RAG-based question-answering method is provided. This method may include: obtaining a query statement input by a user; performing semantic parsing, intent recognition, and entity recognition on the query statement to obtain query parsing and recognition results; employing a hybrid retrieval strategy to retrieve multiple candidate search result sets associated with the query statement from a configured retrieval database, and calculating the association scores between the candidate search results in different candidate search result sets and the query statement; wherein each candidate search result set also contains the document to which the corresponding candidate search result belongs; aggregating multiple candidate search results according to the documents to which different candidate search results belong to, to obtain document aggregation results; determining a search result generation strategy based on the query parsing and recognition results; and adaptively selecting the document aggregation results according to the configured query budget and the search result generation strategy to generate the target search result corresponding to the query statement.
[0006] In an optional implementation, the retrieval database includes a vector retrieval database and a keyword retrieval database; the vector retrieval database contains fragment vectors of document segments from different documents; each document segment corresponds to a fragment identifier; the keyword retrieval database contains fragment identifiers of different document segments and multiple fragment keywords from the corresponding document segments.
[0007] In an optional implementation, a hybrid retrieval strategy is employed to retrieve multiple candidate search result sets associated with the query statement from a configured retrieval database. This includes: converting the query statement into a query vector; retrieving multiple fragment vectors from the vector retrieval database whose first similarity to the query vector is greater than a configured first similarity threshold; using the fragment identifiers of the retrieved fragment vectors, the documents to which the corresponding fragment vectors belong, and the first similarity between the corresponding fragment vectors and the query vector as different first candidate search result sets; splitting the query statement into multiple keywords; retrieving multiple document fragments containing multiple keywords from a configured keyword retrieval database, and calculating the second similarity between each document fragment and the query statement; using the fragment identifiers of the multiple document fragments containing multiple keywords, the documents to which the corresponding document fragments belong, and the corresponding second similarity as different second candidate search result sets; and fusing the different first candidate search result sets and the different second candidate search result sets to obtain multiple candidate search result sets.
[0008] In an optional implementation, calculating the association score between candidate search results in different candidate search result sets and the query statement includes: normalizing the first similarity in different first candidate search result sets and the second similarity in different second candidate search result sets to obtain multiple normalized first similarities and multiple normalized second similarities; if different first candidate search result sets and second candidate search result sets contain the same segment identifier, then the normalized first similarity and normalized second similarity corresponding to the segment identifier are weighted and fused to obtain the association score between the document segment corresponding to the segment identifier and the query statement; if any segment identifier is not simultaneously contained in different first candidate search result sets and second candidate search result sets, then the normalized first similarity or normalized second similarity corresponding to the corresponding segment identifier is used as the association score between the document segment corresponding to the segment identifier and the query statement.
[0009] In an optional implementation, the retrieval result generation strategy includes a first generation strategy and a second generation strategy; the query parsing and identification results include query intent category and entity identification results; the entity identification results include entities and entity types; and determining the retrieval result generation strategy based on the query parsing and identification results includes: counting the number of entities in the entity identification results; matching the target query complexity level corresponding to the query intent category, the number of entities, and the entity type according to a configured lookup table of different query intent categories, different number of entities, different entity types, and different query complexity levels; matching the target retrieval result generation strategy corresponding to the target query complexity level from a configured lookup table of different query complexity levels and different retrieval result generation strategies; using the target retrieval result generation strategy as the first generation strategy; and using other retrieval result generation strategies besides the target retrieval result generation strategy as the second generation strategy.
[0010] In an optional implementation, the document aggregation results are adaptively selected based on the configured query budget and the retrieval result generation strategy to generate the target retrieval result corresponding to the query statement. This includes: adaptively generating a first query budget corresponding to the first generation strategy and a second query budget corresponding to the second generation strategy based on the query budget and the configured budget allocation strategy; extracting a first retrieval result and a second retrieval result from the document aggregation results based on the first query budget and the second query budget, respectively; and fusing the first retrieval result and the second retrieval result to obtain the target retrieval result.
[0011] In an optional implementation, after fusing the first retrieval result and the second retrieval result, the method further includes: determining a comprehensive evidence score for the fused first retrieval result and the second retrieval result based on the fused first retrieval result and the second retrieval result, the query statement, and the query parsing and identification result; if the comprehensive evidence score is less than a configured evidence score threshold, then semantically expanding the query statement to generate a new query statement, and returning to the execution step: performing semantic parsing, intent recognition, and entity recognition on the query statement to obtain the query parsing and identification result.
[0012] Secondly, a RAG-based question-answering device is provided, which may include: an acquisition unit for acquiring a query statement input by a user; a parsing and recognition unit for performing semantic parsing, intent recognition, and entity recognition on the query statement to obtain query parsing and recognition results; a retrieval unit for using a hybrid retrieval strategy to retrieve multiple candidate retrieval result sets associated with the query statement from a configured retrieval database, and calculating the association scores between the candidate retrieval results in different candidate retrieval result sets and the query statement; wherein each candidate retrieval result set also includes the document to which the corresponding candidate retrieval result belongs; an aggregation unit for aggregating multiple candidate retrieval results according to the documents to which different candidate retrieval results belong, to obtain document aggregation results; a determination unit for determining a retrieval result generation strategy based on the query parsing and recognition results; and a generation unit for adaptively selecting the document aggregation results based on a configured query budget and the retrieval result generation strategy to generate the target retrieval result corresponding to the query statement.
[0013] Thirdly, an electronic device is provided, comprising a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other via the communication bus; the memory is used to store computer programs; and the processor, when executing the program stored in the memory, implements any of the steps described in the first aspect above.
[0014] Fourthly, a computer-readable storage medium is provided, wherein a computer program is stored therein, and when executed by a processor, the computer program implements the steps of any of the methods described in the first aspect above.
[0015] This application first performs multi-dimensional analysis of user query statements, including semantic parsing, intent recognition, and entity recognition, which can deeply mine the core needs and key information of the query statements and provide accurate matching basis for subsequent retrieval. At the same time, it adopts a hybrid retrieval strategy and calculates the association score between different candidate retrieval results and the query statements, effectively integrating the advantages of different retrieval methods. This not only solves the semantic matching shortcomings of single sparse retrieval, but also makes up for the long-tail knowledge coverage defects of single dense retrieval, which greatly improves the accuracy and recall of retrieval results and reduces the interference of irrelevant results.
[0016] This application aggregates candidate search results according to the documents to which they belong, integrating scattered fragments from the same document into structured document aggregation results. This avoids the redundant accumulation of fragmented information and makes the search results input into the generation model more contextually relevant and logical. Based on this, the generated answers can better maintain content coherence and reduce the problem of contradictory answers caused by information fragmentation.
[0017] This application determines the retrieval result generation strategy based on the query parsing and identification results, and adaptively selects document aggregation results in conjunction with the configured query budget. This allows for reasonable control of the quantity and quality of retrieval results input into the generation model while meeting user query needs: for queries with simple intents, core and key aggregation results are selected to improve generation efficiency; for queries with complex intents, comprehensive aggregation results are selected within the budget to ensure the completeness of the answer. This design effectively balances answer quality and system resource consumption, avoiding resource waste or insufficient generated results.
[0018] This application can adapt to user query statements from different fields and with different expressions. The hybrid retrieval strategy and adaptive selection mechanism can be compatible with various types of retrieval databases and query needs of different scales. Compared with traditional methods, this application can maintain stable question-answering performance when facing fuzzy queries, long-tail queries, and complex multi-intent queries, which significantly improves the versatility and robustness of the RAG question-answering system. Attached Figure Description
[0019] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments of this application will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 is an architecture diagram of a RAG-based question-answering system provided in an embodiment of this application; Figure 2 is a flowchart of a RAG-based question-answering method provided in an embodiment of this application; Figure 3 is a structural diagram of a RAG-based question-answering device provided in an embodiment of this application; Figure 4 is a structural diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0021] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application. Unless otherwise defined, the technical or scientific terms used in this application should have the ordinary meaning understood by those skilled in the art. The words "first," "second," and similar terms used in this application do not indicate any order, quantity, or importance, but are only used to distinguish different components. The words "comprising" or "including," etc., mean that the element or object preceding the word covers the element or object listed after the word and its equivalents, but do not exclude other elements or objects. The words "connected," "coupled," or "connected," etc., are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. "Up," "down," "left," "right," etc., are only used to indicate relative positional relationships. When the absolute position of the described object changes, the relative positional relationship may also change accordingly.
[0022] RAG stands for Retrieval-Augmented Generation.
[0023] The RAG-based question-answering method provided in this application embodiment can be applied to the system architecture shown in Figure 1. As shown in Figure 1, the system can include a server and a terminal. The server can be a physical server, a server cluster composed of multiple physical servers, or a distributed system. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. The terminal can be a user equipment (UE) such as a mobile phone, smartphone, laptop, digital broadcast receiver, personal digital assistant (PDA), tablet computer (PAD), handheld device, in-vehicle device, wearable device, computing device, or other processing device connected to a wireless modem, mobile station (MS), mobile terminal, etc. The terminal and the server can be directly or indirectly connected through wired or wireless communication methods, which is not limited herein.
[0024] The preferred embodiments of this application are described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit this application. Furthermore, the embodiments and features in the embodiments of this application can be combined with each other without conflict.
[0025] Figure 2 is a flowchart illustrating a RAG-based question-answering method provided in an embodiment of this application. As shown in Figure 2, the method may include: step S210, obtaining the query statement input by the user.
[0026] In practice, the query statement entered by the user in the current dialogue is obtained. The query statement includes the query statement entered by the user in the current round and the query statement entered in previous rounds.
[0027] Step S220: Perform semantic parsing, intent recognition, and entity recognition on the query statement to obtain the query parsing and recognition results.
[0028] In practice, the query statement is standardized to obtain a standardized query statement. This standardization process may include: converting the query statement to a unified character encoding, correcting spelling errors, standardizing date / number formats, and removing irrelevant special characters. The standardized query statement is then input into a pre-trained intent classification model to obtain the query intent category and its corresponding confidence score. The query intent categories may include: process, definition, comparison, compliance, and cross-language categories. Using sequence labeling models or rules, entity recognition and extraction are performed on the standardized query statement to obtain a structured entity list, i.e., the entity recognition result. The entity recognition result contains multiple entities, each with corresponding text content, entity type, and position information within the query statement. Entity types may include: date and time, currency amount, organization name, product / model name, person name, and location. Based on the query statement, the standardized query statement, the query intent category labels, the corresponding confidence scores, and the structured entity list, a query parsing and recognition result is generated.
[0029] In another embodiment of this application, the query parsing and identification result may further include: query task type; specifically, the query task type and query complexity are determined based on the query parsing and identification result; specifically, the query parsing and identification result is input into a pre-trained task type identification model to obtain the query task type, which may include single document focusing task, cross-document aggregation task, or cross-language task, etc.
[0030] Step S230: Using a hybrid retrieval strategy, retrieve multiple candidate retrieval result sets associated with the query statement from the configured retrieval database, and calculate the association score between the candidate retrieval results and the query statement in different candidate retrieval result sets.
[0031] The retrieval database includes a vector retrieval database and a keyword retrieval database. The vector retrieval database contains fragment vectors of document segments from different documents. Each document segment corresponds to a fragment identifier. The keyword retrieval database contains fragment identifiers of different document segments and multiple fragment keywords in the corresponding document segments. Each candidate retrieval result set also contains the document to which the corresponding candidate retrieval result belongs.
[0032] In practice, the query statement is converted into a query vector; multiple fragment vectors with a first similarity greater than a configured first similarity threshold are retrieved from the vector retrieval database; the fragment identifiers of the retrieved fragment vectors, the documents to which the corresponding fragment vectors belong, and the first similarity between the corresponding fragment vectors and the query vector are used as different first candidate retrieval result sets; the query statement is split into multiple keywords; from the configured keyword retrieval database, algorithms such as BM25 are used to retrieve multiple document fragments containing multiple keywords with the highest matching degree, and the second similarity between each document fragment and the query statement is calculated; the fragment identifiers of the multiple document fragments containing multiple keywords, the documents to which the corresponding document fragments belong, and the first similarity between the corresponding document fragments and the query statement are used as different first candidate retrieval result sets; the query statement is split into multiple keywords; from the configured keyword retrieval database, algorithms such as BM25 are used to retrieve multiple document fragments containing multiple keywords, and the second similarity between each document fragment and the query statement is calculated; the fragment identifiers of the multiple document fragments containing multiple keywords, the documents to which the corresponding document fragments belong, and the first similarity between the corresponding document fragments and the query vectors are used as different first candidate retrieval result sets; the query statement is split into multiple keywords; the first similarity between the document fragment identifiers of the multiple document fragments containing multiple keywords, the documents to which the corresponding document fragments belong, and the first similarity between the corresponding document fragments and the query vectors are used as different first candidate retrieval result sets ... The documents and their corresponding second similarities are used as different second candidate search result sets. The different first candidate search result sets and the different second candidate search result sets are then fused to obtain multiple candidate search result sets. Specifically, the first similarities in the different first candidate search result sets and the second similarities in the different second candidate search result sets are normalized to obtain multiple normalized first similarities and multiple normalized second similarities. If different first candidate search result sets and second candidate search result sets contain the same fragment identifier, the normalized first similarity and normalized second similarity corresponding to the fragment identifier are weighted and fused to obtain the relationship between the document fragment corresponding to the fragment identifier and the query statement. The association score is calculated as follows: If any fragment identifier is not simultaneously included in different first and second candidate search result sets, the normalized first similarity or normalized second similarity corresponding to the fragment identifier is used as the association score between the document fragment corresponding to the fragment identifier and the query statement. Document fragments with association scores higher than the configured association threshold are sorted from high to low. Based on the location information of the corresponding document fragment in the metadata (such as page number and offset), the document fragment is aggregated with adjacent document fragments within the configured nearest neighbor window range in the belonging document to form a candidate cluster, i.e., a candidate search result set, and the corresponding overall relevance score. The overall relevance score of the candidate search result set... Take the score of its core segment or the average score of segments within the cluster; from the aggregated multiple candidate search result sets, select the top K candidate search result sets with the highest overall relevance scores, and feed them into the cross-encoder model for refined rearrangement to obtain the rearrangement scores of multiple candidate search result sets; where K is a positive integer; the cross-encoder model is used to perform deep semantic interaction between the query statement and the complete text of the document segment to obtain a more accurate rearrangement score; for each candidate search result set, perform a second weighted fusion of the corresponding association score and the rearrangement score to calculate the target association score; select a preset number of candidate search result sets according to the target association score from high to low to obtain multiple candidate search result sets associated with the query statement.
[0033] In one embodiment of this application, the method for constructing a vector retrieval database may include: acquiring multi-source documents; performing MIME recognition, unpacking, OCR, layout parsing, language detection, noise reduction, and deduplication on the multi-source documents to form fragments with metadata; converting each fragment into an embedded vector and writing it into a vector database; writing the fragments and their metadata into fragment storage; storing the original documents in object storage; establishing a keyword inverted index in the vector retrieval database for mixed retrieval; wherein, when converting each fragment into an embedded vector, the text is generated using the bge-m3 / text-embedding-3-large model; the images are fused with the CLIP / ViT model and OCR text; the tables or code are structured and flattened with annotations, using the HNSW / IVF-PQ index structure, and the measurement method is cosine similarity.
[0034] Step S240: Aggregate multiple candidate search results according to the documents to which different candidate search results belong, and obtain document aggregation results.
[0035] In practice, multiple document groups are formed based on the documents to which different candidate search results belong. For any document group, if the document fragments in the candidate search results belonging to that document are consecutive or adjacent, the consecutive or adjacent document fragments are merged into a document candidate segment according to the configured reading order. For each document group, the mean or maximum value of the target association scores of all document fragments in that document group is calculated as the association strength score between that document group and the query statement. The page number distribution range and total text length of document fragments with target association scores greater than the configured association threshold in each document group are statistically analyzed. Based on the different candidate search results, corresponding association strength scores, page number distribution range, and total text length contained in each document group, the document aggregation result is obtained.
[0036] Step S250: Determine the strategy for generating search results based on the query parsing and identification results.
[0037] The search result generation strategy includes a first generation strategy and a second generation strategy; the search result generation strategy includes a document generation strategy and a fragment generation strategy.
[0038] In practice, the number of entities in the entity recognition results is counted; based on the configured lookup tables for different query intent categories, different number of entities, different entity types, and different query complexity levels, the target query complexity level corresponding to the query intent category, number of entities, and entity type is matched; from the configured lookup tables for different query complexity levels and different retrieval result generation strategies, the target retrieval result generation strategy corresponding to the target query complexity level is matched; the target retrieval result generation strategy is used as the first generation strategy; other retrieval result generation strategies besides the target retrieval result generation strategy are used as the second generation strategy; specifically, the target query complexity level includes high-complexity queries and low-complexity queries; when it is a high-complexity query, the first generation strategy is a document generation strategy; when it is a low-complexity query, the first generation strategy is a fragment generation strategy.
[0039] Step S260: Based on the configured query budget and retrieval result generation strategy, adaptively select the document aggregation results to generate the target retrieval results corresponding to the query statement.
[0040] In specific implementation, based on the query budget and the configured budget allocation strategy, an adaptive first query budget corresponding to the first generation strategy and a second query budget corresponding to the second generation strategy are generated. The query budget is determined based on the configured upper limit of the context length, the configured text length, and the target answer length. The target answer length is predicted based on the query parsing results. The query budget = upper limit of the context length - (text length + target answer length). The budget allocation strategy includes a first allocation ratio and a second allocation ratio. The product of the query budget and the first allocation ratio is used as the first query budget. The product of the query budget and the second allocation ratio is used as the second query budget. Based on the first query budget and the second query budget, the query budget is calculated from the document aggregation results. Extract the first and second search results; specifically, when the first generation strategy is a document generation strategy, filter document groups from the document aggregation results that have a correlation strength score with the query statement and a configured strength threshold to obtain multiple candidate document groups; use the configured coverage score function to calculate the coverage score of each candidate document group based on the page number distribution range and total text length of document segments within each candidate document group whose target correlation score is greater than the configured correlation threshold; use the ratio of the coverage score to the total text length of document segments within each candidate document group whose target correlation score is greater than the configured correlation threshold as the preferred order of each candidate document group; use a greedy algorithm to sequentially select the corresponding candidate documents in descending order of preference. Document fragments with a target association score greater than the configured association threshold in the group are populated into the configured answer template until the cumulative text length reaches the first query budget, resulting in the first search result. For document fragments in the document aggregation result, the highest-ranking document fragment is selected in descending order of target association score, and fragments already covered by the first search result are automatically skipped until the cumulative text length reaches the second query budget limit, resulting in the second search result. The first and second search results are then merged to obtain the target search result. Specifically, the first and second search results are deduplicated, sorted, and validated to obtain the target search result. When the first generation strategy is a fragment generation strategy, document fragments from the document aggregation result are selected according to the target association score. The document fragment with the highest ranking is selected in descending order of relevance score. A sequential selection method is used until the cumulative text length reaches the first query budget limit, yielding the first search result. Based on the document to which the document fragment belongs in the first search result, a small number of paragraphs adjacent to or belonging to the same chapter as the corresponding document fragment are selected from the document view of the document aggregation results. A coverage score function is used to evaluate and select key paragraphs until the cumulative text length reaches the second query budget limit, yielding the second search result. According to the context injection order in the search result generation strategy, the first and second search results are assembled in an orderly manner to form a coherent text sequence with core evidence fragments as the main component and contextual supplementation as a supplement, resulting in the target search result corresponding to the query statement.
[0041] In another embodiment of this application, after fusing the first and second search results, the method may further include: determining a comprehensive evidence score for the fused first and second search results based on the fused first and second search results, the query statement, and the query parsing identification results; specifically, counting the number of entities in the query parsing identification results included in the fused first and second search results; using the ratio of the counted number of entities to the total number of entities included in the query parsing identification results as the entity hit rate of the fused first and second search results; counting the number of different documents included in the fused first and second search results to obtain a diversity score for the fused first and second search results; and taking the arithmetic mean of the rearranged scores of the fused first and second search results. The average quality score of the first and second retrieval results after fusion is used as the basis for the comprehensive evidence score. Based on the configured weighting coefficients, the entity hit rate, diversity score, and average quality score of the first and second retrieval results are weighted and summed to obtain the comprehensive evidence score. If the comprehensive evidence score is less than the configured evidence score threshold, the query statement is semantically expanded to generate a new query statement, and the execution steps are returned: semantic parsing, intent recognition, and entity recognition are performed on the query statement to obtain the query parsing and recognition results. Specifically, based on a dictionary or a pre-trained semantic expansion model, multiple words in the query statement are expanded using synonyms and near-synonyms, and domain terminology mapping is performed to obtain a new query statement. Based on the new query statement, the execution step S220 is returned to obtain the first and second retrieval results after fusion with a comprehensive evidence score not less than the configured evidence score threshold.
[0042] Corresponding to the above method, this application embodiment also provides a RAG-based question-answering device, as shown in FIG3. The device includes: an acquisition unit 310, used to acquire a query statement input by a user; a parsing and recognition unit 320, used to perform semantic parsing, intent recognition, and entity recognition on the query statement to obtain query parsing and recognition results; a retrieval unit 330, used to use a hybrid retrieval strategy to retrieve multiple candidate retrieval result sets associated with the query statement from a configured retrieval database, and to calculate the association score between the candidate retrieval results and the query statement in different candidate retrieval result sets; wherein, each candidate retrieval result set also contains the document to which the corresponding candidate retrieval result belongs; an aggregation unit 340, used to aggregate multiple candidate retrieval results according to the document to which different candidate retrieval results belong, to obtain document aggregation results; a determination unit 350, used to determine a retrieval result generation strategy based on the query parsing and recognition results; and a generation unit 360, used to adaptively select document aggregation results based on the configured query budget and retrieval result generation strategy to generate the target retrieval result corresponding to the query statement.
[0043] The functions of each functional unit in the RAG-based question-answering device provided in the above embodiments of this application can be implemented through the above methods and steps. Therefore, the specific working process and beneficial effects of each unit in the RAG-based question-answering device provided in the embodiments of this application will not be repeated here.
[0044] This application embodiment also provides an electronic device, as shown in FIG4, including a processor 410, a communication interface 420, a memory 430 and a communication bus 440, wherein the processor 410, the communication interface 420 and the memory 430 communicate with each other through the communication bus 440.
[0045] The memory 430 is used to store computer programs; the processor 410, when executing the program stored in the memory 430, performs the following steps: obtaining a query statement input by the user; performing semantic parsing, intent recognition, and entity recognition on the query statement to obtain query parsing and recognition results; employing a hybrid retrieval strategy to retrieve multiple candidate search result sets associated with the query statement from a configured retrieval database, and calculating the association score between the candidate search results and the query statement in different candidate search result sets; wherein each candidate search result set also contains the document to which the corresponding candidate search result belongs; aggregating multiple candidate search results according to the document to which different candidate search results belong to to obtain document aggregation results; determining a search result generation strategy based on the query parsing and recognition results; and adaptively selecting document aggregation results based on the configured query budget and search result generation strategy to generate the target search result corresponding to the query statement.
[0046] The communication bus mentioned above can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0047] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0048] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0049] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0050] Since the implementation methods and beneficial effects of the various devices in the above embodiments of the electronic device can be achieved by referring to the steps in the embodiments shown in Figure 2, the specific working process and beneficial effects of the electronic device provided in this application embodiment will not be repeated here.
[0051] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores instructions that, when executed on a computer, cause the computer to perform any of the RAG-based question-and-answer methods described in the above embodiments.
[0052] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the RAG-based question-and-answer methods described in the above embodiments.
[0053] Those skilled in the art will understand that the embodiments in this application can be provided as methods, systems, or computer program products. Therefore, the embodiments in this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the embodiments in this application can take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0054] This application describes embodiments of methods, apparatus (systems), and computer program products according to embodiments of this application with reference to flowchart illustrations and / or block diagrams. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in one or more blocks of the flowchart illustrations and / or one or more blocks of the block diagrams.
[0055] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means that implement the functions specified in one or more flowcharts and / or one or more block diagrams.
[0056] These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer-implemented process, such that the instructions, which execute on the computer or other programmable apparatus, provide steps for implementing the functions specified in one or more flowcharts and / or one or more block diagrams.
[0057] Although preferred embodiments have been described in this application, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of this application.
[0058] Obviously, those skilled in the art can make various modifications and variations to the embodiments of this application without departing from the spirit and scope of the embodiments of this application. Therefore, if these modifications and variations to the embodiments of this application fall within the scope of this application and its equivalents, then these modifications and variations are also intended to be included in the embodiments of this application.
Claims
1. A question-answering method based on RAG, characterized in that, The method includes: acquiring a query statement input by a user; performing semantic parsing, intent recognition, and entity recognition on the query statement to obtain query parsing and recognition results; employing a hybrid retrieval strategy to retrieve multiple candidate search result sets associated with the query statement from a configured retrieval database, and calculating the association scores between the candidate search results in different candidate search result sets and the query statement; wherein each candidate search result set also contains the document to which the corresponding candidate search result belongs; aggregating multiple candidate search results according to the document to which different candidate search results belong to to obtain document aggregation results; determining a search result generation strategy based on the query parsing and recognition results; and adaptively selecting the document aggregation results according to the configured query budget and the search result generation strategy to generate the target search result corresponding to the query statement.
2. The method as described in claim 1, characterized in that, The retrieval database includes a vector retrieval database and a keyword retrieval database; the vector retrieval database contains fragment vectors of document segments from different documents; each document segment corresponds to a fragment identifier; the keyword retrieval database contains fragment identifiers of different document segments and multiple fragment keywords from the corresponding document segments.
3. The method as described in claim 2, characterized in that, A hybrid retrieval strategy is employed to retrieve multiple candidate search result sets associated with the query statement from a configured retrieval database. This includes: converting the query statement into a query vector; retrieving multiple fragment vectors from the vector retrieval database whose first similarity to the query vector is greater than a configured first similarity threshold; using the fragment identifiers of the retrieved fragment vectors, the documents to which the corresponding fragment vectors belong, and the first similarity between the corresponding fragment vectors and the query vector as different first candidate search result sets; splitting the query statement into multiple keywords; retrieving multiple document fragments containing multiple keywords from a configured keyword retrieval database, and calculating the second similarity between each document fragment and the query statement; using the fragment identifiers of the multiple document fragments containing multiple keywords, the documents to which the corresponding document fragments belong, and the corresponding second similarity as different second candidate search result sets; and fusing the different first candidate search result sets and the different second candidate search result sets to obtain multiple candidate search result sets.
4. The method as described in claim 3, characterized in that, Calculating the association score between candidate search results in different candidate search result sets and the query statement includes: normalizing the first similarity in different first candidate search result sets and the second similarity in different second candidate search result sets to obtain multiple normalized first similarities and multiple normalized second similarities; if different first candidate search result sets and second candidate search result sets contain the same segment identifier, then the normalized first similarity and normalized second similarity corresponding to the segment identifier are weighted and fused to obtain the association score between the document segment corresponding to the segment identifier and the query statement; if any segment identifier is not contained in different first candidate search result sets and second candidate search result sets simultaneously, then the normalized first similarity or normalized second similarity corresponding to the corresponding segment identifier is used as the association score between the document segment corresponding to the segment identifier and the query statement.
5. The method as described in claim 1, characterized in that, The search result generation strategy includes a first generation strategy and a second generation strategy; the query parsing and identification results include query intent category and entity identification results; the entity identification results include entity and entity type. Based on the query parsing and identification results, a retrieval result generation strategy is determined, including: counting the number of entities in the entity identification results; matching the target query complexity level corresponding to the query intent category, the number of entities, and the entity type according to a configured lookup table of different query intent categories, different number of entities, different entity types, and different query complexity levels; matching the target retrieval result generation strategy corresponding to the target query complexity level from a configured lookup table of different query complexity levels and different retrieval result generation strategies; using the target retrieval result generation strategy as the first generation strategy; and using other retrieval result generation strategies besides the target retrieval result generation strategy as the second generation strategy.
6. The method as described in claim 5, characterized in that, Based on the configured query budget and the retrieval result generation strategy, the document aggregation results are adaptively selected to generate the target retrieval result corresponding to the query statement, including: adaptively generating a first query budget corresponding to the first generation strategy and a second query budget corresponding to the second generation strategy based on the query budget and the configured budget allocation strategy; extracting a first retrieval result and a second retrieval result from the document aggregation results based on the first query budget and the second query budget respectively; and fusing the first retrieval result and the second retrieval result to obtain the target retrieval result.
7. The method as described in claim 6, characterized in that, After fusing the first search result and the second search result, the method further includes: determining the comprehensive evidence score of the fused first search result and the second search result based on the fused first search result and the second search result, the query statement, and the query parsing and identification result; if the comprehensive evidence score is less than the configured evidence score threshold, then semantically expanding the query statement to generate a new query statement, and returning to the execution step: performing semantic parsing, intent recognition, and entity recognition on the query statement to obtain the query parsing and identification result.
8. A question-answering device based on RAG, characterized in that, The apparatus includes: an acquisition unit for acquiring a query statement input by a user; a parsing and recognition unit for performing semantic parsing, intent recognition, and entity recognition on the query statement to obtain a query parsing and recognition result; a retrieval unit for employing a hybrid retrieval strategy to retrieve multiple candidate retrieval result sets associated with the query statement from a configured retrieval database, and calculating the association score between the candidate retrieval results in different candidate retrieval result sets and the query statement; wherein each candidate retrieval result set also includes the document to which the corresponding candidate retrieval result belongs; an aggregation unit for aggregating multiple candidate retrieval results according to the document to which different candidate retrieval results belong, to obtain a document aggregation result; a determination unit for determining a retrieval result generation strategy based on the query parsing and recognition result; and a generation unit for adaptively selecting the document aggregation result based on a configured query budget and the retrieval result generation strategy to generate the target retrieval result corresponding to the query statement.
9. An electronic device, characterized in that, The electronic device includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; the memory is used to store computer programs; and the processor, when executing the program stored in the memory, implements the method described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the method described in any one of claims 1-7.