Inspect sources with Amazon Bedrock Knowledge Bases Retrieve

Inspect sources with Amazon Bedrock Knowledge Bases Retrieve

When a retrieval-augmented app returns an unhelpful answer, start by looking at what it retrieved. Amazon Bedrock Knowledge Bases exposes a retrieval-only API so you can inspect the document chunks and their source locations before sending anything to a generation model.

Prepare a knowledge base with known answers

Use AWS CLI v2, a sandbox Knowledge Base with a synchronized S3 text data source, and permission to call bedrock:Retrieve in its Region. For a repeatable drill, use short sample documents and record the expected source key for each question. Start with synthetic data.

For example, add a file called queue-operations.md containing “In the staging runbook, a failed queue replay is escalated to the application on-call after two attempts.” Add a second file on a different topic. Sync the data source and wait for the ingestion job to complete before querying.

Retrieve chunks without generating an answer

AWS_REGION=us-east-1
KB_ID=REPLACE123
QUERY='Who handles a failed queue replay after two attempts?'

aws bedrock-agent-runtime retrieve \
  --region "$AWS_REGION" \
  --knowledge-base-id "$KB_ID" \
  --retrieval-query "text=$QUERY" \
  --retrieval-configuration '{"vectorSearchConfiguration":{"numberOfResults":5}}' \
  --no-paginate \
  --query 'retrievalResults[].{score:score,source:location.s3Location.uri,text:content.text}' \
  --output json

Replace REPLACE123 with the ID of the lab Knowledge Base. This query projects the S3 source URI, text, and relevance score from the first response. Other data-source types expose different location fields, so inspect the full response if you use a source outside S3.

Check what the app would cite

Look for queue-operations.md among the results and read the chunk itself. A promising result contains the exact escalation instruction and maps back to the expected source. Try a similar question with different wording and a question that your sources cannot answer. A relevance score measures ranking for retrieval, not whether a claim is true.

For each test question, record the expected source and whether that source appears among the first five hits. This gives you a repeatable check when you change chunking, add documents, or adjust retrieval options. In an application UI, surface citations only to readers who are authorized to access the underlying documents.

Troubleshoot retrieval before editing the prompt

  • No useful sources: Check the ingestion job, source prefix, Region, and test question.
  • Right source, incomplete evidence: Inspect neighboring passages. A chunk boundary may have separated a rule from its exception.
  • Too many similar results: Check for duplicate documents before raising the number of results.

Clean up the sandbox

The retrieval call does not deploy a generation model. Embeddings, storage, and vector search can still incur charges. Delete sandbox sources, the test Knowledge Base, and its dedicated backing resources if you created them only for this drill. Preserve shared resources.

Retrieve from an Amazon Bedrock Knowledge Base · AWS CLI Retrieve reference

Related reading

Techmandra Avatar

Leave a Reply

Your email address will not be published. Required fields are marked *