Amazon Bedrock、自動生成フィルタで契約検索精度を向上
本文の状態
日本語全文を表示中
詳細モードで約19分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
AWS Machine Learning Blog
AWS は Amazon Bedrock Knowledge Bases を活用した AIDA ソリューションにより、契約書の文脈を考慮した自動フィルタリングとメタデータ付与による検索精度の向上を実現し、法務判断の効率化を図る。
AI深層分析を開く2026年8月19日 02:50
AI深層分析
キーポイント
AIDA ソリューションの概要
AWS が提供する AI-Driven Annotation (AIDA) は、非構造化契約書を検索可能なインテリジェンスへ変換し、自然言語での質問応答を可能にする。
RAG アーキテクチャの活用
Amazon Bedrock Knowledge Bases を基盤とした RAG 構造により、文脈に依存する法的ドキュメントから重要な条項を見逃さずに抽出する仕組みを構築している。
検索精度向上の手法
暗黙的・明示的なフィルタリングとメタデータ付与されたチャンキング技術を採用し、適切な法的文脈とアクセス境界内でユーザーを誘導する。
意味論的セグメンテーションとメタデータ活用
契約文書を検索に最適化された意味論的に意味のあるセグメントに分割し、インゲーション時に付与されるメタデータがインテリジェントなフィルタリングを可能にする。
ベクトルデータベースとセキュリティ基盤
Amazon OpenSearch Service や Amazon S3 Vectors などのベクトルデータベースにエンベディングを保存し、IAM ポリシーによるロールベースアクセス制御と CloudWatch ログで監査証跡を維持する。
重要な引用
AIDA enables users to ask natural-language questions across large contract repositories
Legal documents are highly contextual, and retrieval-augmented generation (RAG)-based systems can surface more content than a language model can effectively process.
Specifically, we explore how AIDA uses implicit and explicit filtering, along with metadata-enriched chunking in Amazon Bedrock Knowledge Bases
The metadata supplied during ingestion plays a critical role in the system's ability to apply intelligent filtering, particularly through the implicit filtering mechanism that distinguishes this architecture from standard RAG implementations.
編集コメントを表示
編集コメント
契約書管理における文脈の重要性を強調し、RAG の限界を補うメタデータ活用という実務的な解決策を示している。企業法務領域での AI 導入において、単なる検索精度だけでなく「正しい文脈」を提供する仕組みの構築が重要であることを再認識させる内容である。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
企業は、権利や更新オプション、地理的制限、コンプライアンス義務といった重要なビジネス判断を下すために、膨大な量の複雑な法的契約書に依存しています。エンターテインメントやメディア業界のように、複数の管轄区域にまたがる数千件の契約書を管理する組織にとって、この作業はまだ手作業が中心であり、時間がかかり、コストが高く、スケーラビリティにも課題があります。
AWS を活用した AI ドライブド・アノテーション(AIDA)ソリューションは、非構造化された契約書を検索可能で実行可能なインテリジェンスへと変換することで、この課題の解決を支援します。AIDA を使えば、ユーザーは大規模な契約書レポジトリに対して自然言語で質問できますが、正確な回答を得るにはセマンティック検索だけでは不十分です。法的文書は文脈に強く依存しており、RAG(Retrieval-Augmented Generation)ベースのシステムでは、言語モデルが効果的に処理できる範囲を超えたコンテンツが引き出されてしまう可能性があります。どの抜粋を引き出すかを慎重に制御せず、ドキュメントレベルの文脈を十分に提供しない場合、重要な条項が見落とされたり誤解されたりするリスクがあります。
本稿では、AIDA の高レベルな仕組みと、それがこれらの課題にどう対処するかについて説明します。具体的には、ユーザーが適切な契約書に導かれ、正しい法的文脈の中で、かつ適切なアクセス境界内でのみ情報を得られるよう支援する方法を解説します。特に、AIDA が Amazon Bedrock Knowledge Bases におけるメタデータ強化型チャンキング(chunking)と併用した暗黙的・明示的なフィルタリングを活用し、契約書の検索精度を劇的に向上させる仕組みについて掘り下げていきます。
Solution overview

