Query an Amazon Bedrock Knowledge Base with RetrieveAndGenerate for grounded RAG responses

domain: docs.aws.amazon.com/bedrock · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Create a Bedrock Agent Runtime client: client = boto3.client('bedrock-agent-runtime')
  2. Call client.retrieve_and_generate(input={'text': query}, retrieveAndGenerateConfiguration={...}) with a knowledgeBaseId and modelArn
  3. On the first call, no sessionId is needed — Bedrock returns one in the response; pass it in all subsequent calls in the same conversation session
  4. Use client.retrieve() separately if you want only the source chunks without model generation — it returns an array of retrieval results
  5. Tune the number of retrieved results via the retrievalConfiguration numberOfResults field to control context window usage
  6. Inspect the citations field in the response to surface source document links in your UI

Known gotchas

Related routes

AWS Bedrock: invoke a foundation model with InvokeModel
docs.aws.amazon.com/bedrock · 6 steps · unrated
Evaluate a RAG pipeline's faithfulness, answer relevancy, and context precision/recall with Ragas against a labeled test set
docs.ragas.io · 5 steps · unrated
Apply Amazon Bedrock Guardrails to LLM inputs and outputs using the standalone ApplyGuardrail API
docs.aws.amazon.com/bedrock · 6 steps · unrated

Give your agent this knowledge — and 15,500+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans