Amazon Bedrocks
This guide will walk you through an example using Amazon Bedrock SDK with vecs
. We will create embeddings using the Amazon Titan Embeddings G1 – Text v1.2 (amazon.titan-embed-text-v1) model, insert these embeddings into a PostgreSQL database using vecs, and then query the collection to find the most similar sentences to a given query sentence.
Create an Environment
First, you need to set up your environment. You will need Python 3.7+ with the vecs
and boto3
libraries installed.
You can install the necessary Python libraries using pip:
You’ll also need:
Create Embeddings
Next, we will use Amazon’s Titan Embedding G1 - Text v1.2 model to create embeddings for a set of sentences.
Store the Embeddings with vecs
Now that we have our embeddings, we can insert them into a PostgreSQL database using vecs.
Querying for Most Similar Sentences
Now, we query the sentences
collection to find the most similar sentences to a sample query sentence. First need to create an embedding for the query sentence. Next, we query the collection we created earlier to find the most similar sentences.
This returns the most similar 3 records and their distance to the query vector.