Error correction in retrieval-augmented generation systems

A taxonomy-based error detection and correction method for RAG systems addresses the complexity of RAG errors by identifying error stages and subtypes, enhancing the accuracy and reliability of generated responses.

US20260377260A1Pending Publication Date: 2026-11-26THE TORONTO DOMINION BANK
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
US19/685914
Authority / Receiving Office
US · United States
Patent Type
Applications(United States)
Current Assignee / Owner
Priority Date
2025-05-23
Filing Date
2026-05-22
Publication Date
2026-11-26

AI Technical Summary

Technical Problem

Existing retrieval-augmented generation (RAG) systems are prone to diverse and complex errors due to their multi-step pipelines, which are difficult to trace and correct effectively, especially in critical industries like healthcare, as current benchmark tasks are overly simplistic and do not reflect real-world complexity.

Method used

A taxonomy of error types is applied to detect the stage and subtype of errors in RAG systems, using a verification dataset to automatically modify the system and correct errors in specific stages such as chunking, retrieval, and generation, by identifying and addressing the root causes of errors.

Benefits of technology

This approach enables targeted corrections to RAG systems, improving the accuracy and reliability of generated responses by effectively diagnosing and modifying individual stages, reducing errors and enhancing overall system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure US20260377260A1-D00000_ABST
    Figure US20260377260A1-D00000_ABST
Patent Text Reader

Abstract

Errors in a RAG system are detected by evaluating errors in intermediate stages of the RAG generation process. Generated responses are automatically evaluated as incorrect by applying a large language model (LLM) to the generated response in combination with the query, a verified response, and retrieved context documents. The incorrect responses may then be evaluated to determine which stage of the RAG system is responsible for the error, such as chunking, retrieval, ranking, or generation. After determining the stage likely responsible for the error, the subtype of error within the stage is determined and the error subtypes across many generated responses may be used to modify operation of the RAG system to correct the particular error subtypes.
Need to check novelty before this filing date? Find Prior Art

Description

CROSS-REFERENCE TO RELATED APPLICATIONS

[0001] This application claims the benefit of U.S. Provisional Application No. 63 / 811,009, filed on May 23, 2025, the contents of which are hereby incorporated by reference in its entirety.BACKGROUND

[0002] This disclosure relates generally to retrieval-augmented generation (RAG) systems and more particularly to detecting errors associated with particular stages of a RAG system and implementing corresponding corrections.

[0003] Retrieval-augmented generation (RAG) has become one effective approach for applying generative large language models (LLMs) in applications where outputs must incorporate knowledge from outside of the model’s training set. This is especially valuable for grounding generated responses in factual information from source documents to reduce fabricated content and to apply non-public domain knowledge where required. RAG systems may be used to provide natural language interfaces to knowledge sources, but despite their merits they can still be error-prone in practice. Due to the greater complexity of RAG pipelines compared to direct generation from a large language model, these errors are diverse and their causes can be difficult to trace. Deploying a RAG pipeline, especially in critical industries like healthcare, requires understanding the variety of errors that can occur in order to monitor and minimize them.

[0004] Existing work on RAG errors has generally not accounted for the complexity of real-world RAG systems and the corresponding complexity of their failure modes. On the data side, widely used benchmark tasks for evaluating RAG systems are often overly simplistic, typically featuring multiple-choice questions or requiring short factual answers that are easy to validate but do not reflect real-world complexity. In practice, users expect more sophisticated answers that can more thoroughly explain a topic, but as a result can fail in more subtle semantic ways without outright fabrications. Real RAG systems use complex multi-step pipelines, with additional data processing steps like adaptive chunking or reranking. Without effectively identifying what portion of a RAG system is associated with particular types of errors, corrections to RAG systems may be applied to stages that do not reflect the upstream cause of an error.SUMMARY

[0005] To more effectively detect and correct for errors in RAG systems, a taxonomy of types of errors is applied to detect the stage of the RAG system that caused the error and an error subtype associated with the error. Based on the detected stages and subtypes, the RAG system may be automatically modified to correct these errors in future applications of the RAG system. As a result, the RAG stages may be evaluated and errors corrected with respect to the RAG system as a whole, such that errors with respect to the overall RAG system can be used to more effectively diagnose and modify individual RAG stages. As such, the detected errors may be used to correct errors in upstream RAG stages beyond the application of a language model to the retrieved information and may include how documents are chunked for retrieval, how documents are retrieved, which retrieved documents are selected for inclusion in a language model context, and so forth.

[0006] To do so, a verification data set having a set of queries and verified responses (i.e., as a known “ground truth”) may be used to detect errors in the RAG system. First, each of the queries may be provided to the RAG system to obtain the corresponding generated response from the RAG system. The generated response may be evaluated by a language model with respect to a verified response to determine whether the generated response is an error. Because the generated response may differ from the verified response while still being “correct,” the language model may also receive the retrieved documents that form a context to more carefully evaluate differences in the generated response from the verified response. Then, a taxonomy of error subtypes describing errors across different stages of the RAG system may be used to detect errors in particular stages of the RAG pipeline as well as the particular subtypes of error that occur. Using the detected subtypes, modifications to the RAG system can be applied that are particular to the detected errors, enabling focused modification to the RAG system without overly complex components that are not needed for the particular errors arising in a given data set.BRIEF DESCRIPTION OF THE DRAWINGS

[0007] FIG. 1 illustrates an example generated response error detection system, according to one embodiment.

[0008] FIG. 2 illustrates stages of a RAG pipeline, according to one embodiment.

[0009] FIG. 3 shows an example flow for automatically detecting errors in generated responses from a RAG system, according to one embodiment.

[0010] FIG. 4 illustrates the detection of an error stage for a RAG pipeline, according to one embodiment.

[0011] FIG. 5 provides an example method for detecting and correcting for errors in a RAG system, according to one embodiment.

[0012] The figures depict various embodiments of the present invention for purposes of illustration only. One skilled in the art will readily recognize from the following discussion that alternative embodiments of the structures and methods illustrated herein may be employed without departing from the principles of the invention described herein.DETAILED DESCRIPTIONArchitecture Overview

