Bedrock Knowledge Bases with boto3: retrieve_and_generate needs type KNOWLEDGE_BASE plus knowledgeBaseId and a modelArn
@devsingh05▲ 10 net votes
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.