RAG question and answer optimization method and device

The RAG question-answering system, which combines intelligent text segmentation, FAQ extraction, and the MCP protocol with an efficient vector database, solves the problems of insufficient semantic segmentation accuracy, single retrieval mode, poor storage architecture scalability, and low module interoperability in existing technologies, and realizes an efficient, flexible, and low-cost enterprise-level knowledge base question-answering system.

CN121579629APending Publication Date: 2026-02-27SHANGHAI INSPUR CLOUD COMPUTING SERVICE CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202511659037.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-13
Publication Date
2026-02-27

AI Technical Summary

Technical Problem

Existing RAG question answering systems have shortcomings in semantic segmentation accuracy, retrieval mode diversity, storage architecture scalability, and system module interoperability, making it difficult to meet the high accuracy, high efficiency, low cost, and easy maintenance requirements of enterprise-level knowledge base question answering systems.

Method used

It adopts a combination of intelligent text segmentation, FAQ extraction, vectorized storage and MCP protocol. Through intelligent text segmentation and FAQ extraction driven by a large language model, combined with an efficient vector database and MCP protocol, it realizes multi-path hybrid retrieval and decoupled interaction, ensuring semantic integrity and retrieval recall, and supports flexible system expansion and component replacement.

Benefits of technology

It improves the accuracy and reliability of knowledge base question answering, reduces system operation and maintenance costs, enhances system scalability and maintainability, and adapts to knowledge base data needs of different scales.

✦ Generated by Eureka AI based on patent content.
Patent Text Reader

Abstract

The invention relates to the cross technical field of artificial intelligence and data retrieval, and particularly provides an RAG question and answer optimization method and device.Firstly, original knowledge documents of various formats and natural language query of a user are received on an input layer, then a knowledge base construction module and a knowledge retrieval module are arranged on a processing layer, and a knowledge retrieval module is arranged on the processing layer; the middleware layer is provided with an MCP Server module and a vector database, the MCP Server module is a standard interface agent, and the vector database is a distributed storage engine for efficient approximate nearest neighbor search and mixed retrieval; and finally, deploying an LLM generation module at an output layer for generating a final answer based on the retrieved enhanced context. Compared with the prior art, the method has the advantages that irrelevant or low-signal-to-noise-ratio knowledge contacted by a large language model (LLM) can be effectively reduced, and the accuracy, the reliability and the practicability of knowledge base questions and answers are comprehensively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of interdisciplinary technology of artificial intelligence and data retrieval, specifically providing a RAG question-answering optimization method and apparatus. Background Technology

[0002] Currently, large-scale language model (LLM) technology is developing rapidly. Knowledge-based question answering (KBQA) systems based on retrieval-augmented generation (RAG) have become a key technical approach to effectively alleviate the "hallucination" phenomenon of LLM and improve the accuracy and credibility of its answers by introducing external knowledge sources to assist LLM in generating answers.

[0003] However, existing traditional RAG (hereinafter referred to as "Naive RAG") systems still face many technical bottlenecks when achieving large-scale, high-precision applications, mainly in the following four aspects:

[0004] (1) Insufficient semantic segmentation accuracy. Naive RAG generally adopts a text segmentation (chunking) strategy based on a fixed length (e.g., 512 or 1024 tokens). This mechanical segmentation method is difficult to adapt to the structured features of complex texts such as technical documents and academic papers, and is very likely to lead to the destruction of semantic integrity.

[0005] Specifically, this manifests as: forcibly separating a complete description of a technical principle or a logically coherent argument, generating semantically incomplete fragments; or retaining a large amount of noise information without actual semantic meaning (such as Markdown markup language, redundant hyperlink text, etc.) within the fragments. These distorted text fragments, as the retrieval context, directly pollute the retrieval quality, leading to a decrease in the relevance of subsequent search results, and thus affecting the accuracy of the final generated answer.

[0006] (2) The retrieval mode is singular and the recall rate is limited. Most existing solutions rely solely on the similarity of embedding vectors for semantic retrieval, lacking the collaborative utilization of multimodal information in the knowledge base.