[0013] FIG. 1 illustrates an example generated response error detection system 100, according to one embodiment. The generated response error detection system 100 detects and corrects errors that may arise in the application of a retrieval-augmented generation (RAG) system 110. As discussed below, the RAG system may include a variety of stages (e.g., as a pipeline) for responding to queries using a large language model in conjunction with a set of source documents 140. The source documents 140 may represent information that forms a knowledge source for the RAG system 110 to respond to queries. Typically, the RAG system 110 may coordinate prompting of a large language model using a context that includes the query along with portions of the source documents 140 that are relevant to the query. The volume of the source documents 140 is typically larger than the available context for the large language model, such that the source documents 140 may be separated into smaller parts, termed “chunks” that are stored in a chunked document repository 150 and retrieved for responding to queries.

[0014] The RAG system 110 may be a component of the generated response error detection or may be accessed at least partially via an external system. For example, the RAG system 110 typically constructs a prompt or “context” for input to a large language model (LLM) that outputs a generated response to the query. In various embodiments, the large language model may be accessed at an external system (e.g., by providing the input prompt for the LLM) and other components may be locally organized, such as the set of source documents 140 and / or chunked document repository 150 used to construct the prompt. The retrieval-augmented generation system 110 may include multiple stages for generating a response to a query as discussed below, and each stage may be located with the generated response error detection system 100 or may be externally located on another system.

[0015] The generated response error detection system 100 includes a response error detection module 120 that automatically detects errors in generated responses from the retrieval-augmented generation system 110 and identifying the stage of the RAG system 110 that the error occurred and an error subtype associated with the error. To do so, the response error detection module 120 may use a verification data set 160 having pairs of queries and associated verified responses for the queries. The verification data set 160 may be a data set that represents holdout data from a set of training data used for training components of the RAG system 110. The verified responses may be a “ground truth” representing a known high-quality answer to the query based on the source documents 140. In some cases, the verified response to a query may include that the query cannot be answered based on the source documents 140. After detecting the stage of the RAG system 110 at which the error occurs and error subtypes, an error correction module 130 may apply modifications to the RAG system 110 to reduce the error frequency and otherwise account for the detected errors. These and other aspects of detecting and correcting for errors in the RAG system 110 are further discussed below.

[0016] FIG. 2 illustrates stages of a RAG pipeline 200, according to one embodiment. To obtain a generated response 280 for a query 220, a RAG system typically constructs a relevant context for a large language model that operates as a generator 270. In the example RAG pipeline 200 of FIG. 2, multiple stages are shown for ultimately obtaining the generated response 280 for a query 220 based on a set of source documents 140. These stages include chunking the source documents 140, retrieving relevant document chunks, reranking document chunks, and generating the response. These stages may be referred to as chunking, retrieval, ranking (or reranking), and generation, respectively. These stages are shown as one example and various embodiments may include more or fewer stages. As also discussed below, certain stages may be performed in response to a particular query, while additional stages may be performed asynchronously or “offline” to prepare or stage data for use during the generation process. For example, the source documents 140 may be chunked before particular queries are received by the RAG system, such that the chunked document repository 150 may be applied to subsequent queries 220 for effective document retrieval 230.Chunker

[0017] While the source documents 140 are the documents that may represent the repository of information to be used in responding to the query 220, typically, the volume of the source documents 140 is not suitable for use directly with the generator 270. In addition, in many cases the source documents 140 may be voluminous, and each document may include hundreds, thousands, or more pages of information. As such, the source documents 140 may be segmented into “chunks” by the chunker 210 and stored in the chunked document repository 150. The particular chunking approach applied by the chunker 210 may vary in different embodiments and may vary the granularity (e.g., chunk size), method for separating portions of a given document, capture interrelationships between concepts in a given chunk, and so forth. In addition to capturing different segments of the source documents 140 as chunks, each chunked document may also be encoded to obtain a chunk representation that may be indexed and used for retrieval of chunks when determining relevance to particular queries. The encoding may be performed by an embedding model that may vary in different embodiments.

[0018] Various embodiments may use different chunking approaches, including fixed-length chunking (with and without overlap) and recursive chunking at the sentence level. These methods enable flexible preprocessing of documents depending on the context granularity needed. In addition, chunks may also be semantically defined such that sentences or paragraphs are separated according to the semantic cohesion of the chunk. In some instances, data sets may also include pre-defined chunks provided by the data set.Retrieval

[0019] To respond to a particular query 220, the document retrieval 230 stage identifies relevant document chunks in the chunked document repository 150 that may be relevant to the query 220. To do so, the document retrieval 230 may identify relevant chunks based on the chunk representation and a query representation of the query 220. The query representation may be determined by applying an encoding to the query 220, such that relevant chunks may be retrieved based on a comparison of the chunk representations with the query representations to obtain the retrieved document chunks 240. As such, the chunk representations are indexed and retrieved with the query representation via a dense retrieval search, which returns top candidates based on similarity to the query 220.

[0020] In various embodiments, the document retrieval 230 may use models from the Hugging Face repository (e.g., gte-large-en-v1.5) to generate embeddings of queries and chunks. In one embodiment, the document retrieval 230 computes vector similarity (based on cosine similarity) between the query representation and chunk representation and selects the top-k most relevant chunks. The value of k may be specified as a parameter of the RAG pipeline 200 and may be, for example, 5, 8, 10, 15, or 20.Reranking

[0021] Retrieved document chunks 240 in some configurations are then reranked with a reranker 250 that may use the query and content of the document chunks for reranking the retrieved document chunks 240. That is, where the document retrieval 230 may use the encoded representations for determining rough relevance across the chunked document repository 150, the reranker may use the content of the query and the chunked documents for more precisely determining relevance of the retrieved document chunks 240. In some embodiments, the reranker 250 may use a large language model that uses the original query as a context for scoring the relevance of the retrieved document chunks 240 to select document chunks having high semantic relevance to the query 220. In one embodiment, the reranker may use a specialized large language model fine-tuned for ranking tasks (e.g., rank-zephyr-7b-v1-full, available from Hugging Face). Using the set of retrieved document chunks 240 and the original query 220, the reranker 250 assigns a relevance score to each chunk. The reranker may then select the top-k ′ candidates (with k ′< k from retrieval) to ensure that only the most relevant context is passed to the generator 270. The reranking step may play a critical role in filtering noisy or marginally relevant content returned by dense retrieval. This two-stage process is meant to enhance retrieval precision, thereby improving final answer quality. The reranker may reduce the number of context documents by a number of a percentage relative to the document retrieval 230.Generation

