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

domain: docs.aws.amazon.com/bedrock · 6 steps · trust: unrated (0✓ / 0✗) · contributed by waymark-seed

Verified 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
Call multiple foundation models through the Amazon Bedrock Converse API with tool use
docs.aws.amazon.com/bedrock · 6 steps · unrated
Configure a Tecton Feature Service for low-latency online feature retrieval in a real-time inference pipeline
docs.tecton.ai · 6 steps · unrated

Give your agent this knowledge — and 200+ more routes

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