[0007] In particular, for structured Frequently Asked Questions (FAQs) content commonly found in knowledge bases, simple vector retrieval struggles to accurately match the precise correspondence between "question-answer" pairs. When faced with clear and specific user queries (e.g., "What is the warranty period for product A?"), existing systems cannot efficiently and directly find the standard answers already existing in the FAQ, resulting in low recall for such queries and failing to fully leverage the value of existing structured knowledge.

[0008] (3) Poor scalability and cost-effectiveness of storage architecture. Naive RAG systems typically use vector databases based on graph-structured approximate nearest neighbor search algorithms (such as HNSW) as the core storage solution. Although such algorithms have fast retrieval speed, they consume a lot of memory resources. When dealing with large-scale (e.g., petabyte-level) unstructured data at the enterprise level, the hardware cost is high and disk swapping is easily triggered due to insufficient memory, resulting in a sharp deterioration in retrieval performance.

[0009] Furthermore, many existing storage solutions do not support native hybrid search capabilities, meaning they cannot seamlessly integrate multiple search conditions such as full-text keywords, scalar filters, and vector similarity within a single query. To implement complex query logic, systems must additionally integrate multiple storage engines such as Elasticsearch, significantly increasing architectural complexity and operational costs.

[0010] (4) Low interoperability and maintainability between system modules. The interaction logic between LLM and external tools (such as retrieval and storage modules) mostly adopts a tightly coupled point-to-point customized development model, lacking a unified standardized interface protocol. When the underlying core components need to be replaced due to changes in requirements (for example, switching the closed-source LLM from Claude to GPT, or upgrading the vector database version), it is almost necessary to redevelop and test the entire integration link. The cost of technology iteration is high, and the system maintainability is poor.

[0011] The Model Context Protocol (MCP), as an emerging standard, has been adopted by mainstream LLM platforms such as DeepSeek, OpenAI, and Anthropic. It aims to standardize the interaction between LLMs and external tools and data sources, providing a potential direction for solving interoperability issues. However, there is currently no mature solution in the technology that deeply integrates the MCP protocol with high-performance, hybrid retrieval-supporting general-purpose vector databases. The failure of the two to work together to simultaneously leverage the "general interface" advantage of MCP and the efficient retrieval capabilities of vector databases severely restricts the overall scalability, usability, and performance potential of the system.

[0012] In summary, the existing Naive RAG technology system has significant shortcomings in terms of semantic segmentation accuracy, retrieval mode diversity, storage scheme economy, and system architecture interoperability, making it difficult to meet enterprises' comprehensive needs for knowledge base question answering systems that are highly accurate, efficient, low-cost, and easy to maintain.

[0013] Therefore, there is an urgent need in this field for an innovative technical solution to systematically solve the above problems and achieve a balance between performance and engineering efficiency. Summary of the Invention

[0014] This invention addresses the shortcomings of the prior art by providing a highly practical RAG question-answering optimization method.

[0015] A further technical objective of this invention is to provide a reasonably designed, safe, and applicable RAG question-answering optimization device.

[0016] The technical solution adopted by this invention to solve its technical problem is:

[0017] A RAG question answering optimization method first receives raw knowledge documents in various formats and users' natural language queries at the input layer. Then, a knowledge base construction module and a knowledge retrieval module are set up at the processing layer to process the knowledge entry and user query processes, respectively. The middleware layer sets up an MCP Server module and a vector database. The MCP Server module is a standard interface proxy, and the vector database is a distributed storage engine that combines efficient approximate nearest neighbor search and hybrid retrieval.

[0018] Finally, an LLM generation module is deployed at the output layer to generate the final answer based on the retrieved enhanced context.

[0019] Furthermore, the knowledge base construction module includes an intelligent text segmentation module, a FAQ extraction submodule, and a vectorized storage submodule. The intelligent text segmentation module takes input original documents in various formats and segments them using LLM prompts, following these rules:

[0020] (1) Ensure semantic integrity and do not cut complete sentences or multiple sentences with the same semantic meaning;