[0022] Finally, the top-ranked chunks are context documents 260 that are provided to the generator 270, which produces the generated response 280 to the query 220. The generator 270 is typically a large language model that is prompted with the query 220 with a response based on the context documents 260. The generator 270 may use the reranked k ′ chunks of the context documents 260 and concatenate them to form the context alongside the query 220. As a result, the source documents 140 are narrowed to the chunked portions that are retrieved and then reranked to form the context for responding to a particular query 220. The generator 270 may apply a general large language model or may use a large language model fine-tuned for query response based on retrieved documents or for response based on source documents 140, in particular.Stage-Based Error Identification & Related Modifications

[0023] To improve the generated responses, rather than generally identify whether the generated response is correct or aligned with context documents, errors in the RAG pipeline 200 are determined by identifying the relevant stage at which the error occurs and characterizing the subtype of error that occurred at that stage. Particularly, the errors may be described according to a taxonomy that can be attributed to different parts of a RAG system. Errors are classified by the pipeline stage that caused them: preprocessing errors during chunking; search errors during retrieval; ranking errors during reranking; and answer errors during generation. For each category and error type, the discussion below describes the nature of the error, why it occurs in RAG systems, provide examples as seen in our RAG implementation, and finally provide modifications to the RAG pipeline 200 that may be applied to reduce that error.

[0024] Error types are not necessarily mutually exclusive; in practice, multiple error types often co-occur as errors early in the pipeline can beget later ones. This taxonomy focuses on errors that occur during the normal operation of RAG systems and hence does not discuss failures caused by adversarial inputs, faults in the corpus, or similar anomalies. The various types of errors are discussed below according to particular error subtypes that may occur at different stages and are characterized numerically (e.g., as errors 1 through 16) for convenience. Although these specific error subtypes and stages are discussed herein, in additional embodiments additional stages of the RAG pipeline 200 may be similarly analyzed and more or fewer error subtypes may be characterized.Chunking Errors

[0025] Chunking errors typically occur when the chunker 210 processes the source documents 140 to chunks that are not properly retrieved or processed in downstream stages of the RAG pipeline 200. Particularly, although the source documents 140 must generally be processed to portions that can be characterized for retrieval and used in the context, ineffective chunking may obtain chunks that do not effectively maintain relevant semantics or other components of the source document data or aspects of the chunking process cause relevant chunks not to be retrieved or correctly processed.

[0026] Error 1, Overchunking: Overchunking may refer to a chunking process that splits documents into excessively small or disjointed segments, causing important context to be broken across chunks. This may cause individual chunks to appear incomplete or ambiguous. Multiple chunks are then required to obtain coherent information, putting greater burden on the RAG system to correctly retrieve all relevant chunks. Errors arise downstream when search fails to retrieve consecutive chunks that should be included to provide complete information for responding to queries.

[0027] Overchunking Error Example:

[0028] Query : What platform did Sunrise Holidays introduce in April 2019?

[0029] Chunk Excerpt : [Excluded from chunk: In April 2019, Sunrise Holidays introduced an online booking platform, which greatly improved its competitiveness.] The launch of this user-friendly platform attracted more customers and strengthened the company’s position in the market. [...]

[0030] Response : The platform introduced by Sunrise Holidays in April 2019 is not specified in the given context.

[0031] Ground Truth : Online booking platform.

[0032] Cause : The retrieved chunks come from the correct document, but the description of it as an online booking platform is cut off.

[0033] Error 2, Underchunking: When chunks are too large (e.g., the source documents should be split into additional chunks), the chunks may cover multiple topics with mixed content. Irrelevant information can dilute keywords or phrases, affecting the encoding for the chunk and lowering retrieval scores on the correct chunks. These chunks may be less likely to be retained (despite containing relevant information) by the reranker 250 as part of the context documents 260 and, when provided to the generator, contains extraneous content that can confuse the model, causing errors.

[0034] Underchunking Error Example:

[0035] Query: What system does CleanCo Housekeeping Services have in place to safeguard assets and ensure financial accuracy?

[0036] Chunk Excerpt: [...] To mitigate risks such as increasing competition, regulatory changes, and economic uncertainties, CleanCo plans to implement risk management strategies through diversification and continuous monitoring. [...]

[0037] Response: CleanCo Housekeeping Services has a system in place to safeguard assets and ensure financial accuracy through its risk management framework, which involves conducting regular risk assessments, strengthening internal controls.

[0038] Ground Truth: Unable to answer.

[0039] Cause : Retrieved chunks contain so much tangential information that the generator tries to synthesize an answer instead of abstaining.

[0040] Error 3, Context Mismatch: Many documents may include lengthy discussion of similar concepts or include referential material such that important contextual information may be located at another (usually nearby) portion of the source document. For example, references like pronouns and other textual pointers can prevent correct contextual interpretation. When chunks are split at arbitrary points, it may break up coherent ideas and disrupt logical structure. Key contextual links like definitions are separated from the information they support, creating ambiguity. This causes errors downstream when the generator lacks context.

[0041] Context Mismatch Error Example:

[0042] Query : Why is the Philippines typhoon prone?

[0043] Chunk A (Retrieved) : The Philippines’ evident risk to natural disasters is due to its location. [...]

[0044] Chunk B (Not Retrieved) : In addition, the country faces the Pacific Ocean where 60% of the world’s typhoons are made.

[0045] Ground Truth : It faces the Pacific Ocean where 60% of the world’s typhoons are made.

[0046] Response : Due to its geographical location, climate, and topography.

[0047] Cause : Chunk B mentions “the country” but not the Philippines by name, which led to the retriever incorrectly assigning it low relevance.

[0048] Chunking Error Modifications : Various types of modifications may aim to address these error subtypes. Straightforward modifications include adjusting chunk size, where larger chunks help reduce E1 and smaller chunks help reduce E2, and adding small overlaps between chunks can mitigate E3 by preserving continuity. In addition, more adaptive, context-sensitive chunking strategies may handle real-world variability more effectively.

