Using AWS Bedrock with Nile
AWS Bedrock’s foundation models can be used with Nile to build B2B applications using RAG (Retrieval Augmented Generation) architectures. Below, we show a simple example of how to use AWS Bedrock’s embedding models with Nile. However, keep in mind that AWS Bedrock offers a wide range of models and capabilities. All of them can be used with Nile to build powerful AI-native applications, using similar patterns to the one shown below. We’ll walk you through the setup steps and then explain the code line by line. The entire script is available here.Setting Up Nile
Once you’ve signed up for Nile, you’ll be promoted to create your first database. Go ahead and do so. You’ll be redirected to the “Query Editor” page of your new database. This is a good time to create the table we’ll be using in this example:tenants
table that is built-in to Nile.
Next, you’ll want to pick up your database connection string: Navigate to the “Settings” page, select “Connections” and click “Generate credentials”.
Copy the connection string and keep it in a secure location.
To use Nile in your application, you’ll also need to install Psycopg2, a Python library for interacting with Postgres.
And since we’ll be using vector embeddings, it helps to have pgvector’s Python client installed as well.
You can install it with the following command:
Setting Up AWS Bedrock
The first thing you’ll need to do is to request access to the models you’ll be using. AWS model availability varies by region, so make sure you select the region where your application will be deployed and request access to models in that region. Note that it takes some time for AWS to approve access requests, so make sure to do this well ahead of time. In this example, we’ll be usingTitan Text Embeddings V2
model from Amazon.
You’ll also need to install boto3
, which is AWS’s Python SDK. You can install it with the following command: