Amazon Bedrock でクエリ認識圧縮により RAG コストを削減
本文の状態
日本語全文を表示中
詳細モードで約16分の本文を読めます。
同じ出来事の情報源
この情報源を基点に整理
AWS Machine Learning Blog
Amazon は、検索結果をクエリに照らして軽量モデルでフィルタリングする「クエリ対応圧縮」パターンを Amazon Bedrock で提供し、RAG の入力トークン削減によるコスト低減とハルシネーション防止を実現した。
AI深層分析を開く2026年8月22日 02:53
AI深層分析
キーポイント
クエリ対応圧縮パターンの導入
検索後かつ最終回答生成前に、軽量で低コストなモデルが取得したチャンクをユーザーのクエリに対してフィルタリングする仕組みを導入した。
コスト削減と品質維持の両立
この手法により主要な基盤モデルへの入力トークンを大幅に減らしながら、回答の質を維持し、スケーラブルな RAG 運用でのコストパフォーマンスを最適化する。
ハルシネーションリスクの低減
関連性の低いコンテキストを除去することで、モデルが誤った情報を生成する可能性(ハルシネーション)の表面積を縮小する副次的な効果がある。
Amazon Bedrock での実装対応
このカスタマイズパターンは Amazon Bedrock の検索機能、特に Knowledge Bases と互換性があり、AWS Lambda を用いた実装例が提示されている。
既存機能との連携による追加コスト削減
このパターンはプロンプトキャッシングやインテリジェントプロンプトラウティング、Rerank APIなどの既存のAmazon Bedrock機能と組み合わせることで、さらなるコスト削減を実現できる。
重要な引用
Query-aware compression offers one way to reduce how many of them reach the model.
As workloads scale, builders often look for ways to optimize the cost-performance tradeoff by reducing the number of input tokens the primary model processes while maintaining answer quality.
After retrieval but before the final answer call, a smaller, lower-cost model on Amazon Bedrock filters retrieved chunks against the user's query.
We also look at how this pattern can layer on top of existing Amazon Bedrock capabilities like prompt caching, Amazon Bedrock Intelligent Prompt Routing, and the Rerank API for compounding cost savings.
編集コメントを表示
編集コメント
RAG のコスト最適化において、検索結果のフィルタリングというアプローチを軽量モデルで自動化する実用的なパターンが提示された。これは大規模運用における信頼性と経済性の両立を目指す開発者にとって即座に検討すべき技術的選択肢となる。
Source Article
元記事を日本語で読む
本文に関係しない購読案内、埋め込み通知、サイト内プロモーションは除いています。
大規模な Retrieval Augmented Generation (RAG) を運用する際、コストの大きな部分を占めるのが、毎回基盤モデル(FM)に送信される入力トークン数です。クエリ対応型圧縮は、モデルに到達するトークンの数を減らす有効な手段の一つです。
Amazon Bedrock は、RAG アプリケーションを構築するための 基盤モデル と機能を提供しています。通常、RAG の検索プロセスは高い再現率(リコール)を重視し、主要なモデルが十分な情報源を得られるよう、関連する可能性のあるチャンクを広範囲に返します。この設計により、開発者は推論時に必要な情報が確実に揃っていると安心できます。
しかし、ワークロードが拡大すると、回答の品質を維持しつつ、主要モデルが処理する入力トークンの数を減らすことでコストと性能のバランスを最適化する方法が求められます。Amazon Bedrock のオープンでコンポーザブルなアーキテクチャは、主要モデルに到達する情報を精査するためのカスタム後処理ステップをサポートしています。
本稿では、回答の品質を維持しつつ、入力トークンを大幅に削減してコストを節約できる「検索後カスタマイズ」のパターンについて解説します。この手法は Amazon Bedrock の RAG リトリーバー(検索エンジン)と互換性があり、Amazon Bedrock Knowledge Bases にも対応しています。
また、関連性の低いコンテキストを除去することで、ハルシネーション(幻覚現象)の発生リスクも低減できるという副次的なメリットもあります。具体的な仕組みとしては、最終的な回答生成の前に、ユーザーのクエリに対して Amazon Bedrock 上の小型・低コストモデルが検索されたチャンクをフィルタリングします。その後、主要なモデルがこのフィルタリング済みコンテキストを受け取り、回答を生成します。
本稿では、このパターンのアーキテクチャを概観し、AWS Lambda 関数を用いた Amazon Bedrock のコア実装を示します。さらにコストモデルとレイテンシのトレードオフについて解説し、回答品質の評価方法についても触れます。また、既存の Amazon Bedrock 機能である プロンプトキャッシュ、インテリジェント・プロンプトラウティング、および Rerank API と組み合わせることで、さらなるコスト削減を実現できる仕組みについても解説します。
事前準備
本ソリューションを実装するには、以下の手順を完了してください。
- アクティブな AWS アカウント を保有していること。
Lambda 関数が Amazon Bedrock にアクセスできるように、AWS Identity and Access Management (IAM) ロールを作成してください。作成手順については、「AWS サービスに権限を委譲するためのロールの作成」をご参照ください。
作成した IAM ロールに対して、必要なポリシー権限を追加します。
Amazon Bedrock コンソールの「モデルアクセス」セクションで、カスケード処理に使用する 2 つのモデル(本記事では圧縮用小規模モデルとして Anthropic Claude Haiku、プライマリモデルとして Anthropic Claude Sonnet)について、お住まいの AWS リージョンでのアクセス権をリクエストしてください。
Amazon Bedrock 上の RAG コスト削減におけるクエリ認識型圧縮の仕組み
従来の RAG インフラやフレームワークを用いた RAG フローは、以下のようになります。
- アプリケーションがユーザーのクエリを埋め込みベクトルに変換します。
- ベクトルインデックスから関連性の高い上位 k 個のチャンク(通常は 5〜20 個)が返されます。
- (オプションで)ランカーがこれらのチャンクを関連性に基づいて再順序付けします。
- 取得されたすべてのチャンクがプロンプトに連結されます。
- プライマリモデルが回答を生成します。
取得されるコンテキスト量は、top-k の値とチャンクサイズに依存して増大します。一般的なチャンクサイズで 5〜20 個のチャンクを取得すると、多くの技術文書や法的ドキュメントを対象とした RAG ワークロードでは、1 クエリあたりの入力トークン数が数千単位に達することがあります。クエリごとのトークン数を削減することで、コストを有意に下げることが可能です。
アーキテクチャの概要
取得したチャンクをクエリと一緒に読み込み、質問に関連する部分のみを原文のまま抽出して出力するのが小規模モデルの役割です。本稿では Claude Haiku を使用していますが、この手法は Amazon Bedrock 上の同系列モデル間で、小規模モデルと主要モデルを組み合わせても機能します。
圧縮処理と主要モデルによる回答生成は、いずれも単一の AWS Lambda 関数内で実行されます。その上流にはクエリを埋め込み、上位 k 件のチャンクを返す検索エンジン(レトリーバー)が存在します。Amazon Bedrock のナレッジベース(Amazon OpenSearch Serverless を基盤とした完全管理型の RAG 機能)がその一例です。
Lambda 関数はこれらのチャンクを入力として受け取り、最終的な回答を出力します。圧縮処理は、標準的な RAG フローに追加される唯一のステップです。
小規模モデルは主要モデルよりもトークンあたりのコストが安いため、高価な回答生成前にコンテキストを削減することでコスト削減を実現できます。その節約額は主に以下の 2 つの要因によって決まります。
以下の図は本ソリューションのアーキテクチャを示しています。