[0049] Structure-aware chunking preserves document logic by splitting along units like paragraphs or section headers. This works especially well for corpora with consistent structure, such as financial reports, and is supported in tools like LangChain and LlamaIndex. Semantic chunking segments text based on meaning, such as by detecting topic shifts using cosine distance between sentence embeddings or spikes in perplexity. Hybrid strategies combine structural and semantic cues to balance coherence and topical focus. For example, S2 Chunking integrates layout with embeddings and achieves strong results on document QA.

[0050] In practice, chunking strategies should be evaluated using retrieval metrics and iteratively tuned for size, overlap, and segmentation. Well-formed chunks yield clearer, more focused embeddings and improve retrieval quality.Retrieval Errors

[0051] Retrieval errors may occur when relevant chunks are not retrieved from the chunked document repository or are insufficiently ranked. This may occur for various reasons such as the content of the chunks or the manner in which the chunks and / or query are encoded, along with the way that the encoded representations are used to assess chunk relevance.

[0052] Error 4, Missed Retrieval : Relevant chunks are not retrieved, leading the generator to give incomplete answers, fabricate information to fill gaps, or abstain unnecessarily. As one example, misses can occur when chunks that are relevant to a portion of the query are not retrieved. When the portion of the query relevant to that chunk is not effectively captured in the query’s encoded representation, the subsequent retrieval relevance score for those chunks may be insufficient for retrieving that chunk.

[0053] Missed Retrieval Error Example:

[0054] Query : What were the large-scale financing activities undertaken by Vanguard Media Group in 2019 and Energex Corp. in 2021?

[0055] Response : Vanguard Media Group’s large-scale financing activities in 2019 included the acquisition of Silver Screen Studios for $200 million [...]

[0056] Ground Truth : Vanguard Media Group raised $100 million in debt capital in 2019, while Energex Corp. conducted large-scale financing in 2021.

[0057] Cause : The query asks about two entities, but all top-ranked chunks relate to only one. Chunks about the second fall outside the top-k threshold.

[0058] Error 5, Low Relevance: Similarly, an error may occur when retrieved chunks are only loosely related to the query or overbalanced with respect to one aspect of the query. Causes include an unbalanced corpus with many chunks relating to one topic, and vocabulary mismatch where the query uses different terms than the corpus.

[0059] Low Retrieval Relevance Error Example:

[0060] Query : In which year is the Corporate Governance Report for Green Fields Agriculture Co.?

[0061] Response : The Corporate Governance Report for Green Fields Agriculture Co. does not provide a specific year, but it appears to cover events and initiatives from 2018 and 2021.

[0062] Ground Truth : 2018.

[0063] Cause : Many chunks from the Report were assigned high similarity and retrieved, but did not relate to the Report’s publication year. Without correctly retrieving a chunk specifying the publication year, the generator may incorrectly use the years discussed in the content.

[0064] Error 6, Semantic Drift: Retrieved documents match keywords, but not the query’s intent, due to overreliance on keyword matching rather than semantic relevance.

[0065] Semantic Drift Error Example:

[0066] Query : According to the judgment of Hartford, Ashland, Court and Glenwood, Quailwood, Court, what sentences were given to the defendants M. Cooper and Y. Nelson?

[0067] Response : M. Cooper was sentenced to four years imprisonment.

[0068] Ground Truth : M. Cooper was sentenced to four years imprisonment; Y. Nelson was sentenced to three years imprisonment.

[0069] Cause : The retrieved chunks contain information about both defendants’ cases, but don’t include the sentence for Y. Nelson.

[0070] Retrieval Error Modifications: The consequences of retrieval errors can appear similar, with the generator giving incomplete answers, fabricating information to fill gaps, or abstaining unnecessarily. Hence, it is challenging to disambiguate the error subtypes without examining retrieved chunks. Luckily, improving the retriever can simultaneously reduce all error types. First, query rewriting via keyword expansion, paraphrasing, or semantic reformulation can improve recall and precision by reducing vocabulary mismatch, especially for short or ambiguous queries. Second, hybrid retrieval that combines sparse and dense retrieval methods can improve robustness by capturing both lexical and semantic matches. Third, fixed top-k retrieval is often insufficient when both E4 and E5 are frequent. Some queries benefit from more context, while others require stricter filtering. These errors may be improved by modifying the retrieval from top-k to another retrieval approach, such as adaptive thresholds or dynamic reranking can better balance recall and precision. Fourth, incorporating global context, such as a chunk’s position or section role, improves relevance, especially in long or structured documents. Fifth, domain-specific or fine-tuned embedding models for encoding (and subsequently retrieving) documents can significantly boost retrieval accuracy and reduce hallucinations. Finally, metadata filtering enhances precision by using structured fields (e.g., source, section, or recency) to prioritize relevant content, particularly in enterprise or multi-source settings.Reranking Errors

[0071] Similar to retrieval errors, reranking errors may typically mean that the reranker 250, when narrowing and organizing the retrieved document chunks 240, has improperly excluded relevant document chunks from the context documents 260 or, conversely, has included irrelevant document chunks that may make it more difficult for the generator 270 to discern the correct information for a response.

[0072] Error 7, Low Recall: Although the necessary chunks are retrieved, they are reranked too low and not forwarded to the generation model. Low recall produces false negatives, where relevant data is available (in the retrieved document chunks 240) but unintentionally ignored and not provided to the generator 270.

[0073] Low Recall Error Example:

[0074] Query : According to Greenfield, Fairview, Court and Vandalia, Bayside, Court, whose sentencing time is longer, H. Price or G. Torres?

[0075] Response : G. Torres’ sentencing time is longer, four years, compared to H. Price, whose sentence is not mentioned in the provided context.

[0076] Ground Truth : H. Price was sentenced to eight years of imprisonment, while G. Torres was sentenced to four years imprisonment. H. Price’s sentencing time is longer.

[0077] Cause : The chunk with H. Price’s sentencing was retrieved, but was ranked below the reranker threshold and not passed to the generator.

[0078] Error 8, Low Precision: Irrelevant chunks are ranked highly and forwarded to the generator, leading to the generation model being confused by noise. Low precision leads to false positives, where the generator is overly confident in noisy context.

