Having previously built a “Self-RAG” in Copilot Studio, this time I’ll implement “CRAG.”

CRAG
CRAG (Corrective Retrieval Augmented Generation) is a RAG technique proposed around February 2024 that offers the advantage of reducing hallucinations compared to traditional RAG (Retrieval Augmented Generation).
The key characteristic of CRAG is the use of a Retrieval Evaluator to assess the relevance between retrieved documents and the user’s question.
- Correct (highly relevant): Generate responses using the documents
- Incorrect (low relevance): Generate responses from web searches without using the retrieved documents
- Ambiguous (difficult to determine): Generate responses using both the retrieved documents and web search results
Building CRAG in Copilot Studio

Implementation
Since our goal is simply to demonstrate how to build CRAG in Copilot Studio, we won’t focus on optimizing accuracy (such as refining prompts).
SharePoint Search


*Note: “Excluded Keywords” remains here only because we reused the prompt from the previous (Self-RAG) implementation. It’s not actually necessary for this purpose.

Here are examples of user questions and their corresponding search queries. Use these examples to guide your transformation of the input question. Example Input 1: "How to connect to a database with Python?" Example Output: "Python database connection method" Example Input 2: "What impact does climate change have on ecosystems?" Example Output: "Climate change ecosystem impact" Additionally, if certain words are specified as "excluded keywords," ensure that these words are NOT included in the generated search query. For example: Excluded Keywords: ["Python connection"] Example Input: "How to connect to a database with Python?" Example Output: "Database connection method" Now, based on these examples and the excluded keywords, transform the following user question into an effective search query, avoiding the specified excluded keywords. Input: {input} Excluded Keywords: {excluded_keywords}



Document Relevance Evaluation




# Task Evaluate relevance between user question and retrieved document on a 0.0-1.0 scale # Evaluation Criteria ## 1.0 - Document provides complete & direct answer (Example: Contains specific numbers/dates/names matching query) ## 0.7-0.9 - Directly relevant but requires: - Context synthesis OR - Partial information extraction OR - Terminology clarification ## 0.4-0.6 - Partial relevance through: - Shared domain knowledge - Indirect supporting evidence - Related concepts without direct answer ## 0.1-0.3 - Barely relevant with only: - Common keywords - Generic domain overlap - Indirect conceptual connections ## 0.0 - No semantic/contextual connection # Output Format - Relevance Score: [Strictly 0.0-1.0 numeric value only] # Input Data Query: {question} Retrieved Document: {document}

Checking Relevance Scores



Case 1: Maximum Score is 0.8 or Higher →Generate Response from Highly Relevant Documents



Case 2: Maximum Score is Below 0.8 →Generate Response from Web Search and Moderately Relevant Documents

*Note: In the “Incorrect” case (Web search only), k_in will be empty.


*Note: Scraping the sites obtained from web searches would increase accuracy, but we’ll skip that step here.
*Note: Ideally, we would regenerate search terms specifically for web searches, but we’ll skip that as well.


Answer Generation


If the query cannot be answered based on the provided context, respond with 'The provided information is not sufficient to answer this question.' Otherwise, generate a complete and accurate answer, and as an annotation, output the name of the referenced files at the end. # query {query} # information {information}
Testing the Implementation






So we’ve confirmed that CRAG successfully improves accuracy.
Since this solution relies on “web search,” it may not improve response accuracy for RAG systems searching internal documents, but it’s worth remembering this approach as it might be useful in certain scenarios.
コメント