この参考アーキテクチャ図は、AIDA が Amazon Bedrock Knowledge Bases を基盤とした RAG 構造を活用し、知的な文書照会システムを構築する方法を示しています。コンポーネント間のデータ転送では、HTTPS/TLS 1.2+ によるトランジット暗号化が使用されます。これには、Amazon Bedrock Knowledge Bases へのドキュメントアップロード、埋め込みモデルへの API 呼び出し、ベクトルデータベースの照会、およびクライアントアプリケーションへのレスポンス配信が含まれます。Amazon Bedrock に保存されるデータについては、AWS の共有責任モデル が適用されます。
実装は以下の体系的なワークフローに従います。
データ取り込みフロー
ステップ 1: ドキュメントの取り込みとメタデータ設定
このアーキテクチャは、契約を Amazon Bedrock Knowledge Bases に同期し、構造化されたメタデータファイルと共に格納することから始まります。メタデータには、当事者、有効日、終了日、管轄権など、重要な契約属性を含める必要があります。これにより、後段の処理で強力なフィルタリング機能を発揮できるようになります。
ステップ 2: チャンキング機構の実装
ナレッジベースの構成フェーズでは、検索に最適化された意味的に意味のあるセグメントへと契約書を分割する高度なチャンキング機構が実装されています。このチャンキング戦略により、各セグメントには十分な文脈を提供しつつ、効率的な処理に必要な簡潔さも保たれています。
インgestion 時に付与されるメタデータは、システムが知的なフィルタリングを適用する能力において決定的な役割を果たします。特に、標準的な RAG(検索拡張生成)実装とこのアーキテクチャを区別する「暗黙的フィルタリング機構」を通じて、その効果が発揮されます。
ステップ 3:ベクトルデータベースへの保存
ドキュメントの取り込みと処理が完了すると、システムはドキュメントチャンキングをベクトル埋め込みに変換し、Amazon Bedrock ナレッジベースで利用可能な複数のベクトルデータベースオプションの一つに格納します。具体的には Amazon OpenSearch Service や、Amazon Simple Storage Service (Amazon S3) の機能である Amazon S3 Vectors などです。いずれの選択肢も、保存時の暗号化を有効に設定する必要があります。
このベクトルデータベースは意味検索の基盤となり、単なるキーワード一致に頼るのではなく、概念的に類似したコンテンツを検出可能にします。
知識ベースへのアクセスやモデルの呼び出しは、AWS Identity and Access Management (IAM) ポリシーによって管理され、コンプライアンス目的のための監査証跡を維持するために Amazon CloudWatch のログ機能が有効になっています。
セキュリティ面では、AIDA はプロジェクトスコープに基づくロールを用いて、アプリケーション層で AWS IAM ポリシーを通じてロールベースのアクセス制御を適用しています。これにより、各ユーザーが実行できる操作を制限します。
ユーザーインタラクションフロー
ステップ 4: クエリの埋め込み生成
ユーザーがクエリを入力すると、AIDA は Amazon Bedrock Guardrails を活用してプロンプトインジェクションやデータ漏洩を防ぎます。その後、システムは拡張された RAG ワークフローを実行し、まず Amazon Bedrock の埋め込みモデルを使用してクエリを埋め込みベクトルに変換します。この変換により、ユーザーの質問と保存されたドキュメント断片との意味的な比較が可能になります。
ステップ 5: 暗黙的および明示的なフィルタリング
意味検索を実行する前に、システムは暗黙的かつ明示的なフィルタリングメカニズムを適用します。これは検索精度を大幅に向上させる重要な革新です。
暗黙的フィルタリングでは、ベクトル検索の実行前に、有効日付範囲や特定の契約当事者など、メタデータに基づく条件が自動的に適用されます。この二段階のアプローチでは、まずメタデータの制約によって検索対象を絞り込み、その後にフィルタリングされたサブセット内で意味的な類似度マッチングを行います。これにより、取得される文書は文脈的に適切であるだけでなく、特定のビジネス要件も満たすようになります。
ステップ 6: 意味検索とドキュメントの取得
ベクトルデータベースは、ユーザーのクエリに対する最も関連性の高いドキュメントチャンクを、意味的な類似度スコアに基づいて取得します。通常、コサイン類似度メトリクスを用いて、クエリに最も近い一致が特定されます。この意味検索はフィルタリング済みのドキュメントサブセット上で動作するため、結果の精度と関連性は非常に高くなります。
ステップ 7: プロンプトの拡張
取得されたチャンクは、ユーザーの質問に関連する契約抜粋やメタデータコンテキストを組み合わせた、注意深く構成されたプロンプト内で元のユーザークエリを補強するために使用されます。この拡張されたプロンプトにより、大規模言語モデル(LLM)は、正確で根拠のある回答を生成するために必要な具体的な情報を入手できます。
ステップ 8: LLM の応答生成
拡張されたプロンプトは Amazon Bedrock を介して LLM に渡され、モデルの学習データだけに頼るのではなく、実際の契約文書に基づいた文脈に即した正確な回答が生成されます。このアプローチにより、組織の契約内容に特化した回答を提供することが可能になります。
さらに、AIDA は Amazon Bedrock Guardrails を活用し、コンテンツフィルタリング、機密情報(PII)の保護、プロンプトの安全性制御を適用することで、回答がセキュリティを保ちつつ、企業および法務基準に適合した内容であることを確保しています。
ステップ 9: ソース情報の明示による回答の提供
最終的な回答は Retrieve API を通じてユーザーへ返されます。これにより、回答が関連性を持つだけでなく、特定のソース文書へと遡って検証可能になります。この追跡可能性は、LLM でよく見られるハルシネーション(幻覚)を軽減し、重要なビジネス判断に信頼できる契約インテリジェンスを提供します。
RAG のチューニング
法的契約分析のための RAG システムを開発する際、核心的な課題の一つは、関連性のある情報の量をいかに管理するかです。以下の質問を考えてみましょう:
"カリフォルニア州法に準拠する有効期限が切れたライセンス契約を特定してください。これらの契約はどうやって更新されますか?"
このような問い合わせは、複数の文書にまたがる数百の関連テキストチャンクと一致する可能性があります。RAG の用語では、これら断片は「候補チャンク」と呼ばれます。
Amazon Bedrock がセマンティック検索を実行して関連するドキュメントの抜粋を検出する際、上位 k 件(最大 100 件)の関連候補チャンクを返すように設計されています。しかし、フィルタリングによって除外された残りの候補チャンクには、重要な文脈が含まれている可能性があります。その結果、LLM の回答が不十分になったり、重要な洞察を見落としたり、場合によっては誤った情報になる恐れがあります。
法的文書は非常に構造化されており、文脈に深く依存しています。例えば、カリフォルニア州のライセンス契約における更新条項と、他の管轄区域で規定されたライセンス契約における更新条項では、その運用が異なる場合があります。検索ステップにおいてライセンス契約やカリフォルニア州法を適切にフィルタリングできない場合、システムはサービス契約、秘密保持契約(NDA)、あるいは他州の法律に基づく契約など、無関係な契約を返してしまう可能性があります。これらの文書に有効期限や更新に関する記述が含まれていても、それは本来の質問に対する回答にはなりません。候補となるセットを最も関連性の高いサブセットに絞り込むために、効果的なメタデータフィルタリングが不可欠です。これにより、後続の LLM 呼び出しに必要な文脈が提供され、より正確で完全な回答が可能になります。
これらの検索機能の改善は精度を大幅に高めるものの、AI が生成した契約解釈は、ビジネス判断に使用する前に必ず有資格の法律専門家によるレビューが必要です。AIDA は専門知識を代替するものではなく、それを補完・強化するための意思決定支援ツールとして設計されています。
RAG(Retrieval-Augmented Generation)の精度向上には、主に「インプリシットフィルタリング」と「エクスプリシットフィルタリング」の 2 つのアプローチがあります。次節ではこれらについて詳しく解説します。
インプリシットフィルタリング
Amazon Bedrock の Knowledge Bases では、「インプリシットフィルタリング」という強力な機能が提供されています。これは、各クエリで明示的なフィルタ式を記述しなくても、メタデータ属性に基づいて検索結果を自動的に絞り込む機能です。
このアプローチでは、意味検索を実行する前にドキュメントのメタデータを基にベクトルストアを事前フィルタリングします。これにより、検索対象となるドキュメントの範囲が最も関連性の高いものに限定され、検索空間が大幅に縮小されます。
インプリシットフィルタリングは、以下の 2 つの段階で動作します。
ステージ 1:メタデータによる事前フィルタリング
意味類似度検索を実行する前に、システムは自動的にメタデータに基づく条件を適用します。Knowledge Base に登録される各ドキュメントには、カスタムメタデータファイル(1 ドキュメントあたり最大 10 KB)を付与できます。これには、有効期限やドキュメントタイプ、関係者、あるいはユースケースに合わせた独自フィールドなどの属性を含めることが可能です。
ステージ 2:意味検索
メタデータフィルタリングによって対象ドキュメントが絞り込まれた後、システムはその限定されたセット内でのみベクトル類似度検索を実行します。これによりノイズや無関係な情報が削減され、検索精度の向上に寄与します。
エクスプリシットフィルタリング
アプリケーション層で明示的なフィルタリングを適用することで、ユーザー入力に依存せず、一貫した検索結果を提供できます。このアプローチにより、検索エンジンが独自に解釈するのではなく、ビジネスポリシーやコンプライアンス要件、組織の制約に沿った結果を得ることが可能になります。つまり、明示的なフィルタリングは重要な境界条件を遵守しているかを確認するための安全装置として機能します。
主なユースケースは以下の通りです。
- アプリケーションレベルでの制約:事前に定義されたシステムルールに基づいて検索結果を制限する地理的制約(特定の地域に居住するユーザーが、現地の規制に準拠したドキュメントのみアクセス可能にする。例:欧州在住ユーザーは EU 契約のみに限定)
- 時間的な制約:特定の期間内に有効なドキュメントのみを返す(例:過去 2 年間に有効だった契約書)
- クラス分けと機密性:必要な機密レベルや分類タグが付与されたドキュメントのみを検索結果に含める
明示的フィルタリングの具体例は以下の通りです。
{
"andAll": [
{ "listContains": { "key": "region", "value": "Germany" } },
{ "stringEquals": { "key": "confidentiality_level", "value": "Public" } }
]
}フィルタリングを超えて:メタデータ値によるチャンクの強化
暗黙的・明示的なフィルタリングは候補となるチャンクを絞り込みますが、ドキュメントメタデータで記述されるような構造化された文書レベルのコンテキストを LLM に自動的に提供することはできません。
メタデータとは、ドキュメントの生テキストを超えてその内容を記述する構造化された属性のことです。これらの属性は、ドキュメントの取り込みとインデックス作成後に生成されます。
もしメタデータの値や文脈がなければ、モデルは不十分または精度の低い回答を生成してしまう可能性があります。特に、類似した複雑な契約書が大量に存在するシナリオではそのリスクが高まります。
法的契約分析において一般的に用いられるメタデータ項目には以下のようなものがあります:
- 契約タイプ(例:ライセンス契約)
- 準拠法(例:カリフォルニア州法)
- 発効日
- 有効期限
- 当事者
- ビジネスユニット
- 機密レベル
こうした構造化された層が、フィルタリングやポリシーの適用、そしてより深い推論を可能にします。
それでは、先ほどの問いに戻りましょう:
「*カリフォルニア州法に基づき管理されている有効期限已过みのライセンス契約をすべて特定してください。これらの契約はどのように更新されますか?*\」
仮に取得されたチャンク(断片)に以下の条項が含まれていたとします。
*「本契約は、いずれの当事者も有効期限の少なくとも 60 日前までに書面による更新しない旨の通知を行わない限り、自動的に 1 年ごとの継続期間で更新されます。」*
この条項を、ドキュメントレベルに関連付けられたメタデータ値なしで LLM(大規模言語モデル)に提供した場合、モデルは以下の点を判断できません。
- 契約がライセンス契約であるかどうか
- カリフォルニア州法に基づいて管理されているかどうか
- すでに有効期限が過ぎているかどうか
- 実際の有効期限日
これらのメタデータ値がないと、モデルは不十分または精度の低い回答を生成してしまう可能性があります。
この課題に対処するため、候補となるチャンクにドキュメントレベルのメタデータ値を追加して補強します。すべてのチャンクでメタデータを複製すると入力トークンが無駄になるため、まずはドキュメント単位でチャンクをグループ化し、関連するメタデータを一度だけ付与します。これにより各チャンクはより豊かな文脈を獲得し、LLM が推論を行う際にも効果が高まり、結果として出力の精度、一貫性、信頼性が向上します。
最後に重要なのは、改善の質が選択したメタデータの関連性と適切さに依存する点です。フィルタリングとエンリッチメントは、クエリが利用可能なメタデータと整合している場合に最も効果を発揮します。逆に、それらのメタデータ値とは無関係なクエリでは、同様の恩恵が得られない可能性があります。したがって、このアプローチのインパクトを最大化するには、メタデータフィールドの慎重な設計と適切な選択が不可欠です。
フィルタリングとエンリッチメントの影響評価
フィルタリングとメタデータエンリッチメントの影響を検証するため、以下のガイドライン質問を用いてテストを行いました。
「カリフォルニア州法に準拠する有効期限切れのライセンス契約を特定してください。これらの契約はどのように更新されますか?」
実験には Contract Understanding Atticus Dataset (CUAD)(ライセンスおよび共同ブランディング契約)を使用しました。各テストでは、検索深度を top-k = 15 に設定し、4 つの段階的に強化された構成を比較検討しました。
Amazon Bedrock で自動生成されたフィルターを活用し、契約検索の精度を向上させる
まず、フィルタもメタデータも使わない基本の RAG(Retrieval-Augmented Generation)構成を確認します。この設定では、検索は意味的な類似性のみに基づいて行われます。その結果、文書全体から 55 の候補条項が取得されました。しかし、モデルに渡される上位 15 件の結果に含まれるのは、関連するコンテキストのごく一部でした。観察された点は以下の通りです。
- モデルは期限切れとなった契約(Snap/United)を正しく特定しました。
- 更新条件については部分的な記述にとどまりました。
- 回答には自信が欠け、文脈的な根拠も不十分でした。
次に、米国契約に限定するなど、明示的なフィルターを適用したケースです。候補となる文書の数は減りましたが、精度は必ずしも向上しませんでした。観察された点は以下の通りです。
- ある契約が誤って期限切れと分類されました。
- 更新条項の解釈にズレが生じました。
フィルターをかけるだけでは検索範囲は狭まりますが、精密な推論に必要な構造化されたコンテキストまでは提供されません。
最後に、クエリから導き出されるフィルター(カリフォルニア州法など)とアプリケーションレベルの制約(米国契約に限定)を組み合わせたケースです。競合する文書の数が減り、コンテキストへの焦点が明確になりました。観察された点は以下の通りです。
- モデルは正しい契約を特定しました。
- ただし、期限切れであると断定するには慎重な姿勢を示しました。
- 更新メカニズムについては記述がありましたが、表現には慎重さが感じられました。
フィルターを活用することで検索の精度は向上しましたが、依然として不確実性が残りました。
フィルタリングとメタデータ拡張
最後に、取得したチャンクに、管轄法、有効期限、契約種類などの文書レベルのメタデータを付与しました。その結果、システムは「Snap/United」のみを正しく期限切れと識別できました。
更新条項も明確かつ正確に説明されています。
回答は条文の内容と構造化された属性の両方に根拠を持っており、この設定が最も精度が高く自信のある出力をもたらしました。
セットアップ
候補プール (n)
カバレッジ (15/k)
期限切れ契約の特定数
更新条項の説明
回答品質
Baseline RAG
55
27.3%
*Snap/United*(2000年12月31日到期)を正しく特定
更新詳細が不十分
部分的 – 期限は発見されたが、根拠が弱い
明示的のみ
40
37.5%
誤って期限切れと分類
更新条項の解釈に誤り
不正確
暗黙的かつ明示的
20
75.0%
*Snap/United* を特定したが、「おそらく期限切れ」という留保付き
更新メカニズムは説明済み
混合 – 期限については慎重な表現に留まった
原文を表示
Enterprises rely on large volumes of complex legal agreements to make critical business decisions — determining rights, renewal options, geographic restrictions, and compliance obligations. In industries like entertainment and media, where organizations manage thousands of contracts across multiple jurisdictions, this work remains largely manual: time-consuming, costly, and difficult to scale.
Our AI-Driven Annotation (AIDA) solution, powered by AWS, helps address this challenge by transforming unstructured contracts into searchable, actionable intelligence. AIDA enables users to ask natural-language questions across large contract repositories — but delivering precise answers requires more than semantic search alone. Legal documents are highly contextual, and retrieval-augmented generation (RAG)-based systems can surface more content than a language model can effectively process. Without careful control over which excerpts are retrieved, and without sufficient document-level context, important clauses risk being overlooked or misinterpreted.
In this post, we describe how AIDA works at a high level and how it helps address these challenges — grounding users in the right contracts, under the right legal context, and within the right access boundaries. Specifically, we explore how AIDA uses implicit and explicit filtering, along with metadata-enriched chunking in Amazon Bedrock Knowledge Bases, to dramatically improve contract search accuracy.
Solution overview

The reference architecture diagram represents how AIDA uses a RAG architecture built on Amazon Bedrock Knowledge Bases to create an intelligent document query system. Data transmission between components uses encryption in transit via HTTPS/TLS 1.2+, including document uploads to Amazon Bedrock Knowledge Bases, API calls to embedding models, vector database queries, and response delivery to client applications. For data stored in Amazon Bedrock, the AWS shared responsibility model applies. The implementation follows a systematic workflow:
Data ingestion flow
Step 1: Document ingestion and metadata configuration
The architecture begins with document ingestion, where contracts are synced into Amazon Bedrock Knowledge Bases alongside structured metadata files. The metadata should contain key contract attributes such as parties, effective date, termination date, jurisdiction, and other key attributes that can enable powerful filtering capabilities downstream.
Step 2: Chunking mechanism implementation
The knowledge base configuration phase implements a sophisticated chunking mechanism that breaks contracts into semantically meaningful segments optimized for retrieval. This chunking strategy helps provide each segment with sufficient context while remaining concise enough for efficient processing. The metadata supplied during ingestion plays a critical role in the system’s ability to apply intelligent filtering, particularly through the implicit filtering mechanism that distinguishes this architecture from standard RAG implementations.
Step 3: Vector database storage
Once documents are ingested and processed, the system converts document chunks into vector embeddings and stores them in one of several vector database options available with Amazon Bedrock Knowledge Bases, such as Amazon OpenSearch Service or Amazon S3 Vectors, a capability of Amazon Simple Storage Service (Amazon S3), both of which should be configured with encryption at rest enabled. This vector database serves as the foundation for semantic search, enabling the system to find conceptually similar content rather than relying solely on keyword matching.
Access to the knowledge base and model invocations are governed through AWS Identity and Access Management (IAM) policies, with Amazon CloudWatch logging enabled to maintain audit trails for compliance purposes.
In terms of security, AIDA uses role-based access that is enforced using AWS IAM policies at the application layer in AIDA via project scoped roles, which restricts what each user can do.
User interaction flow
Step 4: Query embedding generation
When a user submits a query, AIDA uses Amazon Bedrock Guardrails to help safeguard against prompt injections and data leaks, the system then follows an enhanced RAG workflow that begins by converting the query into embeddings using Amazon Bedrock’s embedding models. This transformation enables semantic comparison between the user’s question and the stored document chunks.
Step 5: Implicit and explicit filtering
Before performing semantic search, the system applies both implicit and explicit filtering mechanisms—a key innovation that significantly improves retrieval accuracy. The implicit filtering automatically applies metadata-based conditions, such as filtering by effective date ranges or specific contracting parties, before executing the vector search. This two-stage approach first narrows the search space through metadata constraints, then applies semantic similarity matching within that filtered subset, so that retrieved documents are both contextually relevant and meet specific business criteria.
Step 6: Semantic search and document retrieval
The vector database retrieves the most relevant document chunks based on semantic similarity scores, typically using cosine similarity metrics to identify the closest matches to the user’s query. This semantic search operates on the filtered subset of documents, providing high precision and relevance in the results.
Step 7: Prompt augmentation
The retrieved chunks are then used to augment the original user’s query in a carefully formatted prompt that combines the user’s question with relevant contract excerpts and metadata context. This augmented prompt provides the large language model (LLM) with the specific information required to generate a precise, grounded response.
Step 8: LLM response generation
The augmented prompt is passed to a LLM through Amazon Bedrock, which generates a contextually precise response grounded in the actual contract documents rather than relying on the model’s training data alone. This approach helps provide responses that reflect the specific content of the organization’s contracts.
In addition, AIDA uses Amazon Bedrock Guardrails to apply content filtering, sensitive information (PII) safeguards, and prompt safety controls, to keep responses secure and aligned with enterprise and legal standards.
Step 9: Response delivery with source attribution
The final response is returned to the user through the Retrieve API, so that answers are not only relevant but also traceable back to specific source documents. This traceability reduces hallucinations, a common challenge with LLMs, and provides verifiable contract intelligence that users can trust for critical business decisions.
Tuning RAG
When developing a RAG system for legal contract analysis, one of the core challenges is managing the volume of potentially relevant information. Consider the following question:
“*Please identify any expired licensing agreements governed under California law? How do these agreements renew?*”
Such a query might match hundreds of relevant text chunks across multiple documents. In RAG terminology, these excerpts are often referred to as candidate chunks.
When Amazon Bedrock performs a semantic search to find the relevant document excerpts, it is designed to return the top k (max 100) relevant candidate chunks. The remaining candidate chunks that are filtered out could potentially contain critical context. Consequently, the LLM responses might be incomplete, overlook key insights, or even be inaccurate.
Legal documents are highly structured and deeply dependent on context. In our example, a renewal clause in a California licensing agreement may operate differently from a renewal clause in a licensing agreement governed by another jurisdiction. If the retrieval step does not properly filter licensing agreements and California governing law, the system may return irrelevant contracts such as service agreements, NDAs, or agreements governed under other state laws. Even if those documents contain expiration or renewal language, they do not answer the original question. Effective metadata filtering becomes essential to narrow down the candidate pool to the most relevant subsets. This allows the subsequent LLM call to receive the context required to provide more precise and complete answers.
It is important to note that while these retrieval improvements significantly enhance accuracy, AI-generated contract interpretations should always be reviewed by qualified legal professionals before being used for business decisions. AIDA is designed as a decision-support tool that can augment legal expertise rather than replacing it.
Two ways to assist in fine tuning the RAG are implicit filtering and explicit filtering which we will discuss next.
Implicit filtering
Implicit filtering is a powerful capability in Amazon Bedrock Knowledge Bases that allows you to automatically filter search results based on metadata attributes without requiring explicit filter expressions in each query. This approach enables the system to pre-filter the vector store based on document metadata before performing semantic search, significantly narrowing the search space to the most relevant documents.
The implicit filtering mechanism operates through a two-stage process:
Stage 1: Metadata pre-filtering
Before executing the semantic similarity search, the system applies metadata-based conditions automatically. You can supply a custom metadata file (up to 10 KB per document) for each document in your knowledge base, containing attributes such as effective dates, document types, parties involved, or custom fields relevant to your use case.
Stage 2: Semantic search
After narrowing the document set through metadata filters, the system performs vector similarity search only within this filtered subset. This helps reduce noise and irrelevant information while improving retrieval accuracy.
Explicit filtering
Explicit filtering is applied consistently at the application layer, independent of user input. This approach helps provide search results that remain aligned with business policies, compliance requirements, and organizational constraints, rather than being left entirely to the interpretation of the retrieval engine. Explicit filters can therefore act as a safeguard, helping to verify that every query respects a critical boundary.
Common use cases include the following:
- Application-Level Constraints – Restricting retrieval results based on predefined system rules geographic restrictions – Designed to restrict users in certain regions only access documents aligned with local regulations (e.g., European users restricted to EU-only contracts).
- Temporal Constraints – Returning only documents within a specific time frame (e.g., contracts active in the last two years).
- Classification and Sensitivity – Restricting search results to only documents tagged with a required confidentiality or classification level.
Example of our explicit filtering:
{
"andAll": [
{ "listContains": { "key": "region", "value": "Germany" } },
{ "stringEquals": { "key": "confidentiality_level", "value": "Public" } }
]
}Beyond filtering: Enriching chunks with metadata values
While implicit and explicit filtering narrows the pool of candidate chunks, they do not automatically provide the LLM with structured document-level context as described by the document metadata.
Metadata refers to structured attributes that describe a document beyond its raw text. These attributes are generated after document ingestion and indexing. Without these metadata values and context, the model may generate incomplete or less precise answers, especially in scenarios involving high volumes of contracts that are similar and complex in nature.
For legal contract analysis, common metadata fields include:
- Contract Type (e.g., Licensing Agreement)
- Governing Law (e.g., California)
- Effective Date
- Expiration Date
- Parties
- Business Unit
- Confidentiality Level
This structured layer enables filtering, policy enforcement, and richer reasoning.
Let’s return to our guiding question:
“*Please identify any expired licensing agreements governed under California law? How do these agreements renew?*”
Suppose one retrieved chunk contains the following clause:
*“This Agreement shall automatically renew for successive one-year terms unless either party provides written notice of non-renewal at least 60 days prior to the expiration date.”*
If this clause is provided to the LLM without the document-level associated metadata values, the model cannot determine the following:
- Whether the agreement is a licensing agreement.
- Whether it is governed under California law.
- Whether it has already expired.
- The actual expiration date.
Without these metadata values, the model may generate incomplete or less accurate responses.
To address this limitation, we enrich candidate chunks with document-level metadata values. Rather than duplicating metadata for every chunk, which would waste input tokens, we first group chunks by document and attach the relevant metadata once. This gives each chunk a richer context and helps the LLM reason more effectively, leading to more accurate, consistent, and reliable outputs.
Finally, it’s important to recognize that the quality of improvements depends on the relevance and appropriateness of the metadata we choose. Filtering and enrichment work best when queries are aligned with the available metadata. Conversely, queries unrelated to those metadata values may not show the same benefits. Careful design and thoughtful selection of metadata fields are therefore essential to maximize the impact of this approach.
Evaluating the impact of filtering and enrichment
To evaluate the impact of filtering and metadata enrichment, we tested our guiding question:
“*Please identify any expired licensing agreements governed under California law? How do these agreements renew?*”
The experiments were conducted on the Contract Understanding Atticus Dataset (CUAD) (licensing and co-branding agreements). For each test, the retrieval depth was set to top-k = 15. We compared four progressively enhanced configurations.
- Baseline RAG (no filters, no metadata). In the baseline setup, retrieval relied purely on semantic similarity. The system retrieved 55 potential candidate clauses across documents. However, only a small portion of the relevant context made it into the top 15 results passed to the model. Observations:
The model correctly identified one expired agreement (Snap/United).
- Renewal terms were partially described.
- The response lacked confidence and full contextual grounding.
- Explicit filtering only. Next, we applied explicit filters (for example, restricting results to U.S. contracts). This reduced the candidate pool, but accuracy did not improve consistently. Observations:
One agreement was incorrectly classified as expired.
- Renewal clauses were misinterpreted.
Filtering alone narrowed the search space but did not provide enough structured context for precise reasoning.
- Implicit and explicit filtering. We then combined query-derived filters (California law) and application-level constraints (U.S. contracts). This reduced the number of competing documents and improved contextual focus. Observations:
The model identified the correct agreement.
- However, it hesitated to definitively classify it as expired.
- Renewal mechanisms were described but cautiously phrased.
Filtering improved retrieval precision, but uncertainty remained.
- Filtering and metadata enrichment. Finally, we enriched retrieved chunks with document-level metadata such as governing law, expiration date, and contract type. Observations:
The system correctly identified only Snap/United as expired.
- Renewal terms were clearly and accurately explained.
- The response was grounded in both clause text and structured attributes.
This configuration produced the most accurate and confident output.
Setup
Candidate pool (n)
Coverage (15/k)
Expired agreements identified
Renewal terms explained
Answer quality
Baseline RAG
55
27.3%
Correctly identified *Snap/United* (expired 12/31/2000)
Renewal details incomplete
Partial – expiration found, rationale weak
Explicit only
40
37.5%
Misclassified as expired
Renewal terms misinterpreted
Not precise
Implicit and explicit
20
75.0%
Identified *Snap/United* but only as “potentially expired”
Renewal mechanisms described
Mixed – hedged on expiration
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み