[0079] Low Precision Error Example:

[0080] Query : On which stock exchange is Retail Emporium publicly traded?

[0081] Response : The New York Stock Exchange.

[0082] Ground Truth : Unable to answer.

[0083] Cause : Highly ranked but irrelevant chunks reference New York, leading the model to make an inappropriate conclusion.

[0084] Reranking Error Modifications: Modifying the reranker may include modifying the reranking module with a different type of reranker or modifying reranking parameters or criteria. The two dominant approaches are cross-encoders, which jointly encode query-chunk pairs, and LLM-based rerankers, which use prompted models to assess candidates. Cross-encoders are efficient, while LLM rerankers offer greater flexibility but at higher cost.

[0085] Still, rerankers may miss key context (E7) or over-rank irrelevant chunks (E8), particularly when domain relevance is poorly understood. When these errors occur, the re-ranker may be finetuned on in-domain data to improve performance, and even small amounts of labeled data can yield significant gains in reranking efficacy. More specifically, incorporating hard negatives, which are plausible but nonrelevant passages, further helps the model learn fine-grained distinctions and reduce false positives and particularly correct for E8.Generation Errors

[0086] Generation errors may include errors in which the generator, although appearing to have appropriate context for responding to the query, nonetheless generates a response that fails to correctly account for the context documents 260, misunderstands the query, refuses to generate a response when appropriate, generates a response when insufficient information is available, and so forth.

[0087] Error 9, Abstention Failure: The model should have abstained, but instead answers incorrectly. Abstention is appropriate when the answer is not available in the corpus, or when the query is ambiguous.

[0088] Abstention Failure Error Example:

[0089] Query : How much did Green Fields Agriculture Co. raise through large-scale financing in December 2018?

[0090] Response : Green Fields Agriculture Co. did not raise any funds in December 2018.

[0091] Ground Truth : Unable to answer.

[0092] Cause : The retrieved context contains information about 2018, but not about fundraising. The model mistakenly assumes fundraising did not occur, but this was not stated in the corpus.

[0093] Error 10, Fabricated Content: Although the query is answerable, the response includes unverifiable information not grounded in the retrieved chunks nor supported by external evidence.

[0094] Fabricated Content Error Example:

[0095] Query : According to the hospitalization records of Southport General Hospital, summarize the past medical history of K. Mendoza.

[0096] Response : K. Mendoza has a history of Parkinson’s disease, with symptoms including tremors, bradykinesia, and postural instability.

[0097] Ground Truth : K. Mendoza was generally healthy prior to the onset of his symptoms.

[0098] Cause : The model fabricates a history of Parkinson’s disease, which is not in the context.

[0099] Error 11, Parametric Overreliance: The LLM relies on its internal (parametric) knowledge rather than the retrieved documents forming the context documents 260. Internal knowledge may be correct and factual (i.e., not necessarily fabricated / hallucinated) but is not properly a response based on the context documents 260.

[0100] Parametric Overreliance Error Example:

[0101] Query : What was the total amount of liabilities of Artistic Creations Inc. at the end of 2019?

[0102] Response : The total amount of liabilities of Artistic Creations Inc. at the end of 2019 is $150 million - $20 million (acquisition) - $50 million (financing) - $10 million (investment) + $15 million (debt restructuring) = $85 million.

[0103] Ground Truth: Unable to answer.

[0104] Cause : The model does a calculation based on parametric financial knowledge instead of acknowledging that it has insufficient information.

[0105] Error 12, Incomplete Answer: In this error subtype, the response generated is based on the context documents 260 and is correct, but misses critical details preventing the response from being complete.

[0106] Incomplete Answer Error Example:

[0107] Query : How did the dividend in July 2017 reflect AMS Inc.’s strong financial performance?

[0108] Response : The dividend in July 2017 reflected AMS Inc.’s strong financial performance, which was driven by market demand and changes in product prices, resulting in an operating income of $450 million and a net profit of $60 million.

[0109] Ground Truth : The dividend boosted returns, demonstrating the company’s ability to generate sufficient profits and maintain a healthy cash flow.

[0110] Cause : The response affirms the basis of the question, but does not analyze the situation.

[0111] Error 13, Misinterpretation: The generator misuses or misrepresents retrieved content.

[0112] Misinterpretation Error Example:

[0113] Query : According to the judgments of Trenton, Springfield and Hamilton, Harrison Courts what sentences were given to Q. Ruiz and M. Ward?

[0114] Response : M. Ward was sentenced to four years imprisonment, and Q. Ruiz has the right to appeal this judgment within 30 days.

[0115] Ground Truth : M. Ward was sentenced to four years of imprisonment, and Q. Ruiz was sentenced to 5 years of imprisonment and fined $5,000.

[0116] Cause : The model misinterprets facts about two defendants as being related and incorrectly combines them for the answer.

[0117] Error 14, Contextual Misalignment: The response is factual and comes from related information in the corpus, but does not address the query.

[0118] Contextual Misalignment Error Example:

[0119] Query : According to the judgment of Preston, Lancaster, Court, summarize the facts of M. Harris’s crimes.

[0120] Response : M. Harris was found guilty of homicide and was sentenced to life imprisonment.

[0121] Ground Truth : M. Harris committed the crime of intentional homicide by tampering with the brakes of her business partner.

[0122] Cause : The response contains factual information, but discusses sentences rather than the requested facts of the crimes.

[0123] Error 15, Chronological Inconsistency: The response presents events or facts in the wrong temporal order, or confuses past, present, or future timelines.

[0124] Chronological Inconsistency Error Example:

[0125] Query : Which company, Green Fields Agriculture Ltd. or JetWing Aviation, made changes to their board of directors earlier?

[0126] Response : Green Fields made changes to their board of directors earlier, in December 2021, while JetWing made changes in October 2021.

[0127] Ground Truth : JetWing made changes earlier in September 2021, while Green Fields made changes in December 2021.

[0128] Cause : The model provides a wrong date, and incorrectly considers December earlier than October.

[0129] Error 16, Numerical Error: The response includes incorrect calculations, quantities, or misrepresents numerical data from the retrieved documents.

[0130] Numerical Error Example:

