Reputation: 43
I want to experiment with different ml models and i understand , amazon bedrock platform allows to do so. for starters , i want to use dataset and then generate embeddings. i know, i can use a bedrock client and choose from model available and pass in my content to generate embeddings.
but is there an more automated way than this. say , i dump my content to a s3 bucket and simply point bedrock or open search service and it generates and stores it to an s3 or open search database?
bedrock = boto3.Session.client('bedrock-runtime)
bedrock.invoke_model(
modelID = 'tbd',
body = ''
)
Upvotes: -1
Views: 454
Reputation: 373
What you need is AWS Bedrock Knowledge Base and we can do this in 3 steps:
Step 1: knowledge base creation
see here: https://docs.aws.amazon.com/bedrock/latest/userguide/knowledge-base.html
You upon creating (quick create knowledge base) you get to choose where your data resides (s3) from there you will create your vector storage (OpenSearch serverless? mind the cost, or others)
Afterwards, you'll choose a model to generate the embeddings. There, you can select from multiple models with different dimensional spaces. Larger dimensional spaces provide deeper knowledge and may also increase storage costs and response times but i doubt this would be an issue.
You’ll also get to configure chunking and define fields to connect OpenSearch to the Bedrock Service. (run for the default as a starter) but be mindful that you first need to request access to the Foundation Models (FMs) before using them currently creating the knowledge base will fail silently if you choose a FM that is not granted before hand.
When you've created everything is up and running you need to "sync" your data, it might not be visually intuitive but you select your data source and then click "sync"
After that you will be able to "Test" the knowledge base from the console, you'd choose your model of choice (a FM has already been granted) some are good for reasoning and can take a couple of seconds to answer while others are good for quicker response.
There, you’ll have two options:
Step 2 Now that you are done with the first step, the second one is to consume: Using the agent to interact Reading on the Agent runtime here: Agent runtime
We can see two suitable calls:
You can configure the agent for optimal results. there are various options available, most of which are straightforward if you’re familiar with the topic.
One key thing to remember is the session_id. This sets the "thread" or chat session. If you’re testing and want fresh responses every time, set the session_id to change automatically (in code, maybe time.now() or something like that) otherwise, you might encounter some strange or repeated answers :)
Step 3 Lastly, but not least, comes the ingestion workflow: See Data Source Ingestion
If needed, you can set up an event trigger for updates to your S3 bucket. When new data is added, the trigger can invoke a Lambda function to automatically start an ingestion job (which is part of the Data Source Ingestion link)
happy coding :)
Upvotes: 1