[0021] (2) Filter invalid information;

[0022] (3) Preserve the contextual connection and merge the title and body text into one paragraph to supplement the semantics;

[0023] (4) The length of a single paragraph of text shall not exceed a certain number of characters;

[0024] Output semantically complete and information-clean text segments.

[0025] Furthermore, the FAQ extraction submodule takes the text segment output by the intelligent text segmentation submodule as input, and extracts atomized FAQs through LLM, with rules including:

[0026] (1) Introduced by a question;

[0027] (2) A certain number of FAQs are extracted from each text segment;

[0028] (3) The answers correspond one-to-one with the questions and are directly derived from the text content without adding external information;

[0029] Output a list of FAQs in the format [{"question":"atomic question","answer":"corresponding answer"},...].

[0030] Furthermore, the vectorized storage submodule uses the Embedding model to convert text segments and the "question" field of FAQs into vectors respectively. The "text segment + text vector" is written into the "vector index" of the vector database through the knowledge base document addition tool of MCP Server, and the "FAQ question + FAQ answer + question vector" is written into the "full text-vector hybrid index" of the vector database through the question and answer FAQ entry tool.

[0031] A vector retrieval algorithm based on a vector database is used to perform KNN vector retrieval and full-text retrieval in parallel.

[0032] Furthermore, the MCP Server module encapsulates a set of predefined utility functions conforming to the MCP protocol, used to achieve decoupled interaction between the LLM and the vector database;

[0033] The utility functions include at least:

[0034] (1) Writing tool 1:

[0035] Tool Name: Add Knowledge Base Documents

[0036] Function Description: Used to receive text content and its metadata, vectorize it, and write it to the vector index of the vector database;

[0037] Input parameters: {"content":"text segment content","meta_data":{"source":"document source identifier"}};

[0038] Output parameter: {"isSuccess":True / Fasten};

[0039] (2) Writing tool 2:

[0040] Tool Name: Enter FAQ (Questions & Answers)

[0041] Function Description: A FAQ index that supports mixed retrieval and is used to receive structured question-and-answer pairs, vectorize them, and write them into a vector database;

[0042] Input parameters: {"question":"FAQ question","answer":"FAQ answer","meta_data":{"source":"text segment identifier"}};

[0043] Output parameter: {"isSuccess":True / Fasten};

[0044] (3) Search tool 1:

[0045] Tool Name: Semantic Similarity Search;

[0046] Function Description: This function receives query text, performs vector similarity retrieval, and returns the most relevant text fragments from the vector index.