[0131] Query : Which company reduced its liabilities by a larger amount, InnovateTech, Inc., or Sparkling Clean Housekeeping Services?

[0132] Response : InnovateTech reduced its liabilities by a larger amount, a total of $50 million, compared to Sparkling Clean’s £500,000.

[0133] Ground Truth : InnovateTech, Inc. reduced its liabilities by a larger amount ($30 million) compared to Sparkling Clean (£500,000).

[0134] Cause : The model incorrectly added together two numbers from the context to produce $50 million.

[0135] Generation Error Modifications: Generation-stage errors can be mitigated through abstention modeling, answer validation, prompt engineering, and tool augmentation. For abstention failures (E9), generator 270 can include abstention-aware modules, such as ambiguity detection, conformal abstention, or fine-tuning approaches like Trust-Align. For Fabricated Content (E10), post-generation validation such as Chain-of-Verification or critique modules encourage fact-checking and grounding. Errors related to context misuse (E11-E14) often stem from noisy retrieval; refinement modules can filter context before generation, while Speculative RAG improves alignment by drafting answers from distinct subsets of retrieved documents, then verifying them. Query decomposition helps reduce incomplete answer errors (E12) by breaking complex queries into sub-questions, especially for comparisons, causal questions, or multi-step reasoning. For chronological and numerical errors (E15–E16), structured prompting, timeline reasoning, or tool-augmented generation with code modules like PAL can boost reliability. Finally, prompt tuning helps encode domain-specific expectations, terminology, and answer formats, making generation more aligned with task requirements. Few-shot prompting with curated or dynamically-selected examples address all generation errors by modeling grounded, complete, and context-aware responses without task-specific fine-tuning.

[0136] To improve RAG pipelines by using this information about the stages of the RAG pipeline 200 and related errors, response errors are detected and used to identify the stage that may be associated with the error along with the subtype of error so that modifications to the RAG pipeline 200 can address the error effectively.

[0137] FIG. 3 shows an example flow for automatically detecting errors in generated responses from a RAG system, according to one embodiment. As discussed above, the RAG system may generate a response using a large language model applied to a context of retrieved documents (or more precisely, document chunks) considered relevant to the query. Because the generated response 320 is typically a freeform text response that may have varying lengths, whether a generated response 320 is correct may be affected by various additional information. As discussed above, a verification data set may include a set of queries along with a set of verified responses that constitute a “ground truth” response that is the desired response from the RAG system.

[0138] To detect erroneous responses from the RAG system, each query 300 from the validation data set may be input to the RAG system 310 for processing by the RAG system 310 as discussed above (e.g., by retrieving relevant chunks, reranking, and applying a generator) to obtain a generated response 320 for the query 300 by the RAG system 310. The generated response 320 along with the query 300 and verified response 340 are applied to a large language model 350 to determine whether the generated response 320 is sufficiently similar to the verified response 340 to be considered response valid 360 or response error 370. In some embodiments, the large language model 350 may also be prompted with the context documents 330, such that the large language model 350 may also determine whether differences between the generated response 320 and verified response 340 are acceptable in view of the particular source documents relevant to this query. In some embodiments, the context documents 330 may include the retrieved chunks and / or the reranked chunks forming the context used by the generator of the RAG system 310. In various embodiments, the large language model 350 may be the same large language model used by the RAG system 310 in generating responses, or may be a query to another large language model 350. By generating responses 320 and evaluating them by the large language model 350 with relevant additional information, the queries in the validation data set may be automatically evaluated to detect response errors 370 that may be further investigated to detect the potential source and subtype of the error. When querying the large language model 350, the model may be prompted to evaluate the correctness of the generated response 320 along with the recall of the ground truth, completeness, and overall correctness, along with an option to abstain. More formally, this evaluation for response errors 370 may be performed on each of the N validation data points individually to yield a subset of N err data points identified as response errors 370. This process may be performed by the response error detection module 120 to identify queries in the verification data set that yield errors when applied to the RAG system.

[0139] FIG. 4 illustrates the detection of an error stage for a RAG pipeline, according to one embodiment. After detecting that the generated response for the RAG system is a response error, the stage of an error may be detected along with a subtype of the error. To do so, a large language model may receive a context 400 for stage error evaluation 410 and identify one or more stage errors 420 for the response error. By using a large language model error stage detection and subtype determination, the stage of the RAG system responsible for the error can be flexibly identified without requiring explicitly defined rules for error, which may struggle to effectively detect errors with the flexible content used in the RAG pipeline because queries, answers, source documents, and so forth may generally be free text that is difficult to process with normal evaluative processes, particularly because semantic meaning is important to understanding the source of errors in the RAG system. By articulating information to the language model about the stages of the RAG system and the types of errors, the large language model may effectively detect stage errors 420.

[0140] To do so, a context 400 is constructed for the error stage evaluation 410 that includes relevant information for evaluating an error at the respective stages of the RAG pipeline. In the example shown in FIG. 4, the context for stage error evaluation 400 includes information about the query, verified response, and generated response, along with intermediate information that may have been used at each stage in the RAG pipeline. By including the intermediate information and data about the stages of the RAG pipeline, the stage responsible for the error can be more effectively determined by the LLM. For example, the context 400 may include the retrieved document chunks and reranked chunks forming context documents for the generator for evaluating whether the reranking process effectively processed the retrieved chunks to the reranked chunks used in the context documents.

[0141] In some embodiments, all potential stages are evaluated simultaneously for contribution to the error. In these embodiments, the context 400 may include information relevant to each of the RAG stages. For example, the context 400 may include all intermediate information used during the RAG generation such as the retrieved chunks, adjacent chunks to the retrieved chunks (for example, to determine whether the error is a chunking error that too-narrowly chunks the source documents or has insufficient overlap across chunks), evaluated chunk similarity (e.g., for retrieval), reranked chunks, and so forth. The context may also include a stage error prompt to the LLM that specifies the stages of the RAG pipeline along with a description of the indications that a particular stage may be responsible for the error. For example, a description of the errors associated with each stage or to particular error subtypes similar to the discussion above may be included in the stage error prompt.

[0142] In some embodiments, the large language model determines the stage and error subtype in a single large language model call, such that the large language model directly outputs a subtype (e.g., one of the errors 1-16 described above) and its related error stage. In some embodiments, the determination of error stages and error subtypes may be determined in sequence, such that the error stage is determined first, and given the identified stage, an additional query is made to the large language model to determine the particular subtype based on a context including data relevant to that stage. For example, when the stage error is determined to be the chunking stage, the subtype may be determined by providing information more specifically related to that stage, such as the query, retrieved chunks, and adjacent chunks to determine which subtype of chunking error is present in the operation of the RAG.

[0143] In additional embodiments, rather than evaluate potential errors for all stages simultaneously, the error stages may be evaluated sequentially, such that the earliest pipeline stage is evaluated for an error first; when no error is identified in that stage, a subsequent stage is evaluated for an error. As an example, initially, the chunking stage may be evaluated for an error and, when there is no chunking error identified, then the retrieval stage is evaluated in a separate large language model call. By separating each stage, the first-occurring stage causing an error may be more reliably identified with context data particularly relevant to the information available at that stage.

[0144] By providing the taxonomy of errors describing the stages and types of errors along with the intermediate information for each stage, the large language model may effectively determine the stage errors 420 along with error subtypes, enabling automated error detection and identification of the subtype of error causing the error. As such, this provides an automatic error-classification pipeline leveraging LLMs for evaluating the RAG pipeline. By evaluating a RAG system to understand the distribution of error types it produces, these errors can be corrected in the RAG pipeline with appropriate modifications appropriate for the prevalent error subtypes that would not be possible without discrete identification of the causes of the error.

[0145] Because the large language model may include stochastic elements that result in the potential for different responses to the error detection each time the large language model is queried (with the same context), in some embodiments, the error stage and error subtype evaluation is performed multiple times for the same validation query. For example, the error subtype evaluation may be determined three, five, or ten times or more to determine the frequency that different error subtypes are identified for the set of validation queries. The frequency that each subtype is identified may then be determined and used to modify the RAG pipeline as discussed below.

[0146] FIG. 5 provides an example method for detecting and correcting for errors in a RAG system, according to one embodiment. Initially, a set of validation queries is identified that have corresponding validated responses representing the “ground truth” that generated responses from the RAG system should semantically match. To determine which validation queries that the RAG system generates erroneous responses, the RAG system is applied 500 to the validation queries to obtain respective generated responses for the validation queries. Next, each generated response is evaluated 510 relative to the respective validated response errors with a large language model as discussed above to determine which generated responses can be characterized as response errors. The response errors may be determined based on the query, validated response, generated response, and in some instances in conjunction with a retrieved context for the generation, such that whether the generated response is an error can be properly contextualized in view of the relevant documents.

[0147] For the set of validation queries and associated generated responses that are response errors, the error stage responsible for the error is identified 520 along with identifying 530 a subtype error characterizing the reason for the error. As discussed above, the error stage and subtype may be identified 520, 530 simultaneously in a single query to a large language model or may be determined sequentially. Similarly, the error stage 520 may be identified with a large language model call that evaluates all stages simultaneously, or each stage may be sequentially evaluated for an error along with the intermediate information related to each stage. The large language model used for error stage and error subtype identification 520, 530 may be the same large language model used by the RAG pipeline and / or the large language model used for evaluating 510 the generated response. In additional embodiments, these may be different large language models. For example, the RAG system may be administered by a separate system or with a large language model specialized for query response based on retrieved documents, while the large language model used for response error and stage / subtype identification may be another large language model.

[0148] The error subtype identification 530 may be performed for each verification query in the verification data set evaluated 510 as a response error. In some embodiments, the error stage and error subtype identification may be performed repeatedly for the same verification query to determine the distribution of detected error stage and subtypes.

[0149] Using the error subtypes, the system (e.g., via the error correction module 130) may modify 540 the RAG system based on the identified error subtype 530. For example, the identified error subtypes may be accumulated to determine the most frequent error subtypes across the verification queries and, when applicable, across the different identifications of error subtypes for the same verification query. Across the set of verification data, the most frequent error subtypes may then be identified and used to modify the RAG system with associated modifications for those error subtypes. By identifying specific error stages and subtypes, the modifications to the RAG system may be more effectively targeted to aspects of the RAG system and target corrections that may otherwise conflict with corrections for other subtypes. For example, by identifying that the most common error occurs in the chunking stage and is of the subtype “overchunking,” the modification 540 may apply a modification specifically addressing overchunking, particularly by increasing the size of document chunks, modifying the algorithm for determining breaks between chunks, and so forth.

[0150] The various modifications 540 that may be applied to the RAG system thus include modifications associated with the identified subtypes and may include the modifications discussed above. By selecting modifications based on the identified errors, the RAG system architecture may also avoid additional modification or complexity of components that may arise when implementing additional modules to the RAG system. For example, an initial RAG pipeline may use a cosine similarity to score relevance of document chunks to the query (e.g., between the query encoding and chunk encoding). When applying the error detection of FIG. 5., there may be few errors related to chunk retrieval, suggesting that this approach may be suitable for this data set. As a result, though other, more complex chunk retrieval processes may be available for implementation, because there are few errors related to chunk retrieval with cosine similarity, that aspect may be unmodified and remain relatively simple.

[0151] This approach thus enables evaluation of errors in a RAG system that can direct where additional modification and complexity is beneficial to reduce RAG errors without overly complicating other components of the pipeline. This may enable stages of the pipeline without frequent errors to maintain simpler processing or reduced memory requirements and more effectively direct limited processing or memory budgets to stages responsible for such errors. After modification 540 to the RAG stages based on the identified errors, in some embodiments, the process may be repeated to detect errors in the RAG system after modification, such that the RAG system can be iteratively improved with automatic response error detection and modification of the responsible stages based on the error subtype causing the error.

[0152] In summary, this evaluation system and error detection system provides an entry point for characterizing problems in and improvement of RAG pipelines, which can be complex and opaque to developers. Instead of manually sifting through individual response generations, this system automatically captures intermediate information like retrieved and reranked chunks and distills the information into high-level descriptive statistics in characterizing the subtype error frequency. Hence, this approach focuses on understanding the types and causes of errors that occur so that modifications can be intelligently prioritized to improve aspects of the RAG pipeline.

