A rag question answering optimization method and system based on fusion retrieval
By performing keyword and semantic vector retrieval in parallel, combined with multi-dimensional quality assessment and adaptive fusion ranking, the problem of low answer quality caused by a single retrieval strategy in the RAG system is solved, generating high-quality answers that match user intent, and improving the input context quality and answer accuracy of the large language model.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- JIANGSU RED NET TECH CO LTD
- Filing Date
- 2025-10-23
- Publication Date
- 2026-06-30
AI Technical Summary
Existing RAG systems rely on a single search strategy, which makes it difficult to meet the diverse query needs of users, resulting in low-quality search results. Furthermore, the fixed weight fusion method cannot be dynamically adjusted, leading to incorrect or one-sided answers.
Parallel keyword retrieval and semantic vector retrieval are employed, combined with multi-dimensional quality assessment and adaptive fusion ranking. The quality of text units is evaluated through semantic similarity, timeliness, diversity, and source authority, and the fusion weights are dynamically adjusted to generate structured prompt information for input into the large language model.
It improves the breadth and quality of search results, generates high-quality, high-value answers that are highly matched with the user's query intent, ensures the accuracy and reliability of the answers, reduces information redundancy, and improves the usability and professionalism of the answers.
Smart Images

Figure CN121350210B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large model knowledge question answering technology, and in particular to a RAG question answering optimization method and system based on fusion retrieval. Background Technology
[0002] With the rapid development of artificial intelligence technology, RAG (Retrieval-Augmented Generation) technology has been widely used in various scenarios such as question answering systems, content generation, education, and law. This technology enhances the generation capabilities of large language models by retrieving external knowledge bases.
[0003] Currently, most existing RAG systems rely on a single retrieval strategy, which often fails to fully meet the diverse query needs of users. Furthermore, the ranking of search results is usually based solely on similarity scores, lacking a multi-dimensional evaluation of text units. This results in returned text units that, while relevant, are often of low quality, leading to incorrect or one-sided answers. In addition, when merging multiple search results, fixed weights or simple weighted fusion methods are typically used, preventing the weight coefficients from dynamically adjusting according to the user's query intent, thus causing the ranking results to mismatch with the user's actual needs. Summary of the Invention
[0004] To address the problems of existing RAG systems, such as limited retrieval methods, lack of multi-dimensional quality assessment, and non-adaptive fusion ranking, this invention proposes a RAG question-answering optimization method and system based on fusion retrieval. The aim is to improve the quality of the retrieval context, provide more accurate, relevant, and structured information input for large language models, and thus generate high-quality and reliable answers.
[0005] The present invention achieves the above objectives through the following technical solutions:
[0006] A RAG question-answering optimization method based on fusion retrieval includes:
[0007] Obtain the user query, and perform keyword search and semantic vector search in parallel to obtain the keyword search result list and the semantic vector search result list, respectively.
[0008] Based on multi-dimensional quality assessment, the quality score of each text unit in the keyword retrieval result list and the semantic vector retrieval result list is calculated respectively, and text units with quality scores lower than the preset quality threshold are filtered out; the multi-dimensional quality assessment is based on a comprehensive evaluation of semantic similarity, timeliness, diversity and source authority;
[0009] A quality-weighted inverse ranking fusion algorithm is used to adaptively merge and sort all text units in the filtered keyword search results list and semantic vector search results list to generate a fused search list; wherein, the fusion weight coefficients of keyword search and semantic vector search are dynamically adjusted according to the identified user query intent type;
[0010] For each text unit in the fusion search list, contextual content enhancement is performed based on the length of each text unit and the document format to which it belongs, generating an enhanced text block list;
[0011] Merge enhanced text blocks from the same document in the enhanced text block list to generate an enhanced context block list;
[0012] Based on the enhanced context block list and user query, construct structured prompt information;
[0013] The structured prompts are input into a large language model to generate and output the final answer.
[0014] As a preferred embodiment of the present invention, the keyword retrieval is based on matching and retrieving metadata of document name, worksheet name, and document title; the semantic vector retrieval is based on matching and retrieving semantic vectors of user queries.
[0015] As a preferred embodiment of the present invention, the step of calculating the quality score of each text unit in the keyword retrieval result list and the semantic vector retrieval result list based on multi-dimensional quality assessment includes:
[0016] For any text unit in any search result list, perform the following calculation steps:
[0017] Calculate the cosine similarity between the semantic vector of the text unit and the semantic vector of the user query to obtain the semantic similarity score. ;
[0018] Calculate the timeliness score of this text unit. The calculation formula is: In the formula, As a timeliness adjustment factor; The current time; This refers to the publication time of the text unit;
[0019] Calculate the cosine similarity between the semantic vector of the given text unit and the average semantic vector of the evaluated set of text units. To obtain a diversity score The calculation formula is: The evaluated text unit set consists of text units that belong to the same search result list as the text unit and have undergone multi-dimensional quality assessment before the text unit.
[0020] The source authority score of the text unit is calculated by querying a pre-defined list of authoritative sources. ;
[0021] Calculate the quality score of this text unit. The calculation formula is:
[0022] ;
[0023] In the formula, α is the similarity correlation factor; β is the timeliness correlation factor; γ is the diversity correlation factor; δ is the authority correlation factor; where, .
[0024] As a preferred embodiment of the present invention, the quality-weighted inverse sorting fusion algorithm adaptively merges and sorts all text units in the filtered keyword retrieval result list and semantic vector retrieval result list to generate a fused retrieval list, including:
[0025] Identify the type of intent in the user query; the intent type includes factual, conceptual, summary, or multi-hop inference.
[0026] Based on the identified intent type, query the preset weight configuration table to obtain the corresponding keyword retrieval fusion weight coefficient. Fusion weight coefficients with semantic vector retrieval ;
[0027] For all text units in the filtered keyword search results list and semantic vector search results list, calculate the final fusion score for each text unit using the following formula:
[0028] ;
[0029] In the formula, This is a list of keyword search results. This is a list of semantic vector retrieval results; The final fusion score for text unit i; The quality score of text unit i in the search results list j; Let be the fusion weight coefficient corresponding to the search result list j, where , k is the smoothing constant; The ranking of text unit i in the search results list j;
[0030] Based on the final fusion score of all text units, all text units are sorted from high to low to generate a fusion retrieval list.
[0031] As a preferred embodiment of the present invention, the identification of the intent type of the user query is achieved by analyzing the preset trigger words in the user query.
[0032] As a preferred embodiment of the present invention, the preset weight configuration table defines the fusion weight coefficients of keyword retrieval and semantic vector retrieval corresponding to different intent types; wherein, when the intent type is factual, the fusion weight coefficient of keyword retrieval is... The fusion weight coefficient is higher than that of semantic vector retrieval. When the intent type is conceptual, the fusion weight coefficient of semantic vector retrieval The fusion weight coefficient is higher than that of keyword retrieval. .
[0033] As a preferred embodiment of the present invention, the execution context enhancement includes:
[0034] If the length of a text unit is less than a preset length threshold, then extract the context content, including the text unit, from the document to which the text unit belongs.
[0035] If the text cell originates from an Excel document, the worksheet name, cell row and column structure, and data content of the text cell are parsed, and the parsing results are converted into Markdown text.
[0036] As a preferred embodiment of the present invention, the structured prompt information includes at least:
[0037] Core requirement understanding instructions are used to instruct the large language model to understand the core requirements of the user's problem;
[0038] Context placeholders are used to embed content from the list of enhanced context blocks;
[0039] The answer constraint instruction is used to instruct the large language model to explicitly state that it cannot answer the question based on the provided information when the question answer is not contained in the provided list of augmented context blocks;
[0040] Formatting instructions are used to instruct large language models to generate answers in point-by-point statements and to present them using code blocks or tables when the answers contain program code, command lines, or multi-parameter data.
[0041] A RAG question-answering optimization system based on fusion retrieval includes:
[0042] The parallel retrieval module is used to obtain user queries and perform keyword retrieval and semantic vector retrieval in parallel, respectively obtaining keyword retrieval result lists and semantic vector retrieval result lists;
[0043] The quality assessment and filtering module is used to calculate the quality score of each text unit in the keyword search results list and the semantic vector search results list based on multi-dimensional quality assessment, and filter out text units with quality scores lower than the preset quality threshold.
[0044] The fusion sorting module is used to adaptively fusion sort all text units in the filtered keyword search results list and semantic vector search results list using a quality-weighted inverse sorting fusion algorithm to generate a fusion search list.
[0045] The context enhancement module is used to enhance the context of each text unit in the fusion search list based on the length of each text unit and the document format to which it belongs, and to generate a list of enhanced text blocks.
[0046] The context merging module is used to merge enhanced text blocks from the same document in the enhanced text block list to generate an enhanced context block list;
[0047] The prompt message construction module is used to construct structured prompt messages based on the enhanced context block list and user queries;
[0048] The answer generation and output module is used to input structured prompts into the large language model, generate and output the final answer.
[0049] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of a RAG question-answering optimization method based on fusion retrieval.
[0050] The beneficial effects of this invention are as follows: By executing keyword retrieval and semantic vector retrieval in parallel, it fully utilizes the advantages of both retrieval methods, ensuring not only accurate matching of factual queries but also semantic understanding of conceptual and exploratory queries, fundamentally improving the breadth and quality of the candidate information pool. Simultaneously, the introduction of a multi-dimensional quality assessment system based on semantic similarity, timeliness, diversity, and source authority effectively identifies and filters out outdated, redundant, or low-authority text units, thereby eliminating contamination from low-quality text units. Furthermore, by adaptively adjusting the fusion weight coefficients based on the user's query intent and using a quality-weighted inverse ranking fusion algorithm to reorder all text units in the filtered search lists, the text units that ultimately enter the context are not only relevant but also of high quality, high value, and highly matched to the user's query intent, fundamentally guaranteeing the context quality of the input large language model. By expanding the context of short texts and parsing and converting the format of structured documents, the context information of the input large language model becomes more complete and structured. Merging text units from the same document further reduces information redundancy, helping large language models better understand the relationships between information and thus generate more accurate and reliable answers. By constructing structured prompts that explicitly indicate the core task, answer constraints, and output format of the large language model, it is possible to effectively guide the model to find answers within a given context and proactively declare when it cannot answer, avoiding fabrication. Simultaneously, formatting guidelines ensure the clarity of the answers, presenting them in a more professional format when involving code, command lines, or multi-parameter data, improving the usability and professionalism of the answers. Attached Figure Description
[0051] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort. Wherein:
[0052] Figure 1 A flowchart illustrating a RAG question-answering optimization method based on fusion retrieval, provided as an embodiment of this disclosure;
[0053] Figure 2 A flowchart illustrating the implementation of the quality-weighted reciprocal sorting fusion algorithm provided in this embodiment of the disclosure;
[0054] Figure 3 This is a schematic diagram of the modular structure of a RAG question-answering optimization system based on fusion retrieval, provided in an embodiment of this disclosure. Detailed Implementation
[0055] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. All other embodiments obtained by those skilled in the art based on the described embodiments of the present invention are within the scope of protection of the present invention.
[0056] Existing RAG systems often rely on a single retrieval strategy, failing to meet diverse user query needs. Furthermore, the ranking of search results is based solely on similarity scores, lacking multi-dimensional evaluation, resulting in low-quality returned text units and incorrect or one-sided answers. In addition, when merging multiple search results, fixed weights or simple weighted fusion methods are often used, and the weight coefficients cannot be dynamically adjusted according to the user's query intent, leading to a mismatch between the ranking results and the user's actual needs. To address these issues, this invention proposes a RAG question-answering optimization method and system based on fusion retrieval. By executing keyword retrieval and semantic vector retrieval in parallel, the advantages of both retrieval methods are fully utilized, fundamentally improving the breadth and quality of the candidate information pool. Simultaneously, a multi-dimensional quality evaluation system is introduced to filter out outdated, redundant, or low-authority text units, eliminating pollution from low-quality text units. Furthermore, the fusion weight coefficients are dynamically adjusted based on the user's query intent, and a quality-weighted inverse ranking fusion algorithm is used to re-rank the filtered text units, ensuring that the text units entering the context are relevant, high-quality, and high-value, and highly matched to the user's query intent. By expanding the context of short texts and parsing and transforming the format of structured documents, the input context information becomes more complete and structured. Merging text units within the same document reduces information redundancy, helping the large language model understand the relationships between information and generate more accurate and reliable answers. Constructing structured prompts clarifies the core tasks, answer constraints, and output format of the large language model, guiding it to find answers within the given context and proactively declaring when it cannot answer.
[0057] like Figure 1 As shown, this is an embodiment of the present invention, which provides a RAG question-answering optimization method based on fusion retrieval, the method comprising:
[0058] S1: Obtain the user query, and perform keyword search and semantic vector search in parallel to obtain the keyword search result list and the semantic vector search result list, respectively.
[0059] Keyword retrieval is based on matching metadata such as document name, worksheet name, and document title. Semantic vector retrieval is based on matching semantic vectors of the user query.
[0060] Furthermore, parallel execution is achieved through asynchronous programming or multithreading techniques.
[0061] The specific implementation steps of keyword retrieval include:
[0062] Perform word segmentation on the user query and remove stop words based on a preset stop word list to obtain a keyword set. Among them, the preset stop word list can be customized according to the specific business field to reduce the index size and improve the retrieval efficiency.
[0063] Assume that the user query is "Sales data and analysis in North China in the first quarter of 2024". The preset stop word list should at least include: auxiliary words: de, di, de, le, zhe, guo; prepositions: zai, guanyu; conjunctions: he, yu; common modal particles: ma, ne; domain general words: nian, diqu, shuju.
[0064] Use a standard word segmenter to perform word segmentation on the user query, obtaining an initial word segmentation set ['guanyu', '2024', 'nian', 'di yi ji du', 'hua bei', 'di qu', 'de','sales', 'data', 'yu', 'analysis'].
[0065] Remove stop words based on the preset stop word list, and the obtained keyword set is: ['2024', 'di yi ji du', 'hua bei','sales', 'data', 'analysis'].
[0066] In the inverted index, find all text units that contain any one of the above keywords to form a candidate set.
[0067] Adopt a relevance ranking model to calculate the relevance score between each text unit in the candidate set and the user query. In some embodiments, the relevance ranking model adopts the TF-IDF model or the BM25 model.
[0068] Generate an ordered list of keyword retrieval results according to the relevance score.
[0069] The specific implementation steps of semantic vector retrieval include:
[0070] Adopt a pre-trained semantic model based on the Transformer architecture to convert the user query and text units in the knowledge base into high-dimensional semantic vectors respectively. Among them, the pre-trained semantic model can adopt BERT or a BERT variant.
[0071] Calculate the cosine similarity between the user query semantic vector and each text unit semantic vector in the knowledge base to obtain a cosine similarity score. Among them, the cosine similarity score is the calculated cosine similarity value.
[0072] Sort each text unit from high to low according to the cosine similarity score to generate an ordered list of semantic vector retrieval results.
[0073] In some embodiments, the Weaviate vector database is used. Each text unit and its semantic vector from the knowledge base are pre-imported and stored in Weaviate. During retrieval, the user query is sent to Weaviate, which automatically converts the user query into a semantic vector and performs a nearest neighbor search within Weaviate, finally returning a list of semantic vector retrieval results sorted by similarity.
[0074] This parallel design not only avoids the accumulation of latency caused by serial execution, but also makes full use of the advantages of the two retrieval technologies, taking into account both the accuracy and semantic relevance of the retrieval results, so as to improve retrieval efficiency and overall performance.
[0075] S2, based on multi-dimensional quality assessment, calculates the quality score of each text unit in the keyword search results list and the semantic vector search results list respectively, and filters out text units with quality scores below a preset quality threshold. The multi-dimensional quality assessment is based on a comprehensive evaluation of semantic similarity, timeliness, diversity, and source authority.
[0076] Furthermore, the preset quality threshold is obtained through statistical analysis on a dedicated validation set. Specifically, the quality scores of a large number of text units in the validation set are calculated and compared with the relevance levels of manually annotated text. A PR curve is plotted to set the preset quality threshold at a position that ensures high accuracy. In some embodiments, a recommended value for the preset quality threshold is 0.6.
[0077] Based on multi-dimensional quality assessment, the quality score of each text unit in the keyword retrieval result list and the semantic vector retrieval result list is calculated separately. The specific implementation steps include:
[0078] For any text unit in any search result list, perform the following calculation steps:
[0079] Calculate the cosine similarity between the semantic vector of the text unit and the semantic vector of the user query to obtain the semantic similarity score. .
[0080] Furthermore, the formula for calculating cosine similarity is: ,in, The dot product of vectors A and B; Let A be the magnitude of vector A; Let B be the magnitude of vector B. Semantic similarity score. The higher the value, the better the semantic intent of the text unit matches the user's query.
[0081] Calculate the timeliness score of this text unit. The calculation formula is: In the formula, λ is the timeliness adjustment factor; The current time; This is the publication time of the text unit.
[0082] Furthermore, It can be flexibly configured according to specific business scenarios and information timeliness requirements. In some implementation cases, The value is determined by tuning on a validation set labeled with time-sensitive information.
[0083] Calculate the cosine similarity between the semantic vector of the given text unit and the average semantic vector of the evaluated set of text units. To obtain a diversity score The calculation formula is: The evaluated text unit set consists of text units that belong to the same search result list as the text unit and have undergone multi-dimensional quality assessment before the text unit.
[0084] Furthermore, diversity score The specific calculation steps are as follows: Calculate the average semantic vector of the evaluated set of text units; calculate the cosine similarity between the semantic vector of the text unit and the average semantic vector. ; Calculate diversity score .
[0085] This achieves adaptive redundancy removal in the search results list, improving the comprehensiveness and information content of the final generated answer.
[0086] The source authority score of the text unit is calculated by querying a pre-defined list of authoritative sources. .
[0087] Furthermore, the pre-defined list of authoritative sources is a dynamically maintainable dataset, which pre-records source identifiers that are generally recognized as having high credibility in their respective fields, the corresponding authority level of the source identifier, and the source authority score. Among them, source identifiers include, but are not limited to, official institutions, core journals, and well-known website domains.
[0088] The specific steps for calculating the source authority score include: extracting the source identifier from the metadata of the current text unit; performing a query and matching based on the extracted source identifier in a preset list of authoritative sources; and assigning the text unit the source authority score corresponding to the source identifier if a match is successful. If a match fails, a preset default authority score is assigned to the text unit. This includes the source authority score. It can be statically configured or dynamically adjusted according to specific business needs and domain knowledge. The default authority score is usually lower than the score of any registered source in the default list of authoritative sources.
[0089] This ensures that the final generated answers are more likely to rely on authoritative and reliable data sources, thereby improving the overall credibility of the output answers.
[0090] Calculate the quality score of this text unit. The calculation formula is:
[0091] ;
[0092] In the formula, α is the similarity correlation factor; β is the timeliness correlation factor; γ is the diversity correlation factor; δ is the authority correlation factor; where, .
[0093] Furthermore, the similarity correlation factor α, timeliness correlation factor β, diversity correlation factor γ, and authority correlation factor δ are all configurable parameters that can be set according to specific application scenarios and business objectives. Specific setting methods include, but are not limited to, pre-configured settings based on domain knowledge, or, determining the optimal weight combination by performing parameter search on a labeled validation set. The parameter search employs grid search or Bayesian optimization.
[0094] Introducing a multi-dimensional quality assessment system based on semantic similarity, timeliness, diversity, and source authority can effectively identify and filter out outdated, redundant, or low-authority text units, thereby eliminating the pollution of low-quality text units.
[0095] After performing multi-dimensional quality assessment and filtering on all text units in the keyword search results list and the semantic vector search results list, two purified high-quality search result lists are obtained.
[0096] S3 employs a quality-weighted inverse ranking fusion algorithm to adaptively merge and sort all text units in the filtered keyword search results list and semantic vector search results list, generating a fused search list. The fusion weight coefficients for keyword search and semantic vector search are dynamically adjusted based on the identified user query intent type.
[0097] like Figure 2 The diagram illustrates the specific implementation steps of the quality-weighted reciprocal ranking fusion algorithm provided in this embodiment of the disclosure, including:
[0098] S31, Identify the type of intent in the user's query. The intent type includes factual, conceptual, summary, or multi-hop inference.
[0099] The identification of the intent type of a user query is achieved by analyzing preset trigger words in the user query.
[0100] Furthermore, preset trigger words are stored in a preset trigger word-intent mapping table. This mapping table records the trigger words and their corresponding intent types, and exists in the form of a configuration file or database table, facilitating dynamic maintenance based on specific application scenarios and domain knowledge. The definitions and typical trigger words for various intent types are as follows: Factual intent types are used to query objective, verifiable facts about a specific entity, with corresponding trigger words such as "definition," "capital is," "established in," "inventor is," and "population is." Conceptual intent types are used to query the explanation, principle, or mechanism of a concept, with corresponding trigger words such as "what is," "what does it mean," "how it works," "the principle of," and "difference from." Summary intent types are used to request a general, summarizing description of a topic, with corresponding trigger words such as "introduction," "summary," "overview," "discuss," and "advantages and disadvantages of." Multi-hop reasoning intent types are used for complex questions that require associating multiple information fragments and performing logical reasoning to answer, with corresponding trigger words such as "why," "how it leads to," "the relationship between..." and "if..." and "the impact of...".
[0101] The specific steps for identifying the type of intent in a user query include:
[0102] Regular expressions are used to match user queries with preset trigger words in the trigger word-intent mapping table to find all matched trigger words and their corresponding intent types.
[0103] If a user's query matches a single trigger word, the intent type corresponding to that trigger word is directly obtained and used as the intent type for the user's query. If the user's query matches multiple trigger words simultaneously, a decision is made according to preset priority rules. These priority rules can be customized based on business logic. For example, static priorities can be set for different intent types, or trigger words located at the beginning of the query or in the position of a core verb can have higher weight.
[0104] Suppose a user query is: "Please summarize the definition and development history of artificial intelligence." This query contains the trigger words "summarize" and "definition." "Summary" maps to a summary intent, while "definition" maps to a concept intent. Since the user query matches multiple trigger words simultaneously, a priority rule can be used. If we simply set the priority of summary intents higher than concept intents, the final intent type of this user query is determined to be summary.
[0105] Suppose a user queries "Why do rising interest rates usually lead to falling precious metal prices?", the user query matches the core trigger word "why", which uniquely corresponds to a multi-hop inference intent, and the user query intent type is ultimately determined to be multi-hop inference.
[0106] To ensure system robustness, for user queries that fail to match any preset trigger words, the user query intent type is set to the default intent type. The default intent type should prioritize high recall. In some embodiments, the default intent type is set to summary.
[0107] S32, based on the intent type, query the preset weight configuration table to obtain the corresponding keyword retrieval fusion weight coefficient. Fusion weight coefficients with semantic vector retrieval .
[0108] The preset weight configuration table defines the fusion weight coefficients of keyword retrieval and semantic vector retrieval for different intent types; among them, when the intent type is factual, the fusion weight coefficient of keyword retrieval is... The fusion weight coefficient is higher than that of semantic vector retrieval. When the intent type is conceptual, the fusion weight coefficient of semantic vector retrieval The fusion weight coefficient is higher than that of keyword retrieval. .
[0109] S33. For all text units in the filtered keyword search results list and semantic vector search results list, calculate the final fusion score for each text unit. The calculation formula is as follows:
[0110] ;
[0111] In the formula, This is a list of keyword search results. This is a list of semantic vector retrieval results; The final fusion score for text unit i; The quality score of text unit i in the search results list j; Let be the fusion weight coefficient corresponding to the search result list j, where , k is the smoothing constant; The ranking of text unit i in the search results list j;
[0112] Suppose a text unit appears in both the keyword search results list and the semantic vector search results list. In the keyword search results list, its quality score is 0.8, ranking 2nd; while in the semantic vector search results list, its quality score is 0.9, ranking 1st. The smoothing constant is set to 1. The user's query intent type is determined to be conceptual. Based on this intent type, a preset weight configuration table is consulted, obtaining a fusion weight coefficient of 0.7 for semantic vector search and 0.3 for keyword search. Based on this information, the final fusion score of this text unit is calculated. .
[0113] S34. Based on the final fusion score of all text units, sort all text units from high to low and generate a fusion retrieval list.
[0114] By combining the user's query intent, the fusion weight coefficients are adaptively adjusted, and a quality-weighted inverse ranking fusion algorithm is used to reorder each text unit in all filtered search lists. This ensures that the text units that finally enter the context are not only relevant, but also of high quality, high value, and highly matched with the user's query intent, thus fundamentally guaranteeing the context quality of the input large language model.
[0115] S4. For each text unit in the fusion search list, perform contextual content enhancement based on the length of each text unit and the document format to which it belongs, and generate an enhanced text block list.
[0116] Enhancements to the execution context include:
[0117] If the length of a text unit is less than a preset length threshold, then the context content including the text unit is extracted from the document to which the text unit belongs.
[0118] Furthermore, the preset length threshold can be determined through empirical analysis or specific business requirements. In a preferred embodiment, the preset length threshold is recommended to be set to 8000 characters. The expanded context content serves as an enhanced text block.
[0119] The specific extraction logic can be optimized according to the document format to ensure that the enhanced content maintains semantic integrity.
[0120] For paragraph text, extract the complete paragraph containing the text unit. If the length of the paragraph text is still less than the preset length threshold, then further extract 1 to 2 paragraphs that are adjacent to the paragraph text.
[0121] For a slide, extract all content from the entire slide page containing the text cell, including the title, main points, and notes.
[0122] Suppose a text unit shows that sales in the first quarter of 2025 increased by 43% year-on-year. Since the length of this text unit is much less than 8,000 characters, the content of the entire paragraph containing this text unit is extracted from the document to which the text unit belongs, and used as the enhanced content.
[0123] If the text cell originates from an Excel document, the worksheet name, cell row and column structure, and data content of the text cell are parsed, and the parsing results are converted into Markdown text.
[0124] Assuming the text cell is "4300", the source of the text cell is identified as an Excel file. The worksheet name, row and column structure, and surrounding data of the cell are parsed out, generating the following Markdown-formatted enhanced text block:
[0125] Worksheet: Sales Summary for 2025
[0126] Product line first quarter sales (RMB 10,000) Year-on-year growth rate
[0127] Product A 4300 43%
[0128] Product B 1000 10%
[0129] Through the above conversion, users can clearly understand that "4300" represents the sales revenue of product A in the first quarter of the 2025 sales summary Excel file without opening the Excel file, and can also make horizontal comparisons between products.
[0130] For text units that do not meet the above conditions, i.e., text that is long enough and unstructured, the original content of the text unit is directly used as an enhanced text block.
[0131] After performing contextual content enhancement, the outputs corresponding to all text units are aggregated in the order of the fused search list to generate an enhanced text block list. Therefore, the enhanced text block list is a new text sequence that has undergone content enhancement, corresponding to the order of the fused search list. Each enhanced text block in this list is an enhanced version of a text unit in the fused search list, and the enhanced text block is no longer an isolated text fragment, but a self-explanatory semantic unit carrying rich contextual information.
[0132] This compensates for the shortcomings of insufficient information in short text units and poor readability of structured data, ensuring that the contextual information input into the large language model is complete and structured.
[0133] S5 merges enhanced text blocks from the same document in the enhanced text block list to generate an enhanced context block list.
[0134] Furthermore, to avoid information redundancy and logical confusion arising from different enhanced text blocks within the same document in the final context, this step merges enhanced text blocks originating from the same document. This merging process is not a simple concatenation, but an intelligent processing flow designed to eliminate redundancy and ensure semantic coherence. Specific steps include:
[0135] Identify and remove duplicate text segments between different enhanced text blocks. In some embodiments, a combination of hash-based exact matching and semantic vector-based fuzzy matching is used to identify and remove duplicate text segments between different initial enhanced text blocks.
[0136] Based on the inherent logical order of the text fragments in the original document, all deredundant content is rearranged.
[0137] Suppose there are two enhanced text blocks, P and Q, both from the same document, "Company Product Market Analysis for Q1 2025.docx".
[0138] Enhanced text block P originates from page 25 of the document, and its content is as follows: Our product A has maintained strong competitiveness in the market. According to the latest data, product A achieved a market share of 89% in the first quarter of 2025, an increase of 43 percentage points compared to the same period last year. This is mainly due to its superior performance and successful brand marketing campaigns.
[0139] The enhanced text block Q originates from page 78 of the document, and its content is as follows: In competitive analysis, we need to continuously monitor the dynamics of our competitors. According to the latest data, Product A achieved a market share of 89% in the first quarter of 2025, an increase of 43 percentage points compared to the same period last year. Meanwhile, Product B's performance also exceeded expectations.
[0140] Through merging, an enhanced context block is generated, the specific content of which is:
[0141] Our product A has maintained strong competitiveness in the market. According to the latest data, product A achieved a market share of 89% in the first quarter of 2025, an increase of 43 percentage points compared to the same period last year. This is mainly due to its superior performance and successful brand marketing campaigns.
[0142] In competitive analysis, we need to continuously monitor our competitors' activities. Meanwhile, Product B's performance has exceeded expectations.
[0143] After document-level content merging is completed, an enhanced context block list is generated. The order of this list follows the principle of retrieval relevance inheritance; that is, the position of each merged enhanced context block in the enhanced context block list is not randomly assigned, but determined by the relevance ranking of its source enhanced text blocks in the enhanced text block list. For example, if an enhanced text block of document A ranks first in the enhanced text block list, then the corresponding enhanced context block of document A will also rank first in the enhanced context block list.
[0144] Assume the initial order of the enhanced text block list and the document sources are as follows:
[0145] Ranked #1: Enhanced text block D1 (from document A)
[0146] Ranked #2: Enhanced text block E1 (from document B)
[0147] Ranked 3rd: Enhanced text block D2 (from document A)
[0148] After merging, the order of the generated list of enhanced context blocks is as follows:
[0149] Ranked #1: Enhanced context block of document A (generated by merging, deredundantizing, and rearranging D1 and D2)
[0150] Ranked #2: Enhanced context block of document B (generated by E1)
[0151] In this way, by merging enhanced text blocks from the same document, information redundancy is further reduced, and previously fragmented information is reorganized into more complete semantic units. This helps large language models better understand the inherent connections and overall context between information, thus laying a solid foundation for generating accurate and coherent answers.
[0152] S6 builds structured prompts based on an enhanced list of context blocks and user queries.
[0153] Structured prompts should include at least the core requirement understanding instructions, context placeholders, answer constraint instructions, and format specification instructions.
[0154] The core requirement understanding instruction is used to instruct the large language model to understand the core requirements of the user's problem.
[0155] Context placeholders are used to embed content from the list of enhanced context blocks.
[0156] The answer constraint instruction is used to instruct the large language model to explicitly state that it cannot answer the question based on the provided information when the question answer is not included in the provided list of enhanced context blocks.
[0157] Formatting instructions are used to instruct large language models to generate answers in point-by-point statements and to present them using code blocks or tables when the answers contain program code, command lines, or multi-parameter data.
[0158] Furthermore, by specifying formats such as point-by-point statements, code blocks, and tables, the final generated answer is ensured to be clear, professional, and easy to read.
[0159] By constructing structured prompts that clearly indicate the core tasks, answer constraints, and output formats of the large language model, it is possible to effectively guide the model to find answers within a given context and proactively declare when it cannot answer, thus avoiding fabrication. Simultaneously, formatting guidelines ensure the clarity of the answers and present them in a more professional format when involving code, command lines, or multi-parameter data, improving the usability and professionalism of the answers.
[0160] S7 inputs structured prompts into the large language model, generates and outputs the final answer.
[0161] Furthermore, the large language model can select from multiple models based on specific application scenarios and can be deployed on local servers or cloud service platforms. In practice, structured prompts are used as the core content, encapsulated according to the request message format specified by the large language model service provider, and the API generation parameters are set according to the quality and style requirements of the generated answers. These API generation parameters include at least temperature, maximum generation length, and kernel sampling parameters.
[0162] In some embodiments, the DeepSeek-r1 32b model is selected, which is deployed on a cloud service platform. To generate factually accurate and logically rigorous answers, the creativity parameter `temperature` is set to 0.2, and the `max_tokens` parameter is set to 1024 to ensure sufficient answer length. The constructed structured hint information is sent to the API endpoint corresponding to the DeepSeek model via an HTTPS POST request. After successfully receiving the response, the generated answer text is parsed from the returned JSON data.
[0163] like Figure 3 As shown, another embodiment of the present invention provides a RAG question-answering optimization system based on fusion retrieval. This system includes a parallel retrieval module, a quality assessment and filtering module, a fusion ranking module, a context enhancement module, a context merging module, a prompt information construction module, and an answer generation and output module.
[0164] The parallel retrieval module is used to obtain user queries and perform keyword retrieval and semantic vector retrieval in parallel, respectively obtaining lists of keyword retrieval results and lists of semantic vector retrieval results.
[0165] The quality assessment and filtering module is used to calculate the quality score of each text unit in the keyword search results list and the semantic vector search results list based on multi-dimensional quality assessment, and to filter out text units with quality scores lower than the preset quality threshold.
[0166] The fusion sorting module is used to adaptively merge and sort all text units in the filtered keyword search results list and semantic vector search results list using a quality-weighted inverse sorting fusion algorithm, and generate a fusion search list.
[0167] The context enhancement module is used to enhance the context of each text unit in the fusion search list based on its own length and the document format to generate an enhanced text block list.
[0168] The context merging module is used to merge enhanced text blocks from the same document in the enhanced text block list to generate an enhanced context block list.
[0169] The prompt message construction module is used to build structured prompt messages based on the enhanced context block list and user queries.
[0170] The answer generation and output module is used to input structured prompts into the large language model, generate and output the final answer.
[0171] This embodiment also provides a computer-readable storage medium storing a computer program thereon. When the computer program is executed by a processor, it implements the steps of a RAG question-answering optimization method based on fusion retrieval. The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Read Only Memory (PROM), Read Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0172] In summary, this invention proposes a RAG question-answering optimization method and system based on fusion retrieval. Through a series of collaborative technologies, including parallel retrieval and multi-dimensional quality assessment, quality-weighted adaptive fusion ranking, and document-format-based contextual content enhancement, it achieves a comprehensive improvement in the quality of the retrieval context, providing more accurate, relevant, and structured information input for the large language model, ultimately generating high-quality and reliable answers. Specifically, by executing keyword retrieval and semantic vector retrieval in parallel, it fully leverages the advantages of both retrieval methods, ensuring not only accurate matching of factual queries but also semantic understanding of conceptual and exploratory queries, fundamentally improving the breadth and quality of the candidate information pool. Simultaneously, the introduction of a multi-dimensional quality assessment system based on semantic similarity, timeliness, diversity, and source authority effectively identifies and filters out outdated, redundant, or low-authority text units, thereby eliminating contamination from low-quality text units. Furthermore, by adaptively adjusting the fusion weight coefficients based on the user's query intent, and using a quality-weighted inverse ranking fusion algorithm to reorder all text units in the filtered search lists, the text units entering the final context are not only relevant but also high-quality, high-value, and highly matched to the user's query intent, fundamentally ensuring the context quality of the input large language model. By expanding the context of short texts and parsing and converting the format of structured documents, the context information input to the large language model becomes more complete and structured. Merging text units from the same document further reduces information redundancy, helping the large language model better understand the relationships between information, thereby generating more accurate and reliable answers. By constructing structured prompts that clearly indicate the core task, answer constraints, and output format of the large language model, it effectively guides the large language model to find answers in a given context and proactively declares when it cannot answer, avoiding fabrication. Simultaneously, format specification instructions ensure the clarity of the answers, presenting them in a more professional format when involving code, command lines, or multi-parameter data, improving the usability and professionalism of the answers.
[0173] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any person skilled in the art can easily conceive of various variations or substitutions within the technical scope disclosed in this application, and these should all be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A RAG question-answering optimization method based on fusion retrieval, characterized in that, include: Obtain the user query, and perform keyword search and semantic vector search in parallel to obtain the keyword search result list and the semantic vector search result list, respectively. Based on multi-dimensional quality assessment, the quality score of each text unit in the keyword retrieval result list and the semantic vector retrieval result list is calculated respectively, and text units with quality scores lower than the preset quality threshold are filtered out; the multi-dimensional quality assessment is based on a comprehensive evaluation of semantic similarity, timeliness, diversity and source authority; A quality-weighted inverse ranking fusion algorithm is used to adaptively merge and sort all text units in the filtered keyword search results list and semantic vector search results list to generate a fused search list; wherein, the fusion weight coefficients of keyword search and semantic vector search are dynamically adjusted according to the identified user query intent type; The quality-weighted inverse sorting fusion algorithm adaptively merges and sorts all text units in the filtered keyword search result list and semantic vector search result list to generate a fused search list including: Identify the type of intent in the user query; the intent type includes factual, conceptual, summary, or multi-hop inference. Based on the identified intent type, query the preset weight configuration table to obtain the corresponding keyword retrieval fusion weight coefficient. Fusion weight coefficients with semantic vector retrieval ; For all text units in the filtered keyword search results list and semantic vector search results list, calculate the final fusion score for each text unit using the following formula: ; In the formula, This is a list of keyword search results. This is a list of semantic vector retrieval results; The final fusion score for text unit i; The quality score of text unit i in the search results list j; Let be the fusion weight coefficient corresponding to the search result list j, where , k is the smoothing constant; The ranking of text unit i in the search results list j; Based on the final fusion score of all text units, all text units are sorted from high to low to generate a fusion retrieval list; For each text unit in the fusion search list, contextual content enhancement is performed based on the length of each text unit and the document format to which it belongs, generating an enhanced text block list; Merge enhanced text blocks from the same document in the enhanced text block list to generate an enhanced context block list; Based on the enhanced context block list and user query, construct structured prompt information; The structured prompts are input into a large language model to generate and output the final answer.
2. The RAG question-answering optimization method based on fusion retrieval according to claim 1, characterized in that, The keyword retrieval is based on matching metadata of document name, worksheet name, and document title; the semantic vector retrieval is based on matching semantic vectors of user queries.
3. The RAG question-answering optimization method based on fusion retrieval according to claim 1, characterized in that, The multi-dimensional quality assessment, which calculates the quality score of each text unit in the keyword retrieval result list and the semantic vector retrieval result list respectively, includes: For any text unit in any search result list, perform the following calculation steps: Calculate the cosine similarity between the semantic vector of the text unit and the semantic vector of the user query to obtain the semantic similarity score. ; Calculate the timeliness score of this text unit. The calculation formula is: ; In the formula, As a timeliness adjustment factor; The current time; This refers to the publication time of the text unit; Calculate the cosine similarity between the semantic vector of the given text unit and the average semantic vector of the evaluated set of text units. To obtain a diversity score The calculation formula is: ; The evaluated text unit set consists of text units that belong to the same search result list as the text unit and have undergone multi-dimensional quality evaluation before the text unit. The source authority score of the text unit is calculated by querying a pre-defined list of authoritative sources. ; Calculate the quality score of this text unit. The calculation formula is: ; In the formula, α is the similarity correlation factor; β is the timeliness correlation factor; γ is the diversity correlation factor; δ is the authority correlation factor; where, .
4. The RAG question-answering optimization method based on fusion retrieval according to claim 1, characterized in that, The identification of the intent type of a user query is achieved by analyzing preset trigger words in the user query.
5. The RAG question-answering optimization method based on fusion retrieval according to claim 1, characterized in that, The preset weight configuration table defines the fusion weight coefficients of keyword retrieval and semantic vector retrieval for different intent types; among them, when the intent type is factual, the fusion weight coefficient of keyword retrieval is... The fusion weight coefficient is higher than that of semantic vector retrieval. When the intent type is conceptual, the fusion weight coefficient of semantic vector retrieval The fusion weight coefficient is higher than that of keyword retrieval. .
6. The RAG question-answering optimization method based on fusion retrieval according to claim 1, characterized in that, The enhanced execution context content includes: If the length of a text unit is less than a preset length threshold, then extract the context content, including the text unit, from the document to which the text unit belongs. If the text cell originates from an Excel document, the worksheet name, cell row and column structure, and data content of the text cell are parsed, and the parsing results are converted into Markdown text.
7. The RAG question-answering optimization method based on fusion retrieval according to claim 1, characterized in that, The structured prompt information includes at least: Core requirement understanding instructions are used to instruct the large language model to understand the core requirements of the user's problem; Context placeholders are used to embed content from the list of enhanced context blocks; The answer constraint instruction is used to explicitly state that the large language model cannot answer the question based on the provided information when the question answer is not contained in the provided list of augmented context blocks; Formatting instructions are used to instruct large language models to generate answers in point-by-point statements and to present them using code blocks or tables when the answers contain program code, command lines, or multi-parameter data.
8. A RAG question-answering optimization system based on fusion retrieval, comprising the RAG question-answering optimization method based on fusion retrieval as described in any one of claims 1 to 7, characterized in that, include: The parallel retrieval module is used to obtain user queries and perform keyword retrieval and semantic vector retrieval in parallel, respectively obtaining keyword retrieval result lists and semantic vector retrieval result lists; The quality assessment and filtering module is used to calculate the quality score of each text unit in the keyword search results list and the semantic vector search results list based on multi-dimensional quality assessment, and filter out text units with quality scores lower than the preset quality threshold. The fusion sorting module is used to adaptively fusion sort all text units in the filtered keyword search results list and semantic vector search results list using a quality-weighted inverse sorting fusion algorithm to generate a fusion search list. The context enhancement module is used to enhance the context of each text unit in the fusion search list based on the length of each text unit and the document format to which it belongs, and to generate a list of enhanced text blocks. The context merging module is used to merge enhanced text blocks from the same document in the enhanced text block list to generate an enhanced context block list; The prompt message construction module is used to construct structured prompt messages based on the enhanced context block list and user queries; The answer generation and output module is used to input structured prompts into the large language model, generate and output the final answer.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the RAG question-answering optimization method based on fusion retrieval as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Knowledge base generation and retrieval method based on RAG technology and intelligent question answering system
CN120045653A
Low-altitude intelligent question and answer construction method and system based on dynamic parameters
CN120632055A