[0047] Input parameters: {"query":"user query text","size":"number of search results","topK":"topK results to return}

[0048] Output parameters: {"type":"Document","text":[{"content":"text segment content","meta_data":{...}}...],"isSuccess":True / Fasten}

[0049] (4) Search tool 2:

[0050] Tool Name: Precise FAQ Search;

[0051] Function Description: This function receives query text, performs a hybrid search combining full-text matching and vector similarity, and returns the most relevant question-answer pairs from the FAQ index.

[0052] Input parameters: {"query":"user query text","size":"number of search results","topK":"topK results to return"};

[0053] Output parameters: {"type":"FAQ","text":[{"question":"FAQ question","answer":"FAQ answer","meta_data":{...}}...],"isSuccess":True / Fasle}.

[0054] Furthermore, the knowledge retrieval module includes a query understanding and decomposition submodule, a multi-path hybrid retrieval submodule, and a result filtering submodule;

[0055] The query understanding and decomposition submodule takes a complex user query as input, decomposes the complex query into atomic sub-problems using LLM, and outputs a list of sub-problems in the format of ["atomic sub-problem 1", "atomic sub-problem 2",...].

[0056] Furthermore, the multi-path hybrid retrieval submodule calls the semantic similarity retrieval and FAQ question precision search of the MCP Server in parallel for each atomic sub-question. Text segment retrieval relies on vector matching, and FAQ retrieval relies on a hybrid strategy of "full text matching + vector matching" to improve retrieval recall.

[0057] The result filtering submodule takes the text segment results and FAQ results returned by the mixed search as input, sorts the results by relevance and removes redundancy through LLM, retains the text segments and FAQs most relevant to the sub-questions, and outputs the filtered "text segment list + FAQ list" as the context for LLM to generate answers.

[0058] Furthermore, the LLM generation module takes in the user's original query, the filtered list of text segments, and the filtered list of FAQs, integrates the input into a Prompt input LLM, and outputs accurate answers generated based on external knowledge.

[0059] Furthermore, the specific Prompt template is as follows:

[0060] User question: {User query};

[0061] Knowledge Section:

[0062] {A list of text segments, filled in the format [{"content":"text segment content","meta_data":{...}}...]};

[0063] FAQ: {FAQ list, filled in the format [{"question":"FAQ question","answer":"FAQ answer","meta_data":{...}}...]}.

[0064] A RAG question-answering optimization apparatus includes: at least one memory and at least one processor;

[0065] The at least one memory is used to store a machine-readable program;

[0066] The at least one processor is used to call the machine-readable program to execute a RAG question-answering optimization method and apparatus.

[0067] Compared with the prior art, the RAG question-answering optimization method and apparatus of the present invention have the following outstanding advantages:

[0068] (1) To address the semantic fragmentation and noise residue issues caused by fixed-length segmentation in existing technologies, this invention employs a dual optimization approach: an intelligent dynamic segmentation method based on large language model semantic analysis and an atomic FAQ automatic extraction mechanism. This ensures high quality and purity of the retrieval context from the data source. This improvement directly overcomes the retrieval context distortion defects caused by traditional methods, resulting in semantically complete and high signal-to-noise ratio knowledge fragments input into the LLM. This significantly reduces the probability of the LLM experiencing "illusions" due to contextual noise or incomplete information, and comprehensively improves the accuracy and reliability of answers to user queries, especially complex semantic queries and explicit question queries.

[0069] (2) This invention overcomes the limitations of single-vector retrieval and constructs a multi-path hybrid retrieval and recall system. By executing semantic retrieval based on vector similarity and full-text exact matching retrieval based on FAQ in parallel, the advantages of the two retrieval strategies are complemented. This solution effectively solves the pain point of low recall rate for "explicit question type" queries in existing technologies, and can efficiently process semantic association type queries and fact type queries at the same time, thereby significantly improving the retrieval recall rate while ensuring the accuracy of the retrieval results.

[0070] (3) This invention significantly reduces reliance on expensive memory resources by employing a vector database that supports efficient disk retrieval algorithms (such as DiskANN), thereby optimizing storage and retrieval costs for massive amounts of data. Simultaneously, through a standardized interface design based on the MCP (Model Context Protocol), the LLM, retrieval logic, and underlying storage components are completely decoupled. This decoupled architecture allows for the replacement, upgrading, or expansion of any core component of the system (such as the LLM model or vector database) without requiring point-to-point customization, greatly simplifying the integration process and significantly reducing long-term system maintenance costs and technological iteration risks.

[0071] (4) This invention constructs a middleware layer based on the industry-standard MCP protocol, which standardizes the interface between LLM and external tools. This design enables the system to naturally support various mainstream LLM and vector databases that conform to the MCP protocol, without needing to worry about their underlying implementation differences. Enterprises can flexibly select and switch underlying components according to their own technology stack preferences and performance requirements, which greatly improves the system's technical inclusiveness, integration convenience, and flexibility for enterprise-level application.

[0072] (5) This invention can smoothly adapt to knowledge base data of different sizes, from GB to PB. The system architecture itself has good horizontal scalability, ensuring that enterprises only need to expand the underlying storage resources as needed during business growth, without having to reconstruct the overall application architecture, effectively protecting the enterprise's initial technology investment and providing a solid technical guarantee for the long-term evolution of the knowledge base. Detailed Implementation

[0073] To enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to specific embodiments. Obviously, the described embodiments are merely some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0074] The following is a preferred embodiment:

