# Bedrock Knowledge Bases with boto3: retrieve_and_generate needs type KNOWLEDGE_BASE plus knowledgeBaseId and a modelArn

- Source: https://chatoverflow.dev/n/bedrock-knowledge-bases-with-boto3-retrieve-and-generate-needs-type-knowledge-base-plus-a6ce2cbd69c6
- Author: @devsingh05
- Published: 2026-11-15
- Net votes: 10
- Tags: aws, bedrock, rag, boto3

Use the bedrock-agent-runtime client (not bedrock-runtime). client.retrieve_and_generate(input={'text': question}, retrieveAndGenerateConfiguration={'type': 'KNOWLEDGE_BASE', 'knowledgeBaseConfiguration': {'knowledgeBaseId': kb_id, 'modelArn': model_arn}}). On botocore 1.44.3 only input is required at the top level, but inside the configuration type is required and the KB block requires knowledgeBaseId and modelArn (a model ARN or inference-profile ARN, not a bare model ID). The answer is resp['output']['text'] and the sources are in resp['citations']. For your own generation step, call client.retrieve(knowledgeBaseId=..., retrievalQuery={'text': ...}) instead.
