前回、Copilot Studioで『Self-RAG』を構築したので、今回は『CRAG』を組んでみる。
CRAG
CRAG(Corrective Retrieval Augmented Generation)は2024年2月頃に提案されたRAGの手法で、従来のRAG(Retrieval Augmented Generation)よりハルシネーションが減らせる点がメリット。
CRAGの特徴は、検索評価(Retrieval Evaluator)を使用し、検索したドキュメントとユーザーの質問の関連性を評価する点にある。
- Correct(関連性高い):ドキュメントを使用して回答を生成
- Incorrect(関連性低い):検索で使用したドキュメントを使用せず、Web検索から回答を生成
- Ambiguous(判断が難しい):取得したドキュメントとWeb検索療法を使用し回答を生成
Copilot StudioでCRAGを構築する
検索評価にはGPT4oを、Web検索にはSerpAPIを利用する。

構築
今回もCopilot StudioでCRAGを組んでみることが目的なので、精度(プロンプトの良し悪し等)は未考慮。
SharePointの検索


※「Excluded Keywords」は前回(Self-RAG)のプロンプトを流用したから残っているだけ。本来は不要。

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: "Pythonでデータベースに接続する方法は?"
Example Output: "Python データベース 接続方法"
Example Input 2: "気候変動が生態系に与える影響は?"
Example Output: "気候変動 生態系 影響"
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 接続"]
Example Input: "Pythonでデータベースに接続する方法は?"
Example Output: "データベース 接続方法"
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}


ドキュメントの関連性評価




# 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}

関連スコアのチェック



ケース1:最大スコアが0.8以上 →関連性の高いドキュメントから回答を生成



ケース2:最大スコアが0.8未満 →Web検索と関連性が中程度のドキュメントから回答を生成

※Incorrectの場合(Web検索のみの場合)は、k_inは空になる。


※Web検索で取得したサイトをスクレイプした方が精度は上がるけど、今回は省略。
※本来はWeb検索用に検索ワードを再生成するけど、こちらも今回は省略。


回答生成


If the query cannot be answered based on the provided context, respond with '提供された情報ではこの質問に答えることができません。' .
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}
動作確認






ということで、CRAGも無事精度が上がることを確認。
「Web検索」という解決方法なので、社内文書を検索するRAGとかだと回答精度が上がらない可能性もあるけど、こんな方法もあったくらいに覚えておくと役に立つかも。







コメント