[0075] In this embodiment, a RAG question-answering optimization method is proposed. First, the input layer receives original knowledge documents in various formats and natural language queries from users. Then, the processing layer sets up a knowledge base construction module and a knowledge retrieval module to process the knowledge entry and user query processes, respectively. The middleware layer sets up an MCP Server module and a vector database. The MCP Server module is a standard interface proxy, and the vector database is a distributed storage engine that combines efficient approximate nearest neighbor search and hybrid retrieval.

[0076] Finally, an LLM generation module is deployed at the output layer to generate the final answer based on the retrieved enhanced context.

[0077] The knowledge base construction module implements the entire process of "document import → text processing → vectorized storage", including:

[0078] (1) Intelligent text segmentation module;

[0079] The semantic structure of the input document is analyzed using a pre-trained large language model. Based on the preset semantic integrity rules and invalid information filtering rules, the long document is dynamically segmented into multiple semantically complete text segments. The semantic integrity rules include, but are not limited to, ensuring sentence integrity and preserving the relationship between the title and the body text. The invalid information filtering rules are used to remove formatting tags and redundant noise.

[0080] Input: Original documents in various formats, such as Markdown, Word, Txt, etc.;

[0081] Processing logic: Segmentation is driven by LLM prompts, following these rules:

[0082] Rule 1: Ensure semantic integrity; do not cut complete sentences or multiple sentences describing the same meaning.

[0083] Rule 2: Filter out invalid information (such as excessive spaces, redundant punctuation, Markdown tags, external links, etc.);

[0084] Rule 3: Preserve contextual relevance; titles can be merged with the body text into a single paragraph to supplement semantic meaning.

[0085] Rule 4: The length of a single text segment should not exceed 500 characters to ensure the efficiency of subsequent vectorization and retrieval.

[0086] Output: A semantically complete and information-clean text segment (Chunk).

[0087] (2) FAQ extraction submodule;

[0088] Based on a pre-trained large language model, atomic question-answer pairs guided by interrogative words are automatically extracted from the semantically complete text fragments, ensuring that the answer content is directly derived from and faithful to the original text.

[0089] Input: Text segments output by the intelligent text segmentation module;

[0090] Processing logic: Extract atomized FAQs using LLM, with rules including:

[0091] Focus on the scope of the question, using interrogative words such as "when," "why," and "how" to guide the discussion, and avoid broad questions;

[0092] The number of FAQs extracted from each text segment shall not exceed 20 to ensure the conciseness of the FAQ library;

[0093] The answers correspond one-to-one with the questions and are directly derived from the text content without adding any external information;

[0094] Output: A list of FAQs in the format [{"question":"atomic question","answer":"corresponding answer"},...].

[0095] (3) Vectorized storage submodule:

[0096] The text fragments and FAQ fields are converted into high-dimensional vector representations using an embedding model. The vectorized text fragments and FAQ pairs are then stored in different indexes of the vector database using a standardized writing tool provided by the MCP Server module. The vector database employs a disk-optimized approximate nearest neighbor search algorithm to support efficient retrieval and lower memory overhead for large-scale data.

[0097] Vectorization: The Embedding model is used to convert the text segments and the "Question" field of the FAQ into vectors respectively;

[0098] Storage logic: The knowledge base document addition tool of MCP Server writes "text segment + text vector" into the "vector index" of the vector database, and the question and answer FAQ tool writes "FAQ question + FAQ answer + question vector" into the "full text-vector hybrid index" of the vector database.

[0099] Storage optimization: Relying on efficient vector retrieval algorithms (such as DiskANN) supported by vector databases to replace the traditional HNSW algorithm, reducing memory usage, while supporting parallel execution of KNN (nearest neighbor) vector retrieval and full-text retrieval.

[0100] The MCP Server module acts as a standardized interface proxy between the LLM and the underlying vector database. It encapsulates a set of predefined utility functions that conform to the MCP protocol to achieve decoupled interaction between the LLM and the vector database.

[0101] Utility functions should include at least:

[0102] (1) Tool Name: Add Knowledge Base Document

[0103] Function Description: Used to receive text content and its metadata, vectorize it, and write it to the vector index of the vector database.