[0153] The foregoing description of the embodiments of the invention has been presented for the purpose of illustration; it is not intended to be exhaustive or to limit the invention to the precise forms disclosed. Persons skilled in the relevant art can appreciate that many modifications and variations are possible in light of the above disclosure.

[0154] Some portions of this description describe the embodiments of the invention in terms of algorithms and symbolic representations of operations on information. These algorithmic descriptions and representations are commonly used by those skilled in the data processing arts to convey the substance of their work effectively to others skilled in the art. These operations, while described functionally, computationally, or logically, are understood to be implemented by computer programs or equivalent electrical circuits, microcode, or the like. Furthermore, it has also proven convenient at times, to refer to these arrangements of operations as modules, without loss of generality. The described operations and their associated modules may be embodied in software, firmware, hardware, or any combinations thereof.

[0155] Any of the steps, operations, or processes described herein may be performed or implemented with one or more hardware or software modules, alone or in combination with other devices. In one embodiment, a software module is implemented with a computer program product comprising a computer-readable medium containing computer program code, which can be executed by a computer processor for performing any or all of the steps, operations, or processes described.

[0156] Embodiments of the invention may also relate to an apparatus for performing the operations herein. This apparatus may be specially constructed for the required purposes, and / or it may comprise a general-purpose computing device selectively activated or reconfigured by a computer program stored in the computer. Such a computer program may be stored in a non-transitory, tangible computer readable storage medium, or any type of media suitable for storing electronic instructions, which may be coupled to a computer system bus. Furthermore, any computing systems referred to in the specification may include a single processor or may be architectures employing multiple processor designs for increased computing capability.

[0157] Embodiments of the invention may also relate to a product that is produced by a computing process described herein. Such a product may comprise information resulting from a computing process, where the information is stored on a non-transitory, tangible computer readable storage medium and may include any embodiment of a computer program product or other data combination described herein.

[0158] Finally, the language used in the specification has been principally selected for readability and instructional purposes, and it may not have been selected to delineate or circumscribe the inventive subject matter. It is therefore intended that the scope of the invention be limited not by this detailed description, but rather by any claims that issue on an application based hereon. Accordingly, the disclosure of the embodiments of the invention is intended to be illustrative, but not limiting, of the scope of the invention, which is set forth in the following claims.

Claims

1. A system comprising: a processor that executes instructions; anda non-transitory computer-readable medium having instructions executable by the processor for:applying a retrieval-augmented generation (RAG) system to each of a plurality of queries to obtain a respective generated response based on a set of source documents, the RAG system applying a plurality of stages to respond to a query with at least a portion of source documents provided as context to a first large language model (LLM);determining whether each generated response is a response error by comparing each generated response with a verified response for the respective query;for each response error:determining at least one stage error identifying a stage of the RAG system responsible for the error by applying at least the respective query, generated answer, verified response, and retrieved documents to a second LLM; anddetermining an error subtype for the at least one stage error of the RAG system; andmodifying the RAG system based on the determined error subtype for the response errors.

2. The system of claim 1, wherein the at least one stage error and the error subtype are determined in a single application of the second LLM.

3. The system of claim 1, wherein the error stage is selected from the plurality of stages of the RAG system, including chunking, retrieval, reranking, and generation.

4. The system of claim 1, wherein determining the at least one stage error comprises repeatedly applying the second LLM.

5. The system of claim 1, wherein determining the at least one stage error includes applying retrieved document chunks to the second LLM.

6. The system of claim 5, wherein determining the at least one stage error includes applying adjacent chunks of the retrieved document chunks to the second LLM.

7. The system of claim 1, wherein modifying the RAG system comprises modifying the chunk size of documents retrieved for queries.

8. The system of claim 1, wherein modifying the RAG system comprises modifying the retrieval of document chunks based on the query.

9. The system of claim 1, wherein modifying the RAG system comprises modifying reranking of retrieved documents for the query.

10. The system of claim 1, wherein the at least one stage error is determined separately from determining the error subtype.

11. A method comprising:applying a retrieval-augmented generation (RAG) system to each of a plurality of queries to obtain a respective generated response based on a set of source documents, the RAG system applying a plurality of stages to respond to a query with at least a portion of source documents provided as context to a first large language model (LLM);determining whether each generated response is a response error by comparing each generated response with a verified response for the respective query;for each response error:determining at least one stage error identifying a stage of the RAG system responsible for the error by applying at least the respective query, generated answer, verified response, and retrieved documents to a second LLM; anddetermining an error subtype for the at least one stage error of the RAG system; andmodifying the RAG system based on the determined error subtype for the response errors.

12. The method of claim 11, wherein the at least one stage error and the error subtype are determined in a single application of the second LLM.

13. The method of claim 11, wherein the error stage is selected from the plurality of stages of the RAG system, including chunking, retrieval, reranking, and generation.

14. The method of claim 11, wherein determining the at least one stage error comprises repeatedly applying the second LLM.

15. The method of claim 11, wherein determining the at least one stage error includes applying retrieved document chunks to the second LLM.

16. The method of claim 15, wherein determining the at least one stage error includes applying adjacent chunks of the retrieved document chunks to the second LLM.

17. The method of claim 11, wherein modifying the RAG system comprises modifying the chunk size of documents retrieved for queries.

18. The method of claim 11, wherein modifying the RAG system comprises modifying the retrieval of document chunks based on the query.

19. The method of claim 11, wherein modifying the RAG system comprises modifying reranking of retrieved documents for the query.

20. A non-transitory computer-readable medium, the non-transitory computer-readable medium comprising instructions executable by a processor for:applying a retrieval-augmented generation (RAG) system to each of a plurality of queries to obtain a respective generated response based on a set of source documents, the RAG system applying a plurality of stages to respond to a query with at least a portion of source documents provided as context to a first large language model (LLM);determining whether each generated response is a response error by comparing each generated response with a verified response for the respective query;for each response error:determining at least one stage error identifying a stage of the RAG system responsible for the error by applying at least the respective query, generated answer, verified response, and retrieved documents to a second LLM; anddetermining an error subtype for the at least one stage error of the RAG system; andmodifying the RAG system based on the determined error subtype for the response errors.