79665848

Date: 2025-06-14 12:48:58
Score: 0.5
Natty:
Report link

Since you've already synced your AWS Knowledge Base with Bedrock, you're ready to query it using an Amazon Bedrock Runtime API with a RAG (Retrieval-Augmented Generation) setup. Here's how you can get started programmatically:

1. Set up your environment

2. Use RetrieveAndGenerate API

Here’s an example in Python using boto3:

Replace YOUR_KB_ID with the actual Knowledge Base ID
Replace modelArn with the model you want to use (e.g., Claude 3, Titan, etc.)

import boto3

bedrock_agent_runtime = boto3.client('bedrock-agent-runtime')

response = bedrock_agent_runtime.retrieve_and_generate(
    input={
        "text": "What are the benefits of using Amazon SageMaker?"
    },
    retrieveAndGenerateConfiguration={
        "knowledgeBaseConfiguration": {
            "knowledgeBaseId": "YOUR_KB_ID"
        },
        "modelArn": "arn:aws:bedrock:us-east-1::foundation-model/anthropic.claude-3-sonnet-20240229-v1:0"
    }
)

print(response['output']['text'])

More details and examples on Cloudoku.training here - https://cloudoku.training/blog/aws-knowledge-base-with-bedrock

Good Luck! let me know how it goes.

Reasons:
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Cloudoku.training