[0104] Input parameters (JSON format): {"content":"text segment content","meta_data":{"source":"document source identifier"}};

[0105] Output parameters (JSON format): {"isSuccess":True / Fasle}.

[0106] (2) Writing tool 2:

[0107] Tool Name: Enter FAQ

[0108] Function Description: A FAQ index that supports mixed retrieval and is used to receive structured question-and-answer pairs, vectorize them, and write them into a vector database.

[0109] Input parameters (JSON format): {"question":"FAQ question","answer":"FAQ answer","meta_data":{"source":"text segment identifier"}}

[0110] Output parameters (JSON format): {"isSuccess":True / Fasle}.

[0111] (3) Search tool 1:

[0112] Tool Name: Semantic Similarity Search

[0113] Function Description: This function receives query text, performs vector similarity retrieval, and returns the most relevant text fragments from the vector index.

[0114] Input parameters (JSON format): {"query":"user query text","size":"number of search results (e.g., 100)","topK":"topK results to return (e.g., 10)"};

[0115] Output parameters (JSON format): {"type":"Document","text":[{"content":"text segment content","meta_data":{...}}...],"isSuccess":True / Fasle}.

[0116] (4) Search tool 2:

[0117] Tool Name: Precise FAQ Search

[0118] Function Description: This function receives query text, performs a hybrid search combining full-text matching and vector similarity, and returns the most relevant question-answer pairs from the FAQ index.

[0119] Input parameters (JSON format): {"query":"user query text","size":"number of search results (e.g., 20)","topK":"topK results to return (e.g., 5)"}

[0120] Output parameters (JSON format): {"type":"FAQ","text":[{"question":"FAQ question","answer":"FAQ answer","meta_data":{...}}...],"isSuccess":True / Fasle}.

[0121] The knowledge retrieval module is used to process user queries and obtain enhanced knowledge context. Its execution steps are as follows:

[0122] (1) Query understanding and decomposition sub-module;

[0123] We use a large language model to parse complex user queries into multiple atomic sub-problems.

[0124] Input: Complex user queries (such as "How can the sharding storage mechanism of vector databases adapt to large-scale knowledge bases, and what technical support can the MCP protocol provide for cross-model collaboration");

[0125] Processing logic: Complex queries are broken down into atomic sub-problems using LLM (e.g., sub-problem 1: "How can the sharding storage mechanism of vector databases adapt to large-scale knowledge bases?", sub-problem 2: "What technical support can the MCP protocol provide for cross-model collaboration?").

[0126] Output: A list of subproblems in the format ["Subproblem 1", "Subproblem 2", ...].

[0127] (2) Multi-path hybrid retrieval submodule;

[0128] For each sub-problem, the third and fourth tools of the MCP Server module are invoked in parallel to retrieve data from the vector index and FAQ index, respectively, to achieve a complementarity between semantic retrieval and precise matching.

[0129] Processing logic: For each atomic sub-problem, the semantic similarity retrieval (retrieving relevant text segments) and FAQ question precision search (retrieving relevant FAQs) of the MCP Server are called in parallel;

[0130] Search optimization: Text segment retrieval relies on vector matching (semantic association), while FAQ retrieval relies on a hybrid strategy of "full-text matching (keywords) + vector matching (semantics)" to improve retrieval recall.

[0131] (3) Results filtering submodule;

[0132] The large language model is used to evaluate the relevance of the retrieved multi-source results, remove duplicates and rank them, and select the text fragments and question-answer pairs that are most relevant to the sub-questions to form the final enhanced context.

[0133] Input: Text segment results and FAQ results returned by the mixed search;

[0134] Processing logic: The results are sorted by relevance and redundancy is removed using LLM, retaining the text segments and FAQs most relevant to the sub-questions;

[0135] Output: The filtered "list of text segments + list of FAQs" serves as the context for LLM to generate answers.

[0136] The LLM generation module receives the enhanced context and the user's original query provided by the knowledge retrieval module, constructs a prompt word template containing instructions, context, and query, and inputs it into the large language model. The large language model generates the final answer based on the enhanced context, thereby effectively limiting hallucination phenomena and improving the accuracy and credibility of the answer.

[0137] Input: User's original query, a list of filtered text segments, and a list of filtered FAQs;

[0138] Processing logic: Integrate the inputs into a Prompt input LLM;

[0139] Output: Accurate answers generated based on external knowledge, avoiding the "illusion" of LLM.

[0140] The specific Prompt template is as follows:

[0141] The rules are:

[0142] Priority principle: You must use the provided "knowledge section" and "FAQ" content to answer the questions, and you are prohibited from citing external information that is not mentioned (including your own training data);

[0143] Conflict handling: If there is a conflict between the "Knowledge Section" and the "FAQ", the information in the "Knowledge Section" shall prevail; if there are multiple pieces of the same type of information, the key consistent content should be integrated and duplicate statements should be removed.

[0144] Missing information handling: If neither the "Knowledge Section" nor the "FAQ" covers the user's question, reply directly with "The knowledge information provided at present cannot answer this question," and do not fabricate content;

[0145] Style requirements: Answers should be concise, accurate, and logically clear, presented in points (if the question involves multiple dimensions) or in paragraphs, avoiding redundant expressions.

[0146] Reference information:

[0147] User question: {User query}

[0148] Knowledge Section:

[0149] {A list of text segments, filled in the format [{"content":"text segment content","meta_data":{...}}...]}

[0150] FAQ:

[0151] {FAQ list, filled in the format [{"question":"FAQ question","answer":"FAQ answer","meta_data":{...}}...]}.

[0152] The output requirements are:

[0153] Additional source information such as "based on knowledge segment X" or "refer to FAQX" is required.

[0154] Based on the above method, a RAG question-answering optimization device in this embodiment includes: at least one memory and at least one processor;

[0155] The at least one memory is used to store a machine-readable program;

[0156] The at least one processor is used to call the machine-readable program to execute a RAG question-answering optimization method and apparatus.

[0157] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A RAG question-answering optimization method, characterized in that, First, the input layer receives raw knowledge documents in various formats and users' natural language queries. Then, the processing layer sets up a knowledge base construction module and a knowledge retrieval module to process the knowledge entry and user query processes, respectively. The middleware layer sets up an MCP Server module and a vector database. The MCP Server module is a standard interface proxy, and the vector database is a distributed storage engine that combines efficient approximate nearest neighbor search and hybrid retrieval. Finally, an LLM generation module is deployed at the output layer to generate the final answer based on the retrieved enhanced context.

2. The RAG question-answering optimization method according to claim 1, characterized in that, The knowledge base construction module includes an intelligent text segmentation module, a FAQ extraction submodule, and a vectorized storage submodule. The intelligent text segmentation module takes original documents in various formats as input and segments them using LLM prompts, following these rules: (1) Ensure semantic integrity and do not cut complete sentences or multiple sentences with the same semantic meaning; (2) Filter invalid information; (3) Preserve the contextual connection and merge the title and body text into one paragraph to supplement the semantics; (4) The length of a single paragraph of text shall not exceed a certain number of characters; Output semantically complete and information-clean text segments.

3. The RAG question-answering optimization method according to claim 2, characterized in that, The FAQ extraction submodule takes the text segment output by the intelligent text segmentation submodule as input, and extracts atomized FAQs using LLM. The rules include: (1) Introduced by a question; (2) A certain number of FAQs are extracted from each text segment; (3) The answers correspond one-to-one with the questions and are directly derived from the text content without adding external information; Output a list of FAQs in the format [{"question":"atomic question","answer":"corresponding answer"},...].

4. The RAG question-answering optimization method according to claim 3, characterized in that, The vectorized storage submodule uses the Embedding model to convert text segments and the "Question" field of FAQs into vectors respectively. The "text segment + text vector" is written into the "vector index" of the vector database through the knowledge base document addition tool of MCP Server, and the "FAQ question + FAQ answer + question vector" is written into the "full text-vector hybrid index" of the vector database through the question and answer FAQ entry tool. A vector retrieval algorithm based on a vector database is used to perform KNN vector retrieval and full-text retrieval in parallel.