図 1: Amazon Bedrock 上のクエリ対応型コンテキスト圧縮アーキテクチャ
処理フローは以下の手順で進行します。
- ユーザーがアプリケーションにクエリを送信する。
アプリケーションはクエリを retriever に送信し、ベクトル化された知識ソースを検索させます。
retriever は上位 k 件のチャンク(取得したコンテキスト全体)をアプリケーションに返します。
アプリケーションはクエリと取得したすべてのチャンクを AWS Lambda 関数へ渡し、その関数が Amazon Bedrock の Converse API を介して小規模モデル(Claude Haiku)へ送信します。これが圧縮処理の呼び出しです。
小規模モデルは、クエリに関連する記述通りのスパンのみを出力し、それが圧縮されたコンテキストとなります。
Lambda 関数は、クエリと圧縮されたコンテキストを Converse API を介して主要なモデル(Claude Sonnet)へ送信します。これが回答生成の呼び出しです。
主モデルが最終回答を生成し、アプリケーションがそれをユーザーに返します。
経済的に有効な理由
このアプローチの経済性は、Amazon Bedrock 上の小規模モデルと主モデルの価格比、および小規模モデルが達成する圧縮率という 2 つの要素によって決まります。
RAG クエリにおいて、取得された入力トークン数が R で、圧縮率が c(ただし c > 1)、最終的な回答出力が A トークンの場合、
トークンごとの価格を P_small_in / P_small_out(小規模モデル用)とします。
モデルの入力・出力価格、および大規模モデルの入力・出力価格(P_large_in / P_large_out):
| ステージ | ベースライン | 圧縮あり | 何が起こるか |
|---|---|---|---|
| 小規模モデルがチャンクを読み取る | — | R × P_small_in | 小規模モデルは、クエリと取得されたすべてのチャンクを入力として受け取る |
| 小規模モデルが圧縮出力を書き出す | — | (R/c) × P_small_out | 小規模モデルは、クエリに関連する文字通りのスパンのみを出力する |
| 主要モデルがコンテキストを読み取る | R × P_large_in | (R/c) × P_large_in | 主要モデルは、回答を生成するためにコンテキストを入力として受け取る |
| 主要モデルが回答を書き出す | A × P_large_out | A × P_large_out | 主要モデルは、ユーザー向けの最終回答を生成する |
| 合計 | R·P_large_in + A·P_large_out | R·P_small_in + (R/c)·P_small_out + (R/c)·P_large_in + A·P_large_out |
圧縮処理では、小型モデルの入力と出力のコストが発生しますが、主要なモデルに送信するトークン数を R から R/c に減らすことでコスト削減を実現します。この経済効果が得られるのは、以下の条件が揃った場合です。
- 取得したコンテキストのサイズが大きい場合(大型モデルでのトークン削減効果が支配的になる)
- 大型モデルと小型モデルの価格差が大きい場合(例:Sonnet/Opus と Haiku の組み合わせ)
- 特定のクエリに対して、回答品質を損なわずに取得コンテンツの一部を削除できる割合がある場合
Amazon Bedrock での実装
このパターンは、検索処理と最終的な回答生成の間に位置します。AWS Lambda 関数として実装し、Converse API を用いて2つのAmazon Bedrockモデル呼び出しをオーケストレーションします。この関数は、ユーザーからのクエリと取得したチャンクを入力イベントとして受け取ります。
圧縮用のプロンプト
圧縮処理の肝となるのは、小型モデルに対して要約ではなくスパン(該当部分)の抽出を指示し、言い換えや書き換えを禁止するとともに、引用元が正確に保てるよう十分な周辺コンテキストを残すように促す点です。
COMPRESSION_SYSTEM_PROMPT = """You extract evidence from retrieved documents.
You will receive a user QUESTION and a list of CHUNKS.
Your job:
1. For each chunk, identify the spans (verbatim sentences or short paragraphs)
that contain evidence directly relevant to answering the QUESTION.
2. Output ONLY those spans, copied verbatim from the source. Do not paraphrase,
summarize, or rewrite.
3. Preserve chunk identifiers so the downstream system can cite sources.
4. If a chunk contains no relevant evidence, output the chunk identifier
followed by NO_RELEVANT_EVIDENCE.
Output format (strict):
[CHUNK_ID: ]
[CHUNK_ID: ]
NO_RELEVANT_EVIDENCE
Do not add commentary, headings, conclusions, or your own words. Only verbatim
spans from the source chunks, grouped by chunk identifier."""Lambda 関数の実装
この関数は、ユーザーのクエリと取得したチャンクを受け取り、環境変数から 2 つのモデル ID を読み込んで、適応型リトライを設定した Amazon Bedrock Runtime クライアントを初期化します。その後、Bedrock Converse API を介して 2 回の呼び出しを実行します。1 回目は小型モデルに対してチャンクの圧縮を行い、2 回目はプライマリモデルに対して圧縮された根拠から回答を生成させます。
圧縮用の呼び出しでは温度(temperature)を 0.0 に設定し、抽出の決定性を保ちます。これにより、小型モデルはソース内のスパンをそのままコピーします。
ステップ 1: 圧縮。小型モデルが取得したチャンクをフィルタリングします。
compressed = bedrock.converse(
modelId=COMPRESSION_MODEL_ID,
system=[{"text": COMPRESSION_SYSTEM_PROMPT}],
messages=[{"role": "user",
"content": [{"text": f"QUESTION:\n{query}\n\nCHUNKS:\n{chunks}"}]}],
inferenceConfig={"temperature": 0.0},
)ステップ 2: 回答。プライマリモデルがフィルタリングされた根拠に基づいて推論を行います。
answer = bedrock.converse(
modelId=ANSWER_MODEL_ID,
system=[{"text": "Answer using only the evidence provided. Cite sources."}],
messages=[{"role": "user",
"content": [{"text": f"QUESTION:\n{query}\n\nEVIDENCE:\n{compressed}"}]}],
)注: プロンプトはあくまで例であり、ドキュメントや質問の種類に合わせて適応させる必要があります。
手法
このパターンを推奨する前に、実証的な評価を行いました。ベンチマークでは以下の要素を対象としました。
- チャットメッセージ、メール、課題追跡チケット、共有ドライブの文書、CRM レコード、会議議事録、コードリポジトリ、ウィキページなど、9 種類のエンタープライズソースにまたがる 50 万ドキュメント以上のコーパス。
- 狭義な事実参照から広範な多段階質問までを網羅する 10 カテゴリにわたる 500 問のクエリセット。正確に記述されたものから、よりカジュアルな表現のものまでを含みます。
- 複数の圧縮条件:圧縮なし(ベースライン)、圧縮あり、および再ランク付け+圧縮。
各クエリは、ベースラインと最適化されたパイプラインの両方を通じて実行され、回答は 大規模言語モデル(LLM)による評価者によって採点されます。
品質スコアリングは、参照回答に対して「正しさ」「完全性」「出典の正確さ」「簡潔さ」の 4 つの次元で行われます。一方、「忠実度」は別個に追跡され、各回答の主張が主要モデルが受け取った証拠と一致しているかを確認します。
これらの数値は、特定のコーパス、ドメイン、クエリ分布に基づくものです。実際の文書やクエリにおける結果は異なる可能性があります。
結果
以下の表では、ベースライン、圧縮、そして再ランク付け+圧縮のパイプラインを比較し、各クエリにおける主要な結果を要約しています。
| 指標 | ベースライン | 圧縮 | 再ランク付け+圧縮 |
|---|---|---|---|
| コスト | 100% (参照) | 67% | 64% |
| モデルへのトークン数 | 100% (参照) | 12% | 10% |
| レイテンシ | 0% (参照) | +19% (遅延) | +12% (遅延) |
| 品質(複合指標、4 次元) | 100% (参照) | 97.5% | 97.6% |
| ハルシネーション発生率 | 51% | −7 ポイント | −13 ポイント |
以下の数値はベンチマーク結果に基づくものです。実際のデータセット、クエリ、モデル選択によって結果は異なります。
次の図は、クエリコストの削減率(左軸:ベースラインに対するパーセンテージ)と、主要なモデルへ送信されるコンテキスト量の削減度合い(右軸:トークン数の減少倍率)の平均値を示しています。圧縮手法のみではコストが 33% 削減され、トークン数は 8.6 倍に減りました。一方、再ランク付けと圧縮を組み合わせることで、コスト削減率は 36% に達し、トークン数は 10.1 倍減少しました。

図 2:コスト削減率と主要モデルへの送信トークン数の削減度合い
次の図は、各パイプラインにおける回答品質の 4 つの次元(正しさ、完全性、出典の正確さ、簡潔さ)に対する LLM 判定スコア(1〜5 点)を示しています。どの条件でも「正しさ」のスコアはベースラインから±0.07 の範囲内に保たれています。「圧縮」を適用した場合、「完全性」と「出典の正確さ」はわずかに低下しますが、「簡潔さ」はわずかに向上します。

図 3:パイプライン別の回答品質 4 次元における LLM 判定スコア
以下の図は、各パイプラインにおけるハルシネーション(幻覚)発生率を示しています。これは、回答の中に参照情報で裏付けられない主張が少なくとも一つ含まれている割合として測定されました。ベースラインでは 51%、圧縮処理のみでは 44%、再ランク付けと圧縮を組み合わせると 38% となりました。

図 4: パイプライン別のハルシネーション発生率
次の図は、一般的なクエリセットと難しいクエリセットにおけるベースラインからのコスト削減効果を比較しています。圧縮処理のみでは削減率が 37% から 26% に低下し、再ランク付けと圧縮を組み合わせる場合でも 40% から 30% へと変化します。

図 5: 一般的なクエリセットと難しいクエリセットにおけるコスト削減効果
本番環境での利用に関する考慮事項
このパターンを採用する前に、3 つの要素を慎重に検討する必要があります。それは、追加される圧縮呼び出しによるレイテンシ(遅延)、回答品質への影響、そしてそのワークロードが適しているかどうかです。これら各項目については、以下のセクションで詳しく解説します。
レイテンシ
小型モデルの呼び出しを追加すると、処理パスに1段階が増えます。Claude Haiku は高速化が最適化されており、主要なモデルはその後、小さく焦点を絞ったコンテキストを処理するため、回答時の追加時間は一部回復されます。全体のエンドツーエンドのレイテンシは、圧縮呼び出しと焦点を絞ったコンテキストに対する回答呼び出しの合計になります。実質的な影響は、元のコンテキストサイズに対して主要なモデルが計算リソースに依存している程度によって決まります。
レイテンシが重要な場面(サブ
原文を表示
Input tokens sent to the foundation model (FM) on every call are often a meaningful part of the cost of running Retrieval Augmented Generation (RAG) at scale. Query-aware compression offers one way to reduce how many of them reach the model. Amazon Bedrock provides the foundation models and features to build RAG applications. RAG retrieval usually tunes for high recall, returning a broad set of potentially relevant chunks so the primary model has thorough source material to work with. This design helps builders feel confident that the right information is available at inference time. As workloads scale, builders often look for ways to optimize the cost-performance tradeoff by reducing the number of input tokens the primary model processes while maintaining answer quality. The open, composable architecture of Amazon Bedrock supports custom post-retrieval processing steps that refine what reaches the primary model.
In this post, we describe a post-retrieval customization pattern that achieves significant input-token reduction, and therefore cost savings, while preserving answer quality. It’s compatible with RAG retrievers on Amazon Bedrock, including Amazon Bedrock Knowledge Bases. As a secondary benefit, removing irrelevant context reduces the surface area for hallucination. After retrieval but before the final answer call, a smaller, lower-cost model on Amazon Bedrock filters retrieved chunks against the user’s query. The primary model then receives the filtered context and generates the answer.
We cover the pattern’s architecture at a high level, show the core Amazon Bedrock implementation in a AWS Lambda function, walk through the cost model and the latency tradeoff, and describe how we evaluated answer quality. We also look at how this pattern can layer on top of existing Amazon Bedrock capabilities like prompt caching, Amazon Bedrock Intelligent Prompt Routing, and the Rerank API for compounding cost savings.
Prerequisites
To implement the solution, complete the following prerequisite steps:
- Have an active AWS account.
- Create an AWS Identity and Access Management (IAM) role for the Lambda function to access Amazon Bedrock. For instructions, refer to Create a role to delegate permissions to an AWS service.
- Add policy permissions to the IAM role.
- Amazon Bedrock model access in your AWS Region for the two models in the cascade: a smaller compression model (Anthropic Claude Haiku in this post) and a primary model (Anthropic Claude Sonnet). Request access on the Amazon Bedrock console under Model access.
How query-aware compression reduces RAG costs on Amazon Bedrock
A RAG flow using traditional RAG infrastructure or frameworks looks like:
- The application embeds the user query.
- The vector index returns the top-k chunks (commonly 5–20).
- Optionally, a reranker reorders those chunks by relevance.
- All retrieved chunks are concatenated into the prompt.
- The primary model generates the answer.
Retrieved context scales with top-k and chunk size: retrieving 5–20 chunks at typical chunk sizes puts many technical-documentation and legal RAG workloads in the range of several thousand input tokens per query. Reducing the per-query token count can yield meaningful cost savings.
Architecture overview
A smaller model reads the retrieved chunks alongside the query and outputs only the verbatim spans relevant to the question. We use Claude Haiku in this post, but the pattern works with other small/primary model pairs within a model family on Amazon Bedrock. Both the compression call and the primary model’s answer call run inside a single AWS Lambda function. Upstream, a retriever embeds the query and returns the top-k chunks. An Amazon Bedrock knowledge base, the fully managed RAG capability backed by Amazon OpenSearch Serverless, is one such retriever. The Lambda function receives those chunks as input and returns the final answer. The compression call is the only step added to a standard RAG flow.
Because the smaller model costs less per token than the primary model, trimming the context before the expensive answer call is where the savings come from. How large those savings are comes down to two things.
The following diagram shows the solution architecture.

**Figure 1: Query-aware context compression architecture on Amazon Bedrock
The flow proceeds through the following steps:**
- The user submits a query to the application.
- The application sends the query to the retriever, which searches the vectorized knowledge sources.
- The retriever returns the top-k chunks (full retrieved context) to the application.
- The application passes the query and all retrieved chunks to an AWS Lambda function, which sends them to a smaller model (Claude Haiku) through the Amazon Bedrock Converse API. This is the compression call.
- The smaller model outputs only the verbatim spans relevant to the query (the compressed context).
- The Lambda function sends the query and the compressed context to the primary model (Claude Sonnet) through the Converse API. This is the answer call.
- The primary model generates the final answer, which the application returns to the user.
Why this works economically
The economics depend on two factors: the price ratio between the small and primary models on Amazon Bedrock, and the compression ratio the smaller model achieves.
For a single RAG query with R retrieved input tokens, a compression ratio of c (where c > 1), a final answer output of A tokens, and per-token prices P_small_in / P_small_out (smaller model input and output price) and P_large_in / P_large_out (primary model input and output price):
| Stage | Baseline | With compression | What happens |
|---|---|---|---|
| Smaller model reads chunks | — | R × P_small_in | The smaller model receives the query and all retrieved chunks as input |
| Smaller model writes compressed output | — | (R/c) × P_small_out | The smaller model outputs only the verbatim spans relevant to the query |
| Primary model reads context | R × P_large_in | (R/c) × P_large_in | The primary model receives the context as input to generate the answer |
| Primary model writes answer | A × P_large_out | A × P_large_out | The primary model generates the final answer for the user |
| Total | R·P_large_in + A·P_large_out | R·P_small_in + (R/c)·P_small_out + (R/c)·P_large_in + A·P_large_out |
The compression call adds the input and output cost of the smaller model. Savings come from sending R/c instead of R tokens to the primary model. The economics favor compression when:
- Retrieved context is large (the savings on the larger model dominate).
- The price ratio between large and small is high (Sonnet/Opus paired with Haiku).
- A meaningful portion of the retrieved content can be trimmed for a given query without affecting answer quality.
Implementation on Amazon Bedrock
The pattern fits between retrieval and the final answer call. We implement it as a single AWS Lambda function that orchestrates the two Amazon Bedrock model invocations using the Converse API. The function receives the user query and the retrieved chunks as its input event.
The compression prompt
The compression prompt is the most important part of the implementation. It must instruct the smaller model to extract spans rather than summarize, forbid paraphrasing and rewriting, and preserve enough surrounding context for citations to remain accurate.
COMPRESSION_SYSTEM_PROMPT = """You extract evidence from retrieved documents.
You will receive a user QUESTION and a list of CHUNKS.
Your job:
1. For each chunk, identify the spans (verbatim sentences or short paragraphs)
that contain evidence directly relevant to answering the QUESTION.
2. Output ONLY those spans, copied verbatim from the source. Do not paraphrase,
summarize, or rewrite.
3. Preserve chunk identifiers so the downstream system can cite sources.
4. If a chunk contains no relevant evidence, output the chunk identifier
followed by NO_RELEVANT_EVIDENCE.
Output format (strict):
[CHUNK_ID: ]
[CHUNK_ID: ]
NO_RELEVANT_EVIDENCE
Do not add commentary, headings, conclusions, or your own words. Only verbatim
spans from the source chunks, grouped by chunk identifier."""The Lambda function
The function takes the user query and the retrieved chunks, reads the two model IDs from environment variables, and initializes an Amazon Bedrock Runtime client configured with adaptive retries. It then makes two calls through the Bedrock Converse API: the first to the smaller model to compress the chunks, and the second to the primary model to generate the answer from the compressed evidence. The compression call runs at temperature 0.0, which keeps the extraction deterministic so the smaller model copies spans as they appear in the source:
Step 1: Compress. The smaller model filters the retrieved chunks.
compressed = bedrock.converse(
modelId=COMPRESSION_MODEL_ID,
system=[{"text": COMPRESSION_SYSTEM_PROMPT}],
messages=[{"role": "user",
"content": [{"text": f"QUESTION:\n{query}\n\nCHUNKS:\n{chunks}"}]}],
inferenceConfig={"temperature": 0.0},
)Step 2: Answer. The primary model reasons over the filtered evidence.
answer = bedrock.converse(
modelId=ANSWER_MODEL_ID,
system=[{"text": "Answer using only the evidence provided. Cite sources."}],
messages=[{"role": "user",
"content": [{"text": f"QUESTION:\n{query}\n\nEVIDENCE:\n{compressed}"}]}],
)Note: The prompts are an example and should be adapted to your documents and question types.
Methodology
Before recommending this pattern, we evaluated it empirically. The benchmark covered:
- A corpus of more than 500,000 documents spanning 9 enterprise source types, including chat messages, email, issue-tracker tickets, shared-drive documents, CRM records, meeting transcripts, code repositories, and wiki pages.
- A set of 500 questions across 10 categories, ranging from narrow factual lookups to broader multi-part questions, including both precisely worded and more informally phrased queries.
- Multiple compression conditions: no compression (baseline), compression, and rerank-plus-compression.
- Each query run through baseline and optimized pipelines, with answers scored by a large language model (LLM) judge.
- Quality scoring across four dimensions (correctness, completeness, citation accuracy, and conciseness) against a reference answer. Faithfulness was tracked separately, checking each answer’s claims against the evidence the primary model received.
These figures describe one corpus, one domain, and one query distribution. Results on your own documents and queries will differ.
結果
The following table summarizes the headline results across the queries, comparing the baseline, compression, and rerank + compression pipelines.
| Metric | Baseline | Compression | Rerank + Compression |
|---|---|---|---|
| Cost | 100% (ref) | 67% | 64% |
| Tokens to model | 100% (ref) | 12% | 10% |
| Latency | 0% (ref) | +19% (slower) | +12% (slower) |
| Quality (composite, 4 dims) | 100% (ref) | 97.5% | 97.6% |
| Hallucination rate | 51% | −7 pts | −13 pts |
The following figures come from the benchmark. Results on your own corpus, queries, and model choices will differ. The following figure shows the average of query cost saving (left axis, percentage versus baseline) and the reduction in context sent to the primary model (right axis, times fewer tokens). Compression achieved a 33 percent cost saving or 8.6× fewer tokens. Rerank + compression reached 36 percent cost saving and 10.1× fewer tokens.

Figure 2: Cost savings and reduction in context tokens sent to the primary model
The following figure shows the LLM-judge scores (1–5) across the four answer-quality dimensions for each pipeline. Correctness stays within 0.07 of baseline across conditions. Completeness and citation accuracy are slightly lower under compression, while conciseness is slightly higher.

Figure 3: LLM-judge scores across the 4 answer-quality dimensions by pipeline
The following figure shows the hallucination rate for each pipeline, measured as the share of answers containing at least one claim not supported by the reference. The baseline is 51 percent, compression 44 percent, and rerank + compression 38 percent.

Figure 4: Hallucination rate by pipeline
The following figure shows the cost saving versus baseline for the typical-query set and the hard-query set. Compression moves from 37 percent to 26 percent, and rerank + compression from 40 percent to 30 percent between the two sets.

Figure 5: Cost savings for the typical-query and hard-query sets
Considerations for production use
Three things must be weighed before this pattern is adopted: the latency of the added compression call, the impact on answer quality, and whether the workload is a fit. Each is covered in the following sections.
Latency
Adding a smaller-model call introduces one extra step in the path. Claude Haiku is optimized for speed, and because the primary model then processes a smaller, focused context, part of that added time is recovered on the answer call. The total end-to-end latency is the compression call plus the answer call on the focused context. Net impact depends on how compute-bound the primary model is on the original context size.
For latency-critical surfaces (sub
関連記事
今日のまとめ
AIデイリーブリーフで今日の重要ニュースをまとめ読み