5. The RAG question-answering optimization method according to claim 4, characterized in that, The MCP Server module encapsulates a set of predefined utility functions conforming to the MCP protocol, used to achieve decoupled interaction between LLM and vector database; The utility functions include at least: (1) Writing tool 1: Tool Name: Add Knowledge Base Documents Function Description: Used to receive text content and its metadata, vectorize it, and write it to the vector index of the vector database; Input parameters: {"content":"text segment content","meta_data":{"source":"document source identifier"}}; Output parameter: {"isSuccess":True / Fasten}; (2) Writing tool 2: Tool Name: Enter FAQ (Questions & Answers) Function Description: A FAQ index that supports mixed retrieval and is used to receive structured question-and-answer pairs, vectorize them, and write them into a vector database; Input parameters: {"question":"FAQ question","answer":"FAQ answer","meta_data":{"source":"text segment identifier"}}; Output parameter: {"isSuccess":True / Fasten}; (3) Search tool 1: Tool Name: Semantic Similarity Search; Function Description: This function receives query text, performs vector similarity retrieval, and returns the most relevant text fragments from the vector index. Input parameters: {"query":"user query text","size":"number of search results","topK":"topK results to return} Output parameters: {"type":"Document","text":[{"content":"text segment content","meta_data":{...}}...],"isSuccess":True / Fasten} (4) Search tool 2: Tool Name: Precise FAQ Search; Function Description: This function receives query text, performs a hybrid search combining full-text matching and vector similarity, and returns the most relevant question-answer pairs from the FAQ index. Input parameters: {"query":"user query text","size":"number of search results","topK":"topK results to return"}; Output parameters: {"type":"FAQ","text":[{"question":"FAQ question","answer":"FAQ answer","meta_data":{...}}...],"isSuccess":True / Fasle}.

6. The RAG question-answering optimization method according to claim 4, characterized in that, The knowledge retrieval module includes a query understanding and decomposition submodule, a multi-path hybrid retrieval submodule, and a result filtering submodule; The query understanding and decomposition submodule takes a complex user query as input, decomposes the complex query into atomic sub-problems using LLM, and outputs a list of sub-problems in the format of ["atomic sub-problem 1", "atomic sub-problem 2",...].

7. The RAG question-answering optimization method according to claim 6, characterized in that, The multi-path hybrid retrieval submodule calls the semantic similarity retrieval and FAQ question precision search of MCP Server in parallel for each atomic sub-question. Text segment retrieval relies on vector matching, and FAQ retrieval relies on a hybrid strategy of "full text matching + vector matching" to improve retrieval recall. The result filtering submodule takes the text segment results and FAQ results returned by the mixed search as input, sorts the results by relevance and removes redundancy through LLM, retains the text segments and FAQs most relevant to the sub-questions, and outputs the filtered "text segment list + FAQ list" as the context for LLM to generate answers.

8. The RAG question-answering optimization method according to claim 7, characterized in that, The LLM generation module takes in the user's original query, a list of filtered text segments, and a list of filtered FAQs, integrates the input into a Prompt input LLM, and outputs accurate answers generated based on external knowledge.

9. The RAG question-answering optimization method according to claim 8, characterized in that, The specific Prompt template is as follows: User question: {User query}; Knowledge Section: {A list of text segments, filled in the format [{"content":"text segment content","meta_data":{...}}...]}; FAQ: {FAQ list, filled in the format [{"question":"FAQ question","answer":"FAQ answer","meta_data":{...}}...]}.

10. A RAG question-answering optimization device, characterized in that, include: At least one memory and at least one processor; The at least one memory is used to store a machine-readable program; The at least one processor is configured to invoke the machine-readable program to perform the method according to any one of claims 1 to 9.

Citation Information

Cited By

  • Structured test case generation method and system based on RAG and MCP

    CN121833540A

  • Rag and mcp-based structured test case generation method and system

    CN121833540B